/* ============================
   Budget Tracker — main styles
   ============================ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:          #f5f4f1;
  --surface:     #ffffff;
  --surface-2:   #f9f8f6;
  --border:      rgba(0,0,0,.09);
  --border-md:   rgba(0,0,0,.15);
  --text:        #1a1a1a;
  --text-muted:  #6b6b6b;
  --text-hint:   #a0a0a0;
  --green:       #1a7a52;
  --green-bg:    #e8f5ee;
  --red:         #c0392b;
  --red-bg:      #fdecea;
  --amber:       #9a6000;
  --amber-bg:    #fff3dc;
  --blue:        #1a56a0;
  --blue-bg:     #e8f0fb;
  --radius-sm:   6px;
  --radius-md:   10px;
  --radius-lg:   14px;
  --shadow:      0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
}

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.6;
  min-height: 100vh;
}

/* ---- Layout ---- */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 1.5rem;
  height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
}

.topbar-brand {
  font-size: 17px;
  font-weight: 600;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
}

.topbar-brand span { color: var(--blue); }

.container {
  max-width: 860px;
  margin: 0 auto;
  padding: 2rem 1.25rem;
}

/* ---- Summary bar ---- */
.summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 2rem;
}

.summary-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1rem 1.125rem;
}

.summary-card .label {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.summary-card .value {
  font-size: 20px;
  font-weight: 600;
}

.value.green { color: var(--green); }
.value.red   { color: var(--red);   }

/* ---- Section header ---- */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.section-title {
  font-size: 17px;
  font-weight: 600;
}

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 14px;
  height: 36px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-md);
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s, transform .1s;
  text-decoration: none;
  white-space: nowrap;
}

.btn:hover  { background: var(--surface-2); }
.btn:active { transform: scale(.98); }

.btn-primary {
  background: var(--text);
  color: #fff;
  border-color: var(--text);
}

.btn-primary:hover { background: #333; }

.btn-danger {
  background: var(--red-bg);
  color: var(--red);
  border-color: rgba(192,57,43,.2);
}

.btn-danger:hover { background: #fad5d2; }

.btn-icon {
  padding: 0;
  width: 32px;
  height: 32px;
  justify-content: center;
  border: none;
  background: transparent;
  color: var(--text-hint);
  border-radius: var(--radius-sm);
}

.btn-icon:hover { background: var(--surface-2); color: var(--red); }

.btn-sm { height: 30px; font-size: 13px; padding: 0 10px; }

/* ---- Forms ---- */
.form-row {
  display: grid;
  gap: 10px;
  margin-bottom: 10px;
}

.form-row.cols-2 { grid-template-columns: 1fr 1fr; }

.form-group { display: flex; flex-direction: column; gap: 4px; }

label.form-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
}

input[type="text"],
input[type="number"],
select,
textarea {
  width: 100%;
  height: 38px;
  padding: 0 12px;
  border: 1px solid var(--border-md);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-size: 14px;
  color: var(--text);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}

input:focus, select:focus, textarea:focus {
  border-color: #555;
  box-shadow: 0 0 0 3px rgba(0,0,0,.06);
}

.form-error {
  font-size: 12px;
  color: var(--red);
  margin-top: 4px;
  display: none;
}

/* ---- Cards grid ---- */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.125rem 1.25rem;
  cursor: pointer;
  transition: box-shadow .15s, transform .15s;
  text-decoration: none;
  color: inherit;
  display: block;
}

.card:hover {
  box-shadow: var(--shadow);
  transform: translateY(-2px);
}

.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 10px;
}

.card-title {
  font-size: 15px;
  font-weight: 600;
  line-height: 1.3;
}

.card-budget {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.card-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 12px;
}

.stat-box {
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
}

.stat-box .stat-label {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 2px;
}

.stat-box .stat-val {
  font-size: 15px;
  font-weight: 600;
}

/* ---- Progress bar ---- */
.progress-wrap {
  background: var(--bg);
  border-radius: 4px;
  height: 5px;
  overflow: hidden;
  margin-bottom: 4px;
}

.progress-bar {
  height: 100%;
  border-radius: 4px;
  transition: width .4s ease;
}

.bar-ok     { background: var(--green); }
.bar-warn   { background: #e6a817; }
.bar-danger { background: var(--red); }

.pct-label {
  font-size: 11px;
  color: var(--text-hint);
  text-align: right;
}

/* ---- Empty state ---- */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
}

.empty-state svg {
  margin-bottom: 12px;
  opacity: .35;
}

.empty-state p { font-size: 14px; }

/* ---- Modal ---- */
.modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.35);
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal-backdrop.open { display: flex; }

.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 440px;
  padding: 1.5rem;
  box-shadow: 0 20px 60px rgba(0,0,0,.15);
}

.modal-title {
  font-size: 17px;
  font-weight: 600;
  margin-bottom: 1.25rem;
}

.modal-footer {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 1.25rem;
}

/* ---- Detail page ---- */
.detail-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 1.5rem;
  gap: 1rem;
}

.detail-back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  color: var(--text-muted);
  text-decoration: none;
  margin-bottom: 1.25rem;
}

.detail-back:hover { color: var(--text); }

.detail-summary {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  margin-bottom: 1.5rem;
}

.detail-title { font-size: 22px; font-weight: 700; margin-bottom: 4px; }
.detail-sub   { font-size: 13px; color: var(--text-muted); margin-bottom: 1.25rem; }

.detail-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}

/* ---- Expenses table ---- */
.expense-add-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.125rem 1.25rem;
  margin-bottom: 1.5rem;
}

.expense-add-title {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 1rem;
}

.expenses-list { display: flex; flex-direction: column; gap: 8px; }

.expense-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 14px;
}

.expense-desc { flex: 1; font-size: 14px; }

.expense-date {
  font-size: 12px;
  color: var(--text-hint);
  white-space: nowrap;
}

.expense-amount {
  font-size: 14px;
  font-weight: 600;
  color: var(--red);
  white-space: nowrap;
}

/* ---- Badges ---- */
.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
}

.badge-green  { background: var(--green-bg);  color: var(--green); }
.badge-red    { background: var(--red-bg);    color: var(--red); }
.badge-amber  { background: var(--amber-bg);  color: var(--amber); }

/* ---- Toast ---- */
#toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: #1a1a1a;
  color: #fff;
  padding: 10px 18px;
  border-radius: var(--radius-md);
  font-size: 14px;
  z-index: 9999;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity .25s, transform .25s;
  pointer-events: none;
}

#toast.show { opacity: 1; transform: translateY(0); }

/* ---- Responsive ---- */
@media (max-width: 600px) {
  .summary { grid-template-columns: 1fr 1fr; }
  .summary .summary-card:last-child { grid-column: span 2; }
  .form-row.cols-2 { grid-template-columns: 1fr; }
  .detail-stats { grid-template-columns: 1fr 1fr; }
  .detail-stats .stat-box:last-child { grid-column: span 2; }
  .cards-grid { grid-template-columns: 1fr; }
}
