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

:root {
  --bg:        #0f172a;
  --bg2:       #1e293b;
  --bg3:       #334155;
  --border:    #334155;
  --text:      #f1f5f9;
  --text2:     #94a3b8;
  --primary:   #6366f1;
  --primary-h: #4f46e5;
  --danger:    #ef4444;
  --success:   #10b981;
  --radius:    12px;
  --nav-h:     64px;
  --header-h:  56px;
  font-size: 16px;
}

html, body { height: 100%; overflow: hidden; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

/* ── Utilities ──────────────────────────────────────────────────────────── */
.hidden  { display: none !important; }
.error   { color: var(--danger); font-size: .85rem; margin-top: 4px; }
.mt-16   { margin-top: 16px; }

/* ── Login ──────────────────────────────────────────────────────────────── */
#view-login {
  display: flex; align-items: center; justify-content: center;
  height: 100%; background: var(--bg);
}
.login-wrap {
  display: flex; flex-direction: column; gap: 12px;
  width: min(360px, 90vw); padding: 32px 24px;
  background: var(--bg2); border-radius: var(--radius);
  border: 1px solid var(--border);
}
.login-logo { font-size: 2.5rem; text-align: center; }
.login-wrap h1 { text-align: center; font-size: 1.4rem; }
.login-sub { text-align: center; color: var(--text2); font-size: .9rem; }

/* ── App shell ──────────────────────────────────────────────────────────── */
#app { display: flex; flex-direction: column; height: 100%; }

header {
  height: var(--header-h);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px;
  background: var(--bg2); border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
header h1 { font-size: 1.1rem; font-weight: 600; }

main {
  flex: 1; overflow-y: auto; overflow-x: hidden;
  padding: 16px 16px calc(var(--nav-h) + 16px);
}

/* ── Bottom nav ─────────────────────────────────────────────────────────── */
.bottom-nav {
  height: var(--nav-h);
  display: flex; background: var(--bg2); border-top: 1px solid var(--border);
  flex-shrink: 0; position: relative; z-index: 10;
}
.nav-btn {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 2px;
  background: none; border: none; color: var(--text2);
  font-size: .7rem; cursor: pointer; transition: color .15s;
}
.nav-btn.active { color: var(--primary); }
.nav-icon { font-size: 1.3rem; }

/* ── View sections ──────────────────────────────────────────────────────── */
.view-section { display: none; }
.view-section.active { display: block; }

/* ── Buttons ────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 18px; border-radius: 8px; border: none;
  font-size: .9rem; font-weight: 500; cursor: pointer; transition: background .15s, opacity .15s;
  text-decoration: none;
}
.btn-primary  { background: var(--primary); color: #fff; }
.btn-primary:hover  { background: var(--primary-h); }
.btn-outline  { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn-outline:hover  { background: var(--bg3); }
.btn-danger   { background: var(--danger); color: #fff; }
.btn-full     { width: 100%; }
.btn-sm       { padding: 6px 12px; font-size: .8rem; }
.btn-icon     { width: 36px; height: 36px; padding: 0; border-radius: 50%; font-size: 1.2rem;
                background: var(--primary); color: #fff; }

/* ── Inputs ─────────────────────────────────────────────────────────────── */
label {
  display: flex; flex-direction: column; gap: 6px;
  font-size: .85rem; color: var(--text2); font-weight: 500;
}
input[type="text"], input[type="number"], input[type="date"],
input[type="password"], select, textarea {
  width: 100%; padding: 10px 12px;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text); font-size: .95rem;
  outline: none; transition: border-color .15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); }
input[type="color"] {
  width: 100%; height: 42px; padding: 2px 4px;
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
  cursor: pointer;
}
select option { background: var(--bg2); }

.input-currency { position: relative; }
.input-currency input { padding-right: 36px; }
.currency-badge {
  position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
  color: var(--text2); font-size: .85rem; pointer-events: none;
}

/* ── Rate banner ────────────────────────────────────────────────────────── */
.rate-banner {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 8px 14px;
  font-size: .82rem; color: var(--text2); margin-bottom: 16px;
  text-align: center;
}

/* ── Totals grid ────────────────────────────────────────────────────────── */
#totals-grid {
  display: grid; gap: 12px;
  grid-template-columns: 1fr;
}
@media (min-width: 600px) { #totals-grid { grid-template-columns: 1fr 1fr; } }
@media (min-width: 900px) { #totals-grid { grid-template-columns: 1fr 1fr 1fr; } }

.total-card {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px;
}
.total-card-header {
  display: flex; align-items: center; gap: 8px; margin-bottom: 10px;
}
.total-card-icon { font-size: 1.3rem; }
.total-card-name { font-weight: 600; flex: 1; }
.total-card-count { font-size: .75rem; color: var(--text2); }
.total-card-amounts {
  display: flex; justify-content: space-between; align-items: flex-end;
  margin-bottom: 8px;
}
.spent-amount { font-size: 1.25rem; font-weight: 700; }
.limit-amount { font-size: .82rem; color: var(--text2); }
.progress-bar {
  height: 6px; background: var(--bg3); border-radius: 99px; overflow: hidden;
}
.progress-fill {
  height: 100%; border-radius: 99px; transition: width .4s ease;
}
.total-card-diff {
  margin-top: 6px; font-size: .78rem;
  display: flex; justify-content: flex-end;
}
.diff-ok  { color: var(--success); }
.diff-bad { color: var(--danger); }

/* ── Section header ─────────────────────────────────────────────────────── */
.section-header {
  display: flex; align-items: center; justify-content: space-between;
  margin: 20px 0 12px;
}
.section-header h2 { font-size: 1rem; font-weight: 600; }

/* ── Expense cards ──────────────────────────────────────────────────────── */
.expense-card {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 14px; margin-bottom: 10px;
  cursor: pointer; transition: border-color .15s;
}
.expense-card:hover { border-color: var(--primary); }
.expense-card-top {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 8px;
}
.expense-card-left { flex: 1; min-width: 0; }
.expense-card-concept {
  font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.expense-card-meta { font-size: .78rem; color: var(--text2); margin-top: 2px; }
.expense-card-amount {
  font-weight: 700; font-size: 1.05rem; text-align: right; white-space: nowrap;
}
.expense-card-nzd { font-size: .75rem; color: var(--text2); text-align: right; }
.expense-card-cat {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: .72rem; padding: 2px 8px; border-radius: 99px;
  background: var(--bg3); margin-top: 6px;
}
.expense-card-images {
  display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap;
}
.expense-thumb {
  width: 48px; height: 48px; border-radius: 6px;
  object-fit: cover; cursor: pointer; border: 1px solid var(--border);
}
.expense-card-actions {
  display: flex; gap: 6px; margin-top: 10px; justify-content: flex-end;
}

/* ── Filter bar ─────────────────────────────────────────────────────────── */
#filter-bar { margin-bottom: 14px; }
#filter-bar select { font-size: .9rem; }

/* ── Category list ──────────────────────────────────────────────────────── */
.category-item {
  display: flex; align-items: center; gap: 12px;
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 14px; margin-bottom: 10px;
}
.category-item-icon {
  width: 40px; height: 40px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.3rem; flex-shrink: 0;
}
.category-item-info { flex: 1; min-width: 0; }
.category-item-name { font-weight: 600; }
.category-item-limit { font-size: .82rem; color: var(--text2); }
.category-item-actions { display: flex; gap: 6px; }

/* ── Amount row ─────────────────────────────────────────────────────────── */
.amount-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ── Conversion preview ─────────────────────────────────────────────────── */
.conversion-preview {
  background: var(--bg3); border-radius: 8px; padding: 8px 12px;
  font-size: .82rem; color: var(--text2);
}

/* ── Image actions ──────────────────────────────────────────────────────── */
.image-actions { display: flex; gap: 8px; }
.image-previews { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.preview-wrap {
  position: relative; width: 72px; height: 72px;
}
.preview-wrap img {
  width: 72px; height: 72px; border-radius: 8px;
  object-fit: cover; border: 1px solid var(--border);
}
.preview-remove {
  position: absolute; top: -6px; right: -6px;
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--danger); color: #fff; border: none;
  font-size: .7rem; cursor: pointer; display: flex;
  align-items: center; justify-content: center; line-height: 1;
}

/* ── Form layout ────────────────────────────────────────────────────────── */
#form-expense, #form-category {
  display: flex; flex-direction: column; gap: 14px;
  overflow-y: auto; max-height: calc(85vh - 60px); padding-bottom: 8px;
}
.form-actions { display: flex; gap: 10px; justify-content: flex-end; padding-top: 4px; }
.row-2col { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ── Modals ─────────────────────────────────────────────────────────────── */
.modal {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: flex-end; justify-content: center;
}
.modal-backdrop {
  position: absolute; inset: 0;
  background: rgba(0,0,0,.6); backdrop-filter: blur(2px);
}
.modal-sheet {
  position: relative; width: 100%; max-width: 560px;
  background: var(--bg2); border-radius: var(--radius) var(--radius) 0 0;
  border-top: 1px solid var(--border);
  padding: 16px 20px 32px; max-height: 90vh;
  display: flex; flex-direction: column; gap: 14px;
  animation: slideUp .25s ease;
}
@media (min-width: 600px) {
  .modal { align-items: center; }
  .modal-sheet { border-radius: var(--radius); border: 1px solid var(--border); }
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
}
.modal-header h2 { font-size: 1.1rem; font-weight: 600; }
.modal-close {
  width: 30px; height: 30px; border-radius: 50%; border: none;
  background: var(--bg3); color: var(--text); font-size: .9rem;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.modal-image-wrap {
  position: relative; display: flex; align-items: center; justify-content: center;
  width: 100%; height: 100%; z-index: 1;
}
.modal-image-wrap img { max-width: 95vw; max-height: 90vh; border-radius: var(--radius); }
.modal-close-light {
  position: absolute; top: 12px; right: 12px;
  background: rgba(0,0,0,.7); color: #fff;
}

/* ── Empty states ───────────────────────────────────────────────────────── */
.empty-state {
  text-align: center; padding: 40px 20px; color: var(--text2);
}
.empty-state-icon { font-size: 2.5rem; margin-bottom: 8px; }

/* ── Loading skeleton ───────────────────────────────────────────────────── */
.skeleton {
  background: linear-gradient(90deg, var(--bg2) 25%, var(--bg3) 50%, var(--bg2) 75%);
  background-size: 200% 100%; border-radius: 8px;
  animation: shimmer 1.4s infinite;
}

@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
