/* Personal Keeper — "document validity" visual system.
   Ink: passport navy on cool archival paper. Signature element: the validity
   stub — large condensed tabular numerals, like a printed expiry date. */

:root {
  --ink: #1f2a44;
  --ink-soft: #4a5468;
  --paper: #eef2f6;
  --surface: #ffffff;
  --rule: #cfd7e2;
  --stamp: #0e7c7b;
  --stamp-ink: #ffffff;
  --stamp-soft: #d8efee;
  --seal: #b42318;
  --seal-soft: #fbe4e1;
  --ochre: #8a5a00;
  --ochre-soft: #f8ecd2;
  --info: #2c4f8f;
  --info-soft: #e1e9f7;
  --muted: #5b6577;
  --focus: #1b6fd1;

  --font-text: Seravek, "Gill Sans Nova", Ubuntu, Calibri, "DejaVu Sans", source-sans-pro, sans-serif;
  --font-figure: Bahnschrift, "DIN Alternate", "DIN Next", "Franklin Gothic Medium", "Nimbus Sans Narrow", "Arial Narrow", sans-serif-condensed, sans-serif;

  --step--1: 0.875rem;
  --step-0: 1rem;
  --step-1: 1.2rem;
  --step-2: 1.44rem;
  --step-3: 1.728rem;
  --step-4: 2.488rem;

  --r-sm: 6px;
  --r-md: 10px;
  --space: 1rem;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --ink: #e6ecf5;
    --ink-soft: #b7c1d1;
    --paper: #111a2b;
    --surface: #1a2539;
    --rule: #2f3c55;
    --stamp: #3fb6b4;
    --stamp-ink: #06201f;
    --stamp-soft: #173b3c;
    --seal: #ff8a7a;
    --seal-soft: #3d1d1b;
    --ochre: #f0bf5a;
    --ochre-soft: #3a2e14;
    --info: #9dbaf0;
    --info-soft: #1e2d4c;
    --muted: #9aa6ba;
    --focus: #7fb4ff;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 400 var(--step-0)/1.5 var(--font-text);
  min-height: 100vh;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}
@media (min-width: 900px) { body { padding-bottom: 0; } }

a { color: var(--stamp); text-underline-offset: 2px; }
: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; }
.skip-link { position: absolute; left: -999px; top: 0; background: var(--surface); padding: .5rem 1rem; z-index: 20; }
.skip-link:focus { left: .5rem; }

h1, h2, h3 { line-height: 1.2; margin: 0 0 .5em; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: var(--step-3); }
h2 { font-size: var(--step-1); margin-top: 1.75rem; }
h3 { font-size: var(--step-0); }
p { margin: 0 0 .75em; max-width: 68ch; }
small, .small { font-size: var(--step--1); }
.muted { color: var(--muted); }

/* ---------- shell ---------- */
.topbar {
  display: flex; align-items: center; gap: 1rem;
  padding: .75rem 1rem; padding-top: calc(.75rem + env(safe-area-inset-top));
  background: var(--ink); color: var(--paper);
}
@media (prefers-color-scheme: dark) { .topbar { background: #0b1220; color: var(--ink); } }
.brand { display: flex; align-items: center; gap: .6rem; font-weight: 600; font-size: var(--step-1); color: inherit; text-decoration: none; }
.brand svg { width: 28px; height: 28px; }
.topbar .spacer { flex: 1; }

.layout { display: block; }
@media (min-width: 900px) {
  .layout { display: grid; grid-template-columns: 220px minmax(0, 1fr); min-height: calc(100vh - 56px); }
}

.nav {
  position: fixed; inset: auto 0 0 0; z-index: 10;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--surface); border-top: 1px solid var(--rule);
  padding-bottom: env(safe-area-inset-bottom);
}
.nav a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: 60px; color: var(--ink-soft); text-decoration: none; font-size: .75rem;
}
.nav a svg { width: 22px; height: 22px; }
.nav a[aria-current="page"] { color: var(--stamp); font-weight: 600; }
@media (min-width: 900px) {
  .nav { position: sticky; top: 0; align-self: start; display: flex; flex-direction: column; gap: 2px; border: 0; border-right: 1px solid var(--rule);
         height: calc(100vh - 56px); padding: 1rem .5rem; background: transparent; }
  .nav a { flex-direction: row; justify-content: flex-start; gap: .75rem; min-height: 44px; padding: 0 .75rem; border-radius: var(--r-sm); font-size: var(--step-0); }
  .nav a[aria-current="page"] { background: var(--stamp-soft); }
}

main { padding: 1.25rem 1rem 2rem; max-width: 880px; width: 100%; margin: 0 auto; }
main:focus, h1[tabindex="-1"]:focus { outline: none; }

/* ---------- banners ---------- */
.banner { padding: .75rem 1rem; border-left: 4px solid; border-radius: var(--r-sm); margin-bottom: .75rem; background: var(--surface); }
.banner strong { display: block; }
.banner.error { border-color: var(--seal); background: var(--seal-soft); }
.banner.warn { border-color: var(--ochre); background: var(--ochre-soft); }
.banner.info { border-color: var(--info); background: var(--info-soft); }
.banner.ok { border-color: var(--stamp); background: var(--stamp-soft); }
#offline-banner { position: sticky; top: 0; z-index: 15; margin: 0; border-radius: 0; }
body.offline [data-live] { opacity: .55; }
body.offline [data-live]::before { content: attr(data-loaded); display: block; font-size: var(--step--1); color: var(--ochre); margin-bottom: .25rem; }

/* ---------- validity stub (signature element) ---------- */
.item-row {
  display: grid; grid-template-columns: 76px minmax(0, 1fr) auto; gap: .9rem; align-items: center;
  padding: .7rem .8rem .7rem .7rem; background: var(--surface); border: 1px solid var(--rule); border-radius: var(--r-md);
  color: inherit; text-decoration: none; margin-bottom: .5rem;
}
.item-row:hover { border-color: var(--stamp); }
.stub {
  display: grid; justify-items: center; align-content: center;
  padding: .35rem 0 .3rem; border-right: 2px dashed var(--rule); font-family: var(--font-figure);
  font-variant-numeric: tabular-nums; line-height: 1;
}
.stub .d { font-size: 2.1rem; font-weight: 600; letter-spacing: -0.02em; }
.stub .m { font-size: .85rem; letter-spacing: .02em; margin-top: .15rem; }
.stub .y { font-size: .75rem; color: var(--muted); margin-top: .1rem; }
.stub.month .d { font-size: 1.5rem; }
.stub.tone-danger .d { color: var(--seal); }
.stub.tone-caution .d { color: var(--ochre); }
.item-main { min-width: 0; }
.item-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-sub { color: var(--muted); font-size: var(--step--1); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-sub.wrap { white-space: normal; }
.days { text-align: right; font-family: var(--font-figure); font-variant-numeric: tabular-nums; }
.days b { display: block; font-size: var(--step-2); font-weight: 600; line-height: 1; }
.days span { font-size: .75rem; color: var(--muted); }

.hero-stub { display: flex; gap: 1.25rem; align-items: center; margin-bottom: 1rem; }
.hero-stub .stub { border-right: 0; border: 2px solid var(--ink); border-radius: var(--r-md); padding: .6rem 1rem; min-width: 110px; }
.hero-stub .stub .d { font-size: 3.2rem; }

/* ---------- status label: symbol + word, never colour alone ---------- */
.status { display: inline-flex; align-items: center; gap: .3rem; font-size: var(--step--1); font-weight: 600; padding: .1rem .5rem; border-radius: 999px; border: 1px solid currentColor; white-space: nowrap; }
.status .sym { font-family: var(--font-figure); }
.status.tone-ok { color: var(--stamp); }
.status.tone-caution { color: var(--ochre); }
.status.tone-danger { color: var(--seal); }
.status.tone-info { color: var(--info); }
.status.tone-muted { color: var(--muted); }

/* ---------- panels, lists ---------- */
.panel { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--r-md); padding: 1rem; margin-bottom: 1rem; }
.panel > h2:first-child, .panel > h3:first-child { margin-top: 0; }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 1rem; margin: 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }
.plain-list { list-style: none; margin: 0; padding: 0; }
.plain-list > li { padding: .55rem 0; border-bottom: 1px solid var(--rule); }
.plain-list > li:last-child { border-bottom: 0; }
.timeline > li { display: grid; grid-template-columns: 9rem 1fr; gap: .75rem; }
@media (max-width: 520px) { .timeline > li { grid-template-columns: 1fr; gap: .1rem; } }
.timeline time { font-family: var(--font-figure); font-variant-numeric: tabular-nums; }
.summary-line { display: flex; flex-wrap: wrap; gap: .5rem 1.25rem; align-items: baseline; margin-bottom: 1rem; }
.summary-line .fig { font-family: var(--font-figure); font-size: var(--step-3); font-weight: 600; font-variant-numeric: tabular-nums; }
.empty { text-align: left; padding: 1.5rem 1rem; border: 2px dashed var(--rule); border-radius: var(--r-md); }

/* ---------- forms ---------- */
form { margin: 0; }
fieldset { border: 0; padding: 0; margin: 0 0 1rem; min-width: 0; }
legend { font-weight: 600; margin-bottom: .5rem; padding: 0; }
.field { margin-bottom: 1rem; }
.field > label, .label { display: block; font-weight: 600; margin-bottom: .3rem; }
.hint { display: block; color: var(--muted); font-size: var(--step--1); margin-top: .25rem; }
.error-text { display: block; color: var(--seal); font-size: var(--step--1); margin-top: .25rem; font-weight: 600; }
input[type=text], input[type=email], input[type=password], input[type=date], input[type=time], input[type=number], input[type=search], select {
  width: 100%; max-width: 28rem; min-height: 44px; padding: .5rem .65rem; font: inherit; color: var(--ink);
  background: var(--surface); border: 1px solid var(--ink-soft); border-radius: var(--r-sm);
}
input[type=number] { max-width: 8rem; }
input[type=time] { max-width: 10rem; }
input[aria-invalid=true] { border-color: var(--seal); border-width: 2px; }
.check { display: flex; align-items: flex-start; gap: .55rem; margin: .4rem 0; min-height: 32px; }
.check input { width: 20px; height: 20px; margin-top: .15rem; accent-color: var(--stamp); flex: none; }
.inline { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.chips { display: flex; flex-wrap: wrap; gap: .4rem; }
.chip { position: relative; }
.chip input { position: absolute; opacity: 0; inset: 0; }
.chip span { display: inline-block; min-width: 3.2rem; text-align: center; padding: .45rem .7rem; border: 1px solid var(--ink-soft); border-radius: 999px; font-family: var(--font-figure); font-variant-numeric: tabular-nums; cursor: pointer; }
.chip input:checked + span { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.chip input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 2px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; min-height: 44px; padding: .5rem 1rem; font: inherit; font-weight: 600;
  border-radius: var(--r-sm); border: 1px solid var(--ink-soft); background: var(--surface); color: var(--ink); cursor: pointer; text-decoration: none; }
.btn.primary { background: var(--stamp); border-color: var(--stamp); color: var(--stamp-ink); }
.btn.danger { color: var(--seal); border-color: var(--seal); }
.btn.link { border: 0; background: none; color: var(--stamp); padding-inline: .25rem; text-decoration: underline; }
.btn[disabled], fieldset[disabled] .btn { opacity: .5; cursor: not-allowed; }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; margin: 1rem 0; }

/* combobox */
.combo { position: relative; max-width: 28rem; }
.combo [role=listbox] { position: absolute; z-index: 5; left: 0; right: 0; top: calc(100% + 2px); max-height: 18rem; overflow: auto; margin: 0; padding: .25rem 0; list-style: none;
  background: var(--surface); border: 1px solid var(--ink-soft); border-radius: var(--r-sm); box-shadow: 0 6px 18px rgba(16, 24, 40, .18); }
.combo [role=option] { padding: .55rem .75rem; cursor: pointer; }
.combo [role=option][aria-selected=true], .combo [role=option]:hover { background: var(--stamp-soft); }
.combo [role=option].add { color: var(--stamp); font-weight: 600; border-top: 1px solid var(--rule); }

/* schedule preview */
.preview { border-left: 3px solid var(--stamp); padding-left: .9rem; }
.preview ol { list-style: none; padding: 0; margin: .5rem 0 0; }
.preview li { display: grid; grid-template-columns: 8.5rem 5.5rem 1fr; gap: .5rem; padding: .3rem 0; border-bottom: 1px dashed var(--rule); font-size: var(--step--1); }
.preview li time { font-family: var(--font-figure); font-variant-numeric: tabular-nums; }
@media (max-width: 520px) { .preview li { grid-template-columns: 1fr; gap: 0; } }

dialog { border: 1px solid var(--rule); border-radius: var(--r-md); padding: 1.25rem; max-width: min(30rem, 92vw); background: var(--surface); color: var(--ink); }
dialog::backdrop { background: rgba(10, 16, 30, .55); }

.toast-region { position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 30; width: min(30rem, 92vw); }
@media (min-width: 900px) { .toast-region { bottom: 1.5rem; } }
.toast { background: var(--ink); color: var(--paper); padding: .75rem 1rem; border-radius: var(--r-sm); margin-top: .5rem; box-shadow: 0 6px 18px rgba(0,0,0,.25); }

.auth-wrap { max-width: 26rem; margin: 2rem auto; }
.auth-wrap .panel { padding: 1.5rem; }

.scan-drop { display: grid; gap: .75rem; grid-template-columns: 1fr 1fr; max-width: 30rem; }
.file-btn { position: relative; overflow: hidden; }
.file-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

@media (prefers-reduced-motion: no-preference) {
  .reveal { animation: stamp-in .32s ease-out both; }
  @keyframes stamp-in { from { transform: scale(1.06); opacity: 0; } to { transform: none; opacity: 1; } }
}
