/* ════════════════════════════════════════════════════════
   FisioFlow — Design System
   Estética: clínica, calma, confiável, minimalista (teal/azul).
   ════════════════════════════════════════════════════════ */

:root {
    /* Paleta Clínica (Petrol / Teal / Aqua) — nomes mantidos p/ compatibilidade */
    --rose-50:  #eef5f6;
    --rose-100: #dce9ec;
    --rose-200: #c2dde2;
    --rose-300: #A6D9E0;   /* soft aqua (destaque) */
    --rose-400: #6FB3BF;
    --rose-500: #2E8C9E;   /* teal (primária) */
    --rose-600: #1F6F7E;
    --rose-700: #0E4D5E;   /* petrol (mais forte) */

    --plum-700: #135666;
    --plum-800: #0E4D5E;   /* petrol — sidebar/texto forte */
    --plum-900: #08323d;

    --sage-300: #A6D9E0;   /* aqua */
    --sage-500: #2E8C9E;   /* teal */
    --sage-600: #2D6A4F;   /* sucesso */

    --gold-400: #F4A261;   /* alerta */
    --danger:   #E76F51;   /* erro */
    --info:     #2CB1BC;   /* informação */
    --success:  #2D6A4F;   /* sucesso */

    --bg:       #F7FAFB;
    --surface:  #ffffff;
    --border:   #e1ecee;
    --muted:    #7B8794;   /* texto secundário */
    --text:     #1F2933;   /* texto principal */

    /* Aliases semânticos (paleta oficial FisioFlow) */
    --primary:   #0E4D5E;
    --secondary: #2E8C9E;
    --accent:    #A6D9E0;
    --card:      #ffffff;
    --warning:   #F4A261;

    --radius:   16px;
    --radius-sm: 10px;
    --shadow-sm: 0 1px 2px rgba(14,77,94,.06), 0 1px 3px rgba(14,77,94,.04);
    --shadow:    0 4px 16px rgba(14,77,94,.08);
    --shadow-lg: 0 12px 40px rgba(14,77,94,.12);

    --sidebar-w: 256px;
    --font: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    font-size: 14.5px;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--rose-600); text-decoration: none; }
a:hover { color: var(--rose-700); }

/* ───── Layout shell ───── */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-w);
    background: var(--plum-800);
    color: #fff;
    padding: 24px 16px;
    position: fixed; inset: 0 auto 0 0;
    display: flex; flex-direction: column;
    z-index: 40;
}
.sidebar .brand {
    display: flex; align-items: center; gap: 12px;
    padding: 4px 12px 24px;
    font-weight: 700; font-size: 18px; letter-spacing: -.02em;
}
.sidebar .brand .logo {
    width: 36px; height: 36px; border-radius: 11px;
    background: linear-gradient(135deg, var(--sage-500), var(--sage-300));
    display: grid; place-items: center; font-size: 18px;
    box-shadow: 0 4px 14px rgba(107,144,128,.4);
}
.nav-section { font-size: 11px; text-transform: uppercase; letter-spacing: .08em;
    color: rgba(255,255,255,.4); margin: 18px 12px 8px; font-weight: 600; }
.nav-link {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 12px; border-radius: var(--radius-sm);
    color: rgba(255,255,255,.78); font-weight: 500;
    transition: all .15s ease; margin-bottom: 2px;
}
.nav-link:hover { background: rgba(255,255,255,.07); color: #fff; }
.nav-link.active {
    background: var(--sage-500);
    color: #fff; box-shadow: 0 4px 14px rgba(107,144,128,.4);
}
.nav-link .ico { width: 20px; text-align: center; opacity: .9; }

.sidebar .user-card {
    margin-top: auto; padding: 12px; border-radius: var(--radius-sm);
    background: rgba(255,255,255,.06); display: flex; align-items: center; gap: 10px;
}
.avatar {
    width: 36px; height: 36px; border-radius: 50%; flex: 0 0 36px;
    background: linear-gradient(135deg, var(--sage-300), var(--sage-500));
    display: grid; place-items: center; color: #fff; font-weight: 600; font-size: 14px;
}

/* ───── Conteúdo ───── */
.main { flex: 1; margin-left: var(--sidebar-w); display: flex; flex-direction: column; }
.topbar {
    height: 68px; background: var(--surface); border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 28px; position: sticky; top: 0; z-index: 30;
}
.topbar h1 { font-size: 20px; font-weight: 700; margin: 0; letter-spacing: -.02em; }
.topbar .sub { color: var(--muted); font-size: 13px; }
.content { padding: 28px; max-width: none; width: 100%; min-width: 0; }
/* Evita rolagem horizontal da página em qualquer tela (notebooks inclusive).
   Tabelas largas rolam dentro do próprio .table-wrap, não a página toda. */
html, body { overflow-x: hidden; }
.app-shell { max-width: 100vw; overflow-x: clip; }
.main { min-width: 0; }

/* ───── Cards ───── */
.card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow-sm);
}
.card-pad { padding: 22px; }
.card-title { font-size: 15px; font-weight: 700; margin: 0 0 4px; }

/* ───── KPIs ───── */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px,1fr)); gap: 18px; }
.kpi {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow-sm);
    transition: transform .15s ease, box-shadow .15s ease;
}
.kpi:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.kpi .label { color: var(--muted); font-size: 13px; font-weight: 500; }
.kpi .value { font-size: 28px; font-weight: 800; letter-spacing: -.03em; margin-top: 6px; }
.kpi .ico-badge {
    width: 40px; height: 40px; border-radius: 12px; float: right;
    display: grid; place-items: center; font-size: 18px;
    background: var(--rose-100); color: var(--rose-600);
}
.kpi.sage .ico-badge { background: #e7f0ea; color: var(--sage-600); }
.kpi.gold .ico-badge { background: #faf0e2; color: var(--gold-400); }
.kpi.danger .ico-badge { background: #fbe9e9; color: var(--danger); }
.kpi .trend { font-size: 12px; font-weight: 600; margin-top: 8px; }
.trend.up { color: var(--sage-600); } .trend.down { color: var(--danger); }

/* ───── Tabela ───── */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; }
table.data th {
    text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em;
    color: var(--muted); font-weight: 600; padding: 12px 16px; border-bottom: 1px solid var(--border);
}
table.data td { padding: 14px 16px; border-bottom: 1px solid var(--border); }
table.data tr:last-child td { border-bottom: none; }
table.data tbody tr { transition: background .12s; }
table.data tbody tr:hover { background: var(--rose-50); }

/* ───── Badges ───── */
.badge {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 600;
}
.badge.healthy   { background: #e7f0ea; color: var(--sage-600); }
.badge.attention { background: #faf0e2; color: #b07d3c; }
.badge.risk      { background: #fbe9e9; color: var(--danger); }
.badge.paid      { background: #e7f0ea; color: var(--sage-600); }
.badge.open      { background: var(--rose-100); color: var(--rose-600); }
.badge.overdue   { background: #fbe9e9; color: var(--danger); }
.badge.info      { background: #e1f5f6; color: #1c8a93; }
.dot { width: 8px; height: 8px; border-radius: 50%; }
.dot.healthy { background: var(--sage-500); }
.dot.attention { background: var(--gold-400); }
.dot.risk { background: var(--danger); }

/* ───── Botões ───── */
.btn {
    display: inline-flex; align-items: center; gap: 8px; cursor: pointer;
    padding: 10px 18px; border-radius: var(--radius-sm); font-weight: 600; font-size: 14px;
    border: 1px solid transparent; transition: all .15s ease;
}
.btn-primary { background: #EEF5F3; color: var(--primary); border-color: #DCEAE5;
    box-shadow: none; }
.btn-primary:hover { background: var(--sage-300); transform: translateY(-1px); color: var(--primary); }
.btn-ghost { background: var(--surface); border-color: var(--border); color: var(--text); }
.btn-ghost:hover { background: var(--rose-50); border-color: var(--rose-200); }

/* ───── Alertas ───── */
.alert {
    display: flex; align-items: center; gap: 12px; padding: 14px 16px;
    border-radius: var(--radius-sm); margin-bottom: 10px; font-weight: 500; font-size: 13.5px;
    border: 1px solid transparent;
}
.alert.info    { background: var(--rose-50); border-color: var(--rose-100); color: var(--rose-700); }
.alert.warning { background: #faf0e2; border-color: #f0dcc0; color: #8a6326; }
.alert.danger  { background: #fbe9e9; border-color: #f3d2d2; color: #a64545; }

/* ───── Health bar ───── */
.health-bar { height: 8px; background: var(--border); border-radius: 999px; overflow: hidden; width: 90px; }
.health-bar > span { display: block; height: 100%; border-radius: 999px; }

/* ───── Login ───── */
.auth-wrap { min-height: 100vh; display: grid; grid-template-columns: 1fr 1fr; }
.auth-art {
    background: linear-gradient(155deg, var(--plum-900) 0%, var(--plum-800) 42%, var(--sage-500) 100%);
    color: #fff; display: flex; flex-direction: column; justify-content: center; padding: 64px;
    position: relative; overflow: hidden;
}
.auth-art::before {
    content: ""; position: absolute; width: 360px; height: 360px; border-radius: 50%;
    background: radial-gradient(circle, rgba(164,195,178,.35), transparent 70%);
    top: -130px; left: -110px;
}
.auth-art::after {
    content: ""; position: absolute; width: 420px; height: 420px; border-radius: 50%;
    background: radial-gradient(circle, rgba(255,255,255,.12), transparent 70%);
    bottom: -120px; right: -120px;
}
.auth-art h2 { font-size: 34px; line-height: 1.2; letter-spacing: -.03em; margin: 0 0 16px; }
.auth-art p { opacity: .8; font-size: 16px; max-width: 380px; }
.auth-form { display: grid; place-items: center; padding: 32px; }
.auth-form .box { width: 100%; max-width: 380px; }
.field { margin-bottom: 16px; }
.field label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 6px; }
.field input {
    width: 100%; padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--radius-sm);
    font-size: 14.5px; font-family: var(--font); transition: border .15s, box-shadow .15s;
}
.field input:focus { outline: none; border-color: var(--rose-400); box-shadow: 0 0 0 3px var(--rose-100); }

.helper { color: var(--muted); font-size: 12.5px; }
.flex { display: flex; align-items: center; }
.between { justify-content: space-between; }
.gap { gap: 12px; }
.mt { margin-top: 18px; } .mb { margin-bottom: 18px; }

/* ───── Mobile: drawer + tab bar ───── */
.nav-hamburger { display: none; background: none; border: none; cursor: pointer; font-size: 22px;
    color: var(--text); padding: 4px 8px; margin-right: 4px; }
.sidebar-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 39; display: none; }
.sidebar-overlay.show { display: block; }
.mobile-tabbar { display: none; position: fixed; bottom: 0; left: 0; right: 0; z-index: 50;
    background: var(--surface); border-top: 1px solid var(--border);
    justify-content: space-around; align-items: stretch;
    padding: 6px 0 calc(6px + env(safe-area-inset-bottom)); box-shadow: 0 -2px 12px rgba(0,0,0,.06); }
.mobile-tabbar a, .mobile-tabbar button { flex: 1; background: none; border: none; cursor: pointer;
    color: var(--muted); font-size: 10.5px; font-weight: 600; text-align: center; padding: 4px 0; }
.mobile-tabbar .ti { display: block; font-size: 21px; line-height: 1; margin-bottom: 2px; }
.mobile-tabbar a.active2 { color: var(--rose-600); }

/* Botão de ação flutuante (mobile) */
.fab-wrap { display: none; }
.fab { width: 54px; height: 54px; border-radius: 50%; border: none; cursor: pointer; color: #fff; font-size: 28px; line-height: 1;
    background: var(--plum-800); box-shadow: 0 8px 24px rgba(15,61,62,.4); transition: transform .2s; }
.fab-wrap.open .fab { transform: rotate(45deg); }
.fab-menu { position: absolute; bottom: 64px; right: 0; display: flex; flex-direction: column; gap: 8px; opacity: 0; pointer-events: none; transform: translateY(8px); transition: all .18s; }
.fab-menu.open { opacity: 1; pointer-events: auto; transform: none; }
.fab-menu button { white-space: nowrap; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 11px 16px; font-weight: 600; box-shadow: var(--shadow-sm); cursor: pointer; color: var(--text); }
@media (max-width: 900px) { .fab-wrap { display: block; position: fixed; right: 16px; bottom: 84px; z-index: 55; } }

/* ───── Responsivo ───── */
@media (max-width: 900px) {
    .sidebar { transform: translateX(-100%); transition: transform .25s; box-shadow: var(--shadow-lg); width: 280px; }
    .sidebar.open { transform: translateX(0); }
    .main { margin-left: 0; }
    .auth-wrap { grid-template-columns: 1fr; }
    .auth-art { display: none; }
    .nav-hamburger { display: inline-block; }
    .mobile-tabbar { display: flex; }
    .content { padding: 16px; padding-bottom: 84px; }
    .topbar { padding: 0 14px; height: 60px; }
    .topbar h1 { font-size: 17px; }
    .hide-mobile { display: none !important; }
    .dash-cols, .profile-cols, .week-grid { grid-template-columns: 1fr !important; }
    .card-pad { padding: 16px; }
}

/* Modais (overlay fixo): nunca passam da tela — rolagem interna, no desktop e mobile */
[style*="position:fixed"][style*="inset:0"] > .card,
[style*="position: fixed"][style*="inset: 0"] > .card {
    max-height: 92vh;
    overflow-y: auto;
}

/* ════════ Mobile responsivo — passe global ════════ */

/* Tablets/celulares: empilha QUALQUER grid de 2+ colunas e barras laterais fixas */
@media (max-width: 820px) {
    [style*="grid-template-columns:1fr 1fr"],
    [style*="grid-template-columns: 1fr 1fr"],
    [style*="grid-template-columns:1fr 1fr 1fr"],
    [style*="grid-template-columns:2fr 1fr"],
    [style*="grid-template-columns: 2fr 1fr"],
    [style*="grid-template-columns:1.4fr 1fr"],
    [style*="grid-template-columns:1.5fr 1fr"],
    [style*="grid-template-columns:repeat(2,"],
    [style*="grid-template-columns:repeat(3,"],
    [style*="grid-template-columns:repeat(4,"],
    [style*="grid-template-columns: repeat(2,"],
    [style*="grid-template-columns: repeat(3,"],
    [style*="grid-template-columns: repeat(4,"],
    [style*="320px 1fr"], [style*="340px 1fr"], [style*="360px 1fr"], [style*="300px 1fr"], [style*="280px 1fr"],
    [style*="240px 1fr"], [style*="260px 1fr"], [style*="220px 1fr"], [style*="200px 1fr"],
    [style*="1fr 320px"], [style*="1fr 340px"], [style*="1fr 360px"], [style*="1fr 300px"], [style*="1fr 280px"] {
        grid-template-columns: 1fr !important;
    }
    .kpi-grid { grid-template-columns: 1fr 1fr !important; }
}

/* Telas pequenas */
@media (max-width: 600px) {
    .kpi-grid { grid-template-columns: 1fr !important; }
    h1 { font-size: 17px; }
    .btn { padding: 9px 12px; }
    /* iOS não dá zoom em campos com fonte ≥16px */
    input, select, textarea { font-size: 16px !important; }
    /* evita rolagem horizontal da página inteira */
    html, body { overflow-x: hidden; max-width: 100%; }
    .content { padding: 14px; padding-bottom: 88px; }
}

/* Tabelas: rolagem horizontal própria no celular, mantendo colunas legíveis */
@media (max-width: 760px) {
    .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    /* a própria tabela rola e não deixa as colunas espremerem (nowrap) */
    .content table.data { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; white-space: nowrap; }
    .content table.data th, .content table.data td { padding: 11px 12px; }
    /* dentro de um wrapper que já rola, a tabela volta a ser table normal com piso de largura */
    .table-wrap table.data { display: table; width: 100%; min-width: 560px; white-space: normal; }

    /* Tabelas marcadas com .tcards: cada linha vira um CARTÃO (rótulo + valor) */
    .content table.data.tcards, .table-wrap table.data.tcards { display: block; min-width: 0; overflow: visible; white-space: normal; }
    .content table.data.tcards thead { display: none; }
    .content table.data.tcards tbody { display: block; }
    .content table.data.tcards tr { display: block; border: 1px solid var(--border); border-radius: 14px; padding: 4px 14px; margin-bottom: 10px; background: var(--surface); box-shadow: var(--shadow-sm); }
    .content table.data.tcards td { display: flex; justify-content: space-between; gap: 14px; align-items: center; padding: 9px 0; border: none; border-bottom: 1px solid var(--border); text-align: right; }
    .content table.data.tcards td:last-child { border-bottom: none; }
    .content table.data.tcards td::before { content: attr(data-label); color: var(--muted); font-weight: 700; font-size: 12px; text-align: left; white-space: nowrap; }
    .content table.data.tcards td[data-label=""]::before, .content table.data.tcards td.nolabel::before { display: none; }
    .content table.data.tcards td[data-label=""], .content table.data.tcards td.nolabel { justify-content: flex-end; }
    .content table.data.tcards td:empty { display: none; }
}

/* Modais viram "bottom sheet" no celular: largura cheia, presos embaixo, com rolagem */
@media (max-width: 600px) {
    [style*="position:fixed"][style*="inset:0"] > .card,
    [style*="position: fixed"][style*="inset: 0"] > .card {
        width: 100% !important;
        max-width: 100% !important;
        max-height: 90vh;
        overflow-y: auto;
        border-radius: 18px 18px 0 0 !important;
        position: fixed; left: 0; right: 0; bottom: 0; top: auto;
        animation: sheet-up .22s ease;
    }
    @keyframes sheet-up { from { transform: translateY(100%); } to { transform: none; } }
    /* botões de ação em linha quebram em vez de estourar */
    .card-pad > .flex.gap, .card-pad .flex.between { flex-wrap: wrap; }
}
