*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg-primary: #ffffff;
  --bg-secondary: #f5f5f0;
  --bg-tertiary: #eeede8;
  --text-primary: #1a1a18;
  --text-secondary: #6b6b67;
  --border: rgba(0,0,0,0.12);
  --border-md: rgba(0,0,0,0.22);
  --radius-md: 8px;
  --radius-lg: 12px;
  --accent: #185FA5;
  --accent-light: #E6F1FB;
  --danger: #A32D2D;
  --danger-light: #FCEBEB;
  --success: #3B6D11;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg-primary: #1c1c1a;
    --bg-secondary: #252523;
    --bg-tertiary: #141412;
    --text-primary: #f0efe8;
    --text-secondary: #9a9994;
    --border: rgba(255,255,255,0.1);
    --border-md: rgba(255,255,255,0.2);
    --accent-light: #1a3a5c;
    --danger-light: #3a1a1a;
  }
}
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; background: var(--bg-tertiary); color: var(--text-primary); -webkit-tap-highlight-color: transparent; overscroll-behavior: none; }
.app { max-width: 420px; margin: 0 auto; min-height: 100vh; display: flex; flex-direction: column; background: var(--bg-tertiary); }
.header { background: var(--bg-primary); border-bottom: 0.5px solid var(--border); padding: 16px; display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; z-index: 100; }
.header-title { font-size: 17px; font-weight: 500; color: var(--text-primary); }
.header-sub { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }
.user-pill { display: flex; align-items: center; gap: 6px; background: var(--bg-secondary); border: 0.5px solid var(--border); border-radius: 20px; padding: 4px 10px 4px 6px; cursor: pointer; min-height: 36px; }
.user-avatar { width: 24px; height: 24px; border-radius: 50%; background: #B5D4F4; display: flex; align-items: center; justify-content: center; font-size: 10px; font-weight: 500; color: #0C447C; }
.user-name { font-size: 12px; color: var(--text-secondary); }
.nav { display: flex; background: var(--bg-primary); border-top: 0.5px solid var(--border); position: sticky; bottom: 0; z-index: 100; padding-bottom: var(--safe-bottom); }
.nav-btn { flex: 1; padding: 10px 4px 8px; display: flex; flex-direction: column; align-items: center; gap: 3px; background: none; border: none; cursor: pointer; color: var(--text-secondary); font-size: 10px; font-family: inherit; transition: color 0.15s; min-height: 56px; }
.nav-btn.active { color: var(--accent); }
.nav-btn i { font-size: 22px; }
.content { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; -webkit-overflow-scrolling: touch; }
.screen { display: none; flex-direction: column; gap: 12px; }
.screen.active { display: flex; }
/* metrics */
.metric-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.metric-card { background: var(--bg-secondary); border-radius: var(--radius-md); padding: 12px 14px; }
.metric-label { font-size: 11px; color: var(--text-secondary); margin-bottom: 4px; text-transform: uppercase; letter-spacing: 0.04em; }
.metric-val { font-size: 20px; font-weight: 500; color: var(--text-primary); }
.metric-val.ing { color: var(--accent); }
.metric-val.egr { color: var(--danger); }
.metric-val.pos { color: var(--success); }
.metric-val.neg { color: var(--danger); }
.metric-val.full { font-size: 15px; }
/* layout */
.section-label { font-size: 12px; font-weight: 500; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.06em; padding: 0 2px; }
.row-between { display: flex; align-items: center; justify-content: space-between; }
/* month selector */
.month-selector { display: flex; align-items: center; justify-content: space-between; background: var(--bg-primary); border-radius: var(--radius-md); border: 0.5px solid var(--border); padding: 10px 14px; }
.month-nav { width: 36px; height: 36px; border-radius: 8px; background: none; border: 0.5px solid var(--border); cursor: pointer; display: flex; align-items: center; justify-content: center; color: var(--text-secondary); }
.month-nav:active { background: var(--bg-secondary); }
.month-label-wrap { text-align: center; }
.month-label { font-size: 15px; font-weight: 500; color: var(--text-primary); display: block; }
.year-label { font-size: 12px; color: var(--text-secondary); }
/* transactions */
.txn-list { display: flex; flex-direction: column; gap: 8px; }
.txn-item { background: var(--bg-primary); border-radius: var(--radius-md); border: 0.5px solid var(--border); display: flex; align-items: center; overflow: hidden; position: relative; }
.txn-inner { display: flex; align-items: center; gap: 12px; padding: 12px 14px; flex: 1; min-width: 0; transition: transform 0.2s ease; }
.txn-icon { width: 36px; height: 36px; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 16px; flex-shrink: 0; }
.txn-icon.ing { background: var(--accent-light); color: var(--accent); }
.txn-icon.egr { background: var(--danger-light); color: var(--danger); }
.txn-info { flex: 1; min-width: 0; }
.txn-detail { font-size: 14px; font-weight: 500; color: var(--text-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.txn-meta { font-size: 11px; color: var(--text-secondary); margin-top: 2px; display: flex; align-items: center; gap: 5px; flex-wrap: wrap; }
.txn-amount { font-size: 14px; font-weight: 500; text-align: right; white-space: nowrap; }
.txn-amount.ing { color: var(--accent); }
.txn-amount.egr { color: var(--danger); }
.txn-delete-btn { position: absolute; right: 0; top: 0; bottom: 0; width: 60px; background: var(--danger); display: flex; align-items: center; justify-content: center; color: white; font-size: 18px; cursor: pointer; border: none; opacity: 0; pointer-events: none; transition: opacity 0.2s; flex-shrink: 0; }
.txn-item.swiped .txn-inner { transform: translateX(-60px); }
.txn-item.swiped .txn-delete-btn { opacity: 1; pointer-events: auto; }
/* category pill */
.cat-pill { display: inline-flex; align-items: center; gap: 3px; font-size: 10px; padding: 2px 6px; border-radius: 6px; background: var(--bg-secondary); color: var(--text-secondary); }
/* fab */
.fab { position: fixed; bottom: calc(72px + var(--safe-bottom) + 16px); right: calc(50% - 210px + 20px); width: 52px; height: 52px; border-radius: 50%; background: var(--accent); border: none; color: white; font-size: 24px; cursor: pointer; display: flex; align-items: center; justify-content: center; box-shadow: 0 2px 12px rgba(24,95,165,0.35); z-index: 90; }
@media (max-width: 420px) { .fab { right: 20px; } }
/* modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.45); z-index: 200; display: none; align-items: flex-end; }
.modal-backdrop.open { display: flex; }
.modal { background: var(--bg-primary); border-radius: 20px 20px 0 0; padding: 20px 16px calc(32px + var(--safe-bottom)); width: 100%; max-height: 92vh; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.modal-handle { width: 36px; height: 4px; background: var(--border); border-radius: 2px; margin: 0 auto 20px; }
.modal-title { font-size: 17px; font-weight: 500; color: var(--text-primary); margin-bottom: 20px; }
/* forms */
.form-group { margin-bottom: 14px; }
.form-label { font-size: 12px; color: var(--text-secondary); margin-bottom: 6px; display: block; }
.form-input { width: 100%; background: var(--bg-secondary); border: 0.5px solid var(--border); border-radius: var(--radius-md); padding: 10px 12px; font-size: 15px; color: var(--text-primary); font-family: inherit; -webkit-appearance: none; }
.form-input:focus { outline: none; border-color: var(--accent); }
/* type toggle */
.type-toggle { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.type-btn { padding: 11px; border-radius: var(--radius-md); border: 0.5px solid var(--border); background: var(--bg-secondary); font-size: 14px; font-weight: 500; cursor: pointer; color: var(--text-secondary); transition: all 0.15s; font-family: inherit; min-height: 44px; }
.type-btn.selected.ing { background: var(--accent-light); border-color: var(--accent); color: var(--accent); }
.type-btn.selected.egr { background: var(--danger-light); border-color: var(--danger); color: var(--danger); }
/* category grid */
.cat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.cat-btn { padding: 10px 6px; border-radius: var(--radius-md); border: 0.5px solid var(--border); background: var(--bg-secondary); font-size: 11px; cursor: pointer; color: var(--text-secondary); font-family: inherit; display: flex; flex-direction: column; align-items: center; gap: 5px; transition: all 0.15s; min-height: 60px; justify-content: center; }
.cat-btn i { font-size: 20px; }
.cat-btn.selected { border-color: var(--accent); color: var(--accent); background: var(--accent-light); }
/* buttons */
.btn-primary { width: 100%; padding: 14px; background: var(--accent); border: none; border-radius: var(--radius-md); color: white; font-size: 15px; font-weight: 500; cursor: pointer; margin-top: 8px; font-family: inherit; min-height: 48px; }
.btn-primary:active { background: #0C447C; }
.btn-danger { background: var(--danger) !important; }
.btn-danger:active { background: #7a1f1f !important; }
.btn-outline { padding: 14px; background: var(--bg-secondary); border: 0.5px solid var(--border); border-radius: var(--radius-md); font-size: 15px; font-weight: 500; cursor: pointer; font-family: inherit; color: var(--text-primary); min-height: 48px; width: 100%; }
.btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 8px; }
/* summary */
.summary-table { background: var(--bg-primary); border-radius: var(--radius-lg); border: 0.5px solid var(--border); overflow: hidden; }
.sum-row { display: grid; grid-template-columns: 32px 1fr 1fr 1fr; gap: 8px; align-items: center; padding: 10px 14px; border-bottom: 0.5px solid var(--border); font-size: 12px; }
.sum-row:last-child { border-bottom: none; }
.sum-row.header { background: var(--bg-secondary); font-size: 11px; color: var(--text-secondary); font-weight: 500; text-transform: uppercase; letter-spacing: 0.04em; }
.sum-row.total { background: var(--bg-secondary); font-weight: 500; }
.sum-mes { font-weight: 500; color: var(--text-primary); font-size: 13px; }
.sum-val { text-align: right; color: var(--text-secondary); }
.sum-val.pos { color: var(--success); }
.sum-val.neg { color: var(--danger); }
/* AI */
.ai-box { background: var(--bg-primary); border: 0.5px solid var(--border); border-radius: var(--radius-lg); padding: 14px; }
.ai-input-row { display: flex; gap: 8px; margin-bottom: 12px; }
.ai-input { flex: 1; background: var(--bg-secondary); border: 0.5px solid var(--border); border-radius: var(--radius-md); padding: 10px 12px; font-size: 14px; color: var(--text-primary); font-family: inherit; min-height: 44px; }
.ai-input:focus { outline: none; border-color: var(--accent); }
.ai-send-btn { width: 44px; height: 44px; border-radius: var(--radius-md); background: var(--accent); border: none; color: white; cursor: pointer; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.ai-messages { display: flex; flex-direction: column; gap: 10px; min-height: 40px; max-height: 300px; overflow-y: auto; }
.ai-msg { padding: 10px 12px; border-radius: var(--radius-md); font-size: 13px; line-height: 1.5; }
.ai-msg.user { background: var(--accent-light); color: #0C447C; align-self: flex-end; max-width: 85%; }
.ai-msg.bot { background: var(--bg-secondary); color: var(--text-primary); align-self: flex-start; max-width: 95%; }
.ai-msg.thinking { color: var(--text-secondary); font-style: italic; }
.quick-btn { font-size: 11px; padding: 7px 12px; background: var(--bg-secondary); border: 0.5px solid var(--border); border-radius: 12px; cursor: pointer; color: var(--text-secondary); font-family: inherit; min-height: 34px; }
/* users */
.user-item { display: flex; align-items: center; gap: 12px; padding: 12px 14px; background: var(--bg-secondary); border-radius: var(--radius-md); border: 0.5px solid var(--border); cursor: pointer; margin-bottom: 8px; min-height: 56px; }
.user-item.active-user { border-color: var(--accent); background: var(--accent-light); }
.user-item-avatar { width: 36px; height: 36px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 500; flex-shrink: 0; }
.user-item-info .name { font-size: 14px; font-weight: 500; color: var(--text-primary); }
.user-item-info .role { font-size: 12px; color: var(--text-secondary); }
.add-user-btn { width: 100%; padding: 12px; background: none; border: 0.5px dashed var(--border-md); border-radius: var(--radius-md); font-size: 14px; color: var(--text-secondary); cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 8px; font-family: inherit; min-height: 48px; }
/* empty state */
.empty-state { text-align: center; padding: 40px 20px; color: var(--text-secondary); font-size: 14px; }
.empty-state i { font-size: 40px; margin-bottom: 12px; display: block; opacity: 0.4; }
/* balance bar */
.balance-bar { background: var(--bg-primary); border-radius: var(--radius-lg); border: 0.5px solid var(--border); padding: 16px; }
.bar-track { height: 8px; border-radius: 4px; background: var(--bg-secondary); overflow: hidden; margin: 10px 0 8px; }
.bar-fill { height: 100%; border-radius: 4px; transition: width 0.5s ease; }
.bar-labels { display: flex; justify-content: space-between; font-size: 11px; color: var(--text-secondary); }
/* toast */
.toast { position: fixed; top: 80px; left: 50%; transform: translateX(-50%) translateY(-20px); background: #1a1a18; color: #fff; padding: 10px 18px; border-radius: 20px; font-size: 13px; opacity: 0; transition: all 0.3s; z-index: 999; pointer-events: none; white-space: nowrap; max-width: 90vw; text-overflow: ellipsis; overflow: hidden; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
/* export btn */
.export-btn { display: flex; align-items: center; justify-content: center; gap: 8px; padding: 11px 14px; background: var(--bg-secondary); border: 0.5px solid var(--border); border-radius: var(--radius-md); font-size: 13px; color: var(--text-secondary); cursor: pointer; font-family: inherit; width: 100%; min-height: 44px; }
/* confirm modal */
.confirm-body { text-align: center; padding: 8px 0 16px; }
.confirm-icon { font-size: 44px; color: var(--danger); margin-bottom: 12px; display: block; }
.confirm-text { font-size: 15px; color: var(--text-primary); margin-bottom: 6px; font-weight: 500; }
.confirm-sub { font-size: 13px; color: var(--text-secondary); word-break: break-word; }
/* footer */
.app-footer { text-align: center; padding: 24px 16px 32px; font-size: 11px; color: var(--text-secondary); opacity: 0.55; letter-spacing: 0.3px; }
.app-footer a { color: inherit; text-decoration: none; }
/* loading */
.loading-overlay { position: fixed; inset: 0; background: var(--bg-tertiary); display: flex; align-items: center; justify-content: center; z-index: 1000; flex-direction: column; gap: 14px; }
.loading-spinner { width: 36px; height: 36px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; }
.loading-text { font-size: 13px; color: var(--text-secondary); }
@keyframes spin { to { transform: rotate(360deg); } }
/* login */
.login-screen { position: fixed; inset: 0; background: var(--bg-tertiary); display: none; align-items: center; justify-content: center; z-index: 1500; padding: 24px; }
.login-card { background: var(--bg-primary); border-radius: 20px; padding: 36px 24px 28px; width: 100%; max-width: 360px; display: flex; flex-direction: column; align-items: center; gap: 10px; box-shadow: 0 8px 32px rgba(0,0,0,0.14); }
.login-logo { width: 64px; height: 64px; background: var(--accent); border-radius: 16px; display: flex; align-items: center; justify-content: center; color: #fff; font-size: 30px; margin-bottom: 4px; }
.login-title { font-size: 22px; font-weight: 600; }
.login-sub { font-size: 12px; color: var(--text-secondary); margin-top: -4px; margin-bottom: 6px; }
.login-form { width: 100%; display: flex; flex-direction: column; gap: 10px; }
.login-input { width: 100%; padding: 13px 14px; border: 1px solid var(--border-md); border-radius: 10px; background: var(--bg-secondary); font-size: 16px; color: var(--text-primary); outline: none; }
.login-input:focus { border-color: var(--accent); }
.login-btn { width: 100%; padding: 13px; background: var(--accent); color: #fff; border: none; border-radius: 10px; font-size: 16px; font-weight: 500; cursor: pointer; margin-top: 4px; }
.login-btn:disabled { opacity: 0.6; }
.login-error { font-size: 13px; color: var(--danger); text-align: center; min-height: 18px; }
.pass-wrap { position: relative; width: 100%; }
.pass-wrap .login-input { padding-right: 44px; }
.pass-toggle { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); background: none; border: none; cursor: pointer; color: var(--text-secondary); padding: 0; font-size: 20px; line-height: 1; display: flex; align-items: center; }
.logout-btn { width: 100%; display: flex; align-items: center; justify-content: center; gap: 8px; padding: 12px; background: var(--danger-light); color: var(--danger); border: none; border-radius: var(--radius-md); font-size: 14px; font-weight: 500; cursor: pointer; margin-top: 8px; }
