/* SupportDesk AI — design tokens, layout and components */
:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --surface-3: #f2f4f7;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --text: #111827;
  --text-2: #4b5563;
  --text-3: #8a919e;
  --brand: #4f46e5;
  --brand-hover: #4338ca;
  --brand-soft: #eef0ff;
  --brand-text: #4338ca;
  --focus: rgba(79, 70, 229, .28);

  --blue: #2563eb;   --blue-soft: #eaf1fe;
  --amber: #b45309;  --amber-soft: #fef5e4;
  --green: #15803d;  --green-soft: #e8f6ed;
  --gray: #4b5563;   --gray-soft: #f0f1f3;
  --orange: #c2410c; --orange-soft: #fff0e6;
  --red: #dc2626;    --red-soft: #fdecec;
  --violet: #6d28d9; --violet-soft: #f3edff;
  --note: #fffbeb;   --note-border: #f5e1a4;

  --series-1: #2a78d6;
  --series-2: #eb6834;
  --grid: #eceef1;

  --radius: 10px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .05);
  --shadow: 0 1px 3px rgba(16, 24, 40, .06), 0 1px 2px rgba(16, 24, 40, .04);
  --shadow-lg: 0 20px 40px -12px rgba(16, 24, 40, .22), 0 4px 10px rgba(16, 24, 40, .06);
  --sidebar-w: 248px;
  --topbar-h: 60px;
  --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0e1015; --surface: #161920; --surface-2: #1b1f27; --surface-3: #222731;
    --border: #2a2f3a; --border-strong: #3a404c;
    --text: #f1f3f6; --text-2: #b4bac5; --text-3: #7d8593;
    --brand: #6366f1; --brand-hover: #7477f5; --brand-soft: #23244a; --brand-text: #a5a8ff; --focus: rgba(99, 102, 241, .4);
    --blue: #7aa7ff; --blue-soft: #1a2741; --amber: #f2b452; --amber-soft: #33270f;
    --green: #5fd08a; --green-soft: #13301f; --gray: #b4bac5; --gray-soft: #262a33;
    --orange: #ff9a5c; --orange-soft: #3a2213; --red: #ff7b7b; --red-soft: #3b1a1c;
    --violet: #b9a3ff; --violet-soft: #2a2145; --note: #2b2512; --note-border: #5a4a1c;
    --series-1: #3987e5; --series-2: #d95926; --grid: #262a33;
    --shadow-lg: 0 20px 40px -12px rgba(0, 0, 0, .6);
  }
}
:root[data-theme="dark"] {
    color-scheme: dark;
    --bg: #0e1015; --surface: #161920; --surface-2: #1b1f27; --surface-3: #222731;
    --border: #2a2f3a; --border-strong: #3a404c;
    --text: #f1f3f6; --text-2: #b4bac5; --text-3: #7d8593;
    --brand: #6366f1; --brand-hover: #7477f5; --brand-soft: #23244a; --brand-text: #a5a8ff; --focus: rgba(99, 102, 241, .4);
    --blue: #7aa7ff; --blue-soft: #1a2741; --amber: #f2b452; --amber-soft: #33270f;
    --green: #5fd08a; --green-soft: #13301f; --gray: #b4bac5; --gray-soft: #262a33;
    --orange: #ff9a5c; --orange-soft: #3a2213; --red: #ff7b7b; --red-soft: #3b1a1c;
    --violet: #b9a3ff; --violet-soft: #2a2145; --note: #2b2512; --note-border: #5a4a1c;
    --series-1: #3987e5; --series-2: #d95926; --grid: #262a33;
    --shadow-lg: 0 20px 40px -12px rgba(0, 0, 0, .6);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.5 var(--font); -webkit-font-smoothing: antialiased;
  font-feature-settings: "cv11", "ss01";
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; letter-spacing: -.011em; }
svg { display: block; }
[hidden] { display: none !important; }
::selection { background: var(--brand-soft); }

/* ---------- Layout ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w); z-index: 40;
  display: flex; flex-direction: column; background: var(--surface);
  border-right: 1px solid var(--border); padding: 16px 12px;
  transition: transform .25s ease;
}
.main { flex: 1; min-width: 0; margin-left: var(--sidebar-w); display: flex; flex-direction: column; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; }
.brand-mark { width: 32px; height: 32px; border-radius: 9px; background: var(--brand); color: #fff; display: grid; place-items: center; }
.brand-mark svg { width: 19px; height: 19px; }
.brand-name { font-weight: 700; font-size: 16px; letter-spacing: -.02em; }
.brand-name span { color: var(--brand-text); margin-left: 3px; }

.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
.nav-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--text-3); padding: 14px 10px 6px; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px;
  color: var(--text-2); font-weight: 500; transition: background .15s, color .15s;
}
.nav a svg { width: 18px; height: 18px; flex: none; }
.nav a:hover { background: var(--surface-3); color: var(--text); }
.nav a.active { background: var(--brand-soft); color: var(--brand-text); }
.nav .count { margin-left: auto; font-size: 12px; font-weight: 600; background: var(--surface-3); color: var(--text-2); padding: 0 7px; border-radius: 99px; line-height: 20px; }
.nav a.active .count { background: var(--surface); color: var(--brand-text); }

.sidebar-foot { border-top: 1px solid var(--border); padding-top: 12px; display: grid; gap: 12px; }
.ai-status { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--text-2); padding: 8px 10px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; }
.ai-status .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-3); }
.ai-status.claude .dot { background: #22c55e; box-shadow: 0 0 0 3px rgba(34, 197, 94, .18); }
.ai-status.demo .dot { background: #f59e0b; box-shadow: 0 0 0 3px rgba(245, 158, 11, .18); }
.me { display: flex; align-items: center; gap: 10px; padding: 0 6px; }
.me-name { font-weight: 600; font-size: 13px; }
.me-role { font-size: 12px; color: var(--text-3); }

.topbar {
  position: sticky; top: 0; z-index: 30; height: var(--topbar-h);
  display: flex; align-items: center; gap: 12px; padding: 0 24px;
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.topbar .menu-btn { display: none; }
.topbar-actions { margin-left: auto; display: flex; gap: 8px; }
.search { position: relative; flex: 1; max-width: 460px; }
.search input {
  width: 100%; height: 38px; padding: 0 40px 0 36px; border-radius: 9px;
  border: 1px solid var(--border); background: var(--surface); outline: none; transition: border-color .15s, box-shadow .15s;
}
.search input::-webkit-search-cancel-button { display: none; }
.search input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--focus); }
.search-icon { position: absolute; left: 11px; top: 10px; color: var(--text-3); pointer-events: none; }
.search-icon svg { width: 18px; height: 18px; }
.search kbd { position: absolute; right: 10px; top: 9px; font: 500 11px var(--font); color: var(--text-3); border: 1px solid var(--border); border-radius: 5px; padding: 1px 6px; background: var(--surface-2); }
.search-results {
  position: absolute; top: 44px; left: 0; right: 0; background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: var(--shadow-lg); padding: 6px; max-height: 420px; overflow-y: auto; animation: pop .14s ease;
}
.sr-group { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--text-3); padding: 8px 10px 4px; }
.sr-item { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; cursor: pointer; }
.sr-item:hover, .sr-item.active { background: var(--surface-3); }
.sr-item .sr-sub { color: var(--text-3); font-size: 12.5px; margin-left: auto; white-space: nowrap; }
.sr-empty { padding: 18px; text-align: center; color: var(--text-3); }

.view { padding: 28px 32px 48px; outline: none; animation: fadeIn .22s ease; max-width: 1440px; width: 100%; margin: 0 auto; }
.view.flush { padding: 0; max-width: none; }

/* ---------- Page header ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.page-title { font-size: 24px; font-weight: 700; letter-spacing: -.022em; }
.page-sub { color: var(--text-2); margin-top: 4px; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.back-link { display: inline-flex; align-items: center; gap: 6px; color: var(--text-2); font-weight: 500; margin-bottom: 14px; }
.back-link:hover { color: var(--text); }
.back-link svg { width: 16px; height: 16px; }

/* ---------- Buttons & inputs ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px; height: 36px; padding: 0 14px;
  border-radius: 8px; border: 1px solid var(--border-strong); background: var(--surface); font-weight: 500; font-size: 13.5px;
  cursor: pointer; white-space: nowrap; transition: background .15s, border-color .15s, box-shadow .15s, transform .05s;
  box-shadow: var(--shadow-sm);
}
.btn:hover { background: var(--surface-3); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible, .icon-btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--focus); }
.btn svg { width: 16px; height: 16px; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-hover); border-color: var(--brand-hover); }
.btn.ai { background: var(--brand-soft); border-color: transparent; color: var(--brand-text); box-shadow: none; }
.btn.ai:hover { background: color-mix(in srgb, var(--brand-soft) 70%, var(--brand) 12%); }
.btn.ghost { border-color: transparent; background: transparent; box-shadow: none; }
.btn.ghost:hover { background: var(--surface-3); }
.btn.danger { color: var(--red); }
.btn.danger:hover { background: var(--red-soft); border-color: transparent; }
.btn.sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.loading { pointer-events: none; }
.btn.loading svg { animation: spin .8s linear infinite; }
.icon-btn { width: 36px; height: 36px; display: inline-grid; place-items: center; border-radius: 8px; border: 0; background: transparent; color: var(--text-2); cursor: pointer; }
.icon-btn:hover { background: var(--surface-3); color: var(--text); }
.icon-btn svg { width: 18px; height: 18px; }

.field { display: grid; gap: 6px; }
.field > label, .label { font-size: 13px; font-weight: 500; color: var(--text-2); }
.input, .select, .textarea {
  width: 100%; border: 1px solid var(--border-strong); background: var(--surface); border-radius: 8px;
  padding: 8px 11px; outline: none; transition: border-color .15s, box-shadow .15s;
}
.input, .select { height: 38px; }
.select {
  appearance: none; padding-right: 30px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238a919e' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 9px center; background-size: 15px;
}
.select.sm { height: 32px; font-size: 13px; padding: 4px 28px 4px 10px; }
.textarea { resize: vertical; min-height: 96px; line-height: 1.55; }
.input:focus, .select:focus, .textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--focus); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }
.check { display: flex; align-items: center; gap: 8px; font-size: 13.5px; color: var(--text-2); cursor: pointer; }
.check input { accent-color: var(--brand); width: 16px; height: 16px; }

/* ---------- Cards ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.card-title { font-size: 15px; font-weight: 600; }
.card-sub { color: var(--text-3); font-size: 12.5px; margin-top: 2px; }
.card-body { padding: 20px; }
.card-link { color: var(--brand-text); font-weight: 500; font-size: 13px; }
.card-link:hover { text-decoration: underline; }

.grid { display: grid; gap: 20px; }
.grid.kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.grid.two { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.grid.halves { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.stack { display: grid; gap: 20px; align-content: start; }

.kpi { padding: 18px 20px; }
.kpi-top { display: flex; align-items: center; justify-content: space-between; color: var(--text-2); font-weight: 500; font-size: 13px; }
.kpi-icon { width: 32px; height: 32px; border-radius: 8px; display: grid; place-items: center; background: var(--surface-3); color: var(--text-2); }
.kpi-icon svg { width: 17px; height: 17px; }
.kpi-value { font-size: 28px; font-weight: 700; letter-spacing: -.03em; margin-top: 8px; font-variant-numeric: tabular-nums; }
.kpi-foot { font-size: 12.5px; color: var(--text-3); margin-top: 2px; display: flex; gap: 6px; align-items: center; }
.delta { font-weight: 600; }
.delta.up { color: var(--green); }
.delta.down { color: var(--red); }

/* ---------- Badges / avatars ---------- */
.badge { display: inline-flex; align-items: center; gap: 6px; height: 22px; padding: 0 8px; border-radius: 6px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.b-open { color: var(--blue); background: var(--blue-soft); }
.b-pending { color: var(--amber); background: var(--amber-soft); }
.b-resolved { color: var(--green); background: var(--green-soft); }
.b-closed { color: var(--gray); background: var(--gray-soft); }
.p-low { color: var(--gray); background: var(--gray-soft); }
.p-medium { color: var(--blue); background: var(--blue-soft); }
.p-high { color: var(--orange); background: var(--orange-soft); }
.p-urgent { color: var(--red); background: var(--red-soft); }
.b-neutral { color: var(--text-2); background: var(--surface-3); }
.b-brand { color: var(--brand-text); background: var(--brand-soft); }
.b-plan { color: var(--violet); background: var(--violet-soft); }
.prio { display: inline-flex; align-items: center; gap: 6px; font-weight: 500; font-size: 13px; white-space: nowrap; }
.prio-bars { display: inline-flex; gap: 2px; align-items: flex-end; height: 12px; }
.prio-bars i { width: 3px; border-radius: 1px; background: var(--border-strong); }
.prio-bars i:nth-child(1) { height: 5px; } .prio-bars i:nth-child(2) { height: 8px; } .prio-bars i:nth-child(3) { height: 11px; }
.prio.low .prio-bars i:nth-child(-n+1), .prio.medium .prio-bars i:nth-child(-n+2) { background: var(--blue); }
.prio.low .prio-bars i:nth-child(1) { background: var(--gray); }
.prio.high .prio-bars i { background: var(--orange); }
.prio.urgent { color: var(--red); }
.prio.urgent svg { width: 14px; height: 14px; }
.tag { display: inline-flex; align-items: center; gap: 4px; height: 22px; padding: 0 8px; border-radius: 99px; font-size: 12px; background: var(--surface-3); color: var(--text-2); border: 1px solid var(--border); }
.tag button { border: 0; background: none; padding: 0; cursor: pointer; color: var(--text-3); line-height: 1; font-size: 14px; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }

.avatar {
  --h: 220; width: 36px; height: 36px; border-radius: 50%; flex: none; display: grid; place-items: center;
  font-weight: 600; font-size: 13px; color: hsl(var(--h) 55% 35%); background: hsl(var(--h) 70% 92%);
}
.avatar.sm { width: 28px; height: 28px; font-size: 11px; }
.avatar.lg { width: 56px; height: 56px; font-size: 19px; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .avatar { color: hsl(var(--h) 80% 82%); background: hsl(var(--h) 35% 24%); }
}
:root[data-theme="dark"] .avatar { color: hsl(var(--h) 80% 82%); background: hsl(var(--h) 35% 24%); }
.agent-avatar { background: var(--brand); color: #fff; }
.person { display: flex; align-items: center; gap: 10px; min-width: 0; }
.person-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.person-sub { color: var(--text-3); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: separate; border-spacing: 0; }
.table th {
  text-align: left; font-size: 12px; font-weight: 600; color: var(--text-3); text-transform: uppercase; letter-spacing: .04em;
  padding: 10px 16px; background: var(--surface-2); border-bottom: 1px solid var(--border); white-space: nowrap;
}
.table td { padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr { transition: background .12s; }
.table tbody tr.clickable { cursor: pointer; }
.table tbody tr.clickable:hover { background: var(--surface-2); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.muted { color: var(--text-3); }
.nowrap { white-space: nowrap; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }

/* ---------- Filters / toolbars ---------- */
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.toolbar .input { max-width: 260px; }
.tabs { display: flex; gap: 2px; padding: 3px; background: var(--surface-3); border-radius: 9px; width: max-content; max-width: 100%; overflow-x: auto; }
.tabs button { border: 0; background: transparent; padding: 5px 11px; border-radius: 7px; font-weight: 500; font-size: 13px; color: var(--text-2); cursor: pointer; white-space: nowrap; }
.tabs button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.tabs button .n { color: var(--text-3); margin-left: 4px; font-weight: 500; }
.input-icon { position: relative; }
.input-icon svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--text-3); pointer-events: none; }
.input-icon .input { padding-left: 34px; }

/* ---------- Inbox ---------- */
.inbox { display: grid; grid-template-columns: 380px minmax(0, 1fr); height: calc(100vh - var(--topbar-h)); }
.inbox-list { border-right: 1px solid var(--border); background: var(--surface); display: flex; flex-direction: column; min-height: 0; }
.inbox-list-head { padding: 16px 16px 12px; border-bottom: 1px solid var(--border); display: grid; gap: 10px; }
.inbox-list-head h1 { font-size: 18px; font-weight: 700; display: flex; align-items: center; justify-content: space-between; }
.inbox-filters { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; }
.ticket-items { overflow-y: auto; flex: 1; }
.ticket-item {
  display: block; padding: 13px 16px; border-bottom: 1px solid var(--border); cursor: pointer; position: relative;
  transition: background .12s;
}
.ticket-item:hover { background: var(--surface-2); }
.ticket-item.active { background: var(--brand-soft); }
.ticket-item.active::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--brand); }
.ti-row { display: flex; align-items: center; gap: 8px; min-width: 0; }
.ti-name { font-weight: 600; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ti-time { margin-left: auto; color: var(--text-3); font-size: 12px; white-space: nowrap; }
.ti-subject { font-weight: 500; margin: 3px 0 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ti-preview { color: var(--text-3); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ti-meta { display: flex; gap: 6px; align-items: center; margin-top: 8px; }
.ti-meta .mono { color: var(--text-3); margin-left: auto; font-size: 11.5px; }
.unread-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--brand); flex: none; }

.inbox-detail { min-width: 0; min-height: 0; overflow-y: auto; background: var(--bg); }
.detail-empty { height: 100%; display: grid; place-items: center; text-align: center; color: var(--text-3); padding: 24px; }
.detail { display: grid; grid-template-columns: minmax(0, 1fr) 300px; min-height: 100%; }
.detail-main { min-width: 0; display: flex; flex-direction: column; }
.detail-head { padding: 18px 24px; border-bottom: 1px solid var(--border); background: var(--surface); }
.detail-head h2 { font-size: 19px; font-weight: 700; letter-spacing: -.018em; }
.detail-head-meta { display: flex; gap: 10px; align-items: center; color: var(--text-3); font-size: 13px; margin-top: 6px; flex-wrap: wrap; }
.detail-head-actions { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; align-items: center; }
.detail-side { border-left: 1px solid var(--border); background: var(--surface); padding: 20px; display: grid; gap: 22px; align-content: start; }
.side-section h4 { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--text-3); margin-bottom: 10px; }
.prop-list { display: grid; gap: 10px; }
.prop { display: grid; grid-template-columns: 84px 1fr; align-items: center; gap: 8px; font-size: 13px; }
.prop > span:first-child { color: var(--text-3); }
.mobile-back { display: none; }

.ai-panel { margin: 18px 24px 0; border: 1px solid color-mix(in srgb, var(--brand) 22%, var(--border)); background: linear-gradient(180deg, var(--brand-soft), var(--surface) 70%); border-radius: var(--radius-lg); padding: 14px 16px; animation: slideDown .25s ease; }
.ai-panel-head { display: flex; align-items: center; gap: 8px; font-weight: 600; color: var(--brand-text); font-size: 13px; }
.ai-panel-head svg { width: 16px; height: 16px; }
.ai-panel-head .btn { margin-left: auto; }
.ai-panel p { margin: 8px 0 0; color: var(--text); }
.ai-panel ul { margin: 8px 0 0; padding-left: 18px; color: var(--text-2); }
.ai-grid { display: flex; flex-wrap: wrap; gap: 16px; margin-top: 10px; align-items: center; }
.ai-grid > div { display: grid; gap: 4px; }
.ai-grid .label { font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-3); }
.ai-panels { display: grid; gap: 0; }
.skeleton { height: 12px; border-radius: 6px; background: linear-gradient(90deg, var(--surface-3), var(--border), var(--surface-3)); background-size: 200% 100%; animation: shimmer 1.2s infinite; margin-top: 10px; }

.thread { padding: 20px 24px; display: grid; gap: 18px; flex: 1; align-content: start; }
.msg { display: flex; gap: 12px; max-width: 760px; animation: fadeUp .25s ease; }
.msg.agent { margin-left: auto; flex-direction: row-reverse; }
.msg-body { min-width: 0; }
.msg-meta { font-size: 12.5px; color: var(--text-3); margin-bottom: 5px; display: flex; gap: 6px; align-items: center; }
.msg.agent .msg-meta { justify-content: flex-end; }
.msg-meta b { color: var(--text); font-weight: 600; }
.bubble { padding: 12px 14px; border-radius: 12px; background: var(--surface); border: 1px solid var(--border); white-space: pre-wrap; word-wrap: break-word; box-shadow: var(--shadow-sm); }
.msg.agent .bubble { background: var(--brand-soft); border-color: transparent; }
.msg.note .bubble { background: var(--note); border: 1px dashed var(--note-border); }
.thread-divider { display: flex; align-items: center; gap: 12px; color: var(--text-3); font-size: 12px; }
.thread-divider::before, .thread-divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }

.composer { margin: 0 24px 24px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow); position: sticky; bottom: 16px; }
.composer.note-mode { background: var(--note); border-color: var(--note-border); }
.composer-tabs { display: flex; gap: 4px; padding: 8px 10px 0; }
.composer-tabs button { border: 0; background: none; padding: 6px 10px; font-weight: 500; font-size: 13px; color: var(--text-3); cursor: pointer; border-radius: 6px; }
.composer-tabs button.active { color: var(--text); background: var(--surface-3); }
.composer.note-mode .composer-tabs button.active { background: color-mix(in srgb, var(--note-border) 50%, transparent); }
.composer textarea { border: 0; background: transparent; width: 100%; resize: vertical; min-height: 92px; max-height: 240px; padding: 10px 16px; outline: none; line-height: 1.55; }
.composer-bar { display: flex; align-items: center; gap: 6px; padding: 8px 10px; border-top: 1px solid var(--border); flex-wrap: wrap; }
.composer.note-mode .composer-bar { border-color: var(--note-border); }
.composer-bar .spacer { flex: 1; }
.split-btn { display: inline-flex; }
.split-btn .btn:first-child { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.split-btn .btn:last-child { border-top-left-radius: 0; border-bottom-left-radius: 0; border-left: 1px solid rgba(255, 255, 255, .25); padding: 0 8px; }

/* ---------- Dropdown ---------- */
.dropdown { position: relative; }
.menu {
  position: absolute; z-index: 50; min-width: 240px; max-width: 340px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; box-shadow: var(--shadow-lg); padding: 6px; animation: pop .14s ease; max-height: 320px; overflow-y: auto;
}
.menu.up { bottom: calc(100% + 6px); }
.menu.down { top: calc(100% + 6px); }
.menu.right { right: 0; }
.menu button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 8px 10px; border-radius: 7px; cursor: pointer; }
.menu button:hover { background: var(--surface-3); }
.menu .mi-title { font-weight: 500; font-size: 13.5px; }
.menu .mi-sub { color: var(--text-3); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- Lists ---------- */
.list { display: grid; }
.list-item { display: flex; align-items: center; gap: 12px; padding: 12px 20px; border-bottom: 1px solid var(--border); cursor: pointer; transition: background .12s; min-width: 0; }
.list-item:last-child { border-bottom: 0; }
.list-item:hover { background: var(--surface-2); }
.list-item .grow { flex: 1; min-width: 0; }
.list-title { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-sub { color: var(--text-3); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- KB / canned ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.article-card { padding: 18px 20px; display: flex; flex-direction: column; gap: 8px; cursor: pointer; transition: border-color .15s, box-shadow .15s, transform .15s; }
.article-card:hover { border-color: var(--border-strong); box-shadow: var(--shadow-lg); transform: translateY(-2px); }
.article-card h3 { font-size: 15px; font-weight: 600; }
.article-card p { margin: 0; color: var(--text-2); font-size: 13.5px; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.article-foot { display: flex; align-items: center; gap: 8px; margin-top: auto; padding-top: 6px; color: var(--text-3); font-size: 12.5px; }
.article-foot .views { margin-left: auto; display: inline-flex; gap: 4px; align-items: center; }
.article-foot svg { width: 14px; height: 14px; }
.article-body { white-space: pre-wrap; font-size: 15px; line-height: 1.7; max-width: 720px; }
.canned-card { padding: 16px 18px; display: flex; flex-direction: column; gap: 8px; }
.canned-card pre { margin: 0; font: inherit; font-size: 13px; color: var(--text-2); white-space: pre-wrap; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; max-height: 140px; overflow: hidden; }
.canned-head { display: flex; align-items: center; gap: 8px; }
.canned-head h3 { font-size: 14.5px; font-weight: 600; }
.canned-head .actions { margin-left: auto; display: flex; gap: 2px; }

/* ---------- Profile ---------- */
.profile-head { display: flex; gap: 16px; align-items: center; }
.profile-head h1 { font-size: 22px; font-weight: 700; letter-spacing: -.02em; }
.info-list { display: grid; gap: 12px; }
.info-row { display: flex; gap: 10px; align-items: center; color: var(--text-2); font-size: 13.5px; min-width: 0; }
.info-row svg { width: 16px; height: 16px; color: var(--text-3); flex: none; }
.info-row span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mini-stats { display: grid; grid-template-columns: repeat(3, 1fr); border-top: 1px solid var(--border); }
.mini-stats > div { padding: 14px 16px; text-align: center; }
.mini-stats > div + div { border-left: 1px solid var(--border); }
.mini-stats b { display: block; font-size: 20px; font-variant-numeric: tabular-nums; }
.mini-stats span { color: var(--text-3); font-size: 12px; }

/* ---------- Charts ---------- */
.chart { width: 100%; height: auto; overflow: visible; }
.chart text { font: 11px var(--font); fill: var(--text-3); }
.chart .gridline { stroke: var(--grid); }
.chart .bar { transition: opacity .15s; }
.chart .hit { fill: transparent; cursor: default; }
.chart g.col:hover .bar { opacity: .82; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12.5px; color: var(--text-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; }
.chart-tip {
  position: fixed; z-index: 100; pointer-events: none; background: var(--text); color: var(--surface); padding: 7px 10px;
  border-radius: 8px; font-size: 12.5px; box-shadow: var(--shadow-lg); white-space: nowrap; transform: translate(-50%, calc(-100% - 10px));
}
.chart-tip b { display: block; margin-bottom: 2px; }
.hbars { display: grid; gap: 12px; }
.hbar-row { display: grid; grid-template-columns: 120px 1fr 40px; gap: 12px; align-items: center; font-size: 13px; }
.hbar-track { height: 10px; background: var(--surface-3); border-radius: 99px; overflow: hidden; }
.hbar-fill { height: 100%; background: var(--series-1); border-radius: 99px; transform-origin: left; animation: grow .6s cubic-bezier(.2, .7, .2, 1); }
.hbar-row .num { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.stacked { display: flex; height: 12px; border-radius: 99px; overflow: hidden; gap: 2px; }
.stacked div { height: 100%; animation: grow .6s ease; transform-origin: left; }
.status-legend { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 16px; margin-top: 16px; }
.status-legend div { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.status-legend b { margin-left: auto; font-variant-numeric: tabular-nums; }

/* ---------- Empty / misc ---------- */
.empty { text-align: center; padding: 48px 20px; color: var(--text-3); }
.empty-icon { width: 44px; height: 44px; border-radius: 12px; background: var(--surface-3); display: grid; place-items: center; margin: 0 auto 12px; color: var(--text-3); }
.empty-icon svg { width: 22px; height: 22px; }
.empty h3 { color: var(--text); font-size: 15px; margin-bottom: 4px; }
.banner { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: 10px; background: var(--amber-soft); color: var(--amber); font-size: 13px; }
.banner svg { width: 16px; height: 16px; flex: none; margin-top: 2px; }
.divider { height: 1px; background: var(--border); margin: 4px 0; }
.stars { color: #f59e0b; letter-spacing: 1px; }
.attention-item .prio { margin-left: auto; }

/* ---------- Modal ---------- */
.modal-root:empty { display: none; }
.modal-backdrop { position: fixed; inset: 0; z-index: 80; background: rgba(15, 18, 25, .45); display: grid; place-items: center; padding: 16px; animation: fadeIn .15s ease; }
.modal { width: 100%; max-width: 560px; max-height: calc(100vh - 32px); overflow-y: auto; background: var(--surface); border-radius: 16px; box-shadow: var(--shadow-lg); animation: pop .18s ease; }
.modal.wide { max-width: 720px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px; border-bottom: 1px solid var(--border); }
.modal-head h3 { font-size: 16px; font-weight: 600; }
.modal-body { padding: 20px 22px; display: grid; gap: 14px; }
.modal-foot { display: flex; justify-content: flex-end; align-items: center; gap: 8px; padding: 14px 22px; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 16px 16px; }
.modal-foot .left { margin-right: auto; }

/* ---------- Toast ---------- */
.toasts { position: fixed; bottom: 20px; right: 20px; z-index: 90; display: grid; gap: 8px; }
.toast { display: flex; align-items: center; gap: 10px; background: var(--text); color: var(--surface); padding: 10px 14px; border-radius: 10px; box-shadow: var(--shadow-lg); font-weight: 500; font-size: 13.5px; animation: toastIn .25s ease; max-width: 360px; }
.toast svg { width: 16px; height: 16px; color: #4ade80; flex: none; }
.toast.warn svg { color: #fbbf24; }
.toast.out { animation: toastOut .2s ease forwards; }

/* ---------- Animations ---------- */
@keyframes fadeIn { from { opacity: 0; } }
@keyframes fadeUp { from { opacity: 0; transform: translateY(6px); } }
@keyframes slideDown { from { opacity: 0; transform: translateY(-6px); } }
@keyframes pop { from { opacity: 0; transform: scale(.97) translateY(4px); } }
@keyframes toastIn { from { opacity: 0; transform: translateY(10px); } }
@keyframes toastOut { to { opacity: 0; transform: translateY(10px); } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes shimmer { to { background-position: -200% 0; } }
@keyframes grow { from { transform: scaleX(0); } }
@keyframes growY { from { transform: scaleY(0); } }
.chart .bar { transform-box: fill-box; transform-origin: bottom; animation: growY .5s cubic-bezier(.2, .7, .2, 1); }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

/* ---------- Responsive ---------- */
@media (max-width: 1200px) {
  .detail { grid-template-columns: minmax(0, 1fr); }
  .detail-side { border-left: 0; border-top: 1px solid var(--border); grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
}
@media (max-width: 1080px) {
  .grid.kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.two { grid-template-columns: minmax(0, 1fr); }
  .inbox { grid-template-columns: 320px minmax(0, 1fr); }
}
@media (max-width: 860px) {
  .sidebar { transform: translateX(-100%); box-shadow: var(--shadow-lg); }
  .app.nav-open .sidebar { transform: none; }
  .scrim { position: fixed; inset: 0; z-index: 35; background: rgba(15, 18, 25, .4); display: none; }
  .app.nav-open .scrim { display: block; animation: fadeIn .2s; }
  .main { margin-left: 0; }
  .topbar .menu-btn { display: inline-grid; }
  .topbar { padding: 0 16px; gap: 8px; }
  .search kbd { display: none; }
  .view { padding: 20px 16px 40px; }
  .view.flush { padding: 0; }
  .inbox { grid-template-columns: minmax(0, 1fr); height: auto; min-height: calc(100vh - var(--topbar-h)); }
  .inbox.has-detail .inbox-list { display: none; }
  .inbox:not(.has-detail) .inbox-detail { display: none; }
  .inbox-list { border-right: 0; }
  .mobile-back { display: inline-flex; }
  .detail-head, .thread { padding-left: 16px; padding-right: 16px; }
  .ai-panel { margin-left: 16px; margin-right: 16px; }
  .composer { margin: 0 12px 16px; bottom: 8px; }
  .msg { max-width: 100%; }
  .msg .avatar { display: none; }
  .grid.halves { grid-template-columns: minmax(0, 1fr); }
  .hide-md { display: none; }
}
@media (max-width: 560px) {
  .grid.kpis { gap: 10px; }
  .kpi { padding: 14px; }
  .kpi-value { font-size: 22px; }
  .kpi-icon { display: none; }
  .hide-sm { display: none; }
  .topbar-actions .btn { padding: 0 10px; }
  .form-grid { grid-template-columns: 1fr; }
  .page-title { font-size: 20px; }
  .hbar-row { grid-template-columns: 90px 1fr 32px; }
  .table th, .table td { padding: 10px 12px; }
  .detail-side { grid-template-columns: 1fr; }
  .toasts { left: 16px; right: 16px; }
}
.grid.two.profile { grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); }
.grid.kpis.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 1080px) { .grid.two.profile { grid-template-columns: minmax(0, 1fr); } }

/* ---------- Theme switcher ---------- */
.theme-btn svg { transition: transform .3s ease; }
.theme-btn:hover svg { transform: rotate(15deg); }
.segmented { display: inline-flex; gap: 2px; padding: 3px; background: var(--surface-3); border-radius: 9px; }
.segmented button { display: inline-flex; align-items: center; gap: 6px; border: 0; background: transparent; padding: 6px 12px; border-radius: 7px; font-weight: 500; font-size: 13px; color: var(--text-2); cursor: pointer; }
.segmented button svg { width: 15px; height: 15px; }
.segmented button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
html.theme-switching *, html.theme-switching *::before, html.theme-switching *::after { transition: background-color .25s ease, border-color .25s ease, color .25s ease !important; }
