:root{
  --paper:#EDF1E6;
  --paper-line:#C7D3BA;
  --surface:#F6F8F1;
  --surface-2:#FFFFFF;
  --ink:#1F2A1E;
  --ink-soft:#5B6B52;
  --ink-faint:#8B9A82;
  --debit:#AA3A2C;
  --debit-soft:#C96354;
  --accent:#5C7048;
  --border:#D6DECB;
  --shadow: 0 1px 2px rgba(31,42,30,0.06), 0 6px 20px rgba(31,42,30,0.06);
  --radius:14px;
  color-scheme: light;
}
[data-theme="dark"]{
  --paper:#12160F;
  --paper-line:#2B3524;
  --surface:#1A2016;
  --surface-2:#1F2619;
  --ink:#E7ECDD;
  --ink-soft:#A9B79A;
  --ink-faint:#71806A;
  --debit:#E2685A;
  --debit-soft:#C4544A;
  --accent:#8FAE72;
  --border:#2B3524;
  --shadow: 0 1px 2px rgba(0,0,0,0.3), 0 8px 24px rgba(0,0,0,0.35);
  color-scheme: dark;
}
*{ box-sizing:border-box; -webkit-tap-highlight-color:transparent; }
html,body{ height:100%; overscroll-behavior-y:contain; }
body{
  margin:0;
  background:var(--paper);
  color:var(--ink);
  font-family:'IBM Plex Sans', sans-serif;
  -webkit-font-smoothing:antialiased;
  overflow-x:hidden;
  touch-action:pan-y;
}
button, .row, .cat-chip, .switch{ touch-action:manipulation; }

#frame{
  max-width:520px;
  margin:0 auto;
  min-height:100vh;
  min-height:100dvh;
  background:var(--paper);
  position:relative;
  display:flex;
  flex-direction:column;
  background-image: repeating-linear-gradient(
    to bottom,
    transparent 0px,
    transparent 34px,
    var(--paper-line) 34px,
    var(--paper-line) 35px
  );
}
#frame::before{
  content:"";
  position:absolute;
  top:0; bottom:0; left:38px;
  width:1px;
  background:var(--debit);
  opacity:0.35;
  pointer-events:none;
}
header.topbar{
  padding:calc(20px + env(safe-area-inset-top)) 20px 14px 48px;
  position:relative;
  z-index:2;
}
.brand{ display:flex; align-items:baseline; gap:8px; flex-wrap:wrap; }
.brand h1{
  font-family:'Spectral', serif;
  font-weight:600;
  font-size:26px;
  margin:0;
  letter-spacing:0.2px;
}
.brand span.mark{
  font-family:'Spectral', serif;
  font-style:italic;
  font-weight:500;
  color:var(--debit);
  font-size:14px;
}
.brand-sub{
  margin:2px 0 0;
  font-size:12px;
  color:var(--ink-faint);
  letter-spacing:0.4px;
  text-transform:uppercase;
}
.month-nav{ display:flex; align-items:center; justify-content:space-between; margin-top:16px; }
.month-nav button{
  background:var(--surface-2);
  border:1px solid var(--border);
  color:var(--ink);
  width:36px; height:36px;
  border-radius:50%;
  font-size:18px;
  display:flex; align-items:center; justify-content:center;
  cursor:pointer;
}
.month-nav button:disabled{ opacity:0.35; cursor:default; }
.month-label{
  font-family:'IBM Plex Mono', monospace;
  font-size:13px;
  letter-spacing:0.5px;
  color:var(--ink-soft);
}
main{
  flex:1;
  padding:4px 20px 130px 48px;
  position:relative;
  z-index:2;
  -webkit-overflow-scrolling:touch;
}
.total-card{
  background:var(--surface);
  border:1px solid var(--border);
  border-radius:var(--radius);
  padding:18px 18px 16px;
  box-shadow:var(--shadow);
  margin:8px 0 22px;
}
.total-card .label{ font-size:11px; text-transform:uppercase; letter-spacing:1px; color:var(--ink-faint); font-weight:500; }
.total-card .amount{
  font-family:'IBM Plex Mono', monospace;
  font-weight:600;
  font-size:34px;
  color:var(--debit);
  margin-top:4px;
  font-variant-numeric: tabular-nums;
}
.total-card .count{ font-size:12px; color:var(--ink-soft); margin-top:6px; }
h2.section-title{
  font-family:'Spectral', serif;
  font-weight:600;
  font-size:15px;
  color:var(--ink);
  margin:0 0 10px;
  display:flex; align-items:center; gap:8px;
}
h2.section-title::after{ content:""; flex:1; height:1px; background:var(--border); }
.day-group{ margin-bottom:6px; }
.day-heading{
  font-size:11px; letter-spacing:0.6px; text-transform:uppercase;
  color:var(--ink-faint); margin:14px 0 6px; font-weight:500;
}
.row{
  display:flex; align-items:center; gap:12px;
  padding:14px 4px;
  border-bottom:1px solid var(--border);
  cursor:pointer;
  min-height:44px;
}
.row:active{ background:rgba(0,0,0,0.03); }
.stamp{
  flex:0 0 auto;
  width:36px; height:36px;
  border-radius:50%;
  border:1.5px dashed var(--accent);
  color:var(--accent);
  display:flex; align-items:center; justify-content:center;
  font-family:'IBM Plex Mono', monospace;
  font-size:10px; font-weight:600; letter-spacing:0.5px;
  transform:rotate(-6deg);
  opacity:0.85;
}
.row-main{ flex:1; min-width:0; }
.row-reason{
  font-size:15px; font-weight:500; color:var(--ink);
  white-space:nowrap; overflow:hidden; text-overflow:ellipsis;
}
.row-cat{ font-size:12px; color:var(--ink-faint); margin-top:2px; }
.row-amount{
  font-family:'IBM Plex Mono', monospace;
  font-weight:600; font-size:16px; color:var(--debit);
  font-variant-numeric: tabular-nums;
  white-space:nowrap;
}
.empty-state{ text-align:center; padding:40px 10px; color:var(--ink-faint); }
.empty-state .glyph{ font-family:'Spectral', serif; font-style:italic; font-size:20px; color:var(--ink-soft); margin-bottom:6px; }
.empty-state p{ font-size:13px; line-height:1.5; margin:0; }

.fab{
  position:fixed;
  right:20px;
  bottom:calc(84px + env(safe-area-inset-bottom));
  width:58px; height:58px;
  border-radius:50%;
  background:var(--debit);
  color:#fff;
  border:none;
  font-size:28px;
  font-weight:400;
  box-shadow:0 8px 20px rgba(170,58,44,0.35);
  display:flex; align-items:center; justify-content:center;
  cursor:pointer;
  z-index:20;
  line-height:0;
}
.fab:active{ transform:scale(0.93); }

nav.bottomnav{
  position:sticky;
  bottom:0; left:0; right:0;
  background:var(--surface-2);
  border-top:1px solid var(--border);
  display:flex;
  z-index:15;
  padding-bottom:env(safe-area-inset-bottom);
}
nav.bottomnav button{
  flex:1;
  background:none; border:none;
  padding:12px 4px 10px;
  display:flex; flex-direction:column; align-items:center; gap:4px;
  color:var(--ink-faint);
  font-family:'IBM Plex Sans', sans-serif;
  font-size:11px; letter-spacing:0.3px;
  cursor:pointer;
  min-height:56px;
}
nav.bottomnav button .ic{ width:19px; height:19px; display:flex; align-items:center; justify-content:center; }
nav.bottomnav button.active{ color:var(--debit); }
nav.bottomnav button.active .ic svg{ stroke:var(--debit); }
nav.bottomnav button .ic svg{ stroke:currentColor; }

.search-input, input[type=text].plain, input[type=number].plain, input[type=date].plain, input[type=time].plain, select.plain{
  width:100%;
  background:var(--surface-2);
  border:1px solid var(--border);
  border-radius:10px;
  padding:13px 14px;
  font-size:16px;
  color:var(--ink);
  font-family:'IBM Plex Sans', sans-serif;
  outline:none;
}
.search-input:focus, input.plain:focus, select.plain:focus{ border-color:var(--accent); }
.field{ margin-bottom:16px; }
.field label{
  display:block; font-size:11px; text-transform:uppercase; letter-spacing:0.6px;
  color:var(--ink-faint); margin-bottom:6px; font-weight:500;
}
.amount-field{ position:relative; }
.amount-field .rupee{
  position:absolute; left:14px; top:50%; transform:translateY(-50%);
  font-family:'IBM Plex Mono', monospace; font-weight:600; color:var(--debit); font-size:17px;
}
.amount-field input{ padding-left:32px; font-family:'IBM Plex Mono', monospace; font-weight:600; font-size:17px; }

.settings-card{
  background:var(--surface); border:1px solid var(--border); border-radius:var(--radius);
  padding:16px; margin-bottom:14px;
}
.settings-card h3{ margin:0 0 4px; font-family:'Spectral', serif; font-size:15px; font-weight:600; }
.settings-card p.hint{ font-size:12.5px; color:var(--ink-soft); line-height:1.55; margin:0 0 12px; }
.switch-row{ display:flex; align-items:center; justify-content:space-between; margin-bottom:12px; }
.switch{
  width:44px; height:26px; border-radius:99px; background:var(--border);
  position:relative; cursor:pointer; border:none; flex:0 0 auto;
}
.switch.on{ background:var(--accent); }
.switch::after{
  content:""; position:absolute; top:2px; left:2px;
  width:22px; height:22px; border-radius:50%; background:#fff;
  transition:left 0.15s ease;
}
.switch.on::after{ left:20px; }
.btn{
  background:var(--ink); color:var(--paper); border:none; border-radius:10px;
  padding:14px; font-size:14.5px; font-weight:600; cursor:pointer; width:100%; min-height:48px;
}
.btn.secondary{ background:transparent; color:var(--ink-soft); border:1px solid var(--border); }
.btn.danger{ background:transparent; color:var(--debit); border:1px solid var(--debit-soft); }

.sheet-overlay{
  position:fixed; inset:0;
  background:rgba(18,22,15,0.4);
  z-index:40;
  display:flex; align-items:flex-end; justify-content:center;
  opacity:0; pointer-events:none;
  transition:opacity 0.2s ease;
}
.sheet-overlay.open{ opacity:1; pointer-events:auto; }
.sheet{
  width:100%; max-width:520px;
  background:var(--paper);
  border-radius:20px 20px 0 0;
  padding:10px 20px 26px;
  transform:translateY(100%);
  transition:transform 0.25s cubic-bezier(.32,.72,0,1);
  max-height:90vh;
  max-height:90dvh;
  overflow-y:auto;
  -webkit-overflow-scrolling:touch;
  padding-bottom:calc(26px + env(safe-area-inset-bottom));
}
.sheet-overlay.open .sheet{ transform:translateY(0); }
.sheet-handle{ width:36px; height:4px; border-radius:99px; background:var(--border); margin:6px auto 16px; }
.sheet h2{ font-family:'Spectral', serif; font-size:19px; margin:0 0 18px; }
.cat-picker{ display:flex; flex-wrap:wrap; gap:8px; margin-top:6px; }
.cat-chip{
  font-size:12px; font-family:'IBM Plex Mono', monospace;
  padding:8px 12px; border-radius:99px; border:1px solid var(--border);
  color:var(--ink-soft); background:var(--surface-2); cursor:pointer;
}
.cat-chip.selected{ border-color:var(--debit); color:var(--debit); background:rgba(170,58,44,0.08); }
.sheet-actions{ display:flex; gap:10px; margin-top:20px; }
.toast{
  position:fixed; left:50%; bottom:calc(100px + env(safe-area-inset-bottom)); transform:translateX(-50%);
  background:var(--ink); color:var(--paper);
  padding:11px 18px; border-radius:99px;
  font-size:13px; z-index:60;
  opacity:0; pointer-events:none;
  transition:opacity 0.2s ease;
  max-width:88%;
  text-align:center;
}
.toast.show{ opacity:1; }
.hidden{ display:none !important; }
::selection{ background:var(--debit); color:#fff; }

@media (max-width:370px){
  header.topbar{ padding-left:36px; }
  main{ padding-left:36px; padding-right:16px; }
  #frame::before{ left:28px; }
  .total-card .amount{ font-size:30px; }
}
