/* Digital Library — design system and screens.
   Plain CSS, no framework, no remote fonts/icons/images. Served as a static asset (not through
   Vite's CSS pipeline) so dev and production both load it via a real <link>, never an injected
   <style> tag — that keeps this compatible with a strict style-src 'self' CSP in both modes.
   Every color lives in the two token blocks below; nothing else may hard-code one (a test checks). */

:root {
  /* Color: cool, softly tinted neutrals with one indigo accent */
  --color-bg: #f5f6fb;
  --color-surface: #ffffff;
  --color-surface-muted: #eff1f8;
  --color-text: #12152b;
  --color-muted: #565c78;
  --color-border: #e1e4f0;
  --color-border-strong: #7d84a3;
  --color-accent: #4f46e5;
  --color-accent-hover: #4338ca;
  --color-accent-soft: #eef0ff;
  --color-accent-contrast: #ffffff;
  --color-positive: #0f766e;
  --color-positive-bg: #e7f6f3;
  --color-danger: #b42318;
  --color-danger-hover: #912018;
  --color-danger-bg: #fef3f2;
  --color-danger-border: #fecdca;
  --color-status-bg: #eef2ff;
  --color-status-border: #c7d2fe;
  --color-status-text: #312e81;

  /* Elevation */
  --shadow-1: 0 1px 2px rgb(18 21 43 / 0.06);
  --shadow-2: 0 4px 14px rgb(18 21 43 / 0.08), 0 1px 2px rgb(18 21 43 / 0.06);
  --shadow-3: 0 16px 40px rgb(18 21 43 / 0.16), 0 2px 8px rgb(18 21 43 / 0.08);

  /* Shape and spacing (8px grid) */
  --radius: 12px;
  --radius-sm: 8px;
  --radius-pill: 999px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 16px;
  --space-4: 24px;
  --space-5: 40px;
  --space-6: 64px;

  /* Type scale on the system font stack */
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --text-display: 1.75rem;
  --text-title: 1.25rem;
  --text-body: 1rem;
  --text-caption: 0.8125rem;

  /* Motion */
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  --dur-fast: 120ms;
  --dur: 180ms;
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-bg: #0b0d1a;
    --color-surface: #14172b;
    --color-surface-muted: #1b1f38;
    --color-text: #eceefb;
    --color-muted: #a4aac8;
    --color-border: #2a2f4f;
    --color-border-strong: #6b7299;
    --color-accent: #818cf8;
    --color-accent-hover: #a5b4fc;
    --color-accent-soft: #1e2247;
    --color-accent-contrast: #0b0d1a;
    --color-positive: #5eead4;
    --color-positive-bg: #0f2a2a;
    --color-danger: #fb7185;
    --color-danger-hover: #fda4af;
    --color-danger-bg: #2a1218;
    --color-danger-border: #5b1f2c;
    --color-status-bg: #171c3d;
    --color-status-border: #2e3772;
    --color-status-text: #c7d2fe;
    --shadow-1: 0 1px 2px rgb(0 0 0 / 0.4);
    --shadow-2: 0 4px 14px rgb(0 0 0 / 0.35), 0 1px 2px rgb(0 0 0 / 0.3);
    --shadow-3: 0 16px 40px rgb(0 0 0 / 0.55), 0 2px 8px rgb(0 0 0 / 0.4);
  }
}

* {
  box-sizing: border-box;
}

html {
  color-scheme: light dark;
}

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(60rem 28rem at 50% -12rem, var(--color-accent-soft), transparent), var(--color-bg);
  color: var(--color-text);
  font-family: var(--font);
  font-size: var(--text-body);
  line-height: 1.55;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
}

#app {
  max-width: 44rem;
  margin: 0 auto;
  padding: var(--space-3) var(--space-3) var(--space-5);
}

/* ---------- Header ---------- */

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-3);
  padding: var(--space-2) 0 var(--space-4);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-weight: 650;
  letter-spacing: -0.01em;
  font-size: var(--text-title);
}

.brand-mark {
  color: var(--color-accent);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.chip {
  display: inline-flex;
  align-items: center;
  max-width: 14rem;
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-pill);
  background: var(--color-accent-soft);
  color: var(--color-accent);
  border: 1px solid var(--color-border);
  font-size: var(--text-caption);
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.menu {
  position: relative;
}

.menu > summary {
  list-style: none;
}

.menu > summary::-webkit-details-marker {
  display: none;
}

.menu > summary::after {
  content: "";
  width: 6px;
  height: 6px;
  margin-left: var(--space-2);
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: translateY(-2px) rotate(45deg);
  transition: transform var(--dur) var(--ease);
}

.menu[open] > summary::after {
  transform: translateY(1px) rotate(-135deg);
}

.menu-panel {
  position: absolute;
  right: 0;
  top: calc(100% + var(--space-2));
  z-index: 20;
  min-width: 15rem;
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  padding: var(--space-2);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-3);
  animation: menu-in var(--dur) var(--ease);
}

/* Higher specificity than the general button rule further down, which would otherwise win by order. */
.menu-panel .menu-item {
  width: 100%;
  justify-content: flex-start;
  color: var(--color-text);
  background: transparent;
  border-color: transparent;
  box-shadow: none;
}

.menu-panel .menu-item:hover {
  background: var(--color-surface-muted);
  box-shadow: none;
}

@keyframes menu-in {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ---------- Typography ---------- */

h1 {
  font-size: var(--text-title);
  font-weight: 650;
  letter-spacing: -0.015em;
  line-height: 1.25;
  margin: 0 0 var(--space-3);
}

h2 {
  font-size: var(--text-title);
  font-weight: 650;
  letter-spacing: -0.01em;
  margin: var(--space-4) 0 var(--space-3);
}

p {
  margin: 0 0 var(--space-3);
}

small {
  display: block;
  color: var(--color-muted);
  font-size: var(--text-caption);
}

a {
  color: var(--color-accent);
  text-underline-offset: 3px;
}

/* ---------- Surfaces ---------- */

section {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-2);
  padding: var(--space-4);
  margin-bottom: var(--space-3);
}

section section {
  background: transparent;
  border: 0;
  box-shadow: none;
  padding: 0;
  margin: var(--space-4) 0 0;
}

.screen-narrow {
  max-width: 28rem;
  margin-left: auto;
  margin-right: auto;
  padding: var(--space-5) var(--space-4);
}

.screen-narrow h1 {
  font-size: var(--text-display);
  text-align: center;
}

.hero-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  margin: 0 auto var(--space-3);
  border-radius: var(--radius-pill);
  background: var(--color-accent-soft);
  color: var(--color-accent);
}

/* ---------- Forms ---------- */

form {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

form > label:not(:first-child) {
  margin-top: var(--space-2);
}

form > button[type="submit"] {
  margin-top: var(--space-3);
}

/* The restore-from-backup control under the create and unlock forms */
.import-box {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin-top: var(--space-4);
  padding-top: var(--space-4);
  border-top: 1px solid var(--color-border);
}

.import-box > button {
  align-self: flex-start;
  margin-top: var(--space-2);
}

label {
  display: block;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: var(--space-1);
}

label:has(+ input:required)::after,
label:has(+ select:required)::after {
  content: " *";
  color: var(--color-accent);
}

label:has(input[type="checkbox"]) {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
  font-weight: 400;
  color: var(--color-muted);
}

input,
select,
textarea {
  width: 100%;
  min-height: 44px;
  font: inherit;
  color: var(--color-text);
  background: var(--color-surface);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-sm);
  padding: var(--space-2) var(--space-3);
  transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}

input[type="checkbox"] {
  width: auto;
  min-height: auto;
  margin-top: 0.3em;
  accent-color: var(--color-accent);
}

input[type="file"] {
  padding: var(--space-2);
}

textarea {
  min-height: 6em;
  resize: vertical;
}

input:hover,
select:hover,
textarea:hover {
  border-color: var(--color-accent);
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px var(--color-accent-soft);
}

/* ---------- Buttons ---------- */

button,
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 44px;
  min-width: 44px;
  padding: 0 var(--space-3);
  font: inherit;
  font-weight: 600;
  line-height: 1;
  text-decoration: none;
  color: var(--color-text);
  background: var(--color-surface);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-1);
  cursor: pointer;
  transition:
    background-color var(--dur-fast) var(--ease),
    border-color var(--dur-fast) var(--ease),
    box-shadow var(--dur-fast) var(--ease),
    transform var(--dur-fast) var(--ease);
}

button:hover,
.btn:hover {
  background: var(--color-surface-muted);
  box-shadow: var(--shadow-2);
}

button:active,
.btn:active {
  transform: translateY(1px);
  box-shadow: none;
}

button:disabled,
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  box-shadow: none;
}

button[type="submit"],
.btn-primary {
  color: var(--color-accent-contrast);
  background: var(--color-accent);
  border-color: var(--color-accent);
}

button[type="submit"]:hover,
.btn-primary:hover {
  background: var(--color-accent-hover);
  border-color: var(--color-accent-hover);
}

.btn-danger {
  color: var(--color-danger);
  background: transparent;
  border-color: var(--color-danger-border);
  box-shadow: none;
}

.btn-danger:hover {
  color: var(--color-danger-hover);
  background: var(--color-danger-bg);
}

:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

/* ---------- Notices ---------- */

p[role="alert"] {
  color: var(--color-danger);
  background: var(--color-danger-bg);
  border: 1px solid var(--color-danger-border);
  border-radius: var(--radius-sm);
  padding: var(--space-2) var(--space-3);
  margin: 0;
  font-size: 0.9rem;
}

p[role="status"] {
  color: var(--color-status-text);
  background: var(--color-status-bg);
  border: 1px solid var(--color-status-border);
  border-radius: var(--radius-sm);
  padding: var(--space-2) var(--space-3);
  margin: 0 0 var(--space-3);
  font-size: 0.9rem;
}

p[role="alert"]:empty,
p[role="status"]:empty {
  display: none;
}

/* Top-level banners (update prompt, storage warning) injected at document.body */
body > div[role="status"] {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  margin: 0;
  padding: var(--space-2) var(--space-3);
  color: var(--color-status-text);
  background: var(--color-status-bg);
  border-bottom: 1px solid var(--color-status-border);
}

/* ---------- Lists, cards, empty states ---------- */

ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

ul:empty {
  display: none;
}

li {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--space-3) var(--space-4);
}

.account-card {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas:
    "title balance"
    "last4 balance"
    "notes notes"
    "actions actions";
  column-gap: var(--space-3);
  row-gap: var(--space-1);
  box-shadow: var(--shadow-1);
  transition: box-shadow var(--dur) var(--ease), border-color var(--dur) var(--ease);
}

.account-card:hover {
  border-color: var(--color-border-strong);
  box-shadow: var(--shadow-2);
}

.account-card strong {
  grid-area: title;
  font-size: var(--text-body);
  font-weight: 650;
}

.account-last4 {
  grid-area: last4;
  color: var(--color-muted);
  font-size: var(--text-caption);
  letter-spacing: 0.04em;
}

.account-balance {
  grid-area: balance;
  align-self: center;
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-size: var(--text-title);
  font-weight: 650;
  letter-spacing: -0.01em;
}

.account-card p {
  grid-area: notes;
  margin: var(--space-2) 0 0;
  color: var(--color-muted);
  font-size: 0.9rem;
  overflow-wrap: anywhere;
}

.card-actions {
  grid-area: actions;
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
  margin-top: var(--space-3);
}

.profile-item {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-2);
  padding: var(--space-2);
}

.profile-open {
  flex: 1 1 12rem;
  justify-content: flex-start;
  min-height: 52px;
  font-size: var(--text-body);
  overflow: hidden;
  text-overflow: ellipsis;
}

.profile-item form {
  flex: 1 1 100%;
  padding: var(--space-3);
  background: var(--color-danger-bg);
  border: 1px solid var(--color-danger-border);
  border-radius: var(--radius-sm);
}

.empty-state {
  text-align: center;
  padding: var(--space-5) var(--space-4);
  margin-bottom: var(--space-3);
  color: var(--color-muted);
  background: var(--color-surface-muted);
  border: 1px dashed var(--color-border-strong);
  border-radius: var(--radius);
}

.empty-state .empty-title {
  margin: 0 0 var(--space-2);
  color: var(--color-text);
  font-size: var(--text-title);
  font-weight: 650;
}

.empty-state p:last-child {
  margin-bottom: 0;
}

details:not(.menu) {
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--space-1) var(--space-3);
  margin-top: var(--space-3);
  background: var(--color-surface);
}

details:not(.menu) > summary {
  display: flex;
  align-items: center;
  min-height: 44px;
  font-weight: 600;
  cursor: pointer;
}

details:not(.menu)[open] > summary {
  margin-bottom: var(--space-3);
}

footer {
  max-width: 44rem;
  margin: 0 auto;
  padding: 0 var(--space-3) var(--space-5);
  text-align: center;
  color: var(--color-muted);
  font-size: var(--text-caption);
}

/* ---------- Small screens ---------- */

@media (max-width: 480px) {
  #app {
    padding: var(--space-2) var(--space-2) var(--space-4);
  }

  section {
    padding: var(--space-3);
  }

  .screen-narrow {
    padding: var(--space-4) var(--space-3);
  }

  .app-header {
    padding-bottom: var(--space-3);
  }

  .menu-panel {
    min-width: 12rem;
  }

  .account-balance {
    font-size: var(--text-body);
  }

  .card-actions {
    justify-content: stretch;
  }

  .card-actions > button {
    flex: 1;
  }
}

/* ---------- Reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
}
