/* ===========================================================
   Budget Buddy — stylesheet
   Font: Open Sans throughout. Palette echoes the original ledger:
   orange = income, red = expenses, blue = payables, green = savings.
=========================================================== */

* { box-sizing: border-box; }
html, body { height: 100%; }

body {
  margin: 0;
  font-family: 'Open Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  -webkit-font-smoothing: antialiased;
  transition: background-color .25s ease, color .25s ease;
}

:root {
  --orange: #E08A3E;
  --orange-soft: rgba(224,138,62,.16);
  --red: #C0524B;
  --red-soft: rgba(192,82,75,.16);
  --blue: #3D63C4;
  --blue-soft: rgba(61,99,196,.16);
  --green: #3D8A5A;
  --green-soft: rgba(61,138,90,.16);
  --radius: 16px;
  --radius-sm: 10px;
}

body[data-theme="dark"] {
  --bg: #14100E;
  --bg-elev: #1C1714;
  --bg-elev-2: #241D19;
  --bg-translucent: rgba(20,16,14,.82);
  --bg-elev-translucent: rgba(28,23,20,.92);
  --border: rgba(255,255,255,.08);
  --text: #F1EAE2;
  --text-dim: #B7AFA6;
  --shadow: 0 10px 30px rgba(0,0,0,.35);
}
body[data-theme="light"] {
  --bg: #FAF6F0;
  --bg-elev: #FFFFFF;
  --bg-elev-2: #F3ECE2;
  --bg-translucent: rgba(250,246,240,.82);
  --bg-elev-translucent: rgba(255,255,255,.92);
  --border: rgba(30,20,10,.08);
  --text: #2A2117;
  --text-dim: #6E6255;
  --shadow: 0 10px 24px rgba(60,40,20,.08);
}

body { background: var(--bg); color: var(--text); }

h1, h2, h3, h4 { font-weight: 700; margin: 0; }
p { margin: 0; }
.hidden { display: none !important; }

/* ---------------- animated background ---------------- */
#bg-canvas {
  position: fixed; inset: 0; z-index: 0;
  opacity: 0; transition: opacity .6s ease;
  pointer-events: none; filter: blur(10px);
}
#bg-canvas.visible { opacity: 1; }

/* ---------------- lock screen ---------------- */
.lock-screen {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at 30% 20%, rgba(224,138,62,.18), transparent 55%),
              radial-gradient(circle at 80% 80%, rgba(61,138,90,.16), transparent 55%),
              #14100E;
  padding: 20px;
}
.lock-card {
  width: 100%; max-width: 380px;
  background: rgba(28,23,20,.75);
  border: 1px solid rgba(255,255,255,.08);
  backdrop-filter: blur(18px);
  border-radius: 22px;
  padding: 34px 28px;
  text-align: center;
  color: #F1EAE2;
  box-shadow: 0 20px 60px rgba(0,0,0,.5);
}
.lock-logo { color: var(--orange); margin-bottom: 6px; }
.lock-card h1 { font-size: 24px; margin-bottom: 6px; }
.lock-sub { color: #B7AFA6; font-size: 13.5px; margin-bottom: 22px; line-height: 1.5; }
#lock-form { display: flex; flex-direction: column; gap: 10px; }
#lock-form input {
  padding: 12px 14px; border-radius: 12px; border: 1px solid rgba(255,255,255,.12);
  background: rgba(255,255,255,.05); color: #F1EAE2; font: inherit; font-size: 14px;
}
#lock-form input:focus { outline: 2px solid var(--orange); outline-offset: 1px; }
#lock-submit {
  margin-top: 4px; padding: 12px; border: none; border-radius: 12px;
  background: var(--orange); color: #201409; font-weight: 700; font-size: 14.5px; cursor: pointer;
  transition: transform .15s ease, filter .15s ease;
}
#lock-submit:hover { filter: brightness(1.08); transform: translateY(-1px); }
.lock-error { color: #FF9A8F; font-size: 13px; min-height: 18px; margin-top: 10px; }
.lock-reset { margin-top: 6px; background: none; border: none; color: #B7AFA6; font-size: 12.5px; text-decoration: underline; cursor: pointer; display: none; }

/* ---------------- app shell ---------------- */
.app { position: relative; z-index: 1; display: flex; min-height: 100vh; }

.sidebar {
  width: 240px; flex-shrink: 0;
  background: var(--bg-elev);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  padding: 20px 14px;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 22px; }
.brand-mark { color: var(--orange); display: flex; }
.brand-name { font-weight: 800; font-size: 17px; letter-spacing: -.2px; }

.nav-list { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 12px; border-radius: 12px; border: none;
  background: transparent; color: var(--text-dim);
  font-family: inherit; font-size: 14.5px; font-weight: 600;
  cursor: pointer; text-align: left; width: 100%;
  transition: background .15s ease, color .15s ease;
}
.nav-item .nav-icon { width: 19px; height: 19px; display: flex; }
.nav-item .nav-icon svg { width: 100%; height: 100%; }
.nav-item:hover { background: var(--bg-elev-2); color: var(--text); }
.nav-item.active { background: var(--orange-soft); color: var(--orange); }

.sidebar-foot { display: flex; align-items: center; justify-content: space-between; padding-top: 14px; border-top: 1px solid var(--border); margin-top: 10px; }
.month-pill { font-size: 12px; font-weight: 700; padding: 6px 10px; border-radius: 20px; background: var(--bg-elev-2); color: var(--text-dim); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 12px;
  padding: 16px 22px; background: var(--bg-translucent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar-title { font-size: 19px; font-weight: 800; flex: 1; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }

.icon-btn {
  width: 38px; height: 38px; border-radius: 11px; border: 1px solid var(--border);
  background: var(--bg-elev); color: var(--text); display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: background .15s ease, transform .1s ease;
}
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn:hover { background: var(--bg-elev-2); }
.icon-btn.sm { width: 32px; height: 32px; }
.icon-btn.sm svg { width: 15px; height: 15px; }
.icon-btn.danger:hover { background: var(--red-soft); color: var(--red); }
.only-mobile { display: none; }

.add-btn {
  display: flex; align-items: center; gap: 6px;
  padding: 9px 16px; border-radius: 20px; border: none;
  background: var(--orange); color: #241505; font-weight: 700; font-size: 14px;
  cursor: pointer; transition: filter .15s ease, transform .1s ease;
}
.add-btn:hover { filter: brightness(1.08); transform: translateY(-1px); }

.content { padding: 22px; max-width: 1180px; width: 100%; margin: 0 auto; }

/* ---------------- pill nav ---------------- */
.pill-nav { display: none; }
body[data-nav="pill"] .sidebar { display: none; }
body[data-nav="pill"] .pill-nav {
  display: flex; gap: 4px; position: fixed; z-index: 20;
  background: var(--bg-elev-translucent);
  border: 1px solid var(--border); backdrop-filter: blur(16px);
  border-radius: 999px; padding: 6px; box-shadow: var(--shadow);
  bottom: 18px; left: 50%; transform: translateX(-50%);
}
body[data-nav="pill"] .pill-nav .nav-item { flex-direction: column; gap: 2px; padding: 8px 14px; border-radius: 999px; font-size: 10.5px; }
body[data-nav="pill"] .pill-nav .nav-label { display: none; }
body[data-nav="pill"] .pill-nav .nav-item.active { background: var(--orange); color: #241505; }
@media (min-width: 900px) {
  body[data-nav="pill"] .pill-nav { bottom: auto; top: 16px; left: 50%; }
  body[data-nav="pill"] .pill-nav .nav-label { display: inline; }
  body[data-nav="pill"] .pill-nav .nav-item { flex-direction: row; }
  body[data-nav="pill"] .content { padding-top: 78px; }
  body[data-nav="pill"] .topbar { padding-left: 22px; }
}

body[data-nav="classic"] .pill-nav {
  display: flex; position: fixed; z-index: 20; bottom: 0; left: 0; right: 0;
  background: var(--bg-elev); border-top: 1px solid var(--border);
  border-radius: 0; padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  justify-content: space-around;
}
body[data-nav="classic"] .pill-nav .nav-item { flex-direction: column; gap: 2px; font-size: 10px; padding: 6px 8px; border-radius: 10px; }
body[data-nav="classic"] .pill-nav .nav-item.active { background: var(--orange-soft); color: var(--orange); }
@media (min-width: 900px) {
  body[data-nav="classic"] .sidebar { display: flex; }
  body[data-nav="classic"] .pill-nav { display: none; }
}
@media (max-width: 899px) {
  .sidebar { display: none; }
}

/* mobile off-canvas fallback if a classic sidebar is forced open */
@media (max-width: 899px) {
  .sidebar.open {
    display: flex; position: fixed; inset: 0 30% 0 0; z-index: 30; height: 100vh; box-shadow: var(--shadow);
  }
  .only-mobile { display: flex; }
  .content { padding-bottom: 90px; }
}

/* ---------------- cards / panels ---------------- */
.grid-cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 18px; }
@media (max-width: 900px) { .grid-cards { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 560px) { .grid-cards { grid-template-columns: 1fr; } }

.stat-card {
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow); border-top: 3px solid transparent;
}
.stat-card.orange { border-top-color: var(--orange); }
.stat-card.red { border-top-color: var(--red); }
.stat-card.blue { border-top-color: var(--blue); }
.stat-card.green { border-top-color: var(--green); }
.stat-label { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--text-dim); margin-bottom: 6px; }
.stat-value { font-size: 22px; font-weight: 800; display: flex; align-items: center; gap: 8px; }
.stat-value.editable { cursor: pointer; }
.stat-value.editable svg { width: 14px; height: 14px; opacity: .6; }
.stat-sub { font-size: 12px; color: var(--text-dim); margin-top: 6px; }
.mini-bar { height: 6px; border-radius: 4px; background: var(--bg-elev-2); margin-top: 10px; overflow: hidden; }
.mini-bar-fill { height: 100%; background: linear-gradient(90deg, var(--orange), var(--red)); border-radius: 4px; }

.panel-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 18px; }
.panel-grid.two { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 860px) { .panel-grid, .panel-grid.two { grid-template-columns: 1fr; } }

.panel {
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow); margin-bottom: 18px;
}
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; gap: 10px; }
.panel-head h3 { font-size: 15.5px; font-weight: 800; }
.chart-wrap { height: 240px; position: relative; }

.snapshot-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; font-size: 13px; color: var(--text-dim); }
@media (max-width: 700px) { .snapshot-grid { grid-template-columns: repeat(2, 1fr); } }
.snapshot-grid .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }

/* ---------------- tables ---------------- */
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-dim); padding: 8px 10px; border-bottom: 1px solid var(--border); }
.table td { padding: 11px 10px; border-bottom: 1px solid var(--border); }
.table tbody tr:hover { background: var(--bg-elev-2); }
.table tfoot td { padding: 12px 10px; }
.total-row { font-weight: 800; background: var(--orange-soft); }
.total-row.highlight { background: var(--green-soft); }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.muted-row { opacity: .55; }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 8px; vertical-align: middle; }
.tag { font-size: 11.5px; font-weight: 700; padding: 3px 9px; border-radius: 20px; background: var(--bg-elev-2); color: var(--text-dim); }
.tag-green { background: var(--green-soft); color: var(--green); }
.rate-note { font-size: 11px; color: var(--text-dim); }
.chip { border: none; border-radius: 20px; padding: 6px 12px; font-size: 12px; font-weight: 700; cursor: pointer; display: inline-flex; gap: 4px; align-items: center; }
.chip svg { width: 12px; height: 12px; }
.chip-owing { background: var(--blue-soft); color: var(--blue); }
.chip-paid { background: var(--green-soft); color: var(--green); }
.hint { font-size: 12px; color: var(--text-dim); margin-top: 12px; line-height: 1.5; }

.table-wrap { overflow-x: auto; }
@media (max-width: 640px) { .table { font-size: 12.5px; } .table th, .table td { padding: 8px 6px; } }

/* ---------------- settings ---------------- */
.settings-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 14px 0; border-bottom: 1px solid var(--border); }
.settings-row:last-child { border-bottom: none; }
.settings-row strong { font-size: 14px; }
.settings-row .hint { margin-top: 3px; }
.settings-row input[type="text"], .settings-row input[type="number"] {
  padding: 9px 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--bg-elev-2); color: var(--text); font: inherit; width: 160px;
}
.danger-row strong { color: var(--red); }

.segmented { display: flex; background: var(--bg-elev-2); border-radius: 12px; padding: 3px; gap: 2px; }
.segmented button { display: flex; align-items: center; gap: 6px; border: none; background: transparent; padding: 8px 14px; border-radius: 9px; font: inherit; font-weight: 700; font-size: 12.5px; color: var(--text-dim); cursor: pointer; }
.segmented button svg { width: 14px; height: 14px; }
.segmented button.active { background: var(--bg-elev); color: var(--orange); box-shadow: 0 2px 6px rgba(0,0,0,.15); }

.switch { position: relative; width: 42px; height: 24px; display: inline-block; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; inset: 0; background: var(--bg-elev-2); border-radius: 999px; cursor: pointer; transition: background .2s; }
.slider::before { content: ""; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px; background: white; border-radius: 50%; transition: transform .2s; }
.switch input:checked + .slider { background: var(--orange); }
.switch input:checked + .slider::before { transform: translateX(18px); }

.file-btn { position: relative; overflow: hidden; }

/* ---------------- buttons ---------------- */
.btn-primary, .btn-ghost, .btn-danger {
  font-family: inherit; font-weight: 700; font-size: 13.5px; border-radius: 11px; padding: 10px 16px;
  cursor: pointer; display: inline-flex; align-items: center; gap: 6px; border: 1px solid transparent;
  transition: filter .15s ease, transform .1s ease;
}
.btn-primary { background: var(--orange); color: #241505; }
.btn-primary svg { width: 14px; height: 14px; }
.btn-primary:hover { filter: brightness(1.08); }
.btn-primary.sm { padding: 7px 12px; font-size: 12.5px; }
.btn-ghost { background: var(--bg-elev-2); color: var(--text); border-color: var(--border); }
.btn-ghost:hover { background: var(--bg-elev); }
.btn-danger { background: var(--red-soft); color: var(--red); }
.btn-danger:hover { filter: brightness(1.1); }

/* ---------------- modal ---------------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 60; background: rgba(0,0,0,.55);
  display: flex; align-items: center; justify-content: center; padding: 16px;
  animation: fadeIn .18s ease;
}
.modal-card {
  width: 100%; max-width: 420px; background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: 18px; box-shadow: 0 24px 70px rgba(0,0,0,.4); animation: slideUp .2s ease;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px 10px; }
.modal-head h3 { font-size: 16.5px; }
.modal-body { padding: 6px 20px 10px; display: flex; flex-direction: column; gap: 4px; max-height: 60vh; overflow-y: auto; }
.modal-body label { font-size: 12px; font-weight: 700; color: var(--text-dim); margin-top: 10px; }
.modal-body input, .modal-body select {
  padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--bg-elev-2); color: var(--text); font: inherit; font-size: 14px; width: 100%;
}
.modal-body input[type="color"] { padding: 4px; height: 40px; cursor: pointer; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 16px 20px 20px; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: translateY(0); } }

/* ---------------- toasts ---------------- */
.toast-root { position: fixed; bottom: 90px; left: 50%; transform: translateX(-50%); z-index: 80; display: flex; flex-direction: column; gap: 8px; align-items: center; }
@media (min-width: 900px) { .toast-root { bottom: 24px; } }
.toast {
  background: var(--bg-elev); color: var(--text); border: 1px solid var(--border); box-shadow: var(--shadow);
  padding: 11px 18px; border-radius: 12px; font-size: 13.5px; font-weight: 600;
  opacity: 0; transform: translateY(8px); transition: opacity .25s ease, transform .25s ease;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast-error { border-color: var(--red); color: var(--red); }

/* ---------------- scrollbars ---------------- */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; }

/* Respect reduced motion */
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}
