/* ──────────────────────────────────────────
   TheBudget — style.css
   ────────────────────────────────────────── */

:root {
  --font-mono: 'IBM Plex Mono', 'Fira Mono', monospace;
  --font-sans: 'IBM Plex Sans', system-ui, sans-serif;
  --container-width: 680px;
  --text-xs:   0.70rem;
  --text-sm:   0.875rem;
  --text-base: 1rem;
  --text-lg:   2.6rem;
  --sp1:.25rem; --sp2:.5rem; --sp3:.75rem; --sp4:1rem;
  --sp5:1.25rem; --sp6:1.5rem; --sp8:2rem; --sp10:2.5rem;
  --transition: background-color .2s, color .2s, border-color .2s;
  --radius: 4px;
}

[data-theme="light"] {
  --bg:             #fafaf8;
  --border:         #e4e4e0;
  --text-primary:   #141412;
  --text-secondary: #505048;
  --text-muted:     #9a9a90;
  --modal-bg:       #ffffff;
  --modal-shadow:   0 12px 48px rgba(0,0,0,.10);
  --btn-bg:         #141412;
  --btn-color:      #ffffff;
  --btn-cancel-bg:  #e8e8e4;
  --btn-cancel-clr: #505048;
  --editor-bg:      #fafaf8;
  --editor-border:  #d4d4ce;
  --overlay-bg:     rgba(250,250,248,.90);
  --row-hover:      #f2f2ef;
  --ring-track:     #e8e8e4;
  --ring-ok:        #141412;
  --ring-warn:      #c97d30;
  --ring-over:      #c94040;
  --badge-bg:       #f0f0ec;
  --badge-clr:      #6a6a60;
  --expense-clr:    #141412;
  --income-clr:     #3a7a5a;
  --hist-cell-bg:   #f5f5f2;
  --hist-today-bdr: #141412;
}

[data-theme="dark"] {
  --bg:             #0d0d0b;
  --border:         #252521;
  --text-primary:   #ebebdf;
  --text-secondary: #a8a89a;
  --text-muted:     #555550;
  --modal-bg:       #0d0d0b;
  --modal-shadow:   0 12px 48px rgba(0,0,0,.7);
  --btn-bg:         #ebebdf;
  --btn-color:      #0d0d0b;
  --btn-cancel-bg:  #252521;
  --btn-cancel-clr: #a8a89a;
  --editor-bg:      #080806;
  --editor-border:  #2e2e2a;
  --overlay-bg:     rgba(13,13,11,.92);
  --row-hover:      #161614;
  --ring-track:     #1e1e1a;
  --ring-ok:        #ebebdf;
  --ring-warn:      #d4894a;
  --ring-over:      #e05050;
  --badge-bg:       #1e1e1a;
  --badge-clr:      #666660;
  --expense-clr:    #ebebdf;
  --income-clr:     #5aaa7a;
  --hist-cell-bg:   #141412;
  --hist-today-bdr: #ebebdf;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; background: var(--bg); color: var(--text-primary);
  font-family: var(--font-sans); font-size: 16px; transition: var(--transition); }

/* ── App ── */
#app { display: flex; flex-direction: column; height: 100vh;
  max-width: var(--container-width); margin: 0 auto; padding: 0 var(--sp6); }

/* ── Status panel ── */
#status-panel { flex-shrink: 0; border-bottom: 1px solid var(--border);
  padding: var(--sp5) 0 var(--sp4); }
#score-layout { display: flex; align-items: center; gap: var(--sp6); }

/* ── Ring ── */
#ring-wrap { flex-shrink: 0; width: 100px; height: 100px; position: relative; }
#score-ring { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring-track { fill: none; stroke: var(--ring-track); stroke-width: 10; }
.ring-fill  { fill: none; stroke: var(--ring-ok); stroke-width: 10;
  stroke-linecap: round; stroke-dasharray: 326.73; stroke-dashoffset: 326.73;
  transition: stroke-dashoffset .55s ease, stroke .3s; }
#ring-center-pct { position: absolute; inset: 0; display: flex;
  align-items: center; justify-content: center;
  font-family: var(--font-mono); font-size: 0.72rem;
  color: var(--text-muted); pointer-events: none; }

/* ── Score text ── */
#score-text { flex: 1; min-width: 0; }
#score-label { font-size: var(--text-xs); letter-spacing: .14em; text-transform: uppercase;
  color: var(--text-muted); margin-bottom: var(--sp1); font-family: var(--font-mono); }
#score-display { font-family: var(--font-mono); font-size: var(--text-lg);
  line-height: 1.0; letter-spacing: -.02em; margin-bottom: var(--sp1); }
#score-value { color: var(--text-primary); transition: color .3s; }
#score-subtext { font-size: var(--text-sm); color: var(--text-muted);
  font-family: var(--font-mono); min-height: 1.3em; margin-bottom: var(--sp2); }
#stats-bar { display: flex; gap: var(--sp4); font-size: var(--text-xs);
  color: var(--text-muted); font-family: var(--font-mono); }

/* ── Breakdown panel ── */
#breakdown-panel { flex-shrink: 0; border-bottom: 1px solid var(--border);
  overflow: hidden; max-height: 0; opacity: 0;
  transition: max-height .35s ease, opacity .25s ease, padding .35s ease; padding: 0; }
#breakdown-panel.open { max-height: 600px; opacity: 1; padding: var(--sp5) 0 var(--sp4); }
#breakdown-panel.hidden { display: flex !important; max-height: 0; opacity: 0;
  padding: 0; pointer-events: none; }
#breakdown-list { display: flex; flex-direction: column; gap: var(--sp3); }

.bd-row { display: grid; grid-template-columns: 7rem 1fr 5.5rem;
  align-items: center; gap: var(--sp3); cursor: pointer; border-radius: var(--radius);
  padding: 2px 0; transition: opacity .15s; }
.bd-row:hover { opacity: .7; }
.bd-label { font-family: var(--font-mono); font-size: var(--text-xs);
  color: var(--text-muted); letter-spacing: .04em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: right; }
.bd-track { height: 3px; background: var(--ring-track); border-radius: 2px;
  overflow: visible; position: relative; }
.bd-fill { position: absolute; top: 0; left: 0; height: 100%; border-radius: 2px;
  background: var(--ring-ok); transition: width .55s ease, background .3s; }
.bd-fill.warn { background: var(--ring-warn); }
.bd-fill.over { background: var(--ring-over); }
.bd-fill.income-line { background: var(--income-clr); }
.bd-amounts { font-family: var(--font-mono); font-size: var(--text-xs);
  color: var(--text-muted); white-space: nowrap; text-align: right; }
.bd-amounts.warn { color: var(--ring-warn); }
.bd-amounts.over { color: var(--ring-over); }
.bd-amounts.income-line { color: var(--income-clr); }

/* ── Transaction list ── */
#tx-container { flex: 1; overflow-y: auto; scrollbar-width: none; }
#tx-container::-webkit-scrollbar { display: none; }
#tx-list { padding: var(--sp8) 0 var(--sp10); }

.tx-date-group { font-size: var(--text-xs); font-family: var(--font-mono);
  letter-spacing: .10em; text-transform: uppercase; color: var(--text-muted);
  padding: var(--sp4) 0 var(--sp2); border-bottom: 1px solid var(--border);
  margin-bottom: var(--sp1); }
.tx-date-group:first-child { padding-top: 0; }

.tx-row { display: flex; align-items: center; gap: var(--sp4);
  padding: var(--sp3) var(--sp2); border-radius: var(--radius);
  cursor: pointer; transition: background .12s;
  margin: 0 calc(var(--sp2) * -1); user-select: none; }
.tx-row:hover { background: var(--row-hover); }
.tx-dot { flex-shrink: 0; width: .45rem; height: .45rem; border-radius: 50%;
  background: var(--text-muted); margin-top: 1px; }
.tx-row.income .tx-dot { background: var(--income-clr); }
.tx-content { flex: 1; display: flex; align-items: baseline;
  gap: var(--sp3); min-width: 0; }
.tx-desc { font-size: var(--text-base); color: var(--text-secondary);
  flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-cat { font-family: var(--font-mono); font-size: var(--text-xs);
  color: var(--badge-clr); background: var(--badge-bg);
  border-radius: 3px; padding: 1px 6px; white-space: nowrap; flex-shrink: 0; }
.tx-amount { flex-shrink: 0; font-family: var(--font-mono); font-size: var(--text-sm);
  color: var(--expense-clr); min-width: 4.5rem; text-align: right; }
.tx-row.income .tx-amount { color: var(--income-clr); }

/* ── Controls ── */
#controls { position: fixed; top: var(--sp4); right: var(--sp4);
  display: flex; align-items: center; gap: var(--sp3); z-index: 10; }
#btn-edit, #btn-today, #btn-breakdown, #btn-history {
  border: none; background: none; cursor: pointer;
  font-family: var(--font-mono); font-size: var(--text-xs);
  letter-spacing: .08em; text-transform: uppercase;
  color: var(--text-muted); opacity: .5; padding: 0;
  transition: opacity .2s; line-height: 1; }
#btn-edit { opacity: .75; }
#btn-edit:hover, #btn-today:hover, #btn-breakdown:hover, #btn-history:hover { opacity: 1; }
#btn-breakdown.active, #btn-today.active { opacity: 1; }

#theme-toggle { width: 1.125rem; height: 1.125rem; border-radius: 50%;
  border: none; background: none; cursor: pointer; padding: 0;
  display: flex; align-items: center; justify-content: center;
  opacity: .45; transition: opacity .2s; }
#theme-toggle:hover { opacity: 1; }
[data-theme="light"] #theme-icon { display: block; width: .875rem; height: .875rem;
  border-radius: 50%; background: #111; }
[data-theme="dark"]  #theme-icon { display: block; width: .875rem; height: .875rem;
  border-radius: 50%; background: transparent; border: 1.5px solid #ccc; }

/* ── Login screen ── */
#login-screen { position: fixed; inset: 0; display: flex; align-items: center;
  justify-content: center; background: var(--bg); }
#login-box { display: flex; flex-direction: column; gap: var(--sp4);
  width: min(340px, calc(100vw - var(--sp6) * 2)); }
#login-label { font-family: var(--font-mono); font-size: var(--text-xs);
  letter-spacing: .14em; text-transform: uppercase; color: var(--text-muted); }
#login-sub { font-size: var(--text-sm); color: var(--text-secondary);
  font-family: var(--font-mono); }
#login-email { background: var(--editor-bg); border: 1px solid var(--editor-border);
  border-radius: var(--radius); color: var(--text-primary);
  font-family: var(--font-mono); font-size: var(--text-base);
  padding: var(--sp3) var(--sp4); outline: none; width: 100%; transition: border-color .15s; }
#login-email:focus { border-color: var(--text-muted); }
#login-btn { border: none; border-radius: var(--radius);
  background: var(--btn-bg); color: var(--btn-color);
  font-family: var(--font-sans); font-size: var(--text-sm); font-weight: 500;
  padding: var(--sp3) var(--sp4); cursor: pointer; transition: opacity .15s; }
#login-btn:hover { opacity: .8; }
#login-btn:disabled { opacity: .4; cursor: default; }
#login-msg { font-family: var(--font-mono); font-size: var(--text-xs);
  color: var(--text-muted); min-height: 1.3em; }

/* ── Ledger modal ── */
#modal-overlay { position: fixed; inset: 0; background: var(--overlay-bg);
  display: flex; align-items: center; justify-content: center;
  z-index: 100; backdrop-filter: blur(4px); }
#modal-overlay.hidden { display: none; }
#modal { width: min(var(--container-width), calc(100vw - var(--sp6) * 2));
  background: var(--modal-bg); border: 1px solid var(--border);
  border-radius: 6px; box-shadow: var(--modal-shadow);
  display: flex; flex-direction: column; overflow: hidden; }
#modal-header { display: flex; justify-content: space-between; align-items: center;
  padding: var(--sp4) var(--sp5); border-bottom: 1px solid var(--border); }
#modal-title { font-size: var(--text-xs); font-weight: 600; letter-spacing: .10em;
  text-transform: uppercase; color: var(--text-muted); font-family: var(--font-mono); }
#modal-hint { font-size: var(--text-xs); color: var(--text-muted); font-family: var(--font-mono); }
#plan-editor { width: 100%; min-height: 26rem; max-height: 65vh;
  background: var(--editor-bg); border: none; border-bottom: 1px solid var(--editor-border);
  color: var(--text-primary); font-family: var(--font-mono); font-size: var(--text-sm);
  line-height: 1.85; padding: var(--sp4) var(--sp5); resize: none; outline: none; }
#modal-footer { display: flex; justify-content: space-between; align-items: center;
  padding: var(--sp3) var(--sp5); gap: var(--sp4); }
#modal-format-hint { font-size: var(--text-xs); color: var(--text-muted);
  font-family: var(--font-mono); flex: 1; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#modal-actions { display: flex; gap: var(--sp2); flex-shrink: 0; }
#btn-cancel, #btn-save { border: none; border-radius: var(--radius);
  font-family: var(--font-sans); font-size: var(--text-sm); font-weight: 500;
  padding: var(--sp2) var(--sp4); cursor: pointer; transition: opacity .15s; }
#btn-cancel:hover, #btn-save:hover { opacity: .75; }
#btn-cancel { background: var(--btn-cancel-bg); color: var(--btn-cancel-clr); }
#btn-save   { background: var(--btn-bg);         color: var(--btn-color); }

/* ── History modal ── */
#history-overlay { position: fixed; inset: 0; background: var(--overlay-bg);
  display: flex; align-items: center; justify-content: center;
  z-index: 100; backdrop-filter: blur(4px); }
#history-overlay.hidden { display: none; }
#history-modal { width: min(720px, calc(100vw - var(--sp6) * 2)); max-height: 80vh;
  background: var(--modal-bg); border: 1px solid var(--border);
  border-radius: 6px; box-shadow: var(--modal-shadow);
  display: flex; flex-direction: column; overflow: hidden; }
#history-header { display: flex; justify-content: space-between; align-items: center;
  padding: var(--sp4) var(--sp5); border-bottom: 1px solid var(--border); flex-shrink: 0; }
#history-title { font-size: var(--text-xs); font-weight: 600; letter-spacing: .10em;
  text-transform: uppercase; color: var(--text-muted); font-family: var(--font-mono); }
#history-close { border: none; background: none; cursor: pointer;
  font-size: var(--text-sm); color: var(--text-muted);
  opacity: .5; padding: 0; line-height: 1; transition: opacity .15s; }
#history-close:hover { opacity: 1; }
#history-body { overflow-y: auto; padding: var(--sp5); flex: 1;
  scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
#history-loading, #history-empty { font-family: var(--font-mono); font-size: var(--text-sm);
  color: var(--text-muted); padding: var(--sp4) 0; }
#history-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: var(--sp3); }
.history-cell { background: var(--hist-cell-bg); border-radius: 6px; padding: var(--sp3);
  cursor: pointer; transition: background .15s, transform .1s;
  display: flex; flex-direction: column; align-items: center; gap: var(--sp2);
  border: 1.5px solid transparent; text-decoration: none; }
.history-cell:hover { transform: translateY(-1px); }
.history-cell.current-month { border-color: var(--hist-today-bdr); }
.history-cell-ring { width: 64px; height: 64px; }
.history-cell-ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.h-ring-track { fill: none; stroke: var(--ring-track); stroke-width: 8; }
.h-ring-fill  { fill: none; stroke: var(--ring-ok); stroke-width: 8;
  stroke-linecap: round; stroke-dasharray: 175.93; stroke-dashoffset: 175.93; }
.h-ring-fill.warn { stroke: var(--ring-warn); }
.h-ring-fill.over { stroke: var(--ring-over); }
.history-cell-amount { font-family: var(--font-mono); font-size: var(--text-sm);
  font-weight: 500; color: var(--text-secondary); }
.history-cell-label { font-family: var(--font-mono); font-size: .65rem;
  color: var(--text-muted); text-align: center; line-height: 1.3; }
.history-cell.current-month .history-cell-label { color: var(--text-primary); font-weight: 500; }

/* ── Autocomplete ── */
#autocomplete { position: fixed; z-index: 200; background: var(--modal-bg);
  border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: 0 6px 24px rgba(0,0,0,.12); overflow: hidden; min-width: 10rem; max-width: 22rem; }
#autocomplete.hidden { display: none !important; }
.ac-item { font-family: var(--font-mono); font-size: var(--text-xs); letter-spacing: .04em;
  padding: var(--sp2) var(--sp3); cursor: pointer; color: var(--text-secondary);
  white-space: nowrap; transition: background .1s; }
.ac-item:hover, .ac-item.active { background: var(--row-hover); color: var(--text-primary); }

/* ── Empty state ── */
.empty-state { padding: var(--sp10) 0; color: var(--text-muted);
  font-size: var(--text-sm); font-family: var(--font-mono); line-height: 1.9; }
.empty-state strong { color: var(--text-secondary); font-weight: 500; }

/* ── Toast ── */
#share-toast { position: fixed; bottom: var(--sp6); left: 50%;
  transform: translateX(-50%); background: var(--text-primary); color: var(--bg);
  font-size: var(--text-xs); font-family: var(--font-mono);
  padding: var(--sp2) var(--sp4); border-radius: var(--radius); white-space: nowrap;
  opacity: 1; transition: opacity .5s ease; z-index: 200; }
#share-toast.toast-fade { opacity: 0; }
.hidden { display: none !important; }
