  :root {
    --pl-bg: #EEF2F0; --pl-surface: #FFFFFF; --pl-surface2: #F3F6F4; --pl-ink: #10201B; --pl-muted: #52635E;
    --pl-line: #D5DFDB; --pl-accent: #0F766E; --pl-accent-ink: #FFFFFF; --pl-accent-soft: #D3EEE9; --pl-accent-text: #0B5E57;
    --pl-target: #C2410C; --pl-good: #15803D; --pl-bad: #B91C1C; --pl-warn: #8A3B0A;
    --pl-good-soft: #DCF1E3; --pl-bad-soft: #FBE0DE; --pl-warn-soft: #FBEBC5;
    --pl-shadow: 0 1px 2px rgba(16,32,27,.06), 0 4px 14px rgba(16,32,27,.05);
    --pl-font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  }
  @media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
      color-scheme: dark;
      --pl-bg: #0B1412; --pl-surface: #141F1C; --pl-surface2: #1B2926; --pl-ink: #E9F2EE; --pl-muted: #9DB1AA;
      --pl-line: #2A3B37; --pl-accent: #2DD4BF; --pl-accent-ink: #06211D; --pl-accent-soft: #11403A; --pl-accent-text: #5EEAD4;
      --pl-target: #FB923C; --pl-good: #4ADE80; --pl-bad: #F87171; --pl-warn: #FACC15;
      --pl-good-soft: #123222; --pl-bad-soft: #3A1918; --pl-warn-soft: #3A3009;
      --pl-shadow: none;
    }
  }
  :root[data-theme="dark"] {
    color-scheme: dark;
    --pl-bg: #0B1412; --pl-surface: #141F1C; --pl-surface2: #1B2926; --pl-ink: #E9F2EE; --pl-muted: #9DB1AA;
    --pl-line: #2A3B37; --pl-accent: #2DD4BF; --pl-accent-ink: #06211D; --pl-accent-soft: #11403A; --pl-accent-text: #5EEAD4;
    --pl-target: #FB923C; --pl-good: #4ADE80; --pl-bad: #F87171; --pl-warn: #FACC15;
    --pl-good-soft: #123222; --pl-bad-soft: #3A1918; --pl-warn-soft: #3A3009;
    --pl-shadow: none;
  }
  :root[data-theme="light"] { color-scheme: light; }

  *, *::before, *::after { box-sizing: border-box; }
  html { background: var(--pl-bg); }
  body { margin: 0; background: var(--pl-bg); color: var(--pl-ink); font-family: var(--pl-font); font-size: 14px; line-height: 1.5; padding-inline: 16px; padding-block: 20px 48px; -webkit-font-smoothing: antialiased; }
  button, input, select, textarea { font: inherit; color: inherit; }
  .app { max-width: 1080px; margin-inline: auto; color: var(--pl-ink); }
  .app p, .app h1, .app h2 { margin: 0; }
  .app h1, .app h2, .display { font-family: var(--pl-font); letter-spacing: -0.015em; text-wrap: balance; color: var(--pl-ink); }
  .num { font-variant-numeric: tabular-nums; }

  /* layout utilities */
  .flex { display: flex; } .inline-flex { display: inline-flex; } .grid { display: grid; } .block { display: block; }
  .flex-wrap { flex-wrap: wrap; } .items-center { align-items: center; } .items-end { align-items: flex-end; }
  .justify-between { justify-content: space-between; } .justify-end { justify-content: flex-end; }
  .gap-1 { gap: 4px; } .gap-2 { gap: 8px; } .gap-3 { gap: 12px; } .gap-x-5 { column-gap: 20px; } .gap-y-1 { row-gap: 4px; }
  .mb-2 { margin-bottom: 8px; } .mb-3 { margin-bottom: 12px; } .mb-4 { margin-bottom: 16px; } .mb-5 { margin-bottom: 20px; }
  .mt-2 { margin-top: 8px; } .mt-3 { margin-top: 12px; } .mt-4 { margin-top: 16px; } .mt-5 { margin-top: 20px; }
  .p-4 { padding: 16px; }
  .grid-cols-1 { grid-template-columns: minmax(0, 1fr); }
  .grid-cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .col-span-2 { grid-column: span 2 / span 2; }
  @media (min-width: 640px) { .sm-cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
  @media (min-width: 768px) {
    .md-cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
    .md-span-2 { grid-column: span 2 / span 2; } .md-span-3 { grid-column: span 3 / span 3; } .md-span-4 { grid-column: span 4 / span 4; }
  }

  /* components */
  .card { background: var(--pl-surface); color: var(--pl-ink); border: 1px solid var(--pl-line); border-radius: 14px; box-shadow: var(--pl-shadow); }
  .label { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--pl-muted); font-weight: 600; }
  label > .label { display: block; margin-bottom: 4px; }
  .muted { color: var(--pl-muted); }
  .big { font-size: 28px; font-weight: 700; line-height: 1.2; margin-top: 6px; }
  .btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 12px; border-radius: 10px; border: 1px solid var(--pl-line); background: var(--pl-surface); color: var(--pl-ink); font-weight: 600; cursor: pointer; line-height: 1.3; }
  .btn:hover { background: var(--pl-surface2); }
  .btn-primary { background: var(--pl-accent); border-color: var(--pl-accent); color: var(--pl-accent-ink); }
  .btn-primary:hover { background: var(--pl-accent); filter: brightness(1.08); }
  .btn-danger { background: var(--pl-bad); border-color: var(--pl-bad); color: #FFFFFF; }
  .btn-danger:hover { background: var(--pl-bad); filter: brightness(1.08); }
  .btn-sm { padding: 4px 10px; }
  .icon-btn { padding: 7px; border-radius: 8px; border: 1px solid transparent; background: transparent; color: var(--pl-muted); cursor: pointer; display: inline-flex; }
  .icon-btn:hover { background: var(--pl-surface2); color: var(--pl-ink); border-color: var(--pl-line); }
  .icon-btn.boxed { border-color: var(--pl-line); background: var(--pl-surface); color: var(--pl-ink); }
  button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--pl-accent); outline-offset: 2px; }
  .field { display: block; width: 100%; margin: 0; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--pl-line);
    background-color: var(--pl-surface2); color: var(--pl-ink); caret-color: var(--pl-accent);
    font-size: 16px; line-height: 20px; height: auto; opacity: 1;
    -webkit-appearance: none; -moz-appearance: none; appearance: none; background-clip: padding-box; box-shadow: none; }
  textarea.field { resize: vertical; }
  .field:focus, .field:focus-visible { outline: none; border-color: var(--pl-accent); box-shadow: 0 0 0 2px var(--pl-accent-soft); background-color: var(--pl-surface2); color: var(--pl-ink); }
  .field::placeholder { color: var(--pl-muted); opacity: 1; }
  .field:-webkit-autofill, .field:-webkit-autofill:focus { -webkit-box-shadow: 0 0 0 40px var(--pl-surface2) inset; -webkit-text-fill-color: var(--pl-ink); }
  select.field { padding-right: 34px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%238A9A95' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; }
  input[type="date"].field, input[type="month"].field { -webkit-appearance: auto; appearance: auto; min-height: 42px; }
  .field.auto { width: auto; display: inline-block; }
  select.field option { background: var(--pl-surface); color: var(--pl-ink); }
  .tab { padding: 7px 14px; border-radius: 999px; border: 1px solid var(--pl-line); background: var(--pl-surface); color: var(--pl-muted); font-weight: 600; cursor: pointer; }
  .tab[aria-selected="true"] { background: var(--pl-ink); color: var(--pl-bg); border-color: var(--pl-ink); }
  .tab.sm { padding: 2px 10px; font-size: 12px; }
  .pill { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 700; line-height: 1.5; }
  .pill-good { background: var(--pl-good-soft); color: var(--pl-good); }
  .pill-bad { background: var(--pl-bad-soft); color: var(--pl-bad); }
  .pill-warn { background: var(--pl-warn-soft); color: var(--pl-warn); }
  .pill-acc { background: var(--pl-accent-soft); color: var(--pl-accent-text); }
  .pos { color: var(--pl-good); } .neg { color: var(--pl-bad); }
  .err { color: var(--pl-bad); margin-top: 12px !important; }
  .note { font-size: 12px; color: var(--pl-muted); }

  .tablewrap { overflow-x: auto; }
  table { border-collapse: collapse; width: 100%; color: var(--pl-ink); }
  th { text-align: left; font-weight: 600; }
  th, td { padding: 10px 14px; vertical-align: middle; }
  tbody tr { border-top: 1px solid var(--pl-line); }
  tbody tr:hover { background: var(--pl-surface2); }
  .r { text-align: right; }
  .actions-cell { position: sticky; right: 0; background: var(--pl-surface); padding-inline: 10px; text-align: right; white-space: nowrap; }
  tbody tr:hover .actions-cell { background: var(--pl-surface2); }
  .show-sm { display: none; }
  @media (max-width: 520px) {
    .show-sm { display: block; }
    th, td { padding: 10px 6px; }
    th:first-child, td:first-child { padding-left: 12px; }
    .actions-cell { padding-inline: 6px 10px; }
    .hide-sm { display: none; }
    .btn-sm { padding: 4px 8px; }
  }
  .sortbtn { display: inline-flex; align-items: center; gap: 4px; background: none; border: 0; padding: 0; color: inherit; letter-spacing: inherit; text-transform: inherit; font-weight: inherit; cursor: pointer; }
  .sortbtn:hover { color: var(--pl-ink); }
  .chk { width: 24px; height: 24px; padding: 0; border-radius: 7px; border: 1.5px solid var(--pl-muted); background: transparent; color: var(--pl-accent-ink); display: inline-flex; align-items: center; justify-content: center; cursor: pointer; }
  .chk[aria-pressed="true"] { background: var(--pl-accent); border-color: var(--pl-accent); }
  .viewtabs { display: flex; flex-wrap: wrap; border-bottom: 1px solid var(--pl-line); margin-bottom: 16px; }
  .view-tab { padding: 8px 2px; margin-right: 20px; border: 0; border-bottom: 2px solid transparent; background: none; color: var(--pl-muted); font-weight: 700; cursor: pointer; }
  .view-tab[aria-selected="true"] { color: var(--pl-ink); border-bottom-color: var(--pl-accent); }
  .track { height: 12px; border-radius: 999px; background: var(--pl-surface2); border: 1px solid var(--pl-line); overflow: hidden; }
  .track > span { display: block; height: 100%; background: var(--pl-accent); border-radius: 999px; transition: width .3s; }
  .overlay { position: fixed; inset: 0; background: rgba(6,14,12,.6); display: flex; align-items: flex-start; justify-content: center; padding: 16px; padding-top: max(16px, env(safe-area-inset-top, 0px)); overflow-y: auto; z-index: 50; }
  .modal { width: 100%; max-width: 460px; margin-block: 5vh; padding: 20px; }
  .boot { padding: 40px 0; color: var(--pl-muted); }
  .chart text { font-family: var(--pl-font); }
  @media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
  .viewtabs { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
  .viewtabs::-webkit-scrollbar { display: none; }
  .view-tab { white-space: nowrap; flex: none; }
  .track.warn > span { background: var(--pl-warn); }
  .track.over > span { background: var(--pl-bad); }
  .track.plain > span { background: var(--pl-muted); opacity: .6; }
  .btn:disabled { opacity: .5; cursor: not-allowed; }
  @media (min-width: 768px) { .md-cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
  .modal .col-span-2 { grid-column: 1 / -1; }
  .big { font-size: clamp(18px, 5vw, 28px); white-space: nowrap; }
  .show-cell { display: none; }
  @media (max-width: 520px) { .show-cell { display: table-cell; } }
  /* keypad number fields */
  .numdisplay { display: flex; align-items: center; justify-content: flex-start; text-align: left; cursor: pointer; min-height: 42px; gap: 2px; }
  .numdisplay.active { border-color: var(--pl-accent); box-shadow: 0 0 0 2px var(--pl-accent-soft); }
  .numdisplay .numval { color: var(--pl-ink); font-weight: 600; }
  .ph { color: var(--pl-muted); font-weight: 400; }
  .caret { display: inline-block; width: 2px; height: 20px; background: var(--pl-accent); animation: pl-blink 1s steps(1) infinite; }
  @keyframes pl-blink { 50% { opacity: 0; } }
  .keypad { position: fixed; left: 0; right: 0; bottom: 0; z-index: 80; background: var(--pl-surface); color: var(--pl-ink); border-top: 1px solid var(--pl-line); box-shadow: 0 -8px 24px rgba(0,0,0,.25); padding: 10px 12px; padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px)); }
  .kp-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; max-width: 520px; margin: 0 auto 8px; }
  .kp-title { font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--pl-muted); }
  .kp-val { font-size: 24px; font-weight: 800; color: var(--pl-ink); }
  .kp-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; max-width: 520px; margin: 0 auto; }
  .kp-row { display: flex; gap: 8px; max-width: 520px; margin: 8px auto 0; }
  .kp-key { height: 48px; border-radius: 12px; border: 1px solid var(--pl-line); background: var(--pl-surface2); color: var(--pl-ink); font-size: 22px; font-weight: 700; display: flex; align-items: center; justify-content: center; cursor: pointer; -webkit-tap-highlight-color: transparent; }
  .kp-key:active { background: var(--pl-accent-soft); }
  .kp-small { flex: 1; font-size: 15px; height: 44px; }
  .kp-done { flex: 1.4; height: 44px; font-size: 16px; background: var(--pl-accent); border-color: var(--pl-accent); color: var(--pl-accent-ink); }
  body.kp-open .overlay { padding-bottom: 360px; }
  body.kp-open .app { padding-bottom: 340px; }
  /* live echo under text fields */
  .echo { margin-top: 6px; padding: 6px 10px; border-radius: 8px; background: var(--pl-accent-soft); color: var(--pl-ink); font-size: 15px; line-height: 1.4; overflow-wrap: anywhere; }
  .echo b { color: var(--pl-ink); font-weight: 700; }
  input.field { transform: translateZ(0); }

  /* phones: tables become stacked rows */
  @media (max-width: 560px) {
    .tablewrap:not(.keep-table) thead { display: none; }
    .tablewrap:not(.keep-table) table, .tablewrap:not(.keep-table) tbody { display: block; }
    .tablewrap:not(.keep-table) tr { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; padding: 12px 14px; }
    .tablewrap:not(.keep-table) td { display: block; padding: 0; flex: none; }
    .tablewrap:not(.keep-table) td:first-child { padding-left: 0; }
    .tablewrap:not(.keep-table) td.main { flex: 1 1 50%; min-width: 0; }
    .tablewrap:not(.keep-table) td[colspan] { flex: 1 1 100%; }
    .tablewrap:not(.keep-table) td.r { margin-left: auto; text-align: right; }
    .tablewrap:not(.keep-table) td.hide-sm { display: none; }
    .tablewrap:not(.keep-table) td.actions-cell { position: static; flex: 1 1 100%; display: flex; justify-content: flex-end; background: transparent; padding: 8px 0 0; border-top: 1px dashed var(--pl-line); }
    .tablewrap:not(.keep-table) tbody tr:hover .actions-cell { background: transparent; }
    .tablewrap:not(.keep-table) .btn-sm { padding: 6px 12px; }
    .modal { padding: 16px; margin-block: 2vh; }
    .app h1 { font-size: 22px !important; }
    .icon-btn { padding: 9px; }
  }
  /* login + PIN screens */
  .gate { min-height: 80vh; display: flex; align-items: center; justify-content: center; padding-block: 24px; }
  .gate-card { width: 100%; max-width: 380px; padding: 24px; }
  .pin-dots { display: flex; justify-content: center; gap: 14px; margin: 22px 0 8px; }
  .pin-dots span { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--pl-muted); }
  .pin-dots span.on { background: var(--pl-accent); border-color: var(--pl-accent); }
  .gate .kp-grid { max-width: none; }
  .kp-done:disabled { opacity: .45; }

  /* summary table: aligned grid, scrolls sideways on phones with the month column pinned */
  .keep-table { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .grid-table { min-width: 600px; border-collapse: separate; border-spacing: 0; }
  .grid-table th, .grid-table td { padding: 12px 16px; white-space: nowrap; border-top: 1px solid var(--pl-line); }
  .grid-table thead th { border-top: 0; background: var(--pl-surface); }
  .grid-table tbody tr { border-top: 0; }
  .grid-table th:first-child, .grid-table td.mcol { position: sticky; left: 0; z-index: 1; background: var(--pl-surface); box-shadow: 1px 0 0 var(--pl-line); text-align: left; }
  .grid-table td.mcol { font-weight: 700; }
  .grid-table tr.current td { background: var(--pl-surface2); }
  .grid-table tr.current td.mcol { box-shadow: inset 3px 0 0 var(--pl-accent), 1px 0 0 var(--pl-line); }
  .grid-table tfoot td { background: var(--pl-surface2); font-weight: 700; border-top: 2px solid var(--pl-line); }
  .grid-table tfoot td.mcol { background: var(--pl-surface2); }
  .grid-table .strong { font-weight: 800; }
  .grid-table tbody tr:hover { background: transparent; }
  /* bottom buttons: equal width, aligned */
  .footer-actions { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; border-top: 1px solid var(--pl-line); padding-top: 14px; }
  .footer-actions > .btn, .footer-actions > span > .btn { justify-content: center; }
  .footer-actions > .btn { width: 100%; padding: 10px 8px; white-space: normal; text-align: center; line-height: 1.2; font-size: 13px; }
  .footer-actions > span { grid-column: 1 / -1; }

  /* tap a row to edit it */
  .tap-row { cursor: pointer; -webkit-tap-highlight-color: transparent; }
  .tap-row:active { background: var(--pl-surface2); }
  @media (max-width: 560px) {
    .tablewrap:not(.keep-table) tr { flex-wrap: nowrap; gap: 10px; }
    .tablewrap:not(.keep-table) td.main { flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; }
    .tablewrap:not(.keep-table) td.r { flex: none; white-space: nowrap; }
    .tablewrap:not(.keep-table) td.actions-cell { flex: none; border-top: 0; padding: 0; margin-left: 0; display: flex; }
    .tablewrap:not(.keep-table) td.r { margin-left: auto; }
    .tablewrap:not(.keep-table) td.r + td.actions-cell, .tablewrap:not(.keep-table) td.actions-cell { margin-right: -6px; }
  }
  /* one-tap date picker */
  .dp-overlay { position: fixed; inset: 0; z-index: 90; background: rgba(6,14,12,.55); display: flex; align-items: center; justify-content: center; padding: 16px; }
  .dp { width: 100%; max-width: 360px; padding: 16px; }
  .dp-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; text-align: center; }
  .dp-head span { font-size: 12px; font-weight: 700; color: var(--pl-muted); padding: 4px 0; }
  .dp-day { height: 42px; border-radius: 999px; border: 0; background: transparent; color: var(--pl-ink); font-size: 16px; font-weight: 600; cursor: pointer; }
  .dp-day:hover { background: var(--pl-surface2); }
  .dp-day.today { box-shadow: inset 0 0 0 1.5px var(--pl-accent); }
  .dp-day.sel { background: var(--pl-accent); color: var(--pl-accent-ink); }
  .sugg { border: 0; cursor: pointer; font-size: 13px; padding: 6px 12px; }
