*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f0f2f5;
  --surface: #ffffff;
  --surface2: #f8f9fa;
  --border: #e2e8f0;
  --text: #1a202c;
  --text2: #64748b;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --danger: #dc2626;
  --success: #16a34a;
  --success-bg: #dcfce7;
  --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
  --radius: 12px;
}

@media (prefers-color-scheme: dark) {
  :root { --bg:#0f172a; --surface:#1e293b; --surface2:#273548; --border:#334155; --text:#f1f5f9; --text2:#94a3b8; --shadow:0 1px 3px rgba(0,0,0,.4); }
}
:root[data-theme="light"] { --bg:#f0f2f5; --surface:#ffffff; --surface2:#f8f9fa; --border:#e2e8f0; --text:#1a202c; --text2:#64748b; --shadow:0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06); }
:root[data-theme="dark"]  { --bg:#0f172a; --surface:#1e293b; --surface2:#273548; --border:#334155; --text:#f1f5f9; --text2:#94a3b8; --shadow:0 1px 3px rgba(0,0,0,.4); }

body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; background: var(--bg); color: var(--text); min-height: 100dvh; -webkit-tap-highlight-color: transparent; }

/* ── Header ── */
header { background: var(--surface); border-bottom: 1px solid var(--border); padding: 12px 16px; display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; z-index: 10; box-shadow: var(--shadow); }
header h1 { font-size: 1.05rem; font-weight: 700; color: var(--accent); }
.header-right { display: flex; align-items: center; gap: 8px; }
.user-name { font-size: .8rem; color: var(--text2); }
.btn-icon { background: none; border: none; cursor: pointer; color: var(--text2); padding: 6px; border-radius: 8px; line-height: 1; font-size: 1.1rem; }
.btn-icon:hover { background: var(--surface2); color: var(--text); }

/* ── Nav tabs ── */
nav { display: flex; background: var(--surface); border-bottom: 1px solid var(--border); }
nav button { flex: 1; padding: 12px 8px; border: none; background: none; cursor: pointer; font-size: .85rem; font-weight: 500; color: var(--text2); border-bottom: 3px solid transparent; transition: all .15s; }
nav button.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ── Main ── */
main { max-width: 480px; margin: 0 auto; padding: 20px 16px 80px; }

/* ── Auth screen ── */
#screen-auth { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 80dvh; gap: 16px; }
.auth-card { background: var(--surface); border-radius: var(--radius); padding: 32px 24px; width: 100%; max-width: 360px; box-shadow: var(--shadow); }
.auth-card h2 { text-align: center; margin-bottom: 24px; font-size: 1.3rem; }

/* ── Form ── */
.form-group { margin-bottom: 16px; }
label { display: block; font-size: .8rem; font-weight: 600; color: var(--text2); margin-bottom: 6px; text-transform: uppercase; letter-spacing: .05em; }
input, select, textarea {
  width: 100%; padding: 12px 14px; border: 1.5px solid var(--border);
  border-radius: 10px; background: var(--surface2); color: var(--text);
  font-size: 1rem; transition: border-color .15s;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); background: var(--surface); }
input[type=number] { font-size: 1.4rem; font-weight: 700; text-align: center; }
textarea { resize: none; min-height: 72px; }
select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' fill='none'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%2394a3b8' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 14px center; }

/* ── Amount hint ── */
.amount-hint { font-size: .75rem; color: var(--text2); text-align: center; margin-top: 4px; }

/* ── Buttons ── */
.btn { width: 100%; padding: 14px; border: none; border-radius: 10px; font-size: 1rem; font-weight: 600; cursor: pointer; transition: all .15s; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:active { transform: scale(.98); }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; transform: none; }

/* ── Success toast ── */
#toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(80px); background: var(--success); color: #fff; padding: 12px 24px; border-radius: 50px; font-weight: 600; font-size: .95rem; transition: transform .3s; z-index: 100; white-space: nowrap; box-shadow: 0 4px 12px rgba(0,0,0,.2); }
#toast.show { transform: translateX(-50%) translateY(0); }

/* ── Offline bar ── */
#offline-bar { display: none; background: var(--danger); color: #fff; text-align: center; padding: 8px; font-size: .8rem; font-weight: 500; }
#offline-bar.visible { display: block; }

/* ── Error msg ── */
.error-msg { color: var(--danger); font-size: .82rem; margin-top: 8px; min-height: 20px; }

/* ── Report ── */
.period-btns { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 20px; }
.period-btn { padding: 7px 14px; border: 1.5px solid var(--border); border-radius: 20px; background: var(--surface); color: var(--text2); font-size: .82rem; cursor: pointer; }
.period-btn.active { border-color: var(--accent); color: var(--accent); background: var(--surface); font-weight: 600; }
.custom-dates { display: none; gap: 10px; margin-bottom: 16px; }
.custom-dates.visible { display: flex; }
.custom-dates input { font-size: .9rem; }

.report-total { background: var(--accent); color: #fff; border-radius: var(--radius); padding: 20px; text-align: center; margin-bottom: 20px; }
.report-total .amount { font-size: 2.4rem; font-weight: 800; }
.report-total .label { font-size: .82rem; opacity: .85; margin-top: 2px; }

.report-section { background: var(--surface); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; }
.report-section h3 { font-size: .8rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--text2); margin-bottom: 12px; }
.report-row { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--border); }
.report-row:last-child { border-bottom: none; }
.report-row .name { font-size: .9rem; }
.report-row .amt { font-weight: 700; font-size: .95rem; }

.report-loading { text-align: center; color: var(--text2); padding: 40px; }
.spinner { display: inline-block; width: 28px; height: 28px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; margin-bottom: 10px; }
@keyframes spin { to { transform: rotate(360deg); } }

#screen-expense, #screen-report { display: none; }
#screen-expense.active, #screen-report.active { display: block; }

/* ── Password toggle ── */
.password-wrap { position: relative; }
.password-wrap input { padding-right: 46px; }
.btn-eye {
  position: absolute; right: 12px; top: 50%; transform: translateY(-50%);
  background: none; border: none; cursor: pointer; padding: 4px;
  color: var(--text2); display: flex; align-items: center;
  border-radius: 6px; transition: color .15s;
}
.btn-eye:hover { color: var(--text); }
