:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-soft: #f8fafb;
  --ink: #182126;
  --muted: #637078;
  --line: #dfe5e8;
  --line-strong: #c8d1d6;
  --accent: #142c35;
  --accent-soft: #e8f0f2;
  --success: #1d6b4f;
  --warning: #8b5b16;
  --danger: #a23838;
  --shadow: 0 18px 55px rgba(19, 38, 46, 0.08);
  --radius: 16px;
  --radius-sm: 10px;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body { margin: 0; min-height: 100vh; color: var(--ink); background: var(--bg); }
button, input, select { font: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 32px 20px;
  background:
    radial-gradient(circle at 10% 10%, rgba(20, 44, 53, 0.12), transparent 34%),
    linear-gradient(145deg, #edf2f4 0%, #f8fafb 58%, #eef3f5 100%);
}

.auth-card {
  width: min(100%, 520px);
  padding: 38px;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--shadow);
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand-large { margin-bottom: 38px; }
.brand-mark {
  width: 42px; height: 42px; display: grid; place-items: center;
  border-radius: 12px; background: var(--accent); color: #fff; font-size: 13px; font-weight: 800; letter-spacing: .04em;
}
.brand strong, .brand span { display: block; }
.brand strong { font-size: 15px; letter-spacing: -.01em; }
.brand div > span { margin-top: 2px; color: var(--muted); font-size: 12px; }

h1, h2, h3 { margin: 0; letter-spacing: -.025em; }
h1 { font-size: clamp(26px, 3vw, 34px); }
h2 { font-size: 21px; }
h3 { font-size: 16px; }
p { line-height: 1.55; }
.eyebrow { margin: 0 0 8px; color: var(--muted); font-size: 11px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
.muted { color: var(--muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; overflow-wrap: anywhere; }

.stack { display: flex; flex-direction: column; }
.gap-sm { gap: 10px; }
.gap-md { gap: 16px; }
.field { display: grid; gap: 7px; }
.field > span { font-size: 12px; font-weight: 700; color: #405059; }
input, select {
  width: 100%; min-height: 42px; padding: 9px 11px; color: var(--ink); background: #fff;
  border: 1px solid var(--line-strong); border-radius: 9px; outline: none;
}
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(20,44,53,.10); }

.button {
  min-height: 40px; padding: 9px 14px; border-radius: 9px; border: 1px solid transparent;
  font-weight: 750; font-size: 13px; transition: transform .12s ease, opacity .12s ease, background .12s ease;
}
.button:hover { transform: translateY(-1px); }
.button:disabled { cursor: not-allowed; opacity: .55; transform: none; }
.button.primary { color: #fff; background: var(--accent); }
.button.secondary { color: var(--accent); background: #fff; border-color: var(--line-strong); }
.button.ghost { color: #dce6ea; background: rgba(255,255,255,.06); border-color: rgba(255,255,255,.13); }
.button.danger { color: var(--danger); background: #fff; border-color: #e6bcbc; }
.button.full { width: 100%; }
.button.small { min-height: 34px; padding: 6px 10px; font-size: 12px; }

.form-note { margin: 0; padding: 10px 12px; border-radius: 9px; background: var(--accent-soft); color: var(--accent); font-size: 12px; }
.staging-box { margin-top: 22px; padding: 14px; border: 1px dashed var(--line-strong); border-radius: 12px; background: var(--surface-soft); }
.staging-box summary { font-weight: 750; font-size: 13px; cursor: pointer; }
.staging-box p { color: var(--muted); font-size: 12px; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 236px minmax(0,1fr); }
.sidebar {
  position: sticky; top: 0; height: 100vh; padding: 24px 18px; display: flex; flex-direction: column;
  color: #f6f9fa; background: #10262f; border-right: 1px solid rgba(255,255,255,.08);
}
.sidebar .brand { padding: 0 6px; }
.sidebar .brand div > span { color: #9eb1ba; }
.nav { display: grid; gap: 6px; margin-top: 34px; }
.nav-item {
  width: 100%; padding: 10px 11px; text-align: left; color: #b8c7ce; background: transparent;
  border: 1px solid transparent; border-radius: 9px; font-weight: 700; font-size: 13px;
}
.nav-item:hover, .nav-item.active { color: #fff; background: rgba(255,255,255,.08); }
.sidebar-footer { margin-top: auto; display: grid; gap: 12px; }
.identity { padding: 12px; border-radius: 10px; background: rgba(255,255,255,.06); }
.identity strong { display: block; font-size: 12px; }
.identity span { display: block; margin-top: 4px; color: #9eb1ba; font-size: 11px; overflow-wrap: anywhere; }

.workspace { min-width: 0; padding: 34px clamp(22px, 4vw, 56px) 56px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 30px; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.health-pill { padding: 7px 10px; border-radius: 999px; background: #eceff1; color: var(--muted); font-size: 11px; font-weight: 800; }
.health-pill.ok { background: #e7f3ed; color: var(--success); }
.health-pill.error { background: #f8eaea; color: var(--danger); }

.view { display: grid; gap: 20px; }
.grid { display: grid; gap: 16px; }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0,1fr)); }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
.card { padding: 20px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: 0 6px 24px rgba(19,38,46,.035); }
.card-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.card-header p { margin: 5px 0 0; }
.stat-card { min-height: 122px; }
.stat-value { margin-top: 16px; font-size: 32px; font-weight: 800; letter-spacing: -.04em; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 11px 10px; text-align: left; border-bottom: 1px solid var(--line); font-size: 12px; vertical-align: middle; }
th { color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: .08em; }
tr:last-child td { border-bottom: 0; }

.badge { display: inline-flex; align-items: center; gap: 5px; padding: 5px 8px; border-radius: 999px; background: #edf1f3; color: #52616a; font-size: 10px; font-weight: 800; }
.badge.active, .badge.enabled { background: #e7f3ed; color: var(--success); }
.badge.disabled, .badge.inactive { background: #f8eaea; color: var(--danger); }
.badge.role { background: var(--accent-soft); color: var(--accent); }

.toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; }
.search { max-width: 320px; }
.list { display: grid; gap: 12px; }
.site-row, .membership-card { padding: 16px; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
.site-row { display: grid; grid-template-columns: minmax(0,1.4fr) minmax(0,1fr) auto; gap: 16px; align-items: center; }
.site-meta { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }

.scope-banner { padding: 14px 16px; border: 1px solid #cbd9de; border-radius: 12px; background: #eef4f6; }
.scope-banner strong { display: block; font-size: 13px; }
.scope-banner span { display: block; margin-top: 3px; color: var(--muted); }

.checkbox-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 8px; }
.check { display: flex; align-items: center; gap: 8px; min-height: 36px; padding: 7px 9px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-soft); font-size: 12px; }
.check input { width: auto; min-height: auto; margin: 0; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 12px; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.separator { height: 1px; margin: 18px 0; background: var(--line); }
.empty { padding: 26px; text-align: center; color: var(--muted); border: 1px dashed var(--line-strong); border-radius: 12px; background: var(--surface-soft); }

.toast-region { position: fixed; z-index: 100; right: 20px; top: 20px; display: grid; gap: 8px; width: min(380px, calc(100vw - 40px)); }
.toast { padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px; background: #fff; box-shadow: var(--shadow); font-size: 12px; }
.toast.success { border-color: #b8dacb; }
.toast.error { border-color: #e6bcbc; color: var(--danger); }

@media (max-width: 980px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; padding: 16px; flex-direction: row; align-items: center; gap: 16px; }
  .nav { margin: 0; display: flex; flex: 1; overflow-x: auto; }
  .sidebar-footer { margin: 0; display: flex; align-items: center; }
  .identity { display: none; }
  .button.ghost.full { width: auto; white-space: nowrap; }
  .grid.cols-4 { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .site-row { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  .auth-card { padding: 26px 20px; }
  .sidebar { align-items: flex-start; flex-wrap: wrap; }
  .sidebar .brand { width: 100%; }
  .nav { width: 100%; order: 2; }
  .sidebar-footer { margin-left: auto; position: absolute; right: 16px; top: 18px; }
  .workspace { padding: 24px 16px 40px; }
  .topbar { align-items: flex-start; flex-direction: column; }
  .grid.cols-4, .grid.cols-2, .form-grid, .checkbox-grid { grid-template-columns: 1fr; }
}
