/* ==========================================================================
   Helpdesk — design system
   A dense, calm, agent-first workspace. No framework, no CDN.
   ========================================================================== */

:root {
  --ink: #10151f;
  --ink-2: #3d4757;
  --ink-3: #6b7687;
  --ink-4: #97a1b0;
  --line: #e4e8ee;
  --line-2: #eef1f5;
  --bg: #f6f8fa;
  --panel: #ffffff;
  --panel-2: #fafbfc;

  --brand: #3b6fe0;
  --brand-ink: #2b55b5;
  --brand-soft: #eaf0fe;

  --ok: #12805c;
  --ok-soft: #e2f5ee;
  --warn: #b26a00;
  --warn-soft: #fdf1dd;
  --bad: #c0392f;
  --bad-soft: #fdeceb;
  --info: #0b6f96;
  --info-soft: #e3f2f8;

  --sidebar: #141a24;
  --sidebar-2: #1d2531;
  --sidebar-ink: #9aa6b8;

  --radius: 10px;
  --radius-sm: 7px;
  --shadow: 0 1px 2px rgba(16, 21, 31, .06), 0 4px 14px rgba(16, 21, 31, .05);
  --shadow-lg: 0 8px 40px rgba(16, 21, 31, .18);
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sidebar-w: 232px;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

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

h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }
h1 { font-size: 21px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }

button, input, select, textarea { font: inherit; color: inherit; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #cfd6df; border-radius: 6px; border: 2px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: #b3bdc9; background-clip: content-box; }
::-webkit-scrollbar-track { background: transparent; }

/* ------------------------------------------------------------- layout -- */

.app { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--sidebar);
  color: #dfe5ee;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.brand {
  display: flex; align-items: center; gap: 10px;
  padding: 18px 18px 16px;
  font-weight: 700; font-size: 15px; letter-spacing: -0.01em;
  color: #fff;
}
.brand-mark {
  width: 26px; height: 26px; border-radius: 8px;
  background: linear-gradient(135deg, #5b8def, #7dd3a0);
  display: grid; place-items: center;
  color: #0d1219; font-weight: 800; font-size: 13px;
}

.nav { padding: 4px 10px 16px; flex: 1; }
.nav-group { margin-top: 14px; }
.nav-group-title {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em;
  color: #5f6b7d; padding: 8px 10px 4px; font-weight: 600;
}
.nav a {
  display: flex; align-items: center; gap: 9px;
  padding: 7px 10px; margin: 1px 0;
  border-radius: var(--radius-sm);
  color: var(--sidebar-ink); font-size: 13px; font-weight: 500;
  text-decoration: none;
}
.nav a:hover { background: var(--sidebar-2); color: #fff; text-decoration: none; }
.nav a.active { background: var(--brand); color: #fff; }
.nav a svg { width: 16px; height: 16px; flex: 0 0 16px; opacity: .9; }
.nav .badge {
  margin-left: auto; background: rgba(255,255,255,.14); color: #fff;
  border-radius: 20px; padding: 0 7px; font-size: 11px; font-weight: 600; line-height: 18px;
}
.nav a.active .badge { background: rgba(255,255,255,.22); }

.sidebar-foot { padding: 12px 14px 16px; border-top: 1px solid #232b38; }
.user-chip { display: flex; align-items: center; gap: 9px; }
.avatar {
  width: 30px; height: 30px; border-radius: 50%;
  display: grid; place-items: center;
  color: #fff; font-size: 12px; font-weight: 700; flex: 0 0 30px;
}
.user-chip .name { font-size: 12.5px; font-weight: 600; color: #e6ebf2; line-height: 1.25; }
.user-chip .role { font-size: 11px; color: #6f7c8f; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  height: 58px; background: var(--panel); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 14px; padding: 0 22px;
  position: sticky; top: 0; z-index: 30;
}
.topbar h1 { font-size: 17px; }
.topbar .spacer { flex: 1; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }

.content { padding: 22px; max-width: 1440px; width: 100%; }

/* -------------------------------------------------------------- cards -- */

.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.card-head {
  display: flex; align-items: center; gap: 12px;
  padding: 13px 16px; border-bottom: 1px solid var(--line-2);
}
.card-head h2 { font-size: 13.5px; }
.card-head .spacer { flex: 1; }
.card-body { padding: 16px; }
.card-body.tight { padding: 0; }

.grid { display: grid; gap: 16px; }
.grid.c2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.c3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.c4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid.c5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.grid.side { grid-template-columns: minmax(0, 1fr) 340px; align-items: start; }
@media (max-width: 1180px) {
  .grid.c5, .grid.c4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.side { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 760px) {
  .grid.c2, .grid.c3, .grid.c4, .grid.c5 { grid-template-columns: minmax(0, 1fr); }
  .sidebar { display: none; }
}

/* --------------------------------------------------------------- stat -- */

.stat { padding: 14px 16px; }
.stat .label { font-size: 11.5px; color: var(--ink-3); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.stat .value { font-size: 26px; font-weight: 680; letter-spacing: -0.02em; margin-top: 4px; line-height: 1.1; }
.stat .hint { font-size: 12px; color: var(--ink-4); margin-top: 2px; }
.stat.clickable { cursor: pointer; transition: border-color .12s, transform .12s; }
.stat.clickable:hover { border-color: var(--brand); transform: translateY(-1px); }
.stat.accent-bad .value { color: var(--bad); }
.stat.accent-warn .value { color: var(--warn); }
.stat.accent-ok .value { color: var(--ok); }

/* -------------------------------------------------------------- table -- */

.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--ink-4); font-weight: 650; padding: 9px 14px;
  border-bottom: 1px solid var(--line); background: var(--panel-2);
  position: sticky; top: 0;
}
.table td { padding: 10px 14px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
.table tbody tr:hover { background: #fbfcfe; }
.table tbody tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table tr.clickable { cursor: pointer; }

/* -------------------------------------------------------------- pills -- */

.pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 9px; border-radius: 20px;
  font-size: 11.5px; font-weight: 600; line-height: 18px;
  background: var(--line-2); color: var(--ink-2); white-space: nowrap;
}
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.info { background: var(--info-soft); color: var(--info); }
.pill.brand { background: var(--brand-soft); color: var(--brand-ink); }
.pill.dot::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

.tag {
  display: inline-block; padding: 1px 7px; border-radius: 5px;
  background: var(--line-2); color: var(--ink-2);
  font-size: 11.5px; font-weight: 550;
}

/* ------------------------------------------------------------ buttons -- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 7px 13px; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  font-size: 13px; font-weight: 570; cursor: pointer;
  transition: background .12s, border-color .12s, color .12s;
  white-space: nowrap;
}
.btn:hover { background: var(--panel-2); border-color: #cfd6df; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-ink); border-color: var(--brand-ink); }
.btn.danger { color: var(--bad); border-color: #f0cfcc; background: #fff; }
.btn.danger:hover { background: var(--bad-soft); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--line-2); }
.btn.sm { padding: 4px 9px; font-size: 12px; }
.btn.icon { padding: 6px; }
.btn svg { width: 15px; height: 15px; }

.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ------------------------------------------------------------- inputs -- */

.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 12px; font-weight: 600; color: var(--ink-2); }
.input, .select, .textarea {
  width: 100%; padding: 7px 10px;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: #fff; font-size: 13px; color: var(--ink);
  transition: border-color .12s, box-shadow .12s;
}
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(59, 111, 224, .13);
}
.textarea { resize: vertical; min-height: 78px; font-family: inherit; }
.select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236b7687' d='M6 8.5 2 4.5h8z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 9px center; padding-right: 26px; }
.form-grid { display: grid; gap: 13px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 680px) { .form-grid { grid-template-columns: 1fr; } }

.filters { display: flex; gap: 9px; flex-wrap: wrap; align-items: center; }
.filters .input, .filters .select { width: auto; min-width: 140px; }
.filters .grow { flex: 1; min-width: 220px; }

/* ------------------------------------------------------------- tables -- */

.list { display: flex; flex-direction: column; }
.list-row {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 16px; border-bottom: 1px solid var(--line-2);
  cursor: pointer;
}
.list-row:hover { background: var(--panel-2); }
.list-row:last-child { border-bottom: 0; }
.list-row .grow { flex: 1; min-width: 0; }
.list-row .title { font-weight: 570; font-size: 13.5px; }
.list-row .meta { font-size: 12px; color: var(--ink-3); display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* -------------------------------------------------------------- misc -- */

.empty { padding: 40px 20px; text-align: center; color: var(--ink-4); font-size: 13px; }
.muted { color: var(--ink-3); }
.dim { color: var(--ink-4); }
.small { font-size: 12px; }
.mono { font-family: var(--mono); font-size: 12px; }
.row { display: flex; align-items: center; gap: 8px; }
.row.wrap { flex-wrap: wrap; }
.col { display: flex; flex-direction: column; gap: 8px; }
.spacer { flex: 1; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.center { text-align: center; }
.hidden { display: none !important; }
.mt { margin-top: 14px; }
.mb { margin-bottom: 14px; }

.kv { display: grid; grid-template-columns: 132px minmax(0, 1fr); gap: 8px 14px; font-size: 13px; }
.kv dt { color: var(--ink-3); font-weight: 550; }
.kv dd { margin: 0; }

.hr { height: 1px; background: var(--line-2); border: 0; margin: 16px 0; }

/* ------------------------------------------------------------- login -- */

.login-wrap {
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background:
    radial-gradient(900px 500px at 12% -10%, #dfe8fb 0%, transparent 60%),
    radial-gradient(700px 420px at 96% 110%, #ddf3ea 0%, transparent 60%),
    var(--bg);
}
.login-card { width: 100%; max-width: 400px; }
.login-card .card-body { padding: 26px; }
.login-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 20px; }
.login-brand .brand-mark { width: 34px; height: 34px; font-size: 15px; border-radius: 10px; }
.demo-accounts { margin-top: 18px; border-top: 1px solid var(--line-2); padding-top: 14px; }
.demo-accounts button {
  display: flex; width: 100%; gap: 8px; align-items: center;
  padding: 6px 8px; border: 0; background: transparent; border-radius: 6px;
  cursor: pointer; font-size: 12.5px; text-align: left; color: var(--ink-2);
}
.demo-accounts button:hover { background: var(--line-2); }

.alert {
  padding: 9px 12px; border-radius: var(--radius-sm); font-size: 12.5px;
  background: var(--bad-soft); color: var(--bad); border: 1px solid #f5d5d2;
}
.alert.info { background: var(--info-soft); color: var(--info); border-color: #cfe6ef; }
.alert.warn { background: var(--warn-soft); color: var(--warn); border-color: #f3e0bd; }

/* ------------------------------------------------------------ modal -- */

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(16, 21, 31, .42);
  display: grid; place-items: center; padding: 20px; z-index: 100;
  animation: fade .12s ease;
}
.modal {
  width: 100%; max-width: 520px; max-height: 86vh; overflow: auto;
  background: var(--panel); border-radius: 12px; box-shadow: var(--shadow-lg);
}
.modal.wide { max-width: 780px; }
.modal-head { display: flex; align-items: center; padding: 16px 18px; border-bottom: 1px solid var(--line-2); }
.modal-head h2 { flex: 1; font-size: 15px; }
.modal-body { padding: 18px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 18px; border-top: 1px solid var(--line-2); }

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

/* ------------------------------------------------------------ toasts -- */

.toasts { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast {
  background: var(--ink); color: #fff; padding: 10px 14px;
  border-radius: var(--radius-sm); font-size: 13px; box-shadow: var(--shadow-lg);
  animation: rise .16s ease; max-width: 340px;
}
.toast.bad { background: var(--bad); }
.toast.ok { background: var(--ok); }

/* ---------------------------------------------------------- ticket -- */

.ticket-head { display: flex; gap: 16px; align-items: flex-start; }
.ticket-head h1 { font-size: 19px; line-height: 1.3; }
.ticket-layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 16px; align-items: start; }
@media (max-width: 1080px) { .ticket-layout { grid-template-columns: 1fr; } }

.conversation {
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 14px; margin-bottom: 10px; background: var(--panel);
}
.conversation.inbound { background: #f9fbff; border-color: #dbe6fb; }
.conversation.note { background: var(--warn-soft); border-color: #f0dfbd; }
.conversation-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; font-size: 12px; color: var(--ink-3); }
.conversation-body { font-size: 13.5px; line-height: 1.55; white-space: pre-wrap; word-break: break-word; }

.timeline { position: relative; padding-left: 18px; }
.timeline::before { content: ''; position: absolute; left: 4px; top: 6px; bottom: 6px; width: 2px; background: var(--line); }
.timeline-item { position: relative; padding: 0 0 14px; font-size: 12.5px; }
.timeline-item::before {
  content: ''; position: absolute; left: -18px; top: 4px;
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--panel); border: 2px solid var(--ink-4);
}
.timeline-item.accent::before { border-color: var(--brand); background: var(--brand); }
.timeline-item .when { color: var(--ink-4); font-size: 11.5px; }

.sla-meter { height: 5px; border-radius: 3px; background: var(--line-2); overflow: hidden; margin-top: 6px; }
.sla-meter > span { display: block; height: 100%; border-radius: 3px; background: var(--ok); }
.sla-meter > span.warn { background: var(--warn); }
.sla-meter > span.bad { background: var(--bad); }

/* ------------------------------------------------------------ charts -- */

.chart { width: 100%; display: block; }
.chart-legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--ink-2); }
.chart-legend i { width: 9px; height: 9px; border-radius: 2px; display: inline-block; margin-right: 5px; }

.bar-row { display: flex; align-items: center; gap: 10px; font-size: 12.5px; padding: 3px 0; }
.bar-row .label { width: 108px; color: var(--ink-2); flex: 0 0 108px; }
.bar-row .track { flex: 1; height: 8px; background: var(--line-2); border-radius: 4px; overflow: hidden; }
.bar-row .track > span { display: block; height: 100%; background: var(--brand); border-radius: 4px; }
.bar-row .value { width: 54px; text-align: right; font-variant-numeric: tabular-nums; color: var(--ink-3); }

/* ------------------------------------------------------------ agent -- */

.chat-wrap { display: flex; flex-direction: column; height: calc(100vh - 102px); }
.chat-log { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; padding: 4px 2px 12px; }
.msg { max-width: 74%; padding: 10px 13px; border-radius: 12px; font-size: 13.5px; line-height: 1.55; white-space: pre-wrap; }
.msg.user { align-self: flex-end; background: var(--brand); color: #fff; border-bottom-right-radius: 4px; }
.msg.bot { align-self: flex-start; background: var(--panel); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg.bot.tool { background: var(--panel-2); font-size: 12.5px; color: var(--ink-2); font-family: var(--mono); }
.chat-input { display: flex; gap: 8px; margin-top: 10px; }
.chat-input .input { flex: 1; }
.chip-row { display: flex; gap: 7px; flex-wrap: wrap; margin-top: 8px; }
.chip {
  padding: 4px 10px; border-radius: 20px; border: 1px solid var(--line);
  background: var(--panel); font-size: 12px; cursor: pointer; color: var(--ink-2);
}
.chip:hover { border-color: var(--brand); color: var(--brand-ink); }

/* ------------------------------------------------------------ portal -- */

.portal { min-height: 100vh; background: var(--bg); }
.portal-head { background: var(--panel); border-bottom: 1px solid var(--line); }
.portal-head-inner { max-width: 980px; margin: 0 auto; padding: 16px 22px; display: flex; align-items: center; gap: 14px; }
.portal-body { max-width: 980px; margin: 0 auto; padding: 26px 22px 60px; }
.portal-hero { text-align: center; padding: 26px 0 20px; }
.portal-hero h1 { font-size: 28px; letter-spacing: -0.02em; }
.portal-hero p { color: var(--ink-3); margin: 7px 0 0; }
.portal-search { max-width: 620px; margin: 20px auto 0; position: relative; }
.portal-search .input { padding: 12px 14px; font-size: 15px; border-radius: 10px; }
.portal-tabs { display: flex; gap: 6px; justify-content: center; margin-top: 16px; }
.portal-tabs button {
  padding: 6px 14px; border-radius: 20px; border: 1px solid var(--line);
  background: var(--panel); cursor: pointer; font-size: 13px; color: var(--ink-2);
}
.portal-tabs button.active { background: var(--brand); border-color: var(--brand); color: #fff; }
.portal-article { max-width: 720px; margin: 0 auto; }
.portal-article h1 { font-size: 24px; margin-bottom: 12px; }
.portal-article .body { font-size: 15px; line-height: 1.65; color: var(--ink-2); white-space: pre-wrap; }
.portal-card { padding: 20px; }
.deflect {
  margin-top: 22px; padding: 16px; border-radius: var(--radius);
  background: var(--brand-soft); border: 1px solid #cfdcfb;
}
.deflect h3 { color: var(--brand-ink); }
.deflect p { color: var(--ink-2); margin: 5px 0 12px; font-size: 13px; }

/* -------------------------------------------------------------- misc -- */

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tabs button {
  padding: 8px 13px; border: 0; background: transparent; cursor: pointer;
  font-size: 13px; font-weight: 560; color: var(--ink-3);
  border-bottom: 2px solid transparent; white-space: nowrap;
}
.tabs button:hover { color: var(--ink); }
.tabs button.active { color: var(--brand-ink); border-bottom-color: var(--brand); }

.lang-select {
  background: transparent; border: 1px solid var(--line); border-radius: 6px;
  padding: 4px 8px; font-size: 12px; cursor: pointer; color: var(--ink-2);
}

.progress { height: 6px; background: var(--line-2); border-radius: 3px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--brand); transition: width .25s; }

.split { display: grid; grid-template-columns: 200px minmax(0, 1fr); gap: 16px; align-items: start; }
.side-nav { display: flex; flex-direction: column; gap: 2px; }
.side-nav button {
  text-align: left; padding: 7px 10px; border: 0; background: transparent;
  border-radius: var(--radius-sm); cursor: pointer; font-size: 13px; color: var(--ink-2);
}
.side-nav button:hover { background: var(--line-2); }
.side-nav button.active { background: var(--brand-soft); color: var(--brand-ink); font-weight: 600; }

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