/* The app shell's styles. The three colours that change per app (accent, light and dark
   backgrounds) are written into index.html by the config tool; everything else here is
   shared so every app built on the shell looks coherent. Parts may use the component
   classes at the bottom (card, btn, input, list, ...) and add their own part.css. */

:root {
  color-scheme: light dark;
  /* defaults; the stamped <style id="app-theme"> in index.html overrides these four */
  --accent: #2563eb;
  --on-accent: #ffffff;
  --bg-light: #f6f7fb;
  --bg-dark: #0f1115;

  --bg: var(--bg-light);
  --surface: #ffffff;
  --surface-2: #eef0f5;
  --text: #15171c;
  --muted: #5f6670;
  --line: #e2e5eb;
  --danger: #c62828;
  --ok: #2e7d32;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 6px 20px rgba(16, 24, 40, .06);
  --accent-soft: color-mix(in srgb, var(--accent) 14%, transparent);

  --radius: 14px;
  --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;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: var(--bg-dark);
    --surface: #1a1d24;
    --surface-2: #252934;
    --text: #eef0f4;
    --muted: #9aa3b2;
    --line: #2b303a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
  }
}
:root[data-theme="dark"] {
  --bg: var(--bg-dark);
  --surface: #1a1d24;
  --surface-2: #252934;
  --text: #eef0f4;
  --muted: #9aa3b2;
  --line: #2b303a;
  --shadow: 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: 17px/1.45 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; }
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(--accent);
  color: var(--on-accent);
  box-shadow: 0 1px 0 rgba(0, 0, 0, .08);
  z-index: 2;
}
.appbar-icon { width: 32px; height: 32px; border-radius: 9px; flex: none; }
.appbar-title {
  flex: 1; min-width: 0;
  font-size: 19px; font-weight: 650; letter-spacing: -.01em;
  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(--on-accent) 18%, transparent);
  color: inherit; font-weight: 600; font-size: 15px;
}
.appbar-btn:active { background: color-mix(in srgb, var(--on-accent) 30%, 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(--surface);
  border-top: 1px solid var(--line);
  z-index: 2;
}
.tab {
  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: 11.5px; font-weight: 600; letter-spacing: .01em;
  user-select: none; -webkit-user-select: none;
  transition: color .15s;
}
.tab .tab-ico {
  width: 56px; height: 30px; border-radius: 15px;
  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(--accent-soft); }
.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); }
.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: 20px 20px 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; }
.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(--accent); color: var(--on-accent); 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-size: 26px; font-weight: 700; letter-spacing: -.02em; margin: 4px 0 12px; }
.h2 { font-size: 18px; font-weight: 650; margin: 18px 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.card {
  background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px; margin: 0 0 12px;
}
.card.plain { box-shadow: none; border: 1px 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: 0; border-radius: 12px;
  background: var(--accent); color: var(--on-accent);
  font-weight: 600; font-size: 16px; text-decoration: none;
  transition: filter .1s, transform .1s;
}
.btn:active { filter: brightness(.92); transform: scale(.985); }
.btn:disabled { opacity: .5; }
.btn.secondary { background: var(--surface-2); color: var(--text); }
.btn.ghost { background: transparent; color: var(--accent); }
.btn.danger { background: var(--danger); color: #fff; }
.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: 1px solid var(--line); border-radius: 12px;
  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); } }

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