/* uBroccoli · painel
   Tema por variáveis: claro (padrão) e escuro em [data-theme="dark"]. */

:root {
    --bg: #f6f6f1;
    --surface: #ffffff;
    --surface-2: #fbfbf7;
    --sidebar: #fbfbf7;
    --ink: #1d211b;
    --ink-2: #3a3f37;
    --muted: #6b7166;
    --faint: #9a9f95;
    --line: #e4e5dd;
    --line-2: #d6d8cd;
    --code-bg: #f7f7f2;
    --hover: #f1f7ec;

    --accent: #2f6b22;
    --accent-hover: #234f1a;
    --accent-soft: #e6f0dd;
    --accent-ink: #234f1a;
    --accent-dot: #3d8a2c;
    --on-accent: #ffffff;

    --danger: #a8261b;
    --danger-soft: #fdf1ef;
    --danger-line: #f1c4bd;
    --warn: #8a5a00;
    --warn-soft: #fdf5e3;
    --info: #1f5c8a;
    --info-soft: #eaf3fb;

    --shadow-sm: 0 1px 2px rgba(29, 33, 27, .06);
    --shadow-md: 0 8px 28px rgba(29, 33, 27, .10);
    --scrim: rgba(29, 33, 27, .28);
    --topbar-bg: rgba(246, 246, 241, .92);

    --font: "IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
    --display: "Bricolage Grotesque", var(--font);
    --sidebar-w: 268px;
    --radius: 12px;

    color-scheme: light;
}

:root[data-theme="dark"] {
    --bg: #111410;
    --surface: #191c17;
    --surface-2: #1d211b;
    --sidebar: #151813;
    --ink: #e8eae3;
    --ink-2: #ccd0c5;
    --muted: #9ca296;
    --faint: #737a6c;
    --line: #272b24;
    --line-2: #343a30;
    --code-bg: #1f231d;
    --hover: #1e2619;

    --accent: #3f8a2e;
    --accent-hover: #4b9d38;
    --accent-soft: #223219;
    --accent-ink: #b5dc9d;
    --accent-dot: #6cbc52;
    --on-accent: #ffffff;

    --danger: #f2877a;
    --danger-soft: #2c1916;
    --danger-line: #57302a;
    --warn: #e5b65c;
    --warn-soft: #2b2312;
    --info: #8cc2ef;
    --info-soft: #172431;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .35);
    --shadow-md: 0 10px 30px rgba(0, 0, 0, .45);
    --scrim: rgba(0, 0, 0, .5);
    --topbar-bg: rgba(17, 20, 16, .9);

    color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font: 14px/1.5 var(--font);
    -webkit-font-smoothing: antialiased;
}

body.app-body { overflow: hidden; }

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent-ink); text-decoration-thickness: 1px; text-underline-offset: 2px; }
h1, h2, h3 { margin: 0; }

:focus-visible {
    outline: 2px solid var(--accent-dot);
    outline-offset: 2px;
    border-radius: 6px;
}

.i {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.sr-only {
    position: absolute;
    width: 1px; height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

.mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.nowrap { white-space: nowrap; }

/* ── Estrutura ─────────────────────────────────────────── */

.app {
    display: grid;
    grid-template-columns: var(--sidebar-w) 1fr;
    height: 100vh;
    height: 100dvh;
}

.main {
    display: grid;
    grid-template-rows: auto 1fr;
    min-width: 0;
    min-height: 0;
}

.main.chat { grid-template-rows: auto 1fr auto; }

/* ── Menu lateral ──────────────────────────────────────── */

.sidebar {
    display: flex;
    flex-direction: column;
    min-height: 0;
    background: var(--sidebar);
    border-right: 1px solid var(--line);
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    height: 64px;
    padding: 0 20px;
    text-decoration: none;
    flex-shrink: 0;
}

.brand-mark { width: 30px; height: 30px; }

.brand-name {
    font-family: var(--display);
    font-size: 21px;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--ink);
}

.brand-name span { color: var(--accent-dot); }

.sidebar-scroll {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
}

.nav {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 4px 12px 12px;
}

.nav-label {
    padding: 12px 10px 6px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--faint);
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 7px 10px;
    border-radius: 8px;
    color: var(--ink-2);
    text-decoration: none;
    font-weight: 500;
    transition: background .15s, color .15s;
}

.nav-item:hover { background: var(--hover); color: var(--ink); }

.nav-row { display: flex; align-items: center; gap: 2px; }
.nav-row .nav-item { flex: 1; min-width: 0; }

.nav-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    flex-shrink: 0;
    border: 0;
    border-radius: 7px;
    background: transparent;
    color: var(--faint);
}

.nav-toggle:hover { background: var(--hover); color: var(--ink); }
.nav-toggle .i { width: 16px; height: 16px; transition: transform .15s; }
:root[data-sessions-collapsed] .nav-toggle .i { transform: rotate(-90deg); }
:root[data-sessions-collapsed] .nav-sub { display: none; }
.nav-item[aria-current="page"] { background: var(--accent-soft); color: var(--accent-ink); }

.sidebar-foot {
    display: grid;
    gap: 10px;
    padding: 12px 16px;
    border-top: 1px solid var(--line);
}

.user-row { display: flex; align-items: center; gap: 10px; }

.avatar {
    display: grid;
    place-items: center;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--accent-soft);
    color: var(--accent-ink);
    font-weight: 600;
    font-size: 13px;
    text-transform: uppercase;
    flex-shrink: 0;
}

.user-name {
    flex: 1;
    min-width: 0;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-row form { margin: 0; }

.theme-switch {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 2px;
    padding: 3px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--bg);
}

.theme-switch button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    height: 28px;
    border: 0;
    border-radius: 7px;
    background: transparent;
    color: var(--muted);
    font-size: 12px;
}

.theme-switch button .i { width: 15px; height: 15px; }
.theme-switch button:hover { color: var(--ink); }

.theme-switch button[aria-pressed="true"] {
    background: var(--surface);
    color: var(--ink);
    box-shadow: var(--shadow-sm);
}

/* ── Barra superior ────────────────────────────────────── */

.topbar {
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 64px;
    padding: 10px 24px;
    border-bottom: 1px solid var(--line);
    background: var(--topbar-bg);
    backdrop-filter: blur(6px);
}

.icon-btn.menu-toggle { display: none; }

.page-title { min-width: 0; }

.page-title h1 {
    font-size: 17px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.crumbs {
    display: flex;
    gap: 6px;
    font-size: 12px;
    color: var(--faint);
}

.crumbs a { color: var(--muted); text-decoration: none; }
.crumbs a:hover { color: var(--ink); }

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-left: auto;
}

/* ── Botões ────────────────────────────────────────────── */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    height: 34px;
    padding: 0 12px;
    border: 1px solid var(--line-2);
    border-radius: 9px;
    background: var(--surface);
    color: var(--ink-2);
    font-weight: 500;
    font-size: 13px;
    text-decoration: none;
    white-space: nowrap;
    transition: border-color .15s, background .15s, color .15s;
}

.btn:hover:not(:disabled) { border-color: var(--faint); color: var(--ink); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn .i { width: 16px; height: 16px; }

.btn-primary { border-color: var(--accent); background: var(--accent); color: var(--on-accent); }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); color: var(--on-accent); }

.btn-danger { border-color: var(--danger-line); background: var(--danger-soft); color: var(--danger); }
.btn-danger:hover:not(:disabled) { border-color: var(--danger); color: var(--danger); }

.btn-ghost { border-color: transparent; background: transparent; }
.btn-sm { height: 28px; padding: 0 9px; font-size: 12px; }

.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border: 1px solid transparent;
    border-radius: 8px;
    background: transparent;
    color: var(--muted);
    transition: background .15s, color .15s, border-color .15s;
}

.icon-btn:hover { background: var(--surface); border-color: var(--line); color: var(--ink); }

.btn-count {
    min-width: 20px;
    padding: 0 6px;
    border-radius: 999px;
    background: var(--accent-soft);
    color: var(--accent-ink);
    font-family: var(--mono);
    font-size: 12px;
    line-height: 20px;
    text-align: center;
}

/* ── Página ────────────────────────────────────────────── */

.page { overflow-y: auto; }

.page-inner {
    max-width: 1240px;
    margin: 0 auto;
    padding: 24px;
}

.page-inner.narrow { max-width: 900px; }

.stack { display: grid; gap: 20px; }

.card {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow-sm);
}

.card-head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 18px;
    border-bottom: 1px solid var(--line);
}

.card-head h2 { font-size: 14px; font-weight: 600; }
.card-head p { margin: 2px 0 0; font-size: 12.5px; color: var(--muted); }
.card-head .spacer { flex: 1; }
.card-body { padding: 18px; }

/* ── Filtros ───────────────────────────────────────────── */

.filters {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin-bottom: 14px;
}

.search {
    position: relative;
    flex: 1 1 260px;
    max-width: 380px;
}

.search .i {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    color: var(--faint);
}

.search input { padding-left: 34px; }

.filters .select { width: auto; min-width: 160px; }
.filters .count { margin-left: auto; font-size: 12.5px; color: var(--faint); }

/* ── Campos ────────────────────────────────────────────── */

.input, .select, .textarea {
    width: 100%;
    height: 36px;
    padding: 0 11px;
    border: 1px solid var(--line-2);
    border-radius: 9px;
    background: var(--surface);
    color: var(--ink);
    box-shadow: var(--shadow-sm);
    transition: border-color .15s;
}

.input:hover, .select:hover, .textarea:hover { border-color: var(--faint); }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--accent-dot); }

.select {
    appearance: none;
    padding-right: 32px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%239a9f95' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 16px;
    cursor: pointer;
}

.textarea {
    height: auto;
    min-height: 96px;
    padding: 9px 11px;
    resize: vertical;
    line-height: 1.55;
}

.textarea.code { font-family: var(--mono); font-size: 12.5px; }
.textarea.tall { min-height: 260px; }

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px 18px;
}

.field { display: grid; gap: 6px; align-content: start; }
.field.full { grid-column: 1 / -1; }

.field label, .field-label {
    font-size: 13px;
    font-weight: 500;
    color: var(--ink-2);
}

.field .help { font-size: 12px; color: var(--faint); }
.field .help.warn { color: var(--warn); }
.field .help code { font-family: var(--mono); font-size: 11.5px; color: var(--muted); }

.field .errors { margin: 0; padding: 0; list-style: none; font-size: 12.5px; color: var(--danger); }
.field.has-error .input, .field.has-error .select, .field.has-error .textarea { border-color: var(--danger); }

.check {
    display: inline-flex;
    align-items: center;
    gap: 9px;
    font-size: 13px;
    font-weight: 500;
    color: var(--ink-2);
    cursor: pointer;
}

.check input {
    width: 16px;
    height: 16px;
    margin: 0;
    accent-color: var(--accent);
    cursor: pointer;
}

.choice-row { display: flex; flex-wrap: wrap; gap: 8px 18px; }

.check-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 6px;
}

.check-grid .check {
    padding: 8px 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface-2);
    font-family: var(--mono);
    font-size: 12.5px;
    font-weight: 400;
}

.check-grid .check:hover { border-color: var(--line-2); }

.form-errors {
    margin-bottom: 16px;
    padding: 12px 14px;
    border: 1px solid var(--danger-line);
    border-radius: 10px;
    background: var(--danger-soft);
    color: var(--danger);
}

.form-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    padding-top: 4px;
}

.form-actions .spacer { flex: 1; }

/* ── Tabela ────────────────────────────────────────────── */

.table-wrap { overflow-x: auto; }

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13.5px;
}

.table th {
    position: sticky;
    top: 0;
    padding: 10px 14px;
    border-bottom: 1px solid var(--line);
    background: var(--surface-2);
    color: var(--faint);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: .07em;
    text-align: left;
    text-transform: uppercase;
    white-space: nowrap;
}

.table td {
    padding: 11px 14px;
    border-bottom: 1px solid var(--line);
    vertical-align: middle;
}

.table tr:last-child td { border-bottom: 0; }
.table tbody tr[data-href] { cursor: pointer; }
.table tbody tr[data-href]:hover td { background: var(--hover); }

.table .primary-cell { font-weight: 500; color: var(--ink); }
.row-link { color: inherit; text-decoration: none; }
.row-link:hover .primary-cell { text-decoration: underline; text-underline-offset: 2px; }
.table .primary-cell a { color: inherit; text-decoration: none; }
.table .sub { display: block; font-size: 12px; color: var(--faint); font-weight: 400; }
.table .truncate { display: block; max-width: 340px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.table .num { text-align: right; }
.table td.num { font-family: var(--mono); font-size: 12.5px; }

.empty {
    padding: 48px 20px;
    text-align: center;
    color: var(--muted);
}

.empty .brand-mark { width: 40px; height: 40px; margin-bottom: 10px; opacity: .9; }
.empty h3 { font-size: 15px; font-weight: 600; color: var(--ink); margin-bottom: 4px; }
.empty p { margin: 0 0 14px; }

.pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 12px 14px;
    border-top: 1px solid var(--line);
    font-size: 12.5px;
    color: var(--faint);
}

.pagination .pages { display: flex; gap: 6px; }

/* ── Badges ────────────────────────────────────────────── */

.badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 22px;
    padding: 0 9px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 500;
    white-space: nowrap;
    background: var(--code-bg);
    color: var(--ink-2);
}

.badge::before {
    content: "";
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
    opacity: .8;
}

.badge.plain::before { display: none; }
.badge.success { background: var(--accent-soft); color: var(--accent-ink); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.info { background: var(--info-soft); color: var(--info); }
.badge.neutral { background: var(--code-bg); color: var(--muted); }

.tag {
    display: inline-flex;
    align-items: center;
    height: 22px;
    padding: 0 8px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--surface-2);
    font-family: var(--mono);
    font-size: 12px;
    color: var(--ink-2);
    white-space: nowrap;
}

/* ── Detalhes ──────────────────────────────────────────── */

.kv-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px 20px;
}

.kv-label {
    margin-bottom: 4px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--faint);
}

.kv-value { overflow-wrap: anywhere; }

.code-block { position: relative; }

.code-block pre {
    margin: 0;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--code-bg);
    font: 12.5px/1.6 var(--mono);
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    color: var(--ink-2);
    max-height: 560px;
    overflow: auto;
}

.code-block .copy { position: absolute; top: 8px; right: 8px; }

.prose-block {
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--code-bg);
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.copy-field {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 6px 6px 12px;
    border: 1px solid var(--line-2);
    border-radius: 10px;
    background: var(--code-bg);
}

.copy-field code {
    flex: 1;
    min-width: 0;
    font-family: var(--mono);
    font-size: 12.5px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.notice {
    display: flex;
    gap: 10px;
    padding: 11px 14px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--surface-2);
    color: var(--muted);
    font-size: 13px;
}

.notice.danger { border-color: var(--danger-line); background: var(--danger-soft); color: var(--danger); }

.split {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 360px;
    gap: 20px;
    align-items: start;
}

/* ── Toasts ────────────────────────────────────────────── */

.toasts {
    position: fixed;
    top: 16px;
    right: 16px;
    display: grid;
    gap: 8px;
    z-index: 50;
}

.toast {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 260px;
    max-width: 420px;
    padding: 11px 12px 11px 14px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--surface);
    box-shadow: var(--shadow-md);
    animation: rise .25s ease-out;
}

.toast .i { color: var(--accent-dot); }
.toast.error .i { color: var(--danger); }
.toast span { flex: 1; }

/* ── Painel lateral (detalhes) ─────────────────────────── */

.scrim {
    position: fixed;
    inset: 0;
    background: var(--scrim);
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s;
    z-index: 20;
}

.scrim.show { opacity: 1; pointer-events: auto; }

.drawer {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    width: min(560px, 100vw);
    background: var(--surface);
    border-left: 1px solid var(--line);
    box-shadow: var(--shadow-md);
    transform: translateX(100%);
    transition: transform .22s ease-out;
    z-index: 30;
}

.drawer.open { transform: translateX(0); }

.drawer-head {
    display: flex;
    align-items: center;
    gap: 10px;
    height: 64px;
    padding: 0 16px 0 20px;
    border-bottom: 1px solid var(--line);
    flex-shrink: 0;
}

.drawer-head h2 {
    flex: 1;
    min-width: 0;
    font-size: 15px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.drawer-body { flex: 1; overflow-y: auto; padding: 20px; }
.drawer-body .kv { display: grid; gap: 18px; }
.status-row { display: flex; gap: 8px; margin-bottom: 18px; }

.tool-list { display: grid; gap: 6px; margin: 0; padding: 0; list-style: none; }

.tool-list li {
    padding: 9px 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    font-family: var(--mono);
    font-size: 13px;
}

/* ── Conversa (chat de teste e conversas reais) ────────── */

.messages { overflow-y: auto; }

.thread {
    display: flex;
    flex-direction: column;
    gap: 22px;
    max-width: 860px;
    min-height: 100%;
    margin: 0 auto;
    padding: 32px 24px 24px;
}

.thread.embedded { min-height: 0; padding: 22px; max-width: none; }

.msg { display: flex; gap: 12px; animation: rise .25s ease-out; }
.msg.user { justify-content: flex-end; }
.msg-avatar { width: 28px; height: 28px; flex-shrink: 0; margin-top: 2px; }
.msg-body { min-width: 0; max-width: min(680px, 88%); }
.msg.user .msg-body { max-width: min(620px, 80%); }

.bubble { padding: 11px 15px; border-radius: 14px; overflow-wrap: anywhere; }
.msg.user .bubble { background: var(--accent); color: var(--on-accent); border-bottom-right-radius: 4px; }

.msg.assistant .bubble {
    background: var(--surface);
    border: 1px solid var(--line);
    border-top-left-radius: 4px;
    box-shadow: var(--shadow-sm);
}

.bubble p { margin: 0 0 8px; }
.bubble p:last-child { margin-bottom: 0; }
.bubble ul { margin: 4px 0 8px; padding-left: 20px; }
.bubble li { margin: 2px 0; }
.bubble strong { font-weight: 600; }

/* Resposta que o canal recusou: o cliente não recebeu */
.msg.assistant .bubble.undelivered { border: 1px dashed var(--danger); box-shadow: none; opacity: .8; }
.msg-delivery-error { margin-top: 6px; font-size: 13px; color: var(--danger); overflow-wrap: anywhere; }

.msg-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 8px; }
.msg.user .msg-meta { justify-content: flex-end; }
.msg-time { font-family: var(--mono); font-size: 12px; color: var(--faint); margin-right: 2px; }

.tool-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 26px;
    padding: 0 9px;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: var(--surface);
    font-family: var(--mono);
    font-size: 12px;
    color: var(--ink-2);
    transition: border-color .15s, background .15s;
}

.tool-chip:hover { border-color: var(--accent-dot); background: var(--hover); }
.tool-chip .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent-dot); }
.tool-chip.error { border-color: var(--danger-line); background: var(--danger-soft); color: var(--danger); }
.tool-chip.error .dot { background: var(--danger); }
.tool-chip .ms { color: var(--faint); }

.file-card {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 10px;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--surface);
    box-shadow: var(--shadow-sm);
}

.file-badge {
    display: grid;
    place-items: center;
    width: 36px;
    height: 42px;
    border-radius: 6px;
    background: var(--danger-soft);
    color: var(--danger);
    font-family: var(--mono);
    font-size: 11px;
    font-weight: 500;
    flex-shrink: 0;
}

.file-info { flex: 1; min-width: 0; }
.file-name { font-family: var(--mono); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-size { font-size: 12px; color: var(--faint); }
.file-actions { display: flex; gap: 6px; }

.thinking {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 11px 15px;
    border: 1px solid var(--line);
    border-radius: 14px;
    border-top-left-radius: 4px;
    background: var(--surface);
    color: var(--muted);
}

.dots { display: inline-flex; gap: 4px; }
.dots span { width: 6px; height: 6px; border-radius: 50%; background: var(--accent-dot); animation: blink 1.2s infinite ease-in-out; }
.dots span:nth-child(2) { animation-delay: .15s; }
.dots span:nth-child(3) { animation-delay: .3s; }
.elapsed { font-family: var(--mono); font-size: 12px; color: var(--faint); }

.alert {
    display: flex;
    gap: 10px;
    padding: 11px 14px;
    border: 1px solid var(--danger-line);
    border-radius: 10px;
    background: var(--danger-soft);
    color: var(--danger);
    animation: rise .25s ease-out;
}

.chat-empty { margin: auto; max-width: 420px; text-align: center; color: var(--muted); padding: 40px 0; }
.chat-empty .brand-mark { width: 52px; height: 52px; margin-bottom: 14px; }

.chat-empty h1 {
    margin: 0 0 6px;
    font-family: var(--display);
    font-size: 24px;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--ink);
}

.chat-empty p { margin: 0 0 18px; }
.tips { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none; text-align: left; font-size: 13px; }
.tips li { display: flex; gap: 10px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
.tips b { color: var(--accent-dot); font-weight: 600; }

.project-picker { position: relative; min-width: 0; flex: 0 1 340px; }
.project-picker .select { height: 38px; font-weight: 500; }

.project-facts { display: flex; align-items: center; gap: 6px; min-width: 0; color: var(--muted); font-size: 13px; }
.project-warning { color: var(--danger); font-weight: 500; }

.nav-sub {
    display: flex;
    flex-direction: column;
    gap: 1px;
    max-height: 232px;
    overflow-y: auto;
    margin: 2px 0 8px 19px;
    padding-left: 10px;
    border-left: 1px solid var(--line);
}

.session-item {
    display: block;
    width: 100%;
    padding: 6px 9px;
    border: 0;
    border-radius: 7px;
    background: transparent;
    color: var(--ink-2);
    text-align: left;
    text-decoration: none;
    transition: background .15s;
}

.session-item:hover { background: var(--hover); color: var(--ink); }
.session-item.active { background: var(--surface); color: var(--ink); box-shadow: inset 0 0 0 1px var(--line-2), var(--shadow-sm); }
.session-name { display: block; font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.session-item[data-untitled] .session-name { color: var(--muted); font-weight: 400; }
.session-meta { display: block; font-size: 11px; color: var(--faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.no-sessions { padding: 6px 9px; font-size: 12.5px; color: var(--faint); }

.composer-wrap { padding: 0 24px 18px; }

.composer {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    max-width: 860px;
    margin: 0 auto;
    padding: 10px 10px 10px 16px;
    border: 1px solid var(--line-2);
    border-radius: 16px;
    background: var(--surface);
    box-shadow: var(--shadow-md);
    transition: border-color .15s;
}

.composer:focus-within { border-color: var(--accent-dot); }

.composer textarea {
    flex: 1;
    min-height: 24px;
    max-height: 180px;
    padding: 7px 0;
    border: 0;
    outline: 0;
    resize: none;
    background: transparent;
    line-height: 1.5;
}

.composer textarea:disabled { cursor: not-allowed; }
.composer textarea::placeholder { color: var(--faint); }

.send-btn {
    display: grid;
    place-items: center;
    width: 38px;
    height: 38px;
    border: 0;
    border-radius: 11px;
    background: var(--accent);
    color: var(--on-accent);
    transition: background .15s, opacity .15s;
}

.send-btn:hover:not(:disabled) { background: var(--accent-hover); }
.send-btn:disabled { opacity: .35; cursor: not-allowed; }

.composer-hint { max-width: 860px; margin: 8px auto 0; font-size: 12px; color: var(--faint); text-align: center; }

kbd {
    padding: 1px 5px;
    border: 1px solid var(--line-2);
    border-bottom-width: 2px;
    border-radius: 4px;
    background: var(--surface);
    font-family: var(--mono);
    font-size: 11px;
}

.tool-result {
    border: 1px dashed var(--line-2);
    border-radius: 10px;
    background: var(--surface-2);
}

.tool-result summary {
    padding: 8px 12px;
    font-family: var(--mono);
    font-size: 12px;
    color: var(--muted);
    cursor: pointer;
}

.tool-result .code-block { padding: 0 10px 10px; }

/* ── Login ─────────────────────────────────────────────── */

.auth {
    display: grid;
    place-items: center;
    min-height: 100vh;
    min-height: 100dvh;
    padding: 24px;
}

.auth-card { width: 100%; max-width: 380px; }
.auth-brand { display: flex; flex-direction: column; align-items: center; gap: 10px; margin-bottom: 22px; text-decoration: none; }
.auth-brand .brand-mark { width: 48px; height: 48px; }
.auth-brand .brand-name { font-size: 28px; }
.auth-card .card-body { display: grid; gap: 16px; padding: 24px; }
.auth-card h1 { font-size: 16px; font-weight: 600; }
.auth-card .muted { margin: 2px 0 0; font-size: 13px; }
.auth-card .btn { height: 40px; width: 100%; }
.auth-foot { margin-top: 16px; display: flex; justify-content: center; }
.auth-foot .theme-switch { width: 240px; }

/* ── Animações ─────────────────────────────────────────── */

@keyframes rise {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: none; }
}

@keyframes blink {
    0%, 80%, 100% { opacity: .25; transform: scale(.8); }
    40% { opacity: 1; transform: scale(1); }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

/* ── Telas menores ─────────────────────────────────────── */

@media (max-width: 1100px) {
    .split { grid-template-columns: 1fr; }
}

@media (max-width: 960px) {
    .app { grid-template-columns: 1fr; }

    .sidebar {
        position: fixed;
        top: 0;
        bottom: 0;
        left: 0;
        width: min(var(--sidebar-w), 86vw);
        transform: translateX(-100%);
        transition: transform .22s ease-out;
        z-index: 40;
        box-shadow: var(--shadow-md);
    }

    .app.nav-open .sidebar { transform: translateX(0); }
    .icon-btn.menu-toggle { display: inline-flex; }
    .project-facts { display: none; }
    .btn .label { display: none; }
}

@media (max-width: 700px) {
    .form-grid { grid-template-columns: 1fr; }
    .table .hide-sm { display: none; }
}

@media (max-width: 600px) {
    .topbar { flex-wrap: wrap; padding: 10px 12px; }
    .page-inner { padding: 16px 12px; }
    .project-picker { flex: 1 1 auto; }
    .main.chat .topbar-actions { width: 100%; margin-left: 0; justify-content: flex-end; }
    .thread { padding: 20px 12px 16px; }
    .composer-wrap { padding: 0 12px 12px; }
    .msg-body, .msg.user .msg-body { max-width: 100%; }
    .msg-avatar { display: none; }
    .composer-hint { display: none; }
    .filters .select { flex: 1 1 140px; }
}
