:root {
  --bg: #0d1117;
  --panel: #151b24;
  --panel-2: #1b2330;
  --line: #263041;
  --text: #e6edf3;
  --muted: #8b97a8;
  --accent: #6366f1;
  --accent-2: #818cf8;
  --ok: #34d399;
  --warn: #fbbf24;
  --bad: #f87171;
  --radius: 12px;
}

* { box-sizing: border-box; }
/* Our .login-wrap / .modal rules set `display`, which would otherwise beat the
   UA `[hidden]` rule - keep `hidden` authoritative. */
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: radial-gradient(1200px 600px at 15% -10%, #1a2233 0%, var(--bg) 55%);
  color: var(--text);
  font: 14px/1.5 ui-sans-serif, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
h1, h2, h3 { margin: 0 0 .5rem; font-weight: 650; letter-spacing: -.01em; }
h2 { font-size: 1.05rem; }
code, .mono { font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace; }
.muted { color: var(--muted); }
.small { font-size: .8rem; }
.error-text { color: var(--bad); font-size: .85rem; margin-top: .5rem; min-height: 1em; }

/* ------------------------------------------------------------------ login */
.login-wrap { display: grid; place-items: center; min-height: 100vh; padding: 1rem; }
.login-card {
  width: 100%; max-width: 360px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 16px; padding: 2rem; text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,.45);
}
.logo { font-size: 2.2rem; }
.login-card p { margin: 0 0 1.25rem; }
.login-card input { text-align: center; }

/* ----------------------------------------------------------------- topbar */
.topbar {
  display: flex; align-items: center; gap: 1rem; padding: .85rem 1.25rem;
  border-bottom: 1px solid var(--line); background: rgba(13,17,23,.8);
  backdrop-filter: blur(8px); position: sticky; top: 0; z-index: 5;
}
.brand { font-weight: 650; display: flex; align-items: center; gap: .5rem; }
.logo-sm { font-size: 1.1rem; }
.stats { display: flex; gap: .5rem; flex: 1; flex-wrap: wrap; }
.stat {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 999px;
  padding: .25rem .7rem; font-size: .78rem; color: var(--muted); white-space: nowrap;
}
.stat b { color: var(--text); font-weight: 600; }

/* ----------------------------------------------------------------- layout */
.layout {
  display: grid; grid-template-columns: 340px 1fr; gap: 1.25rem;
  padding: 1.25rem; align-items: start; max-width: 1500px; margin: 0 auto;
}
/* Grid items default to min-width:auto, which would let the table push the
   whole page sideways instead of scrolling inside .table-scroll. */
.layout > * { min-width: 0; }
@media (max-width: 980px) { .layout { grid-template-columns: 1fr; } }

.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 1.1rem;
}
.create { position: sticky; top: 72px; }

/* ------------------------------------------------------------------ forms */
label { display: block; margin-bottom: .85rem; font-size: .82rem; color: var(--muted); }
input, select, textarea, button { font: inherit; }
input:not([type=checkbox]):not([type=radio]), select, textarea {
  width: 100%; margin-top: .3rem; padding: .55rem .7rem; color: var(--text);
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 9px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.row { display: flex; gap: .6rem; align-items: center; }
.row > input { flex: 1; }
.check { display: flex; align-items: center; gap: .35rem; margin: .3rem 0 0; white-space: nowrap; }
.check input { width: auto; margin: 0; }
.quick { display: flex; gap: .35rem; margin-top: .45rem; }
.quick button {
  background: var(--panel-2); border: 1px solid var(--line); color: var(--muted);
  border-radius: 7px; padding: .2rem .5rem; font-size: .75rem; cursor: pointer;
}
.quick button:hover { color: var(--text); border-color: var(--accent); }
details summary { cursor: pointer; color: var(--muted); font-size: .82rem; margin-bottom: .6rem; }

.btn {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--line);
  border-radius: 9px; padding: .5rem .85rem; cursor: pointer; transition: .15s;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); font-weight: 600; }
.btn.primary:hover { background: var(--accent-2); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--bad); }
.btn.block { width: 100%; margin-top: .35rem; }
.btn.small { padding: .3rem .6rem; font-size: .8rem; }

.new-key {
  margin-top: 1rem; padding: .85rem; border-radius: 10px;
  background: rgba(52,211,153,.08); border: 1px solid rgba(52,211,153,.35);
}
.key-row { display: flex; gap: .5rem; align-items: center; margin-top: .4rem; }
.key-row code { flex: 1; font-size: .95rem; letter-spacing: .04em; color: var(--ok); word-break: break-all; }

/* ------------------------------------------------------------------ table */
.list-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: .8rem; }
.filters { display: flex; gap: .5rem; }
.filters input, .filters select { margin: 0; width: auto; }
.filters input { min-width: 220px; }
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th {
  text-align: left; font-size: .72rem; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); font-weight: 600; padding: .5rem .6rem; border-bottom: 1px solid var(--line);
}
td { padding: .7rem .6rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr:hover { background: rgba(255,255,255,.02); }
.keycell { font-family: ui-monospace, Menlo, monospace; font-size: .82rem; letter-spacing: .02em; cursor: pointer; white-space: nowrap; }
th { white-space: nowrap; }
.keycell:hover { color: var(--accent-2); }

.bar { height: 6px; border-radius: 4px; background: var(--panel-2); overflow: hidden; margin-top: .3rem; width: 130px; }
.bar > i { display: block; height: 100%; background: var(--ok); }
.bar > i.warn { background: var(--warn); }
.bar > i.bad { background: var(--bad); }

.pill { display: inline-block; padding: .15rem .55rem; border-radius: 999px; font-size: .73rem; font-weight: 600; }
.pill.active { background: rgba(52,211,153,.15); color: var(--ok); }
.pill.expired { background: rgba(251,191,36,.15); color: var(--warn); }
.pill.exhausted { background: rgba(251,191,36,.15); color: var(--warn); }
.pill.revoked { background: rgba(248,113,113,.15); color: var(--bad); }
.empty { text-align: center; color: var(--muted); padding: 2.5rem 1rem; }
.actions { display: flex; gap: .35rem; justify-content: flex-end; }

/* ------------------------------------------------------------------ modal */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: grid; place-items: center; padding: 1rem; z-index: 20; }
.modal-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  width: min(720px, 100%); max-height: 88vh; overflow: auto; padding: 1.4rem; position: relative;
}
.modal-close { position: absolute; top: .6rem; right: .8rem; background: none; border: 0; color: var(--muted); font-size: 1.5rem; cursor: pointer; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; }
.section { margin-top: 1.2rem; border-top: 1px solid var(--line); padding-top: 1rem; }
.kv { display: flex; justify-content: space-between; padding: .3rem 0; border-bottom: 1px dashed var(--line); font-size: .85rem; }
.kv span:first-child { color: var(--muted); }
pre.snippet {
  background: #0b0f16; border: 1px solid var(--line); border-radius: 9px; padding: .8rem;
  overflow-x: auto; font-size: .78rem; color: #a5b4fc; margin: .5rem 0 0;
}
.chiprow { display: flex; gap: .4rem; flex-wrap: wrap; margin-top: .5rem; }
.log { max-height: 220px; overflow: auto; font-size: .8rem; }
.log div { display: flex; justify-content: space-between; padding: .25rem 0; border-bottom: 1px solid var(--line); }

/* ------------------------------------------------------------------ toast */
.toast {
  position: fixed; bottom: 1.2rem; left: 50%; transform: translateX(-50%);
  background: var(--panel-2); border: 1px solid var(--accent); color: var(--text);
  padding: .6rem 1rem; border-radius: 999px; z-index: 50; box-shadow: 0 10px 30px rgba(0,0,0,.5);
}
