/* The app shell's styles. Every colour, font, corner and size is a variable. The config
   tool writes the app's design profile into index.html (<style id="app-theme">, after this
   file) as -l (light) and -d (dark) sources; this file picks the right one for the mode.
   The fallbacks below are the original look, so a page without a profile still looks as
   it always did. Parts use the component classes at the bottom (card, btn, input, list, ...)
   and the colour variables, and may add their own part.css. */

:root {
  color-scheme: light dark;
  /* light mode: the profile's -l sources, else the original look */
  --accent: var(--accent-l, #2563eb);
  --on-accent: var(--on-accent-l, #ffffff);
  --bg-light: #f6f7fb;
  --bg-dark: #0f1115;
  --bg: var(--bg-l, var(--bg-light));
  --surface: var(--surface-l, #ffffff);
  --surface-2: var(--surface-2-l, #eef0f5);
  --text: var(--text-l, #15171c);
  --muted: var(--muted-l, #5f6670);
  --line: var(--line-l, #e2e5eb);
  --field-line: var(--field-line-l, var(--line));
  --edge: var(--edge-l, var(--line));
  --btn: var(--btn-l, var(--accent));
  --on-btn: var(--on-btn-l, var(--on-accent));
  --bar-bg: var(--bar-bg-l, var(--accent));
  --bar-ink: var(--bar-ink-l, var(--on-accent));
  --tabbar-bg: var(--tabbar-bg-l, var(--surface));
  --support: var(--support-l, var(--accent));
  --support-soft: var(--support-soft-l, var(--surface-2));
  --danger: var(--danger-l, #c62828);
  --on-danger: var(--on-danger-l, #ffffff);
  --ok: var(--ok-l, #2e7d32);
  --shadow: var(--shadow-l, 0 1px 2px rgba(16, 24, 40, .06), 0 6px 20px rgba(16, 24, 40, .06));
  --accent-soft: color-mix(in srgb, var(--accent) var(--soft-pct, 14%), transparent);

  /* shape, type and density (the profile layer overrides any of these) */
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-head: var(--font);
  --fs: 17px;
  --lh: 1.45;
  --head-weight: 700;
  --head-weight-2: 650;
  --head-case: none;
  --head-spacing: -.02em;
  --radius: 14px;
  --radius-btn: 12px;
  --radius-input: 12px;
  --radius-sheet: 20px;
  --icon-radius: 9px;
  --card-pad: 16px;
  --card-border-w: 0px;
  --card-shadow: var(--shadow);
  --btn-weight: 600;
  --btn-case: none;
  --btn-spacing: 0;
  --btn-fs: 16px;
  --btn-border-w: 0px;
  --field-border-w: 1px;
  --appbar-title-fs: 19px;
  --appbar-title-weight: 650;
  --appbar-title-case: none;
  --appbar-title-spacing: -.01em;
  --bar-rule-w: 0px;
  --bar-rule: var(--line);
  --tab-fs: 11.5px;
  --tab-weight: 600;
  --tab-ico-radius: 15px;
  --tab-on-bg: var(--accent-soft);
  --tab-on-ink: var(--accent);
  --tab-ind: transparent;
  --tab-ind-h: 0px;

  --tap: 48px;
  --appbar: 56px;
  --tabbar: 60px;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
  --gutter: 16px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --accent: var(--accent-d, #2563eb);
    --on-accent: var(--on-accent-d, #ffffff);
    --bg: var(--bg-d, var(--bg-dark));
    --surface: var(--surface-d, #1a1d24);
    --surface-2: var(--surface-2-d, #252934);
    --text: var(--text-d, #eef0f4);
    --muted: var(--muted-d, #9aa3b2);
    --line: var(--line-d, #2b303a);
    --field-line: var(--field-line-d, var(--line));
    --edge: var(--edge-d, var(--line));
    --btn: var(--btn-d, var(--accent));
    --on-btn: var(--on-btn-d, var(--on-accent));
    --bar-bg: var(--bar-bg-d, var(--accent));
    --bar-ink: var(--bar-ink-d, var(--on-accent));
    --tabbar-bg: var(--tabbar-bg-d, var(--surface));
    --support: var(--support-d, var(--accent));
    --support-soft: var(--support-soft-d, var(--surface-2));
    --danger: var(--danger-d, #c62828);
    --on-danger: var(--on-danger-d, #ffffff);
    --ok: var(--ok-d, #2e7d32);
    --shadow: var(--shadow-d, 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25));
  }
}
:root[data-theme="dark"] {
  --accent: var(--accent-d, #2563eb);
  --on-accent: var(--on-accent-d, #ffffff);
  --bg: var(--bg-d, var(--bg-dark));
  --surface: var(--surface-d, #1a1d24);
  --surface-2: var(--surface-2-d, #252934);
  --text: var(--text-d, #eef0f4);
  --muted: var(--muted-d, #9aa3b2);
  --line: var(--line-d, #2b303a);
  --field-line: var(--field-line-d, var(--line));
  --edge: var(--edge-d, var(--line));
  --btn: var(--btn-d, var(--accent));
  --on-btn: var(--on-btn-d, var(--on-accent));
  --bar-bg: var(--bar-bg-d, var(--accent));
  --bar-ink: var(--bar-ink-d, var(--on-accent));
  --tabbar-bg: var(--tabbar-bg-d, var(--surface));
  --support: var(--support-d, var(--accent));
  --support-soft: var(--support-soft-d, var(--surface-2));
  --danger: var(--danger-d, #c62828);
  --on-danger: var(--on-danger-d, #ffffff);
  --ok: var(--ok-d, #2e7d32);
  --shadow: var(--shadow-d, 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25));
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-size: var(--fs);
  line-height: var(--lh);
  font-family: var(--font);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
  touch-action: manipulation;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { -webkit-tap-highlight-color: transparent; cursor: pointer; }
a { color: var(--accent); }
img { max-width: 100%; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
svg.ico { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---- the frame: app bar, screens, tab bar */
#app {
  position: fixed; inset: 0;
  display: flex; flex-direction: column;
  background: var(--bg);
}
.boot {
  flex: 1; display: grid; place-items: center;
}
.boot-icon { width: 72px; height: 72px; border-radius: 18px; animation: boot-pulse 1.2s ease-in-out infinite; }
@keyframes boot-pulse { 0%, 100% { opacity: .55; } 50% { opacity: 1; } }

.appbar {
  flex: none;
  display: flex; align-items: center; gap: 12px;
  min-height: calc(var(--appbar) + var(--sat));
  padding: var(--sat) max(var(--gutter), var(--sar)) 0 max(var(--gutter), var(--sal));
  background: var(--bar-bg);
  color: var(--bar-ink);
  box-shadow: 0 1px 0 rgba(0, 0, 0, .08);
  border-bottom: var(--bar-rule-w) solid var(--bar-rule);
  z-index: 2;
}
.appbar-icon { width: 32px; height: 32px; border-radius: var(--icon-radius); flex: none; }
.appbar-title {
  flex: 1; min-width: 0;
  font-size: var(--appbar-title-fs); font-weight: var(--appbar-title-weight); letter-spacing: var(--appbar-title-spacing);
  text-transform: var(--appbar-title-case);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.appbar-actions { display: flex; align-items: center; gap: 6px; flex: none; }
.appbar-btn {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 40px; padding: 0 14px;
  border: 0; border-radius: 999px;
  background: color-mix(in srgb, var(--bar-ink) 16%, transparent);
  color: inherit; font-weight: 600; font-size: 15px;
}
.appbar-btn:active { background: color-mix(in srgb, var(--bar-ink) 28%, transparent); }
.appbar-btn.icon-only { width: 40px; padding: 0; justify-content: center; }

.screens { flex: 1; min-height: 0; position: relative; }
.screen {
  position: absolute; inset: 0;
  overflow-y: auto; overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: var(--gutter) max(var(--gutter), var(--sar)) 28px max(var(--gutter), var(--sal));
}
.screen-inner { max-width: 720px; margin: 0 auto; }
.screen.fill { overflow: hidden; padding: 0; display: flex; flex-direction: column; }
.screen.fill > .screen-inner { max-width: none; margin: 0; flex: 1; min-height: 0; display: flex; flex-direction: column; }
.screen-error { text-align: center; padding: 40px 16px; color: var(--muted); }

.tabbar {
  flex: none;
  display: flex; align-items: stretch;
  min-height: calc(var(--tabbar) + var(--sab));
  padding: 0 max(0px, var(--sar)) var(--sab) max(0px, var(--sal));
  background: var(--tabbar-bg);
  border-top: 1px solid var(--line);
  z-index: 2;
}
.tab {
  position: relative;
  flex: 1 1 0; min-width: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  min-height: var(--tap);
  padding: 6px 4px 4px;
  border: 0; background: none;
  color: var(--muted); font-size: var(--tab-fs); font-weight: var(--tab-weight); letter-spacing: .01em;
  user-select: none; -webkit-user-select: none;
  transition: color .15s;
}
.tab .tab-ico {
  width: 56px; height: 30px; border-radius: var(--tab-ico-radius);
  display: grid; place-items: center;
  transition: background .15s;
  font-size: 20px; line-height: 1;
}
.tab .tab-label { max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tab[aria-selected="true"] { color: var(--accent); }
.tab[aria-selected="true"] .tab-ico { background: var(--tab-on-bg); color: var(--tab-on-ink); }
.tab[aria-selected="true"]::before {
  content: ""; position: absolute; top: 0; left: 22%; right: 22%;
  height: var(--tab-ind-h); border-radius: 0 0 3px 3px; background: var(--tab-ind);
}
.tab:active .tab-ico { background: var(--surface-2); }
.tabbar.single { display: none; }

/* ---- status bits */
.offline-banner {
  position: absolute; left: 0; right: 0; top: 0;
  z-index: 3;
  text-align: center; font-size: 13px; font-weight: 600;
  padding: 6px 12px;
  background: #b45309; color: #fff;
}
.toast-root {
  position: fixed; left: 0; right: 0;
  bottom: calc(var(--tabbar) + var(--sab) + 12px);
  display: flex; justify-content: center;
  pointer-events: none; z-index: 20;
}
.toast {
  max-width: min(92vw, 420px);
  padding: 12px 18px; border-radius: 12px;
  background: #23262e; color: #fff; font-size: 15px; font-weight: 500;
  box-shadow: var(--shadow);
  opacity: 0; transform: translateY(8px);
  transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: none; }
.toast.error { background: var(--danger); color: var(--on-danger); }
.toast.ok { background: var(--ok); }

/* ---- bottom sheet (the install hint, and free for parts to use) */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 30;
  background: rgba(0, 0, 0, .35);
  opacity: 0; transition: opacity .2s;
}
.sheet-backdrop.show { opacity: 1; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 31;
  max-width: 560px; margin: 0 auto;
  background: var(--surface); color: var(--text);
  border-radius: var(--radius-sheet) var(--radius-sheet) 0 0;
  padding: 14px var(--gutter) calc(var(--gutter) + var(--sab));
  box-shadow: 0 -8px 30px rgba(0, 0, 0, .18);
  transform: translateY(100%); transition: transform .25s cubic-bezier(.2, .8, .2, 1);
}
.sheet.show { transform: none; }
.sheet-handle { width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: 0 auto 14px; }
.sheet h2 { margin: 0 0 6px; font-size: 19px; font-family: var(--font-head); font-weight: var(--head-weight-2); }
.sheet p { margin: 0 0 10px; color: var(--muted); font-size: 15px; }
.sheet .steps { margin: 10px 0 14px; padding: 0; list-style: none; display: grid; gap: 10px; }
.sheet .steps li { display: flex; align-items: center; gap: 12px; font-size: 16px; }
.sheet .steps .step-n {
  width: 28px; height: 28px; border-radius: 50%; flex: none;
  display: grid; place-items: center;
  background: var(--btn); color: var(--on-btn); font-weight: 700; font-size: 14px;
}
.sheet .steps svg.ico { color: var(--accent); }
.sheet .sheet-actions { display: flex; gap: 10px; }
.sheet .sheet-actions .btn { flex: 1; }

/* ---- components for parts */
.h1 {
  font-family: var(--font-head); font-size: 26px; font-weight: var(--head-weight);
  letter-spacing: var(--head-spacing); text-transform: var(--head-case); margin: 4px 0 12px;
}
.h2 { font-family: var(--font-head); font-size: 18px; font-weight: var(--head-weight-2); margin: 18px 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.card {
  background: var(--surface); border-radius: var(--radius);
  border: var(--card-border-w) solid var(--edge);
  box-shadow: var(--card-shadow); padding: var(--card-pad); margin: 0 0 12px;
}
.card.plain { box-shadow: none; border: max(1px, var(--card-border-w)) solid var(--line); }
.row { display: flex; align-items: center; gap: 10px; }
.row > .grow { flex: 1; min-width: 0; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap); padding: 0 18px;
  border: var(--btn-border-w) solid var(--edge); border-radius: var(--radius-btn);
  background: var(--btn); color: var(--on-btn);
  font-weight: var(--btn-weight); font-size: var(--btn-fs); text-decoration: none;
  text-transform: var(--btn-case); letter-spacing: var(--btn-spacing);
  transition: filter .1s, transform .1s;
}
.btn:active { filter: brightness(.92); transform: scale(.985); }
.btn:disabled { opacity: .5; }
.btn.secondary { background: var(--support-soft); color: var(--text); }
.btn.ghost { background: transparent; color: var(--accent); border-color: transparent; }
.btn.danger { background: var(--danger); color: var(--on-danger); }
.btn.block { display: flex; width: 100%; }
.btn.small { min-height: 40px; padding: 0 14px; font-size: 15px; }
.icon-btn {
  width: var(--tap); height: var(--tap); border: 0; border-radius: 50%;
  background: transparent; color: var(--muted);
  display: inline-grid; place-items: center; flex: none;
}
.icon-btn:active { background: var(--surface-2); }
.input, .textarea, .select {
  width: 100%; min-height: var(--tap);
  padding: 0 14px;
  border: var(--field-border-w) solid var(--field-line); border-radius: var(--radius-input);
  background: var(--surface); color: var(--text);
  outline: none;
}
.textarea { padding: 12px 14px; min-height: 96px; resize: vertical; }
.input:focus, .textarea:focus, .select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.list { margin: 0; padding: 0; list-style: none; }
.list-item {
  display: flex; align-items: center; gap: 12px;
  min-height: 56px; padding: 10px 0;
  border-top: 1px solid var(--line);
  overflow-wrap: anywhere;
}
.list-item:first-child { border-top: 0; }
.list-item .grow { flex: 1; min-width: 0; }
.empty { text-align: center; color: var(--muted); padding: 36px 16px; }
.empty svg.ico { width: 40px; height: 40px; stroke-width: 1.5; margin-bottom: 8px; opacity: .6; }
.badge {
  display: inline-block; padding: 2px 9px; border-radius: 999px;
  font-size: 12px; font-weight: 700; letter-spacing: .02em;
  background: var(--accent-soft); color: var(--accent);
}
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 15px; }
.kv dt { color: var(--muted); margin: 0; }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.spinner {
  width: 22px; height: 22px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- the profile carried into the parts. Their stylesheets load after this one, so each
   rule is prefixed with :root to outrank them. Headings take the profile's heading face, and
   white text on the warning colour becomes the colour's own readable ink (in dark mode the
   warning colour is lightened so it reads as text, and white on it would not). */
:root .graph-title, :root .tbl-title, :root .fb-head, :root .qr-title, :root .mp-confirm-title, :root .mp-popup-title {
  font-family: var(--font-head);
}
:root .tbl-badge.warn, :root .fb-mic.on, :root .cap-rec { color: var(--on-danger); }
:root .mp-cluster-inner { color: var(--on-accent); }
:root .tbl-fab { border: var(--btn-border-w) solid var(--edge); }
:root .tbl-card, :root .tbl-table-wrap { border: var(--card-border-w) solid var(--edge); box-shadow: var(--card-shadow); }

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