:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --success: #16a34a;
  --warning: #d97706;
  --danger: #dc2626;
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface2: #f8fafc;
  --text: #0f172a;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --nav-h: 64px;
  --header-h: 52px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --radius: 12px;
  --radius-sm: 8px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f172a; --surface: #1e293b; --surface2: #1e293b;
    --text: #f1f5f9; --text-muted: #94a3b8; --border: #334155;
  }
}
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; background: var(--bg); color: var(--text); }
#app { height: 100%; display: flex; flex-direction: column; }

/* Login */
.login-wrap { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 1.5rem; background: var(--bg); }
.login-card { background: var(--surface); border-radius: var(--radius); padding: 2rem; width: 100%; max-width: 360px; box-shadow: 0 4px 24px rgba(0,0,0,.12); }
.login-logo { font-size: 3rem; text-align: center; margin-bottom: .5rem; }
.login-title { text-align: center; font-size: 1.4rem; font-weight: 700; margin-bottom: 1.5rem; }
.login-error { color: var(--danger); font-size: .85rem; text-align: center; margin-top: .75rem; }

/* Header */
.app-header { position: fixed; top: 0; left: 0; right: 0; height: var(--header-h); padding-top: var(--safe-t); background: var(--primary); color: #fff; display: flex; align-items: center; justify-content: space-between; padding-left: .75rem; padding-right: .75rem; z-index: 100; box-shadow: 0 2px 8px rgba(0,0,0,.2); }
.header-back { background: none; border: none; color: #fff; font-size: 1.5rem; cursor: pointer; padding: 8px; }
#header-title { font-size: 1rem; font-weight: 600; }

/* Main content */
.screen-content { margin-top: var(--header-h); margin-bottom: calc(var(--nav-h) + var(--safe-b)); padding: 1rem; overflow-y: auto; min-height: calc(100vh - var(--header-h) - var(--nav-h)); }

/* Bottom nav */
.bottom-nav { position: fixed; bottom: 0; left: 0; right: 0; height: calc(var(--nav-h) + var(--safe-b)); padding-bottom: var(--safe-b); background: var(--surface); border-top: 1px solid var(--border); display: flex; align-items: stretch; z-index: 100; }
.nav-btn { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; border: none; background: none; cursor: pointer; padding: 6px 0; color: var(--text-muted); transition: color .15s; }
.nav-btn.active { color: var(--primary); }
.nav-icon { font-size: 1.3rem; line-height: 1; }
.nav-label { font-size: .65rem; font-weight: 500; }

/* Cards */
.card { background: var(--surface); border-radius: var(--radius); padding: 1rem; margin-bottom: .75rem; box-shadow: 0 1px 4px rgba(0,0,0,.07); }
.card-title { font-size: .7rem; text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); margin-bottom: .5rem; }
.card-value { font-size: 1.8rem; font-weight: 700; }
.card-sub { font-size: .8rem; color: var(--text-muted); margin-top: .15rem; }

/* Grid */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: .5rem; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; padding: .75rem 1.25rem; border-radius: var(--radius-sm); font-size: 1rem; font-weight: 600; border: none; cursor: pointer; transition: opacity .15s, transform .1s; min-height: 48px; }
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); color: #fff; }
.btn-danger  { background: var(--danger);  color: #fff; }
.btn-ghost   { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-full    { width: 100%; }
.btn-lg      { padding: 1rem; font-size: 1.1rem; min-height: 56px; border-radius: var(--radius); }

/* Form fields */
.field { margin-bottom: 1rem; }
.field label { display: block; font-size: .8rem; font-weight: 600; color: var(--text-muted); margin-bottom: .35rem; text-transform: uppercase; letter-spacing: .04em; }
.field-input { width: 100%; padding: .75rem 1rem; border: 1.5px solid var(--border); border-radius: var(--radius-sm); font-size: 1rem; background: var(--surface); color: var(--text); min-height: 48px; }
.field-input:focus { outline: none; border-color: var(--primary); }
select.field-input { -webkit-appearance: none; }

/* App chip selector */
.app-chips { display: flex; flex-wrap: wrap; gap: .5rem; }
.app-chip { padding: .5rem 1rem; border-radius: 999px; border: 2px solid var(--border); background: var(--surface2); font-size: .9rem; font-weight: 600; cursor: pointer; transition: all .15s; color: var(--text); min-height: 44px; display: flex; align-items: center; }
.app-chip.selected { border-color: var(--primary); background: var(--primary); color: #fff; }

/* Category toggle */
.cat-toggle { display: flex; border: 1.5px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; }
.cat-btn { flex: 1; padding: .75rem; border: none; background: var(--surface2); color: var(--text-muted); font-size: .95rem; font-weight: 600; cursor: pointer; min-height: 48px; }
.cat-btn.active { background: var(--primary); color: #fff; }

/* Section header */
.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: .75rem; }
.section-title { font-size: 1rem; font-weight: 700; }

/* List items */
.list-item { background: var(--surface); border-radius: var(--radius-sm); padding: .85rem 1rem; margin-bottom: .5rem; display: flex; align-items: center; justify-content: space-between; box-shadow: 0 1px 3px rgba(0,0,0,.06); }
.list-item-left { flex: 1; }
.list-item-title { font-weight: 600; font-size: .95rem; }
.list-item-sub { font-size: .78rem; color: var(--text-muted); margin-top: .15rem; }
.list-item-right { font-size: 1.1rem; font-weight: 700; color: var(--success); white-space: nowrap; margin-left: .75rem; }
.list-item-right.expense { color: var(--danger); }

/* Badge */
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: .72rem; font-weight: 600; }
.badge-blue   { background: #dbeafe; color: #1e40af; }
.badge-green  { background: #dcfce7; color: #15803d; }
.badge-orange { background: #fff7ed; color: #c2410c; }
.badge-open   { background: #fef9c3; color: #854d0e; }

/* Summary row */
.summary-row { display: flex; justify-content: space-between; padding: .4rem 0; border-bottom: 1px solid var(--border); font-size: .9rem; }
.summary-row:last-child { border-bottom: none; }
.summary-row.total { font-weight: 700; padding-top: .6rem; }
.summary-row.highlight { color: var(--primary); font-weight: 700; }

/* Alert */
.alert { padding: .75rem 1rem; border-radius: var(--radius-sm); font-size: .875rem; margin-bottom: .75rem; }
.alert-info    { background: #dbeafe; color: #1e40af; }
.alert-success { background: #dcfce7; color: #15803d; }
.alert-warn    { background: #fef9c3; color: #854d0e; }
.alert-danger  { background: #fee2e2; color: #991b1b; }

/* Open shift banner */
.open-shift-banner { background: #fef9c3; border: 1.5px solid #fbbf24; border-radius: var(--radius); padding: .85rem 1rem; margin-bottom: 1rem; display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.open-shift-text { font-size: .88rem; font-weight: 600; color: #854d0e; }

/* Month selector */
.month-sel { display: flex; align-items: center; gap: .5rem; background: var(--surface); border-radius: var(--radius-sm); padding: .4rem .75rem; }
.month-sel button { background: none; border: none; font-size: 1.2rem; cursor: pointer; color: var(--text); padding: 4px; }
.month-sel span { font-size: .95rem; font-weight: 600; min-width: 110px; text-align: center; }

/* Toast */
.toast { position: fixed; bottom: calc(var(--nav-h) + var(--safe-b) + 12px); left: 50%; transform: translateX(-50%); background: #1e293b; color: #fff; padding: .6rem 1.2rem; border-radius: 999px; font-size: .875rem; z-index: 999; box-shadow: 0 4px 16px rgba(0,0,0,.3); pointer-events: none; }

/* Spinner */
.spinner { display: inline-block; width: 20px; height: 20px; border: 2px solid #fff3; border-top-color: #fff; border-radius: 50%; animation: spin .6s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Offline indicator */
.offline-bar { background: var(--warning); color: #fff; text-align: center; font-size: .78rem; font-weight: 600; padding: .3rem; }

/* App stats table */
.app-table { width: 100%; border-collapse: collapse; font-size: .82rem; }
.app-table th { text-align: left; color: var(--text-muted); font-weight: 600; padding: .4rem .3rem; border-bottom: 1px solid var(--border); }
.app-table td { padding: .45rem .3rem; border-bottom: 1px solid var(--border); }
.app-table tr:last-child td { border-bottom: none; }

/* Tabs (sub-nav within screen) */
.tabs { display: flex; border-bottom: 2px solid var(--border); margin-bottom: 1rem; }
.tab-btn { flex: 1; padding: .6rem; border: none; background: none; font-size: .85rem; font-weight: 600; color: var(--text-muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -2px; }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }

/* Service selector (income screen) */
.service-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; margin-bottom: .25rem; }
.service-btn { padding: .7rem .5rem; border: 2px solid var(--border); border-radius: var(--radius-sm); background: var(--surface2); color: var(--text); font-size: .88rem; font-weight: 600; cursor: pointer; transition: all .15s; min-height: 48px; text-align: center; }
.service-btn.selected { border-color: var(--primary); background: var(--primary); color: #fff; }

/* Theme swatches */
.theme-swatches { display: flex; gap: .6rem; flex-wrap: wrap; padding: .25rem 0; }
.swatch { width: 34px; height: 34px; border-radius: 50%; cursor: pointer; border: 3px solid transparent; transition: transform .15s; }
.swatch.selected { border-color: var(--text); transform: scale(1.2); }

/* Utility */
.text-right { text-align: right; }
.text-muted { color: var(--text-muted); }
.text-success { color: var(--success); }
.text-danger  { color: var(--danger); }
.mt-1 { margin-top: .5rem; }
.mt-2 { margin-top: 1rem; }
.empty-state { text-align: center; padding: 3rem 1rem; color: var(--text-muted); font-size: .95rem; }
