/* ============================================================
   AutoRyn Platform Admin — design system
   Dark "Nebula" theme · zero dependencies · system fonts
   ============================================================ */

:root {
  --canvas:    #070b15;
  --surface:   #0d1526;
  --surface-2: #111b31;
  --surface-3: #16223c;
  --border:    rgba(126, 166, 255, .14);
  --border-2:  rgba(126, 166, 255, .26);
  --text:      #e9eefb;
  --muted:     #8fa1c7;
  --accent:    #3ba0ff;
  --accent-2:  #2176c9;
  --grad:      linear-gradient(135deg, #3ba0ff 0%, #7c5cff 100%);
  --ok:        #34d399;
  --warn:      #fbbf24;
  --bad:       #fb7185;
  --info:      #3ba0ff;
  --violet:    #a78bfa;
  --shadow:    0 8px 30px rgba(2, 6, 18, .45);
  --r-card:    14px;
  --r-ctl:     9px;
  --sidebar-w: 236px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, 'Liberation Mono', monospace;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body { height: 100%; }

body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--canvas);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* Ambient glows */
body::before, body::after {
  content: '';
  position: fixed;
  border-radius: 50%;
  filter: blur(90px);
  pointer-events: none;
  z-index: 0;
}
body::before {
  width: 560px; height: 560px;
  top: -180px; right: -120px;
  background: radial-gradient(circle, rgba(59, 160, 255, .13), transparent 65%);
}
body::after {
  width: 640px; height: 640px;
  bottom: -260px; left: 8%;
  background: radial-gradient(circle, rgba(124, 92, 255, .10), transparent 65%);
}

::selection { background: rgba(59, 160, 255, .35); }

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

.mono  { font-family: var(--mono); font-size: .92em; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.divider { height: 1px; background: var(--border); margin: 14px 0; }

/* Scrollbars */
* { scrollbar-width: thin; scrollbar-color: rgba(126,166,255,.25) transparent; }
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-thumb { background: rgba(126,166,255,.22); border-radius: 8px; }
*::-webkit-scrollbar-track { background: transparent; }

/* ============================================================
   Login screen
   ============================================================ */
#login-screen {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  z-index: 5;
}
.login-card {
  width: 400px; max-width: 100%;
  background: rgba(13, 21, 38, .88);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 34px 32px 30px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
  position: relative;
  z-index: 2;
}
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 26px; }
.brand-mark {
  width: 42px; height: 42px; border-radius: 12px;
  background: var(--grad);
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 20px; color: #fff;
  box-shadow: 0 4px 18px rgba(59, 160, 255, .35);
}
.brand-name { font-size: 17px; font-weight: 700; letter-spacing: -.01em; }
.brand-sub  { font-size: 11px; color: var(--muted); font-family: var(--mono); text-transform: uppercase; letter-spacing: .08em; }
.login-card h2 { font-size: 20px; font-weight: 650; letter-spacing: -.01em; margin-bottom: 4px; }
.login-card .subtitle { color: var(--muted); font-size: 13px; margin-bottom: 22px; }
.login-tabs { display: flex; gap: 6px; margin-bottom: 18px; }
.login-tabs button {
  flex: 1; padding: 7px 0; font-size: 12.5px; font-weight: 600;
  background: var(--surface-2); color: var(--muted);
  border: 1px solid var(--border); border-radius: var(--r-ctl);
  cursor: pointer; transition: all .15s;
}
.login-tabs button.active { background: rgba(59,160,255,.15); color: var(--accent); border-color: rgba(59,160,255,.4); }
.login-foot { margin-top: 18px; text-align: center; font-size: 12px; color: var(--muted); }
#login-form .field + .field, #setup-form .field + .field { margin-top: 13px; }
#login-form .btn, #setup-form .btn { margin-top: 18px; }

/* ============================================================
   App shell
   ============================================================ */
#app-shell { display: flex; min-height: 100vh; position: relative; z-index: 1; }

#sidebar {
  width: var(--sidebar-w);
  position: fixed; top: 0; bottom: 0; left: 0;
  background: rgba(9, 14, 27, .82);
  border-right: 1px solid var(--border);
  backdrop-filter: blur(12px);
  display: flex; flex-direction: column;
  padding: 18px 14px 14px;
  z-index: 40;
}
.sidebar-brand { display: flex; align-items: center; gap: 11px; padding: 2px 6px 16px; }
.sidebar-brand .brand-mark { width: 36px; height: 36px; border-radius: 10px; font-size: 17px; }

.nav-section-label {
  font-size: 10.5px; font-family: var(--mono);
  text-transform: uppercase; letter-spacing: .1em;
  color: var(--muted); opacity: .75;
  padding: 14px 8px 6px;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; margin: 1px 0;
  border-radius: var(--r-ctl);
  font-size: 13.5px; font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  border: 1px solid transparent;
  transition: all .14s;
  user-select: none;
}
.nav-item svg { flex-shrink: 0; opacity: .85; }
.nav-item:hover { color: var(--text); background: rgba(126,166,255,.07); }
.nav-item.active {
  color: #fff;
  background: linear-gradient(135deg, rgba(59,160,255,.22), rgba(124,92,255,.18));
  border-color: rgba(59,160,255,.35);
}
.nav-badge {
  margin-left: auto;
  font-size: 10.5px; font-weight: 700; font-family: var(--mono);
  background: rgba(59,160,255,.18); color: var(--accent);
  padding: 1px 7px; border-radius: 999px;
}

.sidebar-foot { margin-top: auto; border-top: 1px solid var(--border); padding-top: 12px; }
.sidebar-user { display: flex; align-items: center; gap: 10px; padding: 4px 6px 10px; }
.sidebar-user .name { font-size: 13px; font-weight: 600; line-height: 1.25; }
.sidebar-user .role { font-size: 11px; color: var(--muted); }

/* Main column */
#main {
  flex: 1;
  margin-left: var(--sidebar-w);
  min-width: 0;
  display: flex; flex-direction: column;
}
#topbar {
  position: sticky; top: 0;
  display: flex; align-items: center; gap: 14px;
  padding: 16px 28px 14px;
  background: rgba(7, 11, 21, .75);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  z-index: 30;
  min-height: 66px;
}
.topbar-kicker {
  font-size: 10.5px; font-family: var(--mono);
  text-transform: uppercase; letter-spacing: .12em;
  color: var(--accent);
}
.topbar-title { font-size: 19px; font-weight: 650; letter-spacing: -.015em; line-height: 1.2; }
#topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 9px; }

.free-chip {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11.5px; font-weight: 650;
  color: var(--warn);
  background: rgba(251,191,36,.12);
  border: 1px solid rgba(251,191,36,.35);
  padding: 4px 11px; border-radius: 999px;
  cursor: pointer;
  animation: freepulse 2.6s ease-in-out infinite;
}
@keyframes freepulse { 0%,100% { box-shadow: 0 0 0 0 rgba(251,191,36,0); } 50% { box-shadow: 0 0 12px 0 rgba(251,191,36,.25); } }

#page-root { padding: 24px 28px 90px; max-width: 1460px; width: 100%; margin: 0 auto; }

/* ============================================================
   Cards / layout
   ============================================================ */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  padding: 20px;
  box-shadow: 0 2px 14px rgba(2,6,18,.25);
}
.card-tight { padding: 14px 16px; }
.card-title { font-size: 13.5px; font-weight: 650; display: flex; align-items: center; gap: 8px; }
.card-title svg { color: var(--accent); }
.card-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 14px; }

.grid { display: grid; gap: 16px; }
.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 1100px) { .cols-3, .cols-4 { grid-template-columns: repeat(2, minmax(0,1fr)); } }
@media (max-width: 760px)  { .cols-2, .cols-3, .cols-4 { grid-template-columns: 1fr; } }

.section-gap > * + * { margin-top: 16px; }

.kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
}
.stat-val { font-size: 22px; font-weight: 750; letter-spacing: -.02em; line-height: 1.15; }
.stat-val.ok { color: var(--ok); } .stat-val.warn { color: var(--warn); }
.stat-val.bad { color: var(--bad); } .stat-val.info { color: var(--accent); }
.stat-label { font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin-top: 3px; }
.stat-sub { font-size: 11.5px; color: var(--muted); margin-top: 4px; }

.kv-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px 20px; }
.kv .k { font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin-bottom: 2px; }
.kv .v { font-size: 13.5px; word-break: break-word; }

/* ============================================================
   Tables
   ============================================================ */
.tbl-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  overflow-x: auto;
}
table.tbl { width: 100%; border-collapse: collapse; min-width: 640px; }
.tbl th {
  text-align: left;
  font-size: 10.5px; font-weight: 650;
  text-transform: uppercase; letter-spacing: .08em;
  color: var(--muted);
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  position: sticky; top: 0;
  background: var(--surface);
  z-index: 2;
}
.tbl td { padding: 12px 16px; font-size: 13px; border-bottom: 1px solid rgba(126,166,255,.07); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tbody tr { transition: background .12s; }
.tbl tbody tr:hover { background: rgba(126,166,255,.05); }
.tbl-click tbody tr { cursor: pointer; }
.tbl .num { text-align: right; font-variant-numeric: tabular-nums; }

.tbl-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px;
  font-size: 12.5px; color: var(--muted);
  border-top: 1px solid var(--border);
}

/* ============================================================
   Pills / badges / dots / bars
   ============================================================ */
.pill {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11px; font-weight: 600;
  padding: 2px 9px;
  border-radius: 999px;
  white-space: nowrap;
  vertical-align: middle;
}
.pill-ok    { background: rgba(52,211,153,.13);  color: var(--ok); }
.pill-warn  { background: rgba(251,191,36,.13);  color: var(--warn); }
.pill-bad   { background: rgba(251,113,133,.13); color: var(--bad); }
.pill-info  { background: rgba(59,160,255,.13);  color: var(--accent); }
.pill-violet{ background: rgba(167,139,250,.14); color: var(--violet); }
.pill-muted { background: rgba(143,161,199,.13); color: var(--muted); }
.pill-grad  { background: var(--grad); color: #fff; }

.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; }
.dot.ok  { background: var(--ok);  box-shadow: 0 0 6px rgba(52,211,153,.6); }
.dot.bad { background: var(--bad); box-shadow: 0 0 6px rgba(251,113,133,.6); }

.bar { height: 5px; border-radius: 999px; background: rgba(126,166,255,.12); overflow: hidden; min-width: 54px; }
.bar-fill { height: 100%; border-radius: 999px; background: var(--accent); transition: width .3s; }
.bar-fill.warn { background: var(--warn); }
.bar-fill.bad  { background: var(--bad); }
.bar-fill.ok   { background: var(--ok); }

.avatar-chip {
  --hue: 210;
  width: 34px; height: 34px; flex-shrink: 0;
  border-radius: 10px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700; color: #fff;
  background: linear-gradient(135deg, hsl(var(--hue), 75%, 52%), hsl(calc(var(--hue) + 40), 70%, 45%));
}
.avatar-chip.lg { width: 52px; height: 52px; border-radius: 14px; font-size: 20px; }
.avatar-chip.sm { width: 26px; height: 26px; border-radius: 8px; font-size: 11px; }

.copy-chip {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: var(--mono); font-size: 11.5px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 7px;
  padding: 2px 8px;
  cursor: pointer;
  transition: all .13s;
}
.copy-chip:hover { color: var(--accent); border-color: rgba(59,160,255,.4); }

/* ============================================================
   Buttons
   ============================================================ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  font-family: var(--font); font-size: 13px; font-weight: 600;
  padding: 8px 15px;
  border-radius: var(--r-ctl);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all .14s;
  white-space: nowrap;
  user-select: none;
  color: var(--text);
  background: transparent;
}
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn:active:not(:disabled) { transform: translateY(1px); }

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-2); }

.btn-grad { background: var(--grad); color: #fff; box-shadow: 0 3px 14px rgba(59,160,255,.3); }
.btn-grad:hover:not(:disabled) { filter: brightness(1.08); }

.btn-ghost { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-3); border-color: var(--border-2); }

.btn-danger { background: rgba(251,113,133,.12); color: var(--bad); border-color: rgba(251,113,133,.35); }
.btn-danger:hover:not(:disabled) { background: rgba(251,113,133,.2); }

.btn-sm { font-size: 12px; padding: 5px 11px; border-radius: 8px; }
.btn-icon { padding: 6px; width: 30px; height: 30px; border-radius: 8px; }
.btn-block { width: 100%; }

/* ============================================================
   Inputs / forms
   ============================================================ */
.field { display: block; }
.field > span {
  display: block;
  font-size: 11.5px; font-weight: 600;
  color: var(--muted);
  margin-bottom: 5px;
  text-transform: uppercase; letter-spacing: .05em;
}
.field input, .field select, .field textarea,
.search-box input, textarea.composer {
  width: 100%;
  font-family: var(--font); font-size: 13.5px;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-ctl);
  padding: 8px 12px;
  outline: none;
  transition: border-color .14s, box-shadow .14s;
}
.field input:focus, .field select:focus, .field textarea:focus,
.search-box input:focus, textarea.composer:focus {
  border-color: rgba(59,160,255,.55);
  box-shadow: 0 0 0 3px rgba(59,160,255,.12);
}
.field input::placeholder, textarea::placeholder { color: rgba(143,161,199,.55); }
.field 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 24 24' fill='none' stroke='%238fa1c7' stroke-width='2.5' 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; padding-right: 30px; }
.field select option { background: var(--surface-2); color: var(--text); }
.field .hint { font-size: 11.5px; color: var(--muted); margin-top: 4px; text-transform: none; letter-spacing: 0; font-weight: 400; }

.input-row { display: flex; gap: 10px; align-items: flex-end; }
.input-row > * { flex: 1; }
.input-row > .btn, .input-row > .no-flex { flex: 0 0 auto; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 640px) { .form-grid { grid-template-columns: 1fr; } }

.search-box { position: relative; }
.search-box svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.search-box input { padding-left: 34px; }

/* Toggle switch */
.toggle { position: relative; display: inline-flex; align-items: center; cursor: pointer; flex-shrink: 0; }
.toggle input { position: absolute; opacity: 0; width: 0; height: 0; }
.toggle .knob {
  width: 38px; height: 21px;
  background: rgba(126,166,255,.18);
  border: 1px solid var(--border);
  border-radius: 999px;
  transition: background .16s, border-color .16s;
  position: relative;
  display: inline-block;
}
.toggle .knob::after {
  content: '';
  position: absolute; top: 2px; left: 2px;
  width: 15px; height: 15px;
  border-radius: 50%;
  background: var(--muted);
  transition: transform .16s, background .16s;
}
.toggle input:checked + .knob { background: rgba(59,160,255,.55); border-color: rgba(59,160,255,.6); }
.toggle input:checked + .knob::after { transform: translateX(17px); background: #fff; }
.toggle input:disabled + .knob { opacity: .45; cursor: not-allowed; }
.toggle.toggle-warn input:checked + .knob { background: rgba(251,191,36,.55); border-color: rgba(251,191,36,.6); }

/* ============================================================
   Tabs (page-local)
   ============================================================ */
.tabbar {
  display: inline-flex; gap: 4px; flex-wrap: wrap;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 4px;
}
.tabbar .tab {
  font-family: var(--font); font-size: 12.5px; font-weight: 600;
  color: var(--muted);
  background: transparent;
  border: 0; border-radius: 8px;
  padding: 6px 14px;
  cursor: pointer;
  transition: all .14s;
  display: inline-flex; align-items: center; gap: 7px;
}
.tabbar .tab:hover { color: var(--text); }
.tabbar .tab.active { background: var(--grad); color: #fff; box-shadow: 0 2px 10px rgba(59,160,255,.3); }
.tab-count {
  font-size: 10px; font-weight: 700; font-family: var(--mono);
  background: rgba(126,166,255,.15);
  padding: 1px 6px; border-radius: 999px;
}
.tab.active .tab-count { background: rgba(255,255,255,.22); }

/* ============================================================
   Banners
   ============================================================ */
.banner {
  display: flex; align-items: flex-start; gap: 10px;
  font-size: 12.5px;
  padding: 11px 14px;
  border-radius: 11px;
  line-height: 1.45;
}
.banner svg { flex-shrink: 0; margin-top: 1px; }
.banner-info   { background: rgba(59,160,255,.09);  border: 1px solid rgba(59,160,255,.3);  color: #bcd9ff; }
.banner-info svg { color: var(--accent); }
.banner-warn   { background: rgba(251,191,36,.09);  border: 1px solid rgba(251,191,36,.3);  color: #fde8b8; }
.banner-warn svg { color: var(--warn); }
.banner-danger { background: rgba(251,113,133,.09); border: 1px solid rgba(251,113,133,.3); color: #ffd3da; }
.banner-danger svg { color: var(--bad); }
.banner a { color: inherit; text-decoration: underline; }

/* ============================================================
   Feature flags UI
   ============================================================ */
.flag-group-head {
  position: sticky; top: 66px;
  display: flex; align-items: center; gap: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 14px;
  z-index: 5;
}
.flag-group-head .t { font-size: 13px; font-weight: 650; }
.flag-group-head .b { font-size: 11.5px; color: var(--muted); }
.flag-group-head .cnt { margin-left: auto; font-family: var(--mono); font-size: 11px; color: var(--muted); }
.flag-row {
  display: flex; align-items: center; gap: 12px;
  padding: 9px 14px;
  border-bottom: 1px solid rgba(126,166,255,.06);
}
.flag-row:last-child { border-bottom: 0; }
.flag-row:hover { background: rgba(126,166,255,.04); }
.flag-row .fl-label { font-size: 13px; font-weight: 550; }
.flag-row .fl-key { font-family: var(--mono); font-size: 10.5px; color: var(--muted); }
.flag-row .fl-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.flag-row.changed { background: rgba(59,160,255,.07); box-shadow: inset 3px 0 0 var(--accent); }

/* Sticky save bar */
.savebar {
  position: fixed;
  bottom: 18px; left: calc(var(--sidebar-w) + 28px); right: 28px;
  max-width: 1404px;
  display: flex; align-items: center; gap: 14px;
  background: rgba(17, 27, 49, .95);
  border: 1px solid rgba(59,160,255,.4);
  border-radius: 13px;
  padding: 12px 18px;
  box-shadow: 0 10px 34px rgba(2,6,18,.6);
  backdrop-filter: blur(10px);
  z-index: 45;
  animation: slideup .18s ease-out;
}
@keyframes slideup { from { transform: translateY(12px); opacity: 0; } to { transform: none; opacity: 1; } }
.savebar .msg { font-size: 13px; font-weight: 600; }
.savebar .spacer { flex: 1; }

/* ============================================================
   Modal
   ============================================================ */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(4, 7, 14, .68);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center; justify-content: center;
  padding: 24px;
  z-index: 60;
}
.modal-backdrop.open { display: flex; }
.modal {
  width: 480px; max-width: 100%;
  max-height: 88vh;
  display: flex; flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: 16px;
  box-shadow: var(--shadow);
  animation: modalin .16s ease-out;
}
.modal.wide { width: 680px; }
@keyframes modalin { from { transform: translateY(10px) scale(.985); opacity: 0; } to { transform: none; opacity: 1; } }
.modal-head {
  display: flex; align-items: center; gap: 10px;
  padding: 18px 22px 0;
}
.modal-head h3 { font-size: 16px; font-weight: 650; letter-spacing: -.01em; flex: 1; }
.modal-body { padding: 16px 22px; overflow-y: auto; }
.modal-body > * + * { margin-top: 13px; }
.modal-foot {
  display: flex; justify-content: flex-end; gap: 9px;
  padding: 14px 22px 18px;
  border-top: 1px solid var(--border);
}

/* ============================================================
   Drawer (slide-over)
   ============================================================ */
.drawer-backdrop {
  position: fixed; inset: 0;
  background: rgba(4, 7, 14, .55);
  opacity: 0; pointer-events: none;
  transition: opacity .18s;
  z-index: 55;
}
.drawer-backdrop.open { opacity: 1; pointer-events: auto; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0;
  width: 600px; max-width: 94vw;
  background: var(--surface);
  border-left: 1px solid var(--border-2);
  box-shadow: -18px 0 50px rgba(2,6,18,.55);
  transform: translateX(102%);
  transition: transform .2s ease-out;
  z-index: 56;
  display: flex; flex-direction: column;
}
.drawer-backdrop.open .drawer, .drawer.open { transform: none; }
.drawer-head { padding: 18px 22px 14px; border-bottom: 1px solid var(--border); display: flex; align-items: flex-start; gap: 10px; }
.drawer-head h3 { font-size: 15.5px; font-weight: 650; flex: 1; line-height: 1.35; }
.drawer-body { flex: 1; overflow-y: auto; padding: 18px 22px; }
.drawer-body > * + * { margin-top: 14px; }
.drawer-foot { border-top: 1px solid var(--border); padding: 14px 22px; }

/* ============================================================
   Support conversation
   ============================================================ */
.msg-item { display: flex; flex-direction: column; gap: 4px; }
.msg-meta { display: flex; align-items: center; gap: 8px; font-size: 11.5px; color: var(--muted); }
.msg-bubble {
  border-radius: 11px;
  padding: 10px 13px;
  font-size: 13px;
  border: 1px solid var(--border);
  background: var(--surface-2);
}
.msg-item.staff .msg-bubble { background: rgba(59,160,255,.09); border-color: rgba(59,160,255,.28); }
.msg-item.internal .msg-bubble { background: rgba(251,191,36,.08); border-color: rgba(251,191,36,.3); }

.prio-rail { width: 4px; border-radius: 4px; align-self: stretch; flex-shrink: 0; }
.prio-rail.low { background: rgba(143,161,199,.5); }
.prio-rail.medium { background: var(--accent); }
.prio-rail.high { background: var(--warn); }
.prio-rail.critical { background: var(--bad); }

.ticket-row {
  display: flex; gap: 13px; align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 16px;
  cursor: pointer;
  transition: border-color .13s, background .13s;
}
.ticket-row:hover { border-color: var(--border-2); background: var(--surface-2); }

/* ============================================================
   Rich text (backend-sanitized)
   ============================================================ */
.rich { font-size: 13.5px; line-height: 1.6; overflow-wrap: break-word; }
.rich p + p { margin-top: 8px; }
.rich ul, .rich ol { padding-left: 22px; margin: 8px 0; }
.rich img { max-width: 100%; border-radius: 8px; }
.rich a { color: var(--accent); }
.rich code { font-family: var(--mono); font-size: .9em; background: var(--surface-3); padding: 1px 5px; border-radius: 5px; }
.rich blockquote { border-left: 3px solid var(--border-2); padding-left: 12px; color: var(--muted); margin: 8px 0; }

/* ============================================================
   States: empty / error / skeleton / spinner
   ============================================================ */
.empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center;
  padding: 46px 20px;
  color: var(--muted);
}
.empty svg { opacity: .5; margin-bottom: 12px; }
.empty .t { font-size: 14px; font-weight: 600; color: var(--text); }
.empty .s { font-size: 12.5px; margin-top: 3px; max-width: 380px; }

.error-box {
  background: rgba(251,113,133,.08);
  border: 1px solid rgba(251,113,133,.3);
  border-radius: 11px;
  padding: 14px 16px;
  font-size: 13px;
  color: #ffd3da;
  display: flex; align-items: center; gap: 10px;
}
.error-box svg { color: var(--bad); flex-shrink: 0; }

.skel {
  height: 42px;
  border-radius: 9px;
  background: linear-gradient(90deg, rgba(126,166,255,.06) 25%, rgba(126,166,255,.13) 45%, rgba(126,166,255,.06) 65%);
  background-size: 400% 100%;
  animation: shimmer 1.3s ease-in-out infinite;
  margin-bottom: 8px;
}
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }

.spin {
  display: inline-block;
  width: 15px; height: 15px;
  border: 2px solid rgba(59,160,255,.3);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: rot .7s linear infinite;
  vertical-align: -2px;
}
@keyframes rot { to { transform: rotate(360deg); } }
.spinner-block { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 38px; color: var(--muted); font-size: 13px; }

/* ============================================================
   Toasts
   ============================================================ */
#toast-root {
  position: fixed;
  bottom: 20px; right: 20px;
  display: flex; flex-direction: column; gap: 8px;
  z-index: 90;
  max-width: 380px;
}
.toast {
  display: flex; align-items: center; gap: 9px;
  background: var(--surface-3);
  border: 1px solid var(--border-2);
  border-radius: 11px;
  padding: 10px 14px;
  font-size: 13px;
  box-shadow: var(--shadow);
  animation: toastin .18s ease-out;
}
.toast.out { opacity: 0; transform: translateY(6px); transition: all .25s; }
@keyframes toastin { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }
.toast svg { flex-shrink: 0; }
.toast-success svg { color: var(--ok); }
.toast-error svg { color: var(--bad); }
.toast-info svg { color: var(--accent); }

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 900px) {
  :root { --sidebar-w: 64px; }
  #sidebar { padding: 14px 9px; }
  .sidebar-brand div:not(.brand-mark), .nav-section-label, .nav-item .nav-label, .nav-badge,
  .sidebar-user .user-info, #sidebar .btn .nav-label { display: none; }
  .nav-item { justify-content: center; padding: 10px; }
  .sidebar-user { justify-content: center; }
  .savebar { left: calc(var(--sidebar-w) + 12px); right: 12px; }
  #page-root { padding: 18px 14px 90px; }
  #topbar { padding: 12px 16px; }
}
