/* Household Money Dashboard — calm, durable, dark-friendly */

:root {
  --bg: #0f1419;
  --bg-elev: #161d25;
  --bg-card: #1a232d;
  --bg-hover: #222c38;
  --border: #2a3544;
  --text: #e8eef4;
  --text-muted: #8b9aab;
  --accent: #5b9fd4;
  --accent-soft: rgba(91, 159, 212, 0.15);
  --positive: #3dba7a;
  --positive-soft: rgba(61, 186, 122, 0.12);
  --negative: #e07070;
  --negative-soft: rgba(224, 112, 112, 0.12);
  --warn: #d4a05b;
  --warn-soft: rgba(212, 160, 91, 0.15);
  --stub: #6b7a8a;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --max: 1100px;
  --space: 1rem;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f6f8;
    --bg-elev: #ffffff;
    --bg-card: #ffffff;
    --bg-hover: #eef2f6;
    --border: #d5dde6;
    --text: #1a2330;
    --text-muted: #5c6b7a;
    --accent: #2a7ab8;
    --accent-soft: rgba(42, 122, 184, 0.1);
    --positive: #1f8a52;
    --positive-soft: rgba(31, 138, 82, 0.1);
    --negative: #c44;
    --negative-soft: rgba(204, 68, 68, 0.1);
    --warn: #a67c2e;
    --warn-soft: rgba(166, 124, 46, 0.12);
    --stub: #7a8896;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  }
}

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

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
  min-height: 100dvh;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--accent);
  color: #fff;
  padding: 0.5rem 1rem;
  z-index: 100;
}
.skip-link:focus {
  left: 0.5rem;
  top: 0.5rem;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

/* Header */
.app-header {
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.header-inner {
  max-width: var(--max);
  margin: 0 auto;
  padding: 0.85rem var(--space);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.brand-mark {
  font-size: 1.5rem;
  color: var(--accent);
  line-height: 1;
}

.brand h1 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 650;
  letter-spacing: -0.02em;
}

.subtitle {
  margin: 0.1rem 0 0;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.header-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
}

.badge {
  display: inline-block;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  text-transform: uppercase;
}

.badge-example {
  background: var(--warn-soft);
  color: var(--warn);
  border: 1px solid var(--warn);
}

.badge-live {
  background: var(--positive-soft);
  color: var(--positive);
  border: 1px solid var(--positive);
  text-transform: none;
  letter-spacing: 0.04em;
}

.last-updated {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.month-nav {
  max-width: var(--max);
  margin: 0 auto;
  padding: 0  var(--space) 0.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
}

.month-label {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  min-width: 9rem;
  text-align: center;
}

.btn-icon {
  width: 2.25rem;
  height: 2.25rem;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  border-radius: var(--radius-sm);
  font-size: 1.25rem;
  cursor: pointer;
  line-height: 1;
}
.btn-icon:hover {
  background: var(--bg-hover);
}
.btn-icon:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

/* Main */
.main {
  max-width: var(--max);
  margin: 0 auto;
  padding: 1.25rem var(--space) 3rem;
}

.section {
  margin-bottom: 2rem;
}

.section-head {
  margin-bottom: 0.85rem;
}

.section-head h2 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.section-note {
  margin: 0.2rem 0 0;
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* Summary cards */
.card-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.85rem;
}

@media (min-width: 640px) {
  .card-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (min-width: 960px) {
  .card-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

.summary-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  min-height: 100%;
}

.summary-card.primary {
  border-color: var(--accent);
  box-shadow: var(--shadow), 0 0 0 1px var(--accent-soft);
}

.summary-card.stub {
  opacity: 0.72;
}

.card-title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem;
}

.card-title {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 650;
}

.card-tag {
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--stub);
  background: var(--bg-hover);
  padding: 0.15rem 0.4rem;
  border-radius: 3px;
  white-space:nowrap;
}

.card-tag.active {
  color: var(--accent);
  background: var(--accent-soft);
}

.metric-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  flex: 1;
}

.metric {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.5rem;
  font-size: 0.8rem;
}

.metric-label {
  color: var(--text-muted);
}

.metric-value {
  font-variant-numeric: tabular-nums;
  font-family: var(--mono);
  font-size: 0.78rem;
}

.metric.emphasis {
  margin-top: 0.35rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border);
  font-weight: 600;
}

.metric.emphasis .metric-label {
  color: var(--text);
}

.surplus {
  color: var(--positive);
}
.shortage {
  color: var(--negative);
}

.example-chip {
  font-size: 0.55rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: var(--warn);
  vertical-align: super;
  margin-left: 0.15rem;
}

.example-chip.live-chip {
  background: var(--positive-soft);
  color: var(--positive);
  border-color: var(--positive);
}

/* Dues table */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
  box-shadow: var(--shadow);
}

.dues-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
  min-width: 560px;
}

.dues-table th,
.dues-table td {
  padding: 0.65rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.dues-table th {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  font-weight: 600;
  background: var(--bg-elev);
  position: sticky;
  top: 0;
}

.dues-table tbody tr:last-child td {
  border-bottom: none;
}

.dues-table tbody tr:hover {
  background: var(--bg-hover);
}

.dues-table tbody tr.dues-row-warn {
  background: var(--warn-soft);
}

.dues-table tbody tr.dues-row-warn:hover {
  background: rgba(212, 160, 91, 0.22);
}

.dues-table tbody tr.dues-row-warn td.account-nick {
  color: var(--warn);
  font-weight: 600;
}

.dues-table .amount {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
}

.status-pill {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
}

.status-paid {
  background: var(--positive-soft);
  color: var(--positive);
}

.status-topay {
  background: var(--warn-soft);
  color: var(--warn);
}

.account-nick {
  color: var(--text-muted);
  font-size: 0.78rem;
}

.how-tag {
  font-size: 0.7rem;
  color: var(--text-muted);
}

/* Liquid / invest */
.split-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.85rem;
}

@media (min-width: 640px) {
  .split-grid {
    grid-template-columns: 1fr 1fr;
  }
}

.panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
}

.panel h3 {
  margin: 0 0 0.75rem;
  font-size: 0.85rem;
  font-weight: 650;
}

.balance-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.balance-list li {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.75rem;
  padding: 0.45rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}

.balance-list li:last-child {
  border-bottom: none;
}

.balance-list .name {
  color: var(--text);
}

.balance-list .bal {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-size: 0.8rem;
}

.balance-list .total {
  font-weight: 650;
  margin-top: 0.25rem;
  padding-top: 0.55rem;
  border-top: 1px solid var(--border);
  border-bottom: none;
}

/* Data panel */
.data-panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.data-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.45rem 0.85rem;
  font-size: 0.8rem;
  font-weight: 600;
  font-family: inherit;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-elev);
  color: var(--text);
  cursor: pointer;
}

.btn:hover {
  background: var(--bg-hover);
}

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

.btn-primary:hover {
  filter: brightness(1.08);
}

.file-label {
  position: relative;
  overflow: hidden;
}

.file-label input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.csv-paste {
  width: 100%;
  resize: vertical;
  min-height: 6rem;
  padding: 0.75rem;
  font-family: var(--mono);
  font-size: 0.75rem;
  line-height: 1.4;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.csv-paste:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.csv-meta {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.csv-preview-wrap {
  max-height: 220px;
  overflow: auto;
}

.csv-preview-wrap:empty,
#csv-preview:not(:has(td)) {
  display: none;
}

.app-footer {
  max-width: var(--max);
  margin: 0 auto;
  padding: 0 var(--space) 2rem;
  text-align: center;
}

.app-footer p {
  margin: 0;
  font-size: 0.7rem;
  color: var(--text-muted);
}

.logout-btn {
  position: fixed;
  top: 0.75rem;
  left: 0.75rem;
  z-index: 100;
  display: inline-flex;
  align-items: center;
  min-height: 2.4rem;
  padding: 0.4rem 0.85rem;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,0.14);
  background: rgba(15, 20, 25, 0.92);
  color: #9aa3b2;
  font: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  text-decoration: none;
  backdrop-filter: blur(8px);
}
.logout-btn:hover, .logout-btn:focus-visible {
  color: #f2f4f8;
  border-color: #3b82f6;
  outline: 2px solid #3b82f6;
  outline-offset: 2px;
}
.app-header { padding-top: 2.75rem; }
