:root {
  color-scheme: light dark;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", sans-serif;
  --bg: #f5f7f8;
  --panel: rgba(255, 255, 255, 0.9);
  --panel-solid: #ffffff;
  --text: #172c35;
  --muted: #667982;
  --line: #e2e9ec;
  --line-strong: #d0dce0;
  --accent: #17765f;
  --accent-soft: rgba(23, 118, 95, 0.11);
  --past-due: #b5483e;
  --past-due-soft: rgba(181, 72, 62, 0.07);
  --shadow: 0 22px 54px rgba(39, 68, 78, 0.09);
  --app-header-height: 94px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html {
  min-width: 320px;
  min-height: 100%;
  overflow-x: clip;
  background: var(--bg);
}

body {
  min-height: 100vh;
  margin: 0;
  overflow-x: clip;
  color: var(--text);
  background:
    radial-gradient(circle at 12% -8%, var(--accent-soft), transparent 32rem),
    var(--bg);
  font-size: 16px;
  line-height: 1.45;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

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

.app-shell {
  width: min(100%, 900px);
  max-width: 100%;
  margin: 0 auto;
  padding: 0 16px max(24px, env(safe-area-inset-bottom));
}

.page-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 11px;
  min-height: calc(94px + env(safe-area-inset-top));
  margin: 0 -16px;
  padding: env(safe-area-inset-top) 20px 0;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
  text-align: center;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

.brand-home {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
  padding: 0;
  color: var(--text);
  border: 0;
  background: transparent;
  cursor: pointer;
}

.brand-title {
  font-size: clamp(1.65rem, 4vw, 2rem);
  font-weight: 700;
  letter-spacing: -0.035em;
  line-height: 1.05;
}

.admin-menu-wrap { position: relative; }
.menu-button {
  display: grid;
  width: 44px;
  height: 44px;
  place-content: center;
  gap: 4px;
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  background: var(--panel-solid);
  cursor: pointer;
}
.menu-button span { width: 4px; height: 4px; border-radius: 50%; background: var(--accent); }
.admin-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 30;
  min-width: 150px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel-solid);
  box-shadow: var(--shadow);
}
.admin-menu button { width: 100%; padding: 10px 12px; color: var(--text); border: 0; border-radius: 9px; background: transparent; text-align: left; font: inherit; font-weight: 700; cursor: pointer; }
.admin-menu button:hover { background: var(--accent-soft); }

.brand-mark {
  display: grid;
  width: 46px;
  height: 46px;
  place-items: center;
  padding: 9px;
  border: 1px solid color-mix(in srgb, var(--accent) 28%, transparent);
  border-radius: 15px;
  background: linear-gradient(145deg, var(--accent-soft), transparent);
}

.brand-mark svg {
  width: 27px;
  height: 27px;
  overflow: visible;
  fill: none;
  stroke: var(--accent);
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.eyebrow {
  margin: 0 0 2px;
  color: var(--muted);
  font-size: 0.69rem;
  font-weight: 740;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(1.65rem, 4vw, 2rem);
  letter-spacing: -0.035em;
  line-height: 1.05;
}

.table-panel {
  width: 100%;
  min-width: 0;
  overflow: visible;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px) saturate(135%);
  -webkit-backdrop-filter: blur(18px) saturate(135%);
}

.table-scroll {
  width: 100%;
  min-width: 0;
  overflow: visible;
}

table {
  width: 100%;
  max-width: 100%;
  min-width: 580px;
  border-collapse: collapse;
  table-layout: fixed;
  font-variant-numeric: tabular-nums;
}

th,
td {
  padding: 15px 20px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

thead th {
  position: sticky;
  top: calc(var(--app-header-height) + env(safe-area-inset-top));
  z-index: 8;
  color: var(--muted);
  background: var(--panel-solid);
  font-size: 0.72rem;
  font-weight: 750;
  letter-spacing: 0.075em;
  text-transform: uppercase;
}

tbody tr:last-child td { border-bottom: 1px solid var(--line-strong); }
tbody tr:hover { background: var(--accent-soft); }
tbody td:first-child { width: 110px; color: var(--muted); white-space: nowrap; }
tbody td:nth-child(2) { font-weight: 590; }
tbody tr.past-due { background: var(--past-due-soft); }
tbody tr.past-due:hover { background: color-mix(in srgb, var(--past-due-soft) 72%, var(--accent-soft)); }
tbody tr.past-due td:first-child { color: var(--past-due); box-shadow: inset 3px 0 var(--past-due); }
.past-due-label { display: block; margin-top: 1px; font-size: 0.62rem; font-weight: 760; line-height: 1.05; letter-spacing: 0.015em; }

.amount {
  width: 138px;
  text-align: right;
  white-space: nowrap;
}

tfoot {
  position: sticky;
  bottom: 0;
  z-index: 7;
}

tfoot th,
tfoot td {
  border-bottom: 0;
  background: color-mix(in srgb, var(--panel-solid) 88%, var(--accent));
  font-size: 1rem;
  font-weight: 760;
}

.footer-meta td {
  padding-top: 4px;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 500;
}

.footer-meta-content {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  width: 100%;
}

.footer-meta-content span { white-space: nowrap; }
.past-due-count { color: var(--past-due); font-weight: 720; }

button, input, select { font: inherit; }
.auth-panel { padding: 24px; border: 1px solid var(--line); border-radius: 24px; background: var(--panel); box-shadow: var(--shadow); }
.auth-panel h2 { margin: 0 0 8px; font-size: 1.45rem; }
.auth-panel h3 { margin: 26px 0 10px; }
.auth-panel > p { color: var(--muted); }
.auth-panel form { display: grid; gap: 10px; }
.auth-panel label { font-size: 0.83rem; font-weight: 700; }
input, select { width: 100%; min-height: 46px; padding: 10px 12px; color: var(--text); border: 1px solid var(--line-strong); border-radius: 12px; background: var(--panel-solid); }
.primary, .text-button { min-height: 42px; padding: 9px 14px; border-radius: 12px; cursor: pointer; }
.primary { color: #fff; border: 1px solid var(--accent); background: var(--accent); font-weight: 720; }
.text-button { color: var(--accent); border: 1px solid transparent; background: transparent; font-weight: 700; }
.notice { padding: 12px 14px; border: 1px solid var(--line); border-radius: 14px; background: var(--accent-soft); }
.notice.error { color: #a43d32; }
.inline-form { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.member-list { padding: 0; margin: 0; list-style: none; }
.member-list li { display: flex; justify-content: space-between; gap: 12px; padding: 13px 0; border-top: 1px solid var(--line); }
.member-list span { color: var(--muted); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid label { display: grid; gap: 6px; }
.form-grid .wide { grid-column: 1 / -1; }
.form-actions { display: flex; align-items: center; gap: 8px; margin-top: 4px; }
.inline-admin-tools { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 14px; border-bottom: 1px solid var(--line); background: var(--panel-solid); }
.inline-admin-tools span { color: var(--muted); font-size: 0.72rem; font-weight: 750; letter-spacing: 0.075em; text-transform: uppercase; }
.inline-admin-tools .primary { min-height: 38px; padding: 7px 13px; }
.inline-bill-form { display: grid; gap: 10px; padding: 16px 20px 18px; border-bottom: 1px solid var(--line-strong); background: var(--panel-solid); scroll-margin-top: calc(var(--app-header-height) + env(safe-area-inset-top)); }
.inline-bill-form label { display: grid; gap: 6px; font-size: 0.83rem; font-weight: 700; }
.inline-bill-form p { margin: 0; color: var(--past-due); }
.description { min-width: 0; }
.bill-description { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bill-row-actions { display: flex; gap: 10px; margin-top: 5px; }
.row-action { padding: 0; color: var(--accent); border: 0; background: transparent; font: inherit; font-size: 0.72rem; font-weight: 740; cursor: pointer; }
.danger-button { min-height: 42px; padding: 9px 10px; color: var(--past-due); border: 1px solid transparent; border-radius: 12px; background: transparent; font: inherit; font-weight: 700; cursor: pointer; }
.row-action.danger-button { min-height: 0; padding: 0; border-radius: 0; }

@media (max-width: 620px) {
  :root { --app-header-height: 106px; }
  .app-shell { padding-right: 10px; padding-left: 10px; }
  .page-header {
    min-height: calc(106px + env(safe-area-inset-top));
    margin-right: -10px;
    margin-left: -10px;
    padding-right: 18px;
    padding-left: 18px;
  }
  .table-panel {
    width: calc(100% + 20px);
    margin-right: -10px;
    margin-left: -10px;
    border-top: 0;
    border-right: 0;
    border-bottom: 0;
    border-left: 0;
    border-radius: 0;
  }
  table { min-width: 0; }
  th, td { padding: 12px 10px; }
  tr > :first-child { padding-left: 14px; }
  tr > :last-child { padding-right: 14px; }
  thead th { font-size: 0.65rem; }
  thead th:first-child, tbody td:first-child { width: 72px; }
  tbody td { font-size: clamp(0.72rem, 3.25vw, 0.84rem); }
  tbody td:first-child { white-space: nowrap; }
  tbody td:nth-child(2) { overflow: hidden; line-height: 1.25; }
  .amount { width: 100px; }
  tfoot th, tfoot td { font-size: 0.86rem; }
  .footer-meta td { padding-bottom: calc(12px + env(safe-area-inset-bottom)); font-size: 0.7rem; }
  .inline-bill-form { padding: 14px; }
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #10161a;
    --panel: rgba(24, 32, 37, 0.91);
    --panel-solid: #182025;
    --text: #f0f5f4;
    --muted: #91a2a8;
    --line: rgba(164, 184, 191, 0.14);
    --line-strong: rgba(164, 184, 191, 0.25);
    --accent: #57c9a7;
    --accent-soft: rgba(87, 201, 167, 0.11);
    --past-due: #ff8d82;
    --past-due-soft: rgba(255, 141, 130, 0.08);
    --shadow: 0 22px 60px rgba(0, 0, 0, 0.22);
  }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; }
}
