/* ============================================================
   Revio Web — design system (inspirado em Apple/macOS)
   ============================================================ */
:root {
    --primary: #185FA5;
    --primary-light: #E6F1FB;
    --primary-dark: #0C447C;
    --teal: #5FB5BC;
    --success: #1D9E75;
    --success-light: #E1F5EE;
    --warning: #EF9F27;
    --warning-light: #FAEEDA;
    --danger: #E24B4A;
    --danger-light: #FCEBEB;
    --purple: #3C3489;

    --text-primary: #1A1A18;
    --text-secondary: #6B6B67;
    --text-tertiary: #A8A8A3;

    --bg-page: #F5F5F2;
    --bg-card: #FFFFFF;
    --bg-secondary: #F0EFEB;
    --border: #E2E1DC;
    --separator: #EAEAE6;

    --radius-sm: 8px;
    --radius: 12px;
    --radius-lg: 16px;
    --shadow-sm: 0 1px 2px rgba(0,0,0,.04), 0 1px 3px rgba(0,0,0,.06);
    --shadow: 0 4px 16px rgba(0,0,0,.06), 0 1px 3px rgba(0,0,0,.04);
    --shadow-lg: 0 12px 40px rgba(0,0,0,.12);

    --topbar-h: 60px;
    --sidebar-w: 248px;

    --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display",
            "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    font-family: var(--font);
    color: var(--text-primary);
    background: var(--bg-page);
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
    font-size: 15px;
    line-height: 1.45;
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; }

/* ============================ Shell ============================ */
.app-shell {
    display: grid;
    grid-template-columns: var(--sidebar-w) 1fr;
    grid-template-rows: var(--topbar-h) 1fr;
    grid-template-areas:
        "brand topbar"
        "sidebar content";
    min-height: 100vh;
}

/* ============================ Topbar ============================ */
.topbar {
    grid-area: topbar;
    position: sticky;
    top: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    gap: 16px;
    height: var(--topbar-h);
    padding: 0 20px;
    background: rgba(255,255,255,.72);
    backdrop-filter: saturate(180%) blur(20px);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    border-bottom: 1px solid var(--separator);
}

.brand {
    grid-area: brand;
    position: sticky;
    top: 0;
    z-index: 51;
    display: flex;
    align-items: center;
    gap: 10px;
    height: var(--topbar-h);
    padding: 0 18px;
    background: rgba(255,255,255,.72);
    backdrop-filter: saturate(180%) blur(20px);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    border-bottom: 1px solid var(--separator);
    border-right: 1px solid var(--separator);
}
.brand img { height: 26px; width: auto; display: block; }

/* Busca global */
.search {
    position: relative;
    flex: 0 1 420px;
}
.search input {
    width: 100%;
    height: 38px;
    padding: 0 14px 0 38px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--bg-secondary);
    font-size: 14px;
    color: var(--text-primary);
    transition: border-color .15s, background .15s, box-shadow .15s;
}
.search input::placeholder { color: var(--text-tertiary); }
.search input:focus {
    outline: none;
    background: #fff;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}
.search .ico {
    position: absolute;
    left: 12px; top: 50%;
    transform: translateY(-50%);
    color: var(--text-tertiary);
    pointer-events: none;
}

.topbar-spacer { flex: 1; }

/* Navegação primária na barra superior (acesso rápido às principais áreas) */
.topnav { display: flex; align-items: center; gap: 2px; }
.topnav-link {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    height: 34px;
    padding: 0 12px;
    border: 0;
    border-radius: 9px;
    background: transparent;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
    text-decoration: none;
    cursor: pointer;
    white-space: nowrap;
    transition: background .15s, color .15s;
}
.topnav-link:hover { background: var(--bg-secondary); color: var(--text-primary); }
.topnav-link.active { background: var(--primary); color: #fff; }
.topnav-link.active svg { color: #fff; }
@media (max-width: 900px) { .topnav { display: none; } }

/* Hambúrguer (só no mobile) + overlay do drawer */
.hamburger {
    display: none;
    align-items: center;
    justify-content: center;
    width: 38px; height: 38px;
    border: 0; border-radius: 10px;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
}
.hamburger:hover { background: var(--bg-secondary); color: var(--text-primary); }
.nav-overlay { display: none; }
.nav-sections-mobile { display: none; }

/* Badge de contagem (Solicitações pendentes) */
.nav-badge { margin-left: auto; display: inline-flex; }
.nav-badge .badge-num {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 18px; height: 18px; padding: 0 5px;
    border-radius: 9px;
    background: var(--danger, #e5484d); color: #fff;
    font-size: 11px; font-weight: 700; line-height: 1;
}
.nav-item.active .nav-badge .badge-num { background: #fff; color: var(--primary); }

/* O bloco responsivo (@media max-width:820px) fica no FIM do arquivo, para vencer por
   ordem de origem as regras-base de .sidebar/.content/.app-shell (media query não soma
   especificidade — em empate, a última regra do arquivo vence). */

/* Ações do topo (ícones) */
.icon-btn {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px; height: 38px;
    border: none;
    border-radius: 10px;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--bg-secondary); color: var(--text-primary); }
.icon-btn .dot {
    position: absolute;
    top: 8px; right: 9px;
    width: 8px; height: 8px;
    border-radius: 50%;
    background: var(--danger);
    border: 2px solid rgba(255,255,255,.9);
}

/* Avatar / menu do usuário */
.user-trigger {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 4px 8px 4px 4px;
    border: none;
    border-radius: 999px;
    background: transparent;
    cursor: pointer;
    transition: background .15s;
}
.user-trigger:hover { background: var(--bg-secondary); }
.avatar {
    width: 32px; height: 32px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--teal));
    color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-weight: 600; font-size: 13px;
    flex: none;
}
.user-trigger .u-name { font-size: 14px; font-weight: 550; max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-trigger .u-org { font-size: 11px; color: var(--text-secondary); }

/* ============================ Dropdown ============================ */
.dropdown { position: relative; }
.menu {
    position: absolute;
    right: 0;
    top: calc(100% + 8px);
    min-width: 268px;
    background: rgba(255,255,255,.85);
    backdrop-filter: saturate(180%) blur(24px);
    -webkit-backdrop-filter: saturate(180%) blur(24px);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 6px;
    z-index: 60;
    transform-origin: top right;
}
.menu-header { padding: 10px 12px; }
.menu-header .h-name { font-weight: 600; font-size: 14px; }
.menu-header .h-email { font-size: 12px; color: var(--text-secondary); }
.menu-sep { height: 1px; background: var(--separator); margin: 6px 4px; border: 0; }
.menu-label { font-size: 11px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--text-tertiary); padding: 6px 12px 2px; }
.menu-item {
    display: flex; align-items: center; gap: 10px;
    width: 100%;
    padding: 9px 12px;
    border: none; background: transparent;
    border-radius: 8px;
    font-size: 14px; color: var(--text-primary);
    cursor: pointer;
    text-align: left;
    transition: background .12s;
}
.menu-item:hover { background: var(--primary-light); color: var(--primary-dark); }
.menu-item.danger:hover { background: var(--danger-light); color: var(--danger); }
.menu-item .ico { color: var(--text-secondary); flex: none; }
.menu-item:hover .ico { color: inherit; }
.menu-item .check { margin-left: auto; color: var(--primary); }

/* ============================ Sidebar ============================ */
.sidebar {
    grid-area: sidebar;
    position: sticky;
    top: var(--topbar-h);
    align-self: start;
    height: calc(100vh - var(--topbar-h));
    overflow-y: auto;
    background: rgba(250,250,248,.7);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-right: 1px solid var(--separator);
    padding: 14px 12px;
}
.nav-group { margin-bottom: 18px; }
.nav-group > .g-label {
    font-size: 11px; font-weight: 600;
    letter-spacing: .04em; text-transform: uppercase;
    color: var(--text-tertiary);
    padding: 0 12px 6px;
}
.nav-item {
    display: flex; align-items: center; gap: 11px;
    padding: 8px 12px;
    border-radius: 9px;
    color: var(--text-secondary);
    font-size: 14px; font-weight: 500;
    cursor: pointer;
    transition: background .12s, color .12s;
    margin-bottom: 1px;
}
.nav-item:hover { background: var(--bg-secondary); color: var(--text-primary); }
.nav-item.active { background: var(--primary); color: #fff; box-shadow: var(--shadow-sm); }
.nav-item.active .ico { color: #fff; }
.nav-item .ico { color: var(--text-tertiary); flex: none; }
.nav-item:hover .ico { color: var(--text-secondary); }

/* ============================ Content ============================ */
.content {
    grid-area: content;
    padding: 28px 32px 48px;
    max-width: 1280px;
    width: 100%;
}
.page-head {
    display: flex; align-items: flex-end; justify-content: space-between;
    gap: 16px; margin-bottom: 22px;
}
.page-title { font-size: 26px; font-weight: 700; letter-spacing: -.02em; margin: 0; }
.page-sub { color: var(--text-secondary); font-size: 14px; margin: 4px 0 0; }

/* Cards */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}
.card-pad { padding: 20px; }

.grid-kpi {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}
.kpi { display: flex; flex-direction: column; gap: 6px; }
.kpi .k-ico {
    width: 40px; height: 40px; border-radius: 11px;
    display: flex; align-items: center; justify-content: center;
    margin-bottom: 6px;
}
.kpi .k-val { font-size: 30px; font-weight: 700; letter-spacing: -.02em; line-height: 1; }
.kpi .k-label { font-size: 13px; color: var(--text-secondary); }

.tint-primary { background: var(--primary-light); color: var(--primary); }
.tint-success { background: var(--success-light); color: var(--success); }
.tint-warning { background: var(--warning-light); color: var(--warning); }
.tint-danger  { background: var(--danger-light);  color: var(--danger); }
.tint-neutral { background: var(--bg-secondary);   color: var(--text-secondary); }

.cols-2 { display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; }
@media (max-width: 1000px) { .cols-2 { grid-template-columns: 1fr; } }

.section-title { font-size: 15px; font-weight: 650; margin: 0 0 2px; }
.card-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--separator); }

/* Tabela */
.table { width: 100%; border-collapse: collapse; }
.table th {
    text-align: left;
    font-size: 11px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase;
    color: var(--text-tertiary);
    padding: 10px 20px;
    border-bottom: 1px solid var(--separator);
}
.table td { padding: 12px 20px; border-bottom: 1px solid var(--separator); font-size: 14px; }
.table tbody tr { transition: background .12s; cursor: pointer; }
.table tbody tr:hover { background: var(--bg-secondary); }
.table tbody tr:last-child td { border-bottom: none; }

.cell-name { display: flex; align-items: center; gap: 11px; }
.cell-name .avatar { width: 34px; height: 34px; font-size: 13px; }
.cell-name .n { font-weight: 550; }
.cell-name .s { font-size: 12px; color: var(--text-secondary); }

/* Badges / chips */
.badge {
    display: inline-flex; align-items: center; gap: 5px;
    font-size: 12px; font-weight: 550;
    padding: 3px 9px; border-radius: 999px;
}
.chip { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 6px; background: var(--bg-secondary); color: var(--text-secondary); margin: 2px 2px 0 0; }

/* Botões */
.btn {
    display: inline-flex; align-items: center; gap: 8px;
    height: 38px; padding: 0 16px;
    border: 1px solid transparent;
    border-radius: 10px;
    font-size: 14px; font-weight: 600;
    cursor: pointer;
    transition: filter .15s, background .15s, border-color .15s;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { filter: brightness(1.07); }
.btn-ghost { background: #fff; color: var(--text-primary); border-color: var(--border); }
.btn-ghost:hover { background: var(--bg-secondary); }

/* Estado vazio */
.empty { text-align: center; padding: 56px 20px; color: var(--text-secondary); }
.empty .e-ico { color: var(--text-tertiary); margin-bottom: 12px; }

/* HTMX: indicador de carregamento + transição suave */
.htmx-indicator { opacity: 0; transition: opacity .2s; }
.htmx-request .htmx-indicator { opacity: 1; }
.htmx-request.htmx-indicator { opacity: 1; }
#content-fade.htmx-swapping { opacity: 0; transition: opacity .12s; }
#content-fade { opacity: 1; transition: opacity .18s; }

.top-progress {
    position: fixed; top: 0; left: 0; height: 2px; width: 100%;
    background: linear-gradient(90deg, var(--primary), var(--teal));
    transform: scaleX(0); transform-origin: left;
    z-index: 100; opacity: 0;
}
.htmx-request ~ .top-progress,
body.htmx-request .top-progress { opacity: 1; animation: load 1s ease-in-out infinite; }
@keyframes load { 0%{transform:scaleX(.1)} 50%{transform:scaleX(.7)} 100%{transform:scaleX(1)} }

/* Busca interna (página) */
.toolbar { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.field {
    position: relative; flex: 0 1 320px;
}
.field input {
    width: 100%; height: 38px; padding: 0 12px 0 36px;
    border: 1px solid var(--border); border-radius: 10px; background: #fff; font-size: 14px;
}
.field input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light); }
.field .ico { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--text-tertiary); }

/* ============================ Login (tema claro) ============================ */
.auth-body {
    margin: 0; min-height: 100vh;
    background: radial-gradient(1200px 600px at 50% -10%, #e8f1fb 0%, #f6f7f9 60%);
    display: flex; align-items: center; justify-content: center;
    padding: 24px;
}
.auth-card {
    width: 100%; max-width: 400px;
    background: #fff; border: 1px solid #e5e7eb; border-radius: 18px;
    box-shadow: 0 10px 40px rgba(15, 35, 65, .08);
    padding: 32px 28px;
}
.auth-logo { display: block; margin: 0 auto 14px; height: 60px; }
.auth-tag { text-align: center; color: #6b7280; font-size: 13px; margin-bottom: 30px; }
.auth-field { margin-bottom: 12px; }
.auth-field label {
    display: block; font-size: 11px; font-weight: 600; letter-spacing: .05em;
    text-transform: uppercase; color: #6b7280; margin-bottom: 6px;
}
.auth-field input {
    width: 100%; height: 48px; padding: 0 14px;
    background: #fff; border: 1px solid #d1d5db; border-radius: 12px;
    color: #111827; font-size: 15px;
    transition: border-color .15s, box-shadow .15s;
}
.auth-field input::placeholder { color: #9ca3af; }
.auth-field input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(24,95,165,.15); }
.auth-btn {
    width: 100%; height: 48px; border: none; border-radius: 12px;
    background: var(--primary); color: #fff; font-size: 15px; font-weight: 600;
    cursor: pointer; transition: filter .15s; margin-top: 6px;
}
.auth-btn:hover { filter: brightness(1.08); }
.auth-error {
    background: #fef2f2; border: 1px solid #fecaca;
    color: #b91c1c; font-size: 13px; padding: 10px 12px; border-radius: 10px; margin-bottom: 14px;
}
.auth-sep { display: flex; align-items: center; gap: 12px; margin: 22px 0 14px; color: #9ca3af; font-size: 12px; }
.auth-sep::before, .auth-sep::after { content: ""; flex: 1; height: 1px; background: #e5e7eb; }
.auth-social {
    width: 100%; height: 48px; border-radius: 12px; font-size: 15px; font-weight: 600;
    cursor: pointer; margin-bottom: 10px; border: 1px solid #d1d5db;
    background: #fff; color: #1f2937; text-decoration: none;
    display: flex; align-items: center; justify-content: center; gap: 10px;
    transition: background .15s;
}
.auth-social:hover { background: #f9fafb; }
.auth-version { text-align: center; color: #9ca3af; font-size: 12px; margin-top: 30px; }
.auth-switch { text-align: center; color: #6b7280; font-size: 13px; margin-top: 18px; }
.auth-switch a { color: var(--primary); text-decoration: none; font-weight: 600; }
.auth-switch a:hover { text-decoration: underline; }

/* ============================ Detalhe do paciente ============================ */
.back-link {
    display: inline-flex; align-items: center; gap: 6px;
    font-size: 13px; font-weight: 600; color: var(--text-secondary);
    margin-bottom: 14px; cursor: pointer;
}
.back-link:hover { color: var(--primary); }

.detail-head { display: flex; gap: 18px; align-items: flex-start; padding: 22px; }
.detail-avatar {
    width: 64px; height: 64px; border-radius: 18px; flex: none;
    background: linear-gradient(135deg, var(--primary), var(--teal));
    color: #fff; display: flex; align-items: center; justify-content: center;
    font-size: 23px; font-weight: 650;
}
.detail-name { font-size: 22px; font-weight: 700; letter-spacing: -.01em; margin: 0; }
.detail-tags { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.detail-facts { display: flex; flex-wrap: wrap; gap: 18px 28px; margin-top: 14px; }
.fact .f-label { font-size: 11px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--text-tertiary); }
.fact .f-value { font-size: 14px; font-weight: 500; margin-top: 2px; }

.detail-cols { display: grid; grid-template-columns: 1fr 320px; gap: 16px; align-items: start; margin-top: 16px; }
@media (max-width: 1040px) { .detail-cols { grid-template-columns: 1fr; } }

.info-list { padding: 6px 0; }
.info-row { display: flex; justify-content: space-between; gap: 12px; padding: 10px 20px; font-size: 14px; border-bottom: 1px solid var(--separator); }
.info-row:last-child { border-bottom: none; }
.info-row .k { color: var(--text-secondary); }
.info-row .v { font-weight: 550; text-align: right; }
.chips-wrap { padding: 6px 20px 16px; display: flex; flex-wrap: wrap; gap: 6px; }
.chip-danger { background: var(--danger-light); color: var(--danger); }
.chip-warning { background: var(--warning-light); color: #b9791a; }

/* Linha do tempo */
.timeline { position: relative; padding: 8px 20px 20px 20px; }
.timeline::before {
    content: ""; position: absolute; left: 33px; top: 14px; bottom: 14px;
    width: 2px; background: var(--separator);
}
.tl-item { position: relative; padding-left: 38px; margin-bottom: 16px; }
.tl-item:last-child { margin-bottom: 0; }
.tl-dot {
    position: absolute; left: 6px; top: 4px;
    width: 26px; height: 26px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    border: 3px solid var(--bg-card); box-shadow: 0 0 0 1px var(--border);
    z-index: 1;
}
.tl-time { font-size: 12px; color: var(--text-secondary); margin-bottom: 6px; font-weight: 550; }
.tl-card {
    border: 1px solid var(--border); border-radius: var(--radius);
    background: var(--bg-card); box-shadow: var(--shadow-sm);
    overflow: hidden;
}
.tl-card-head { display: flex; align-items: center; gap: 10px; padding: 13px 16px; cursor: pointer; }
.tl-card-head:hover { background: var(--bg-secondary); }
.tl-card-title { font-weight: 600; font-size: 14px; }
.tl-card-body { padding: 4px 16px 16px; border-top: 1px solid var(--separator); }
.tl-chevron { margin-left: auto; color: var(--text-tertiary); transition: transform .18s; }
.tl-chevron.open { transform: rotate(180deg); }

.tl-mini { padding: 12px 16px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg-card); display: flex; align-items: center; gap: 10px; box-shadow: var(--shadow-sm); }

.soap-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 12px; }
@media (max-width: 760px) { .soap-grid { grid-template-columns: 1fr; } }
.soap-block { background: var(--bg-secondary); border-radius: 10px; padding: 11px 13px; }
.soap-block .s-label { font-size: 11px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--primary); margin-bottom: 4px; }
.soap-block .s-text { font-size: 13.5px; color: var(--text-primary); white-space: pre-wrap; }
.rx-line { margin-top: 12px; }
.rx-line .r-label { font-size: 11px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--text-tertiary); margin-bottom: 4px; }
.transcricao-box {
    font-size: 13.5px; color: var(--text-primary);
    background: var(--bg-secondary); border-radius: 10px; padding: 11px 13px;
    white-space: pre-wrap; max-height: 66px; overflow: hidden; transition: max-height .2s ease;
}
.transcricao-box.expandida { max-height: 1200px; }
.link-btn { background: none; border: none; color: var(--primary); font-size: 13px; font-weight: 600; cursor: pointer; padding: 6px 0 0; }
.link-btn:hover { text-decoration: underline; }
.file-input { font-size: 13px; max-width: 280px; }
.file-input::file-selector-button {
    font: inherit; font-size: 13px; font-weight: 600;
    border: 1px solid var(--border); background: #fff; color: var(--text-primary);
    border-radius: 8px; padding: 7px 12px; margin-right: 10px; cursor: pointer;
}
.file-input::file-selector-button:hover { background: var(--bg-secondary); }

/* Documentos do prontuário */
.doc-upload { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 16px 20px; border-bottom: 1px solid var(--separator); }
.doc-cat { height: 38px; padding: 0 10px; border: 1px solid var(--border); border-radius: 10px; background: #fff; font-size: 14px; font-family: inherit; }
.doc-cat:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light); }
.doc-list { display: flex; flex-direction: column; }
.doc-item { display: flex; align-items: center; gap: 13px; padding: 12px 20px; border-bottom: 1px solid var(--separator); }
.doc-item:last-child { border-bottom: none; }
.doc-item:hover { background: var(--bg-secondary); }
.doc-ico { width: 38px; height: 38px; border-radius: 10px; display: flex; align-items: center; justify-content: center; flex: none; }
.doc-meta { flex: 1; min-width: 0; }
.doc-nome { font-weight: 550; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-sub { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }
.doc-btn { height: 32px; padding: 0 14px; font-size: 13px; }
.doc-del { width: 34px; height: 34px; color: var(--text-tertiary); }
.doc-del:hover { background: var(--danger-light); color: var(--danger); }

/* ============================ Chat de IA ============================ */
.chat-wrap { display: flex; flex-direction: column; height: calc(100vh - 230px); min-height: 420px; }
#chat-msgs { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 12px; }
.chat-row { display: flex; }
.chat-row.user { justify-content: flex-end; }
.chat-bubble {
    max-width: 78%; padding: 11px 14px; border-radius: 16px; font-size: 14px; line-height: 1.5;
    white-space: pre-wrap; word-wrap: break-word;
}
.chat-bubble.user { background: var(--primary); color: #fff; border-bottom-right-radius: 5px; }
.chat-bubble.bot { background: var(--bg-secondary); color: var(--text-primary); border-bottom-left-radius: 5px; }
.chat-empty { margin: auto; text-align: center; color: var(--text-tertiary); font-size: 14px; }
.chat-typing { padding: 0 20px 8px; font-size: 13px; color: var(--text-secondary); }
.chat-form { display: flex; gap: 10px; padding: 14px 16px; border-top: 1px solid var(--separator); align-items: flex-end; }
.chat-form textarea {
    flex: 1; min-height: 44px; max-height: 140px; resize: none; padding: 11px 13px;
    border: 1px solid var(--border); border-radius: 12px; font-family: inherit; font-size: 14px; line-height: 1.4;
}
.chat-form textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light); }
.chat-send { width: 44px; height: 44px; border-radius: 12px; border: none; background: var(--primary); color: #fff; cursor: pointer; flex: none; display: flex; align-items: center; justify-content: center; }
.chat-send:hover { filter: brightness(1.08); }

/* ============================ Estudos / oráculo ============================ */
.oraculo-resposta { white-space: pre-wrap; word-wrap: break-word; font-size: 14px; line-height: 1.55; color: var(--text-primary); }
.citacao { padding: 9px 0; border-bottom: 1px solid var(--separator); font-size: 13px; }
.citacao:last-child { border-bottom: none; }

/* ============================ Formulário ============================ */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; padding: 22px; }
@media (max-width: 720px) { .form-grid { grid-template-columns: 1fr; } }
.form-field.col-2 { grid-column: 1 / -1; }
.form-field label { display: block; font-size: 12px; font-weight: 600; color: var(--text-secondary); margin-bottom: 6px; }
.form-field input, .form-field select, .form-field textarea {
    width: 100%; height: 42px; padding: 0 12px;
    border: 1px solid var(--border); border-radius: 10px; background: #fff;
    font-size: 14px; font-family: inherit; color: var(--text-primary);
    transition: border-color .15s, box-shadow .15s;
}
.form-field textarea { height: auto; min-height: 64px; padding: 10px 12px; resize: vertical; line-height: 1.4; }
.form-field input:focus, .form-field select:focus, .form-field textarea:focus {
    outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light);
}
.form-field .hint { font-size: 12px; color: var(--text-tertiary); margin-top: 5px; }
.req { color: var(--danger); }
.form-actions { display: flex; align-items: center; gap: 10px; padding: 16px 22px; border-top: 1px solid var(--separator); }
.form-actions .spacer { flex: 1; }
.btn-danger { background: #fff; color: var(--danger); border-color: var(--border); }
.btn-danger:hover { background: var(--danger-light); border-color: var(--danger); }
.alert-error {
    margin: 18px 22px 0; background: var(--danger-light);
    border: 1px solid rgba(226,75,74,.3); color: #a3302f;
    padding: 10px 14px; border-radius: 10px; font-size: 14px;
}

/* ============================ Agenda / calendário ============================ */
.agenda-cols { display: grid; grid-template-columns: 360px 1fr; gap: 16px; align-items: start; }
@media (max-width: 1040px) { .agenda-cols { grid-template-columns: 1fr; } }

.cal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px 8px; }
.cal-title { font-size: 15px; font-weight: 650; text-transform: capitalize; }
.cal-nav { display: flex; gap: 4px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); grid-auto-rows: 40px; gap: 3px; padding: 4px 14px 16px; }
.cal-dow { display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 600; color: var(--text-tertiary); text-transform: uppercase; }
.cal-day {
    display: flex; align-items: center; justify-content: center;
    border-radius: 9px; font-size: 13.5px; cursor: pointer; color: var(--text-primary);
    transition: background .12s;
}
.cal-day:hover { background: var(--bg-secondary); }
.cal-day.empty { cursor: default; }
.cal-day.today { color: var(--primary); font-weight: 700; box-shadow: inset 0 0 0 1.5px var(--primary); }
.cal-day.sel { background: var(--primary); color: #fff; font-weight: 650; box-shadow: none; }
.cal-day.sel:hover { background: var(--primary); }

.dia-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--separator); }
.dia-title { font-size: 16px; font-weight: 650; text-transform: capitalize; }
.slot { display: flex; gap: 14px; padding: 14px 20px; border-bottom: 1px solid var(--separator); }
.slot:last-child { border-bottom: none; }
.slot-time { width: 58px; flex: none; font-weight: 650; color: var(--primary-dark); }
.slot-time .dur { display: block; font-size: 11px; color: var(--text-tertiary); font-weight: 500; }
.slot-body { flex: 1; display: flex; align-items: center; gap: 11px; }
.slot-body .n { font-weight: 550; }
.slot-body .t { font-size: 12px; color: var(--text-secondary); }

/* SOAP no formulário de consulta */
.soap-form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 720px) { .soap-form-grid { grid-template-columns: 1fr; } }
.soap-form-grid .form-field.col-2 { grid-column: 1 / -1; }
.soap-tag {
    display: inline-flex; align-items: center; justify-content: center;
    width: 18px; height: 18px; border-radius: 5px; margin-right: 6px;
    background: var(--primary-light); color: var(--primary);
    font-size: 11px; font-weight: 700;
}

/* Gráficos embutidos pela IA (chat/oráculo) */
.revio-chart {
    position: relative;
    height: 240px;
    margin-top: 12px;
    background: #fff;
    border: 1px solid #E2E1DC;
    border-radius: 10px;
    padding: 10px;
}
.chat-bubble .revio-chart { background: #fff; }

/* Conteúdo rico renderizado da IA (markdown/tabelas/esquemas) */
.rich > *:first-child { margin-top: 0; }
.rich > *:last-child { margin-bottom: 0; }
.rich h1, .rich h2, .rich h3 { margin: 10px 0 6px; line-height: 1.25; font-weight: 650; }
.rich h1 { font-size: 19px; } .rich h2 { font-size: 17px; } .rich h3 { font-size: 15px; }
.rich p { margin: 6px 0; }
.rich ul, .rich ol { margin: 6px 0; padding-left: 20px; }
.rich li { margin: 2px 0; }
.rich code { background: #F0EFEB; padding: 1px 5px; border-radius: 5px; font-size: 13px; }
.rich pre { background: #F5F5F2; border: 1px solid #E2E1DC; border-radius: 8px; padding: 10px; overflow-x: auto; }
.rich pre code { background: none; padding: 0; }
.rich blockquote { margin: 6px 0; padding: 4px 12px; border-left: 3px solid #185FA5; color: #6B6B67; }
.rich table { border-collapse: collapse; width: 100%; margin: 8px 0; font-size: 13px; }
.rich th, .rich td { border: 1px solid #E2E1DC; padding: 6px 9px; text-align: left; vertical-align: top; }
.rich thead th { background: #E6F1FB; color: #0C447C; font-weight: 600; }
.rich tbody tr:nth-child(even) { background: #FAFAF8; }
.rich .mermaid { background: #fff; border: 1px solid #E2E1DC; border-radius: 10px; padding: 12px; margin: 10px 0; text-align: center; overflow-x: auto; }
.rich .mermaid-erro { font-family: monospace; font-size: 12px; white-space: pre-wrap; text-align: left; color: #E24B4A; }

/* Coleta por WhatsApp — itens + conversa */
[x-cloak] { display: none !important; }
.intake-item { border-top: 1px solid var(--border-color, #E2E1DC); padding: 12px 0; }
.intake-item:first-child { border-top: 0; }
.intake-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.intake-toggle { font-size: 13px; padding: 4px 0; color: #185FA5; }
.intake-conversa { margin-top: 8px; max-height: 340px; overflow-y: auto; padding: 4px 2px; display: flex; flex-direction: column; gap: 6px; }
.wa-row { display: flex; }
.wa-row.paciente { justify-content: flex-end; }
.wa-row.ia { justify-content: flex-start; }
.wa-bubble { max-width: 78%; padding: 7px 11px; border-radius: 12px; font-size: 14px; line-height: 1.4; white-space: pre-wrap; word-wrap: break-word; }
.wa-bubble.paciente { background: #DCF8C6; border-bottom-right-radius: 4px; }
.wa-bubble.ia { background: #F0EFEB; border-bottom-left-radius: 4px; }
.wa-autor { font-size: 10px; font-weight: 600; color: var(--text-tertiary, #A8A8A3); margin-bottom: 2px; }

/* ── Chat WhatsApp (aba do paciente) ── */
.wa-chat { display: flex; flex-direction: column; height: calc(100vh - 200px); min-height: 460px; overflow: hidden; padding: 0; }
.wa-head { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--border, #ECEAE4); background: #F7F6F2; flex: 0 0 auto; }
.wa-head-info { min-width: 0; }
.wa-head-nome { font-weight: 600; font-size: 15px; color: var(--text-primary, #1A1A18); }
.wa-head-sub { font-size: 12px; color: var(--text-secondary, #6B6B67); }
.wa-head-badge { margin-left: auto; font-size: 12px; white-space: nowrap; }
.wa-thread {
    flex: 1 1 auto; overflow-y: auto; padding: 16px 18px;
    display: flex; flex-direction: column; gap: 4px;
    background: #EFE7DE url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='40'%3E%3Ccircle cx='3' cy='3' r='1' fill='%23000' opacity='0.02'/%3E%3C/svg%3E");
}
.wa-day { text-align: center; margin: 8px 0; }
.wa-day span { background: #fff; color: var(--text-secondary, #6B6B67); font-size: 11px; font-weight: 600; padding: 3px 10px; border-radius: 10px; box-shadow: 0 1px 2px rgba(0,0,0,.06); }
.wa-row.in { justify-content: flex-start; }
.wa-row.out { justify-content: flex-end; }
.wa-bubble.in { background: #fff; border-bottom-left-radius: 4px; box-shadow: 0 1px 1px rgba(0,0,0,.06); }
.wa-bubble.out { background: #D9FDD3; border-bottom-right-radius: 4px; box-shadow: 0 1px 1px rgba(0,0,0,.06); }
.wa-bubble { position: relative; display: inline-flex; flex-direction: column; gap: 3px; }
.wa-text { white-space: pre-wrap; word-wrap: break-word; }
.wa-time { align-self: flex-end; font-size: 10px; color: var(--text-tertiary, #9A9A95); margin-top: 1px; }
.wa-cap { white-space: pre-wrap; word-wrap: break-word; }
.wa-img { display: block; max-width: 260px; max-height: 320px; border-radius: 8px; cursor: pointer; object-fit: cover; }
.wa-video { display: block; max-width: 280px; max-height: 320px; border-radius: 8px; background: #000; }
.wa-audio { display: block; max-width: 240px; }
.wa-doc { display: flex; align-items: center; gap: 10px; min-width: 200px; max-width: 280px; text-decoration: none; color: inherit; padding: 4px 2px; }
.wa-doc-ico { flex: 0 0 auto; width: 40px; height: 40px; border-radius: 8px; display: grid; place-items: center; background: rgba(0,0,0,.05); color: var(--primary, #185FA5); }
.wa-doc-info { display: flex; flex-direction: column; min-width: 0; }
.wa-doc-nome { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wa-doc-meta { font-size: 11px; color: var(--text-secondary, #6B6B67); }
.wa-empty { flex: 1 1 auto; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; color: var(--text-secondary, #6B6B67); text-align: center; }
.wa-empty svg { color: var(--text-tertiary, #B8B8B3); margin-bottom: 4px; }
.wa-erro { background: rgba(226,75,74,.1); color: var(--danger, #E24B4A); font-size: 13px; padding: 8px 12px; border-radius: 8px; margin-bottom: 8px; align-self: center; }
.wa-compose { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-top: 1px solid var(--border, #ECEAE4); background: #F7F6F2; flex: 0 0 auto; }
.wa-input { flex: 1 1 auto; border-radius: 22px; }
.wa-input:disabled { background: #F0EFEB; cursor: not-allowed; }
.wa-send { flex: 0 0 auto; width: 42px; height: 42px; border-radius: 50%; border: none; background: var(--primary, #185FA5); color: #fff; display: grid; place-items: center; cursor: pointer; }
.wa-send:disabled { background: #C9C7C1; cursor: not-allowed; }
.wa-send:not(:disabled):hover { filter: brightness(1.05); }

/* ── Insights da IA (paciente) ── */
.insight-resumo { font-size: 14.5px; line-height: 1.6; color: var(--text-primary, #1A1A18); white-space: pre-wrap; }
.insight-alertas { display: flex; flex-direction: column; gap: 8px; }
.insight-alerta { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border: 1px solid var(--border, #ECEAE4); border-radius: var(--radius, 12px); background: #FCFBF9; }
.insight-alerta .ia-titulo { font-size: 13.5px; font-weight: 600; color: var(--text-primary, #1A1A18); }
.insight-alerta .ia-detalhe { font-size: 13px; color: var(--text-secondary, #6B6B67); margin-top: 2px; line-height: 1.5; }

/* ── Combobox pesquisável (paciente) ── */
.combo { position: relative; }
.combo-input { width: 100%; }
.combo-results { position: absolute; z-index: 50; left: 0; right: 0; top: calc(100% + 4px);
    background: #fff; border: 1px solid var(--border, #e5e7eb); border-radius: 10px;
    box-shadow: 0 12px 32px rgba(0,0,0,.14); max-height: 280px; overflow-y: auto; }
.combo-results:empty { display: none; }
.combo-opt, .combo-novo { display: block; width: 100%; text-align: left; background: transparent;
    border: none; padding: 9px 12px; cursor: pointer; font-size: 13.5px; color: var(--text-primary, #111827); }
.combo-opt:hover, .combo-novo:hover { background: var(--bg-secondary, #f3f4f6); }
.combo-opt .combo-nome { font-weight: 500; }
.combo-opt .combo-cpf { color: var(--text-tertiary, #9ca3af); font-size: 12px; margin-left: 8px; }
.combo-novo { color: #2563eb; font-weight: 600; border-top: 1px solid var(--border, #e5e7eb); }
.combo-empty { padding: 11px 12px; color: var(--text-tertiary, #9ca3af); font-size: 13px; }

/* ── Responsivo: drawer mobile (NO FIM do arquivo p/ vencer as regras-base por ordem) ── */
@media (max-width: 820px) {
    .app-shell {
        grid-template-columns: 1fr;
        grid-template-rows: var(--topbar-h) 1fr;
        grid-template-areas: "topbar" "content";
    }
    .brand { display: none; }
    .sidebar {
        position: fixed; left: 0; top: var(--topbar-h);
        width: 270px; max-width: 82vw;
        height: calc(100vh - var(--topbar-h));
        transform: translateX(-100%);
        transition: transform .24s ease;
        z-index: 60;
        box-shadow: 0 10px 40px rgba(0,0,0,.18);
    }
    .app-shell.nav-open .sidebar { transform: translateX(0); }
    .nav-overlay {
        display: block;
        position: fixed; inset: var(--topbar-h) 0 0 0;
        background: rgba(0,0,0,.34);
        z-index: 55;
    }
    .hamburger { display: inline-flex; }
    .nav-sections-mobile { display: block; }
    .content { padding: 18px 16px 40px; max-width: none; }

    /* Topbar enxuta no celular: ☰ | busca (cresce) | 🔔 | avatar (sem nome/org) */
    .topbar { padding: 0 12px; gap: 8px; }
    .topbar-spacer { display: none; }
    .search { flex: 1 1 auto; min-width: 0; }
    .user-trigger > span:not(.avatar) { display: none; }
    .user-trigger > svg { display: none; }
}

/* ── Prescrições: linhas dinâmicas de medicamento + typeahead do bulário ── */
.rx-row { margin-bottom: 10px; }
.rx-grid { display: grid; grid-template-columns: 2fr 1.4fr 1fr 1.1fr 32px; gap: 6px; align-items: center; }
.rx-row input, .rx-row select {
    height: 36px; padding: 0 10px; border: 1px solid var(--border, #d1d5db);
    border-radius: 8px; background: #fff; font-size: 13.5px; width: 100%;
}
.rx-row .rx-ori { margin-top: 6px; }
.rx-del {
    height: 32px; width: 32px; border: 0; border-radius: 8px; background: transparent;
    color: var(--text-tertiary, #9ca3af); font-size: 20px; line-height: 1; cursor: pointer;
}
.rx-del:hover { background: var(--danger-light, #fdecec); color: var(--danger, #e5484d); }
.rx-ac {
    position: absolute; z-index: 80; display: none; background: #fff;
    border: 1px solid var(--border, #d1d5db); border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0,0,0,.14); max-height: 280px; overflow: auto;
}
.rx-ac-opt {
    display: flex; flex-direction: column; align-items: flex-start; width: 100%;
    text-align: left; border: 0; background: transparent; padding: 8px 11px; cursor: pointer;
}
.rx-ac-opt:hover { background: var(--bg-secondary, #f3f4f6); }
.rx-ac-nome { font-weight: 500; font-size: 13.5px; }
.rx-ac-pa { font-size: 12px; color: var(--text-tertiary, #9ca3af); }
@media (max-width: 720px) {
    .rx-grid { grid-template-columns: 1fr 1fr; }
    .rx-grid .rx-del { grid-column: 2; justify-self: end; }
}

/* ── Hub Coretax: cards dos módulos ── */
.coretax-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.coretax-card {
    display: flex; flex-direction: column; gap: 4px;
    padding: 18px; border: 1px solid var(--separator); border-radius: 14px;
    background: #fff; text-decoration: none; color: var(--text-primary); cursor: pointer;
    transition: border-color .15s, box-shadow .15s;
}
.coretax-card:hover { border-color: var(--primary); box-shadow: var(--shadow-sm); }
.coretax-card .cx-ico { color: var(--primary); margin-bottom: 6px; }
.coretax-card .cx-label { font-weight: 600; font-size: 15px; }
.coretax-card .cx-desc { font-size: 12.5px; color: var(--text-secondary); }

/* ── Gravação do atendimento (consulta) ── */
.rec-box { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.rec-box .rec-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: #fff; margin-right: 8px; vertical-align: middle; }
.rec-box .btn.rec-on { background: var(--danger, #e5484d); }
.rec-box .btn.rec-on .rec-dot { background: #fff; animation: recPulse 1s ease-in-out infinite; }
@keyframes recPulse { 0%,100% { opacity: 1; } 50% { opacity: .35; } }
.rec-timer { font-variant-numeric: tabular-nums; font-size: 15px; font-weight: 600; color: var(--text-secondary); min-width: 48px; }
.rec-status { font-size: 13px; color: var(--text-secondary); }
