/* ====== ROOT ====== */
:root {
  --bg: #f5f6f8;
  --bg-pri: #ffffff;
  --bg-sec: #f1f3f6;
  --bg-ter: #e9ecef;
  --text: #1a1a1a;
  --text-sec: #6c757d;
  --text-ter: #adb5bd;
  --bd: #e0e3e7;
  --bd-sec: #dee2e6;
  --primary: #0f3a8a;
  --primary-dk: #173d85;
  --accent: #f4a623;
  --pos: #10894e;
  --neg: #d63838;
  --warn-tx: #b8761c;
  --warn-bg: #fef4dd;
  --warn-bd: #f4d896;
  --info-tx: #0f3a8a;
  --info-bg: #e6efff;
  --info-bd: #b3cdff;
  --pos-bg: #d9f5e5;
  --neg-bg: #fce0e0;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15171a;
    --bg-pri: #1c1f23;
    --bg-sec: #25282d;
    --bg-ter: #2d3137;
    --text: #e8eaed;
    --text-sec: #9aa0a6;
    --text-ter: #5f6368;
    --bd: #2d3137;
    --bd-sec: #3a3e45;
    --warn-bg: #3a2e10;
    --warn-bd: #5a4818;
    --info-bg: #1a2845;
    --info-bd: #2a4275;
    --pos-bg: #14352a;
    --neg-bg: #3a1818;
    --primary: #4a86e8;
    --primary-dk: #6ba0f5;
    --info-tx: #8ab4f8;
    --pos: #34d399;
    --neg: #f87171;
    --warn-tx: #fbbf24;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; overflow: hidden; -webkit-tap-highlight-color: transparent; }
body { font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif; background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.4; }

input, select, textarea, button { font-family: inherit; font-size: 13px; color: var(--text); }
input, select, textarea { padding: 8px 10px; border: 0.5px solid var(--bd); border-radius: 6px; background: var(--bg-pri); width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; border-color: var(--primary); }
textarea { resize: vertical; min-height: 60px; }

/* ====== LOGIN SCREEN ====== */
.login-screen { min-height: 100vh; min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 20px; background: linear-gradient(135deg, #0f3a8a 0%, #1e4ea8 100%); overflow-y: auto; }
.login-card { background: var(--bg-pri); border-radius: 14px; padding: 32px; max-width: 400px; width: 100%; box-shadow: 0 10px 40px rgba(0,0,0,0.15); }
.login-brand { display: flex; align-items: center; gap: 14px; margin-bottom: 24px; }
.login-mark { width: 56px; height: 56px; border-radius: 10px; object-fit: contain; background: #fff; padding: 4px; flex-shrink: 0; }
.login-brand h1 { font-size: 17px; font-weight: 600; margin: 0 0 4px; }
.login-brand p { font-size: 10px; color: var(--text-sec); margin: 0; letter-spacing: 1px; text-transform: uppercase; }
.login-brand p b { color: var(--primary); font-weight: 700; }
.login-brand p span { color: var(--accent); font-weight: 700; }
.login-form .fg { margin-bottom: 14px; }
.login-form label { display: block; font-size: 12px; color: var(--text-sec); margin-bottom: 5px; }
.login-form input { padding: 10px 12px; font-size: 14px; }
.login-form .bp { width: 100%; padding: 11px; font-size: 14px; justify-content: center; margin-top: 6px; }
.login-error { color: var(--neg); font-size: 12px; margin-top: 10px; min-height: 16px; }
.login-foot { text-align: center; font-size: 10px; color: var(--text-ter); margin-top: 18px; letter-spacing: 1px; text-transform: uppercase; }

/* ====== APP SHELL ====== */
.app-screen { min-height: 100vh; display: flex; flex-direction: column; align-items: center; padding: 0; background: var(--bg); }
/* ====== APP SHELL — fixed viewport with scrolling body ====== */
.app-screen { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; align-items: stretch; padding: 0; background: var(--bg); }

.gbm { display: flex; flex-direction: column; background: var(--bg-ter); border-radius: 0; border: none; overflow: hidden; height: 100vh; height: 100dvh; max-width: 100%; width: 100%; margin: 0 auto; position: relative; }

@media (min-width: 640px) {
  .app-screen { padding: 16px; align-items: center; }
  .gbm { height: calc(100vh - 32px); height: calc(100dvh - 32px); max-width: 720px; border-radius: 16px; border: 0.5px solid var(--bd); box-shadow: 0 4px 20px rgba(0,0,0,0.08); }
}

@media (min-width: 1024px) {
  .gbm { max-width: 920px; }
}

.gbm-head { background: linear-gradient(135deg, #0f3a8a 0%, #1e4ea8 100%); padding: 10px 14px; display: flex; align-items: center; justify-content: space-between; gap: 8px; color: #fff; padding-top: max(10px, env(safe-area-inset-top)); flex-shrink: 0; }
.gbm-brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.gbm-mark { width: 36px; height: 36px; border-radius: 8px; background: #fff; display: flex; align-items: center; justify-content: center; flex-shrink: 0; padding: 3px; }
.gbm-mark img { width: 100%; height: 100%; object-fit: contain; }
.gbm-title { min-width: 0; }
.gbm-title h1 { font-size: 13px; font-weight: 600; margin: 0; white-space: nowrap; letter-spacing: 0.3px; }
.gbm-title .sub { font-size: 9px; color: rgba(255,255,255,0.75); letter-spacing: 0.5px; text-transform: uppercase; }
.gbm-title .sub b { color: var(--accent); font-weight: 600; }
.head-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.biz { font-size: 11px; color: rgba(255,255,255,0.85); max-width: 110px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn { background: rgba(255,255,255,0.1); border: none; color: #fff; width: 32px; height: 32px; border-radius: 6px; cursor: pointer; display: flex; align-items: center; justify-content: center; }
.icon-btn:hover { background: rgba(255,255,255,0.2); }
.icon-btn i { font-size: 16px; }

/* Body is the ONLY scrolling region. Header and tabs stay pinned. */
.gbm-body { flex: 1 1 auto; min-height: 0; padding: 14px; padding-bottom: 40px; overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch; }
.loading-state { text-align: center; padding: 60px 20px; color: var(--text-sec); }
.spinner { width: 32px; height: 32px; border: 3px solid var(--bd); border-top-color: var(--primary); border-radius: 50%; animation: spin 0.8s linear infinite; margin: 0 auto 14px; }
@keyframes spin { to { transform: rotate(360deg); } }

.gbm-tabs { display: flex; background: var(--bg-pri); border-top: 0.5px solid var(--bd); padding: 6px 2px; gap: 1px; padding-bottom: max(6px, env(safe-area-inset-bottom)); flex-shrink: 0; }
.tb { flex: 1; background: transparent; border: none; padding: 7px 1px; display: flex; flex-direction: column; align-items: center; gap: 2px; cursor: pointer; border-radius: 8px; color: var(--text-sec); font-size: 10px; min-width: 0; }
.tb:hover { background: var(--bg-sec); }
.tb.on { color: var(--primary); background: var(--info-bg); }
.tb i { font-size: 17px; }
.tb span { overflow: hidden; text-overflow: ellipsis; max-width: 100%; }

.gbm-foot { padding: 6px 14px; background: var(--bg-pri); border-top: 0.5px solid var(--bd); font-size: 9px; color: var(--text-ter); text-align: center; letter-spacing: 0.5px; text-transform: uppercase; display: flex; align-items: center; justify-content: center; gap: 6px; flex-shrink: 0; }
.gbm-foot b { color: var(--primary); font-weight: 600; }
.gbm-foot span { color: var(--accent); font-weight: 600; }

/* ====== COMPONENTS ====== */
.vt { font-size: 18px; font-weight: 500; margin: 0 0 14px; }
.mgrid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-bottom: 16px; }
.m { background: var(--bg-sec); border-radius: 8px; padding: 12px; }
.m .l { font-size: 11px; color: var(--text-sec); margin-bottom: 4px; }
.m .v { font-size: 17px; font-weight: 500; }
.m .v.pos { color: var(--pos); }
.m .v.neg { color: var(--neg); }
.m .v.warn { color: var(--warn-tx); }

.card { background: var(--bg-pri); border: 0.5px solid var(--bd); border-radius: 8px; padding: 11px 12px; margin-bottom: 8px; cursor: pointer; }
.card:hover { border-color: var(--bd-sec); }
.card .r1 { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.card .r2 { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 4px; font-size: 12px; color: var(--text-sec); }
.card .ttl { font-size: 14px; font-weight: 500; }
.card .amt { font-size: 14px; font-weight: 500; }

.secH { display: flex; align-items: center; justify-content: space-between; margin: 14px 0 10px; }
.secH h3 { font-size: 12px; font-weight: 500; margin: 0; color: var(--text-sec); text-transform: uppercase; letter-spacing: 0.5px; }

.bp { background: var(--primary); color: white; border: none; padding: 9px 13px; border-radius: 8px; font-size: 13px; cursor: pointer; font-weight: 500; display: inline-flex; align-items: center; gap: 6px; }
.bp:hover { background: var(--primary-dk); }
.bp:disabled { opacity: 0.6; cursor: not-allowed; }
.bl { background: var(--bg-pri); border: 0.5px solid var(--bd); color: var(--primary); cursor: pointer; font-size: 13px; padding: 6px 10px; border-radius: 6px; display: inline-flex; align-items: center; gap: 4px; }
.bl:hover { background: var(--bg-sec); }
.bl i { font-size: 16px; }
.bbk { display: inline-flex; align-items: center; gap: 4px; background: transparent; border: none; color: var(--text-sec); font-size: 13px; cursor: pointer; padding: 4px 0; margin-bottom: 10px; }

.fg { margin-bottom: 11px; }
.fg label { display: block; font-size: 12px; color: var(--text-sec); margin-bottom: 4px; }
.frow { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.frow3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }

.empty { text-align: center; padding: 32px 16px; color: var(--text-sec); font-size: 13px; }
.empty i { font-size: 32px; display: block; margin-bottom: 8px; color: var(--text-ter); }

.li { display: grid; grid-template-columns: 1fr 50px 80px 28px; gap: 6px; margin-bottom: 6px; align-items: center; }
.li input { font-size: 13px; padding: 6px 8px; }
.li button { background: transparent; border: none; color: var(--neg); cursor: pointer; font-size: 16px; padding: 0; }

/* ====== INVOICE / DOC RENDER ====== */
.inv { background: white; color: #1a1a1a; padding: 24px; border-radius: 8px; border: 0.5px solid var(--bd); font-size: 11px; font-family: system-ui, sans-serif; }
.inv * { color: #1a1a1a; border-color: #ddd; }
.inv h2 { margin: 0; font-size: 20px; letter-spacing: 1px; font-weight: 600; color: #0f3a8a; }
.inv table { width: 100%; border-collapse: collapse; margin: 10px 0; }
.inv th, .inv td { padding: 6px 4px; text-align: left; font-size: 11px; }
.inv th { border-bottom: 1px solid #0f3a8a; font-weight: 600; text-transform: uppercase; font-size: 10px; color: #0f3a8a; }
.inv tr.li-row td { border-bottom: 0.5px solid #eee; }
.inv .tot { margin-top: 8px; }
.inv .tot td { padding: 4px; }
.inv .tot .lab { text-align: right; color: #555; }
.inv .tot .val { text-align: right; width: 90px; }
.inv .tot tr:last-child { font-weight: 600; font-size: 13px; }
.inv .tot tr:last-child td { border-top: 1.5px solid #0f3a8a; padding-top: 8px; color: #0f3a8a; }
.inv-logo { max-width: 120px; max-height: 60px; object-fit: contain; }
.gdi-footer { margin-top: 22px; padding-top: 12px; border-top: 0.5px solid #e0e0e0; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.gdi-footer img { height: 28px; opacity: 0.85; }
.gdi-footer .pby { font-size: 8px; color: #999; text-transform: uppercase; letter-spacing: 1.5px; text-align: right; line-height: 1.4; }
.gdi-footer .pby b { color: #0f3a8a; font-weight: 600; }
.gdi-footer .pby span { color: #f4a623; font-weight: 600; }

/* ====== RECEIPTS ====== */
.rcpt { width: 100%; max-height: 260px; object-fit: contain; border-radius: 8px; background: var(--bg-sec); margin-bottom: 10px; display: block; }
.rcpt-pdf { display: flex; align-items: center; gap: 10px; padding: 16px; background: var(--bg-sec); border-radius: 8px; margin-bottom: 10px; }
.rcpt-pdf i { font-size: 32px; color: var(--neg); }

.cam { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; background: var(--info-bg); border: 1.5px dashed var(--info-bd); border-radius: 8px; padding: 20px; color: var(--info-tx); cursor: pointer; width: 100%; font-size: 13px; }
.cam i { font-size: 28px; }
.cam input { display: none; }
.upload-opts { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 10px; }
.upload-opts .cam { padding: 14px 8px; font-size: 12px; }
.upload-opts .cam i { font-size: 22px; }

/* ====== PILLS / STATUS ====== */
.pill { display: inline-flex; align-items: center; gap: 3px; padding: 2px 7px; border-radius: 10px; font-size: 10px; font-weight: 500; }
.p-s { background: var(--pos-bg); color: var(--pos); }
.p-w { background: var(--warn-bg); color: var(--warn-tx); }
.p-i { background: var(--info-bg); color: var(--info-tx); }
.p-d { background: var(--neg-bg); color: var(--neg); }
.p-g { background: var(--bg-sec); color: var(--text-sec); }

/* ====== CHARTS ====== */
.bars { display: flex; gap: 3px; align-items: flex-end; height: 130px; padding: 8px 0; border-bottom: 0.5px solid var(--bd); margin-bottom: 8px; }

/* Daily 30-day chart (denser than .bars) */
.daily-chart { display: flex; gap: 2px; align-items: flex-end; height: 110px; padding: 4px 0 6px; border-bottom: 0.5px solid var(--bd); overflow-x: auto; -webkit-overflow-scrolling: touch; }
.dcol { display: flex; flex-direction: column; align-items: center; gap: 3px; flex: 1 0 auto; min-width: 18px; }
.dgrp { display: flex; gap: 1px; align-items: flex-end; height: 100%; width: 100%; justify-content: center; }
.dbar { width: 6px; border-radius: 2px 2px 0 0; min-height: 2px; }
.dbar.empty { background: var(--bd); opacity: 0.3; height: 2px; min-height: 2px; }
.dlab { font-size: 8px; color: var(--text-ter); margin-top: 1px; }
.bcol { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 0; }
.bgrp { display: flex; gap: 2px; align-items: flex-end; height: 100%; width: 100%; justify-content: center; }
.bar { width: 9px; border-radius: 2px 2px 0 0; min-height: 1px; }
.b-in { background: var(--pos); }
.b-ex { background: var(--neg); }
.blab { font-size: 9px; color: var(--text-sec); }
.lgnd { display: flex; gap: 14px; font-size: 11px; color: var(--text-sec); justify-content: center; margin-bottom: 14px; }
.lgnd span { display: inline-flex; align-items: center; gap: 4px; }
.lgnd i { width: 8px; height: 8px; border-radius: 2px; display: inline-block; }

.tx-row { display: flex; justify-content: space-between; padding: 9px 0; border-bottom: 0.5px solid var(--bd); gap: 8px; }
.tx-row:last-child { border-bottom: none; }
.tx-row .lbl { font-size: 13px; }
.tx-row .dt { font-size: 12px; color: var(--text-sec); }
.tx-row .when { font-size: 11px; padding: 2px 8px; border-radius: 10px; background: var(--bg-sec); color: var(--text-sec); white-space: nowrap; }
.tx-row .when.soon { background: var(--warn-bg); color: var(--warn-tx); }

.toast { position: fixed; bottom: 80px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg-pri); padding: 8px 14px; border-radius: 8px; font-size: 13px; z-index: 100; opacity: 0; transition: opacity 0.2s; pointer-events: none; }
.toast.on { opacity: 1; }

.chk { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text); cursor: pointer; margin-bottom: 10px; }
.chk input { width: 16px; height: 16px; margin: 0; }

.act { display: flex; gap: 8px; margin-top: 14px; }
.act .bp { flex: 1; justify-content: center; }
.gh { font-size: 12px; color: var(--text-ter); margin-bottom: 12px; }

.subnav { display: flex; gap: 4px; margin-bottom: 14px; padding: 3px; background: var(--bg-sec); border-radius: 8px; }
.subnav button { flex: 1; background: transparent; border: none; padding: 6px 8px; border-radius: 6px; font-size: 12px; cursor: pointer; color: var(--text-sec); }
.subnav button.on { background: var(--bg-pri); color: var(--text); font-weight: 500; }

.logo-wrap { display: flex; align-items: center; gap: 12px; margin-bottom: 11px; }
.logo-thumb { width: 60px; height: 60px; border-radius: 8px; background: var(--bg-sec); border: 0.5px solid var(--bd); object-fit: contain; display: flex; align-items: center; justify-content: center; color: var(--text-ter); font-size: 11px; }
img.logo-thumb { padding: 4px; }

.is-row { display: flex; justify-content: space-between; padding: 6px 0; font-size: 13px; }
.is-row.h { font-weight: 500; border-top: 0.5px solid var(--bd-sec); padding-top: 10px; margin-top: 6px; }
.is-row.sub { padding-left: 14px; font-size: 12px; color: var(--text-sec); }
.is-row.tot { font-weight: 500; border-top: 1px solid var(--text); padding-top: 8px; margin-top: 6px; font-size: 14px; }

.cf-tbl { width: 100%; font-size: 11px; border-collapse: collapse; }
.cf-tbl th, .cf-tbl td { padding: 6px 4px; text-align: right; border-bottom: 0.5px solid var(--bd); }
.cf-tbl th:first-child, .cf-tbl td:first-child { text-align: left; }
.cf-tbl th { font-weight: 500; color: var(--text-sec); font-size: 10px; text-transform: uppercase; }
.cf-tbl td.pos { color: var(--pos); }
.cf-tbl td.neg { color: var(--neg); }

.email-paste { background: var(--bg-sec); border-radius: 8px; padding: 10px; margin-bottom: 10px; }
.email-paste summary { cursor: pointer; font-size: 13px; font-weight: 500; color: var(--primary); display: flex; align-items: center; gap: 6px; list-style: none; }
.email-paste summary::-webkit-details-marker { display: none; }
.email-paste textarea { min-height: 80px; font-size: 12px; }

.pmt-row { display: flex; justify-content: space-between; align-items: center; padding: 8px; background: var(--bg-sec); border-radius: 8px; margin-bottom: 6px; font-size: 12px; }
.pmt-row .x { background: transparent; border: none; color: var(--neg); cursor: pointer; padding: 0 4px; }
