:root {
  --navy: #0B1F33;
  --green: #0E6B4F;
  --gold: #D4AF37;
  --red: #C0392B;
  --orange: #E67E22;
  --white: #FFFFFF;
  --bg: #F5F7FA;
  --card-bg: #FFFFFF;
  --text: #1F2933;
  --text2: #657786;
  --border: #E1E8ED;
  --topbar-h: 56px;
  --subnav-h: 44px;
  --bottomnav-h: 64px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0B1F33;
    --card-bg: #1A2F44;
    --text: #FFFFFF;
    --text2: #8899AA;
    --border: #2A3F54;
  }
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.4;
  overscroll-behavior-y: contain;
}
button, input, select, textarea { font-family: inherit; font-size: 15px; }
a { color: var(--green); }
.hidden { display: none !important; }

/* ── TOP BAR ── */
#topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  height: calc(var(--topbar-h) + var(--safe-top));
  padding-top: var(--safe-top);
  background: var(--navy); color: #fff;
  display: flex; align-items: center; justify-content: space-between;
  padding-left: 12px; padding-right: 12px;
}
#topbar-left { display: flex; align-items: center; gap: 8px; min-width: 0; }
#topbar-left span#page-title { font-size: 17px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#back-btn { background: none; border: none; color: #fff; font-size: 22px; min-width: 44px; min-height: 44px; cursor: pointer; }
#topbar-right { display: flex; align-items: center; gap: 8px; }
#company-badge { font-size: 11px; background: rgba(255,255,255,.15); padding: 3px 8px; border-radius: 20px; white-space: nowrap; }
#notif-btn { position: relative; background: none; border: none; color: #fff; font-size: 20px; min-width: 44px; min-height: 44px; cursor: pointer; }
.badge {
  position: absolute; top: 2px; right: 2px; background: var(--red); color: #fff;
  font-size: 10px; font-weight: 700; min-width: 16px; height: 16px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center; padding: 0 3px;
}

/* ── SUB NAV ── */
#subnav {
  position: fixed; left: 0; right: 0; z-index: 90;
  top: calc(var(--topbar-h) + var(--safe-top));
  height: var(--subnav-h);
  background: var(--card-bg); border-bottom: 1px solid var(--border);
  display: flex; overflow-x: auto;
}
#subnav .subnav-btn {
  flex: 1; min-width: 90px; border: none; background: none; color: var(--text2);
  font-size: 14px; font-weight: 600; cursor: pointer; border-bottom: 2px solid transparent;
  min-height: 44px;
}
#subnav .subnav-btn.active { color: var(--green); border-bottom-color: var(--green); }

/* ── MAIN CONTENT ── */
#main-content {
  padding-top: calc(var(--topbar-h) + var(--safe-top) + 12px);
  padding-bottom: calc(var(--bottomnav-h) + var(--safe-bottom) + 16px);
  padding-left: 12px; padding-right: 12px;
  min-height: 100vh;
}
#main-content.has-subnav { padding-top: calc(var(--topbar-h) + var(--subnav-h) + var(--safe-top) + 12px); }

/* ── BOTTOM NAV ── */
#bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 100;
  height: calc(var(--bottomnav-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--card-bg); border-top: 1px solid var(--border);
  display: flex;
}
.nav-btn {
  flex: 1; border: none; background: none; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 2px; min-height: 44px; cursor: pointer;
  color: var(--text2);
}
.nav-btn.active { color: var(--green); }
.nav-icon { font-size: 20px; line-height: 1; }
.nav-label { font-size: 11px; font-weight: 600; }

/* ── FAB ── */
.fab, #fab {
  position: fixed; right: 20px; bottom: calc(var(--bottomnav-h) + var(--safe-bottom) + 16px);
  width: 56px; height: 56px; border-radius: 50%; background: var(--green); color: #fff;
  border: none; font-size: 28px; box-shadow: 0 4px 12px rgba(0,0,0,.3); cursor: pointer; z-index: 95;
  display: flex; align-items: center; justify-content: center;
}

/* ── CARDS ── */
.card {
  background: var(--card-bg); border-radius: 12px; padding: 16px; margin-bottom: 12px;
  box-shadow: 0 1px 3px rgba(0,0,0,.08); border: 1px solid var(--border);
}
.card-title { font-size: 13px; font-weight: 700; color: var(--text2); text-transform: uppercase; letter-spacing: .4px; margin-bottom: 10px; }

.kpi-row { display: flex; gap: 10px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 12px; -webkit-overflow-scrolling: touch; }
.kpi-card {
  flex: 0 0 140px; background: var(--card-bg); border-radius: 12px; padding: 14px;
  border: 1px solid var(--border); box-shadow: 0 1px 3px rgba(0,0,0,.08);
}
.kpi-label { font-size: 11px; color: var(--text2); text-transform: uppercase; letter-spacing: .4px; margin-bottom: 6px; }
.kpi-value { font-size: 20px; font-weight: 800; }
.kpi-trend { font-size: 12px; margin-top: 4px; font-weight: 600; }
.kpi-trend.up { color: var(--green); }
.kpi-trend.down { color: var(--red); }

/* ── QUICK ACTIONS GRID ── */
.qa-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 16px; }
.qa-btn {
  background: var(--card-bg); border: 1px solid var(--border); border-radius: 12px;
  padding: 14px 6px; display: flex; flex-direction: column; align-items: center; gap: 6px;
  cursor: pointer; min-height: 76px; justify-content: center;
}
.qa-icon { font-size: 22px; }
.qa-label { font-size: 11px; font-weight: 600; text-align: center; color: var(--text); }

/* ── LIST ITEMS ── */
.list-item {
  min-height: 64px; display: flex; align-items: center; gap: 12px; padding: 10px 4px;
  border-bottom: 1px solid var(--border); cursor: pointer;
}
.list-item:last-child { border-bottom: none; }
.list-icon {
  width: 40px; height: 40px; border-radius: 50%; background: var(--bg);
  display: flex; align-items: center; justify-content: center; font-size: 18px; flex-shrink: 0;
}
.list-body { flex: 1; min-width: 0; }
.list-title { font-size: 14px; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-sub { font-size: 12px; color: var(--text2); margin-top: 2px; }
.list-right { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.list-amount { font-size: 14px; font-weight: 700; color: var(--text); }
.list-chevron { color: var(--text2); font-size: 16px; margin-left: 4px; }

/* ── BADGE PILLS ── */
.badge-pill { display: inline-block; padding: 3px 9px; border-radius: 20px; font-size: 11px; font-weight: 700; white-space: nowrap; }
.pill-green { background: rgba(14,107,79,.15); color: var(--green); }
.pill-red { background: rgba(192,57,43,.15); color: var(--red); }
.pill-amber { background: rgba(212,175,55,.18); color: #9a7d1f; }
.pill-blue { background: rgba(52,120,246,.15); color: #3478f6; }
.pill-gray { background: rgba(101,119,134,.15); color: var(--text2); }

/* ── FORMS ── */
.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 12px; font-weight: 600; color: var(--text2); margin-bottom: 6px; }
.form-group input, .form-group select, .form-group textarea {
  width: 100%; min-height: 44px; padding: 10px 12px; border: 1px solid var(--border);
  border-radius: 8px; background: var(--card-bg); color: var(--text); outline: none;
}
.form-group textarea { min-height: 80px; resize: vertical; }
.form-error { color: var(--red); font-size: 13px; margin-bottom: 10px; }
.form-row { display: flex; gap: 10px; }
.form-row .form-group { flex: 1; }

.btn-primary {
  width: 100%; min-height: 48px; background: var(--green); color: #fff; border: none;
  border-radius: 10px; font-size: 15px; font-weight: 700; cursor: pointer;
}
.btn-primary:disabled { opacity: .6; }
.btn-secondary {
  width: 100%; min-height: 48px; background: transparent; color: var(--green);
  border: 1.5px solid var(--green); border-radius: 10px; font-size: 15px; font-weight: 700; cursor: pointer;
}
.btn-danger { background: var(--red); color: #fff; border: none; }
.btn-row { display: flex; gap: 10px; margin-top: 12px; }
.btn-row > * { flex: 1; }

/* ── ALERT BANNER ── */
.alert-banner {
  position: fixed; top: 0; left: 0; right: 0; z-index: 200;
  padding: 10px 16px; padding-top: calc(10px + var(--safe-top));
  font-size: 13px; font-weight: 600; text-align: center; color: #fff;
  background: var(--orange);
}
.alert-banner.critical { background: var(--red); }
.alert-banner.sync { background: var(--green); }

/* ── BOTTOM SHEET ── */
.bottom-sheet-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 300;
  display: flex; align-items: flex-end;
}
.bottom-sheet {
  background: var(--card-bg); width: 100%; max-height: 88vh; border-radius: 16px 16px 0 0;
  display: flex; flex-direction: column; padding-bottom: var(--safe-bottom);
}
.sheet-handle { width: 36px; height: 4px; background: var(--border); border-radius: 2px; margin: 10px auto; }
.sheet-header { display: flex; justify-content: space-between; align-items: center; padding: 0 16px 10px; border-bottom: 1px solid var(--border); }
.sheet-title { font-size: 16px; font-weight: 700; }
.link-btn { background: none; border: none; color: var(--green); font-size: 14px; font-weight: 600; cursor: pointer; min-height: 44px; }
.sheet-body { padding: 16px; overflow-y: auto; flex: 1; }
.sheet-footer { padding: 12px 16px; border-top: 1px solid var(--border); }

/* ── SKELETON LOADING ── */
.skeleton { background: linear-gradient(90deg, var(--border) 25%, rgba(255,255,255,.3) 50%, var(--border) 75%); background-size: 200% 100%; animation: skeleton-loading 1.4s ease infinite; border-radius: 8px; height: 16px; margin-bottom: 8px; }
@keyframes skeleton-loading { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* ── PULL TO REFRESH ── */
.pull-to-refresh {
  position: fixed; top: calc(var(--topbar-h) + var(--safe-top)); left: 0; right: 0; z-index: 80;
  text-align: center; font-size: 12px; color: var(--text2); padding: 6px;
}

/* ── LOGIN SCREEN ── */
#login-screen { position: fixed; inset: 0; background: var(--bg); z-index: 500; display: flex; align-items: center; padding: 24px; overflow-y: auto; }
.login-wrap { width: 100%; max-width: 400px; margin: 0 auto; }
.login-logo { text-align: center; margin-bottom: 28px; }
.login-icon { width: 64px; height: 64px; border-radius: 16px; background: var(--navy); color: var(--gold); font-weight: 800; font-size: 22px; display: flex; align-items: center; justify-content: center; margin: 0 auto 12px; }
.login-title { font-size: 20px; font-weight: 700; }
.login-sub { font-size: 13px; color: var(--text2); margin-top: 2px; }

/* ── INSTALL BANNER ── */
.install-banner {
  position: fixed; left: 12px; right: 12px; bottom: calc(var(--bottomnav-h) + var(--safe-bottom) + 12px);
  background: var(--navy); color: #fff; border-radius: 12px; padding: 12px 14px; z-index: 150;
  display: flex; align-items: center; gap: 10px; font-size: 13px; box-shadow: 0 4px 12px rgba(0,0,0,.3);
}
.install-banner button { min-height: 36px; border-radius: 8px; border: none; cursor: pointer; padding: 0 12px; font-weight: 700; }
.install-banner #install-btn { background: var(--green); color: #fff; }
.install-banner #install-dismiss { background: transparent; color: #fff; font-size: 16px; min-width: 36px; }

/* ── TOAST ── */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--bottomnav-h) + var(--safe-bottom) + 16px);
  background: var(--navy); color: #fff; padding: 12px 18px; border-radius: 10px; font-size: 13px; z-index: 400;
  max-width: 90vw; text-align: center; box-shadow: 0 4px 12px rgba(0,0,0,.3);
}

/* ── PROGRESS BAR ── */
.progress-track { height: 6px; background: var(--border); border-radius: 3px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--green); border-radius: 3px; }

/* ── EMPTY / ERROR STATES ── */
.empty-state { text-align: center; padding: 40px 20px; color: var(--text2); font-size: 14px; }
.section-title { font-size: 15px; font-weight: 700; margin: 4px 0 10px; }

/* ── SWIPE HINT (visual only, actual swipe handled in JS) ── */
.swipeable { touch-action: pan-y; }

@media (min-width: 480px) {
  #main-content, #login-screen .login-wrap { max-width: 480px; margin-left: auto; margin-right: auto; }
}
