:root {
  --font-heading: 'Space Grotesk', sans-serif;
  --font-body: 'Inter', -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
}

:root[data-theme="dark"] {
  --bg: #14171C;
  --surface: #1B1F26;
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.2);
  --text: #E7E9EC;
  --text-muted: #9AA2AC;
  --text-faint: #6B7280;
  --accent: #3B6E8F;
  --accent-hover: #4d84a8;
  --accent-strong: #E8590C;
  --green-rgb: 34, 197, 94;
  --amber-rgb: 242, 194, 48;
  --red-rgb: 239, 68, 68;
  --green: rgb(var(--green-rgb));
  --amber: rgb(var(--amber-rgb));
  --red: rgb(var(--red-rgb));
  --radius: 10px;
  --radius-sm: 6px;
}

:root[data-theme="light"] {
  --bg: #F7F5F0;
  --surface: #FFFFFF;
  --border: #D8DCE1;
  --border-strong: #1B4F72;
  --text: #1E2530;
  --text-muted: #5A6472;
  --text-faint: #8A93A0;
  --accent: #1B4F72;
  --accent-hover: #163d59;
  --accent-strong: #D9622B;
  --green-rgb: 21, 128, 61;
  --amber-rgb: 180, 83, 9;
  --red-rgb: 185, 28, 28;
  --green: rgb(var(--green-rgb));
  --amber: rgb(var(--amber-rgb));
  --red: rgb(var(--red-rgb));
  --radius: 2px;
  --radius-sm: 2px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --bg: #14171C; --surface: #1B1F26; --border: rgba(255,255,255,0.08); --border-strong: rgba(255,255,255,0.2);
    --text: #E7E9EC; --text-muted: #9AA2AC; --text-faint: #6B7280;
    --accent: #3B6E8F; --accent-hover: #4d84a8; --accent-strong: #E8590C;
    --green-rgb: 34,197,94; --amber-rgb: 242,194,48; --red-rgb: 239,68,68;
    --green: rgb(var(--green-rgb)); --amber: rgb(var(--amber-rgb)); --red: rgb(var(--red-rgb));
    --radius: 10px; --radius-sm: 6px;
  }
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme]) {
    --bg: #F7F5F0; --surface: #FFFFFF; --border: #D8DCE1; --border-strong: #1B4F72;
    --text: #1E2530; --text-muted: #5A6472; --text-faint: #8A93A0;
    --accent: #1B4F72; --accent-hover: #163d59; --accent-strong: #D9622B;
    --green-rgb: 21,128,61; --amber-rgb: 180,83,9; --red-rgb: 185,28,28;
    --green: rgb(var(--green-rgb)); --amber: rgb(var(--amber-rgb)); --red: rgb(var(--red-rgb));
    --radius: 2px; --radius-sm: 2px;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  transition: background-color .25s ease, color .25s ease;
}

header, main, .card, .btn, .btn-secondary, input, table, th, td, .status, form,
nav a, nav button, .brand {
  transition: background-color .25s ease, color .25s ease, border-color .25s ease;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 28px 64px;
  border-bottom: 1px solid var(--border);
}
:root[data-theme="light"] header { border-bottom: 2px solid var(--border-strong); }

header .brand {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 1.15rem;
  color: var(--text);
  display: inline-flex;
  align-items: center;
  gap: 2px;
}
:root[data-theme="dark"] header .brand::before { content: "> "; color: var(--accent); }
:root[data-theme="dark"] header .brand::after {
  content: "_"; color: var(--accent-strong); margin-left: 2px;
  animation: cursorBlink 1.1s steps(1) infinite;
}
:root[data-theme="light"] header .brand {
  font-family: var(--font-heading);
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  font-size: 1.05rem;
}
@keyframes cursorBlink { 0%, 49% { opacity: 1; } 50%, 100% { opacity: 0; } }

nav { display: flex; align-items: center; gap: 32px; }
nav a, nav button {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.95rem;
  background: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
  padding: 0;
}
nav a:hover, nav button:hover { color: var(--text); }

#theme-toggle {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  background: transparent;
}
#theme-toggle:hover { color: var(--text); border-color: var(--text-muted); }

main {
  max-width: 880px;
  margin: 0 auto;
  padding: 40px 24px;
}

.btn {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 11px 24px;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
}
.btn:hover { background: var(--accent-hover); }
.btn:disabled { background: var(--border); color: var(--text-muted); cursor: not-allowed; }

.btn-secondary {
  background: transparent;
  border: 1px solid var(--border-strong);
  color: var(--text);
  border-radius: var(--radius-sm);
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  position: relative;
}
:root[data-theme="light"] .card::before {
  content: "";
  position: absolute; top: 12px; right: 12px;
  width: 7px; height: 7px; border-radius: 50%;
  border: 1px solid var(--accent-strong);
}
.card h3 { font-family: var(--font-heading); margin: 0 0 10px; font-size: 1.05rem; }
.meta { color: var(--text-muted); font-size: 0.8rem; margin: 3px 0; }

.status {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
:root[data-theme="light"] .status { border-radius: 3px; }
.status-active, .status-full { background: rgba(var(--green-rgb), 0.15); color: var(--green); }
.status-demo { background: rgba(var(--amber-rgb), 0.15); color: var(--amber); }
.expiring-soon { color: var(--amber); font-weight: 600; }
.status-expired, .status-forbidden, .status-hidden, .status-deprecated, .status-revoked, .status-closed {
  background: rgba(var(--red-rgb), 0.15); color: var(--red);
}

table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 16px;
}
th, td {
  text-align: left;
  padding: 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
th {
  font-family: var(--font-mono);
  color: var(--text-faint);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.matrix-cell { cursor: pointer; white-space: nowrap; }
.matrix-cell:hover { background: var(--border); }

.access-item { margin-bottom: 12px; }
.access-item:last-child { margin-bottom: 0; }
.access-item-header { font-family: var(--font-heading); font-weight: 600; font-size: 0.85rem; margin-bottom: 4px; }
.access-actions { margin-top: 6px; display: flex; gap: 6px; flex-wrap: wrap; }
.btn-small { padding: 4px 10px; font-size: 0.78rem; }
.subsection-label {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-top: 10px;
}
.subsection-label:first-of-type { margin-top: 6px; }

#create-user-form, #generate-offline-keys-form {
  max-width: none;
  margin: 16px 0 0;
  padding: 0;
  background: none;
  border: none;
}

form {
  max-width: 360px;
  margin: 48px auto 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
}
form h2 { font-family: var(--font-heading); margin-top: 0; }

label {
  display: block;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 6px;
  margin-top: 16px;
}

input {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.95rem;
  font-family: var(--font-body);
}
input:focus { outline: none; border-color: var(--accent); }

select {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.95rem;
  font-family: var(--font-body);
}
select:focus { outline: none; border-color: var(--accent); }

form .btn { width: 100%; margin-top: 24px; }

.error { color: var(--red); font-size: 0.85rem; margin-top: 12px; min-height: 1.2em; }
.hint { color: var(--text-muted); font-size: 0.8rem; margin-top: 16px; text-align: center; }

dialog {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  max-width: 420px;
  width: calc(100% - 48px);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.5); }
dialog form { max-width: none; margin: 0; padding: 0; background: none; border: none; }
dialog h2 { font-family: var(--font-heading); margin-top: 0; font-size: 1.15rem; }
