  :root {
    color-scheme: light;
    --bg: #ffffff; --bg2: #ffffff; --bg3: #f1f4f9; --surface: #ffffff; --border: #cfd6e4;
    --text: #0b1220; --text2: #38425a; --text3: #5f6b85;
    --accent: #1d4ed8; --accent-bg: #e6efff;
    --shadow: 0 2px 12px rgba(0,0,0,0.08); --shadow2: 0 4px 24px rgba(0,0,0,0.12);
    --radius: 12px; --radius2: 8px;
  }
  [data-theme="dark"] {
    color-scheme: dark;
    --bg: #1b2030; --bg2: #232a3d; --bg3: #181d2b; --surface: #2a3248; --border: #3b4666;
    --text: #f5f7ff; --text2: #c3cae0; --text3: #8f99b8;
    --accent: #7db4ff; --accent-bg: #22304f;
    --shadow: 0 2px 12px rgba(0,0,0,0.5); --shadow2: 0 4px 24px rgba(0,0,0,0.6);
  }
  * { box-sizing: border-box; margin: 0; padding: 0; }
  body { font-family: -apple-system, 'Noto Sans KR', sans-serif; background: var(--bg); color: var(--text); min-height: 100vh; -webkit-tap-highlight-color: transparent; }
  button { font-family: inherit; }

  /* 헤더·탭: sticky. 위치는 syncStickyOffsets()가 높이를 측정해 --hdr-h, --tab-h에 넣는다(고정 숫자 금지). */
  .app-header { background: var(--bg2); border-bottom: 1px solid var(--border); padding: 8px 16px; display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; z-index: 100; box-shadow: var(--shadow); }
  .app-title { font-size: 15px; font-weight: 700; color: var(--accent); }
  .hdr-version { margin-left: 6px; font-size: 10px; font-weight: 500; color: var(--text3); }
  .header-actions { display: flex; gap: 8px; }
  .icon-btn { background: var(--bg3); border: 1px solid var(--border); color: var(--text2); width: 30px; height: 30px; border-radius: 6px; cursor: pointer; font-size: 16px; display: flex; align-items: center; justify-content: center; }
  .tab-bar { display: flex; background: var(--bg2); border-bottom: 1px solid var(--border); position: sticky; top: calc(var(--hdr-h, 49px) - 1px); z-index: 90; }
  .tab-btn { flex: 1; padding: 8px 2px; border: none; background: transparent; color: var(--text3); font-size: 12px; font-weight: 600; cursor: pointer; border-bottom: 2px solid transparent; }
  .tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); background: var(--accent-bg); }
  .tab-panel { display: none; }
  .tab-panel.active { display: block; }

  .main { max-width: 720px; margin: 0 auto; padding: 8px 12px 40px; }
  .card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 8px; box-shadow: var(--shadow); }
  .card-title { font-size: 11px; font-weight: 700; color: var(--text2); margin-bottom: 8px; }
  .btn { padding: 10px 14px; border-radius: var(--radius2); border: 1px solid var(--border); background: var(--bg); color: var(--text); font-size: 14px; cursor: pointer; }
  .btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
  .btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
  textarea, input[type=text] { width: 100%; padding: 10px; border: 1px solid var(--border); border-radius: var(--radius2); background: var(--bg); color: var(--text); font-size: 16px; font-family: inherit; }
  .table-outer { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .table-outer table { width: max-content; border-collapse: collapse; font-size: 13px; }
  .table-outer th, .table-outer td { padding: 6px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }

  /* 팝업. 열면 pushNav로 기록에 쌓아 뒤로 가기가 팝업만 닫게 한다. */
  .modal-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 200; align-items: center; justify-content: center; padding: 20px; }
  .modal-overlay.open { display: flex; }
  .modal { background: var(--surface); border-radius: var(--radius); padding: 24px; width: 100%; max-width: 360px; box-shadow: var(--shadow2); }
  .modal h3 { font-size: 16px; font-weight: 700; margin-bottom: 16px; }

  .update-bar { position: fixed; left: 12px; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom, 0px)); z-index: 1000; display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 12px; border-radius: 10px; background: var(--accent); color: #fff; font-size: 13px; box-shadow: 0 4px 14px rgba(0,0,0,0.25); }
  .update-bar[hidden] { display: none; }
  .update-bar button { padding: 5px 12px; border: 1px solid rgba(255,255,255,0.8); border-radius: 6px; background: transparent; color: #fff; font-size: 12px; font-weight: 600; cursor: pointer; }

  /* ===== 복리 7:3 ===== */
  :root { --holiday: #fee2e2; --holiday-text: #b91c1c; --today-bg: #fde047; --c7: #3b82f6; --c3: #94a3b8; --c-act: #f59e0b; --pos: #16a34a; --neg: #dc2626; }
  [data-theme="dark"] { --holiday: #3d1f1f; --holiday-text: #f87171; --today-bg: #b45309; --c7: #60a5fa; --c3: #64748b; --c-act: #fbbf24; --pos: #4ade80; --neg: #f87171; }
  [hidden] { display: none !important; }
  .muted { color: var(--text3); font-size: 12px; }
  .pos { color: var(--pos); } .neg { color: var(--neg); }
  .field { margin-bottom: 10px; }
  .field label { display: block; font-size: 12px; font-weight: 600; color: var(--text2); margin-bottom: 4px; }
  .field .hint { font-size: 11px; color: var(--text3); margin-top: 3px; }
  input[type=text], input[type=date] { width: 100%; padding: 10px; border: 1px solid var(--border); border-radius: var(--radius2); background: var(--bg); color: var(--text); font-size: 16px; font-family: inherit; }
  .two { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  .seg { display: flex; gap: 6px; } .seg .btn { flex: 1; padding: 8px 4px; }
  .btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }
  .btn.small { padding: 6px 10px; font-size: 12px; }
  .check-row { display: flex; gap: 14px; flex-wrap: wrap; font-size: 13px; color: var(--text2); }
  .check-row label { display: flex; align-items: center; gap: 5px; }
  .preview { font-size: 12px; color: var(--text2); background: var(--accent-bg); border-radius: var(--radius2); padding: 8px 10px; margin: 8px 0; line-height: 1.6; }
  .notice { font-size: 11px; color: var(--text3); line-height: 1.5; margin: 6px 2px 10px; }
  .kv { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; padding: 3px 0; }
  .kv span { color: var(--text2); flex-shrink: 0; } .kv b { font-weight: 600; text-align: right; word-break: keep-all; }
  .hist .hist-main { display: flex; justify-content: space-between; gap: 8px; font-size: 14px; }
  .hist .hist-sub { font-size: 12px; color: var(--text2); margin: 4px 0 8px; line-height: 1.5; }
  .hist.current { border-color: var(--accent); }
  .file-msg { font-size: 12px; margin-top: 10px; color: var(--text2); word-break: break-all; } .file-msg.err { color: var(--neg); }

  /* ===== 앱 잠금 ===== */
  html.locked body > *:not(#lockScreen) { visibility: hidden; }
  .lock-screen { display: none; position: fixed; inset: 0; z-index: 5000; background: var(--bg); flex-direction: column; align-items: center; justify-content: center; padding: 20px; padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px)); overflow-y: auto; }
  .lock-screen.open { display: flex; }
  .lock-title { font-size: 18px; font-weight: 700; color: var(--text); margin-bottom: 6px; text-align: center; }
  .lock-msg { min-height: 36px; font-size: 13px; color: var(--text2); text-align: center; margin-bottom: 10px; max-width: 300px; }
  .lock-msg.err { color: var(--neg); font-weight: 600; }
  .pin-dots { display: flex; gap: 12px; margin: 8px 0 18px; }
  .pin-dots i { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--accent); }
  .pin-dots i.on { background: var(--accent); }
  .keypad { display: grid; grid-template-columns: repeat(3, 72px); gap: 12px; }
  .keypad button { height: 60px; border-radius: 50%; border: 1px solid var(--border); background: var(--bg3); color: var(--text); font-size: 22px; font-weight: 600; cursor: pointer; }
  .keypad button:active { background: var(--accent-bg); }
  .keypad button:disabled { opacity: 0.4; }
  .keypad .ghost { border-color: transparent; background: transparent; font-size: 16px; }
  .lock-links { margin-top: 18px; display: flex; gap: 16px; font-size: 13px; }
  .lock-links button { background: none; border: none; color: var(--accent); cursor: pointer; text-decoration: underline; padding: 6px; }
  .lock-links .danger { color: var(--neg); }
  .two > * { min-width: 0; }
  input[type=date] { min-width: 0; max-width: 100%; -webkit-appearance: none; appearance: none; min-height: 44px; }
  .date-pick { display: grid; grid-template-columns: 1.4fr 1fr 1fr; gap: 6px; }
  .date-pick select { width: 100%; min-width: 0; min-height: 44px; padding: 8px 6px; border: 1px solid var(--border); border-radius: var(--radius2); background: var(--bg); color: var(--text); font-size: 16px; font-family: inherit; }
  .preview .pv-main { font-size: 14px; font-weight: 700; color: var(--accent); }
  .preview .pv-warn { color: var(--neg); margin-top: 4px; }
  /* ===== 탭 5개 ===== */
  .tab-btn { padding: 8px 0; font-size: 11px; white-space: nowrap; }
  /* ===== 일기 ===== */
  .diary-nav { display: grid; grid-template-columns: 44px 1.3fr 1fr 44px; gap: 6px; align-items: center; margin-bottom: 8px; }
  .diary-nav select { width: 100%; min-width: 0; min-height: 44px; padding: 8px 6px; border: 1px solid var(--border); border-radius: var(--radius2); background: var(--bg); color: var(--text); font-size: 15px; font-family: inherit; }
  .diary-sub { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; color: var(--text2); margin-bottom: 6px; flex-wrap: wrap; }
  .diary-info { font-size: 12px; color: var(--text2); background: var(--accent-bg); border-radius: var(--radius2); padding: 6px 8px; margin-bottom: 8px; }
  .diary-text { min-height: 140px; resize: vertical; }
  .diary-photo-bar { display: flex; align-items: center; gap: 10px; margin: 8px 0; }
  .diary-add { cursor: pointer; }
  .diary-thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; }
  .thumb-wrap { position: relative; }
  .thumb { display: block; width: 100%; aspect-ratio: 1; padding: 0; border: 1px solid var(--border); border-radius: var(--radius2); overflow: hidden; background: var(--bg3); cursor: pointer; }
  .thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
  .thumb-del { position: absolute; top: 3px; right: 3px; width: 26px; height: 26px; border-radius: 50%; border: none; background: rgba(0,0,0,0.6); color: #fff; font-size: 13px; cursor: pointer; }
  .modal-overlay.viewer { background: rgba(0,0,0,0.92); z-index: 300; }
  .viewer-box { width: 100%; max-width: 720px; display: flex; flex-direction: column; gap: 12px; align-items: center; }
  .viewer-box img { max-width: 100%; max-height: 72vh; object-fit: contain; border-radius: var(--radius2); }
  /* ===== 캘린더 ===== */
  .m-row { display: grid; grid-template-columns: 62px 1fr auto auto 30px; gap: 6px; align-items: center; padding: 7px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
  .m-date { color: var(--text2); font-size: 12px; } .m-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .chip { min-height: 30px; padding: 2px 8px; font-size: 11px; border-radius: 6px; border: 1px solid var(--border); background: var(--bg3); color: var(--text2); cursor: pointer; font-family: inherit; }
  .chip.once { background: #8b5cf6; color: #fff; border-color: #8b5cf6; } .chip.subst { background: #f59e0b; color: #fff; border-color: #f59e0b; } .chip.del { color: var(--neg); font-size: 16px; padding: 0; width: 30px; }
  .two-sel { grid-template-columns: 1fr 1fr; }
  .y-row { display: grid; grid-template-columns: 92px 1fr auto; gap: 6px; padding: 7px 4px; border-bottom: 1px solid var(--border); font-size: 13px; align-items: center; }
  .y-row.sub { background: rgba(245,158,11,0.08); } .y-date.wk { color: #f97316; } .y-src { font-size: 11px; color: var(--text3); }
  .unit-note { display: flex; justify-content: space-between; font-size: 11px; color: var(--text3); margin: 2px 2px 6px; }

  /* ===== 결과 표(기존 앱 방식) ===== */
  .table-outer { height: calc(100vh - var(--hdr-h, 49px) - var(--tab-h, 38px) - 24px); height: calc(100dvh - var(--hdr-h, 49px) - var(--tab-h, 38px) - 24px); min-height: 280px; overflow: auto; border: 1px solid var(--border); border-radius: var(--radius2); -webkit-overflow-scrolling: touch; background: var(--bg); }
  #resTable { table-layout: fixed; border-collapse: collapse; font-size: 11px; width: max-content; min-width: 100%; }
  #resTable col.c-seq { width: 26px; } #resTable col.c-date { width: 38px; } #resTable col.c-dow { width: 20px; } #resTable col.c-note { width: 32px; }
  #resTable col.c-amt { width: 52px; } #resTable col.c-act { width: 56px; } #resTable col.c-daily { width: 60px; } #resTable col.c-cum { width: 44px; }
  #resTable thead th { position: sticky; top: 0; z-index: 10; background: var(--bg3); padding: 8px 2px; text-align: center; font-size: 10px; font-weight: 600; color: var(--text3); border-bottom: 1px solid var(--border); white-space: nowrap; }
  #resTable tbody td { padding: 6px 2px; text-align: center; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; border-bottom: 1px solid var(--border); }
  #resTable td.amount, #resTable td.amount3 { font-family: ui-monospace, 'JetBrains Mono', monospace; font-weight: 600; text-align: right; padding-right: 4px; font-size: 11px; }
  #resTable td.amount { color: var(--pos); } #resTable td.amount3 { color: var(--text2); }
  #resTable td.date-cell { color: var(--text2); } #resTable td.seq { color: var(--text3); }
  #resTable td.holiday-name { font-size: 9px; color: var(--text3); }
  #resTable td.daily-cell, #resTable td.cum-cell { font-size: 11px; font-family: ui-monospace, 'JetBrains Mono', monospace; }
  #resTable .act-input { width: 100%; min-width: 0; box-sizing: border-box; padding: 3px 4px; border: 1px solid var(--border); border-radius: 4px; background: var(--bg3); color: var(--text); font-size: 13px; font-family: ui-monospace, 'JetBrains Mono', monospace; text-align: right; }
  .ach-ok { color: var(--pos); font-weight: 600; } .ach-ng { color: var(--neg); font-weight: 600; }
  tr.holiday-row { opacity: 0.55; background: var(--holiday); } tr.holiday-row td { color: var(--holiday-text) !important; }
  tr.weekend td.date-cell { color: #f97316; }
  #resTable .sticky-1, #resTable .sticky-2 { position: sticky; background: var(--bg); }
  #resTable td.sticky-1, #resTable th.sticky-1 { left: 0; padding-left: 2px; padding-right: 2px; }
  #resTable td.sticky-2, #resTable th.sticky-2 { left: 26px; box-shadow: 1px 0 0 var(--border); }
  #resTable td.sticky-1, #resTable td.sticky-2 { z-index: 5; }
  #resTable th.sticky-1, #resTable th.sticky-2 { z-index: 12; background: var(--bg3); }
  tr.holiday-row td.sticky-1, tr.holiday-row td.sticky-2 { background: var(--holiday); }
  #resTable tr.expandable { cursor: pointer; } #resTable tr.expandable.open td { border-bottom-color: transparent; }
  #resTable tbody td.sticky-2 { position: sticky; }
  tbody tr.today-row td { background: var(--today-bg); color: var(--text); font-weight: 700; }
  tbody tr.today-row td.sticky-1, tbody tr.today-row td.sticky-2 { background: var(--today-bg); }
  tbody tr.today-row .act-input { font-weight: 700; background: var(--bg); }
  .sum-details > summary { cursor: pointer; font-size: 12px; font-weight: 700; color: var(--text2); } .sum-details[open] > summary { margin-bottom: 8px; }
  #resTable tr.detail-row td { padding: 0; text-align: left; background: var(--bg); white-space: normal; overflow: visible; border-bottom: 2px solid var(--border); }
  .rd { padding: 6px 10px 10px; background: var(--accent-bg); }
  .rd .kv { font-size: 12px; } .rd .det-title { font-size: 11px; font-weight: 700; color: var(--text2); margin: 8px 0 4px; }
  .rd .det-in { display: grid; grid-template-columns: 60px 1fr; gap: 8px; align-items: center; font-size: 12px; color: var(--text2); }
  .rd .det-in .act-input { padding: 8px; font-size: 14px; }
  #resTable td.has-memo::after { content: '📝'; position: absolute; right: 1px; top: 1px; font-size: 8px; line-height: 1; }
  .rd [data-role="res"] { margin-top: 6px; border-top: 1px dashed var(--border); padding-top: 4px; }
