/* VT client styles. No external fonts; light/dark via prefers-color-scheme. */
:root {
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", "Cascadia Code", Consolas, "SFMono-Regular", Menlo, monospace;
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #eef2f7;
  --surface-3: #e3e9f2;
  --border: #d5dce7;
  --text: #132036;
  --muted: #56667f;
  --primary: #1f4b8f;
  --primary-hover: #173a70;
  --primary-fg: #ffffff;
  --primary-soft: #e4ecf8;
  --focus: #2f6fd6;
  --danger: #b42318;
  --danger-hover: #8f1c13;
  --danger-bg: #fdecea;
  --danger-fg: #8a1c12;
  --ok-bg: #e5f5ea;
  --ok-fg: #13612a;
  --warn-bg: #fff4dc;
  --warn-fg: #714600;
  --info-bg: #e7effb;
  --info-fg: #163f7a;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 4px 16px rgba(16, 24, 40, 0.06);
  --radius: 10px;
  --radius-sm: 6px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1220;
    --surface: #111a2b;
    --surface-2: #162238;
    --surface-3: #1d2b45;
    --border: #26344f;
    --text: #e5ebf4;
    --muted: #97a6bf;
    --primary: #4d84d6;
    --primary-hover: #6797e0;
    --primary-fg: #08101e;
    --primary-soft: #1a2a46;
    --focus: #7fb0ff;
    --danger: #f06d5f;
    --danger-hover: #f58b80;
    --danger-bg: #3a1613;
    --danger-fg: #ffb4aa;
    --ok-bg: #0f2e1c;
    --ok-fg: #8fe0a8;
    --warn-bg: #33250a;
    --warn-fg: #ffd27a;
    --info-bg: #13243f;
    --info-fg: #a9c8ff;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 4px 16px rgba(0, 0, 0, 0.3);
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  min-height: 100vh;
}
h1, h2, h3 { line-height: 1.25; margin: 0 0 0.5em; }
h1 { font-size: 1.55rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.02rem; }
p { margin: 0 0 0.75em; }
a { color: var(--primary); }
a:hover { color: var(--primary-hover); }
code, .mono { font-family: var(--mono); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: 0.86rem; }
.nowrap { white-space: nowrap; }
.break { overflow-wrap: anywhere; word-break: break-word; }
.hidden { display: none !important; }

/* ------------------------------------------------------------- layout */
.skip-link { position: absolute; left: -9999px; top: 8px; background: var(--surface); padding: 8px 12px; z-index: 100; }
.skip-link:focus { left: 8px; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 10px 20px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 750; letter-spacing: 0.08em; color: var(--text); text-decoration: none; }
.brand-mark { width: 28px; height: 28px; border-radius: 7px; background: var(--primary); position: relative; flex: none; }
.brand-mark::after { content: ""; position: absolute; inset: 9px 8px 6px; border: 2.5px solid var(--primary-fg); border-radius: 3px; }
.nav { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
.nav a { padding: 6px 10px; border-radius: var(--radius-sm); color: var(--muted); text-decoration: none; font-weight: 550; white-space: nowrap; }
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a[aria-current="page"] { background: var(--primary-soft); color: var(--primary); }
.topbar-right { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.user-chip { font-size: 0.86rem; color: var(--muted); max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
main { max-width: 1120px; margin: 0 auto; padding: 24px 20px 64px; }
main.narrow { max-width: 560px; }
main.medium { max-width: 760px; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head h1 { margin: 0; }
.stack > * + * { margin-top: 14px; }
.stack-sm > * + * { margin-top: 8px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row-between { display: flex; gap: 10px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; }
.split { display: grid; grid-template-columns: minmax(0, 340px) minmax(0, 1fr); gap: 18px; align-items: start; }
@media (max-width: 820px) { .split { grid-template-columns: 1fr; } }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.card-tight { padding: 12px; }
.card h2 { margin-bottom: 12px; }
.auth-card { margin-top: 6vh; }
.auth-logo { display: flex; justify-content: center; margin-bottom: 18px; }
.auth-logo .brand-mark { width: 44px; height: 44px; border-radius: 11px; }
.auth-logo .brand-mark::after { inset: 14px 12px 9px; border-width: 3px; }
.steps { display: flex; gap: 6px; list-style: none; padding: 0; margin: 0 0 18px; flex-wrap: wrap; }
.steps li { font-size: 0.78rem; padding: 3px 9px; border-radius: 99px; background: var(--surface-2); color: var(--muted); }
.steps li[aria-current="step"] { background: var(--primary); color: var(--primary-fg); }
.steps li.done { background: var(--ok-bg); color: var(--ok-fg); }

/* ------------------------------------------------------------- forms */
.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-weight: 600; font-size: 0.92rem; }
.hint { color: var(--muted); font-size: 0.84rem; margin: 0; }
input[type="text"], input[type="email"], input[type="password"], input[type="search"], input[type="number"], input[type="url"], select, textarea {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 9px 11px; width: 100%; min-height: 40px;
}
textarea { min-height: 90px; resize: vertical; }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 3px solid var(--focus); outline-offset: 0; border-color: var(--focus); }
input[aria-invalid="true"], textarea[aria-invalid="true"] { border-color: var(--danger); }
input.code-input { font-family: var(--mono); font-size: 1.4rem; letter-spacing: 0.3em; text-align: center; }
input.mono, textarea.mono { font-family: var(--mono); }
.checkbox { display: flex; gap: 10px; align-items: flex-start; }
.checkbox input { margin-top: 4px; width: 18px; height: 18px; flex: none; }
fieldset { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px; margin: 0; }
legend { font-weight: 600; padding: 0 6px; }
.form-error { color: var(--danger-fg); background: var(--danger-bg); border-radius: var(--radius-sm); padding: 8px 12px; font-size: 0.92rem; }
.form-error:empty { display: none; }

.btn {
  font: inherit; font-weight: 600; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 38px; padding: 7px 14px; border-radius: var(--radius-sm);
  border: 1px solid transparent; text-decoration: none; white-space: nowrap;
}
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: var(--primary-fg); }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-secondary:hover:not(:disabled) { background: var(--surface-2); }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: var(--danger-hover); }
.btn-sm { min-height: 30px; padding: 3px 10px; font-size: 0.85rem; }
.btn-block { width: 100%; }
.link-btn { background: none; border: 0; padding: 0; color: var(--primary); font: inherit; cursor: pointer; text-decoration: underline; }

/* ------------------------------------------------------------- feedback */
.alert { border-radius: var(--radius-sm); padding: 12px 14px; border: 1px solid transparent; }
.alert > * + * { margin-top: 6px; }
.alert p:last-child { margin-bottom: 0; }
.alert-title { display: block; }
.alert-info { background: var(--info-bg); color: var(--info-fg); }
.alert-ok { background: var(--ok-bg); color: var(--ok-fg); }
.alert-warn { background: var(--warn-bg); color: var(--warn-fg); border-color: color-mix(in srgb, var(--warn-fg) 30%, transparent); }
.alert-danger { background: var(--danger-bg); color: var(--danger-fg); border-color: color-mix(in srgb, var(--danger-fg) 35%, transparent); }
.alert-critical { background: var(--danger-bg); color: var(--danger-fg); border: 2px solid var(--danger); padding: 16px; }
.alert-critical .alert-title { font-size: 1.1rem; }
.badge { display: inline-flex; align-items: center; gap: 4px; font-size: 0.75rem; font-weight: 650; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge-ok { background: var(--ok-bg); color: var(--ok-fg); }
.badge-danger { background: var(--danger-bg); color: var(--danger-fg); }
.badge-warn { background: var(--warn-bg); color: var(--warn-fg); }
.badge-info { background: var(--info-bg); color: var(--info-fg); }
.banner { padding: 8px 20px; text-align: center; font-size: 0.9rem; }
.banner-danger { background: var(--danger); color: #fff; }
.banner-warn { background: var(--warn-bg); color: var(--warn-fg); }

.spinner-wrap { display: inline-flex; align-items: center; gap: 10px; }
.spinner { width: 20px; height: 20px; border-radius: 50%; border: 3px solid var(--surface-3); border-top-color: var(--primary); animation: spin 0.8s linear infinite; flex: none; }
.spinner-lg { width: 40px; height: 40px; border-width: 4px; }
@keyframes spin { to { transform: rotate(360deg); } }
.progress-panel { display: flex; flex-direction: column; align-items: center; gap: 14px; padding: 24px 8px; text-align: center; }
.progress-bar { width: 100%; height: 6px; border-radius: 6px; background: var(--surface-3); overflow: hidden; position: relative; }
.progress-bar::after { content: ""; position: absolute; inset: 0; width: 40%; background: var(--primary); border-radius: 6px; animation: indet 1.2s ease-in-out infinite; }
@keyframes indet { from { transform: translateX(-100%); } to { transform: translateX(250%); } }
@media (prefers-reduced-motion: reduce) { .spinner, .progress-bar::after { animation-duration: 3s; } }

.toast-host { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 1000; max-width: calc(100vw - 32px); }
.toast { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: var(--radius-sm); box-shadow: var(--shadow); font-size: 0.92rem; max-width: 380px; }
.toast-danger { background: var(--danger); color: #fff; }
.toast-ok { background: var(--ok-fg); color: var(--bg); }

/* ------------------------------------------------------------- modal */
dialog.modal { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); padding: 22px; width: min(520px, calc(100vw - 32px)); max-height: calc(100vh - 32px); overflow: auto; box-shadow: var(--shadow); }
dialog.modal-wide { width: min(860px, calc(100vw - 32px)); }
dialog.modal::backdrop { background: rgba(5, 10, 20, 0.55); }
.modal-title { margin-bottom: 12px; }
.modal-body > * + * { margin-top: 12px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; margin-top: 18px; }

/* ------------------------------------------------------------- tables & lists */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table.table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
.table th, .table td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table th { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); background: var(--surface-2); white-space: nowrap; }
.table tr:last-child td { border-bottom: 0; }
.table td.actions { white-space: nowrap; text-align: right; }
.table .mono { font-size: 0.85rem; }
.empty { padding: 28px; text-align: center; color: var(--muted); }

.collection-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
.collection-card { display: flex; flex-direction: column; gap: 6px; text-decoration: none; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.collection-card:hover { border-color: var(--primary); }
.collection-card .name { font-weight: 700; font-size: 1.05rem; overflow-wrap: anywhere; }
.collection-card .desc { color: var(--muted); font-size: 0.88rem; overflow-wrap: anywhere; }
.collection-card .meta { margin-top: auto; display: flex; gap: 6px; flex-wrap: wrap; }

.item-list { list-style: none; margin: 0; padding: 0; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); overflow: hidden; max-height: 70vh; overflow-y: auto; }
.item-list li + li { border-top: 1px solid var(--border); }
.item-list button { all: unset; box-sizing: border-box; display: flex; flex-direction: column; width: 100%; padding: 10px 14px; cursor: pointer; }
.item-list button:hover { background: var(--surface-2); }
.item-list button:focus-visible { outline: 3px solid var(--focus); outline-offset: -3px; }
.item-list button[aria-current="true"] { background: var(--primary-soft); }
.item-list .t { font-weight: 650; overflow-wrap: anywhere; }
.item-list .s { color: var(--muted); font-size: 0.85rem; overflow-wrap: anywhere; }

.detail-grid { display: grid; grid-template-columns: 120px minmax(0, 1fr); gap: 10px 14px; align-items: center; }
.detail-grid dt { color: var(--muted); font-size: 0.86rem; font-weight: 600; }
.detail-grid dd { margin: 0; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; min-width: 0; }
@media (max-width: 520px) { .detail-grid { grid-template-columns: 1fr; gap: 2px; } .detail-grid dd { margin-bottom: 10px; } }
.secret { font-family: var(--mono); background: var(--surface-2); padding: 4px 8px; border-radius: 4px; overflow-wrap: anywhere; min-width: 0; }
.notes { white-space: pre-wrap; overflow-wrap: anywhere; background: var(--surface-2); padding: 8px 10px; border-radius: 6px; width: 100%; }
.tag { font-size: 0.78rem; padding: 1px 8px; border-radius: 99px; background: var(--primary-soft); color: var(--primary); }

/* ------------------------------------------------------------- security-critical displays */
.fingerprint { display: flex; flex-direction: column; gap: 6px; padding: 12px 14px; border: 1px dashed var(--border); border-radius: var(--radius-sm); background: var(--surface-2); }
.fingerprint-label { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); font-weight: 650; }
.fingerprint-groups { display: flex; flex-wrap: wrap; gap: 6px 12px; font-family: var(--mono); font-size: 1.15rem; font-weight: 600; letter-spacing: 0.04em; }
.passphrase-box { border: 2px solid var(--primary); border-radius: var(--radius); padding: 18px; background: var(--primary-soft); }
.passphrase-words { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; counter-reset: w; }
.passphrase-words li { font-family: var(--mono); font-size: 1.3rem; font-weight: 700; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; display: flex; gap: 10px; align-items: baseline; white-space: nowrap; }
.passphrase-words li::before { counter-increment: w; content: counter(w); font-size: 0.8rem; color: var(--muted); font-weight: 600; }
.passphrase-inline { font-family: var(--mono); font-size: 1.05rem; font-weight: 650; overflow-wrap: anywhere; }
.share-box { border: 2px dashed var(--danger); border-radius: var(--radius); padding: 18px; background: var(--surface); }
.share-text { font-family: var(--mono); font-size: 1.1rem; line-height: 1.9; overflow-wrap: anywhere; display: flex; flex-wrap: wrap; gap: 4px 10px; }
.share-text .hdr { font-weight: 700; color: var(--primary); }
.share-text .chk { font-weight: 700; color: var(--danger-fg); }
.codes-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 8px; list-style: none; padding: 0; margin: 0; }
.codes-grid li { font-family: var(--mono); font-size: 1.05rem; background: var(--surface-2); border-radius: 6px; padding: 8px 10px; text-align: center; }
.qr { background: #fff; padding: 12px; border-radius: 8px; width: 220px; height: 220px; display: block; }
.kit { max-width: 720px; }
.kit h2 { margin-top: 16px; }
.kit .writein { border-bottom: 1px solid var(--text); min-height: 2em; }

.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.toolbar input[type="search"] { flex: 1; min-width: 180px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 14px; flex-wrap: wrap; }
.tabs button { all: unset; cursor: pointer; padding: 8px 12px; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; }
.tabs button[aria-selected="true"] { color: var(--primary); border-bottom-color: var(--primary); }
.tabs button:focus-visible { outline: 3px solid var(--focus); }
details > summary { cursor: pointer; font-weight: 600; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; font-size: 0.9rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }

/* ------------------------------------------------------------- small screens */
@media (max-width: 600px) {
  body { font-size: 15px; }
  main { padding: 16px 12px 48px; }
  .topbar { padding: 8px 12px; gap: 8px; }
  .nav { order: 3; flex-basis: 100%; overflow-x: auto; flex-wrap: nowrap; }
  .user-chip { display: none; }
  .card { padding: 14px; }
  .passphrase-words li { font-size: 1.15rem; }
  .fingerprint-groups { font-size: 1rem; }
  .table th, .table td { padding: 8px; }
}

/* ------------------------------------------------------------- print (emergency kit, shares, codes) */
.print-host { display: none; }
@media print {
  body { background: #fff; color: #000; }
  body > *:not(.print-host) { display: none !important; }
  .print-host.printing { display: block; }
  .print-target { width: 100%; border: 0; box-shadow: none; background: #fff; color: #000; padding: 0; }
  .print-target * { color: #000 !important; }
  .print-target .no-print { display: none; }
  .print-target .passphrase-words li, .print-target .codes-grid li, .print-target .share-box, .print-target .fingerprint, .print-target .passphrase-box { border: 1px solid #000; background: #fff; }
  .print-target .page-break { break-before: page; }
}

/* ---- sub-collection tree (SPEC 3.13) ---- */
.collection-tree { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.collection-tree-children { margin-top: 10px; padding-left: 28px; border-left: 2px solid var(--border); margin-left: 14px; }
.collection-tree-row { display: flex; align-items: center; gap: 8px; }
.collection-tree-row > .collection-card { flex: 1 1 auto; min-width: 0; }
.tree-toggle { flex: 0 0 auto; width: 28px; height: 28px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); color: var(--text); cursor: pointer; font-size: 0.9rem; line-height: 1; }
.tree-toggle:hover { border-color: var(--primary); }
.tree-toggle:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.tree-toggle-spacer { flex: 0 0 auto; width: 28px; }
.tree-cell { display: flex; align-items: center; gap: 6px; }
.tree-depth-2 { padding-left: 24px; }
.tree-depth-3 { padding-left: 48px; }
.tree-depth-4 { padding-left: 72px; }
.tree-depth-5 { padding-left: 96px; }
.breadcrumb { display: flex; flex-wrap: wrap; gap: 4px; list-style: none; margin: 0; padding: 0; font-size: 0.88rem; }
.breadcrumb li + li::before { content: "/"; color: var(--muted); margin-right: 4px; }
.subcollection-list { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.size-bar { width: 120px; height: 10px; vertical-align: middle; }
.storage-totals { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; }
.storage-totals .stat { display: flex; flex-direction: column; gap: 2px; }
.storage-totals .stat strong { font-size: 1.15rem; }
.import-row-error td { background: var(--danger-bg); }

/* v1.3: user import warnings, plain-text email preview */
.import-row-warn td { background: var(--warn-bg); }
.email-preview { white-space: pre-wrap; overflow-wrap: anywhere; font-family: var(--mono); font-size: 0.85rem; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px 14px; max-height: 420px; overflow: auto; margin: 0; }
