:root {
  --accent: #4f83cc;
  --accent-dark: #3d6aa8;
  --accent-soft: #e9f2fb;
  --bg: #f5f5fa;
  --card-bg: #ffffff;
  --border: #ececf3;
  --text: #16161f;
  --text-muted: #6b7280;
  --danger-bg: #fde8e8;
  --danger-border: #f5b5b5;
  --danger-text: #b42318;
  --paid-bg: #e9f9ef;
  --paid-text: #15803d;
  --unpaid-bg: #fff4e5;
  --unpaid-text: #b45309;
}

* { box-sizing: border-box; }

body {
  font-family: -apple-system, "Segoe UI", system-ui, sans-serif;
  max-width: 1000px;
  margin: 2rem auto;
  padding: 0 1rem;
  color: var(--text);
  background: var(--bg);
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1rem 1.5rem;
  margin-bottom: 1.5rem;
}

.topbar h1 {
  font-size: 1.15rem;
  margin: 0;
}

.taskbar-nav {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.inline-form {
  display: inline;
}

.btn-link.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 0.35rem;
}

.section-title {
  font-size: 1.5rem;
  font-weight: 700;
  margin: 0 0 1.25rem;
}

.card {
  position: relative;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}

.row {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  align-items: center;
}

input, select {
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card-bg);
  color: var(--text);
  font-size: 0.9rem;
}

input:focus, select:focus {
  outline: 2px solid var(--accent-soft);
  border-color: var(--accent);
}

input.narrow {
  width: 3.5rem;
}

.auth-page {
  display: flex;
  justify-content: center;
  margin-top: 4rem;
}

.auth-card {
  width: 100%;
  max-width: 360px;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.stack label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.stack input {
  font-size: 1rem;
}

.form-error {
  background: var(--danger-bg);
  border: 1px solid var(--danger-border);
  color: var(--danger-text);
  border-radius: 8px;
  padding: 0.6rem 0.85rem;
  font-size: 0.85rem;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th, td {
  text-align: left;
  padding: 0.65rem 0.5rem;
  border-bottom: 1px solid var(--border);
}

th {
  text-transform: uppercase;
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  font-weight: 700;
}

tr.paid td {
  color: var(--text-muted);
}

.actions form {
  display: inline;
}

button {
  padding: 0.45rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #f3f3f7;
  color: var(--text);
  cursor: pointer;
  font-size: 0.85rem;
}

button:hover {
  background: #e9e9f0;
}

button.primary, button[type="submit"] {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

button.primary:hover, button[type="submit"]:hover {
  background: var(--accent-dark);
}

button.danger {
  background: var(--danger-bg);
  border-color: var(--danger-border);
  color: var(--danger-text);
}

.btn-link {
  display: inline-block;
  padding: 0.45rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #f3f3f7;
  color: var(--text);
  text-decoration: none;
  font-size: 0.85rem;
}

.btn-link:hover {
  background: #e9e9f0;
}

.badge {
  background: var(--accent);
  color: #fff;
  border-radius: 10px;
  padding: 0 0.5rem;
  font-size: 0.75rem;
  margin-left: 0.3rem;
}

.status-pill {
  display: inline-block;
  padding: 0.15rem 0.6rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: capitalize;
}

.status-pill.paid {
  background: var(--paid-bg);
  color: var(--paid-text);
}

.status-pill.unpaid {
  background: var(--unpaid-bg);
  color: var(--unpaid-text);
}

.income-icon {
  width: 20px;
  height: 20px;
  vertical-align: middle;
  margin-right: 0.35rem;
}

.review-status-icon {
  width: 16px;
  height: 16px;
  vertical-align: middle;
  margin-right: 0.35rem;
}

.repeats-empty-icon {
  width: 12px;
  height: 12px;
  vertical-align: middle;
  color: var(--text-muted);
}

.notes-details summary {
  cursor: pointer;
  list-style: none;
}

.notes-details summary::-webkit-details-marker {
  display: none;
}

.notes-details summary::before {
  content: "\25B8";
  display: inline-block;
  margin-right: 0.3rem;
  color: var(--text-muted);
  transition: transform 0.15s ease;
}

.notes-details[open] summary::before {
  transform: rotate(90deg);
}

.notes-content {
  margin-top: 0.3rem;
  padding: 0.4rem 0.6rem;
  background: #f3f3f7;
  border-radius: 6px;
  font-size: 0.82rem;
  color: var(--text-muted);
  white-space: pre-wrap;
  max-width: 260px;
}

.hint {
  color: var(--text-muted);
  font-size: 0.85rem;
}

.income-veiled {
  cursor: pointer;
}

.income-header-veiled {
  visibility: hidden;
}

.income-veil-label {
  color: var(--text-muted);
  letter-spacing: 0.1em;
}

.income-group-summary td {
  font-weight: 600;
}

.income-group-toggle {
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

.income-group-chevron {
  transition: transform 0.15s ease;
}

.income-group-toggle[aria-expanded="true"] .income-group-chevron {
  transform: rotate(90deg);
}

.income-group-detail td:first-child {
  padding-left: 1.6rem;
}

.notice {
  background: var(--accent-soft);
  border: 1px solid #c5dcf3;
  padding: 0.6rem;
  border-radius: 8px;
}

.toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  max-width: 320px;
  background: var(--text);
  color: #fff;
  padding: 0.75rem 1rem;
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 50;
}

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

.toast-text {
  font-size: 0.85rem;
  line-height: 1.35;
}

.toast-close {
  background: none;
  border: none;
  color: #fff;
  opacity: 0.7;
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  padding: 0;
}

.toast-close:hover {
  opacity: 1;
}

.pending-row {
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 0;
}

.snippet {
  font-style: italic;
  margin-bottom: 0.4rem;
}

.search-row {
  margin-bottom: 1rem;
}

/* ---- dashboard ---- */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem;
  margin-bottom: 1.75rem;
}

.stat-tile {
  position: relative;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem 1.8rem 1rem 1.1rem;
}

.stat-label {
  text-transform: uppercase;
  font-size: 0.7rem;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  font-weight: 700;
  margin-bottom: 0.5rem;
}

.stat-value {
  font-size: 1.7rem;
  font-weight: 700;
  color: var(--text);
}

.stat-info-wrap {
  position: absolute;
  top: 0.7rem;
  right: 0.7rem;
}

.stat-info-toggle {
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  display: inline-flex;
  vertical-align: middle;
}

.stat-info-icon {
  width: 15px;
  height: 15px;
  display: block;
  opacity: 0.6;
  transition: opacity 0.15s ease;
}

.stat-info-toggle:hover .stat-info-icon,
.stat-info-wrap.active .stat-info-icon {
  opacity: 1;
}

.stat-info-tooltip {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: max-content;
  max-width: 200px;
  background: var(--text);
  color: #fff;
  font-size: 0.78rem;
  font-weight: 400;
  line-height: 1.35;
  padding: 0.45rem 0.65rem;
  border-radius: 8px;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.18);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(-4px);
  transition: opacity 0.15s ease, transform 0.15s ease;
  z-index: 20;
}

.stat-info-tooltip::after {
  content: "";
  position: absolute;
  bottom: 100%;
  right: 8px;
  border: 5px solid transparent;
  border-bottom-color: var(--text);
}

.stat-info-toggle:hover + .stat-info-tooltip,
.stat-info-wrap.active .stat-info-tooltip {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.pie-row {
  display: flex;
  gap: 2rem;
  align-items: center;
  flex-wrap: wrap;
}

.donut {
  width: 160px;
  height: 160px;
  flex: none;
}

.donut-track {
  fill: none;
  stroke: var(--border);
  stroke-width: 18;
}

.pie-slice {
  fill: none;
  stroke-width: 18;
  stroke-linecap: butt;
  transition: stroke-dasharray 1s ease;
}

.donut-total {
  font-size: 16px;
  font-weight: 700;
  fill: var(--text);
  text-anchor: middle;
}

.donut-caption {
  font-size: 8px;
  fill: var(--text-muted);
  text-anchor: middle;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.legend {
  list-style: none;
  margin: 0;
  padding: 0;
  flex: 1;
  min-width: 220px;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.legend li {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.88rem;
}

.swatch {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex: none;
}

.legend-name {
  flex: 1;
}

.legend-amount {
  color: var(--text-muted);
}

.legend-pct {
  font-weight: 700;
  min-width: 3.5rem;
  text-align: right;
}

.stat-tile-link {
  display: block;
  text-decoration: none;
  color: inherit;
  transition: border-color .15s ease, transform .15s ease;
}

.stat-tile-link:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
}

/* ---- bills header / tabs ---- */

.bills-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1rem;
}

.bills-header .section-title {
  margin-bottom: 0;
}

.tabs-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-bottom: 1rem;
}

.tabs-row .tabs {
  margin-bottom: 0;
}

.tabs {
  display: flex;
  gap: 0.4rem;
  margin-bottom: 1rem;
}

.tab {
  padding: 0.4rem 0.9rem;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 600;
}

.tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* ---- modal ---- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 15, 31, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity .2s ease;
  z-index: 100;
}

.modal-overlay.open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.modal-panel {
  background: var(--card-bg);
  border-radius: 14px;
  padding: 1.5rem;
  max-width: 640px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 24px 64px rgba(15, 15, 31, 0.28);
  transform: translateY(16px) scale(.97);
  transition: transform .22s ease;
}

.modal-overlay.open .modal-panel {
  transform: translateY(0) scale(1);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-header .section-title {
  margin-bottom: 0;
}

/* ---- icon buttons / row actions ---- */

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #f3f3f7;
  color: var(--text);
  cursor: pointer;
  padding: 0;
  flex: none;
}

.icon-btn:hover {
  background: #e9e9f0;
}

a.icon-btn {
  text-decoration: none;
}

.pay-form {
  display: inline;
}

button.icon-btn.pay-toggle {
  background: transparent;
  border-color: transparent;
}

button.icon-btn.pay-toggle:hover {
  background: var(--bg);
}

.pay-icon {
  overflow: visible;
}

.pay-ring {
  fill: none;
  stroke: var(--border);
  stroke-width: 2;
  transition: stroke .3s ease, fill .3s ease;
}

.pay-check {
  fill: none;
  stroke: #fff;
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 20;
  stroke-dashoffset: 20;
  transition: stroke-dashoffset .3s ease .05s;
}

.pay-toggle.paid .pay-ring {
  fill: var(--paid-text);
  stroke: var(--paid-text);
}

.pay-toggle.paid .pay-check {
  stroke-dashoffset: 0;
}

.pay-toggle.animating {
  transform: scale(1.12);
  transition: transform .18s ease;
}

.actions {
  width: 194px;
}

.actions-viewport {
  overflow: hidden;
  width: 194px;
}

.actions-track {
  display: flex;
  width: 388px;
  transition: transform .25s ease;
}

.actions-track.confirming {
  transform: translateX(-194px);
}

.action-row, .confirm-row {
  width: 194px;
  flex: none;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.confirm-row {
  justify-content: flex-end;
}

.confirm-label {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-right: 0.2rem;
}

button.confirm-yes {
  background: var(--danger-text);
  border-color: var(--danger-text);
  color: #fff;
  padding: 0.4rem 0.7rem;
}

button.confirm-yes:hover {
  background: #93190f;
}

.confirm-no {
  padding: 0.4rem 0.7rem;
}

/* ---- section switcher ---- */
/* One panel shown at a time, all rendered at the same full width - a tab
   row (reusing the .tabs/.tab pill styling used elsewhere) switches which
   one, instead of the old side-by-side "aside cards you click on" layout,
   which produced two identical arrow icons once a 3rd card was added and
   never let same-sized cards sit next to each other. */

.panel-switcher {
  margin-bottom: 1rem;
}

.focus-stage {
  display: block;
}

.focus-panel {
  display: none;
}

.focus-panel.is-focused {
  display: block;
}

@media (max-width: 720px) {
  /* Touch targets + form usability on phones */
  body {
    margin: 1rem auto;
  }

  .topbar {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.75rem;
  }

  .taskbar-nav {
    width: 100%;
  }

  .taskbar-nav .btn-link,
  .taskbar-nav .inline-form,
  .taskbar-nav .inline-form button {
    flex: 1 1 auto;
    width: 100%;
    text-align: center;
  }

  input, select {
    font-size: 16px; /* below 16px, iOS Safari zooms in on focus */
  }

  .row input, .row select {
    flex: 1 1 160px;
  }

  .row input.narrow {
    flex: 0 0 3.5rem;
  }

  .icon-btn {
    width: 42px;
    height: 42px;
  }

  button, .btn-link, .tab {
    padding: 0.55rem 0.9rem; /* taller tap targets than the mouse-sized default */
  }

  .modal-panel {
    padding: 1.1rem;
  }

  .stat-value {
    font-size: 1.45rem;
  }
}

/* Tables can outgrow a phone screen (Actions column alone is ~200px) -
   scope the scroll to the table itself so the page never scrolls sideways. */
.table-scroll {
  overflow-x: auto;
}

/* ---- your bills / totals flip card ---- */

.flip-scene {
  perspective: 2000px;
}

.flip-card {
  position: relative;
  width: 100%;
  transform-style: preserve-3d;
  transition: transform 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

.flip-card.flipped {
  transform: rotateY(180deg);
}

.flip-face {
  width: 100%;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

.flip-face.flip-back {
  position: absolute;
  inset: 0;
  transform: rotateY(180deg);
}

.flip-face.flip-back .card {
  max-height: 640px;
  overflow-y: auto;
}

.modal-hint {
  margin-top: 0.75rem;
}

/* ---- privacy blur ---- */

.focus-panel:not(.revealed) > .flip-scene,
.focus-panel:not(.revealed) > section.card {
  filter: blur(10px);
  pointer-events: none;
  user-select: none;
  transition: filter .35s ease;
}

.focus-panel.revealed > .flip-scene,
.focus-panel.revealed > section.card {
  transition: filter .35s ease;
}

.privacy-veil {
  display: none;
  position: absolute;
  inset: 0;
  z-index: 40;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 0.5rem;
  cursor: pointer;
  color: var(--text);
}

.privacy-veil svg {
  color: var(--accent);
}

.privacy-veil-label {
  font-weight: 700;
  background: var(--card-bg);
  border: 1px solid var(--border);
  padding: 0.5rem 1.1rem;
  border-radius: 999px;
  box-shadow: 0 10px 30px rgba(15, 15, 31, 0.12);
}

.focus-panel.is-focused:not(.revealed) .privacy-veil {
  display: flex;
}
