/* ─── RESET & BASE ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f0f2f8;
  --bg2: #e8eaf2;
  --surface: #ffffff;
  --text: #1a1a2e;
  --text2: #6b7280;
  --accent: #FFC107;
  --income: #4CAF50;
  --expense: #F44336;
  --blue: #4A90D9;
  --nav-h: 68px;
  --radius: 18px;
  --shadow: 0 4px 20px rgba(0,0,0,0.08);
}

html, body {
  font-family: 'Nunito', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

#app { padding-bottom: calc(var(--nav-h) + 8px); min-height: 100vh; }
a { text-decoration: none; color: inherit; }
button { cursor: pointer; border: none; background: none; font-family: inherit; }
.hidden { display: none !important; }

/* ─── COLOR UTILS ────────────────────────────────────────────────────────────── */
.income  { color: var(--income); }
.expense { color: var(--expense); }

/* ─── LOGIN ─────────────────────────────────────────────────────────────────── */
.login-page {
  background: linear-gradient(145deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; padding: 24px;
}
.login-container { width: 100%; max-width: 360px; }
.login-logo { text-align: center; margin-bottom: 40px; }
.login-icon { font-size: 60px; margin-bottom: 12px; animation: bounce 2s infinite; }
@keyframes bounce { 0%,100%{transform:translateY(0)} 50%{transform:translateY(-8px)} }
.login-logo h1 { color:#fff; font-size:26px; font-weight:900; margin-bottom:6px; }
.login-logo p  { color:rgba(255,255,255,0.5); font-size:14px; }
.login-form {
  background: rgba(255,255,255,0.05); border: 1px solid rgba(255,255,255,0.1);
  border-radius: 24px; padding: 28px; backdrop-filter: blur(10px);
}
.error-msg {
  background: rgba(244,67,54,0.15); border: 1px solid rgba(244,67,54,0.3);
  color: #ff6b6b; padding: 10px 14px; border-radius: 10px; margin-bottom: 16px; font-size: 14px;
}
.input-group { margin-bottom: 16px; }
.input-group label {
  display: block; color: rgba(255,255,255,0.6); font-size: 12px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 6px;
}
.input-group input {
  width: 100%; background: rgba(255,255,255,0.1); border: 1px solid rgba(255,255,255,0.2);
  border-radius: 12px; padding: 14px 16px; color: #fff; font-size: 16px;
  font-family: inherit; outline: none; transition: border-color 0.2s;
}
.input-group input::placeholder { color: rgba(255,255,255,0.3); }
.input-group input:focus { border-color: var(--accent); }
.btn-login {
  width: 100%; background: var(--accent); color: #1a1a2e; font-size: 16px; font-weight: 800;
  padding: 16px; border-radius: 14px; margin-top: 8px;
  box-shadow: 0 4px 20px rgba(255,193,7,0.4); transition: transform 0.1s;
}
.btn-login:active { transform: scale(0.97); }

/* ─── APP HEADER ─────────────────────────────────────────────────────────────── */
.app-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 52px 20px 12px; background: var(--bg);
  position: sticky; top: 0; z-index: 10;
}
.header-center { text-align: center; flex: 1; }
.header-label  { font-size: 12px; color: var(--text2); font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; }
.header-balance { font-size: 30px; font-weight: 900; color: var(--text); margin-top: 2px; }
.header-icon {
  width: 42px; height: 42px; display: flex; align-items: center; justify-content: center;
  background: var(--surface); border-radius: 14px; box-shadow: var(--shadow);
}
.header-icon svg { width: 20px; height: 20px; stroke: var(--text2); }

/* ─── PERIOD BAR ─────────────────────────────────────────────────────────────── */
.period-bar {
  display: flex; align-items: center; justify-content: center;
  gap: 8px; padding: 6px 20px;
}
.period-btn {
  flex: 1; background: var(--surface); border-radius: 30px; padding: 10px 20px;
  font-size: 13px; font-weight: 800; color: var(--text); letter-spacing: 0.5px;
  box-shadow: var(--shadow); display: flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid rgba(0,0,0,0.05);
}
.period-arrow {
  width: 36px; height: 36px; background: var(--surface); border-radius: 50%;
  font-size: 16px; color: var(--text2); box-shadow: var(--shadow); flex-shrink: 0;
}
.period-dropdown {
  background: var(--surface); margin: 4px 20px 0; border-radius: var(--radius);
  box-shadow: 0 8px 30px rgba(0,0,0,0.12); overflow: hidden; z-index: 20; position: relative;
}
.period-option {
  padding: 14px 20px; font-size: 15px; font-weight: 600; cursor: pointer;
  transition: background 0.15s; border-bottom: 1px solid rgba(0,0,0,0.04);
}
.period-option:last-child { border-bottom: none; }
.period-option:active { background: var(--bg); }
.custom-range {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 20px; background: var(--surface); margin: 4px 20px 0; border-radius: var(--radius);
}
.date-input {
  flex: 1; border: 1px solid rgba(0,0,0,0.1); border-radius: 10px;
  padding: 10px 12px; font-size: 14px; font-family: inherit; outline: none; background: var(--bg);
}
.btn-apply { background: var(--accent); color: #1a1a2e; font-weight: 800; padding: 10px 18px; border-radius: 10px; font-size: 14px; }

/* ─── CHART SECTION ─────────────────────────────────────────────────────────── */
.chart-section {
  display: flex; align-items: center; justify-content: center;
  padding: 8px 4px 12px; gap: 4px; min-height: 230px;
}
.categories-ring {
  flex: 1; display: flex; flex-direction: column;
  gap: 10px; align-items: center; max-width: 95px;
}
.cat-bubble {
  display: flex; flex-direction: column; align-items: center;
  cursor: pointer; transition: transform 0.15s;
}
.cat-bubble:active { transform: scale(0.90); }
.cat-circle {
  width: 54px; height: 54px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 24px; margin-bottom: 4px;
  box-shadow: 0 3px 12px rgba(0,0,0,0.15);
  cursor: pointer; transition: transform 0.1s;
}
.cat-circle:active { transform: scale(0.88); }
.add-circle {
  background: var(--bg2) !important;
  color: var(--text2);
  font-size: 26px;
  font-weight: 300;
  border: 2px dashed var(--text2);
}
.cat-name {
  font-size: 12px; font-weight: 700; color: var(--text2);
  text-align: center; max-width: 86px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.cat-amount { font-size: 13px; font-weight: 900; text-align: center; margin-top: 2px; }

/* ─── DONUT ──────────────────────────────────────────────────────────────────── */
.donut-wrapper { position: relative; width: 180px; height: 180px; flex-shrink: 0; }
#donutChart { width: 180px !important; height: 180px !important; }
.donut-center {
  position: absolute; top: 50%; left: 50%;
  transform: translate(-50%, -50%); text-align: center; pointer-events: none;
}
.donut-label { font-size: 11px; color: var(--text2); font-weight: 700; text-transform: uppercase; letter-spacing: 0.3px; }
.donut-amount { font-size: 17px; font-weight: 900; line-height: 1.2; }
.donut-amount.income  { color: var(--income); }
.donut-amount.expense { color: var(--expense); }
.donut-amount2 { font-size: 12px; font-weight: 700; opacity: 0.65; }
.donut-amount2.income  { color: var(--income); }
.donut-amount2.expense { color: var(--expense); }

/* ─── ADD FAB ────────────────────────────────────────────────────────────────── */
.add-btn-container { display: flex; justify-content: center; padding: 4px 0 12px; }
.add-fab {
  width: 64px; height: 64px; border-radius: 50%; background: var(--accent);
  box-shadow: 0 6px 24px rgba(255,193,7,0.5);
  display: flex; align-items: center; justify-content: center;
  transition: transform 0.15s, box-shadow 0.2s;
}
.add-fab:active { transform: scale(0.88); box-shadow: 0 2px 12px rgba(255,193,7,0.3); }

/* ─── BOTTOM NAV ─────────────────────────────────────────────────────────────── */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; height: var(--nav-h);
  background: var(--surface); display: flex; align-items: center;
  box-shadow: 0 -2px 20px rgba(0,0,0,0.08); z-index: 50;
  padding: 0 4px; border-top: 1px solid rgba(0,0,0,0.05);
}
.nav-item {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  gap: 4px; padding: 8px 4px; color: var(--text2);
  font-size: 10px; font-weight: 700; transition: color 0.2s;
}
.nav-item svg { width: 22px; height: 22px; stroke: currentColor; }
.nav-item.active { color: var(--accent); }

/* ─── MODAL OVERLAY ─────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.45);
  z-index: 100; display: flex; align-items: flex-end;
  backdrop-filter: blur(3px);
}
.modal-sheet {
  background: var(--bg); width: 100%; border-radius: 28px 28px 0 0;
  max-height: 96vh; overflow-y: auto;
  animation: slideUp 0.3s cubic-bezier(0.34,1.56,0.64,1);
}
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }

.modal-drag-bar {
  width: 40px; height: 4px; background: rgba(0,0,0,0.15);
  border-radius: 2px; margin: 12px auto 0;
}
.modal-title {
  font-size: 17px; font-weight: 800; text-align: center;
  padding: 14px 16px 8px; color: var(--text);
}
.modal-nav-row {
  display: flex; align-items: center; padding: 8px 12px 4px;
}
.modal-back-btn {
  width: 36px; height: 36px; background: var(--bg2); border-radius: 50%;
  font-size: 22px; color: var(--text2); display: flex; align-items: center; justify-content: center;
}
.modal-step { padding-bottom: 8px; }

/* ─── TYPE BUTTONS ───────────────────────────────────────────────────────────── */
.modal-type-row { display: flex; gap: 10px; padding: 8px 16px 4px; }
.modal-type-btn {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 16px 12px; border-radius: 16px; font-size: 16px; font-weight: 800;
  background: var(--surface); color: var(--text2); transition: all 0.2s;
  box-shadow: var(--shadow);
}
.modal-type-btn.active[data-type="expense"],
.modal-type-btn[data-type="expense"]:active { background: rgba(244,67,54,0.12); color: var(--expense); }
.modal-type-btn.active[data-type="income"],
.modal-type-btn[data-type="income"]:active  { background: rgba(76,175,80,0.12);  color: var(--income); }

/* ─── CATEGORY PICK GRID ─────────────────────────────────────────────────────── */
.cat-pick-grid {
  display: flex; flex-wrap: wrap;
  gap: 10px; padding: 8px 16px 8px; max-height: 55vh; overflow-y: auto;
}
.cat-pick-item {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  background: var(--surface); border-radius: 16px; padding: 14px 6px;
  cursor: pointer; transition: transform 0.1s; border: 2px solid transparent;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
  width: calc(33.33% - 7px);
}
.cat-pick-item:active { transform: scale(0.92); border-color: var(--accent); }
.cat-pick-circle {
  width: 48px; height: 48px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; font-size: 22px;
}
.cat-pick-name { font-size: 11px; font-weight: 700; text-align: center; color: var(--text); width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ─── MODAL SPLIT HEADER ─────────────────────────────────────────────────────── */
.split-head-table { width: 100%; border-collapse: collapse; }
.split-td {
  width: 50%; text-align: center; padding: 14px 8px;
  cursor: pointer; vertical-align: middle;
}
.split-td-account { background: #4A90D9; }
.split-td-cat { background: #4A90D9; }
.split-icon { font-size: 26px; margin-bottom: 4px; }
.split-sublabel { font-size: 11px; font-weight: 700; color: rgba(255,255,255,0.8); text-transform: uppercase; letter-spacing: 0.5px; }
.split-mainlabel { font-size: 18px; font-weight: 900; color: #fff; margin-top: 2px; }

/* ─── CALCULATOR DISPLAY ─────────────────────────────────────────────────────── */
.calc-display { padding: 14px 16px 8px; text-align: center; }
.calc-label {
  font-size: 13px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.5px; color: var(--expense); margin-bottom: 2px;
}
.calc-amount-wrap { font-size: 40px; font-weight: 900; color: var(--text); line-height: 1.1; margin-bottom: 10px; }
.calc-currency { font-size: 28px; font-weight: 700; }
.calc-note {
  width: 100%; background: var(--surface); border: 1px solid rgba(0,0,0,0.08);
  border-radius: 14px; padding: 12px 16px; font-size: 15px; font-family: inherit;
  outline: none; color: var(--text); text-align: center;
}

/* ─── NUMPAD (table layout - visuzticamākais cross-browser) ─────────────────── */
.numpad-table {
  width: 100%; border-collapse: separate; border-spacing: 6px;
  padding: 6px 10px 2px; table-layout: fixed;
}
.numpad-table td { padding: 0; }
.nb {
  width: 100%; height: 54px; border-radius: 13px; font-size: 20px; font-weight: 700;
  background: var(--surface); color: var(--text);
  box-shadow: 0 2px 8px rgba(0,0,0,0.07);
  border: none; font-family: inherit; cursor: pointer;
  transition: transform 0.08s, background 0.1s;
}
.nb:active { transform: scale(0.88); background: var(--bg2); }
.nb.op  { background: var(--bg2); color: var(--text2); }
.nb.del { background: var(--bg2); color: var(--expense); }
.nb.confirm {
  width: 100%; height: 100%;
  background: var(--accent); color: #1a1a2e;
  font-size: 34px; font-weight: 900; border-radius: 13px;
  box-shadow: 0 4px 16px rgba(255,193,7,0.4);
}
.nb.confirm:active { background: #e6a800; transform: scale(0.95); }

.calc-date-row { padding: 6px 12px 12px; }
.date-input-inline {
  width: 100%; border: 1px solid rgba(0,0,0,0.1); border-radius: 14px;
  padding: 12px 16px; font-size: 15px; font-family: inherit;
  outline: none; background: var(--surface); text-align: center; color: var(--text2);
}

.modal-close {
  display: block; width: calc(100% - 32px); margin: 8px 16px 12px;
  padding: 14px; border-radius: 14px; background: rgba(0,0,0,0.05);
  color: var(--text2); font-size: 14px; font-weight: 700; text-align: center;
}

/* ─── ACCOUNT PICKER ─────────────────────────────────────────────────────────── */
.mini-modal {
  position: fixed; bottom: 0; left: 0; right: 0; background: var(--bg);
  border-radius: 28px 28px 0 0; padding: 20px 16px 40px;
  box-shadow: 0 -8px 40px rgba(0,0,0,0.2); max-height: 70vh; overflow-y: auto;
  animation: slideUp 0.25s ease;
}
.mini-modal-title { font-size: 17px; font-weight: 800; margin-bottom: 16px; text-align: center; color: var(--text); }
.mini-modal-cancel { width: 100%; padding: 14px; border-radius: 14px; margin-top: 12px; background: rgba(0,0,0,0.06); color: var(--text2); font-size: 15px; font-weight: 700; }
#account-list { display: flex; flex-direction: column; gap: 8px; }
.account-item {
  display: flex; align-items: center; gap: 12px; background: var(--surface);
  border-radius: 14px; padding: 14px 16px; cursor: pointer; transition: transform 0.1s;
}
.account-item:active { transform: scale(0.97); }
.account-dot { width: 14px; height: 14px; border-radius: 50%; flex-shrink: 0; }
.account-name { font-size: 16px; font-weight: 700; flex: 1; }
.account-bal { font-size: 14px; font-weight: 700; color: var(--text2); }

/* ─── CATEGORY ADD MODAL ─────────────────────────────────────────────────────── */
.picker-label {
  font-size: 12px; font-weight: 700; color: var(--text2);
  text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 8px;
}
.emoji-grid { display: flex; flex-wrap: wrap; gap: 8px; max-height: 110px; overflow-y: auto; }
.emoji-opt {
  width: 40px; height: 40px; display: flex; align-items: center; justify-content: center;
  font-size: 22px; border-radius: 10px; cursor: pointer; background: var(--surface);
  border: 2px solid transparent; transition: border-color 0.15s;
}
.emoji-opt.selected { border-color: var(--accent); }
.color-grid { display: flex; flex-wrap: wrap; gap: 10px; }
.color-opt {
  width: 34px; height: 34px; border-radius: 50%; cursor: pointer;
  border: 3px solid transparent; outline: 2px solid transparent; transition: outline 0.15s;
}
.color-opt.selected { outline: 2px solid var(--text); outline-offset: 2px; }
.btn-save {
  width: 100%; background: var(--accent); color: #1a1a2e;
  font-size: 16px; font-weight: 800; padding: 16px; border-radius: 14px;
  border: none; cursor: pointer; margin-bottom: 8px;
}

/* ─── TRANSACTIONS ───────────────────────────────────────────────────────────── */
.txn-summary-bar {
  display: flex; margin: 8px 16px; background: var(--surface);
  border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden;
}
.txn-sum { flex: 1; padding: 14px; text-align: center; }
.txn-sum span { display: block; font-size: 11px; color: var(--text2); font-weight: 700; text-transform: uppercase; }
.txn-sum strong { font-size: 18px; font-weight: 900; }
.txn-sum.income strong  { color: var(--income); }
.txn-sum.expense strong { color: var(--expense); }

.txn-list { padding: 0 16px 16px; }
.txn-day-group { margin-bottom: 8px; }
.txn-date-header { font-size: 12px; font-weight: 700; color: var(--text2); text-transform: uppercase; letter-spacing: 0.5px; padding: 8px 4px 6px; }
.txn-row {
  display: flex; align-items: center; gap: 12px; background: var(--surface);
  border-radius: 14px; padding: 12px 14px; margin-bottom: 6px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.04);
}
.txn-cat-circle { width: 44px; height: 44px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 20px; flex-shrink: 0; }
.txn-info { flex: 1; min-width: 0; }
.txn-cat-name { font-size: 15px; font-weight: 700; }
.txn-note { font-size: 12px; color: var(--text2); margin-top: 2px; }
.txn-account { font-size: 11px; color: var(--text2); }
.txn-amount { font-size: 17px; font-weight: 900; flex-shrink: 0; }
.txn-amount.income  { color: var(--income); }
.txn-amount.expense { color: var(--expense); }
.txn-del { width: 28px; height: 28px; border-radius: 50%; background: rgba(244,67,54,0.1); color: var(--expense); font-size: 12px; flex-shrink: 0; }

/* ─── REPORTS ────────────────────────────────────────────────────────────────── */
.reports-page { padding: 8px 16px; }
.report-card { background: var(--surface); border-radius: var(--radius); padding: 20px; margin-bottom: 16px; box-shadow: var(--shadow); }
.report-card h3 { font-size: 15px; font-weight: 800; margin-bottom: 16px; color: var(--text); }
.legend-item { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid rgba(0,0,0,0.05); }
.legend-item:last-child { border-bottom: none; }
.legend-dot { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; }
.legend-name { flex: 1; font-size: 14px; font-weight: 600; }
.legend-val  { font-size: 14px; font-weight: 800; }

/* ─── SETTINGS ───────────────────────────────────────────────────────────────── */
.settings-content { padding: 0 16px 16px; }
.settings-section { margin-bottom: 20px; }
.settings-title { font-size: 13px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text2); margin-bottom: 10px; padding: 0 4px; }
.settings-row {
  display: flex; align-items: center; gap: 12px; background: var(--surface);
  border-radius: 14px; padding: 12px 14px; margin-bottom: 6px; box-shadow: var(--shadow);
}
.settings-circle { width: 40px; height: 40px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 18px; flex-shrink: 0; }
.settings-balance { font-size: 13px; color: var(--text2); font-weight: 600; margin-left: auto; }
.add-settings-btn {
  width: 100%; padding: 14px; border-radius: 14px;
  background: rgba(255,193,7,0.1); color: var(--accent);
  font-size: 14px; font-weight: 800; border: 2px dashed rgba(255,193,7,0.4);
  margin-bottom: 4px;
}
.del-btn { width: 28px; height: 28px; border-radius: 50%; background: rgba(244,67,54,0.1); color: var(--expense); font-size: 12px; margin-left: auto; }
.logout-btn {
  display: block; width: 100%; padding: 14px; border-radius: 14px;
  background: rgba(244,67,54,0.08); color: var(--expense);
  font-size: 15px; font-weight: 800; text-align: center;
}

/* ─── HEADER FOR INNER PAGES ─────────────────────────────────────────────────── */
.page-header {
  display: flex; align-items: center; padding: 52px 16px 12px;
  background: var(--bg); position: sticky; top: 0; z-index: 10;
}
.page-header-title { flex: 1; text-align: center; font-size: 18px; font-weight: 900; }
.page-back-btn {
  width: 38px; height: 38px; background: var(--surface); border-radius: 12px;
  font-size: 20px; color: var(--text2); box-shadow: var(--shadow);
  display: flex; align-items: center; justify-content: center;
}

/* ─── TOAST ──────────────────────────────────────────────────────────────────── */
.toast {
  position: fixed; top: 24px; left: 50%; transform: translateX(-50%) translateY(-100px);
  background: #1a1a2e; color: #fff; padding: 12px 24px; border-radius: 30px;
  font-size: 14px; font-weight: 700; z-index: 999;
  transition: transform 0.35s cubic-bezier(0.34,1.56,0.64,1);
  box-shadow: 0 8px 30px rgba(0,0,0,0.3); white-space: nowrap; pointer-events: none;
}
.toast.show { transform: translateX(-50%) translateY(0); }

/* ─── EMPTY / LOADING ────────────────────────────────────────────────────────── */
.empty-state { text-align: center; padding: 60px 20px; color: var(--text2); font-size: 15px; font-weight: 600; }
.loading { text-align: center; padding: 40px; color: var(--text2); font-size: 15px; font-weight: 600; }
