/* ============================================================
   AutoSecure — design system
   Tokens → primitives → components. Dark, restrained, premium.
   ============================================================ */

:root {
  /* surfaces */
  --bg: #08090c;
  --bg-elev: #0d0f14;
  --surface: #111318;
  --surface-2: #16181f;
  --surface-3: #1c1f27;
  --overlay: rgba(5, 6, 9, .72);

  /* lines */
  --line: #1e2129;
  --line-2: #282c36;
  --line-3: #363b47;

  /* text */
  --txt: #e9ebf0;
  --txt-2: #a2a9b8;
  --txt-3: #6e7686;
  --txt-4: #4d5462;

  /* accent */
  --accent: #5865f2;
  --accent-h: #4752c4;
  --accent-soft: rgba(88, 101, 242, .12);
  --accent-line: rgba(88, 101, 242, .35);

  /* semantic */
  --ok: #3ba55d;
  --ok-soft: rgba(59, 165, 93, .12);
  --warn: #f0a929;
  --warn-soft: rgba(240, 169, 41, .12);
  --bad: #ed4245;
  --bad-soft: rgba(237, 66, 69, .12);

  /* geometry */
  --r-xs: 5px;
  --r-sm: 7px;
  --r: 10px;
  --r-lg: 14px;
  --r-xl: 18px;

  /* elevation */
  --sh-sm: 0 1px 2px rgba(0, 0, 0, .4);
  --sh: 0 4px 14px rgba(0, 0, 0, .35);
  --sh-lg: 0 18px 48px rgba(0, 0, 0, .55);

  /* motion */
  --ease: cubic-bezier(.32, .72, 0, 1);
  --fast: 120ms;
  --med: 200ms;

  --sidebar: 236px;
  --topbar: 56px;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Inter", -apple-system, "Segoe UI", system-ui, sans-serif;
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--txt);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* ambient wash — subtle, not a gradient soup */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(900px 420px at 78% -8%, rgba(88, 101, 242, .10), transparent 62%),
    radial-gradient(700px 380px at 4% 104%, rgba(59, 130, 246, .07), transparent 62%);
}

h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -.018em; line-height: 1.25; }
h1 { font-size: 1.32rem; }
h2 { font-size: 1.02rem; }
h3 { font-size: .88rem; }
p { margin: 0; }

a { color: var(--txt); text-decoration: none; }
a:hover { color: #fff; }

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

::selection { background: var(--accent-line); }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-xs);
}

.mono { font-family: "JetBrains Mono", ui-monospace, "Cascadia Code", Consolas, monospace; font-size: .92em; }
.muted { color: var(--txt-2); }
.dim { color: var(--txt-3); }
.faint { color: var(--txt-4); }
.small { font-size: .78rem; }
.tiny { font-size: .7rem; }
.nowrap { white-space: nowrap; }
.trunc { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hidden { display: none !important; }

/* ── shell ─────────────────────────────────────────────── */

.shell { display: grid; grid-template-columns: var(--sidebar) 1fr; min-height: 100vh; }

.sidebar {
  position: sticky; top: 0; z-index: 40;
  height: 100vh;
  display: flex; flex-direction: column;
  background: var(--bg-elev);
  border-right: 1px solid var(--line);
}

.sb-head {
  display: flex; align-items: center; gap: 9px;
  height: var(--topbar); padding: 0 14px;
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}

.logo {
  width: 24px; height: 24px; border-radius: var(--r-sm);
  display: grid; place-items: center;
  background: linear-gradient(150deg, var(--accent), #7c86ff);
  color: #fff; font-weight: 700; font-size: .72rem;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, .09) inset;
}

.brand-name { font-weight: 600; font-size: .88rem; letter-spacing: -.01em; }
.brand-name span { color: var(--txt-3); font-weight: 500; }

.sb-nav { flex: 1 1 auto; overflow-y: auto; padding: 10px 8px; display: flex; flex-direction: column; gap: 1px; }

.sb-group { padding: 14px 8px 5px; font-size: .66rem; font-weight: 600; letter-spacing: .09em; text-transform: uppercase; color: var(--txt-4); }

.nav-item {
  display: flex; align-items: center; gap: 9px;
  padding: 7px 9px; border-radius: var(--r-sm);
  color: var(--txt-2); font-weight: 500; font-size: .83rem;
  transition: background var(--fast) var(--ease), color var(--fast) var(--ease);
}
.nav-item svg { width: 15px; height: 15px; flex: 0 0 auto; opacity: .8; }
.nav-item:hover { background: var(--surface-2); color: var(--txt); }
.nav-item.on { background: var(--accent-soft); color: #c3c9ff; }
.nav-item.on svg { opacity: 1; }
.nav-item .count {
  margin-left: auto; font-size: .68rem; font-weight: 600;
  padding: 1px 6px; border-radius: 999px;
  background: var(--surface-3); color: var(--txt-2);
}

.sb-foot { flex: 0 0 auto; padding: 8px; border-top: 1px solid var(--line); }

.user-chip {
  display: flex; align-items: center; gap: 9px;
  padding: 7px; border-radius: var(--r-sm);
  transition: background var(--fast) var(--ease);
}
.user-chip:hover { background: var(--surface-2); }
.user-chip img { width: 26px; height: 26px; border-radius: 50%; flex: 0 0 auto; }
.user-chip .nm { font-size: .8rem; font-weight: 600; line-height: 1.2; }
.user-chip .tg { font-size: .68rem; color: var(--txt-3); }

/* ── topbar ────────────────────────────────────────────── */

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

.topbar {
  position: sticky; top: 0; z-index: 30;
  height: var(--topbar); flex: 0 0 auto;
  display: flex; align-items: center; gap: 12px;
  padding: 0 20px;
  background: rgba(8, 9, 12, .82);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}

.crumbs { display: flex; align-items: center; gap: 7px; font-size: .8rem; color: var(--txt-3); min-width: 0; }
.crumbs a { color: var(--txt-3); }
.crumbs a:hover { color: var(--txt); }
.crumbs .sep { color: var(--txt-4); }
.crumbs .cur { color: var(--txt); font-weight: 500; }

.topbar-spacer { flex: 1 1 auto; }

.icon-btn {
  width: 30px; height: 30px; flex: 0 0 auto;
  display: grid; place-items: center;
  border: 1px solid var(--line-2); border-radius: var(--r-sm);
  background: var(--surface); color: var(--txt-2);
  cursor: pointer; transition: all var(--fast) var(--ease);
}
.icon-btn:hover { background: var(--surface-3); color: var(--txt); border-color: var(--line-3); }
.icon-btn svg { width: 14px; height: 14px; }
.icon-btn.danger:hover { color: #ff8a8c; border-color: rgba(237, 66, 69, .5); background: var(--bad-soft); }

.content { padding: 22px 24px 72px; max-width: 1240px; width: 100%; }

.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head .sub { color: var(--txt-3); font-size: .82rem; margin-top: 3px; }

/* ── buttons ───────────────────────────────────────────── */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 32px; padding: 0 12px;
  border: 1px solid var(--line-2); border-radius: var(--r-sm);
  background: var(--surface-2); color: var(--txt);
  font-size: .8rem; font-weight: 500; white-space: nowrap;
  cursor: pointer;
  transition: background var(--fast) var(--ease), border-color var(--fast) var(--ease), color var(--fast) var(--ease), transform var(--fast) var(--ease);
}
.btn:hover { background: var(--surface-3); border-color: var(--line-3); }
.btn:active { transform: translateY(.5px); }
.btn svg { width: 14px; height: 14px; }
.btn:disabled, .btn[aria-busy="true"] { opacity: .55; cursor: not-allowed; }

.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-h); border-color: var(--accent-h); }

.btn-ghost { background: transparent; border-color: transparent; color: var(--txt-2); }
.btn-ghost:hover { background: var(--surface-2); color: var(--txt); }

.btn-danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn-danger:hover { background: #d43a3d; border-color: #d43a3d; }

.btn-danger-ghost { color: #ff8a8c; border-color: rgba(237, 66, 69, .35); background: transparent; }
.btn-danger-ghost:hover { background: var(--bad-soft); border-color: rgba(237, 66, 69, .6); }

.btn-sm { height: 27px; padding: 0 9px; font-size: .74rem; }
.btn-sm svg { width: 12px; height: 12px; }
.btn-lg { height: 38px; padding: 0 16px; font-size: .86rem; }

/* ── surfaces ──────────────────────────────────────────── */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
}

.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 13px 16px; border-bottom: 1px solid var(--line);
}
.card-head h2 { font-size: .88rem; }
.card-body { padding: 16px; }
.card-foot { padding: 12px 16px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }

.grid { display: grid; gap: 12px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.g-auto { grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); }

.stat { padding: 14px 16px; }
.stat .k { font-size: .68rem; font-weight: 600; letter-spacing: .07em; text-transform: uppercase; color: var(--txt-4); }
.stat .v { font-size: 1.5rem; font-weight: 600; letter-spacing: -.03em; margin-top: 5px; font-variant-numeric: tabular-nums; }
.stat .v.ok { color: var(--ok); }
.stat .v.bad { color: var(--bad); }
.stat .v.warn { color: var(--warn); }

/* ── badges ────────────────────────────────────────────── */

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  height: 20px; padding: 0 7px; border-radius: 999px;
  font-size: .68rem; font-weight: 600; letter-spacing: .01em;
  border: 1px solid var(--line-2); background: var(--surface-2); color: var(--txt-2);
  white-space: nowrap;
}
.badge .dot { width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.badge.ok { color: #6fd68f; border-color: rgba(59, 165, 93, .35); background: var(--ok-soft); }
.badge.bad { color: #ff8a8c; border-color: rgba(237, 66, 69, .35); background: var(--bad-soft); }
.badge.warn { color: #f5c05e; border-color: rgba(240, 169, 41, .35); background: var(--warn-soft); }
.badge.accent { color: #b3baff; border-color: var(--accent-line); background: var(--accent-soft); }

/* ── forms ─────────────────────────────────────────────── */

.field { margin-bottom: 13px; }
.field:last-child { margin-bottom: 0; }
.label { display: block; font-size: .74rem; font-weight: 600; color: var(--txt-2); margin-bottom: 5px; }
.hint { font-size: .71rem; color: var(--txt-4); margin-top: 4px; }
.err { font-size: .71rem; color: #ff8a8c; margin-top: 4px; }

.input, .select, .textarea {
  width: 100%; padding: 7px 10px;
  border: 1px solid var(--line-2); border-radius: var(--r-sm);
  background: var(--bg-elev); color: var(--txt);
  font-size: .82rem;
  transition: border-color var(--fast) var(--ease), background var(--fast) var(--ease);
}
.input:hover, .select:hover, .textarea:hover { border-color: var(--line-3); }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--accent); background: var(--surface); }
.input::placeholder, .textarea::placeholder { color: var(--txt-4); }
.textarea { min-height: 78px; resize: vertical; font-family: inherit; }
.input.mono { font-family: "JetBrains Mono", monospace; font-size: .78rem; }
.input[aria-invalid="true"] { border-color: var(--bad); }

.input-group { display: flex; gap: 6px; }
.input-group .input { flex: 1 1 auto; }

.select {
  appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236e7686' stroke-width='2.5'><path d='M6 9l6 6 6-6'/></svg>");
  background-repeat: no-repeat; background-position: right 9px center;
  padding-right: 28px; cursor: pointer;
}

/* switch */
.switch { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.switch:last-child { border-bottom: 0; }
.switch .t { font-size: .82rem; font-weight: 500; }
.switch .d { font-size: .72rem; color: var(--txt-4); margin-top: 1px; }
.track {
  flex: 0 0 auto; width: 34px; height: 19px; margin-top: 2px;
  border-radius: 999px; border: 1px solid var(--line-3);
  background: var(--surface-3); position: relative; cursor: pointer;
  transition: background var(--med) var(--ease), border-color var(--med) var(--ease);
}
.track::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 13px; height: 13px; border-radius: 50%;
  background: var(--txt-3);
  transition: transform var(--med) var(--ease), background var(--med) var(--ease);
}
.track.on { background: var(--accent); border-color: var(--accent); }
.track.on::after { transform: translateX(15px); background: #fff; }
.track[aria-busy="true"] { opacity: .6; }

/* ── tables ────────────────────────────────────────────── */

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .82rem; }
th {
  text-align: left; font-size: .67rem; font-weight: 600;
  letter-spacing: .07em; text-transform: uppercase; color: var(--txt-4);
  padding: 8px 12px; border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr { transition: background var(--fast) var(--ease); }
tbody tr:hover { background: var(--surface-2); }
td.actions { text-align: right; white-space: nowrap; }

/* ── tabs ──────────────────────────────────────────────── */

.tabs { display: flex; gap: 2px; overflow-x: auto; border-bottom: 1px solid var(--line); margin-bottom: 18px; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  padding: 8px 11px; font-size: .8rem; font-weight: 500;
  color: var(--txt-3); border-bottom: 2px solid transparent;
  white-space: nowrap; transition: color var(--fast) var(--ease), border-color var(--fast) var(--ease);
}
.tab:hover { color: var(--txt); }
.tab.on { color: var(--txt); border-bottom-color: var(--accent); }

/* ── empty / skeleton ──────────────────────────────────── */

.empty { padding: 52px 24px; text-align: center; }
.empty .ico {
  width: 40px; height: 40px; margin: 0 auto 12px;
  display: grid; place-items: center; border-radius: var(--r);
  background: var(--surface-2); border: 1px solid var(--line-2); color: var(--txt-3);
}
.empty .ico svg { width: 18px; height: 18px; }
.empty h3 { margin-bottom: 4px; }
.empty p { color: var(--txt-3); font-size: .82rem; max-width: 340px; margin: 0 auto 14px; }

.skel { background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 50%, var(--surface-2) 75%); background-size: 200% 100%; animation: skel 1.4s infinite; border-radius: var(--r-xs); }
@keyframes skel { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* ── toast ─────────────────────────────────────────────── */

.toasts { position: fixed; bottom: 18px; right: 18px; z-index: 200; display: flex; flex-direction: column; gap: 8px; max-width: 340px; }

.toast {
  display: flex; align-items: flex-start; gap: 9px;
  padding: 10px 12px; border-radius: var(--r);
  background: var(--surface-2); border: 1px solid var(--line-3);
  box-shadow: var(--sh-lg); font-size: .8rem;
  animation: toast-in var(--med) var(--ease);
}
.toast.out { animation: toast-out var(--fast) var(--ease) forwards; }
.toast svg { width: 15px; height: 15px; flex: 0 0 auto; margin-top: 1px; }
.toast.ok { border-color: rgba(59, 165, 93, .45); }
.toast.ok svg { color: var(--ok); }
.toast.bad { border-color: rgba(237, 66, 69, .45); }
.toast.bad svg { color: var(--bad); }
.toast.warn { border-color: rgba(240, 169, 41, .45); }
.toast.warn svg { color: var(--warn); }
.toast .body { flex: 1 1 auto; }
.toast .ttl { font-weight: 600; }
.toast .msg { color: var(--txt-2); font-size: .76rem; }

@keyframes toast-in { from { opacity: 0; transform: translateY(8px) scale(.98); } }
@keyframes toast-out { to { opacity: 0; transform: translateX(12px); } }

/* ── dialog ────────────────────────────────────────────── */

.scrim {
  position: fixed; inset: 0; z-index: 150;
  background: var(--overlay); backdrop-filter: blur(3px);
  display: grid; place-items: center; padding: 20px;
  animation: fade var(--med) var(--ease);
}
@keyframes fade { from { opacity: 0; } }

.dialog {
  width: 100%; max-width: 460px;
  background: var(--surface); border: 1px solid var(--line-3);
  border-radius: var(--r-xl); box-shadow: var(--sh-lg);
  animation: pop var(--med) var(--ease);
  max-height: calc(100vh - 40px); display: flex; flex-direction: column;
}
.dialog.wide { max-width: 620px; }
@keyframes pop { from { opacity: 0; transform: translateY(10px) scale(.98); } }

.dialog-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 16px 18px 0; }
.dialog-body { padding: 14px 18px; overflow-y: auto; }
.dialog-foot { padding: 0 18px 16px; display: flex; justify-content: flex-end; gap: 8px; }

/* ── bot cards ─────────────────────────────────────────── */

.bot-card {
  display: flex; flex-direction: column; gap: 12px;
  padding: 14px; border-radius: var(--r-lg);
  background: var(--surface); border: 1px solid var(--line);
  transition: border-color var(--fast) var(--ease), background var(--fast) var(--ease), transform var(--fast) var(--ease);
}
.bot-card:hover { border-color: var(--line-3); background: var(--surface-2); }
.bot-card .top { display: flex; align-items: center; gap: 10px; }
.bot-card .av { width: 38px; height: 38px; border-radius: var(--r); flex: 0 0 auto; background: var(--surface-3); object-fit: cover; }
.bot-card .nm { font-weight: 600; font-size: .86rem; }
.bot-card .id { font-size: .7rem; color: var(--txt-4); }
.bot-card .foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding-top: 10px; border-top: 1px solid var(--line); }

/* ── misc ──────────────────────────────────────────────── */

.kv { display: grid; grid-template-columns: 132px 1fr; gap: 9px 14px; font-size: .82rem; align-items: baseline; }
.kv dt { color: var(--txt-4); font-size: .72rem; font-weight: 500; }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.stack { display: flex; flex-direction: column; gap: 12px; }

.divider { height: 1px; background: var(--line); margin: 14px 0; }

.copy-btn { opacity: 0; transition: opacity var(--fast) var(--ease); }
tr:hover .copy-btn, .bot-card:hover .copy-btn, .kv:hover .copy-btn { opacity: 1; }

.pager { display: flex; align-items: center; gap: 6px; justify-content: center; padding: 12px; }

/* ── welcome ───────────────────────────────────────────── */

.hero { max-width: 700px; margin: 0 auto; padding: 15vh 24px 60px; text-align: center; }
.hero h1 { font-size: clamp(1.9rem, 4.4vw, 2.7rem); letter-spacing: -.04em; line-height: 1.08; }
.hero .sub { color: var(--txt-2); font-size: .95rem; margin: 14px auto 26px; max-width: 440px; }
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 11px; border-radius: 999px; margin-bottom: 20px;
  border: 1px solid var(--line-2); background: var(--surface); color: var(--txt-2);
  font-size: .72rem; font-weight: 500;
}
.pill .dot { width: 5px; height: 5px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 8px var(--ok); }

.hero-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 46px; text-align: left; }
.hero-cards .card { padding: 14px; }
.hero-cards h3 { font-size: .82rem; margin-bottom: 3px; }
.hero-cards p { font-size: .76rem; color: var(--txt-3); }

/* ── responsive ────────────────────────────────────────── */

.sb-toggle { display: none; }

@media (max-width: 1024px) {
  .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .g3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: 260px;
    transform: translateX(-100%);
    transition: transform var(--med) var(--ease);
    box-shadow: var(--sh-lg);
  }
  .sidebar.open { transform: none; }
  .sb-toggle { display: grid; }
  .content { padding: 18px 14px 60px; }
  .topbar { padding: 0 14px; }
  .g2, .g3, .g4, .hero-cards { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 1fr; gap: 2px 0; }
  .kv dt { margin-top: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
