:root {
  --bg: #0b0f17;
  --panel: #131a27;
  --panel-2: #1a2231;
  --border: #232c3d;
  --text: #e8ecf3;
  --muted: #8993a8;
  --accent: #1487c9;
  --accent-2: #0f6ea3;
  --danger: #ef4444;
  --ok: #22c55e;
  --grace: #f5b942;
  --blocked: #ef4444;
  --unknown: #6b7280;
  --mono: "SF Mono", "Cascadia Code", "Consolas", "JetBrains Mono", monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

a { color: inherit; }

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

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

/* ---- Auth (login) ---- */

.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.auth-card {
  width: 100%;
  max-width: 360px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 36px 32px 32px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.35);
}

.auth-logo { display: flex; justify-content: center; margin-bottom: 22px; }

.auth-logo img {
  background: #ffffff;
  border-radius: 14px;
  padding: 14px 20px;
  max-width: 170px;
  width: 100%;
  height: auto;
  display: block;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.3);
}

.auth-card h1 { font-size: 18px; margin: 0 0 4px; text-align: center; }
.auth-card p.sub { color: var(--muted); font-size: 13px; margin: 0 0 24px; text-align: center; }

/* ---- Form basics ---- */

label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }

input[type="text"], input[type="password"], input[type="number"], input[type="search"], textarea {
  width: 100%;
  padding: 10px 12px;
  margin-bottom: 6px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
}

input[type="text"], input[type="password"], input[type="number"], input[type="search"] { margin-bottom: 16px; }

textarea {
  resize: vertical;
  min-height: 64px;
  line-height: 1.4;
}

input:focus, textarea:focus { outline: none; border-color: var(--accent); }

.field-hint {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin: -2px 0 16px;
}

button {
  width: 100%;
  padding: 10px 12px;
  background: var(--accent);
  border: none;
  border-radius: 8px;
  color: white;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}

button:hover { background: var(--accent-2); }
button:disabled { opacity: 0.6; cursor: default; }

.error {
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(239, 68, 68, 0.35);
  color: #ff9498;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 13px;
  margin-bottom: 16px;
}

.ok {
  background: rgba(34, 197, 94, 0.12);
  border: 1px solid rgba(34, 197, 94, 0.35);
  color: #7fe3b8;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 13px;
  margin-bottom: 16px;
}

.checkbox-row { display: flex; align-items: center; gap: 8px; margin-bottom: 16px; }
.checkbox-row input { width: auto; margin: 0; }

/* ---- Layout ---- */

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

.sidebar {
  width: 220px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 20px 12px;
  flex-shrink: 0;
}

.sidebar .brand { display: flex; align-items: center; gap: 10px; padding: 0 10px 24px; }

.sidebar .brand img {
  background: #ffffff;
  border-radius: 8px;
  padding: 4px 6px;
  height: 26px;
  width: auto;
  display: block;
}

.sidebar .brand-text { font-size: 14px; font-weight: 700; color: var(--text); }
.sidebar .brand-text b { color: var(--accent); font-weight: 700; }

.nav-item {
  display: block;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--muted);
  text-decoration: none;
  font-size: 14px;
  margin-bottom: 2px;
}

.nav-item:hover { background: var(--panel-2); color: var(--text); }
.nav-item.active { background: var(--panel-2); color: var(--text); font-weight: 600; }

.content { flex: 1; padding: 32px 40px; min-width: 0; }
.content h1 { font-size: 22px; margin: 0 0 4px; }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
}

.muted { color: var(--muted); }

.topbar {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 16px;
  margin-bottom: 20px;
  font-size: 13px;
  color: var(--muted);
}

.topbar a { color: var(--muted); }
.topbar a:hover { color: var(--text); }

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-bottom: 20px;
  gap: 16px;
}

.page-header h1 { margin: 0; }
.page-subtitle { color: var(--muted); font-size: 13px; margin: 4px 0 0; }

/* ---- Buttons ---- */

.btn {
  display: inline-block;
  width: auto;
  padding: 9px 16px;
  background: var(--accent);
  color: #fff;
  border-radius: 8px;
  text-decoration: none;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}

.btn:hover { background: var(--accent-2); }

.btn-small {
  width: auto;
  padding: 7px 12px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.btn-small:hover { border-color: var(--accent); }
.btn-small.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-small.btn-primary:hover { background: var(--accent-2); border-color: var(--accent-2); }
.btn-small.btn-danger { color: #ff9498; border-color: rgba(239, 68, 68, 0.35); background: transparent; }
.btn-small.btn-danger:hover { border-color: var(--danger); }

.btn-text {
  width: auto;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  padding: 8px 0;
}

.btn-text:hover { color: var(--text); }
.btn-danger-text { color: #ff9498; }
.btn-danger-text:hover { color: var(--danger); }

/* ---- Stat chips ---- */

.stat-row { display: flex; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }

.stat-chip {
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-left: 3px solid var(--border);
  border-radius: 10px;
  padding: 12px 18px;
  min-width: 96px;
}

.stat-num { font-size: 22px; font-weight: 700; font-family: var(--mono); }
.stat-label { font-size: 12px; color: var(--muted); }

.stat-chip.stat-ok { border-left-color: var(--ok); }
.stat-chip.stat-grace { border-left-color: var(--grace); }
.stat-chip.stat-blocked { border-left-color: var(--blocked); }
.stat-chip.stat-error { border-left-color: var(--unknown); }

/* ---- Search ---- */

.search-input { max-width: 320px; margin-bottom: 16px; }

/* ---- Client list ---- */

.client-rows {
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}

.client-row {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  padding: 14px 18px;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  text-align: left;
  cursor: pointer;
  font-size: 14px;
  border-radius: 0;
}

.client-row:last-child { border-bottom: none; }
.client-row:hover { background: var(--panel-2); }

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--unknown);
}

.dot-ok { background: var(--ok); }
.dot-grace { background: var(--grace); }
.dot-blocked { background: var(--blocked); }
.dot-error { background: var(--unknown); }

.client-info { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }
.client-name { font-weight: 600; }

.client-sub {
  font-size: 12.5px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pill {
  flex-shrink: 0;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
}

.pill-on { background: rgba(34, 197, 94, 0.15); color: #7fe3b8; }
.pill-off { background: rgba(139, 147, 167, 0.15); color: var(--muted); }

.chevron { color: var(--muted); font-size: 18px; flex-shrink: 0; }

.empty-state {
  background: var(--panel);
  border: 1px dashed var(--border);
  border-radius: 12px;
  padding: 40px 24px;
  text-align: center;
  color: var(--muted);
}

.empty-state .btn { margin-top: 12px; }

/* ---- Drawer ---- */

.drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(5, 8, 13, 0.55);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 40;
}

.drawer-overlay.open { opacity: 1; pointer-events: auto; }

.drawer {
  position: fixed;
  top: 50%;
  left: 50%;
  width: min(700px, 92vw);
  max-height: 86vh;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.5);
  transform: translate(-50%, -50%) scale(0.96);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.2s ease;
  z-index: 41;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.drawer.open {
  transform: translate(-50%, -50%) scale(1);
  opacity: 1;
  pointer-events: auto;
}

#drawer-content {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.drawer-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  padding: 24px 24px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.drawer-header h2 { font-size: 17px; margin: 0 0 4px; }
.client-url { color: var(--muted); font-size: 12.5px; word-break: break-all; }

.drawer-close {
  width: auto;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 13px;
  cursor: pointer;
  flex-shrink: 0;
}

.drawer-close:hover { color: var(--text); border-color: var(--accent); }

.drawer-scroll {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}

.drawer-form { padding: 20px 24px 4px; }

.drawer-section { margin-bottom: 24px; padding-bottom: 24px; border-bottom: 1px solid var(--border); }
.drawer-section:last-of-type { border-bottom: none; }
.drawer-section h3 { font-size: 12.5px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); margin: 0 0 14px; }

.field-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }

.drawer-footer {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  background: var(--panel);
}

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

.footer-actions .btn { flex-shrink: 0; width: auto; }

.form-msg { font-size: 13px; margin: 0; }
.form-msg:empty { display: none; }
.form-msg-error { color: #ff9498; }

/* ---- Toggle switch ---- */

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin: 16px 24px 0;
  padding: 14px 16px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.toggle-row strong { display: block; font-size: 14px; }
.toggle-hint { display: block; font-size: 12px; margin-top: 2px; }

.toggle-switch {
  width: 44px;
  height: 26px;
  padding: 0;
  border-radius: 999px;
  background: var(--border);
  border: none;
  position: relative;
  flex-shrink: 0;
  cursor: pointer;
  transition: background 0.15s ease;
}

.toggle-switch:hover { background: #3a4457; }
.toggle-switch.is-on { background: var(--ok); }
.toggle-switch.is-on:hover { background: #1ea854; }

.toggle-thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.15s ease;
}

.toggle-switch.is-on .toggle-thumb { transform: translateX(18px); }
.toggle-switch:disabled { opacity: 0.6; cursor: default; }

/* ---- State banner ---- */

.state-banner {
  margin: 16px 24px 0;
  padding: 16px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel-2);
}

.state-banner-main { display: flex; align-items: flex-start; gap: 12px; }

.state-icon {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  margin-top: 4px;
  flex-shrink: 0;
  background: var(--unknown);
}

.state-banner-ok .state-icon { background: var(--ok); }
.state-banner-grace .state-icon { background: var(--grace); }
.state-banner-blocked .state-icon { background: var(--blocked); }
.state-banner-error .state-icon { background: var(--unknown); }

.state-banner strong { display: block; font-size: 15px; margin-bottom: 2px; }
.state-detail { font-size: 13px; color: var(--muted); display: block; }

.state-banner-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.unlocked-tag { font-size: 12px; color: var(--muted); }

.pulse { animation: pulse 2s ease-in-out infinite; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}

/* ---- Toast ---- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translate(-50%, 16px);
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 50;
}

.toast.toast-show { opacity: 1; transform: translate(-50%, 0); }
.toast.toast-error { border-color: rgba(239, 68, 68, 0.4); color: #ff9498; }

/* ---- Responsive ---- */

@media (max-width: 760px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; display: flex; align-items: center; padding: 12px 16px; gap: 8px; }
  .sidebar .brand { padding: 0 8px 0 0; }
  .nav-item { margin-bottom: 0; }
  .content { padding: 20px; }
  .drawer { width: 94vw; max-height: 92vh; }
  .field-row { grid-template-columns: 1fr; }
  .page-header { flex-direction: column; align-items: flex-start; }
}

/* ---- Motion preference ---- */

@media (prefers-reduced-motion: reduce) {
  .drawer, .drawer-overlay, .toast, .toggle-switch, .toggle-thumb { transition: none; }
  .pulse { animation: none; }
}
