:root {
  --bg: #0b0f17;
  --surface: #121826;
  --surface-2: #1a2234;
  --border: #263147;
  --text: #e8eefc;
  --muted: #8b9bb8;
  --primary: #4f8cff;
  --primary-hover: #3b78eb;
  --success: #22c55e;
  --warn: #f59e0b;
  --danger: #ef4444;
  --radius: 14px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }

.auth-gate {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
}
.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.error-text { color: var(--danger); font-size: 0.88rem; min-height: 1.2em; margin: 0; }
.hint-text { color: var(--muted); font-size: 0.82rem; margin: 0; }
.hint-text code { color: #93c5fd; }

.brand-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.brand-row h1 { margin: 0; font-size: 1.25rem; letter-spacing: -0.02em; }
.logo-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: linear-gradient(135deg, #60a5fa, #a855f7);
  box-shadow: 0 0 12px rgba(96, 165, 250, 0.7);
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  background: rgba(18, 24, 38, 0.92);
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: blur(8px);
}
.topbar-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.layout {
  max-width: 1280px;
  margin: 0 auto;
  padding: 20px;
  display: grid;
  grid-template-columns: 1.45fr 1fr;
  gap: 20px;
  align-items: start;
}
@media (max-width: 920px) {
  .layout { grid-template-columns: 1fr; }
}

.sidebar { display: flex; flex-direction: column; gap: 20px; }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}
.panel h2 { margin: 0 0 8px 0; font-size: 1.05rem; }
.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 14px;
}
.panel-header.compact { margin-bottom: 10px; }
.filters { display: flex; gap: 8px; align-items: center; }

input, textarea, select {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 12px;
  font: inherit;
  font-size: 0.92rem;
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--primary);
}
label { display: block; font-size: 0.82rem; color: var(--muted); margin-bottom: 4px; }

.stack { display: flex; flex-direction: column; gap: 12px; }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.btn {
  border: none;
  border-radius: 10px;
  padding: 9px 14px;
  font: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.btn.full { width: 100%; }
.btn.small { padding: 6px 11px; font-size: 0.82rem; }
.btn.primary { background: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-hover); }
.btn.secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.btn.secondary:hover { border-color: var(--primary); }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--text); }
.btn.danger { background: rgba(239, 68, 68, 0.16); color: #fca5a5; border: 1px solid rgba(239, 68, 68, 0.35); }

.pill {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
}
.pill.online { background: rgba(34, 197, 94, 0.16); color: #86efac; }
.pill.offline { background: rgba(239, 68, 68, 0.16); color: #fca5a5; }
.pill.neutral { background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }

.messages-list { display: flex; flex-direction: column; gap: 12px; }
.msg-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-left: 4px solid var(--primary);
  border-radius: 12px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.msg-card.urgency-critical { border-left-color: var(--danger); background: rgba(239, 68, 68, 0.08); }
.msg-card.urgency-high { border-left-color: var(--warn); }
.msg-card.urgency-low { border-left-color: #64748b; }

.msg-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.model-chip {
  background: rgba(79, 140, 255, 0.18);
  color: #93c5fd;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
}
.urgency-badge {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  padding: 2px 7px;
  border-radius: 6px;
}
.urgency-badge.critical { background: var(--danger); color: #fff; }
.urgency-badge.high { background: rgba(245, 158, 11, 0.25); color: #fcd34d; }
.urgency-badge.normal { background: rgba(79, 140, 255, 0.2); color: #93c5fd; }
.urgency-badge.low { background: rgba(100, 116, 139, 0.25); color: #cbd5e1; }

.msg-title { font-weight: 700; font-size: 1rem; margin: 0; }
.msg-body { margin: 0; color: #d5def2; white-space: pre-wrap; font-size: 0.92rem; }
.msg-image { display: block; max-width: 100%; max-height: 360px; margin-top: 8px; border-radius: 8px; border: 1px solid rgba(148, 163, 184, 0.25); background: #0b0f17; object-fit: contain; }

.actions-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 4px; }
.replies-box {
  background: rgba(11, 15, 23, 0.55);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.reply-form { display: flex; gap: 8px; margin-top: 4px; }
.reply-form input { padding: 7px 10px; font-size: 0.85rem; }

.key-form { display: flex; gap: 8px; margin-bottom: 12px; }
.keys-list { display: flex; flex-direction: column; gap: 8px; }
.key-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  background: var(--surface-2);
  padding: 8px 10px;
  border-radius: 10px;
  font-size: 0.84rem;
}
.new-key-banner {
  background: rgba(34, 197, 94, 0.12);
  border: 1px solid rgba(34, 197, 94, 0.35);
  border-radius: 10px;
  padding: 10px;
  font-size: 0.82rem;
  margin-bottom: 10px;
  word-break: break-all;
}

.code-box {
  background: #080b12;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  font-size: 0.78rem;
  overflow-x: auto;
  color: #a5f3fc;
  margin: 8px 0;
}
.snippet-actions { display: flex; gap: 8px; }

.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: #1e293b;
  color: #fff;
  border: 1px solid var(--primary);
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 0.88rem;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.4);
  z-index: 99;
}
