:root {
  --sb-bg: #0f172a;
  --sb-text: #94a3b8;
  --sb-text-hi: #f1f5f9;
  --sb-active: rgba(255,255,255,0.09);
  --sb-hover: rgba(255,255,255,0.05);
  --bg: #f1f5f9;
  --surface: #ffffff;
  --border: #e2e8f0;
  --ink: #0f172a;
  --muted: #64748b;
  --accent: #2563eb;
  --accent-hi: #1d4ed8;
  --success: #059669;
  --success-bg: #d1fae5;
  --danger: #dc2626;
  --danger-bg: #fee2e2;
  --warn: #d97706;
  --warn-bg: #fef3c7;
  --radius: 6px;
  --radius-lg: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,.1),0 1px 2px rgba(0,0,0,.06);
  --shadow-lg: 0 10px 25px rgba(0,0,0,.12),0 4px 6px rgba(0,0,0,.05);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
}

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

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

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

.hidden { display: none !important; }

/* ── Login ──────────────────────────────────────────────────────── */

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: var(--sb-bg);
  padding: 24px;
}

.login-card {
  width: min(400px, 100%);
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 36px 32px;
  box-shadow: var(--shadow-lg);
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 28px;
}

.login-icon {
  width: 38px;
  height: 38px;
  background: var(--accent);
  border-radius: 8px;
  display: grid;
  place-items: center;
  color: #fff;
  font-size: 17px;
  font-weight: 700;
  flex-shrink: 0;
}

.login-name {
  font-size: 14px;
  font-weight: 700;
  color: var(--ink);
}

.login-sub {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .05em;
}

.login-card h2 {
  margin: 0 0 20px;
  font-size: 22px;
  font-weight: 700;
}

.lf { margin-bottom: 14px; }

.lf label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .05em;
  margin-bottom: 5px;
}

.lf input {
  width: 100%;
  height: 38px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  padding: 0 10px;
}

.lf input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(37,99,235,.12); }

.err-msg { color: var(--danger); font-size: 13px; margin: 8px 0 0; min-height: 18px; }

/* ── Buttons ────────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 34px;
  padding: 0 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  text-decoration: none;
  transition: background 120ms, border-color 120ms;
}

.btn:hover { background: #f8fafc; border-color: #cbd5e1; }
.btn:focus { outline: none; box-shadow: 0 0 0 3px rgba(37,99,235,.18); }
.btn:disabled { opacity: .5; cursor: not-allowed; pointer-events: none; }

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

.btn-danger { color: var(--danger); border-color: #fca5a5; }
.btn-danger:hover { background: #fef2f2; }

.btn-sm { height: 28px; padding: 0 10px; font-size: 12px; }
.btn-full { width: 100%; justify-content: center; height: 40px; margin-top: 6px; }

/* ── Shell layout ───────────────────────────────────────────────── */

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

/* ── Sidebar ────────────────────────────────────────────────────── */

.sidebar {
  width: 210px;
  flex-shrink: 0;
  background: var(--sb-bg);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sb-brand {
  padding: 16px 14px;
  border-bottom: 1px solid rgba(255,255,255,.06);
}

.sb-brand-name {
  font-size: 13px;
  font-weight: 700;
  color: #f1f5f9;
  letter-spacing: .01em;
}

.sb-brand-sub { font-size: 11px; color: #475569; margin-top: 2px; }

.sb-nav {
  padding: 8px 6px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sb-nav button {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 10px;
  border: none;
  border-radius: var(--radius);
  background: transparent;
  color: var(--sb-text);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  transition: background 120ms, color 120ms;
}

.sb-nav button:hover { background: var(--sb-hover); color: var(--sb-text-hi); }
.sb-nav button.active { background: var(--sb-active); color: var(--sb-text-hi); }

.sb-icon { font-size: 14px; width: 18px; text-align: center; flex-shrink: 0; }

.sb-badge {
  margin-left: auto;
  background: rgba(59,130,246,.25);
  color: #93c5fd;
  border-radius: 99px;
  padding: 1px 7px;
  font-size: 11px;
  font-weight: 700;
}

.sb-footer {
  padding: 12px 14px;
  border-top: 1px solid rgba(255,255,255,.06);
}

.sb-user {
  color: #94a3b8;
  font-size: 12px;
  margin: 0 0 8px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sb-user strong { display: block; color: #e2e8f0; font-size: 13px; margin-bottom: 1px; }

.sb-signout {
  width: 100%;
  justify-content: center;
  color: #94a3b8;
  border-color: rgba(255,255,255,.1);
  background: transparent;
  font-size: 12px;
}

.sb-signout:hover { background: rgba(255,255,255,.06); border-color: rgba(255,255,255,.15); color: #f1f5f9; }

/* ── Main content ───────────────────────────────────────────────── */

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

.topbar {
  height: 52px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar-title { font-size: 15px; font-weight: 700; color: var(--ink); margin: 0; }
.topbar-right { display: flex; gap: 8px; align-items: center; }

.content { flex: 1; padding: 18px 20px; overflow-x: hidden; }

/* ── Views ──────────────────────────────────────────────────────── */

.view { display: grid; gap: 16px; }

/* ── Panels ─────────────────────────────────────────────────────── */

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.panel-hdr {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 16px;
  border-bottom: 1px solid var(--border);
  background: #f8fafc;
  gap: 10px;
}

.panel-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .07em;
  margin: 0;
}

.panel-body { padding: 16px; }

/* ── Form grids ─────────────────────────────────────────────────── */

.fg {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(185px, 1fr));
  gap: 11px;
  align-items: end;
}

.fg-full { grid-column: 1 / -1; }

.fld { display: grid; gap: 5px; }

.fld label {
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .04em;
}

.fld input, .fld select {
  height: 34px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  padding: 0 9px;
  font-size: 13px;
  transition: border-color 150ms;
}

.fld input:focus, .fld select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37,99,235,.1);
}

.field-help {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.fld-check {
  display: flex;
  align-items: center;
  gap: 7px;
  padding-top: 17px;
  font-size: 13px;
  color: var(--ink);
}

.fld-check input[type="checkbox"] { width: 15px; height: 15px; cursor: pointer; flex-shrink: 0; }
.fld-check label { text-transform: none; letter-spacing: 0; color: var(--ink); font-size: 13px; font-weight: 500; cursor: pointer; }

.form-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  padding-top: 11px;
  border-top: 1px solid var(--border);
  margin-top: 2px;
}

/* ── Tables ─────────────────────────────────────────────────────── */

.table-wrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; }

thead tr { background: #f8fafc; }

th {
  padding: 8px 12px;
  text-align: left;
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .06em;
  white-space: nowrap;
  border-bottom: 1px solid var(--border);
}

td {
  padding: 9px 12px;
  font-size: 13px;
  color: var(--ink);
  border-top: 1px solid var(--border);
  vertical-align: middle;
}

tr:first-child td { border-top: none; }
tbody tr:hover td { background: #f8fafc; }

/* ── Status chips ───────────────────────────────────────────────── */

.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 20px;
  padding: 0 7px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  white-space: nowrap;
}

.chip-dot { width: 5px; height: 5px; border-radius: 50%; flex-shrink: 0; }

.chip-green  { background: var(--success-bg); color: var(--success); }
.chip-green .chip-dot  { background: var(--success); }

.chip-blue   { background: #dbeafe; color: #1d4ed8; }
.chip-blue .chip-dot   { background: var(--accent); }

.chip-red    { background: var(--danger-bg); color: var(--danger); }
.chip-red .chip-dot    { background: var(--danger); }

.chip-yellow { background: var(--warn-bg); color: var(--warn); }
.chip-yellow .chip-dot { background: var(--warn); }

.chip-gray   { background: #f1f5f9; color: var(--muted); }
.chip-gray .chip-dot   { background: #94a3b8; }

/* ── Row actions ────────────────────────────────────────────────── */

.row-actions { display: flex; gap: 5px; align-items: center; flex-wrap: nowrap; }

.access-btns {
  display: flex;
  gap: 4px;
  align-items: center;
  flex-wrap: wrap;
}

.dur-input {
  width: 58px;
  height: 28px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0 6px;
  font-size: 12px;
  color: var(--ink);
}

/* ── Item lists (clients / sites) ───────────────────────────────── */

.item-list { display: flex; flex-direction: column; }

.list-item {
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: start;
}

.list-item:first-child { border-top: none; }

.item-main { min-width: 0; }

.item-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  margin: 0 0 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.item-meta {
  font-size: 12px;
  color: var(--muted);
  margin: 0 0 6px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.assoc-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px;
  margin-top: 6px;
}

.assoc-row input {
  height: 28px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0 8px;
  font-size: 12px;
  color: var(--ink);
  background: var(--surface);
}

.assoc-row input:focus { outline: none; border-color: var(--accent); }

/* ── Workspace split ────────────────────────────────────────────── */

.ws-split {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

/* ── URL display ────────────────────────────────────────────────── */

.url-cell { display: flex; align-items: center; gap: 6px; max-width: 280px; }
.url-cell a { font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.btn-copy {
  flex-shrink: 0;
  height: 22px;
  width: 22px;
  padding: 0;
  display: grid;
  place-items: center;
  font-size: 11px;
  border-radius: 4px;
}

/* ── Misc ───────────────────────────────────────────────────────── */

.text-muted { color: var(--muted); }
.text-sm { font-size: 12px; }
.text-mono { font-family: ui-monospace, "Cascadia Code", monospace; font-size: 12px; }

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

pre {
  margin: 0;
  padding: 14px 16px;
  background: #0f172a;
  color: #94a3b8;
  border-radius: var(--radius-lg);
  font-size: 12px;
  line-height: 1.65;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-all;
  min-height: 160px;
}

/* ── Toast ──────────────────────────────────────────────────────── */

.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  max-width: min(380px, calc(100vw - 40px));
  background: #0f172a;
  color: #e2e8f0;
  border-radius: var(--radius-lg);
  padding: 11px 16px;
  font-size: 13px;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
  z-index: 100;
}

.toast.visible { opacity: 1; transform: translateY(0); }
.toast.toast-err { background: #7f1d1d; }

/* ── Responsive ─────────────────────────────────────────────────── */

@media (max-width: 900px) {
  .app-shell { flex-direction: column; }

  .sidebar {
    width: 100%;
    height: auto;
    position: static;
    flex-direction: row;
    flex-wrap: wrap;
    overflow-y: visible;
  }

  .sb-brand { padding: 10px 14px; border-bottom: none; border-right: 1px solid rgba(255,255,255,.06); flex-shrink: 0; }
  .sb-brand-sub { display: none; }

  .sb-nav { flex-direction: row; flex-wrap: wrap; padding: 6px; flex: 1; gap: 3px; }
  .sb-nav button { width: auto; }
  .sb-icon { display: none; }

  .sb-footer { width: 100%; border-top: 1px solid rgba(255,255,255,.06); padding: 8px 14px; display: flex; align-items: center; gap: 10px; }
  .sb-user { margin: 0; flex: 1; }

  .ws-split { grid-template-columns: 1fr; }
  .fg { grid-template-columns: 1fr; }
}

@media (max-width: 620px) {
  .content { padding: 12px; }
  .topbar { padding: 0 12px; }
  .sb-badge { display: none; }
}
