/* app.css — Personal Vault. Plain system fonts; restrained palette; iPhone-first. */

:root {
  --ink: #0f172a;
  --ink-2: #334155;
  --ink-3: #64748b;
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-2: #f1f5f9;
  --border: #e2e8f0;
  --accent: #1e3a8a;
  --accent-text: #ffffff;
  --good: #166534;
  --warn: #92400e;
  --bad: #991b1b;
  --amber-bg: #fef3c7;
  --amber-text: #78350f;
  --red-bg: #fee2e2;
  --red-text: #7f1d1d;
  --blue-bg: #dbeafe;
  --blue-text: #1e3a8a;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .05), 0 4px 12px rgba(15, 23, 42, .04);
}

@media (prefers-color-scheme: dark) {
  :root {
    --ink: #f1f5f9;
    --ink-2: #cbd5e1;
    --ink-3: #94a3b8;
    --bg: #0f172a;
    --surface: #1e293b;
    --surface-2: #334155;
    --border: #334155;
    --accent: #93c5fd;
    --accent-text: #0f172a;
    --amber-bg: #78350f;
    --amber-text: #fef3c7;
    --red-bg: #7f1d1d;
    --red-text: #fee2e2;
    --blue-bg: #1e3a8a;
    --blue-text: #dbeafe;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 12px rgba(0, 0, 0, .25);
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

input, select, textarea, button {
  font: inherit;
  color: inherit;
}

input[type="text"], input[type="password"], input[type="email"], input[type="date"],
input[type="search"], select, textarea {
  width: 100%;
  padding: 12px 14px;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  appearance: none;
  outline: none;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}

/* ============================ views ============================ */

/* The author rules below set display:flex/block on .view-* classes. At equal
   specificity, author CSS wins over the user-agent `[hidden] { display: none }`
   rule — which means every view would render simultaneously, stacked
   vertically by min-height: 100dvh, with the user only seeing whichever sits
   at scroll-position 0. Force hidden to actually hide. */
main.view[hidden] { display: none !important; }

.view {
  display: block;
  min-height: 100dvh;
  padding-bottom: env(safe-area-inset-bottom);
}

/* Center auth-style views in a card */
.view-loading, .view-setup, .view-unlock, .view-recovery, .view-recovery-unlock {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  padding-top: max(24px, env(safe-area-inset-top));
}

.card {
  width: 100%;
  max-width: 440px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
}

.card h1 {
  margin: 0 0 6px;
  font-size: 22px;
  font-weight: 600;
}

.lede {
  margin: 0 0 18px;
  color: var(--ink-3);
  font-size: 14px;
}

.card label {
  display: block;
  font-size: 13px;
  color: var(--ink-2);
  margin: 14px 0 4px;
  font-weight: 500;
}

.card .hint {
  font-size: 12px;
  color: var(--ink-3);
  margin: 4px 0 0;
}

.note {
  margin-top: 12px;
  font-size: 13px;
  min-height: 18px;
}
.note[data-kind="error"] { color: var(--bad); }
.note[data-kind="info"] { color: var(--ink-3); }

.recovery-key {
  margin: 12px 0;
  padding: 14px;
  background: var(--surface-2);
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 17px;
  letter-spacing: 0.02em;
  text-align: center;
  white-space: pre-wrap;
  word-break: break-all;
}

.check {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 12px 0;
  font-size: 14px;
  color: var(--ink-2);
}

/* ============================ buttons ============================ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  user-select: none;
  width: 100%;
  margin-top: 14px;
  min-height: 44px;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  color: var(--accent-text);
  border-color: var(--accent);
}

.btn-ghost {
  background: transparent;
}

.btn-small { padding: 8px 12px; font-size: 14px; min-height: 36px; margin-top: 8px; }
.btn-xs { padding: 6px 10px; font-size: 13px; min-height: 0; margin: 0 0 0 6px; width: auto; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  background: transparent;
  border: 0;
  color: var(--ink-2);
  border-radius: 50%;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.icon-btn:active { background: var(--surface-2); }

.icon-btn-small {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  cursor: pointer;
  font-size: 13px;
  color: var(--ink-2);
}

/* ============================ vault home ============================ */

.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  padding-top: max(8px, env(safe-area-inset-top));
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 5;
}

.search-wrap {
  flex: 1;
}

.search {
  height: 40px;
  padding: 10px 14px;
  border-radius: 20px;
  background: var(--surface);
}

.topbar-title {
  font-size: 16px;
  font-weight: 600;
  margin: 0;
  flex: 1;
  text-align: center;
}

.categories {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 10px 12px 4px;
  scrollbar-width: none;
}
.categories::-webkit-scrollbar { display: none; }

.cat-chip {
  flex-shrink: 0;
  padding: 8px 14px;
  border-radius: 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--ink-2);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}
.cat-chip-active {
  background: var(--accent);
  color: var(--accent-text);
  border-color: var(--accent);
}

.sort-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
}
.sort-toggle {
  background: transparent;
  border: 0;
  color: var(--ink-3);
  font-size: 13px;
  padding: 4px 8px;
  cursor: pointer;
  border-radius: var(--radius-sm);
}
.sort-toggle.sort-active { color: var(--ink); font-weight: 600; }
.grow { flex: 1; }

.entries {
  list-style: none;
  margin: 0;
  padding: 0 8px 100px;
}
.entry-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px;
  margin: 6px 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.entry-tap {
  flex: 1;
  text-align: left;
  background: transparent;
  border: 0;
  padding: 10px 12px;
  cursor: pointer;
  min-height: 56px;
}
.entry-row-main { display: flex; flex-direction: column; gap: 2px; }
.entry-title { font-size: 16px; font-weight: 500; color: var(--ink); display: flex; align-items: center; flex-wrap: wrap; gap: 6px; }
.entry-sub { font-size: 13px; color: var(--ink-3); }
.entry-actions { display: flex; gap: 4px; padding-right: 6px; }
.copy-btn {
  background: var(--surface-2);
  border: 0;
  color: var(--ink-2);
  border-radius: 50%;
  width: 36px;
  height: 36px;
  font-weight: 600;
  font-size: 12px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.copy-btn:active { background: var(--accent); color: var(--accent-text); }

.badge {
  display: inline-block;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.badge-red { background: var(--red-bg); color: var(--red-text); }
.badge-amber { background: var(--amber-bg); color: var(--amber-text); }
.badge-blue { background: var(--blue-bg); color: var(--blue-text); }

.empty { padding: 40px 24px; text-align: center; color: var(--ink-3); }

.footer-bar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  padding: 8px 12px;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: center;
}
.footer-bar .btn { width: auto; margin: 0; }

/* ============================ entry form ============================ */

.entry-form {
  padding: 12px 16px 80px;
  max-width: 560px;
  margin: 0 auto;
}
.entry-form label {
  display: block;
  font-size: 13px;
  color: var(--ink-2);
  margin: 14px 0 4px;
  font-weight: 500;
}
.entry-form textarea {
  font-family: -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  resize: vertical;
}

.row-with-action {
  display: flex;
  gap: 6px;
  align-items: stretch;
}
.row-with-action input { flex: 1; }

.reminder-fieldset, .attachments-fieldset {
  margin-top: 24px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}
.reminder-fieldset legend, .attachments-fieldset legend {
  padding: 0 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-2);
}

.attachments-list {
  list-style: none; margin: 0 0 12px; padding: 0;
}
.attachment-row {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.attachment-row:last-child { border-bottom: 0; }
.att-name { flex: 1; word-break: break-all; }
.att-meta { font-size: 12px; color: var(--ink-3); }

.actions {
  display: flex;
  flex-direction: column;
  gap: 0;
  margin-top: 18px;
}

.hint { font-size: 12px; color: var(--ink-3); margin: 4px 0 0; }

/* ============================ settings ============================ */

.settings-body { padding: 12px 16px 80px; max-width: 560px; margin: 0 auto; }
.settings-body section { margin: 20px 0; padding: 14px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.settings-body h3 { margin: 0 0 8px; font-size: 15px; font-weight: 600; }

#settings-categories { list-style: none; margin: 0; padding: 0; }
.settings-cat { display: flex; gap: 6px; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--border); }
.settings-cat:last-child { border-bottom: 0; }
.settings-cat input { flex: 1; }

#new-cat-form { display: flex; gap: 6px; margin-top: 10px; }
#new-cat-form input { flex: 1; }

/* ============================ toast ============================ */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(72px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 22px;
  font-size: 14px;
  z-index: 20;
  box-shadow: var(--shadow);
}

/* ============================ spinner ============================ */

.spinner-wrap { display: flex; }
.spinner {
  width: 32px; height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============================ print modal (screen) ============================ */

.modal[hidden] { display: none !important; }
.modal {
  position: fixed; inset: 0; z-index: 30;
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
}
.modal-backdrop {
  position: absolute; inset: 0;
  background: rgba(15, 23, 42, 0.6);
}
.modal-card {
  position: relative;
  width: 100%;
  max-width: 480px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
}
.modal-card h2 {
  margin: 0 0 8px;
  font-size: 18px;
  font-weight: 600;
}
.modal-lede {
  margin: 0 0 12px;
  font-size: 14px;
  color: var(--ink);
}
.modal-warn {
  margin: 8px 0 12px;
  padding-left: 20px;
  font-size: 13px;
  color: var(--ink-2);
  line-height: 1.5;
}
.modal-warn strong { color: var(--ink); }
.modal-meta {
  margin: 12px 0;
  padding: 10px 12px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--ink-2);
}
.modal-actions {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}
.modal-actions .btn {
  margin-top: 0;
  flex: 1;
}

/* The print-output region is only used at print time. Hide on screen. */
#print-output { display: none; }

/* ============================ @media print ============================ */
/*
 * Spec PER_personal-vault-print_v1.md §4.1:
 *   - strip every piece of app chrome
 *   - render only the entry list
 *   - multiple entries per page
 *   - break-inside avoid per entry
 *   - password in monospace
 */
@media print {
  /* Hide everything by default. Show only the print-output region. */
  body > * { display: none !important; }
  body > #print-output { display: block !important; }

  /* Force the modal hidden in case it was open when print was invoked. */
  #print-modal { display: none !important; }

  html, body {
    background: #fff !important;
    color: #000 !important;
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  }

  @page {
    size: letter;
    margin: 14mm 12mm;
  }

  #print-output {
    color: #000;
    font-size: 10.5pt;
    line-height: 1.35;
  }

  /* Page header — view name, date, count. Shown once at the start. */
  .print-head {
    border-bottom: 1.5pt solid #000;
    padding-bottom: 6pt;
    margin-bottom: 10pt;
  }
  .print-head .print-title {
    font-size: 14pt;
    font-weight: 700;
    margin: 0 0 4pt 0;
  }
  .print-head .print-sub {
    font-size: 9pt;
    color: #333;
  }

  /* Entry list — 2-column flow, multiple entries per page. */
  .print-entries {
    column-count: 2;
    column-gap: 8mm;
  }
  .print-entry {
    break-inside: avoid;
    page-break-inside: avoid;       /* legacy fallback */
    -webkit-column-break-inside: avoid;
    margin: 0 0 8pt 0;
    padding: 6pt 8pt;
    border: 0.5pt solid #888;
    border-radius: 2pt;
  }
  .print-entry .print-entry-title {
    font-size: 11pt;
    font-weight: 700;
    margin: 0 0 2pt 0;
  }
  .print-entry .print-entry-cat {
    font-size: 8.5pt;
    color: #555;
    margin: 0 0 4pt 0;
  }
  .print-entry dl {
    margin: 4pt 0 0 0;
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: 1pt 6pt;
  }
  .print-entry dt {
    font-size: 8pt;
    color: #555;
    text-transform: uppercase;
    letter-spacing: 0.04em;
  }
  .print-entry dd {
    margin: 0;
    font-size: 10pt;
    word-break: break-all;
  }
  /* Password renders monospace so 0/O, l/1/I are unambiguous on paper. */
  .print-entry dd.mono {
    font-family: ui-monospace, SFMono-Regular, Menlo, "DejaVu Sans Mono", Consolas, monospace;
    font-size: 10.5pt;
    letter-spacing: 0.02em;
  }
  .print-entry .print-notes {
    margin-top: 4pt;
    padding-top: 4pt;
    border-top: 0.25pt dashed #aaa;
    font-size: 9.5pt;
    color: #222;
    white-space: pre-wrap;
  }

  /* Page footer note + build stamp — printed on first page (and via @page where supported). */
  .print-foot {
    margin-top: 10pt;
    padding-top: 4pt;
    border-top: 0.5pt solid #888;
    font-size: 8pt;
    color: #555;
  }
}

/* ============ Shelf in the Vault (blueprint v2) ============ */
.app-nav { display: flex; align-items: center; gap: 4px; padding: 8px 16px 0; }
.app-nav .grow { flex: 1; }
.app-nav .icon-btn { min-width: 44px; min-height: 44px; }
.app-nav-link { display: inline-flex; align-items: center; min-height: 44px; padding: 0 14px; color: var(--ink-2); text-decoration: none; font-weight: 600; border-bottom: 2px solid transparent; }
.app-nav-link[aria-current="page"] { color: var(--ink); border-bottom-color: var(--ink); }
.view-shelf #shelf { padding: 0 16px 32px; }
/* The cover: the Vault's ground color and nothing else, over every view. */
.privacy-cover { position: fixed; inset: 0; z-index: 10000; background: var(--bg); }
.privacy-cover[hidden] { display: none !important; }
.entry-file-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.entry-file-row .entry-file-thumb { width: 44px; height: 56px; flex: none; object-fit: cover; background: var(--surface-2); border: 1px solid var(--border); display: flex; align-items: center; justify-content: center; font-size: 10px; font-weight: 700; color: var(--ink-3); overflow: hidden; }
.entry-file-row .entry-file-thumb img { width: 100%; height: 100%; object-fit: cover; }
.entry-file-row .entry-file-main { flex: 1; min-width: 0; }
.entry-file-row .entry-file-name { overflow-wrap: anywhere; }
.entry-file-row .entry-file-where { font-size: 13px; color: var(--ink-3); }
.entry-file-row .btn { min-height: 44px; }
#entry-add-file { min-height: 44px; }
@media (max-width: 480px) {
  .entry-file-row { flex-wrap: wrap; }
  .entry-file-row .btn { margin-left: 54px; }
}
