/* Foundation Demo : base and components. Built ONLY from css/tokens.css variables: a raw hex
   in here is a bug. Stacking uses the core ladder (var(--z-*) from css/core.css), never a bare
   z-index (Register #50, #99). */

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg-050);
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: var(--fs-body);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

h1, h2, h3, p { margin: 0; }
.display { font-family: var(--font-display); font-weight: 600; letter-spacing: -0.01em; }
.num { font-family: var(--font-display); font-variant-numeric: tabular-nums; }
.muted { color: var(--text-muted); }
.small { font-size: var(--fs-sm); }
[hidden] { display: none !important; }

/* ---------------------------------------------------------------- buttons */
.btn {
  appearance: none;
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  min-height: 46px;                       /* a thumb, not a cursor */
  padding: 0 var(--sp-4);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-md);
  background: var(--surface-200);
  color: var(--text-primary);
  font: 600 var(--fs-body)/1 var(--font-ui);
  box-shadow: var(--shadow-2);
  cursor: pointer;
  touch-action: manipulation;             /* no 300ms delay, no double-tap zoom on a fast tapper */
  transition: transform var(--t-fast) var(--ease), background var(--t-fast) var(--ease);
}
.btn:active { transform: translateY(2px); box-shadow: none; }
.btn:focus-visible { outline: 3px solid var(--accent-glow); outline-offset: 2px; }
.btn-primary { background: var(--accent); border-color: var(--accent-deep); color: var(--accent-ink); }
.btn-primary:active { background: var(--accent-deep); }
.btn-quiet { background: transparent; box-shadow: none; border-color: var(--line); min-height: 38px; font-size: var(--fs-sm); }
.btn-danger { border-color: var(--danger); color: var(--danger); }
.btn-block { width: 100%; }
.btn:disabled, .btn.is-busy { opacity: .55; cursor: default; transform: none; box-shadow: none; }

/* ---------------------------------------------------------------- fields */
.field { display: grid; gap: var(--sp-1); margin-bottom: var(--sp-4); }
.field > span { font-size: var(--fs-sm); font-weight: 600; color: var(--text-secondary); }
.field input, .field textarea, .field select {
  width: 100%;
  min-height: 46px;
  padding: var(--sp-3);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface-400);
  color: var(--text-primary);
  font: 400 1rem/1.3 var(--font-ui);      /* 16px or iOS zooms the page on focus */
}
.field textarea { min-height: 84px; resize: vertical; }
.field input:focus, .field textarea:focus { outline: 3px solid var(--accent-glow); border-color: var(--accent); }
.field-row { display: grid; grid-template-columns: 1fr auto; gap: var(--sp-2); align-items: end; }
.unit-tag { min-height: 46px; display: inline-flex; align-items: center; padding: 0 var(--sp-3); border: 1px solid var(--line); border-radius: var(--r-md); color: var(--text-secondary); font-family: var(--font-display); }

/* ---------------------------------------------------------------- login */
.login { min-height: 100dvh; display: grid; place-items: center; padding: var(--sp-5); padding-top: calc(var(--sp-5) + var(--safe-top)); }
.login-card { width: min(420px, 100%); }
.login-logo { display: block; border: 1px solid var(--line-strong); border-radius: var(--r-lg); margin-bottom: var(--sp-4); }
.login-card h1 { font-size: var(--fs-h1); }
.login-card .sub { color: var(--text-secondary); margin: var(--sp-2) 0 var(--sp-5); }
.err { margin-top: var(--sp-4); padding: var(--sp-3); border: 1px solid var(--danger); border-radius: var(--r-md); background: var(--danger-dim); display: grid; gap: var(--sp-2); }
.demo-logins { margin-top: var(--sp-5); padding-top: var(--sp-4); border-top: 1px dashed var(--line); display: grid; gap: var(--sp-2); }

/* ---------------------------------------------------------------- shell */
.app-shell { min-height: 100dvh; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: var(--z-sticky);
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3);
  padding: calc(var(--sp-3) + var(--safe-top)) var(--sp-4) var(--sp-3);
  background: var(--bg-050);
  border-bottom: 1px solid var(--line-strong);
}
.topbar h1 { font-size: var(--fs-h2); }
.topbar-right { display: flex; align-items: center; gap: var(--sp-2); }
.screen { flex: 1; width: min(620px, 100%); margin: 0 auto; padding: var(--sp-4); padding-bottom: calc(var(--tabbar-h) + var(--safe-b) + var(--sp-6)); }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: var(--z-tabbar);
  display: grid; grid-template-columns: repeat(4, 1fr);
  padding-bottom: var(--safe-b);
  background: var(--surface-200);
  border-top: 1px solid var(--line-strong);
}
.tab {
  appearance: none; border: 0; background: transparent;
  min-height: 60px;
  font: 600 var(--fs-sm)/1 var(--font-display);
  color: var(--text-muted);
  border-top: 3px solid transparent;
  touch-action: manipulation;
  cursor: pointer;
}
.tab.is-on { color: var(--text-primary); border-top-color: var(--accent); }

/* ---------------------------------------------------------------- sync state
   The ONLY place green / amber / red appear. */
.sync { display: inline-flex; align-items: center; gap: 6px; padding: 4px 9px; border-radius: var(--r-full); border: 1px solid var(--line); font: 600 var(--fs-xs)/1 var(--font-display); white-space: nowrap; }
.sync::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.sync.is-ok { color: var(--ok); background: var(--ok-dim); border-color: transparent; }
.sync.is-wait { color: var(--warn); background: var(--warn-dim); border-color: transparent; }
.sync.is-dead { color: var(--danger); background: var(--danger-dim); border-color: transparent; }

/* ---------------------------------------------------------------- panels + lists */
.panel { background: var(--surface-100); border: 1px solid var(--line); border-radius: var(--r-lg); padding: var(--sp-4); margin-bottom: var(--sp-4); }
.panel > h2 { font: 600 var(--fs-sm)/1.2 var(--font-display); text-transform: uppercase; letter-spacing: .06em; color: var(--text-secondary); margin-bottom: var(--sp-3); }
.panel-danger { border-color: var(--danger); border-style: dashed; }
.stack { display: grid; gap: var(--sp-2); }
.kv { display: flex; justify-content: space-between; gap: var(--sp-3); padding: var(--sp-2) 0; border-bottom: 1px solid var(--line-soft); font-size: var(--fs-sm); }
.kv:last-child { border-bottom: 0; }
.kv b { font-family: var(--font-display); font-weight: 500; text-align: right; overflow-wrap: anywhere; }

.rows { list-style: none; margin: 0; padding: 0; }
.row { display: grid; grid-template-columns: 1fr auto; gap: var(--sp-2) var(--sp-3); align-items: start; padding: var(--sp-3) 0; border-bottom: 1px solid var(--line-soft); }
.row:last-child { border-bottom: 0; }
.row-main { min-width: 0; overflow-wrap: anywhere; }
.row-meta { font-size: var(--fs-xs); color: var(--text-muted); font-family: var(--font-display); }
.row-thumb { grid-column: 1 / -1; width: 96px; height: 96px; object-fit: cover; border: 1px solid var(--line); border-radius: var(--r-md); background: var(--surface-300); }
.emptyline { color: var(--text-muted); font-size: var(--fs-sm); padding: var(--sp-3) 0; }

.big-num { font: 600 var(--fs-hero)/1 var(--font-display); font-variant-numeric: tabular-nums; }
.explain { font-size: var(--fs-sm); color: var(--text-secondary); margin-top: var(--sp-2); }
.filepick { font-size: var(--fs-sm); }

/* The scaffold's own toast (auth.toast). core/oops.js brings its own and styles it in oops.css. */
.toast { position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + var(--safe-b) + var(--sp-4)); transform: translate(-50%, 20px); z-index: var(--z-toast); max-width: min(92vw, 420px); padding: var(--sp-3) var(--sp-4); border-radius: var(--r-md); background: var(--text-primary); color: var(--bg-050); font-size: var(--fs-sm); opacity: 0; pointer-events: none; transition: opacity var(--t-base) var(--ease), transform var(--t-base) var(--ease); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
