:root {
  --bg: #0e1116;
  --bg-elev: #161b22;
  --bg-elev-2: #1d2430;
  --border: #2a313c;
  --text: #e6edf3;
  --text-dim: #8b949e;
  --accent: #ffd400;        /* Monobank yellow */
  --accent-ink: #1a1400;
  --green: #3fb950;
  --red: #f85149;
  --blue: #58a6ff;
  --radius: 12px;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
}

/* --- top bar --- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 20px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; }
.logo {
  display: inline-grid; place-items: center;
  width: 30px; height: 30px; border-radius: 8px;
  background: var(--accent); color: var(--accent-ink); font-weight: 800;
}
.topbar-controls { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.period-picker { display: flex; align-items: center; gap: 6px; color: var(--text-dim); font-size: 13px; }
.period-picker select {
  background: var(--bg-elev-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; font-size: 14px;
}

/* --- buttons --- */
.btn {
  background: var(--accent); color: var(--accent-ink); border: none;
  border-radius: 8px; padding: 7px 14px; font-weight: 600; font-size: 14px; cursor: pointer;
  transition: filter .15s, opacity .15s;
}
.btn:hover { filter: brightness(1.08); }
.btn:disabled { opacity: .5; cursor: progress; }
.btn-ghost { background: var(--bg-elev-2); color: var(--text); border: 1px solid var(--border); }
.btn-sm { padding: 4px 10px; font-size: 13px; }
.btn-danger { background: var(--red); color: #fff; }

/* --- tabs --- */
.tabs { display: flex; gap: 4px; padding: 0 16px; background: var(--bg-elev); border-bottom: 1px solid var(--border); overflow-x: auto; }
.tab {
  background: none; border: none; color: var(--text-dim);
  padding: 12px 14px; font-size: 14px; cursor: pointer; white-space: nowrap;
  border-bottom: 2px solid transparent;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }

/* --- content --- */
.content { padding: 20px; max-width: 1100px; margin: 0 auto; }
.loader { color: var(--text-dim); padding: 40px; text-align: center; }
.section-title { font-size: 16px; font-weight: 700; margin: 0 0 12px; }
.muted { color: var(--text-dim); }
.error-box { background: rgba(248,81,73,.12); border: 1px solid var(--red); color: #ffb4af; padding: 12px 14px; border-radius: 8px; }

/* --- cards / grid --- */
.grid { display: grid; gap: 14px; }
.cards { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.card {
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px;
}
.stat-label { color: var(--text-dim); font-size: 13px; margin-bottom: 6px; }
.stat-value { font-size: 24px; font-weight: 700; }
.stat-value.pos { color: var(--green); }
.stat-value.neg { color: var(--red); }
.stat-sub { color: var(--text-dim); font-size: 12px; margin-top: 4px; }

/* --- bars --- */
.barlist { display: flex; flex-direction: column; gap: 10px; }
.bar-row { display: grid; grid-template-columns: 160px 1fr auto; gap: 12px; align-items: center; }
.bar-name { color: var(--text); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { background: var(--bg-elev-2); border-radius: 6px; height: 16px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--accent); border-radius: 6px; }
.bar-fill.essential { background: var(--blue); }
.bar-val { font-variant-numeric: tabular-nums; font-size: 14px; min-width: 110px; text-align: right; }
.trend { font-size: 12px; margin-left: 6px; }
.trend.up { color: var(--red); }
.trend.down { color: var(--green); }

/* --- table --- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--text-dim); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
tbody tr:hover { background: var(--bg-elev); }
tr.excluded { opacity: .45; }
tr.excluded td:nth-child(2) { text-decoration: line-through; }
.amount-pos { color: var(--green); font-variant-numeric: tabular-nums; }
.amount-neg { color: var(--text); font-variant-numeric: tabular-nums; }
.pill { display: inline-block; padding: 2px 8px; border-radius: 20px; font-size: 12px; background: var(--bg-elev-2); border: 1px solid var(--border); color: var(--text-dim); }
.pill.tag { background: rgba(88,166,255,.12); border-color: transparent; color: var(--blue); }
.row-actions { display: flex; gap: 6px; }
.icon-btn { background: var(--bg-elev-2); border: 1px solid var(--border); color: var(--text); border-radius: 6px; padding: 3px 8px; cursor: pointer; font-size: 13px; }
.icon-btn:hover { border-color: var(--accent); }

/* --- filters --- */
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.filters input, .filters select {
  background: var(--bg-elev-2); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: 7px 10px; font-size: 14px;
}
.filters input[type="search"] { min-width: 220px; }
.pager { display: flex; gap: 10px; align-items: center; justify-content: flex-end; margin-top: 12px; color: var(--text-dim); font-size: 13px; }

/* --- goals --- */
.goal { margin-bottom: 14px; }
.goal-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 6px; }
.goal-name { font-weight: 700; }
.goal-status.ok { color: var(--green); }
.goal-status.bad { color: var(--red); }
.progress { background: var(--bg-elev-2); border-radius: 8px; height: 10px; overflow: hidden; margin: 6px 0; }
.progress > div { height: 100%; background: var(--green); }
.progress.bad > div { background: var(--red); }
.goal-meta { display: flex; gap: 18px; flex-wrap: wrap; color: var(--text-dim); font-size: 13px; }
.goal-meta b { color: var(--text); }

/* --- plan --- */
.plan-output { background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; white-space: pre-wrap; line-height: 1.6; }
.plan-meta { color: var(--text-dim); font-size: 13px; margin-bottom: 10px; }

/* --- modal --- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: grid; place-items: center; z-index: 50; }
.modal { background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius); padding: 22px; width: min(440px, 92vw); box-shadow: var(--shadow); }
.modal h3 { margin: 0 0 14px; }
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 13px; color: var(--text-dim); margin-bottom: 4px; }
.field input, .field select {
  width: 100%; background: var(--bg-elev-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; font-size: 14px;
}
.field.checkbox { display: flex; align-items: center; gap: 8px; }
.field.checkbox label { margin: 0; }
.modal-actions { display: flex; justify-content: space-between; gap: 10px; margin-top: 18px; }
.modal-actions .right { display: flex; gap: 8px; margin-left: auto; }

/* --- toast --- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--bg-elev-2); border: 1px solid var(--border); color: var(--text);
  padding: 10px 18px; border-radius: 10px; box-shadow: var(--shadow);
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 100;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { border-color: var(--red); color: #ffb4af; }

.hidden { display: none !important; }

@media (max-width: 640px) {
  .bar-row { grid-template-columns: 110px 1fr; }
  .bar-val { grid-column: 2; text-align: left; min-width: 0; }
}
