:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --sidebar: #111827;
  --sidebar-fg: #d1d5db;
  --text: #111827;
  --muted: #6b7280;
  --border: #e5e7eb;
  --accent: #4f46e5;
  --accent-fg: #ffffff;
  --accent-soft: #eef2ff;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --success: #15803d;
  --success-soft: #f0fdf4;
  --radius: 10px;
  color-scheme: light;
  font-family: Inter, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  color: var(--text);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0f17;
    --surface: #131a26;
    --sidebar: #0a0d14;
    --sidebar-fg: #9ca3af;
    --text: #e5e7eb;
    --muted: #8b95a5;
    --border: #243045;
    --accent: #6366f1;
    --accent-soft: #1e1b4b;
    --danger: #f87171;
    --danger-soft: #2a1414;
    --success: #4ade80;
    --success-soft: #0f2418;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 16px; margin: 0; }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; overflow-wrap: anywhere; }

/* layout */
.center { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.sidebar { background: var(--sidebar); color: var(--sidebar-fg); display: flex; flex-direction: column; padding: 20px 12px; gap: 24px; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; }
.sidebar nav a { color: var(--sidebar-fg); text-decoration: none; padding: 8px 12px; border-radius: 8px; }
.sidebar nav a:hover { background: rgba(255, 255, 255, 0.06); color: #fff; }
.sidebar nav a.active { background: rgba(99, 102, 241, 0.2); color: #fff; }
.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 10px; }
.sidebar-foot .ghost { color: var(--sidebar-fg); border-color: rgba(255, 255, 255, 0.15); }
.whoami { display: flex; align-items: center; gap: 10px; color: #fff; padding: 0 4px; }
.brand { font-weight: 700; font-size: 17px; color: #fff; padding: 0 12px; display: flex; align-items: center; gap: 8px; }
.brand.big { font-size: 22px; color: var(--text); padding: 0; }
.logo { color: var(--accent); font-size: 1.3em; }
.content { padding: 32px 40px; max-width: 1100px; width: 100%; min-width: 0; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 20px; }

@media (max-width: 760px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar { flex-direction: row; flex-wrap: wrap; align-items: center; padding: 12px 16px; gap: 12px; }
  .sidebar nav { flex-direction: row; }
  .sidebar-foot { margin: 0 0 0 auto; flex-direction: row; align-items: center; }
  .sidebar .brand { padding: 0; font-size: 16px; }
  .sidebar nav { order: 3; width: 100%; overflow-x: auto; }
  .sidebar nav a { padding: 6px 10px; white-space: nowrap; }
  .whoami > div { display: none; }
  .content { padding: 20px 16px; }
  .page-head { flex-direction: column; align-items: stretch; }
  .toolbar input { max-width: none; flex: 1; min-width: 0; }

  /* tables become stacked cards */
  table thead, table .hide-sm { display: none; }
  table tr { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; padding: 12px 16px; border-bottom: 1px solid var(--border); }
  table tr:last-child { border-bottom: none; }
  table td, table tr:last-child td { padding: 0; border: none; }
  table td:first-child { flex-basis: 100%; }
  table td.actions { margin-left: auto; }
  table td.empty { flex-basis: 100%; padding: 24px 0; }
}

/* surfaces */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.card.padded { padding: 20px; margin-bottom: 16px; }
.narrow { max-width: 480px; }
.login { width: 100%; max-width: 360px; padding: 28px; display: flex; flex-direction: column; gap: 14px; }
.toolbar { display: flex; gap: 8px; margin-bottom: 12px; }
.toolbar input { max-width: 320px; }

/* table */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); padding: 10px 16px; border-bottom: 1px solid var(--border); }
td { padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
td.empty { text-align: center; color: var(--muted); padding: 40px; }
td.actions { text-align: right; white-space: nowrap; }
td.actions button + button { margin-left: 4px; }

/* controls */
button { font: inherit; cursor: pointer; border-radius: 8px; padding: 8px 14px; border: 1px solid transparent; background: none; color: inherit; }
button:disabled { opacity: 0.6; cursor: default; }
button.primary { background: var(--accent); color: var(--accent-fg); font-weight: 600; }
button.primary:hover:not(:disabled) { filter: brightness(1.08); }
button.ghost { border-color: var(--border); padding: 6px 12px; }
button.ghost:hover { background: var(--accent-soft); }
button.danger { color: var(--danger); }
button.danger:hover { background: var(--danger-soft); }
button.icon { font-size: 22px; line-height: 1; padding: 2px 8px; color: var(--muted); }

input[type='text'], input[type='password'], input[type='url'], input:not([type]) {
  font: inherit; width: 100%; padding: 9px 11px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text);
}
input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
input:disabled { opacity: 0.6; }
label { display: flex; flex-direction: column; gap: 6px; font-weight: 500; }
label.check { flex-direction: row; align-items: flex-start; gap: 10px; font-weight: 400; }
label.check > span { display: flex; flex-direction: column; }
.hint { font-weight: 400; font-size: 12px; color: var(--muted); }
.input-row { display: flex; gap: 8px; }
fieldset { border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; margin: 0; }
legend { font-weight: 500; padding: 0 4px; }
.form { display: flex; flex-direction: column; gap: 14px; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* bits */
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; background: var(--border); color: var(--text); margin-right: 4px; }
.badge.global { background: var(--accent-soft); color: var(--accent); }
.avatar { display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 50%; background: var(--accent); color: #fff; font-weight: 600; flex-shrink: 0; }
.avatar.sm { width: 24px; height: 24px; font-size: 12px; margin-right: 6px; }
.error { background: var(--danger-soft); color: var(--danger); padding: 10px 12px; border-radius: 8px; margin-bottom: 12px; }
.form .error { margin: 0; }
.success { background: var(--success-soft); color: var(--success); padding: 10px 12px; border-radius: 8px; }
.facts { display: grid; grid-template-columns: 120px 1fr; gap: 8px; margin: 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }

/* modal */
.backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.45); display: grid; place-items: center; padding: 16px; z-index: 10; }
.modal { background: var(--surface); border-radius: 12px; width: 100%; max-width: 460px; padding: 20px 22px; box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3); }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }

/* models & rules */
h3 { font-size: 14px; margin: 0; }
a { color: var(--accent); }
.notice { margin-bottom: 12px; }
select, input[type='number'] {
  font: inherit; width: 100%; padding: 9px 11px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text);
}
select:disabled { opacity: 0.6; }
.split { display: grid; grid-template-columns: 240px 1fr; gap: 16px; align-items: start; }
.list { display: flex; flex-direction: column; padding: 6px; }
.list-item { display: flex; justify-content: space-between; align-items: center; gap: 8px; text-align: left; padding: 10px 12px; border-radius: 8px; width: 100%; }
button.list-item:hover { background: var(--accent-soft); }
.list-item.active { background: var(--accent-soft); color: var(--accent); }
.detail { min-width: 0; margin: 0; }
.detail-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 16px; }
.detail-head h2 { font-size: 18px; margin-bottom: 4px; }
.row-actions { display: flex; gap: 4px; }
.section-head { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; }
.detail .table-wrap { margin: 12px -20px -20px; border-top: 1px solid var(--border); }
.prio { display: inline-grid; place-items: center; min-width: 28px; height: 24px; padding: 0 6px; border-radius: 6px; background: var(--bg); font-weight: 600; font-variant-numeric: tabular-nums; }
.grid2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (max-width: 1100px) {
  .split { grid-template-columns: 1fr; }
  .list { flex-direction: row; flex-wrap: wrap; gap: 4px; }
  .list-item { width: auto; }
}
@media (max-width: 760px) {
  .grid2 { grid-template-columns: 1fr; }
  .detail-head { flex-direction: column; }
}
.nowrap { white-space: nowrap; }
.provider-cell { min-width: 160px; }
.detail th, .detail td { padding-left: 12px; padding-right: 12px; }

/* api keys */
input[type='date'] {
  font: inherit; width: 100%; padding: 9px 11px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text);
}
.checks { display: flex; flex-direction: column; gap: 8px; max-height: 220px; overflow-y: auto; }
.badge.ok-badge { background: var(--success-soft); color: var(--success); }
.badge.danger-badge { background: var(--danger-soft); color: var(--danger); }
.badge.mono { font-size: 12px; margin-bottom: 2px; }
