:root {
  --bg: #f3f6f5;
  --card: #ffffff;
  --text: #13211e;
  --muted: #687670;
  --primary: #0b6b5f;
  --primary-dark: #07554c;
  --primary-soft: #e9f7f4;
  --income: #187a43;
  --income-soft: #eaf8ef;
  --expense: #b44d25;
  --expense-soft: #fff2ec;
  --danger: #a43a32;
  --border: #dce5e1;
  --shadow: 0 14px 35px rgba(13, 65, 57, 0.08);
  --radius-lg: 22px;
  --radius-md: 14px;
}

* { box-sizing: border-box; }
html { color-scheme: light; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at top right, rgba(11, 107, 95, .08), transparent 32rem),
    var(--bg);
  color: var(--text);
}
body.modal-open { overflow: hidden; }
button, input, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .55; }
h1, h2, h3, h4, p { margin-top: 0; }
[hidden] { display: none !important; }

.app-shell { width: min(100%, 820px); margin: 0 auto; padding: 18px 16px 36px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 18px; }
.brand-row, .header-actions { display: flex; align-items: center; gap: 11px; }
.brand-mark {
  width: 62px;
  height: 62px;
  display: grid;
  place-items: center;
  border-radius: 20px;
  background: linear-gradient(145deg, #0d7568, #07564d);
  color: white;
  font-size: 1.75rem;
  font-weight: 950;
  box-shadow: 0 12px 25px rgba(11, 107, 95, .24);
}
.brand-mark.small { width: 43px; height: 43px; border-radius: 14px; font-size: 1.2rem; }
h1 { margin-bottom: 0; font-size: 1.45rem; letter-spacing: -.02em; }
.eyebrow { margin-bottom: 4px; color: var(--muted); font-size: .72rem; text-transform: uppercase; letter-spacing: .09em; font-weight: 850; }
.muted { color: var(--muted); }
.small-text { font-size: .84rem; line-height: 1.5; }
.optional { color: var(--muted); font-size: .75rem; font-weight: 600; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

.icon-btn {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 13px;
  background: rgba(255,255,255,.86);
  color: var(--text);
  font-weight: 900;
  box-shadow: 0 6px 18px rgba(20, 56, 51, .06);
}
.icon-btn:hover { border-color: #a8c7c0; background: white; }

.summary-card {
  background: linear-gradient(145deg, #0c7467, #07564d);
  color: white;
  border-radius: 26px;
  padding: 24px;
  box-shadow: 0 18px 38px rgba(8, 81, 72, .20);
  margin-bottom: 14px;
}
.summary-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.summary-head p { opacity: .78; margin-bottom: 6px; }
.summary-card h2 { font-size: clamp(1.85rem, 7vw, 2.45rem); margin-bottom: 20px; letter-spacing: -.04em; }
.balance-badge { padding: 7px 10px; border-radius: 999px; background: rgba(255,255,255,.13); font-size: .74rem; font-weight: 800; white-space: nowrap; }
.summary-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.summary-grid div { background: rgba(255,255,255,.10); padding: 13px; border-radius: 15px; }
.summary-grid span { display: block; font-size: .78rem; opacity: .78; margin-bottom: 5px; }
.summary-grid strong { font-size: 1rem; }
.period-switch { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; margin-top: 14px; padding: 5px; border-radius: 14px; background: rgba(0,0,0,.10); }
.period-btn { border: 0; border-radius: 10px; padding: 9px 6px; background: transparent; color: rgba(255,255,255,.76); font-size: .78rem; font-weight: 800; }
.period-btn.active { background: white; color: var(--primary); box-shadow: 0 5px 15px rgba(0,0,0,.10); }

.quick-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 18px; }
.quick-stats article { min-width: 0; padding: 14px; background: rgba(255,255,255,.82); border: 1px solid var(--border); border-radius: 17px; box-shadow: 0 8px 24px rgba(13, 65, 57, .05); }
.quick-stats span { display: block; margin-bottom: 5px; color: var(--muted); font-size: .72rem; }
.quick-stats strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .92rem; }

.panel { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 19px; box-shadow: var(--shadow); margin-bottom: 18px; }
.panel-title, .history-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.panel h3 { margin-bottom: 16px; font-size: 1.12rem; }
.panel-title .text-btn { margin-top: -10px; }

.type-switch { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 16px; }
.type-btn, .filter-btn, .ghost-btn {
  border: 1px solid var(--border);
  background: white;
  border-radius: 12px;
  padding: 11px 12px;
  font-weight: 800;
  color: var(--muted);
}
.type-btn.active.income { color: var(--income); background: var(--income-soft); border-color: #b8dfc6; }
.type-btn.active.expense { color: var(--expense); background: var(--expense-soft); border-color: #edc4b4; }
.ghost-btn:hover { border-color: #a8c7c0; color: var(--primary); }
.full-width { width: 100%; margin-top: 12px; }
.danger-outline { color: var(--danger); border-color: #e3b8b3; }
.danger-outline:hover { color: #842e28; border-color: #ce8c85; background: #fff7f6; }

label { display: block; font-size: .86rem; font-weight: 760; margin-bottom: 14px; }
input, select {
  width: 100%;
  margin-top: 7px;
  border: 1px solid var(--border);
  background: #fbfcfc;
  border-radius: 13px;
  padding: 13px 14px;
  outline: none;
  color: var(--text);
}
input:focus, select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(11,107,95,.12); background: white; }
input::placeholder { color: #9aa5a1; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.photo-field input, .file-button input { position: absolute; opacity: 0; pointer-events: none; width: 1px; height: 1px; }
.photo-field span {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 54px;
  margin-top: 7px;
  border: 1.5px dashed #b5c8c2;
  border-radius: 13px;
  background: #f7fbfa;
  color: var(--primary);
  text-align: center;
  padding: 10px;
}
.photo-preview-wrap { display: flex; align-items: center; gap: 12px; margin: -3px 0 15px; padding: 10px; border: 1px solid var(--border); border-radius: 14px; background: #f8faf9; }
.photo-preview-wrap img { width: 62px; height: 62px; object-fit: cover; border-radius: 11px; border: 1px solid var(--border); }
.primary-btn { width: 100%; border: 0; border-radius: 14px; background: var(--primary); color: white; padding: 14px; font-weight: 900; box-shadow: 0 9px 20px rgba(11,107,95,.16); }
.primary-btn:hover { background: var(--primary-dark); }
.text-btn { border: 0; padding: 6px 0; background: transparent; color: var(--primary); font-weight: 800; }
.text-btn.danger { color: var(--danger); }
.form-error { min-height: 1.1em; margin: 0 0 10px; color: var(--danger); font-size: .82rem; font-weight: 700; }

.search-row { display: grid; grid-template-columns: 1fr 165px; gap: 9px; margin-bottom: 10px; }
.search-row label { margin: 0; }
.search-row input { margin: 0; padding: 11px 12px; }
.filters { display: flex; gap: 8px; overflow-x: auto; margin-bottom: 14px; scrollbar-width: none; }
.filters::-webkit-scrollbar { display: none; }
.filter-btn { white-space: nowrap; padding: 8px 12px; font-size: .8rem; }
.filter-btn.active { color: var(--primary); border-color: #98cdc4; background: var(--primary-soft); }
.empty-state { text-align: center; padding: 32px 12px; color: var(--muted); }
.empty-state p { margin-bottom: 4px; font-weight: 800; color: var(--text); }
.empty-icon { font-size: 2rem; margin-bottom: 10px; }
.transaction-list { display: grid; gap: 10px; }
.transaction-item { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 11px; border: 1px solid var(--border); border-radius: 17px; padding: 12px; background: #fff; }
.transaction-item:hover { border-color: #c6d7d2; }
.transaction-icon { width: 43px; height: 43px; display: grid; place-items: center; border-radius: 13px; font-weight: 950; }
.transaction-icon.income { background: var(--income-soft); color: var(--income); }
.transaction-icon.expense { background: var(--expense-soft); color: var(--expense); }
.transaction-info { min-width: 0; }
.transaction-info strong { display: block; margin-bottom: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.transaction-info small { display: block; color: var(--muted); line-height: 1.45; }
.transaction-side { text-align: right; }
.transaction-amount { font-weight: 900; white-space: nowrap; }
.transaction-amount.income { color: var(--income); }
.transaction-amount.expense { color: var(--expense); }
.item-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 5px; }
.item-action { border: 0; background: transparent; color: var(--primary); font-size: .75rem; font-weight: 800; padding: 2px 0; }
.item-action.delete { color: var(--danger); }
.receipt-thumb { width: 35px; height: 35px; border-radius: 8px; object-fit: cover; border: 1px solid var(--border); margin-top: 6px; cursor: zoom-in; }
footer { text-align: center; color: var(--muted); font-size: .78rem; line-height: 1.5; padding: 0 12px; }

.lock-screen { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 18px; background: radial-gradient(circle at top, #eaf7f4, #f4f6f5 48%, #eef2f0); }
.lock-card { width: min(100%, 390px); padding: 28px; border: 1px solid var(--border); border-radius: 26px; background: rgba(255,255,255,.95); text-align: center; box-shadow: 0 24px 70px rgba(13,65,57,.14); }
.lock-card .brand-mark { margin: 0 auto 18px; }
.lock-card h1 { margin-bottom: 8px; font-size: 1.8rem; }
.pin-form { text-align: left; margin-top: 22px; }
.pin-form input { text-align: center; letter-spacing: .45em; font-size: 1.2rem; }

.modal { position: fixed; inset: 0; z-index: 80; display: grid; place-items: center; padding: 16px; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(10, 27, 24, .62); backdrop-filter: blur(4px); }
.modal-card { position: relative; width: min(100%, 560px); max-height: min(88vh, 760px); overflow: auto; background: white; border-radius: 23px; padding: 21px; box-shadow: 0 30px 80px rgba(0,0,0,.24); }
.modal-card.compact { width: min(100%, 420px); }
.modal-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 18px; }
.modal-head h3 { margin-bottom: 0; }
.settings-section { padding: 17px 0; border-top: 1px solid var(--border); }
.settings-section:first-of-type { border-top: 0; padding-top: 0; }
.settings-section h4 { margin-bottom: 6px; }
.settings-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.file-button { display: inline-flex; align-items: center; margin: 0; font-size: 1rem; }
.danger-zone { margin-top: 4px; }
.photo-modal-card { position: relative; max-width: min(94vw, 900px); max-height: 90vh; }
.photo-modal-card img { display: block; max-width: 100%; max-height: 86vh; border-radius: 16px; box-shadow: 0 25px 70px rgba(0,0,0,.32); }
.photo-close { position: absolute; top: -13px; right: -13px; z-index: 2; width: 38px; height: 38px; border: 0; border-radius: 50%; background: white; color: var(--text); font-size: 1.5rem; box-shadow: 0 8px 20px rgba(0,0,0,.2); }
.toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); z-index: 120; transform: translateX(-50%); max-width: calc(100vw - 32px); padding: 12px 16px; border-radius: 13px; background: #143a34; color: white; box-shadow: 0 15px 35px rgba(0,0,0,.22); font-size: .86rem; font-weight: 750; text-align: center; }

@media (max-width: 620px) {
  .app-shell { padding: 14px 12px 28px; }
  .summary-card { padding: 20px; border-radius: 22px; }
  .quick-stats { grid-template-columns: 1fr 1fr; }
  .quick-stats article:last-child { grid-column: 1 / -1; }
  .panel { border-radius: 19px; padding: 15px; }
  .form-row { grid-template-columns: 1fr; gap: 0; }
  .search-row { grid-template-columns: 1fr; }
  .history-header { align-items: flex-start; }
  .ghost-btn { padding: 9px 10px; font-size: .8rem; }
  .transaction-item { grid-template-columns: auto minmax(0,1fr); }
  .transaction-side { grid-column: 2; text-align: left; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
  .item-actions { margin: 0; }
}

@media (max-width: 390px) {
  .brand-mark.small { display: none; }
  .summary-head { display: block; }
  .balance-badge { display: inline-block; margin-bottom: 10px; }
  .summary-grid { grid-template-columns: 1fr; }
  .period-btn { font-size: .72rem; }
}

@media (prefers-reduced-motion: no-preference) {
  .modal-card, .lock-card { animation: rise .2s ease-out; }
  .toast { animation: toastIn .18s ease-out; }
  @keyframes rise { from { opacity: 0; transform: translateY(8px) scale(.99); } }
  @keyframes toastIn { from { opacity: 0; transform: translate(-50%, 8px); } }
}
