:root {
  --bg: #07080b;
  --bg-elev: #0d0f14;
  --bg-card: #12141c;
  --bg-hover: #181b25;
  --line: rgba(255, 255, 255, 0.07);
  --line-strong: rgba(255, 255, 255, 0.12);
  --text: #eceef4;
  --muted: #8b91a3;
  --faint: #5c6272;
  --accent: #6d7cff;
  --accent-2: #8b6cff;
  --accent-soft: rgba(109, 124, 255, 0.16);
  --ok: #34d399;
  --ok-soft: rgba(52, 211, 153, 0.14);
  --warn: #fbbf24;
  --warn-soft: rgba(251, 191, 36, 0.14);
  --err: #f87171;
  --err-soft: rgba(248, 113, 113, 0.14);
  --info: #67e8f9;
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
  --radius: 16px;
  --radius-sm: 10px;
  --nav-w: 248px;
  --font: "Segoe UI", "Helvetica Neue", ui-sans-serif, system-ui, sans-serif;
  --mono: ui-monospace, "SFMono-Regular", "Cascadia Code", "Menlo", monospace;
  --focus: 0 0 0 3px rgba(109, 124, 255, 0.35);
}

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

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
}

body {
  background-image:
    radial-gradient(1200px 600px at -10% -20%, rgba(109, 124, 255, 0.14), transparent 55%),
    radial-gradient(900px 500px at 110% 0%, rgba(139, 108, 255, 0.1), transparent 50%),
    linear-gradient(180deg, #090a0e 0%, var(--bg) 40%);
  background-attachment: fixed;
}

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

a:hover {
  text-decoration: underline;
}

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

button {
  cursor: pointer;
}

:focus-visible {
  outline: none;
  box-shadow: var(--focus);
}

.boot {
  display: grid;
  place-items: center;
  min-height: 100vh;
  color: var(--muted);
}

/* ——— Shell ——— */

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

.nav {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 20px 14px;
  border-right: 1px solid var(--line);
  background: rgba(8, 9, 12, 0.72);
  backdrop-filter: blur(16px);
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 8px 10px;
}

.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 11px;
  background: linear-gradient(145deg, var(--accent), var(--accent-2));
  display: grid;
  place-items: center;
  box-shadow: 0 8px 24px rgba(109, 124, 255, 0.35);
  flex-shrink: 0;
}

.brand-mark svg {
  width: 20px;
  height: 20px;
}

.brand strong {
  display: block;
  font-size: 14px;
  letter-spacing: 0.01em;
}

.brand span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.nav-links {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-links a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  color: var(--muted);
  text-decoration: none;
}

.nav-links a svg {
  width: 18px;
  height: 18px;
  opacity: 0.85;
}

.nav-links a:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.nav-links a.active {
  background: var(--accent-soft);
  color: var(--text);
}

.nav-spacer {
  flex: 1;
}

.nav-user {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg-card);
}

.nav-user .who {
  font-size: 13px;
  margin-bottom: 8px;
  color: var(--muted);
}

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 28px 8px;
}

.topbar h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 620;
  letter-spacing: -0.02em;
}

.topbar p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.menu-btn {
  display: none;
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: 10px;
  width: 40px;
  height: 40px;
  align-items: center;
  justify-content: center;
}

.content {
  padding: 12px 28px 40px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.stub-banner {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid rgba(251, 191, 36, 0.22);
  background: var(--warn-soft);
  color: #fde68a;
  font-size: 13px;
}

.nav-scrim {
  display: none;
}

/* ——— Login ——— */

.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: min(420px, 100%);
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 32px 28px;
}

.login-card h1 {
  margin: 16px 0 6px;
  font-size: 24px;
  letter-spacing: -0.03em;
}

.login-card .lede {
  margin: 0 0 22px;
  color: var(--muted);
  font-size: 14px;
}

.login-card .brand-mark {
  width: 44px;
  height: 44px;
}

.form-error {
  background: var(--err-soft);
  color: #fecaca;
  border: 1px solid rgba(248, 113, 113, 0.25);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 14px;
  font-size: 13px;
}

.form-error[hidden] {
  display: none;
}

/* ——— Forms ——— */

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}

.field label {
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0.02em;
}

.field .hint {
  font-size: 12px;
  color: var(--faint);
}

input[type="text"],
input[type="password"],
input[type="url"],
select,
textarea {
  width: 100%;
  background: var(--bg-elev);
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  padding: 10px 12px;
}

input:disabled,
select:disabled,
textarea:disabled {
  opacity: 0.55;
}

textarea {
  min-height: 88px;
  resize: vertical;
}

.row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--muted);
  margin: 4px 0 12px;
}

/* ——— Buttons ——— */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 0;
  border-radius: 10px;
  padding: 10px 14px;
  background: var(--bg-hover);
  color: var(--text);
  font-weight: 600;
  font-size: 14px;
}

.btn:hover {
  filter: brightness(1.08);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  filter: none;
}

.btn-primary {
  background: linear-gradient(180deg, #7b88ff, var(--accent));
  color: #fff;
  width: 100%;
}

.btn-accent {
  background: var(--accent-soft);
  color: #c7cdff;
  border: 1px solid rgba(109, 124, 255, 0.25);
}

.btn-danger {
  background: var(--err-soft);
  color: #fecaca;
  border: 1px solid rgba(248, 113, 113, 0.22);
}

.btn-ghost {
  background: transparent;
  border: 1px solid var(--line-strong);
}

.btn-sm {
  padding: 7px 10px;
  font-size: 13px;
  font-weight: 560;
}

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

/* ——— Cards / stats ——— */

.grid-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
}

.card h2 {
  margin: 0 0 12px;
  font-size: 14px;
  font-weight: 620;
  color: var(--muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.stat-label {
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 8px;
}

.stat-value {
  font-size: 20px;
  font-weight: 650;
  letter-spacing: -0.03em;
}

.stat-sub {
  margin-top: 6px;
  color: var(--faint);
  font-size: 12px;
  font-family: var(--mono);
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 650;
}

.pill::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}

.pill-ok {
  background: var(--ok-soft);
  color: var(--ok);
}

.pill-off {
  background: rgba(139, 145, 163, 0.14);
  color: #a1a7b8;
}

.pill-warn {
  background: var(--warn-soft);
  color: var(--warn);
}

.pill-err {
  background: var(--err-soft);
  color: var(--err);
}

.dl {
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: 8px 16px;
  font-size: 14px;
}

.dl dt {
  color: var(--muted);
  margin: 0;
}

.dl dd {
  margin: 0;
  font-family: var(--mono);
  font-size: 13px;
  word-break: break-all;
}

/* ——— Tables ——— */

.table-wrap {
  overflow: auto;
}

table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

table.data th,
table.data td {
  text-align: left;
  padding: 11px 10px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

table.data th {
  color: var(--muted);
  font-weight: 600;
  font-size: 12px;
}

table.data tr:hover td {
  background: rgba(255, 255, 255, 0.015);
}

table.data tr.is-placeholder td {
  opacity: 0.72;
}

.mono {
  font-family: var(--mono);
  font-size: 12px;
}

.empty {
  color: var(--muted);
  padding: 28px 8px;
  text-align: center;
}

/* ——— Logs ——— */

.log-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.log-view {
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.55;
  background: #0a0b10;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 16px;
  min-height: 360px;
  max-height: min(70vh, 720px);
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

.log-line {
  display: grid;
  grid-template-columns: 168px 64px 110px 1fr;
  gap: 10px;
  padding: 3px 0;
}

.log-ts {
  color: var(--faint);
}

.log-level {
  font-weight: 700;
  text-transform: uppercase;
  font-size: 11px;
}

.log-level.info { color: var(--info); }
.log-level.warn { color: var(--warn); }
.log-level.error, .log-level.err { color: var(--err); }
.log-level.debug { color: var(--muted); }

.log-src {
  color: #a5b4fc;
}

.result-box {
  white-space: pre-wrap;
  font-family: var(--mono);
  font-size: 13px;
  background: #0a0b10;
  border-radius: 12px;
  border: 1px solid var(--line);
  padding: 14px;
  min-height: 88px;
}

/* ——— Chat ——— */

.chat-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: min(70vh, 740px);
}

.chat-card .toolbar h2 {
  margin: 0;
}

.chat-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chat-tab {
  background: var(--bg-elev);
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}

.chat-tab:hover {
  color: var(--text);
  background: var(--bg-hover);
}

.chat-tab.active {
  background: var(--accent-soft);
  border-color: rgba(109, 124, 255, 0.35);
  color: #c7cdff;
}

.chat-thread {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: #0a0b10;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 16px;
  min-height: 320px;
  max-height: min(55vh, 560px);
  overflow: auto;
}

.chat-bubble {
  max-width: min(78%, 640px);
  padding: 10px 12px;
  border-radius: 14px;
  border: 1px solid var(--line);
}

.chat-bubble.in {
  align-self: flex-start;
  background: var(--bg-hover);
  border-bottom-left-radius: 4px;
}

.chat-bubble.out {
  align-self: flex-end;
  background: var(--accent-soft);
  border-color: rgba(109, 124, 255, 0.22);
  border-bottom-right-radius: 4px;
}

.chat-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 6px;
}

.chat-author {
  font-weight: 700;
  color: var(--text);
  font-size: 13px;
}

.chat-legend {
  margin: -4px 0 0;
  font-size: 12px;
}

.chat-status {
  font-family: var(--mono);
  color: var(--faint);
}

.chat-text {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 14px;
}

.chat-composer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: end;
}

.chat-composer textarea {
  min-height: 72px;
  margin: 0;
}

.chat-composer .btn {
  min-width: 108px;
  height: 42px;
}

.chat-hint {
  margin: 0;
  font-size: 13px;
}

/* ——— Drawer ——— */

.drawer-scrim {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 40;
}

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  height: 100%;
  width: min(440px, 100%);
  background: var(--bg-elev);
  border-left: 1px solid var(--line);
  z-index: 41;
  padding: 22px;
  overflow: auto;
  box-shadow: var(--shadow);
}

.drawer h2 {
  margin: 0 0 16px;
  font-size: 18px;
}

/* ——— Toasts ——— */

.toasts {
  position: fixed;
  right: 18px;
  bottom: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 80;
  width: min(360px, calc(100% - 24px));
}

.toast {
  background: var(--bg-card);
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  padding: 12px 14px;
  box-shadow: var(--shadow);
  font-size: 13px;
}

.toast.ok { border-color: rgba(52, 211, 153, 0.35); }
.toast.err { border-color: rgba(248, 113, 113, 0.4); }

/* ——— Misc ——— */

.muted { color: var(--muted); }
.hidden { display: none !important; }

.toolbar {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}

@media (max-width: 1100px) {
  .grid-stats {
    grid-template-columns: 1fr 1fr;
  }
  .log-line {
    grid-template-columns: 1fr;
    gap: 2px;
    padding: 8px 0;
    border-bottom: 1px solid var(--line);
  }
}

@media (max-width: 860px) {
  .shell {
    grid-template-columns: 1fr;
  }
  .nav {
    position: fixed;
    left: 0;
    top: 0;
    z-index: 30;
    transform: translateX(-105%);
    transition: transform 0.2s ease;
    width: min(var(--nav-w), 86vw);
  }
  .nav.open {
    transform: none;
  }
  .nav-scrim.show {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 25;
  }
  .menu-btn {
    display: inline-flex;
  }
  .content,
  .topbar {
    padding-left: 16px;
    padding-right: 16px;
  }
  .row-2,
  .dl,
  .grid-stats {
    grid-template-columns: 1fr;
  }
  .chat-composer {
    grid-template-columns: 1fr;
  }
  .chat-composer .btn {
    width: 100%;
  }
  .chat-bubble {
    max-width: 92%;
  }
}
