:root {
  --bg: #f4f6fa;
  --panel: #ffffff;
  --panel-2: #eef1f6;
  --text: #182033;
  --muted: #5d6880;
  --line: #d9dee8;
  --accent: #2f6fed;
  --accent-text: #ffffff;
  --danger: #c83737;
  --ok: #1f8a4c;
  --focus: #2f6fed55;
  --radius: 10px;
  --mono: ui-monospace, "JetBrains Mono", "Cascadia Code", Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1420;
    --panel: #171e2d;
    --panel-2: #1f2840;
    --text: #e6eaf3;
    --muted: #96a1b8;
    --line: #2a3450;
    --accent: #5b8cff;
    --accent-text: #0b1020;
    --danger: #ff6b6b;
    --ok: #4cd18a;
    --focus: #5b8cff55;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body, #app { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
[hidden] { display: none !important; }
a { color: var(--accent); }
h1, h2, h3 { margin: 0 0 .5rem; line-height: 1.2; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.2rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.mono { font-family: var(--mono); }

/* ── Forms ───────────────────────────────────────────── */
label { display: block; font-size: .85rem; color: var(--muted); margin: .9rem 0 .3rem; }
input, textarea, select {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: .6rem .7rem;
}
textarea { min-height: 7rem; resize: vertical; }
input:focus, textarea:focus, select:focus, button:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--focus);
}
input[type="checkbox"], input[type="radio"] { width: auto; margin: 0 .5rem 0 0; flex: none; }
input[type="range"] { padding: 0; background: none; border: 0; }
.check { display: flex; align-items: center; color: var(--text); font-size: .95rem; margin: .5rem 0; }
.code-input { font-family: var(--mono); font-size: 1.6rem; letter-spacing: .4em; text-align: center; }

button {
  font: inherit;
  cursor: pointer;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  padding: .55rem .9rem;
  white-space: nowrap;
}
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: .6; cursor: wait; }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
button.danger { color: var(--danger); }
button.danger.solid { background: var(--danger); color: #fff; border-color: var(--danger); }
button.link { background: none; border: 0; color: var(--accent); padding: .3rem; }
button.icon { padding: .35rem .6rem; font-size: .85rem; }
.row { display: flex; gap: .5rem; align-items: center; }
.row > .grow { flex: 1; min-width: 0; }
.actions { display: flex; gap: .5rem; justify-content: flex-end; margin-top: 1.2rem; flex-wrap: wrap; }
.actions .spacer { flex: 1; }
.form-error { color: var(--danger); background: color-mix(in srgb, var(--danger) 10%, transparent); padding: .5rem .7rem; border-radius: 8px; margin: 0 0 .5rem; }
.warn { background: color-mix(in srgb, #e8a400 15%, transparent); border-radius: 8px; padding: .6rem .8rem; font-size: .9rem; }

/* ── Auth screens ────────────────────────────────────── */
.center { min-height: 100%; display: grid; place-items: center; padding: 1.5rem; }
.card {
  width: 100%;
  max-width: 420px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 1.6rem;
  box-shadow: 0 10px 30px #0000001a;
}
.brand { display: flex; align-items: center; gap: .6rem; margin-bottom: 1.2rem; }
.brand img { width: 32px; height: 32px; }
.brand strong { font-size: 1.25rem; }
.tabs { display: flex; gap: .3rem; background: var(--panel-2); border-radius: 9px; padding: .25rem; margin-bottom: .5rem; }
.tabs button { flex: 1; border: 0; background: none; }
.tabs button.active { background: var(--panel); box-shadow: 0 1px 3px #0002; font-weight: 600; }

/* ── Vault layout ────────────────────────────────────── */
.vault { height: 100%; display: grid; grid-template-rows: auto 1fr; }
.topbar {
  display: flex; gap: .6rem; align-items: center;
  padding: .7rem 1rem;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.topbar .brand { margin: 0; }
.topbar input[type="search"] { max-width: 420px; }
.topbar .grow { flex: 1; }
.body { display: grid; grid-template-columns: minmax(260px, 360px) 1fr; min-height: 0; }
.list { overflow: auto; border-right: 1px solid var(--line); background: var(--panel); }
.list .count { padding: .6rem 1rem; font-size: .8rem; color: var(--muted); border-bottom: 1px solid var(--line); }
.list button.entry {
  display: block; width: 100%; text-align: left;
  border: 0; border-bottom: 1px solid var(--line); border-radius: 0;
  background: none; padding: .7rem 1rem;
}
.list button.entry:hover { background: var(--panel-2); }
.list button.entry.selected { background: color-mix(in srgb, var(--accent) 14%, transparent); }
.entry .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.entry .sub { font-size: .85rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; }
.empty { padding: 2rem 1rem; text-align: center; color: var(--muted); }
.detail { overflow: auto; padding: 1.5rem; }
.detail .inner { max-width: 640px; }
.field { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: .6rem .8rem; margin-bottom: .6rem; }
.field .k { font-size: .78rem; color: var(--muted); }
.field .v { overflow-wrap: anywhere; white-space: pre-wrap; }
.field .row { justify-content: space-between; }

/* ── Dialogs ─────────────────────────────────────────── */
dialog {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  color: var(--text);
  padding: 1.4rem;
  width: min(480px, calc(100vw - 2rem));
}
dialog::backdrop { background: #0008; }
dialog.wide { width: min(860px, calc(100vw - 2rem)); }
dialog hr { border: 0; border-top: 1px solid var(--line); margin: 1.2rem 0; }
.row.wrap { flex-wrap: wrap; }
.map-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 0 .8rem; }
.preview { overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; }
.preview table { width: 100%; border-collapse: collapse; font-size: .85rem; }
.preview th, .preview td { text-align: left; padding: .45rem .6rem; border-bottom: 1px solid var(--line); white-space: nowrap; }
.preview th { background: var(--panel-2); color: var(--muted); font-weight: 600; }
.preview tr:last-child td { border-bottom: 0; }
.empty p { margin: 0 0 .6rem; }
.gen-out {
  font-family: var(--mono); font-size: 1.15rem;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px;
  padding: .8rem; overflow-wrap: anywhere; min-height: 3.2rem;
}

/* ── Toast ───────────────────────────────────────────── */
#toast {
  position: fixed; left: 50%; bottom: 1.2rem; transform: translateX(-50%) translateY(150%);
  background: var(--text); color: var(--bg);
  padding: .6rem 1rem; border-radius: 8px; max-width: calc(100vw - 2rem);
  transition: transform .2s ease, visibility .2s; pointer-events: none; z-index: 10;
  visibility: hidden;
}
#toast.show { transform: translateX(-50%) translateY(0); visibility: visible; }
#toast.error { background: var(--danger); color: #fff; }
#toast.ok { background: var(--ok); color: #fff; }

/* ── Small screens ───────────────────────────────────── */
@media (max-width: 760px) {
  .topbar { flex-wrap: wrap; gap: .4rem; padding: .6rem .75rem; }
  .topbar button { padding: .45rem .6rem; font-size: .85rem; }
  .topbar .grow { display: none; }
  .topbar .brand strong { display: none; }
  .topbar input[type="search"] { order: 5; max-width: none; flex-basis: 100%; }
  .body { grid-template-columns: 1fr; }
  .body.has-detail .list { display: none; }
  .body:not(.has-detail) .detail { display: none; }
  .detail { padding: 1rem; }
}
@media (min-width: 761px) { .only-mobile { display: none; } }
