:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --border: #e1e5ea;
  --text: #1c2530;
  --muted: #6b7684;
  --accent: #2f6fed;
  --green: #1a8f5a;
  --red: #d0402a;
  --amber: #b8860b;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.shell { display: flex; min-height: 100vh; }

.sidenav {
  width: 200px;
  flex-shrink: 0;
  background: #16202e;
  color: #cdd6e0;
  padding: 20px 0;
  display: flex;
  flex-direction: column;
}

.sidenav .brand {
  font-weight: bold;
  font-size: 16px;
  color: #fff;
  padding: 0 20px 18px;
  border-bottom: 1px solid #2a3648;
  margin-bottom: 10px;
}

.sidenav a {
  color: #cdd6e0;
  text-decoration: none;
  padding: 10px 20px;
  font-size: 14px;
}

.sidenav a:hover { background: #1f2c3d; }
.sidenav a.active { background: var(--accent); color: #fff; }

.content { flex: 1; padding: 28px 34px; max-width: 1200px; }

h1 { font-size: 22px; margin: 0 0 18px; }
h2 { font-size: 16px; margin: 0 0 12px; color: var(--text); }

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 18px 20px;
  margin-bottom: 20px;
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 14px;
  margin-bottom: 22px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px;
}

.card .label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.card .value { font-size: 22px; font-weight: bold; margin-top: 4px; }
.card .sub { font-size: 12px; color: var(--muted); margin-top: 4px; }

.positive { color: var(--green); }
.negative { color: var(--red); }
.warning { color: var(--amber); }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--border); }
th { font-size: 12px; text-transform: uppercase; color: var(--muted); font-weight: 600; }
/* Zebra striping — declared before the status-color rules below so those
   (row-negative/row-credit/row-confirmed/bold-row) always win when a row
   is both alternating AND has a meaningful status color. */
tr.row-alt td { background: #f6f8fb; }
tr.bold-row td { font-weight: bold; background: #f8fafc; }
tr.row-negative td { background: #fdecea; }
tr.row-credit td { background: #e6f6ed; }
tr.row-confirmed td { background: #eef0f2; color: var(--muted); }
tr.row-negative.bold-row td { background: #fbdfdb; }
tr.row-credit.bold-row td { background: #d9f0e2; }
tr.row-confirmed.bold-row td { background: #e6e9ec; }
tr:hover td { background: #fafcff; }
tr.row-negative:hover td { background: #fbdcd8; }
tr.row-credit:hover td { background: #ddf1e5; }
tr.row-confirmed:hover td { background: #e6e9ec; }

.right { text-align: right; }
.center { text-align: center; }

.toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; flex-wrap: wrap; gap: 10px; }
.toolbar .nav-links a { margin-right: 10px; text-decoration: none; color: var(--accent); font-size: 14px; }

.month-tabs {
  display: flex;
  overflow-x: auto;
  gap: 2px;
  margin-bottom: 20px;
  border-bottom: 2px solid var(--border);
}
.month-tabs .month-tab {
  flex-shrink: 0;
  padding: 8px 14px;
  font-size: 13px;
  text-decoration: none;
  color: var(--muted);
  background: #eef1f5;
  border-radius: 6px 6px 0 0;
  white-space: nowrap;
}
.month-tabs .month-tab:hover { background: #e4e9f0; color: var(--text); }
.month-tabs .month-tab.active { background: var(--accent); color: #fff; font-weight: bold; }

form.inline { display: inline; }

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 10px;
  align-items: end;
}

.form-grid label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 3px; }
.form-grid input, .form-grid select, .form-grid textarea {
  width: 100%;
  padding: 7px 8px;
  border: 1px solid var(--border);
  border-radius: 5px;
  font-size: 14px;
  font-family: inherit;
}

button, .btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 5px;
  padding: 8px 14px;
  font-size: 13px;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
}

button.secondary, .btn.secondary { background: #eef1f5; color: var(--text); }
button.danger, .btn.danger { background: #fdecea; color: var(--red); }
button:hover { opacity: .9; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 11px; font-weight: bold; }
.badge-style-amber { background: #fff4e0; color: var(--amber); }
.badge-style-blue { background: #e8f0fe; color: var(--accent); }
.badge-style-grey { background: #dde1e6; color: var(--muted); }
/* "pending" (nothing scheduled yet) is deliberately the loudest badge in the
   app — a solid fill plus a border, not just a tinted pill like the rest —
   so it's impossible to mistake for something already handled. */
.badge-style-red { background: var(--red); color: #fff; border: 1px solid #a3301e; letter-spacing: .03em; }

.pill { display: inline-block; padding: 2px 7px; border-radius: 8px; font-size: 11px; background: #eef1f5; color: var(--muted); }

.flash-stack { margin-bottom: 16px; }
.flash { padding: 10px 14px; border-radius: 6px; font-size: 14px; margin-bottom: 8px; }
.flash-error { background: #fdecea; color: var(--red); }
.flash-success { background: #e6f6ed; color: var(--green); }

.progress-bar { background: #eef1f5; border-radius: 6px; height: 8px; overflow: hidden; }
.progress-bar > div { background: var(--accent); height: 100%; }

.bar-chart-v-wrap { overflow-x: auto; }
.bar-chart-v { display: flex; align-items: flex-end; gap: 10px; height: 220px; padding-top: 10px; min-width: 760px; }
.bar-chart-v-col { flex: 1; min-width: 54px; display: flex; flex-direction: column; align-items: center; height: 100%; }
/* Fixed height, rendered for every column whether or not it has spike text
   — otherwise the bar-wrap below (flex:1) ends up a different height in
   spike vs. non-spike columns, and the bars stop being visually comparable
   even though their underlying values are fine. */
.bar-chart-v-spike-note { height: 32px; display: flex; align-items: flex-end; justify-content: center; font-size: 10px; color: var(--amber); text-align: center; max-width: 92px; line-height: 1.2; overflow: hidden; margin: 0 auto; }
.bar-chart-v-bar-wrap { flex: 1; display: flex; align-items: flex-end; width: 100%; }
.bar-chart-v-bar { width: 100%; background: var(--accent); border-radius: 4px 4px 0 0; min-height: 3px; transition: opacity .15s; }
.bar-chart-v-bar:hover { opacity: .8; }
.bar-chart-v-bar.bar-spike { background: var(--amber); }
.bar-chart-v-value { font-size: 11px; font-weight: bold; margin-top: 6px; white-space: nowrap; }
.bar-chart-v-label { font-size: 11px; color: var(--muted); margin-top: 2px; white-space: nowrap; }

.center-page {
  max-width: 380px;
  margin: 12vh auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 28px 30px;
}
.collapsible-header { cursor: pointer; user-select: none; margin-bottom: 12px; }
.collapsible-arrow { display: inline-block; margin-right: 6px; transition: transform .15s ease; }
.collapsible-panel.collapsed .collapsible-header { margin-bottom: 0; }
.collapsible-panel.collapsed .collapsible-arrow { transform: rotate(-90deg); }
.collapsible-panel.collapsed .collapsible-body { display: none; }

.balance-pill { font-size: 13px; font-weight: bold; padding: 3px 10px; border-radius: 8px; background: #eef1f5; }
.balance-pill.positive { color: var(--green); }
.balance-pill.negative { color: var(--red); }

/* The current week gets a visible accent border + tinted header so it's
   immediately obvious where "now" falls in the month, collapsed or not. */
.collapsible-panel.current-week { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); background: #f7faff; }
.collapsible-panel.current-week .collapsible-header { background: #eaf1fe; padding: 8px 10px; border-radius: 6px; margin-left: -10px; margin-right: -10px; }
.collapsible-panel.current-week.collapsed .collapsible-header { margin-bottom: 0; }
.pill-current { background: var(--accent); color: #fff; font-weight: bold; }

.center-page h1 { font-size: 18px; }
.center-page p { color: var(--muted); font-size: 13px; }

.two-col { display: grid; grid-template-columns: 1.3fr 1fr; gap: 20px; }
@media (max-width: 900px) { .two-col { grid-template-columns: 1fr; } }

.masked { font-family: monospace; letter-spacing: 1px; }
.reveal-btn { font-size: 11px; color: var(--accent); background: none; border: none; cursor: pointer; padding: 0; }

.nav-logout { margin-top: 16px; padding: 0 10px; }
.nav-logout button { width: 100%; }

/* Installed app (PWA) on iPhone uses a translucent status bar, so content
   would otherwise slide under the clock/notch. env() is 0 everywhere else. */
.sidenav { padding-top: calc(20px + env(safe-area-inset-top)); }

/* Phone layout: the side nav becomes a sticky, swipeable bar across the
   top; wide tables scroll sideways inside their panel instead of squashing
   or pushing the whole page sideways. */
@media (max-width: 760px) {
  .shell { flex-direction: column; }
  .sidenav {
    width: 100%;
    flex-direction: row;
    align-items: center;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding: env(safe-area-inset-top) 6px 0;
    position: sticky;
    top: 0;
    z-index: 10;
  }
  .sidenav::-webkit-scrollbar { display: none; }
  .sidenav .brand { display: none; }
  .sidenav a { flex-shrink: 0; white-space: nowrap; padding: 13px 12px; font-size: 14px; }
  .nav-logout { margin: 0 0 0 auto; padding: 0 6px; flex-shrink: 0; }
  .nav-logout button { width: auto; padding: 6px 10px; font-size: 12px; }

  .content { padding: 16px 16px calc(24px + env(safe-area-inset-bottom)); max-width: 100%; min-width: 0; }
  h1 { font-size: 19px; margin-bottom: 14px; }
  .panel { padding: 14px; overflow-x: auto; }
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .card { padding: 12px; }
  .card .value { font-size: 18px; }
  table { font-size: 13px; }
  th, td { padding: 6px; }
  /* 16px+ stops iPhone Safari from zooming the page when a field is tapped. */
  .form-grid input, .form-grid select, .form-grid textarea, input, select, textarea { font-size: 16px; }
  .form-grid { grid-template-columns: 1fr 1fr; }
  .center-page { margin: 6vh auto; padding: 22px 18px; }
}
