/* PassVault – stilmall. Inga externa resurser (CSP: style-src 'self'). */
:root {
  --bg: #e9edf1;
  --surface: #ffffff;
  --surface-2: #f4f6f8;
  --ink: #1b2430;
  --muted: #5b6876;
  --line: #d3dae1;
  --accent: #245c8a;
  --accent-ink: #ffffff;
  --accent-hover: #1b4a70;
  --danger: #b03a2e;
  --success: #27754a;
  --warn: #8d6512;
  --radius: 4px;
  --radius-lg: 8px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14191f;
    --surface: #1d242c;
    --surface-2: #242d36;
    --ink: #e4e9ee;
    --muted: #9aa7b4;
    --line: #313c47;
    --accent: #6aa8dc;
    --accent-ink: #0d1b28;
    --accent-hover: #86bbe8;
    --danger: #e0685c;
    --success: #5cb883;
    --warn: #d9a83f;
  }
}
* { box-sizing: border-box; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }
h1 { font-size: 1.6rem; font-weight: 650; letter-spacing: -0.01em; margin: 0 0 0.75rem; }
code { font-family: var(--mono); font-size: 0.92em; }
.hint { color: var(--muted); font-size: 0.9rem; }
.lead { color: var(--muted); margin-top: 0; max-width: 60ch; }
.nowrap { white-space: nowrap; }

/* Topp */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: 0.75rem 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.brand { display: inline-flex; align-items: center; gap: 0.6rem; font-weight: 700; text-decoration: none; color: var(--ink); font-size: 1.05rem; }
.brand-mark { width: 14px; height: 14px; background: var(--accent); transform: rotate(45deg); border-radius: 2px; }
.nav { display: flex; align-items: center; gap: 0.25rem 1rem; flex-wrap: wrap; }
.nav a { color: var(--ink); text-decoration: none; padding: 0.25rem 0; border-bottom: 2px solid transparent; }
.nav a:hover { border-bottom-color: var(--accent); }

.page { max-width: 1040px; margin: 0 auto; padding: 1.5rem; }
.narrow { max-width: 520px; margin: 2rem auto; background: var(--surface); padding: 2rem; border: 1px solid var(--line); border-radius: var(--radius-lg); }
.login { margin-top: 4rem; }

/* Formulär */
label { display: block; font-weight: 600; font-size: 0.92rem; margin: 1rem 0 0.35rem; }
input[type="text"], input[type="password"], input[type="email"], input[type="search"], input[type="number"], select, textarea {
  width: 100%; padding: 0.6rem 0.7rem; font: inherit; color: var(--ink);
  background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius);
}
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
textarea { resize: vertical; }
.pw-wrap { display: flex; gap: 0.4rem; align-items: stretch; }
.pw-wrap input { flex: 1; font-family: var(--mono); }
.gen-opts { display: flex; gap: 1.25rem; margin-top: 0.5rem; }
.check { display: inline-flex; align-items: center; gap: 0.4rem; font-weight: 500; margin: 0; }
.check input[type="number"] { width: 4.5rem; padding: 0.3rem 0.4rem; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1rem; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0 1rem; align-items: end; }
.form-actions { display: flex; gap: 0.5rem; margin-top: 1.5rem; grid-column: 1 / -1; }
.inline { display: inline; margin: 0; }

/* Knappar */
.btn {
  display: inline-block; padding: 0.55rem 0.95rem; font: inherit; font-weight: 600; font-size: 0.92rem;
  color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  cursor: pointer; text-decoration: none; line-height: 1.2; white-space: nowrap;
}
.btn:hover { border-color: var(--accent); }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-ghost { background: transparent; }
.btn-danger-ghost { background: transparent; color: var(--danger); }
.btn-danger-ghost:hover { border-color: var(--danger); }
.btn-wide { width: 100%; margin-top: 1.25rem; }
.btn-small { padding: 0.35rem 0.6rem; font-size: 0.85rem; }
.btn-ok { border-color: var(--success); color: var(--success); }

/* Meddelanden */
.flash { padding: 0.75rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; border: 1px solid; }
.flash-info { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, var(--surface)); }
.flash-success { border-color: var(--success); background: color-mix(in srgb, var(--success) 10%, var(--surface)); }
.flash-error { border-color: var(--danger); background: color-mix(in srgb, var(--danger) 10%, var(--surface)); }
.toast {
  position: fixed; left: 50%; bottom: 1.5rem; transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 0.6rem 1rem; border-radius: var(--radius);
  font-size: 0.92rem; box-shadow: 0 6px 20px rgba(0,0,0,0.25); z-index: 10;
}

/* Valv */
.vault-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.vault-tools { display: flex; gap: 0.5rem; align-items: center; flex: 1; justify-content: flex-end; }
.vault-tools input[type="search"] { max-width: 360px; }
.count { color: var(--muted); font-size: 0.9rem; margin: 0.5rem 0 0.75rem; }
.items { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); }
.item { display: grid; grid-template-columns: 1fr auto; gap: 0.25rem 1rem; padding: 0.9rem 1.1rem; border-bottom: 1px solid var(--line); border-left: 3px solid transparent; }
.item:last-child { border-bottom: 0; }
.item:hover { border-left-color: var(--accent); }
.item-title { font-weight: 650; }
.item-meta { display: flex; flex-wrap: wrap; gap: 0.2rem 1rem; color: var(--muted); font-size: 0.9rem; }
.meta-user { font-family: var(--mono); }
.meta-url { color: var(--accent); text-decoration: none; overflow-wrap: anywhere; }
.meta-url:hover { text-decoration: underline; }
.item-comment { color: var(--muted); font-size: 0.9rem; margin-top: 0.25rem; white-space: pre-wrap; }
.item-actions { display: flex; gap: 0.35rem; align-items: flex-start; flex-wrap: wrap; justify-content: flex-end; }
.item-secret { grid-column: 1 / -1; display: flex; gap: 1rem; align-items: baseline; padding: 0.5rem 0.75rem; background: var(--surface-2); border-radius: var(--radius); }
.secret { font-size: 1.05rem; overflow-wrap: anywhere; user-select: all; }
.secret-note { color: var(--muted); font-size: 0.85rem; }
.empty { text-align: center; padding: 3rem 1rem; background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius-lg); }
.empty-filter { color: var(--muted); text-align: center; padding: 2rem; }
.tag { display: inline-block; font-size: 0.75rem; font-weight: 600; padding: 0.05rem 0.4rem; border-radius: 3px; background: var(--surface-2); color: var(--muted); vertical-align: middle; }
.tag-warn { color: var(--warn); border: 1px solid var(--warn); background: transparent; }

/* Admin */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 0.75rem 1.25rem 1.25rem; margin-bottom: 1.25rem; }
.panel summary { cursor: pointer; font-weight: 600; }
.reveal-box { background: var(--surface); border: 2px solid var(--warn); border-radius: var(--radius-lg); padding: 1rem 1.25rem; margin-bottom: 1.25rem; }
.reveal-row { display: flex; align-items: center; gap: 0.75rem; margin: 0.5rem 0; }
.reveal-row code { font-size: 1.15rem; padding: 0.4rem 0.7rem; background: var(--surface-2); border-radius: var(--radius); user-select: all; }
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); }
.table { width: 100%; border-collapse: collapse; font-size: 0.93rem; }
.table th, .table td { text-align: left; padding: 0.65rem 0.9rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.table th { font-weight: 600; color: var(--muted); font-size: 0.85rem; }
.table tr:last-child td { border-bottom: 0; }
.table-dense td, .table-dense th { padding: 0.4rem 0.7rem; }
.row-muted td { color: var(--muted); }
.actions { white-space: nowrap; }
.actions form { margin-right: 0.25rem; }

@media (prefers-reduced-motion: no-preference) {
  .btn, .nav a, .item { transition: border-color 120ms ease, background-color 120ms ease; }
}

/* --- v2: dialog, nycklar, 2FA, konto --- */
.mono { font-family: var(--mono); }
.short { max-width: 9rem; }
.centered { text-align: center; }
.warn-text { color: var(--warn); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-danger:hover { filter: brightness(0.92); }
.panel h2 { font-size: 1.1rem; margin: 0.25rem 0 0.5rem; }
.panel p { margin: 0 0 0.75rem; max-width: 70ch; }
.row-form { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; margin-top: 0.5rem; }
.row-form input { width: auto; flex: 1; min-width: 12rem; }
.settings-form .check { display: flex; align-items: flex-start; gap: 0.6rem; margin: 0.75rem 0; font-weight: 500; line-height: 1.4; }
.settings-form .check input { margin-top: 0.3rem; }
.keybox { display: flex; gap: 0.75rem; align-items: center; flex-wrap: wrap; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; margin: 1rem 0; }
.keytext { font-size: 1.15rem; letter-spacing: 0.04em; overflow-wrap: anywhere; user-select: all; }
.codes { margin: 0; font-family: var(--mono); font-size: 1.05rem; line-height: 1.7; user-select: all; }
.qr-wrap { display: flex; justify-content: center; margin: 1rem 0; }
#qr svg { width: 220px; height: 220px; border: 8px solid #fff; border-radius: var(--radius); }
.steps { padding-left: 1.25rem; }
.steps li { margin-bottom: 0.4rem; }
.strength { font-size: 0.85rem; color: var(--muted); min-height: 1.2rem; margin-top: 0.3rem; }
.strength[data-level="weak"] { color: var(--danger); }
.strength[data-level="good"], .strength[data-level="great"] { color: var(--success); }
.dialog { border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--surface); color: var(--ink); padding: 1.5rem; max-width: 32rem; width: calc(100% - 2rem); }
.dialog::backdrop { background: rgba(0,0,0,0.45); }
.dialog h2 { margin: 0 0 0.5rem; font-size: 1.2rem; }
.dialog p { margin: 0 0 0.5rem; }
.account .lead { margin-bottom: 1.25rem; }
.accept { align-items: flex-start; margin-top: 1rem; font-weight: 500; line-height: 1.4; } .accept input { margin-top: 0.3rem; }
.radios { border: 1px solid var(--line); border-radius: var(--radius); padding: 0.5rem 1rem 0.25rem; margin: 0.75rem 0; }
.radios legend { font-weight: 600; font-size: 0.92rem; padding: 0 0.3rem; }
.radios .check { margin: 0.4rem 0; }

.lang-switch { display: inline-flex; gap: 2px; margin-left: 0.5rem; }
.lang-btn { font: inherit; font-size: 0.78rem; font-weight: 600; letter-spacing: 0.04em; padding: 0.2rem 0.5rem; border: 1px solid var(--line); background: transparent; color: var(--muted); cursor: pointer; border-radius: var(--radius); }
.lang-btn.is-active { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.lang-btn:not(.is-active):hover { border-color: var(--accent); color: var(--ink); }

/* ---------- Responsivt ---------- */
img, svg { max-width: 100%; }
.topbar { flex-wrap: wrap; padding-left: max(1.5rem, env(safe-area-inset-left)); padding-right: max(1.5rem, env(safe-area-inset-right)); }
.page { padding-left: max(1.5rem, env(safe-area-inset-left)); padding-right: max(1.5rem, env(safe-area-inset-right)); padding-bottom: max(1.5rem, env(safe-area-inset-bottom)); }
.keytext, .codes, .secret, .meta-url { overflow-wrap: anywhere; word-break: break-word; }

/* Större träffytor på pekskärm */
@media (pointer: coarse) {
  .btn { min-height: 44px; padding-top: 0.65rem; padding-bottom: 0.65rem; }
  .btn-small { min-height: 40px; }
  .lang-btn { min-height: 36px; padding: 0.3rem 0.7rem; }
  input[type="text"], input[type="password"], input[type="email"], input[type="search"], input[type="number"], select, textarea { min-height: 44px; }
  .check input[type="checkbox"], .check input[type="radio"] { width: 1.25rem; height: 1.25rem; }
}

@media (max-width: 900px) {
  .nav { width: 100%; justify-content: flex-start; }
}

@media (max-width: 720px) {
  .topbar { padding: 0.6rem 1rem; gap: 0.5rem 0.75rem; }
  .nav { gap: 0.25rem 0.5rem; }
  .nav a { padding: 0.35rem 0.6rem; border: 1px solid var(--line); border-radius: var(--radius); border-bottom-width: 1px; font-size: 0.92rem; }
  .nav a:hover { border-color: var(--accent); }
  .lang-switch { margin-left: auto; }
  .page { padding: 1rem; }
  h1 { font-size: 1.35rem; }
  .narrow { padding: 1.25rem; margin: 0.75rem 0 0; }
  .login { margin-top: 1rem; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .form-actions { flex-wrap: wrap; }
  .form-actions .btn { flex: 1 1 auto; text-align: center; }
  .pw-wrap { flex-wrap: wrap; }
  .pw-wrap input { flex: 1 1 100%; }
  .pw-wrap .btn { flex: 1 1 auto; }
  .gen-opts { flex-wrap: wrap; gap: 0.75rem 1.25rem; }
  .row-form { flex-direction: column; align-items: stretch; }
  .row-form input { width: 100%; min-width: 0; }
  .row-form .short { max-width: none; }
  .vault-head { flex-direction: column; align-items: stretch; }
  .vault-tools { flex-direction: column; align-items: stretch; }
  .vault-tools input[type="search"] { max-width: none; }
  .item { grid-template-columns: 1fr; padding: 0.85rem 0.9rem; }
  .item-actions { justify-content: flex-start; }
  .item-actions .btn { flex: 1 1 auto; text-align: center; }
  .item-actions form { display: contents; }
  .item-secret { flex-direction: column; gap: 0.25rem; }
  .keybox { flex-direction: column; align-items: stretch; }
  .keybox .btn { align-self: flex-start; }
  .keytext { font-size: 1rem; }
  .reveal-row { flex-direction: column; align-items: flex-start; }
  #qr svg { width: min(220px, 70vw); height: auto; }
  .panel { padding: 0.75rem 1rem 1rem; }
  .dialog { padding: 1.25rem; }
  .dialog .form-actions .btn { flex: 1 1 auto; }
  .btn-wide { margin-top: 1rem; }

  /* Tabeller: användarlistan staplas till kort, loggen scrollar i sidled */
  .table-stack { display: block; border: 0; background: transparent; }
  .table-stack thead { display: none; }
  .table-stack tbody, .table-stack tr, .table-stack td { display: block; }
  .table-stack tr { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); margin-bottom: 0.75rem; padding: 0.35rem 0.9rem; }
  .table-stack td { border: 0; padding: 0.35rem 0; display: flex; gap: 0.75rem; justify-content: space-between; align-items: baseline; }
  .table-stack td::before { content: attr(data-label); color: var(--muted); font-size: 0.82rem; flex: 0 0 7rem; }
  .table-stack td.actions { display: flex; flex-wrap: wrap; gap: 0.4rem; padding-top: 0.6rem; white-space: normal; }
  .table-stack td.actions::before { flex-basis: 100%; }
  .table-stack td.actions form { margin: 0; }
  .table-stack td.actions .btn { flex: 1 1 auto; text-align: center; }
}

@media (max-width: 400px) {
  .brand { font-size: 1rem; }
  .table-stack td::before { flex-basis: 5.5rem; }
}

/* ---- v2: valv-verktygsrad, hälsa, import/export, uppdateringar ---- */
.vault-sub { display: flex; flex-wrap: wrap; gap: .5rem 1rem; align-items: center; margin: -.25rem 0 1rem; }
.vault-sub a { font-size: .9rem; }
.inline-details { display: inline-block; }
.inline-details summary { list-style: none; cursor: pointer; }
.inline-details summary::-webkit-details-marker { display: none; }
.ie-panel { margin-top: .5rem; padding: .75rem; border: 1px solid var(--border); border-radius: 8px; background: var(--panel); display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.ie-panel .hint { flex-basis: 100%; margin: 0; }
.health-score { font-size: 1.4rem; font-weight: 600; margin: .25rem 0 .5rem; }
.health-list { margin: 0; padding-left: 1.2rem; }
.tag-ok { background: #d8f3dc; color: #1b5e20; }
.tag-danger { background: #fde2e1; color: #8a1c1c; }
.kv { list-style: none; padding: 0; margin: 0; }
.kv li { display: flex; justify-content: space-between; gap: 1rem; padding: .35rem 0; border-bottom: 1px solid var(--border); font-size: .95rem; }
.kv li strong { text-align: right; word-break: break-all; }
.log { background: #111; color: #e6e6e6; padding: .75rem; border-radius: 8px; font-size: .8rem; overflow-x: auto; max-height: 24rem; white-space: pre-wrap; }
.panel-danger { border-color: #d9534f; }
.js-error { margin-bottom: 1rem; }
@media (max-width: 400px) { .kv li { flex-direction: column; gap: .1rem; } .kv li strong { text-align: left; } }

.panel-ok { border-color: #2e7d32; }
.warn-text code { white-space: normal; overflow-wrap: anywhere; }

.pin-input { font-size: 1.6rem; letter-spacing: .4em; text-align: center; }

.star { color: #e0a800; }
.tag-folder { background: #e3ecf7; color: #1f4e79; }
.tag-tag { background: #eef; color: #445; }
.totp-box { margin-top: .4rem; }
.totp-code { font-size: 1.3rem; letter-spacing: .2em; }
.history-list { margin: .3rem 0 0; padding-left: 1.1rem; font-size: .9rem; }
#folder-filter { max-width: 12rem; }
