:root {
  --ground: #F2F3F5;
  --surface: #FFFFFF;
  --surface-2: #E7E9ED;
  --line: #D6DAE1;
  --ink: #12151B;
  --muted: #5B6472;
  --silver: #6B7280;
  --accent: #1C6FD1;
  --accent-ink: #FFFFFF;
  --accent-soft: rgba(28, 111, 209, .10);
  --critical: #C1483A;
  --good: #1E9A64;
  --radius: 8px;
  --display: 'Chakra Petch', var(--sans);
  --sans: 'IBM Plex Sans', ui-sans-serif, system-ui, sans-serif;
  --shadow: 0 1px 2px rgba(20, 22, 28, .06), 0 10px 28px -14px rgba(20, 22, 28, .22);
}

/* Dark is the intended home turf of this palette - a console for people who
   already trust the badge on the login page, not a marketing page - so it's
   the default for both "no preference" and an explicit OS dark setting;
   light is the deliberate override, not an afterthought. */
@media (prefers-color-scheme: dark) {
  :root {
    --ground: #0A0C10; --surface: #12151B; --surface-2: #1A1F27;
    --line: #262C36; --ink: #E7EAF0; --muted: #8890A0; --silver: #B7BEC9;
    --accent: #4FB3FF; --accent-ink: #04101C; --accent-soft: rgba(79, 179, 255, .13);
    --critical: #FF6B5E; --good: #4FD98F;
    --shadow: 0 1px 2px rgba(0, 0, 0, .35), 0 12px 32px -14px rgba(0, 0, 0, .55);
  }
}

* { box-sizing: border-box; }
body {
  margin: 0; background: var(--ground); color: var(--ink);
  font-family: var(--sans); min-height: 100vh;
}
a { color: var(--accent); }
code { font-family: ui-monospace, monospace; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }

/* A faint tactical grid behind every page - the one atmospheric flourish,
   kept quiet enough to disappear the moment there's real content over it. */
.auth-page, .topbar + .dash {
  background-image:
    linear-gradient(var(--line) 1px, transparent 1px),
    linear-gradient(90deg, var(--line) 1px, transparent 1px);
  background-size: 34px 34px;
  background-position: center top;
  background-color: var(--ground);
  opacity: 1;
}
.auth-page { position: relative; overflow: hidden; }
.auth-page::before {
  content: ""; position: absolute; inset: -20%;
  background: radial-gradient(circle at 50% 30%, var(--accent-soft), transparent 60%);
  pointer-events: none;
}

/* -- badge mark -- */
.badge-mark { display: block; margin: 0 auto 14px; filter: drop-shadow(0 6px 18px var(--accent-soft)); }
.badge-mark.lg { width: 84px; height: 84px; }
.badge-mark.sm { width: 34px; height: 34px; margin: 0; }

/* -- auth pages (login / forbidden / 2fa) -- */
.auth-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.auth-card {
  position: relative; z-index: 1;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 36px 32px 32px; width: min(340px, 100%); box-shadow: var(--shadow);
}
.auth-card.wide { width: min(410px, 100%); }
.auth-card::before {
  content: ""; position: absolute; top: 0; left: 14px; right: 14px; height: 2px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  border-radius: 2px;
}
.totp-qr {
  display: flex; justify-content: center; padding: 14px; margin: 4px 0 16px;
  background: #fff; border: 1px solid var(--line); border-radius: 8px;
}
.totp-qr svg { width: 168px; height: 168px; }
.totp-manual { margin: 0 0 18px; }
.totp-manual summary {
  font-size: 12.5px; color: var(--muted); cursor: pointer; margin-bottom: 8px;
}
.totp-secret {
  font-family: ui-monospace, monospace; font-size: 17px; letter-spacing: .04em;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px;
  padding: 12px 14px; text-align: center; margin: 4px 0;
}
.hint { font-size: 12.5px; color: var(--muted); margin: 8px 0 18px; }
.auth-card h1 {
  margin: 0 0 6px; font-size: 23px; text-align: center;
  font-family: var(--display); font-weight: 600; letter-spacing: .01em;
}
.auth-card .sub { color: var(--muted); font-size: 14px; margin: 0 0 22px; text-align: center; }
.auth-card form { display: flex; flex-direction: column; gap: 6px; }
.auth-card label { font-size: 11.5px; font-weight: 600; color: var(--muted); margin-top: 10px;
  text-transform: uppercase; letter-spacing: .06em; }
.auth-card input {
  font: inherit; font-size: 15px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 7px;
  background: var(--surface-2); color: var(--ink); transition: border-color .15s, box-shadow .15s;
}
.auth-card input:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
.auth-card button, .link-btn {
  margin-top: 18px; padding: 11px; border: 0; border-radius: 7px;
  background: var(--accent); color: var(--accent-ink); cursor: pointer;
  font-family: var(--display); font-weight: 600; font-size: 14px;
  text-transform: uppercase; letter-spacing: .06em;
  transition: filter .15s, transform .1s;
}
.auth-card button:hover { filter: brightness(1.08); }
.auth-card button:active { transform: translateY(1px); }
.error { background: color-mix(in srgb, var(--critical) 14%, transparent); color: var(--critical);
  border: 1px solid color-mix(in srgb, var(--critical) 30%, transparent);
  border-radius: 8px; padding: 9px 12px; font-size: 13.5px; margin: 0 0 14px; }
.back-link {
  display: block; margin-top: 18px; font-size: 13px; text-align: center; color: var(--muted);
  text-transform: uppercase; letter-spacing: .05em; font-family: var(--display); font-weight: 600;
}

/* -- dashboard -- */
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 14px 24px;
  border-bottom: 1px solid var(--line); background: var(--surface);
}
.brand {
  font-family: var(--display); font-weight: 600; font-size: 17px; letter-spacing: .02em;
  display: flex; align-items: center; gap: 10px;
}
.who { margin-left: auto; font-size: 13.5px; color: var(--muted); display: flex; align-items: center; gap: 8px; }
.role-pill {
  font-family: var(--display); font-size: 10px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .05em; padding: 3px 8px; border-radius: 999px;
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--line);
}
.role-pill[data-role="admin"], .role-pill[data-role="superadmin"] {
  background: var(--accent-soft); color: var(--accent); border-color: transparent;
}
.link-btn {
  margin: 0; background: none; color: var(--muted); padding: 0; font-size: 12.5px;
  text-transform: uppercase; letter-spacing: .05em; font-family: var(--display); font-weight: 600;
}
.link-btn:hover { color: var(--ink); }

.dash { max-width: 900px; margin: 0 auto; padding: 40px 24px; min-height: calc(100vh - 53px); }
.dash h1 {
  font-family: var(--display); font-weight: 600; font-size: 21px; margin-bottom: 20px;
  letter-spacing: .01em;
}
.empty {
  color: var(--muted); border: 1px dashed var(--line); border-radius: var(--radius);
  padding: 28px; text-align: center; font-size: 14px;
}

.project-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 14px; }
.project-tile {
  position: relative; overflow: hidden;
  display: flex; flex-direction: column; gap: 6px; padding: 18px 20px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  text-decoration: none; color: var(--ink); transition: border-color .15s, transform .12s;
  box-shadow: var(--shadow);
}
.project-tile::before {
  content: ""; position: absolute; top: 0; left: 0; right: 0; height: 3px;
  background: var(--accent); transform: scaleX(0); transform-origin: left;
  transition: transform .18s;
}
.project-tile:hover { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); transform: translateY(-1px); }
.project-tile:hover::before { transform: scaleX(1); }
.project-name { font-weight: 600; font-size: 15px; }
.project-role {
  font-size: 10.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em;
  font-family: var(--display); font-weight: 600;
}
