:root {
  --bg: #f4f6f8; --surface: #ffffff; --surface-2: #eef1f4; --text: #18202a; --muted: #5d6875;
  --border: #d9dee4; --accent: #0b8f6a; --accent-2: #0a6fb0; --accent-text: #fff;
  --danger: #c0392b; --warn: #b7791f; --ok: #12805c; --code-bg: #eef1f4;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 2px 8px rgba(0,0,0,.04);
  --radius: 10px; --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "Cascadia Code", Consolas, monospace;
}
[data-theme="dark"] {
  --bg: #0d1117; --surface: #161b22; --surface-2: #1f2630; --text: #e6edf3; --muted: #93a0ad;
  --border: #2d3540; --accent: #1fc493; --accent-2: #4aa8ec; --accent-text: #04110c;
  --danger: #ff6b5e; --warn: #e3b341; --ok: #3fd3a0; --code-bg: #1f2630;
  --shadow: 0 1px 2px rgba(0,0,0,.4);
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--font); font-size: 15px; line-height: 1.5; }
a { color: var(--accent-2); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .6em; }
h1 { font-size: 1.5rem; } h2 { font-size: 1.15rem; } h3 { font-size: 1rem; }
code, pre, .mono { font-family: var(--mono); }
code { background: var(--code-bg); padding: .1em .35em; border-radius: 5px; font-size: .92em; }
pre { background: var(--code-bg); padding: .75rem; border-radius: 8px; overflow: auto; white-space: pre; font-size: .85rem; }
.muted { color: var(--muted); } .small { font-size: .85rem; } .ok { color: var(--ok); } .warn { color: var(--warn); } .danger { color: var(--danger); }

.shell { display: grid; grid-template-columns: 230px 1fr; min-height: 100vh; }
.sidebar { background: var(--surface); border-right: 1px solid var(--border); padding: 1rem .75rem; position: sticky; top: 0; height: 100vh; overflow: auto; display: flex; flex-direction: column; gap: .25rem; }
.brand { font-weight: 700; font-size: 1.05rem; padding: .25rem .5rem 1rem; display: flex; gap: .5rem; align-items: center; color: var(--text); }
.brand .dot { width: 12px; height: 12px; border-radius: 50%; background: linear-gradient(135deg, var(--accent), var(--accent-2)); }
.nav a { display: block; padding: .45rem .65rem; border-radius: 8px; color: var(--text); }
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.active { background: var(--surface-2); font-weight: 600; box-shadow: inset 3px 0 0 var(--accent); }
.sidebar .spacer { flex: 1; }
.main { padding: 1.5rem 2rem 3rem; max-width: 1300px; width: 100%; }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: 1.25rem; flex-wrap: wrap; }
.topbar h1 { margin: 0; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.1rem 1.25rem; box-shadow: var(--shadow); margin-bottom: 1.25rem; }
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .9rem 1rem; }
.stat .label { color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; }
.stat .value { font-size: 1.6rem; font-weight: 700; margin-top: .15rem; }
.row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.between { justify-content: space-between; }
.stack > * + * { margin-top: .75rem; }

.btn { display: inline-flex; align-items: center; gap: .35rem; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); padding: .45rem .85rem; border-radius: 8px; font: inherit; font-size: .92rem; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { filter: brightness(.97); text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.btn-blue { background: var(--accent-2); border-color: var(--accent-2); color: #fff; }
.btn-danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn-sm { padding: .25rem .55rem; font-size: .82rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
form.inline { display: inline; }

label { display: block; font-weight: 600; font-size: .88rem; margin-bottom: .25rem; }
input[type=text], input[type=email], input[type=password], input[type=url], input[type=number], input[type=date], input[type=datetime-local], input[type=search], select, textarea {
  width: 100%; padding: .5rem .65rem; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); font: inherit; font-size: .93rem;
}
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 50%, transparent); border-color: var(--accent); }
textarea { min-height: 80px; resize: vertical; }
.field { margin-bottom: .9rem; }
.help { color: var(--muted); font-size: .8rem; margin-top: .2rem; }
.check { display: flex; gap: .5rem; align-items: center; font-weight: 500; }
.form-grid { display: grid; gap: 0 1rem; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }

table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: .5rem .55rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { color: var(--muted); font-weight: 600; font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; }
.table-wrap { overflow-x: auto; }
td input, td select { padding: .3rem .45rem; font-size: .85rem; }

.badge { display: inline-block; padding: .1rem .5rem; border-radius: 999px; font-size: .75rem; font-weight: 600; background: var(--surface-2); border: 1px solid var(--border); }
.badge-open { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); border-color: transparent; }
.badge-closed { color: var(--muted); }
.badge-draft { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); border-color: transparent; }
.badge-enl { background: #1f8a3a; color: #fff; border: 0; } .badge-res { background: #1b6fc2; color: #fff; border: 0; }

.alert { padding: .75rem 1rem; border-radius: 8px; margin-bottom: 1rem; border: 1px solid var(--border); background: var(--surface); }
.alert-ok { border-color: var(--ok); } .alert-error { border-color: var(--danger); color: var(--danger); }
.alert ul { margin: .25rem 0 0 1.1rem; padding: 0; }

.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--border); margin-bottom: 1.25rem; flex-wrap: wrap; }
.tabs a { padding: .55rem .9rem; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a.active { color: var(--text); border-color: var(--accent); font-weight: 600; }
.tabs a:hover { text-decoration: none; color: var(--text); }

.passcode-big { font-family: var(--mono); font-size: 2rem; letter-spacing: .08em; padding: .6rem 1rem; background: var(--code-bg); border-radius: 10px; display: inline-block; word-break: break-all; }
.slots { display: flex; gap: .35rem; flex-wrap: wrap; }
.slot { min-width: 44px; text-align: center; border: 1px solid var(--border); border-radius: 8px; padding: .35rem .4rem; background: var(--surface-2); }
.slot .v { font-family: var(--mono); font-size: 1.25rem; font-weight: 700; }
.slot .n { font-size: .7rem; color: var(--muted); }
.slot.empty .v { color: var(--muted); }
.slot.kw { min-width: 110px; }

.thumb { width: 72px; height: 72px; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); background: var(--surface-2); display: block; }
.gallery { display: grid; gap: .75rem; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
.gallery figure { margin: 0; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.gallery img { width: 100%; height: 160px; object-fit: cover; display: block; }
.gallery figcaption { padding: .5rem .6rem; font-size: .82rem; }

.checklist li { list-style: none; margin: .35rem 0; display: flex; gap: .5rem; align-items: center; }
.checklist { padding: 0; margin: 0; }
.qr svg { background: #fff; padding: 10px; border-radius: 10px; }
.codes { display: grid; grid-template-columns: repeat(2, max-content); gap: .25rem 1.5rem; font-family: var(--mono); }

/* Snipping tool */
.snip-layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 1rem; align-items: start; }
.snip-stage { position: relative; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; overflow: auto; max-height: 80vh; }
.snip-stage .inner { position: relative; display: inline-block; cursor: crosshair; user-select: none; }
.snip-stage img { display: block; max-width: none; }
.box { position: absolute; border: 2px solid var(--accent); background: color-mix(in srgb, var(--accent) 14%, transparent); cursor: move; }
.box.selected { border-color: #ff9f1a; background: rgba(255, 159, 26, .15); }
.box .lbl { position: absolute; left: -2px; top: -24px; background: var(--accent); color: var(--accent-text); font-weight: 700; font-size: 13px; padding: 1px 7px; border-radius: 6px 6px 0 0; }
.box.selected .lbl { background: #ff9f1a; color: #000; }
.box .h { position: absolute; width: 12px; height: 12px; right: -7px; bottom: -7px; background: #fff; border: 2px solid #333; border-radius: 3px; cursor: nwse-resize; }
.snip-list .item { display: flex; gap: .5rem; align-items: center; padding: .35rem; border-radius: 8px; border: 1px solid transparent; }
.snip-list .item.selected { border-color: #ff9f1a; }
.snip-list canvas { width: 54px; height: 54px; object-fit: cover; border-radius: 6px; border: 1px solid var(--border); background: var(--surface-2); }
.snip-list input { width: 64px; }

.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.auth-card { width: 100%; max-width: 420px; }
.theme-switch { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.theme-switch button { background: transparent; border: 0; color: var(--muted); padding: .3rem .55rem; cursor: pointer; font-size: .85rem; }
.theme-switch button.on { background: var(--surface-2); color: var(--text); font-weight: 600; }
.menu-toggle { display: none; }

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; }
  .sidebar .nav { display: flex; flex-wrap: wrap; gap: .25rem; }
  .sidebar .spacer { display: none; }
  .main { padding: 1rem; }
  .snip-layout { grid-template-columns: minmax(0, 1fr); }
}
nav[role=navigation] { margin-top: 1rem; }
.pagination { display: flex; gap: .25rem; list-style: none; padding: 0; margin: 1rem 0 0; flex-wrap: wrap; }
.pagination li > * { display: block; padding: .3rem .65rem; border: 1px solid var(--border); border-radius: 6px; }
.pagination li.active > * { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.pagination li.disabled > * { color: var(--muted); }
