:root {
    --bg: #0e0f13;
    --panel: #16181f;
    --panel-2: #1c1f28;
    --border: #262a35;
    --text: #e7e9ee;
    --muted: #9aa0ad;
    --accent: #7c5cff;
    --accent-ink: #ffffff;
    --radius: 12px;
    color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    font-size: 16px;
    line-height: 1.5;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.shell {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.topbar {
    display: flex;
    align-items: center;
    padding: 14px 24px;
    border-bottom: 1px solid var(--border);
    background: var(--panel);
}

.brand { font-weight: 700; letter-spacing: 0.2px; }
.brand-sub { color: var(--accent); font-weight: 600; }

.content {
    flex: 1;
    width: 100%;
    max-width: 860px;
    margin: 0 auto;
    padding: 48px 24px;
}

.foot {
    padding: 16px 24px;
    border-top: 1px solid var(--border);
    color: var(--muted);
    font-size: 0.85rem;
}

.hero h1 { font-size: 2rem; margin: 0 0 12px; }
.lead { font-size: 1.1rem; color: var(--text); max-width: 60ch; }
.muted { color: var(--muted); }

.card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
}

.btn {
    display: inline-block;
    padding: 10px 16px;
    border-radius: 8px;
    background: var(--accent);
    color: var(--accent-ink);
    border: none;
    font-weight: 600;
    cursor: pointer;
    text-align: center;
}
.btn:hover { text-decoration: none; filter: brightness(1.08); }
.btn.ghost { background: var(--panel-2); color: var(--text); border: 1px solid var(--border); }

.back-link { margin-left: auto; color: var(--muted); font-size: 0.9rem; }

/* Page scaffold */
.page { display: flex; flex-direction: column; gap: 8px; }
.page.narrow { max-width: 680px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.page-head h1 { font-size: 1.5rem; margin: 4px 0; }
.expectation { margin-top: -4px; }

.empty { text-align: left; }
.empty p { margin: 6px 0; }

/* Ticket list */
.ticket-list { list-style: none; padding: 0; margin: 12px 0 0; display: flex; flex-direction: column; gap: 8px; }
.ticket-row { }
.ticket-link {
    display: grid;
    grid-template-columns: auto 1fr auto auto;
    gap: 12px;
    align-items: center;
    padding: 14px 16px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 10px;
    color: var(--text);
}
.ticket-link:hover { text-decoration: none; border-color: var(--accent); }
.ticket-ref { font-family: ui-monospace, "Cascadia Code", monospace; color: var(--muted); font-size: 0.85rem; }
.ticket-subject { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ticket-updated { font-size: 0.85rem; white-space: nowrap; }

/* Status chips */
.chip {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 600;
    white-space: nowrap;
    border: 1px solid transparent;
}
.chip-new     { background: #1e2a44; color: #9dc0ff; border-color: #2c3f66; }
.chip-open    { background: #24303a; color: #7fd6ff; border-color: #335063; }
.chip-waiting { background: #3a3320; color: #e9c66b; border-color: #5b4f2c; }
.chip-solved  { background: #1f3a2a; color: #7fe0a0; border-color: #2e563d; }
.chip-closed  { background: #2a2d36; color: #9aa0ad; border-color: #3a3f4b; }

/* AI triage (T6) — advisory chips + summary */
.chip.urgency { text-transform: capitalize; }
.urgency-low    { background: #23282f; color: #9aa0ad; border-color: #363c46; }
.urgency-normal { background: #24303a; color: #8bbcd6; border-color: #335063; }
.urgency-high   { background: #3a3320; color: #e9c66b; border-color: #5b4f2c; }
.urgency-urgent { background: #3a2224; color: #f08a8a; border-color: #5f3236; }
.ai-summary { margin-left: 8px; font-weight: 400; font-size: 0.85em; }
.ai-triage { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 10px 0; padding: 10px 14px; }
.ai-badge { font-size: 0.8em; color: #b79cff; font-weight: 600; }
.draft-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 6px; }
.sm { font-size: 0.85em; }

/* API keys (T7) */
.mint { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin: 12px 0; }
.key-reveal .key-plain { display: inline-block; margin-top: 4px; padding: 4px 8px; border-radius: 6px;
    background: #10151f; color: #7fe0a0; font-family: ui-monospace, monospace; user-select: all; word-break: break-all; }
.key-list { list-style: none; padding: 0; margin: 16px 0; display: flex; flex-direction: column; gap: 8px; }
.key-row { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border: 1px solid var(--border);
    border-radius: 10px; background: var(--panel); }
.key-row.revoked { opacity: 0.55; }
.key-row code { font-family: ui-monospace, monospace; }
.key-row .btn { margin-left: auto; }

/* Thread */
.thread { display: flex; flex-direction: column; gap: 12px; margin: 16px 0; }
.msg { border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; background: var(--panel); }
.msg-user { border-left: 3px solid var(--accent); }
.msg-agent { border-left: 3px solid #7fd6ff; background: var(--panel-2); }
.msg-system { border-left: 3px solid var(--muted); background: transparent; }
.msg-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 6px; }
.msg-author { font-weight: 700; }
.msg-time { font-size: 0.8rem; }
.msg-body { line-height: 1.55; }
.msg-body :first-child { margin-top: 0; }
.msg-body :last-child { margin-bottom: 0; }
.msg-body pre { background: #0b0c10; padding: 12px; border-radius: 8px; overflow-x: auto; }
.msg-body code { background: #0b0c10; padding: 2px 5px; border-radius: 4px; }
.msg-body pre code { background: none; padding: 0; }

/* Forms */
.field { display: flex; flex-direction: column; gap: 6px; margin: 14px 0; }
.label { font-weight: 600; font-size: 0.9rem; }
.input {
    width: 100%;
    padding: 10px 12px;
    background: var(--panel-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font: inherit;
}
.input:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent); }
.textarea { resize: vertical; min-height: 90px; }

.banner { padding: 10px 14px; border-radius: 8px; margin: 12px 0; }
.banner.err { background: #3a1f24; color: #ffb4bd; border: 1px solid #5b2c34; }
.banner.info { background: #1e2a44; color: #bcd4ff; border: 1px solid #2c3f66; }
.validation-message { color: #ffb4bd; font-size: 0.85rem; }

@media (max-width: 560px) {
    .ticket-link { grid-template-columns: 1fr auto; }
    .ticket-ref, .ticket-updated { grid-column: 1 / -1; }
}

/* Agent surface */
.agent-shell .topbar { gap: 20px; }
.agent-nav { display: flex; gap: 16px; }
.agent-nav a { color: var(--text); }
.agent-who { margin-left: auto; font-size: 0.85rem; }
.agent-content { max-width: 900px; }
.filters { display: flex; gap: 8px; }
.filters .input { width: auto; }
.ctx { display: flex; gap: 14px; flex-wrap: wrap; font-size: 0.85rem; margin: 8px 0; }
.msg-internal { border-left-color: #e9c66b !important; background: #221f14; }
.composer { margin-top: 16px; display: flex; flex-direction: column; gap: 10px; }
.chk { display: flex; align-items: center; gap: 8px; font-size: 0.9rem; color: var(--muted); }
.actions { display: flex; gap: 10px; flex-wrap: wrap; }
.btn.sm { padding: 4px 10px; font-size: 0.85rem; }
.canned-list { list-style: none; padding: 0; display: flex; flex-direction: column; gap: 10px; margin: 16px 0 0; }
.canned-body { white-space: pre-wrap; background: #0b0c10; padding: 10px; border-radius: 6px; margin: 8px 0 0; font-size: 0.85rem; }

/* Attachments */
.dropzone { border: 1px dashed var(--border); border-radius: 8px; padding: 12px; background: var(--panel-2); }
.dropzone.drag { border-color: var(--accent); background: #1c2030; }
.att-add { display: inline-block; padding: 6px 12px; border: 1px solid var(--border); border-radius: 6px; cursor: pointer; font-size: 0.9rem; }
.att-hint { font-size: 0.8rem; margin: 8px 0 0; }
.att-list, .att-compose { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 0; align-items: center; }
.att-chip { background: var(--panel); border: 1px solid var(--border); border-radius: 999px; padding: 3px 10px; font-size: 0.8rem; }
.att-status { font-size: 0.8rem; }
.attachments { display: flex; flex-wrap: wrap; gap: 10px; margin: 10px 0 0; }
.att-thumb { max-width: 220px; max-height: 220px; border-radius: 8px; border: 1px solid var(--border); display: block; }
.att-file { display: inline-block; padding: 6px 12px; background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; font-size: 0.85rem; }
.att-compose { margin-top: 4px; }
