:root {
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #f4f7fb;
  color: #0f172a;
  --page: #f4f7fb;
  --panel: #ffffff;
  --panel-soft: #f8fafc;
  --line: #d9e2ef;
  --line-strong: #cbd5e1;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --accent: #14b8a6;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --shadow: 0 18px 50px rgba(15, 23, 42, .08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--page);
  color: var(--text);
  overflow-x: hidden;
}

button, input, select {
  font: inherit;
  max-width: 100%;
  min-width: 0;
}

button {
  min-height: 46px;
  border: 0;
  border-radius: 9px;
  background: var(--primary);
  color: #fff;
  font-weight: 800;
  padding: 0 16px;
}

button:hover { background: var(--primary-dark); }
button:active { transform: translateY(1px); opacity: .88; }
button:disabled { cursor: not-allowed; opacity: .45; }

button.secondary {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line-strong);
}

button.secondary:hover { background: var(--panel-soft); }

button.compact {
  min-height: 30px;
  padding: 0 9px;
  margin-top: 0;
  border-radius: 8px;
  font-size: 13px;
}

.hidden { display: none !important; }

.screen {
  width: 100%;
  min-height: 100svh;
  padding: max(20px, env(safe-area-inset-top)) 16px max(28px, env(safe-area-inset-bottom));
  overflow-x: hidden;
}

.auth {
  display: grid;
  place-items: center;
  background:
    linear-gradient(135deg, rgba(37, 99, 235, .08), rgba(20, 184, 166, .12)),
    var(--page);
}

.auth-shell {
  width: min(100%, 1080px);
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(320px, .8fr);
  gap: 22px;
  align-items: center;
}

.auth-copy {
  min-width: 0;
}

.auth-copy h1 {
  font-size: clamp(34px, 6vw, 58px);
  max-width: 680px;
}

.eyebrow {
  margin-bottom: 10px;
  color: var(--primary-dark);
  font-size: 13px;
  font-weight: 900;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.auth-description {
  max-width: 620px;
  margin: 10px 0 16px;
  color: #334155;
  font-size: 17px;
  line-height: 1.55;
}

.auth-highlights {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 18px;
}

.auth-highlights span {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 0 11px;
  border: 1px solid rgba(37, 99, 235, .16);
  border-radius: 999px;
  background: rgba(255, 255, 255, .72);
  color: #1e293b;
  font-size: 13px;
  font-weight: 800;
}

.auth-hero {
  display: block;
  width: 100%;
  max-height: 390px;
  object-fit: cover;
  object-position: center;
  border: 1px solid rgba(203, 213, 225, .85);
  border-radius: 12px;
  box-shadow: 0 24px 60px rgba(15, 23, 42, .14);
}

.auth-panel {
  width: 100%;
}

.auth-panel h2 {
  margin-bottom: 6px;
}

.panel, .tab-page {
  width: min(100%, 760px);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 18px;
  box-shadow: var(--shadow);
}

.panel { padding: 24px; }
.app { max-width: 980px; margin: 0 auto; }

h1, h2, h3, p { margin-top: 0; }
h1 { font-size: 30px; line-height: 1.1; margin-bottom: 6px; letter-spacing: 0; }
h2 { font-size: 22px; margin-bottom: 14px; letter-spacing: 0; }
h3 { font-size: 16px; margin: 22px 0 10px; letter-spacing: 0; }
.small, .muted { color: var(--muted); font-size: 13px; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.topbar p { margin-bottom: 0; color: var(--muted); }

.bucket-panel {
  width: 100%;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 14px;
}

.bucket-panel label { margin-bottom: 6px; }
.bucket-panel p { margin-bottom: 0; }

.stats, .cards {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.cards.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.stat, .card {
  min-width: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-top: 4px solid var(--primary);
  border-radius: 10px;
  padding: 10px;
  min-height: 66px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, .05);
}

.stat span, .card span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.stat strong, .card strong {
  display: block;
  font-size: clamp(15px, 4vw, 18px);
  margin-top: 8px;
  overflow-wrap: anywhere;
}

.tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin-bottom: 16px;
}

.tab {
  background: var(--panel);
  color: #334155;
  border: 1px solid var(--line-strong);
  min-height: 42px;
  padding: 0 4px;
  font-size: clamp(11px, 3.2vw, 13px);
}

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

.tab-page { width: 100%; min-width: 0; }

label {
  display: grid;
  gap: 7px;
  color: #334155;
  font-size: 13px;
  font-weight: 800;
  margin-bottom: 13px;
}

input, select {
  width: 100%;
  display: block;
  min-height: 46px;
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  background: #ffffff;
  color: var(--text);
  padding: 0 12px;
  font-size: 16px;
}

input:focus, select:focus {
  outline: 3px solid rgba(37, 99, 235, .16);
  border-color: var(--primary);
}

input[type="date"] { line-height: 46px; min-width: 0; }
input[type="color"] { padding: 4px; }

.list, .chart { display: grid; gap: 10px; }

.spending-tools {
  display: grid;
  grid-template-columns: minmax(160px, 190px) minmax(260px, 1fr) auto;
  gap: 10px;
  align-items: end;
  margin-bottom: 10px;
}

.spending-tools label {
  margin-bottom: 0;
}

.spending-tools input {
  min-height: 46px;
}

.spending-tools #expenseCount {
  align-self: end;
  min-height: 46px;
  display: inline-flex;
  align-items: center;
  white-space: nowrap;
  padding-bottom: 2px;
}

.export-panel {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto auto;
  gap: 8px;
  align-items: end;
  margin-bottom: 10px;
}

.export-panel label {
  margin-bottom: 0;
}

.export-panel select {
  min-height: 78px;
}

.search-field { margin-bottom: 0; }

.expense-table-wrap,
.admin-table-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
}

.expense-table,
.admin-table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
  font-size: 14px;
}

.expense-table th,
.expense-table td,
.admin-table th,
.admin-table td {
  border-bottom: 1px solid var(--line);
  padding: 8px 10px;
  text-align: left;
  vertical-align: middle;
}

.expense-table tbody tr:hover,
.admin-table tbody tr:hover { background: var(--panel-soft); }

.expense-table tbody tr:last-child td,
.admin-table tbody tr:last-child td { border-bottom: 0; }

.admin-table {
  min-width: 860px;
  font-size: 13px;
}

.admin-table input,
.admin-table select {
  min-height: 34px;
  padding: 6px 8px;
  font-size: 13px;
}

.admin-table input[type="color"] {
  width: 42px;
  min-height: 34px;
  padding: 3px;
}

.sort-header {
  min-height: 30px;
  width: 100%;
  justify-content: space-between;
  display: flex;
  align-items: center;
  gap: 8px;
  background: transparent;
  color: var(--muted);
  border-radius: 6px;
  padding: 0 4px;
  text-align: left;
  font-size: 12px;
  text-transform: uppercase;
}

.sort-header:hover,
.sort-header.active {
  background: #eaf1ff;
  color: var(--primary-dark);
}

.description-cell {
  min-width: 220px;
  font-weight: 800;
}

.amount-cell {
  text-align: right;
  white-space: nowrap;
  font-weight: 900;
}

.table-actions {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  white-space: nowrap;
}

.admin-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  white-space: nowrap;
}

.current-user-row {
  background: #f8fbff;
}

.user-name-cell {
  min-width: 210px;
}

.user-name-cell input {
  width: min(190px, 100%);
}

.you-badge {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 2px 7px;
  border-radius: 999px;
  background: #eaf1ff;
  color: var(--primary-dark);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

.security-note {
  margin: -6px 0 10px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.pin-cell {
  min-width: 150px;
}

.email-cell {
  min-width: 220px;
}

.color-cell {
  width: 62px;
}

.bucket-table {
  min-width: 900px;
}

.bucket-name-cell {
  min-width: 220px;
}

.bucket-name-cell input {
  width: min(240px, 100%);
}

.currency-cell {
  min-width: 190px;
}

.members-cell {
  min-width: 220px;
}

.member-select {
  width: 100%;
  min-height: 96px;
  padding: 6px 8px;
  overflow: auto;
  font-size: 13px;
}

.member-select option {
  padding: 4px 6px;
}

.row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  background: var(--panel-soft);
  min-width: 0;
}

.user-editor {
  display: grid;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  background: var(--panel-soft);
}

.checkbox-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 13px;
}

.checkbox-list label {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  background: var(--panel-soft);
}

.checkbox-list input {
  width: auto;
  min-height: auto;
}

.user-editor-heading,
.user-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.user-editor-heading span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.user-actions { justify-content: flex-end; }

#userForm {
  display: grid;
  grid-template-columns: repeat(6, minmax(110px, 1fr)) auto;
  gap: 8px;
  align-items: end;
}

#bucketForm {
  display: grid;
  grid-template-columns: minmax(160px, 220px) minmax(150px, 200px) minmax(0, 1fr) auto;
  gap: 8px;
  align-items: end;
}

#userForm label {
  margin-bottom: 0;
}

#bucketForm label,
#newBucketMembers {
  margin-bottom: 0;
}

#newBucketMembers h4 {
  margin: 0 0 6px;
  font-size: 13px;
}

#newBucketMembers .member-select {
  min-height: 78px;
}

#userForm button,
#bucketForm button {
  min-height: 40px;
  white-space: nowrap;
}

.row p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.amount { font-weight: 900; white-space: nowrap; font-size: clamp(13px, 3.5vw, 16px); }

.danger {
  background: var(--danger);
  min-height: 36px;
}

.danger:hover { background: #b91c1c; }

.empty {
  color: var(--muted);
  text-align: center;
  padding: 18px;
  border: 1px dashed var(--line-strong);
  border-radius: 10px;
  background: var(--panel-soft);
}

.bar-label {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-weight: 800;
  margin-bottom: 7px;
}

.bar-progress {
  display: block;
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  height: 10px;
  border: 0;
  border-radius: 999px;
  overflow: hidden;
  background: #e2e8f0;
}

.bar-progress::-webkit-progress-bar {
  background: #e2e8f0;
  border-radius: 999px;
}

.bar-progress::-webkit-progress-value {
  background: var(--accent);
  border-radius: 999px;
}

.bar-progress::-moz-progress-bar {
  background: var(--accent);
  border-radius: 999px;
}

.report-kpis {
  grid-template-columns: repeat(12, minmax(0, 1fr));
}

.report-kpis .card {
  grid-column: span 3;
}

.report-kpis .card:nth-child(n+5) {
  grid-column: span 4;
}

.pie-chart-card {
  display: grid;
  grid-template-columns: minmax(170px, 220px) minmax(0, 1fr);
  gap: 18px;
  align-items: center;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-soft);
}

.donut-chart {
  position: relative;
  width: min(100%, 220px);
  aspect-ratio: 1;
  display: grid;
  place-items: center;
}

.donut-chart svg {
  width: 100%;
  height: 100%;
}

.donut-total {
  position: absolute;
  inset: 23%;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 4px;
  min-width: 0;
  padding: 8px;
  text-align: center;
  border-radius: 50%;
  background: var(--panel);
  box-shadow: 0 0 0 1px rgba(15, 23, 42, .06);
}

.donut-chart strong {
  max-width: 100%;
  font-size: clamp(13px, 1.5vw, 16px);
  line-height: 1.05;
  white-space: nowrap;
}

.donut-chart span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  line-height: 1;
}

.pie-legend {
  display: grid;
  gap: 8px;
  min-width: 0;
}

.pie-legend-row {
  display: grid;
  grid-template-columns: 12px minmax(0, 1fr) auto;
  gap: 9px;
  align-items: center;
  min-width: 0;
  font-weight: 800;
}

.pie-legend-row span:nth-child(2) {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pie-legend-row strong {
  display: inline-flex;
  gap: 7px;
  align-items: baseline;
  white-space: nowrap;
}

.pie-legend-row em {
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
}

.pie-swatch {
  width: 12px;
  height: 12px;
  box-shadow: 0 0 0 1px rgba(15, 23, 42, .12);
}

.report-controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

@media (max-width: 880px) {
  .auth-shell {
    grid-template-columns: 1fr;
    gap: 16px;
  }

  .auth-copy {
    text-align: center;
  }

  .auth-description {
    margin-left: auto;
    margin-right: auto;
  }

  .auth-highlights {
    justify-content: center;
  }

  .auth-hero {
    max-height: 280px;
  }

  .report-kpis {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .report-kpis .card,
  .report-kpis .card:nth-child(n+5) {
    grid-column: auto;
  }
}

@media (max-width: 620px) {
  .auth {
    place-items: start center;
  }

  .auth-shell {
    gap: 12px;
  }

  .auth-description {
    font-size: 15px;
    line-height: 1.45;
  }

  .auth-hero {
    max-height: 190px;
    border-radius: 10px;
  }

  .auth-panel {
    padding: 18px;
  }

  .stats, .cards, .cards.four { grid-template-columns: 1fr 1fr; }
  .report-kpis { grid-template-columns: 1fr; }
  .pie-chart-card { grid-template-columns: 1fr; }
  .donut-chart { justify-self: center; max-width: 210px; }
  .topbar { align-items: flex-start; }
  .report-controls { grid-template-columns: 1fr; }
  .export-panel { grid-template-columns: 1fr; }
  .spending-tools { grid-template-columns: 1fr; }
  .checkbox-list { grid-template-columns: 1fr; }
  #userForm { grid-template-columns: 1fr; }
  #bucketForm { grid-template-columns: 1fr; }
}
