/* ==========================================================================
   THEME.CSS — Design System WhiteLabel
   Sistema de clínica (PHP) — camada visual centralizada.
   Todas as cores/marca vêm de variáveis CSS definidas no header.php
   (a partir da tabela `configuracoes`). Este arquivo NÃO fixa marca.
   Leve: usa Bootstrap 5 (já carregado) + variáveis. Sem dependências extras.
   ========================================================================== */

:root {
    /* Fallbacks — o header.php sobrescreve com os valores da clínica */
    --primary-color: #0d6efd;
    --secondary-color: #6c757d;
    --accent-color: #28a745;
    --bg-color: #f4f6f9;
    --text-color: #1f2937;

    /* Derivadas (calculadas no header; fallback aqui) */
    --primary-dark: #0b5ed7;
    --primary-soft: rgba(13, 110, 253, .10);
    --primary-softer: rgba(13, 110, 253, .06);
    --btn-color: var(--primary-color);

    /* Tokens de UI */
    --radius-sm: 10px;
    --radius: 14px;
    --radius-lg: 20px;
    --shadow-sm: 0 1px 3px rgba(16, 24, 40, .06), 0 1px 2px rgba(16, 24, 40, .04);
    --shadow: 0 4px 16px rgba(16, 24, 40, .06);
    --shadow-lg: 0 12px 34px rgba(16, 24, 40, .10);
    --border-soft: #eaecf0;
    --muted: #667085;
    --sidebar-w: 264px;
    --topbar-h: 62px;

    --surface: #ffffff;
    --surface-2: #f8fafc;
}

/* ---------------------------------- Base --------------------------------- */
* { -webkit-tap-highlight-color: transparent; }

body {
    color: var(--text-color);
    font-family: 'Inter', 'Segoe UI', Tahoma, system-ui, -apple-system, sans-serif;
    letter-spacing: .1px;
}

h1, h2, h3, h4, h5, h6 { font-weight: 700; color: var(--text-color); }
a { text-decoration: none; }

::selection { background: var(--primary-soft); }

/* Scrollbar discreta */
* { scrollbar-width: thin; scrollbar-color: #cfd6e4 transparent; }
*::-webkit-scrollbar { width: 9px; height: 9px; }
*::-webkit-scrollbar-thumb { background: #cfd6e4; border-radius: 20px; }
*::-webkit-scrollbar-thumb:hover { background: #b6c0d4; }

/* ------------------------- Layout: topbar + sidebar ---------------------- */
.app-topbar {
    position: sticky;
    top: 0;
    z-index: 1040;
    height: var(--topbar-h);
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 20px;
    background: rgba(255, 255, 255, .88);
    backdrop-filter: saturate(180%) blur(10px);
    -webkit-backdrop-filter: saturate(180%) blur(10px);
    border-bottom: 1px solid var(--border-soft);
}
.app-topbar .tb-brand {
    display: flex; align-items: center; gap: 10px;
    font-weight: 700; color: var(--text-color); min-width: 0;
}
.app-topbar .tb-brand img { height: 34px; width: auto; max-width: 150px; object-fit: contain; }
.app-topbar .tb-brand .tb-name { font-size: 1.02rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.app-topbar .tb-spacer { flex: 1 1 auto; }
.app-topbar .tb-user {
    display: flex; align-items: center; gap: 10px;
    padding: 5px 6px 5px 12px; border-radius: 999px;
    border: 1px solid var(--border-soft); background: #fff;
}
.app-topbar .tb-user .tb-user-name { font-size: .86rem; font-weight: 600; line-height: 1; }
.app-topbar .tb-user .tb-user-role { font-size: .7rem; color: var(--muted); line-height: 1; }
.app-topbar .tb-avatar {
    width: 34px; height: 34px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: .85rem; color: #fff;
    background: linear-gradient(135deg, var(--primary-color), var(--accent-color));
}
.app-topbar .tb-hamburger {
    border: 1px solid var(--border-soft); background: #fff; color: var(--text-color);
    width: 40px; height: 40px; border-radius: var(--radius-sm);
    display: none; align-items: center; justify-content: center; font-size: 1.05rem;
}

.app-sidebar {
    position: fixed; top: 0; left: 0; bottom: 0;
    width: var(--sidebar-w);
    background: #ffffff;
    border-right: 1px solid var(--border-soft);
    z-index: 1055;
    display: none;                 /* mostrado no desktop via media query */
    flex-direction: column;
    padding: 0;
}
.app-sidebar .sb-brand {
    height: var(--topbar-h);
    display: flex; align-items: center; gap: 10px;
    padding: 0 18px; border-bottom: 1px solid var(--border-soft);
    font-weight: 800; color: var(--text-color);
}
.app-sidebar .sb-brand img { height: 36px; max-width: 170px; object-fit: contain; }
.app-sidebar .sb-brand .sb-name { font-size: 1.05rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.app-sidebar .sb-nav { flex: 1 1 auto; overflow-y: auto; padding: 14px 12px 20px; }
.app-sidebar .sb-group-label {
    font-size: .68rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
    color: #98a2b3; padding: 14px 12px 6px;
}
.app-sidebar .sb-link {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 12px; margin-bottom: 2px;
    border-radius: var(--radius-sm);
    color: #475467; font-weight: 600; font-size: .92rem;
    transition: background .15s, color .15s;
}
.app-sidebar .sb-link i { width: 20px; text-align: center; font-size: 1rem; color: var(--secondary-color); }
.app-sidebar .sb-link:hover { background: var(--surface-2); color: var(--text-color); }
.app-sidebar .sb-link.active { background: var(--primary-soft); color: var(--primary-color); }
.app-sidebar .sb-link.active i { color: var(--primary-color); }
.app-sidebar .sb-foot { border-top: 1px solid var(--border-soft); padding: 12px; }

/* Backdrop do menu mobile (offcanvas simples) */
.app-sidebar-backdrop {
    position: fixed; inset: 0; background: rgba(16, 24, 40, .45);
    z-index: 1054; display: none;
}
body.sidebar-open .app-sidebar-backdrop { display: block; }
body.sidebar-open .app-sidebar { display: flex; }

/* ------------------------------- Cards ----------------------------------- */
.card,
.card-shadow {
    border: 1px solid var(--border-soft);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    background: var(--surface);
}
.card-shadow { border-radius: var(--radius-lg); }
.card { overflow: hidden; }
.card-header {
    background: var(--surface);
    border-bottom: 1px solid var(--border-soft);
    font-weight: 700;
    padding: .9rem 1.1rem;
}
.card-body { padding: 1.1rem; }
.card:hover { box-shadow: var(--shadow); }
.card.no-hover:hover { box-shadow: var(--shadow-sm); }

/* KPI / cards de resumo do dashboard */
.stat-card {
    border: 1px solid var(--border-soft);
    border-radius: var(--radius);
    background: var(--surface);
    padding: 1rem 1.15rem;
    box-shadow: var(--shadow-sm);
    display: flex; align-items: center; gap: 14px;
    transition: transform .15s, box-shadow .15s;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.stat-card .stat-icon {
    width: 48px; height: 48px; flex: 0 0 48px;
    border-radius: 12px; display: flex; align-items: center; justify-content: center;
    font-size: 1.25rem; color: var(--primary-color); background: var(--primary-soft);
}
.stat-card .stat-label { font-size: .8rem; color: var(--muted); font-weight: 600; }
.stat-card .stat-value { font-size: 1.5rem; font-weight: 800; line-height: 1.15; }

/* ------------------------------- Botões ---------------------------------- */
.btn {
    border-radius: var(--radius-sm);
    font-weight: 600;
    padding: .5rem 1rem;
    transition: transform .12s ease, box-shadow .15s ease, background-color .15s, color .15s;
}
.btn:active { transform: translateY(1px); }
.btn-lg { border-radius: var(--radius); padding: .7rem 1.3rem; }
.btn-sm { border-radius: 9px; }

.btn-primary {
    background-color: var(--btn-color) !important;
    border-color: var(--btn-color) !important;
    color: #fff !important;
    box-shadow: 0 2px 8px color-mix(in srgb, var(--btn-color) 35%, transparent);
}
.btn-primary:hover, .btn-primary:focus {
    background-color: var(--primary-dark) !important;
    border-color: var(--primary-dark) !important;
    box-shadow: 0 4px 14px color-mix(in srgb, var(--btn-color) 45%, transparent);
}
.btn-outline-primary {
    color: var(--primary-color) !important;
    border-color: var(--primary-color) !important;
}
.btn-outline-primary:hover {
    background-color: var(--primary-color) !important;
    color: #fff !important;
}
.btn-success { background-color: var(--accent-color) !important; border-color: var(--accent-color) !important; }
.btn-success:hover { filter: brightness(.94); }
.btn-light { background: var(--surface-2); border-color: var(--border-soft); }

/* ------------------------------- Tabelas --------------------------------- */
.table-modern-wrap {
    background: var(--surface);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}
.table {
    margin-bottom: 0;
    color: var(--text-color);
}
.table > thead th {
    background: var(--surface-2);
    color: #667085;
    font-size: .74rem;
    font-weight: 700;
    letter-spacing: .04em;
    text-transform: uppercase;
    border-bottom: 1px solid var(--border-soft);
    padding: .8rem .9rem;
    white-space: nowrap;
}
.table > tbody > tr { transition: background .12s; }
.table > tbody > tr:hover > * { background: var(--primary-softer); }
.table > tbody td { padding: .78rem .9rem; vertical-align: middle; border-color: #f1f3f7; }
.table-hover > tbody > tr:hover > * { background: var(--primary-softer); }

/* ------------------------------- Forms ----------------------------------- */
.form-label { font-weight: 600; font-size: .88rem; margin-bottom: .35rem; color: #344054; }
.form-control, .form-select {
    border-radius: var(--radius-sm);
    border: 1px solid #d5dbe5;
    padding: .55rem .8rem;
    font-size: .95rem;
    transition: border-color .15s, box-shadow .15s;
    color: var(--text-color);
}
.form-control:focus, .form-select:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px var(--primary-soft);
}
.form-control-lg, .input-group-lg > .form-control { border-radius: var(--radius); }
.input-group-text { border-radius: var(--radius-sm); background: var(--surface-2); border-color: #d5dbe5; }
.form-control.is-invalid, .was-validated .form-control:invalid { border-color: #dc3545; }
.form-control.is-valid, .was-validated .form-control:valid { border-color: var(--accent-color); }
.form-check-input:checked { background-color: var(--primary-color); border-color: var(--primary-color); }

/* ------------------------------- Badges ---------------------------------- */
.badge { font-weight: 600; border-radius: 999px; padding: .38em .7em; letter-spacing: .02em; }

/* Chips de status suaves (uso opcional: <span class="chip chip-success">) */
.chip { display: inline-flex; align-items: center; gap: 5px; font-size: .76rem; font-weight: 600;
    padding: .28rem .6rem; border-radius: 999px; line-height: 1; }
.chip::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; opacity: .9; }
.chip-success { color: #067647; background: #ecfdf3; }
.chip-warning { color: #b54708; background: #fffaeb; }
.chip-danger  { color: #b42318; background: #fef3f2; }
.chip-info    { color: #175cd3; background: #eff8ff; }
.chip-muted   { color: #475467; background: #f2f4f7; }

/* ------------------------------- Alerts ---------------------------------- */
.alert { border: 1px solid transparent; border-radius: var(--radius); border-left-width: 4px; font-weight: 500; }
.alert-success { background: #ecfdf3; color: #05603a; border-color: #a6f4c5; border-left-color: var(--accent-color); }
.alert-danger  { background: #fef3f2; color: #912018; border-color: #fecdca; border-left-color: #f04438; }
.alert-warning { background: #fffaeb; color: #93370d; border-color: #fedf89; border-left-color: #f79009; }
.alert-info    { background: #eff8ff; color: #0b4a6f; border-color: #b2ddff; border-left-color: #2e90fa; }
.alert-primary { background: var(--primary-soft); color: var(--primary-dark); border-color: transparent; border-left-color: var(--primary-color); }

/* ------------------------- Nav tabs / pills ------------------------------ */
.nav-tabs { border-bottom: 1px solid var(--border-soft); gap: 2px; }
.nav-tabs .nav-link {
    border: none; border-radius: 0; color: var(--muted); font-weight: 600;
    padding: .65rem 1rem; border-bottom: 2px solid transparent;
}
.nav-tabs .nav-link:hover { color: var(--text-color); border-bottom-color: #d5dbe5; }
.nav-tabs .nav-link.active {
    color: var(--primary-color); background: transparent;
    border-bottom: 2px solid var(--primary-color);
}
.nav-pills .nav-link { border-radius: var(--radius-sm); font-weight: 600; color: var(--muted); }
.nav-pills .nav-link.active { background: var(--primary-color); }

/* ---------------------- Dropdowns / modais / offcanvas ------------------- */
.dropdown-menu {
    border: 1px solid var(--border-soft);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 6px;
}
.dropdown-item { border-radius: var(--radius-sm); padding: .5rem .7rem; font-weight: 500; }
.dropdown-item:active, .dropdown-item.active { background: var(--primary-color); }
.dropdown-item:hover { background: var(--surface-2); }

.modal-content { border: none; border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); overflow: hidden; }
.modal-header { border-bottom: 1px solid var(--border-soft); padding: 1rem 1.25rem; }
.modal-footer { border-top: 1px solid var(--border-soft); }

.list-group-item { border-color: var(--border-soft); }
.progress { border-radius: 999px; background: var(--surface-2); }
.progress-bar { background-color: var(--primary-color); }

.text-primary { color: var(--primary-color) !important; }
.text-secondary { color: var(--secondary-color) !important; }
.bg-primary { background-color: var(--primary-color) !important; }
.bg-secondary { background-color: var(--secondary-color) !important; }
.border-primary { border-color: var(--primary-color) !important; }

/* Login / cartão central */
.auth-shell { min-height: calc(100vh - 40px); display: flex; align-items: center; justify-content: center; }
.auth-card { width: 100%; max-width: 410px; }

/* --------------------------- Bottom nav (mobile) ------------------------- */
/* Estilos base ficam no footer.php; aqui só refinamentos visuais */
.bottom-nav { border-top: 1px solid var(--border-soft) !important; }

/* ------------------------------ Responsivo ------------------------------- */
@media (min-width: 992px) {
    body.app-authenticated { padding-left: var(--sidebar-w); }
    body.app-authenticated .app-sidebar { display: flex; }
    body.app-authenticated .bottom-nav { display: none !important; }
    body.app-authenticated .app-topbar .tb-hamburger { display: none; }
    /* No desktop o menu lateral já exibe a marca — evita logo duplicada */
    body.app-authenticated .app-topbar .tb-brand { display: none; }
    /* Chat flutuante alinhado à área de conteúdo */
    body.app-authenticated .chat-fab { bottom: 24px; }
}

@media (max-width: 991.98px) {
    .app-topbar .tb-hamburger { display: flex; }
    .app-topbar .tb-user .tb-user-meta { display: none; }
}

@media (max-width: 575.98px) {
    .app-topbar .tb-brand .tb-name { max-width: 150px; }
    .stat-card .stat-value { font-size: 1.3rem; }
    .card-body { padding: .9rem; }
}

/* Utilitário: rolagem horizontal segura para tabelas largas */
.scroll-x { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.min-w-0 { min-width: 0; }
.stat-card .stat-value { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Cabeçalho de etapa (formulários em passos, ex.: Nova Venda) */
.step-header {
    display: flex; align-items: center; gap: 10px;
    padding: .85rem 1.1rem; font-weight: 700; color: var(--text-color);
    background: var(--surface); border-bottom: 1px solid var(--border-soft);
}
.step-header .step-num {
    width: 26px; height: 26px; flex: 0 0 26px; border-radius: 50%;
    background: var(--primary-color); color: #fff;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: .82rem; font-weight: 700;
}
.step-header .step-num.step-pay { background: var(--accent-color); }
.step-header .step-hint { margin-left: auto; font-size: .75rem; font-weight: 500; color: var(--muted); }

/* Grade de ações do dashboard (tiles uniformes) */
.dash-section-title {
    font-size: .72rem; font-weight: 800; letter-spacing: .09em; text-transform: uppercase;
    color: var(--muted); margin: 1.5rem 0 .75rem;
}
.action-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
@media (min-width: 576px) { .action-grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 992px) { .action-grid { grid-template-columns: repeat(4, 1fr); } }
.action-tile {
    position: relative; display: flex; flex-direction: column; gap: 12px;
    padding: 16px; min-height: 116px;
    border: 1px solid var(--border-soft); border-radius: var(--radius);
    background: var(--surface); box-shadow: var(--shadow-sm);
    text-decoration: none; color: var(--text-color);
    transition: transform .15s ease, box-shadow .15s ease;
}
.action-tile:hover { transform: translateY(-3px); box-shadow: var(--shadow); color: var(--text-color); }
.action-tile .at-icon {
    width: 44px; height: 44px; border-radius: 12px;
    display: flex; align-items: center; justify-content: center; font-size: 1.15rem;
    background: var(--primary-soft); color: var(--primary-color);
}
.action-tile .at-icon.at-success { background: #ecfdf3; color: #12b76a; }
.action-tile .at-icon.at-danger  { background: #fef3f2; color: #f04438; }
.action-tile .at-icon.at-warning { background: #fffaeb; color: #f79009; }
.action-tile .at-icon.at-accent  { background: color-mix(in srgb, var(--accent-color) 14%, transparent); color: var(--accent-color); }
.action-tile .at-title { font-weight: 700; font-size: .95rem; line-height: 1.2; }
.action-tile .at-sub { font-size: .78rem; color: var(--muted); margin-top: 2px; }
.action-tile .at-badge {
    position: absolute; top: 14px; right: 14px;
    font-size: .72rem; font-weight: 700; padding: .25rem .55rem; border-radius: 999px;
    background: #fef3f2; color: #f04438;
}
.action-tile.is-disabled { opacity: .5; pointer-events: none; }
.action-tile-primary {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
    border: none; color: #fff;
    box-shadow: 0 8px 22px color-mix(in srgb, var(--primary-color) 30%, transparent);
}
.action-tile-primary:hover { color: #fff; }
.action-tile-primary .at-icon { background: rgba(255,255,255,.22); color: #fff; }
.action-tile-primary .at-sub { color: rgba(255,255,255,.82); }
.action-tile-primary .at-title { color: #fff; }

/* Estado vazio (empty state) reutilizável */
.empty-state { text-align: center; padding: 1.5rem 1rem; color: var(--muted); }
.empty-state .empty-icon {
    width: 66px; height: 66px; margin: 0 auto .9rem;
    border-radius: 50%; display: flex; align-items: center; justify-content: center;
    font-size: 1.6rem; color: var(--primary-color); background: var(--primary-soft);
}
.empty-state .empty-title { font-weight: 700; color: var(--text-color); font-size: 1rem; }
.empty-state .empty-sub { font-size: .88rem; margin-top: .25rem; }

/* Reduz motion se o usuário preferir */
@media (prefers-reduced-motion: reduce) {
    * { transition: none !important; animation: none !important; }
}
