:root {
  --bg: #f4f5f7;
  --paper: #ffffff;
  --ink: #16191d;
  --muted: #5d6670;
  --line: #c9ced4;
  --line-strong: #8a929b;
  --input-bg: #ffffff;
  --input-line: #9aa3ad;
  --copy-bg: #e7f0ff;
  --copy-ink: #0b3d91;
  --shade: #1f2328;
  --accent: #1f5fbf;
  --warn-bg: #fff4d6;
  --warn-ink: #7a5300;
  --err-ink: #b3261e;
  --tab-bg: #e3e6ea;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1114; --paper: #171a1f; --ink: #e6e8eb; --muted: #9aa3ad;
    --line: #2c3138; --line-strong: #4a525c; --input-bg: #0f1114; --input-line: #4a525c;
    --copy-bg: #13284a; --copy-ink: #a8c7ff; --shade: #000; --accent: #6ea2ff;
    --warn-bg: #3a2e0a; --warn-ink: #f2cf72; --err-ink: #ff8a80; --tab-bg: #22262c;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1114; --paper: #171a1f; --ink: #e6e8eb; --muted: #9aa3ad;
  --line: #2c3138; --line-strong: #4a525c; --input-bg: #0f1114; --input-line: #4a525c;
  --copy-bg: #13284a; --copy-ink: #a8c7ff; --shade: #000; --accent: #6ea2ff;
  --warn-bg: #3a2e0a; --warn-ink: #f2cf72; --err-ink: #ff8a80; --tab-bg: #22262c;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.35 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
header {
  position: sticky; top: 0; z-index: 5; background: var(--bg);
  display: flex; align-items: center; gap: 12px; padding: 10px 16px 8px; border-bottom: 1px solid var(--line);
}
header h1 { font-size: 17px; margin: 0; white-space: nowrap; }
nav { display: flex; gap: 4px; background: var(--tab-bg); border-radius: 10px; padding: 3px; overflow-x: auto; }
nav button {
  border: 0; background: transparent; color: var(--ink); font: inherit; font-weight: 600;
  padding: 8px 14px; border-radius: 8px; min-height: 40px; white-space: nowrap;
}
nav button[aria-selected="true"] { background: var(--paper); box-shadow: 0 1px 2px rgb(0 0 0 / .15); }
.spacer { flex: 1; }
.icon-btn { border: 1px solid var(--line-strong); background: var(--paper); color: var(--ink); border-radius: 8px; min-height: 40px; padding: 0 12px; font: inherit; }

main { padding: 12px 16px 48px; max-width: 1400px; margin: 0 auto; }
section.card { background: var(--paper); border: 1px solid var(--line); border-radius: 10px; padding: 12px; margin-bottom: 12px; }
h2 { font-size: 13px; letter-spacing: .06em; text-transform: uppercase; margin: 0 0 8px; color: var(--muted); }
.row { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-start; }
.row > section.card { flex: 1 1 300px; margin-bottom: 0; }
.stack { display: flex; flex-direction: column; gap: 12px; margin-bottom: 12px; }

.scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.form { border-collapse: collapse; width: 100%; }
table.form th, table.form td { border: 1px solid var(--line-strong); padding: 0; text-align: center; vertical-align: middle; height: 44px; }
table.form th { font-size: 11px; font-weight: 700; line-height: 1.15; padding: 4px 3px; text-transform: uppercase; background: var(--paper); }
table.form td.label { text-align: left; padding: 0 8px; font-weight: 600; font-size: 13px; white-space: nowrap; }
td.shade { background: var(--shade); }
td.copy, span.copy { background: var(--copy-bg); color: var(--copy-ink); font-weight: 700; font-variant-numeric: tabular-nums; font-size: 16px; }
span.copy { display: inline-block; min-width: 64px; padding: 8px 10px; border-radius: 6px; text-align: center; }
td.copy.inherit, .inherit { opacity: .55; }
td.total { font-weight: 700; }

input, select {
  font: inherit; font-size: 16px; color: var(--ink); background: var(--input-bg);
  border: 1px solid var(--input-line); border-radius: 6px; padding: 8px; min-height: 40px; width: 100%;
}
td input { border: 0; border-radius: 0; background: transparent; text-align: center; height: 44px; padding: 4px; }
td input:focus, input:focus { outline: 3px solid var(--accent); outline-offset: -3px; }
td.in { background: var(--input-bg); }
.wind { display: flex; align-items: stretch; }
.wind input { width: 50%; }
.wind input + input { border-left: 1px solid var(--line); }
input::placeholder { color: var(--muted); opacity: .7; }

.fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.field label, .fl { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
.kv { display: grid; grid-template-columns: auto auto; gap: 6px 12px; align-items: center; justify-content: start; }
.kv .copy { justify-self: start; }

.warn { background: var(--warn-bg); color: var(--warn-ink); border-radius: 6px; padding: 6px 10px; font-size: 13px; margin-top: 8px; }
.warn:empty { display: none; }
.err { color: var(--err-ink); font-weight: 600; font-size: 13px; }
.note { color: var(--muted); font-size: 13px; margin: 6px 0 0; }
.legend { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; font-size: 13px; color: var(--muted); margin-bottom: 10px; }
.legend i { display: inline-block; width: 18px; height: 14px; border-radius: 3px; vertical-align: -2px; margin-right: 5px; border: 1px solid var(--line-strong); }
.legend .lc { background: var(--copy-bg); } .legend .li { background: var(--input-bg); } .legend .ls { background: var(--shade); }

.btn { font: inherit; font-weight: 600; border-radius: 8px; min-height: 44px; padding: 0 16px; border: 1px solid var(--line-strong); background: var(--paper); color: var(--ink); }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.danger { color: var(--err-ink); }
.btns { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.toggle { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; min-height: 44px; }
.toggle input { width: 22px; height: 22px; min-height: 0; }

.plans { list-style: none; padding: 0; margin: 0; }
.plans li { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.plans li .name { flex: 1; font-weight: 600; min-width: 160px; }
.plans li .when { color: var(--muted); font-size: 13px; }

#update-banner { position: fixed; left: 50%; bottom: calc(16px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--accent); color: #fff; border-radius: 10px; padding: 10px 14px; display: none; gap: 10px; align-items: center; z-index: 10; box-shadow: 0 4px 16px rgb(0 0 0 / .3); }
#update-banner button { background: #fff; color: var(--accent); border: 0; border-radius: 6px; font: inherit; font-weight: 700; padding: 8px 12px; }

.side-label { font-weight: 700; text-align: left; padding-left: 8px; }
.split { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 700px) {
  header { flex-wrap: wrap; }
  .split { grid-template-columns: 1fr; }
}
@media print { header, nav, #update-banner { display: none; } }
