:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #1b1f24;
  --muted: #5f6b7a;
  --border: #dde2e8;
  --accent: #3b5bdb;
  --accent-text: #ffffff;
  --user-bubble: #e7ecfb;
  --danger: #c92a2a;
  --warn-bg: #fff4e0;
  --warn-border: #f0b44c;
  --ok: #2b8a3e;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111418;
    --surface: #1a1f25;
    --text: #e6e9ed;
    --muted: #95a1ae;
    --border: #2c333b;
    --accent: #7b93f5;
    --accent-text: #0d1117;
    --user-bubble: #243052;
    --danger: #ff6b6b;
    --warn-bg: #2d2412;
    --warn-border: #a8761f;
    --ok: #51cf66;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

a { color: var(--accent); }

header {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 12px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

header .brand { font-weight: 700; font-size: 18px; color: var(--text); text-decoration: none; }
header nav { display: flex; gap: 16px; flex: 1; }
header nav a { color: var(--muted); text-decoration: none; }
header nav a.active { color: var(--text); font-weight: 600; }
header .user { color: var(--muted); font-size: 14px; }

main { max-width: 1000px; margin: 0 auto; padding: 32px 16px; }

h1 { margin: 0 0 8px; }
.subtitle { color: var(--muted); margin: 0 0 24px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px;
  margin-bottom: 20px;
}

.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; }
.stat .label { color: var(--muted); font-size: 13px; }
.stat .value { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }

.button, button {
  display: inline-block;
  background: var(--accent);
  color: var(--accent-text);
  border: none;
  border-radius: 6px;
  padding: 9px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
}
button:disabled { opacity: 0.6; cursor: wait; }
button.secondary { background: transparent; color: var(--accent); border: 1px solid var(--border); }
button.danger { background: transparent; color: var(--danger); border: 1px solid var(--border); padding: 4px 10px; }

label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 4px; }
input, select, textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}
.form-row { margin-bottom: 14px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
.status-active { color: var(--ok); }
.status-revoked { color: var(--muted); }

code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
pre { background: var(--bg); border: 1px solid var(--border); border-radius: 6px; padding: 12px; overflow-x: auto; }

.notice { background: var(--warn-bg); border: 1px solid var(--warn-border); border-radius: 8px; padding: 16px; margin-bottom: 20px; }
.notice code { word-break: break-all; }
.error { color: var(--danger); }
.muted { color: var(--muted); }
.hidden { display: none; }

/* Chat */
.chat { display: flex; flex-direction: column; height: calc(100vh - 200px); min-height: 400px; }
.messages { flex: 1; overflow-y: auto; padding: 8px 0; }
.msg { max-width: 80%; margin: 8px 0; padding: 10px 14px; border-radius: 10px; white-space: pre-wrap; }
.msg.user { margin-left: auto; background: var(--user-bubble); }
.msg.assistant { background: var(--surface); border: 1px solid var(--border); }
.msg .meta { display: block; margin-top: 6px; font-size: 12px; color: var(--muted); }
.composer { display: flex; gap: 8px; padding-top: 12px; border-top: 1px solid var(--border); }
.composer textarea { resize: none; height: 60px; }

@media (max-width: 640px) {
  header { flex-wrap: wrap; gap: 8px 16px; padding: 12px 16px; }
  .form-grid { grid-template-columns: 1fr; }
  .msg { max-width: 95%; }
}
