/* ═══════════════════════════════════════════════════════════════
   NEXUS · APP SHELL (refatoração)
   Rail de ícones + painel contextual colapsável + workspace.
   Estende os tokens de base.css. Mantém a marca monocromática.
   ═══════════════════════════════════════════════════════════════ */

:root {
    --rail-w: 78px;
    --panel-w: 300px;
    --topbar-h: 64px;
    --botnav-h: 60px;
    /* accent dinâmico (Tweak) · por padrão branco da marca */
    --brand: var(--acc);
    --brand-soft: var(--acc-soft);
    --brand-glow: var(--acc-glow);
}

/* densidade compacta (Tweak) */
body[data-density="compact"] {
    --panel-w: 270px;
    --topbar-h: 56px;
}

/* ── App shell ─────────────────────────────────────── */
.app-shell {
    display: flex;
    height: 100vh; height: 100dvh;
    width: 100%;
    overflow: hidden;
    background: var(--bg);
}

/* ═══════════════════════════════════════════════════
   RAIL DE ÍCONES
   ═══════════════════════════════════════════════════ */
.rail {
    width: var(--rail-w);
    min-width: var(--rail-w);
    height: 100vh; height: 100dvh;
    background: var(--bg-2);
    border-right: 1px solid var(--line-soft);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 16px 0 14px;
    gap: 10px;
    z-index: 70;
    position: relative;
}

.rail-logo {
    width: 46px;
    height: 46px;
    display: grid;
    place-items: center;
    border-radius: 14px;
    background: radial-gradient(120% 120% at 30% 20%, var(--surface), var(--bg-2));
    border: 1px solid var(--line-soft);
    overflow: hidden;
    position: relative;
}
.rail-logo img { width: 30px; height: auto; display: block; }
.rail-logo::after {
    content: "";
    position: absolute; left: 6px; right: 6px; height: 1.5px;
    background: var(--brand);
    box-shadow: 0 0 8px var(--brand);
    opacity: 0.5;
    animation: railScan 3.4s var(--ease) infinite;
}
@keyframes railScan {
    0%, 100% { top: 9px; opacity: 0.2; }
    50%      { top: 34px; opacity: 0.7; }
}

.rail-nav {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    margin-top: 10px;
    width: 100%;
}

.rail-item {
    position: relative;
    width: 50px;
    height: 46px;
    display: grid;
    place-items: center;
    border-radius: 14px;
    color: var(--faint);
    background: transparent;
    border: none;
    cursor: pointer;
    transition: color var(--transition), background var(--transition);
}
.rail-item svg { width: 21px; height: 21px; stroke-width: 1.8; }
.rail-item:hover { color: var(--fg); background: var(--surface); }
.rail-item.active { color: var(--fg); background: var(--brand-soft); }
.rail-item.active::before {
    content: "";
    position: absolute;
    left: -16px;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 22px;
    border-radius: 0 3px 3px 0;
    background: var(--brand);
    box-shadow: 0 0 10px var(--brand-glow);
}

/* tooltip no hover */
.rail-item .tip {
    position: absolute;
    left: calc(100% + 14px);
    top: 50%;
    transform: translateY(-50%) translateX(-4px);
    white-space: nowrap;
    background: var(--surface-2);
    border: 1px solid var(--line);
    color: var(--fg);
    font-family: var(--font-mono);
    font-size: 0.66rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    padding: 7px 11px;
    border-radius: 9px;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition), transform var(--transition);
    z-index: 90;
    box-shadow: var(--shadow);
}
.rail-item:hover .tip { opacity: 1; transform: translateY(-50%) translateX(0); }

.rail-item .badge-dot {
    position: absolute;
    top: 9px; right: 12px;
    width: 6px; height: 6px;
    border-radius: 50%;
    background: var(--brand);
    box-shadow: 0 0 0 2px var(--bg-2);
}

.rail-sep {
    width: 30px;
    height: 1px;
    background: var(--line-soft);
    margin: 4px 0;
}

.rail-foot {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    width: 100%;
}

.rail-avatar {
    width: 40px; height: 40px;
    border-radius: 12px;
    background: var(--brand);
    color: var(--on-acc);
    display: grid;
    place-items: center;
    font-family: var(--font-mono);
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
    border: none;
    position: relative;
    transition: transform var(--transition), box-shadow var(--transition);
}
.rail-avatar:hover { transform: translateY(-1px); box-shadow: var(--shadow-cta); }
.rail-avatar .tip {
    position: absolute;
    left: calc(100% + 14px); top: 50%;
    transform: translateY(-50%) translateX(-4px);
    white-space: nowrap;
    background: var(--surface-2); border: 1px solid var(--line);
    color: var(--fg); font-family: var(--font-mono); font-size: 0.66rem;
    letter-spacing: 0.08em; padding: 7px 11px; border-radius: 9px;
    opacity: 0; pointer-events: none; transition: opacity var(--transition);
    box-shadow: var(--shadow); text-transform: none;
}
.rail-avatar:hover .tip { opacity: 1; }

/* ═══════════════════════════════════════════════════
   PAINEL CONTEXTUAL
   ═══════════════════════════════════════════════════ */
.context-panel {
    width: var(--panel-w);
    min-width: var(--panel-w);
    height: 100vh; height: 100dvh;
    background: var(--bg-2);
    border-right: 1px solid var(--line-soft);
    display: flex;
    flex-direction: column;
    transition: margin-left 0.34s var(--ease), opacity 0.2s ease;
    z-index: 60;
    overflow: hidden;
}
.app-shell.panel-collapsed .context-panel {
    margin-left: calc(-1 * var(--panel-w));
    opacity: 0;
    pointer-events: none;
}

.panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 0 16px 0 20px;
    height: var(--topbar-h);
    min-height: var(--topbar-h);
    border-bottom: 1px solid var(--line-soft);
}
.panel-head h2 {
    font-family: var(--font-display);
    font-size: 1.06rem;
    font-weight: 600;
    letter-spacing: -0.02em;
}
.panel-head .t-label { margin-top: 2px; display: block; }
.panel-head-titles { min-width: 0; }

.panel-body {
    flex: 1;
    overflow-y: auto;
    padding: 14px 12px;
}

/* Conteúdo de painel só visível para o módulo ativo */
.panel-view { display: none; flex-direction: column; height: 100%; }
.panel-view.active { display: flex; }

/* botão Nova conversa */
.btn-new-chat {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 12px 14px;
    background: var(--brand);
    color: var(--on-acc);
    border: none;
    border-radius: var(--radius-sm);
    font-family: var(--font-mono);
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    cursor: pointer;
    transition: transform var(--transition), box-shadow var(--transition);
    margin-bottom: 12px;
}
.btn-new-chat:hover { transform: translateY(-1px); box-shadow: var(--shadow-cta); }
.btn-new-chat svg { width: 16px; height: 16px; }

/* busca no painel */
.panel-search {
    position: relative;
    display: flex;
    align-items: center;
    margin-bottom: 12px;
}
.panel-search svg {
    position: absolute; left: 12px;
    width: 15px; height: 15px;
    color: var(--faint); pointer-events: none;
}
.panel-search input {
    width: 100%;
    height: 40px;
    padding: 0 12px 0 36px;
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    color: var(--fg);
    font-family: var(--font-body);
    font-size: 0.86rem;
    outline: none;
    transition: border-color var(--transition), box-shadow var(--transition);
}
.panel-search input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-glow); }
.panel-search input::placeholder { color: var(--faint); }

/* grupos de sessões por data */
.session-group { margin-bottom: 6px; }
.session-group-label {
    font-family: var(--font-mono);
    font-size: 0.62rem;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--faint);
    padding: 12px 10px 7px;
}

.session-list { list-style: none; display: flex; flex-direction: column; gap: 2px; }
.session-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 11px;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    cursor: pointer;
    color: var(--muted);
    transition: background var(--transition), color var(--transition), border-color var(--transition);
}
.session-item .s-icon { width: 15px; height: 15px; min-width: 15px; opacity: 0.5; }
.session-item .s-text { flex: 1; min-width: 0; overflow: hidden; }
.session-item .s-title {
    font-size: 0.85rem;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.session-item .s-meta {
    font-family: var(--font-mono);
    font-size: 0.6rem;
    letter-spacing: 0.06em;
    color: var(--faint);
    margin-top: 2px;
    display: flex; gap: 6px; align-items: center;
}
.session-item .s-del {
    display: none;
    background: none; border: none; color: var(--faint);
    cursor: pointer; padding: 3px; border-radius: 6px; flex-shrink: 0;
    transition: color var(--transition), background var(--transition);
}
.session-item .s-del svg { width: 14px; height: 14px; }
.session-item:hover { background: var(--surface); color: var(--fg); }
.session-item:hover .s-del { display: flex; }
.session-item .s-del:hover { color: var(--danger); background: var(--danger-soft); }
.session-item.active { background: var(--surface); border-color: var(--line); color: var(--fg); }
.session-item.active .s-icon { opacity: 0.9; }

/* lista genérica de itens de navegação no painel (settings, etc.) */
.panel-nav { list-style: none; display: flex; flex-direction: column; gap: 2px; }
.panel-nav li {
    display: flex; align-items: center; gap: 12px;
    padding: 11px 12px;
    border-radius: var(--radius-sm);
    color: var(--muted);
    cursor: pointer;
    font-size: 0.88rem;
    transition: background var(--transition), color var(--transition);
}
.panel-nav li svg { width: 17px; height: 17px; opacity: 0.7; }
.panel-nav li:hover { background: var(--surface); color: var(--fg); }
.panel-nav li.active { background: var(--surface); color: var(--fg); border: 1px solid var(--line); }

/* bloco de filtros / meta no painel */
.panel-block { padding: 4px 8px 16px; }
.panel-block + .panel-block { border-top: 1px solid var(--line-soft); padding-top: 16px; }
.panel-block-title {
    font-family: var(--font-mono);
    font-size: 0.62rem;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--faint);
    margin-bottom: 12px;
}

.panel-stat {
    display: flex; align-items: baseline; justify-content: space-between;
    padding: 9px 4px;
}
.panel-stat + .panel-stat { border-top: 1px dashed var(--line-soft); }
.panel-stat .ps-label { font-size: 0.82rem; color: var(--muted); }
.panel-stat .ps-value {
    font-family: var(--font-display);
    font-size: 1.05rem; font-weight: 600; letter-spacing: -0.02em;
    color: var(--fg);
    font-variant-numeric: tabular-nums;
}

/* segmented control (período etc.) */
.seg {
    display: flex;
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    padding: 3px;
    gap: 3px;
}
.seg button {
    flex: 1;
    padding: 8px 6px;
    background: transparent;
    border: none;
    border-radius: 9px;
    color: var(--faint);
    font-family: var(--font-mono);
    font-size: 0.64rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    cursor: pointer;
    transition: background var(--transition), color var(--transition);
}
.seg button.active { background: var(--surface-2); color: var(--fg); }
.seg button:hover:not(.active) { color: var(--muted); }

/* ═══════════════════════════════════════════════════
   WORKSPACE
   ═══════════════════════════════════════════════════ */
.workspace {
    flex: 1;
    min-width: 0;
    height: 100vh; height: 100dvh;
    display: flex;
    flex-direction: column;
    background: var(--bg);
}

.topbar {
    display: flex;
    align-items: center;
    gap: 14px;
    height: var(--topbar-h);
    min-height: var(--topbar-h);
    padding: 0 24px;
    border-bottom: 1px solid var(--line-soft);
    background: oklch(0.145 0.012 255 / 0.72);
    backdrop-filter: blur(16px) saturate(1.4);
    -webkit-backdrop-filter: blur(16px) saturate(1.4);
    z-index: 40;
}
.topbar-toggle {
    width: 38px; height: 38px;
    display: grid; place-items: center;
    background: transparent;
    border: 1px solid var(--line-soft);
    border-radius: var(--radius-sm);
    color: var(--muted);
    cursor: pointer;
    transition: all var(--transition);
}
.topbar-toggle:hover { background: var(--surface); color: var(--fg); border-color: var(--line); }
.topbar-toggle svg { width: 18px; height: 18px; }

.topbar-titles { min-width: 0; flex-shrink: 1; }
.topbar-titles h1 {
    font-family: var(--font-display);
    font-size: 1.08rem;
    font-weight: 600;
    letter-spacing: -0.02em;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.topbar-titles .crumb {
    font-family: var(--font-mono);
    font-size: 0.62rem;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: var(--faint);
    margin-bottom: 1px;
}
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 10px; }

/* view do workspace */
.workspace-view { display: none; flex: 1; min-height: 0; flex-direction: column; }
.workspace-view.active { display: flex; }

.view-scroll { flex: 1; overflow-y: auto; }
.view-pad { padding: 28px 32px; }

/* ── Chip de banco no topbar (reaproveita db-selector) ── */
.db-pill {
    display: flex; align-items: center; gap: 9px;
    height: 38px; padding: 0 14px;
    background: var(--surface);
    border: 1px solid var(--line-soft);
    border-radius: var(--r-pill);
    color: var(--muted);
    font-family: var(--font-mono);
    font-size: 0.7rem;
    letter-spacing: 0.04em;
    cursor: pointer;
    transition: all var(--transition);
    max-width: 240px;
}
.db-pill:hover { border-color: var(--line); color: var(--fg); }
.db-pill.filtered { border-color: var(--brand); color: var(--fg); }
.db-pill svg { width: 15px; height: 15px; flex-shrink: 0; }
.db-pill span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* botão fantasma genérico no topbar */
.btn-ghost {
    display: inline-flex; align-items: center; gap: 8px;
    height: 38px; padding: 0 16px;
    background: transparent;
    border: 1px solid var(--line);
    border-radius: var(--r-pill);
    color: var(--muted);
    font-family: var(--font-mono);
    font-size: 0.7rem; letter-spacing: 0.1em; text-transform: uppercase;
    cursor: pointer;
    transition: all var(--transition);
}
.btn-ghost:hover { background: var(--surface); color: var(--fg); }
.btn-ghost svg { width: 15px; height: 15px; }

/* ═══════════════════════════════════════════════════
   OVERVIEW / HOME (novo)
   ═══════════════════════════════════════════════════ */
.welcome-band {
    position: relative;
    overflow: hidden;
    border: 1px solid var(--line-soft);
    border-radius: var(--radius-lg);
    background:
        radial-gradient(120% 130% at 88% -20%, var(--surface), transparent 60%),
        linear-gradient(180deg, var(--surface), var(--bg-2));
    padding: 34px 36px;
    margin-bottom: 22px;
}
.welcome-band .mesh { opacity: 0.5; }
.welcome-band > * { position: relative; z-index: 2; }
.welcome-band h2 {
    font-family: var(--font-display);
    font-size: clamp(1.5rem, 3vw, 2rem);
    font-weight: 600; letter-spacing: -0.03em;
    margin-bottom: 8px;
}
.welcome-band p { color: var(--muted); max-width: 52ch; font-size: 0.95rem; }

.overview-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 16px;
    margin-bottom: 22px;
}
.nav-card {
    position: relative;
    overflow: hidden;
    text-align: left;
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding: 22px;
    background: var(--surface);
    border: 1px solid var(--line-soft);
    border-radius: var(--radius);
    cursor: pointer;
    color: var(--fg);
    font-family: var(--font-body);
    transition: transform var(--transition), border-color var(--transition), background var(--transition), box-shadow var(--transition);
}
.nav-card:hover { transform: translateY(-5px); border-color: var(--brand); background: var(--surface-2); box-shadow: var(--shadow); }
.nav-card::after {
    content: ""; position: absolute; top: 0; right: 0;
    width: 90px; height: 90px;
    background: radial-gradient(circle at top right, var(--brand-soft), transparent 70%);
    opacity: 0; transition: opacity var(--transition); pointer-events: none;
}
.nav-card:hover::after { opacity: 1; }
.nav-card-icon {
    width: 46px; height: 46px;
    display: grid; place-items: center;
    background: var(--brand-soft);
    border: 1px solid var(--line-soft);
    border-radius: var(--radius-sm);
    color: var(--fg);
    transition: background var(--transition), color var(--transition), border-color var(--transition);
}
.nav-card:hover .nav-card-icon { background: var(--brand); color: var(--on-acc); border-color: var(--brand); }
.nav-card-icon svg { width: 22px; height: 22px; }
.nav-card h3 { font-family: var(--font-display); font-size: 1.05rem; font-weight: 600; letter-spacing: -0.02em; margin-bottom: 5px; }
.nav-card p { font-size: 0.82rem; color: var(--muted); line-height: 1.5; }
.nav-card .nav-card-foot {
    display: flex; align-items: center; gap: 7px;
    font-family: var(--font-mono); font-size: 0.64rem;
    letter-spacing: 0.12em; text-transform: uppercase; color: var(--faint);
}

.section-title {
    font-family: var(--font-mono);
    font-size: 0.66rem; letter-spacing: 0.18em; text-transform: uppercase;
    color: var(--faint);
    margin-bottom: 14px;
}

/* ═══════════════════════════════════════════════════
   CONFIGURAÇÕES (novo)
   ═══════════════════════════════════════════════════ */
.settings-wrap { max-width: 760px; margin: 0 auto; width: 100%; }
.settings-section {
    background: var(--surface);
    border: 1px solid var(--line-soft);
    border-radius: var(--radius);
    padding: 8px 22px;
    margin-bottom: 18px;
}
.settings-row {
    display: flex; align-items: center; justify-content: space-between;
    gap: 20px; padding: 18px 0;
}
.settings-row + .settings-row { border-top: 1px solid var(--line-soft); }
.settings-row .sr-info h4 { font-family: var(--font-display); font-size: 0.98rem; font-weight: 600; letter-spacing: -0.01em; margin-bottom: 4px; }
.settings-row .sr-info p { font-size: 0.84rem; color: var(--muted); max-width: 46ch; }

/* toggle switch */
.switch {
    position: relative; width: 46px; height: 26px;
    background: var(--bg); border: 1px solid var(--line);
    border-radius: 999px; cursor: pointer; flex-shrink: 0;
    transition: background var(--transition), border-color var(--transition);
}
.switch::after {
    content: ""; position: absolute; top: 2px; left: 2px;
    width: 20px; height: 20px; border-radius: 50%;
    background: var(--muted);
    transition: transform var(--transition), background var(--transition);
}
.switch.on { background: var(--brand); border-color: var(--brand); }
.switch.on::after { transform: translateX(20px); background: var(--on-acc); }

/* desliga animações de scan (Tweak) */
body.no-scan .scanline,
body.no-scan .rail-logo::after,
body.no-scan .message.assistant .message-avatar::after { animation: none; opacity: 0; }

/* ═══════════════════════════════════════════════════
   RESPONSIVO (hambúrguer + polimento mobile)
   ═══════════════════════════════════════════════════ */
.scrim {
    display: none;
    position: fixed; inset: 0;
    background: oklch(0 0 0 / 0.55);
    backdrop-filter: blur(2px);
    z-index: 85;
}
.scrim.active { display: block; }

/* Navegação de módulos no drawer (só no mobile; no desktop o rail cuida disso) */
.panel-modules { display: none; }
.topbar-toggle .ic-menu { display: none; }   /* hambúrguer só no mobile */

@media (max-width: 1024px) {
    .view-pad { padding: 22px 22px; }
    :root { --panel-w: 280px; }
}

@media (max-width: 900px) {
    /* rail some; conteúdo ocupa a tela toda; ☰ abre o drawer */
    .rail { display: none; }
    .topbar-toggle .ic-panel { display: none; }
    .topbar-toggle .ic-menu { display: block; }
    .topbar { padding: 0 14px; gap: 10px; }
    .topbar-titles h1 { font-size: 1rem; }

    .context-panel {
        position: fixed; top: 0; left: 0;
        width: min(88vw, 360px);
        height: 100dvh;
        max-width: none; min-width: 0;
        z-index: 90;
        box-shadow: var(--shadow-panel);
        transition: transform 0.34s var(--ease);
    }
    .app-shell.panel-collapsed .context-panel { margin-left: 0; transform: translateX(-100%); }
    .app-shell:not(.panel-collapsed) .scrim { display: block; }

    /* lista de módulos no topo do drawer */
    .panel-modules { display: flex; flex-direction: column; gap: 2px; padding: 10px 12px; border-bottom: 1px solid var(--line-soft); }
    .pm-item { display: flex; align-items: center; gap: 12px; width: 100%; padding: 11px 12px; background: transparent; border: none; border-radius: var(--radius-sm); color: var(--muted); font-family: var(--font-body); font-size: 0.92rem; text-align: left; cursor: pointer; transition: background var(--transition), color var(--transition); }
    .pm-item svg { width: 20px; height: 20px; flex-shrink: 0; }
    .pm-item:hover { background: var(--surface); color: var(--fg); }
    .pm-item.active { background: var(--brand-soft); color: var(--brand); }
    .pm-logout { color: var(--faint); }
    .pm-logout:hover { background: var(--surface); color: var(--fg); }
}

@media (max-width: 760px) {
    .view-pad { padding: 18px 16px 28px; }
    .overview-grid { grid-template-columns: 1fr; }
    .usage-grid, .widgets-grid { grid-template-columns: 1fr !important; }
    .kpi-row { grid-template-columns: repeat(2, 1fr); }
    .welcome-band { padding: 26px 22px; }
    .welcome-band h2 { font-size: 1.5rem; }
    .settings-row { flex-direction: column; align-items: flex-start; gap: 12px; }
    .settings-row .sr-control { width: 100%; }
    .settings-row .sr-control .select-field,
    .settings-row .sr-control input,
    .settings-row .sr-control .seg { width: 100% !important; }
    .chat-input-area { padding: 14px 14px calc(16px + env(safe-area-inset-bottom)); }
    .message { padding: 12px 16px; }
}

/* Modais viram bottom sheets no celular */
@media (max-width: 560px) {
    .modal-overlay { align-items: flex-end; padding: 0; }
    .modal-card, .modal-card-sm {
        max-width: 100%; width: 100%;
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
        max-height: 92dvh; overflow-y: auto;
        padding: 24px 22px calc(26px + env(safe-area-inset-bottom));
        animation: sheetUp 0.28s var(--ease);
    }
    .db-list { max-height: 44vh; }
}
@keyframes sheetUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
