:root {
    --ink: #f4f6f8;
    --ink-soft: #b7c0c9;
    --paper: #000000;
    --card: #12121a;
    --rail: #050508;
    --line: rgba(255, 255, 255, 0.12);
    --accent: #4041c5;
    --accent-dark: #3132a8;
    --orange: #e76a1f;
    --violet: #7140c5;
    --pine: #3dd68c;
    --pine-soft: rgba(61, 214, 140, 0.14);
    --shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
    --sans: "Manrope", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; min-height: 100%; }
body {
    font-family: var(--sans);
    color: var(--ink);
    background:
        radial-gradient(circle at 80% -10%, rgba(64, 65, 197, 0.28), transparent 32%),
        var(--paper);
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.55; }
h1, h2, h3 { font-family: var(--sans); font-weight: 800; letter-spacing: -0.03em; margin: 0; }
p { margin: 0; }
a { color: #9aa0ff; }
.sr-only {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0, 0, 0, 0); border: 0;
}
::placeholder { color: #8b95a1; }

.shell {
    display: grid;
    grid-template-columns: 320px minmax(0, 1fr);
    min-height: 100vh;
    max-width: 1180px;
    margin: 0 auto;
}
.rail {
    padding: 28px 24px;
    color: var(--ink);
    background: var(--rail);
    border-right: 1px solid var(--line);
    display: flex;
    flex-direction: column;
    gap: 18px;
}
.brand { display: flex; align-items: center; text-decoration: none; }
.brand img { display: block; width: 168px; height: auto; }
.brand h1, .rail h1 { font-size: 32px; line-height: 1; color: white; }
.eyebrow {
    margin: 0;
    text-transform: uppercase;
    letter-spacing: 0.16em;
    font-size: 11px;
    font-weight: 700;
    color: var(--orange);
}
.lede, .rail-foot { color: var(--ink-soft); line-height: 1.55; }
.rail-foot { margin-top: auto; font-size: 14px; }
.rail-foot a { color: white; font-weight: 700; text-decoration: none; }
.rail-foot a:hover { color: var(--orange); }
.label { font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase; color: #9aa0ff; font-weight: 700; }
.topics { display: flex; flex-direction: column; gap: 8px; }
.topics button, .ghost, .composer button, .card button, .login-card button, .decision button, .choice-row a {
    border-radius: 7px;
    border: 1px solid transparent;
    padding: 10px 14px;
}
.topics button {
    text-align: left;
    background: #14141c;
    color: #eeeeee;
    border-color: rgba(64, 65, 197, 0.55);
}
.topics button:hover { background: #292734; border-color: var(--accent); }

.chat { display: flex; flex-direction: column; min-height: 100vh; padding: 22px 22px 16px; }
.chat-top, .desk-bar, .table-head, .pager, .button-row, .desk-actions {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.chat-top h2 { font-size: 28px; color: white; }
.accent { color: var(--orange); }
.status-dot { color: var(--pine); font-size: 13px; font-weight: 700; margin-bottom: 4px; }
.status-dot::before {
    content: ""; display: inline-block; width: 8px; height: 8px; margin-right: 6px;
    border-radius: 50%; background: var(--pine);
}
.ghost { background: transparent; border-color: var(--line); color: var(--ink); text-decoration: none; }
.chat-top .ghost { background: var(--card); }
.ghost:hover { border-color: var(--accent); }

.transcript {
    flex: 1;
    overflow: auto;
    padding: 18px 4px 8px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.bubble { max-width: min(640px, 88%); display: flex; flex-direction: column; gap: 6px; }
.bubble p {
    margin: 0;
    white-space: pre-wrap;
    line-height: 1.5;
    padding: 12px 14px;
    border-radius: 7px;
}
.bubble time { font-size: 12px; color: var(--ink-soft); }
.bubble.customer { align-self: flex-end; align-items: flex-end; }
.bubble.customer p { background: var(--accent); color: white; }
.bubble.assistant { align-self: flex-start; }
.bubble.assistant p { background: var(--card); border: 1px solid var(--line); color: var(--ink); }
.bubble.assistant a, .bubble.system a { color: #b7baff; }
.bubble.system { align-self: center; max-width: 100%; }
.bubble.system p {
    background: transparent; color: var(--ink-soft); font-size: 14px; text-align: center; padding: 4px 8px;
}
.typing { align-self: flex-start; color: var(--ink-soft); font-size: 14px; }

.actions { min-height: 0; }
.decision {
    margin: 8px 0 12px;
    padding: 18px;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 7px;
    box-shadow: var(--shadow);
    animation: rise 0.22s ease;
}
.decision h3 { font-size: 22px; margin-bottom: 6px; color: white; }
.decision p { color: var(--ink-soft); margin-bottom: 14px; line-height: 1.45; }
.choice-row { display: flex; flex-wrap: wrap; gap: 8px; }
.choice-row button, .card > button, .login-card button, .composer button, .button-row button {
    background: var(--accent); color: white; border: 0; font-weight: 700;
}
.choice-row button:hover, .card > button:hover, .login-card button:hover, .composer button:hover, .button-row button:hover {
    background: var(--accent-dark);
}
.choice-row button.secondary, .ghost {
    background: transparent; color: var(--ink); border: 1px solid var(--line);
}
.choice-row a {
    display: inline-flex; align-items: center; text-decoration: none;
    background: var(--accent); color: white; font-weight: 700;
}
.choice-row a.secondary-link {
    background: #292734; color: #9aa0ff; border: 1px solid rgba(64, 65, 197, 0.45);
}
.composer {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px;
    padding-top: 4px;
}
textarea, input[type="text"], input[type="password"], input[type="search"], input[type="tel"], input[type="url"], input:not([type]) {
    width: 100%;
    border: 1px solid var(--line);
    background: #0c0c12;
    border-radius: 7px;
    padding: 12px 14px;
    outline: none;
}
textarea { resize: none; min-height: 52px; max-height: 140px; }
textarea:focus, input:focus, select:focus { border-color: var(--accent); }
.composer button { padding-inline: 18px; }

.page-desk { background: var(--paper); }
.page-desk, .page-desk button, .page-desk input, .page-desk textarea, .page-desk select {
    font-family: "Manrope", "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
}
.page-desk h1, .page-desk h2, .page-desk h3 {
    font-family: "Manrope", "PingFang SC", "Microsoft YaHei", sans-serif;
}
.page-desk select {
    width: 100%;
    border: 1px solid var(--line);
    background: #0c0c12;
    border-radius: 7px;
    padding: 12px 14px;
}
.desk-bar {
    padding: 16px 28px;
    background: #000;
    color: var(--ink);
    border-bottom: 1px solid var(--line);
}
.desk-nav { display: flex; gap: 6px; flex-wrap: wrap; }
.desk-nav[hidden], .desk-view[hidden] { display: none; }
.desk-nav button {
    background: transparent;
    border: 1px solid var(--line);
    color: var(--ink);
    border-radius: 7px;
    padding: 8px 14px;
    font-weight: 700;
}
.desk-nav button.active { background: var(--accent); border-color: var(--accent); color: white; }
.settings-card { margin-top: 16px; }
.transcript-log { display: flex; flex-direction: column; gap: 12px; margin: 14px 0; }
.transcript-line strong { display: block; margin-bottom: 4px; color: var(--orange); font-size: 12px; }
.transcript-line p { white-space: pre-wrap; line-height: 1.5; }
.brand.compact { color: inherit; text-decoration: none; gap: 12px; }
.brand.compact strong { display: block; font-size: 18px; font-weight: 800; color: white; }
.brand.compact em { font-style: normal; color: var(--orange); font-size: 12px; letter-spacing: 0.08em; }
.desk, .login-wrap { max-width: 1240px; margin: 0 auto; padding: 28px 20px 60px; }
.login-wrap { min-height: calc(100vh - 90px); display: grid; place-items: center; }
.login-card { width: min(460px, 100%); }
.card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 7px;
    padding: 20px;
    box-shadow: var(--shadow);
}
.card h2 { font-size: 26px; margin-bottom: 8px; color: white; }
.muted { color: var(--ink-soft); line-height: 1.45; margin-bottom: 12px; }
label { display: block; font-size: 13px; font-weight: 700; margin: 12px 0 6px; }
.check { display: flex; gap: 8px; align-items: center; font-weight: 500; }
.check input { width: auto; }
.card > button, .button-row button, .login-card button { margin-top: 14px; }
.desk-grid { display: grid; grid-template-columns: 1.1fr 0.9fr; gap: 16px; margin: 16px 0; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.stat-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.stat { padding: 16px 18px; }
.stat b { display: block; font-size: 32px; font-weight: 800; color: white; }
.stat span { color: var(--ink-soft); font-size: 13px; }
.category-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 12px; }
details { margin-top: 12px; }
summary { cursor: pointer; font-weight: 700; }
.table-card { margin-bottom: 16px; }
.table-card .table-head { align-items: flex-end; margin-bottom: 14px; }
.table-card .table-head h2 { font-size: 22px; }
.table-head input { width: min(320px, 100%); }
.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: top; font-size: 14px; }
th { color: var(--ink-soft); font-size: 12px; letter-spacing: 0.04em; text-transform: uppercase; }
.kb-table { table-layout: fixed; min-width: 760px; }
.kb-table .col-topic { width: 112px; }
.kb-table .col-source { width: 120px; }
.kb-table .col-count { width: 84px; }
.kb-table .col-actions { width: 156px; }
.kb-table th, .kb-table td { vertical-align: middle; padding: 12px 14px; }
.kb-table th {
    text-transform: none;
    letter-spacing: 0;
    font-size: 13px;
    font-weight: 700;
    white-space: nowrap;
    background: #0c0c12;
}
.kb-table tbody tr:hover td { background: rgba(255, 255, 255, 0.035); }
.kb-table tr.is-inactive td { opacity: 0.55; }
.kb-table td.question p {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    line-height: 1.5;
    overflow-wrap: anywhere;
}
.kb-table td.topic, .kb-table td.source-cell { white-space: nowrap; }
.kb-table th.num, .kb-table td.num { text-align: center; font-variant-numeric: tabular-nums; }
.kb-table th.actions, .kb-table td.actions { text-align: right; }
.source { display: inline-block; white-space: nowrap; font-size: 12px; border-radius: 7px; padding: 3px 8px; background: #292734; color: #d2d7dc; }
.source.learned { background: var(--pine-soft); color: var(--pine); }
.source.whatsapp { background: rgba(113, 64, 197, 0.2); color: #d2c4ff; }
.source.manual { background: rgba(231, 106, 31, 0.16); color: #ffc7a3; }
.source.starter { background: rgba(64, 65, 197, 0.22); color: #c5c6ff; }
.row-actions { display: flex; gap: 6px; flex-wrap: nowrap; justify-content: flex-end; }
.row-actions button { white-space: nowrap; padding: 6px 10px; border-radius: 7px; }
.pager { margin-top: 12px; }
.chat-log { display: flex; flex-direction: column; gap: 10px; }
.chat-item { border: 1px solid var(--line); border-radius: 7px; padding: 10px 12px; }
.chat-item button { margin-top: 8px; }
.overlay {
    position: fixed; inset: 0; background: rgba(0, 0, 0, 0.72);
    display: grid; place-items: center; padding: 20px;
}
.overlay[hidden] { display: none; }
.editor { width: min(680px, 100%); max-height: 90vh; overflow: auto; }
.error-note { color: var(--orange); min-height: 0; }
.error-note:not([hidden]) { margin-top: 8px; }
.preview-item { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--line); }
.preview-item strong { display: block; margin-bottom: 4px; }

@keyframes rise {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
    .decision { animation: none; }
}
@media (max-width: 860px) {
    .shell { grid-template-columns: 1fr; }
    .rail { padding: 18px; border-right: 0; border-bottom: 1px solid var(--line); }
    .topics { flex-direction: row; overflow: auto; }
    .topics button { white-space: nowrap; }
    .rail-foot { margin-top: 8px; }
    .chat { min-height: auto; height: calc(100vh - 280px); }
    .desk-grid, .stat-row, .category-grid { grid-template-columns: 1fr; }
    .desk-bar { align-items: flex-start; flex-direction: column; }
    .desk-nav { width: 100%; }
}
