/* Chart Viewer. Light and dark themes; "system" follows the iPad. No inline styles anywhere (the page's CSP forbids them). */
:root {
  --top: #06243d; --top-ink: #ffffff; --bg: #f1f5f9; --panel: #f4f7fa; --card: #ffffff; --ink: #0f1b2a; --muted: #5c6b7c;
  --line: #d4dde6; --stage: #c9d7e2; --accent: #1478d4; --accent-ink: #ffffff; --tabbar: #eef2f6; --tab-on: #1478d4;
  --fab: rgba(31, 41, 55, .92); --fab-ink: #ffffff; --tools: #1b212c; --tools-ink: #ffffff; --tool: #2a3140; --tool-on: #0d5ea8;
  --err: #b3261e; --warn: #b45309; --tag: #f59e0b; --shadow: 0 2px 8px rgba(8, 24, 48, .18);
  color-scheme: light;
}
:root[data-theme="dark"] {
  --top: #1a1f27; --top-ink: #ffffff; --bg: #0b0e13; --panel: #0e1218; --card: #262b37; --ink: #f1f4f8; --muted: #9aa6b4;
  --line: #2d3441; --stage: #05070a; --accent: #3b9cff; --accent-ink: #04121f; --tabbar: #14181f; --tab-on: #3b9cff;
  --fab: rgba(48, 56, 72, .95); --fab-ink: #ffffff; --tools: #161a22; --tools-ink: #ffffff; --tool: #262d3b; --tool-on: #0d5ea8;
  --err: #ff8a80; --warn: #fbbf24; --shadow: 0 2px 10px rgba(0, 0, 0, .5);
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --top: #1a1f27; --top-ink: #ffffff; --bg: #0b0e13; --panel: #0e1218; --card: #262b37; --ink: #f1f4f8; --muted: #9aa6b4;
    --line: #2d3441; --stage: #05070a; --accent: #3b9cff; --accent-ink: #04121f; --tabbar: #14181f; --tab-on: #3b9cff;
    --fab: rgba(48, 56, 72, .95); --fab-ink: #ffffff; --tools: #161a22; --tools-ink: #ffffff; --tool: #262d3b; --tool-on: #0d5ea8;
    --err: #ff8a80; --warn: #fbbf24; --shadow: 0 2px 10px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
/* what shows in the iPad's status-bar and home-indicator gaps: navy at the top (like the top bar), tab-bar colour at the bottom */
html { margin: 0; height: 100%; background: linear-gradient(to bottom, var(--top) 50%, var(--tabbar) 50%); }
body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--ink); overflow: hidden; overscroll-behavior: none;
  font: 17px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; -webkit-text-size-adjust: 100%;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
[hidden] { display: none !important; }
h1, h2 { margin: 0; line-height: 1.2; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.pad { padding: 16px; }
.grow { flex: 1; min-width: 0; }
.ico { width: 26px; height: 26px; flex: none; }
.btn {
  appearance: none; border: 1px solid var(--line); background: var(--card); color: var(--ink); min-height: 48px; padding: 0 18px; border-radius: 12px;
  font: inherit; font-weight: 600; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn.small { min-height: 38px; padding: 0 12px; font-size: 15px; }
.btn.wide { width: 100%; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary.danger { background: var(--err); border-color: var(--err); color: #fff; }
.btn:disabled { opacity: .5; }
button:focus-visible, select:focus-visible, input:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.tag { display: inline-block; background: var(--tag); color: #1b1200; font-weight: 700; font-size: 13px; padding: 1px 8px; border-radius: 3px; letter-spacing: .02em; }
.toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%); max-width: min(92vw, 560px); background: #1b212c; color: #fff; padding: 12px 18px; border-radius: 12px; z-index: 50; box-shadow: var(--shadow); font-size: 16px; }
.err { color: var(--err); min-height: 1.3em; margin: 8px 0; }

/* ---------- gate */
.gate { min-height: 100%; height: 100%; display: flex; align-items: center; justify-content: center; padding: 20px; background: var(--top); }
.gatecard { background: var(--bg); color: var(--ink); width: min(440px, 100%); padding: 28px 24px 22px; border-radius: 18px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 10px; -webkit-user-select: text; user-select: text; }
.gatecard input { width: 100%; min-height: 52px; padding: 0 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--card); color: var(--ink); font: inherit; font-size: 20px; letter-spacing: .06em; text-transform: uppercase; }
.gatecard .tag { align-self: flex-start; }

/* ---------- shell */
.shell { height: 100vh; height: 100dvh; display: grid; grid-template-rows: auto minmax(0, 1fr) auto; background: var(--bg); }
.top {
  position: relative; display: flex; align-items: center; gap: 8px; background: var(--top); color: var(--top-ink);
  padding: calc(12px + env(safe-area-inset-top)) calc(8px + env(safe-area-inset-right)) 4px calc(8px + env(safe-area-inset-left)); min-height: 54px;
}
.brandpill { display: flex; align-items: center; gap: 6px; background: #fff; color: #06243d; font-weight: 700; font-size: 14px; letter-spacing: .03em; padding: 0 10px; min-height: 34px; border-radius: 5px; white-space: nowrap; }
.tag.mini { font-size: 11px; padding: 0 6px; border-radius: 3px; margin-left: 2px; }
.brandpill .ico { width: 20px; height: 20px; }
:root[data-theme="dark"] .brandpill { display: flex; align-items: center; gap: 6px; background: #fff; color: #06243d; font-weight: 700; font-size: 14px; letter-spacing: .03em; padding: 0 10px; min-height: 34px; border-radius: 5px; white-space: nowrap; }
.brandpill .ico { width: 20px; height: 20px; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .brandpill { display: flex; align-items: center; gap: 6px; background: #fff; color: #06243d; font-weight: 700; font-size: 14px; letter-spacing: .03em; padding: 0 10px; min-height: 34px; border-radius: 5px; white-space: nowrap; }
.brandpill .ico { width: 20px; height: 20px; } }
.airpair { display: flex; gap: 6px; }
.airpair.dim { opacity: .55; }
.airslot { position: relative; display: flex; align-items: center; gap: 4px; background: rgba(255, 255, 255, .14); color: var(--top-ink); border-radius: 6px; padding: 0 4px 0 7px; min-height: 34px; border: 2px solid transparent; }
.airslot.on { background: #fff; color: #06243d; border-color: var(--accent); }
.airtag { font-size: 10px; font-weight: 700; letter-spacing: .07em; opacity: .8; }
.airsel { appearance: none; -webkit-appearance: none; min-height: 30px; min-width: 66px; padding: 0 18px 0 2px; border: 0; background: transparent; color: inherit; font: inherit; font-size: 15px; font-weight: 700; letter-spacing: .04em; cursor: pointer; }
.airsel option { color: #06243d; }
.airslot::after { content: ''; position: absolute; right: 8px; top: 11px; width: 5px; height: 5px; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(45deg); pointer-events: none; }
.seg { display: inline-flex; border-radius: 8px; overflow: hidden; background: rgba(255, 255, 255, .12); }
.segbtn { appearance: none; border: 0; background: transparent; color: inherit; font: inherit; font-size: 14px; font-weight: 700; min-height: 34px; min-width: 36px; padding: 0 10px; cursor: pointer; }
.segbtn.icon { min-width: 44px; padding: 0 9px; display: inline-flex; align-items: center; justify-content: center; }
.segbtn.icon .ico { width: 24px; height: 24px; }
.segbtn.on { background: var(--accent); color: var(--accent-ink); }
.chip { font-size: 13px; background: rgba(255, 255, 255, .14); padding: 4px 10px; border-radius: 999px; white-space: nowrap; }
.chip.warn { background: var(--warn); color: #1b1200; font-weight: 700; }
.iconbtn { appearance: none; border: 0; background: transparent; color: inherit; width: 40px; height: 40px; border-radius: 8px; cursor: pointer; display: grid; place-items: center; }
.iconbtn.on { background: rgba(255, 255, 255, .18); }
.iconbtn .ico { width: 24px; height: 24px; }
.iconbtn:active { background: rgba(255, 255, 255, .16); }

.menu { position: absolute; right: 10px; top: calc(100% + 6px); width: min(420px, calc(100vw - 20px)); z-index: 30; background: var(--card); color: var(--ink); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); padding: 8px; display: flex; flex-direction: column; }
.menu .seg { background: var(--panel); border: 1px solid var(--line); }
.menu .segbtn.on { color: var(--accent-ink); }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 6px 0; width: 100%; }
.menuhead { display: flex; flex-direction: column; padding: 8px 10px 10px; }
.menurow { display: flex; align-items: center; justify-content: space-between; padding: 6px 10px; gap: 10px; }
.menuitem { appearance: none; border: 0; background: transparent; color: inherit; font: inherit; text-align: left; padding: 14px 10px; border-radius: 8px; cursor: pointer; }
.menuitem:active { background: var(--panel); }
.menuitem:disabled { opacity: .45; }
.menuitem.danger { color: var(--err); }

/* ---------- body: list + stage */
.body { display: flex; min-height: 0; }
.list { position: absolute; left: 0; top: 0; bottom: 0; width: clamp(290px, 40%, 430px); z-index: 8; background: var(--panel); border-right: 1px solid var(--line); box-shadow: 6px 0 22px rgba(0, 0, 0, .35); display: flex; flex-direction: column; min-height: 0; }
.scrim { position: absolute; inset: 0; z-index: 7; background: rgba(0, 0, 0, .25); }
.listhead { display: flex; flex-direction: column; padding: 10px 16px 8px; border-bottom: 1px solid var(--line); gap: 0; }
.listtitle { font-size: 18px; font-weight: 700; }
.listbody { overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 12px 14px 20px; display: flex; flex-direction: column; gap: 10px; }
.card { appearance: none; text-align: left; border: 0; border-left: 4px solid var(--line); background: var(--card); color: var(--ink); font: inherit; padding: 12px 14px; border-radius: 4px; box-shadow: var(--shadow); cursor: pointer; display: flex; flex-direction: column; gap: 4px; }
.card.sel { border-left-color: var(--accent); outline: 2px solid var(--accent); }
.cardtitle { font-size: 19px; text-transform: uppercase; line-height: 1.25; overflow-wrap: anywhere; }
.cardcode { font-size: 14px; color: var(--muted); }
.main { position: relative; flex: 1; min-width: 0; min-height: 0; background: var(--stage); display: flex; flex-direction: column; }
.empty { position: absolute; inset: 0; z-index: 1; margin: 0; background: var(--stage); text-align: center; padding: 24px; color: var(--muted); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; }
.empty svg { width: 150px; height: 125px; opacity: .55; }
.empty h2 { color: var(--ink); font-size: 30px; font-weight: 500; }
.reader { display: flex; flex: 1; min-height: 0; flex-direction: column; }

.strip { display: flex; align-items: center; background: var(--top); color: var(--top-ink); font-size: 15px; min-height: 32px; padding: 0 10px; justify-content: center; border-top: 1px solid rgba(255, 255, 255, .1); }
.strip .sc { padding: 0 12px; border-left: 1px solid rgba(255, 255, 255, .25); white-space: nowrap; }
.strip .sc:first-child { border-left: 0; }
.strip .sc.title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; font-size: 14px; opacity: .85; }
.stagebox { position: relative; flex: 1; min-height: 0; }
.stage { position: absolute; inset: 0; overflow: hidden; touch-action: none; background: #05070a; cursor: grab; }
.stage.drawing { cursor: crosshair; }
.sheet { position: absolute; left: 0; top: 0; transform-origin: 0 0; background: #fff; box-shadow: 0 0 0 1px rgba(0, 0, 0, .1); will-change: transform; }
.sheet canvas { position: absolute; left: 0; top: 0; display: block; }
.stage.dark .sheet { background: #000; }
.stage.dark .pg { filter: invert(.93) hue-rotate(180deg); }
.ink { pointer-events: none; }
.stagemsg { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; padding: 30px; color: #fff; pointer-events: none; font-size: 20px; }
.fabs { position: absolute; right: 0; top: 30%; display: flex; flex-direction: column; background: var(--fab); border-radius: 8px 0 0 8px; overflow: hidden; z-index: 5; box-shadow: var(--shadow); }
.fab { appearance: none; border: 0; border-top: 1px solid rgba(255, 255, 255, .08); background: transparent; color: var(--fab-ink); width: 58px; height: 58px; display: grid; place-items: center; cursor: pointer; }
.fab:first-child { border-top: 0; }
.fab .ico { width: 30px; height: 30px; }
.fab.on { background: var(--tool-on); }
.pager { position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); display: flex; align-items: center; gap: 4px; background: var(--fab); color: #fff; border-radius: 999px; padding: 2px 6px; z-index: 5; }
.pbtn { appearance: none; border: 0; background: transparent; color: #fff; font-size: 30px; width: 48px; height: 44px; cursor: pointer; }
.pageno { min-width: 56px; text-align: center; font-size: 16px; }

.tools { position: absolute; left: 50%; bottom: 12px; transform: translateX(-50%); width: min(96%, 780px); background: var(--tools); color: var(--tools-ink); border-radius: 10px; padding: 12px 14px 14px; z-index: 6; box-shadow: 0 6px 24px rgba(0, 0, 0, .5); }
.toolshead { display: flex; justify-content: space-between; align-items: center; font-size: 22px; margin-bottom: 10px; }
.x { appearance: none; border: 0; background: transparent; color: inherit; font-size: 34px; line-height: 1; width: 44px; height: 44px; cursor: pointer; }
.toolrow { display: flex; align-items: stretch; gap: 8px; }
.tool { appearance: none; border: 0; flex: 1; min-height: 78px; background: var(--tool); color: inherit; border-radius: 4px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; font: inherit; font-size: 15px; cursor: pointer; }
.tool .ico { width: 32px; height: 32px; }
.tool.on { background: var(--tool-on); }
.tool:disabled { opacity: .4; }
.vsep { width: 1px; background: rgba(255, 255, 255, .2); margin: 4px 2px; }
.toolopts { display: flex; align-items: center; justify-content: space-between; margin-top: 12px; gap: 10px; flex-wrap: wrap; }
.colors { display: inline-flex; gap: 10px; }
.dot { appearance: none; width: 40px; height: 40px; border-radius: 50%; border: 3px solid rgba(255, 255, 255, .35); background: var(--c); cursor: pointer; }
.dot.on { border-color: #fff; box-shadow: 0 0 0 2px var(--tool-on); }
.toolopts .btn { background: var(--tool); border-color: transparent; color: #fff; }

/* ---------- bottom: section tabs (choosing) and the + bar (reading) */
.tabs { display: flex; background: var(--tabbar); border-top: 1px solid var(--line); padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); overflow-x: auto; }
.tab { appearance: none; border: 0; background: transparent; color: var(--ink); flex: 1 0 84px; max-width: 200px; min-height: 58px; padding: 6px 4px 5px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font: inherit; font-size: 13px; cursor: pointer; position: relative; }
.tab .ico { width: 24px; height: 24px; }
.tab.on { color: var(--tab-on); font-weight: 700; }
.tab.on::after { content: ''; position: absolute; left: 14px; right: 14px; top: 0; height: 3px; background: var(--tab-on); border-radius: 0 0 3px 3px; }
.tab.none { opacity: .45; }
.tabn { position: absolute; top: 4px; right: calc(50% - 26px); min-width: 17px; height: 17px; padding: 0 4px; border-radius: 9px; background: var(--accent); color: var(--accent-ink); font-size: 11px; font-weight: 700; display: grid; place-items: center; }
.tabn:empty { display: none; }

/* ---------- dialogs */
.dlg { border: 0; border-radius: 16px; padding: 22px; width: min(520px, 92vw); background: var(--card); color: var(--ink); box-shadow: 0 12px 40px rgba(0, 0, 0, .4); }
.dlg::backdrop { background: rgba(0, 0, 0, .5); }
.dlg p { margin: 10px 0; }
.row { display: flex; gap: 10px; align-items: center; }
.row.end { justify-content: flex-end; margin-top: 16px; }

/* ---------- narrow screens (phone): the list fills the screen while choosing */
@media (max-width: 720px) {
  .list { width: 86%; }
  .brandpill span { display: none; }
  .fab { width: 52px; height: 52px; }
}
