:root {
  --bg: #1B1C18;
  --surface: #232520;
  --surface-raised: #2A2C24;
  --border: #3A3C33;
  --text: #ECE8DC;
  --text-muted: #8D9082;

  --rust: #C15F33;
  --olive: #76864E;
  --steel: #52727C;
  --gold: #B8923E;
  --brick: #9C4438;

  --mono: ui-monospace, "JetBrains Mono", "SF Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;

  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

button, input, select {
  font-family: inherit;
  color: inherit;
}

input:focus-visible,
button:focus-visible,
select:focus-visible {
  outline: 2px solid var(--rust);
  outline-offset: 2px;
}

/* ===== Login ===== */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 320px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 32px 24px;
  text-align: center;
}
.login-mark {
  font-family: var(--mono);
  letter-spacing: 0.15em;
  font-size: 14px;
  color: var(--rust);
  margin-bottom: 4px;
}
.login-sub {
  color: var(--text-muted);
  font-size: 13px;
  margin: 0 0 20px;
}
.login-card input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 11px 12px;
  font-size: 15px;
  margin-bottom: 12px;
}
.login-error {
  color: var(--brick);
  font-size: 13px;
  min-height: 16px;
  margin: 10px 0 0;
}

/* ===== Buttons ===== */
.btn {
  border: 1px solid var(--border);
  background: var(--surface-raised);
  color: var(--text);
  border-radius: 3px;
  padding: 10px 14px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.btn:active { transform: translateY(1px); }
.btn-block { width: 100%; }
.btn-primary {
  background: var(--rust);
  border-color: var(--rust);
  color: #1B1C18;
}
.btn-accent {
  background: var(--accent, var(--rust));
  border-color: var(--accent, var(--rust));
  color: #1B1C18;
  white-space: nowrap;
}
.icon-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  width: 34px;
  height: 34px;
  border-radius: 3px;
  font-size: 16px;
  cursor: pointer;
  line-height: 1;
}
.icon-btn:hover { color: var(--text); border-color: var(--text-muted); }
.link-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 12px;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
  display: block;
  margin: 2px auto 18px;
}

/* ===== Shell / nav ===== */
.app { max-width: 560px; margin: 0 auto; padding: 0 16px 64px; }

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 0 14px;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 5;
}
.brand {
  font-family: var(--mono);
  letter-spacing: 0.12em;
  font-size: 13px;
  color: var(--rust);
  flex: 0 0 auto;
}
.tabs { display: flex; gap: 4px; flex: 1; }
.tab {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 3px;
  padding: 7px 14px;
  font-size: 13px;
  cursor: pointer;
}
.tab.active {
  color: var(--bg);
  background: var(--text);
  border-color: var(--text);
}

/* ===== Date nav ===== */
.date-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-top: 6px;
}
.date-stamp {
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom: 2px solid var(--rust);
  color: var(--text);
  font-family: var(--mono);
  letter-spacing: 0.08em;
  font-size: 13px;
  padding: 9px 16px;
  border-radius: 3px;
  cursor: pointer;
}
.sr-date-input {
  position: absolute;
  width: 1px; height: 1px;
  opacity: 0;
  pointer-events: none;
}
#today-btn { margin-top: 8px; }

/* ===== Cards / sections ===== */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 16px;
  margin-bottom: 16px;
}
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.tag {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.12em;
  color: var(--accent, var(--text-muted));
  border-left: 3px solid var(--accent, var(--text-muted));
  padding-left: 8px;
}
.card-head-meta {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
.card-head-meta.over { color: var(--brick); }

/* gauge: flat tick-bar, not a glossy progress ring */
.gauge {
  position: relative;
  height: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 2px;
  margin-bottom: 14px;
  overflow: visible;
}
.gauge-fill {
  position: absolute;
  inset: 0;
  width: 0%;
  background: var(--accent, var(--rust));
  border-radius: 1px;
}
.gauge-fill.over { background: var(--brick); }
.gauge-tick {
  position: absolute;
  top: -3px;
  bottom: -3px;
  width: 2px;
  left: 100%;
  background: var(--text-muted);
}

/* ===== Entry lists ===== */
.entry-list { list-style: none; margin: 0 0 12px; padding: 0; }
.entry-row {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 9px 0;
  border-bottom: 1px solid var(--border);
}
.entry-row:last-child { border-bottom: none; }
.entry-name { flex: 1; font-size: 14px; }
.entry-detail { color: var(--text-muted); font-size: 12px; }
.entry-amount {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-size: 13px;
  color: var(--text-muted);
  white-space: nowrap;
}
.entry-actions { display: flex; gap: 4px; }
.entry-actions button {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 13px;
  padding: 2px 4px;
}
.entry-actions button:hover { color: var(--text); }
.empty-row {
  color: var(--text-muted);
  font-size: 13px;
  font-style: italic;
  padding: 6px 0;
}

/* ===== Forms ===== */
.inline-form { display: flex; gap: 8px; }
.inline-form input {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 9px 10px;
  font-size: 14px;
  flex: 1;
  min-width: 0;
}
.inline-form-3 { flex-wrap: wrap; }
.inline-form-3 input { flex: 1 1 120px; }
.inline-form-3 button { flex: 1 1 100%; }
.hint {
  color: var(--text-muted);
  font-size: 12px;
  margin: 10px 0 0;
}

/* ===== Dashboard ===== */
.dash-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 6px 0 16px;
}
.range-select {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 3px;
  padding: 7px 10px;
  font-size: 13px;
}
.chart svg { width: 100%; height: auto; display: block; }
.chart-empty { color: var(--text-muted); font-size: 13px; font-style: italic; }
.chart-legend {
  display: flex;
  gap: 16px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 8px;
}
.chart-legend span { display: inline-flex; align-items: center; gap: 5px; }
.swatch { width: 8px; height: 8px; display: inline-block; border-radius: 1px; }

.exercise-summary-totals {
  display: flex;
  gap: 24px;
  font-family: var(--mono);
  margin-bottom: 14px;
}
.exercise-summary-totals .big { font-size: 22px; font-variant-numeric: tabular-nums; }
.exercise-summary-totals .label { font-size: 10px; color: var(--text-muted); letter-spacing: 0.08em; }

/* ===== Modal ===== */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 20;
}
.modal-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px 8px 0 0;
  padding: 18px 20px 24px;
}
@media (min-width: 480px) {
  .modal { align-items: center; }
  .modal-card { border-radius: 6px; }
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
#goals-form label {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 12px;
}
#goals-form input {
  display: block;
  width: 100%;
  margin-top: 5px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 9px 10px;
  font-size: 14px;
}

/* ===== Toast ===== */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: var(--surface-raised);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 13px;
  padding: 10px 16px;
  border-radius: 4px;
  z-index: 30;
}
.toast.error { border-color: var(--brick); color: var(--brick); }

@media (max-width: 380px) {
  .app { padding: 0 10px 64px; }
}
