:root {
  --bg: #0e1116;
  --surface: #171b22;
  --surface-2: #1f242d;
  --border: #2a313c;
  --text: #e6e9ef;
  --muted: #8b94a3;
  --accent: #6d8bff;
  --accent-ink: #0e1116;
  --green: #3fb950;
  --amber: #d29922;
  --red: #f85149;
  --radius: 10px;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
code { font-family: var(--mono); background: var(--surface-2); padding: 1px 5px; border-radius: 5px; font-size: 0.85em; }

/* --- Gate (sign in/up) --- */
.gate {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; padding: 24px;
}
.gate-card {
  width: 100%; max-width: 420px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 32px;
}
.brand { display: flex; gap: 14px; align-items: center; margin-bottom: 24px; }
.brand.small { font-weight: 600; font-size: 15px; gap: 10px; margin: 0 0 28px; }
.brand h1 { font-size: 20px; margin: 0; }
.brand p { margin: 2px 0 0; font-size: 13px; }
.brand-mark {
  width: 42px; height: 42px; border-radius: 12px;
  display: block; object-fit: contain;
}
.brand.small .brand-mark { width: 26px; height: 26px; border-radius: 7px; }
.tabs { display: flex; gap: 6px; margin-bottom: 20px; background: var(--surface-2); padding: 4px; border-radius: 10px; }
.tab { flex: 1; padding: 8px; background: transparent; border: 0; color: var(--muted); border-radius: 7px; cursor: pointer; font-size: 13px; }
.tab.active { background: var(--surface); color: var(--text); }

.panel { display: flex; flex-direction: column; gap: 14px; }
label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
input, select, textarea {
  background: var(--bg); border: 1px solid var(--border); color: var(--text);
  padding: 9px 11px; border-radius: 8px; font-size: 14px; font-family: inherit;
}
textarea { resize: vertical; min-height: 80px; font-family: var(--mono); font-size: 12px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
.hint { font-size: 12px; color: var(--muted); margin: 4px 0 0; }

button { cursor: pointer; }
button.primary { background: var(--accent); color: var(--accent-ink); border: 0; padding: 10px 16px; border-radius: 8px; font-weight: 600; font-size: 14px; }
button.primary:hover { filter: brightness(1.08); }
button.ghost { background: transparent; border: 1px solid var(--border); color: var(--muted); padding: 7px 12px; border-radius: 8px; font-size: 13px; }
button.ghost:hover { color: var(--text); border-color: var(--muted); }
button:disabled { opacity: .5; cursor: not-allowed; }

/* --- App shell --- */
.app { display: grid; grid-template-columns: 240px 1fr; height: 100vh; }
.sidebar { background: var(--surface); border-right: 1px solid var(--border); padding: 22px 16px; display: flex; flex-direction: column; }
nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav-item {
  text-align: left; background: transparent; border: 0; color: var(--muted);
  padding: 9px 12px; border-radius: 8px; font-size: 14px; display: flex; align-items: center; justify-content: space-between;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--surface-2); color: var(--text); font-weight: 600; }
.badge { background: var(--amber); color: #1a1100; font-size: 11px; font-weight: 700; border-radius: 20px; padding: 1px 7px; }
.session { border-top: 1px solid var(--border); padding-top: 16px; display: flex; flex-direction: column; gap: 6px; }
.session-org { font-weight: 600; }

.content { display: flex; flex-direction: column; overflow: hidden; }
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 18px 28px; border-bottom: 1px solid var(--border); }
.topbar h2 { margin: 0; font-size: 18px; }
.view { padding: 28px; overflow-y: auto; }

.toast { padding: 7px 14px; border-radius: 8px; font-size: 13px; max-width: 60%; }
.toast.ok { background: rgba(63,185,80,.15); color: var(--green); border: 1px solid rgba(63,185,80,.3); }
.toast.err { background: rgba(248,81,73,.15); color: var(--red); border: 1px solid rgba(248,81,73,.3); }
.toast.warn { background: rgba(210,153,34,.15); color: var(--amber); border: 1px solid rgba(210,153,34,.3); }

/* --- Cards / tables --- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; margin-bottom: 20px; }
.card h3 { margin: 0 0 14px; font-size: 15px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.row label { flex: 1; min-width: 140px; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); font-size: 13px; }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
tbody tr:hover { background: var(--surface-2); }
.clickable { cursor: pointer; }
td.mono, .mono { font-family: var(--mono); font-size: 12px; }

.pill { font-size: 11px; padding: 2px 9px; border-radius: 20px; font-weight: 600; display: inline-block; }
.pill.role-owner { background: rgba(109,139,255,.18); color: var(--accent); }
.pill.role-operator { background: rgba(63,185,80,.15); color: var(--green); }
.pill.role-approver { background: rgba(210,153,34,.15); color: var(--amber); }
.pill.role-viewer { background: var(--surface-2); color: var(--muted); }
.gate-tag { font-size: 11px; padding: 2px 9px; border-radius: 20px; font-weight: 600; }
.gate-tag.forbidden { background: rgba(248,81,73,.15); color: var(--red); }
.gate-tag.blocked { background: rgba(210,153,34,.15); color: var(--amber); }
.gate-tag.approved { background: rgba(63,185,80,.15); color: var(--green); }

.empty { color: var(--muted); text-align: center; padding: 40px; }
.back { background: transparent; border: 0; color: var(--accent); padding: 0; margin-bottom: 16px; font-size: 13px; }
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 8px 16px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-family: var(--mono); font-size: 12px; word-break: break-all; }
.actions { display: flex; gap: 10px; margin-top: 4px; }
