:root {
  --bg: #f3f4f6;
  --surface: #ffffff;
  --surface-2: #f8f9fa;
  --surface-3: #eef1f4;
  --border: #d0d7de;
  --border-strong: #b7bec6;
  --text: #1f2328;
  --text-dim: #656d76;
  --excel: #217346;        /* Excel green */
  --excel-dark: #1a5c38;
  --excel-light: #e6f3ec;
  --accent: #c47f0a;
  --danger: #cf222e;
  --danger-light: #ffebe9;
  --radius: 6px;
  --shadow: 0 8px 28px rgba(31,35,40,.18);
  --grid-head: #f3f4f6;
  --cell-paid: #e6f4ea;
  --cell-partial: #fff4d6;
  --cell-due: #fde8e8;
  --font-grid: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font-grid);
  background: var(--bg); color: var(--text);
  font-size: 13.5px; line-height: 1.5;
}
a { color: inherit; text-decoration: none; }

#app { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar {
  width: 230px; flex-shrink: 0; background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 11px; padding: 18px; border-bottom: 1px solid var(--border); }
.brand-mark {
  width: 38px; height: 38px; border-radius: 8px;
  background: linear-gradient(135deg, var(--excel), var(--excel-dark));
  display: grid; place-items: center; font-size: 20px; font-weight: 700; color: #fff;
}
.brand-name { font-weight: 700; font-size: 17px; }
.brand-sub { font-size: 10.5px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 1px; }
.nav { display: flex; flex-direction: column; padding: 12px 10px; gap: 3px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 13px; border-radius: 6px; color: var(--text-dim); font-weight: 500; }
.nav a .ico { width: 18px; text-align: center; }
.nav a:hover { background: var(--surface-3); color: var(--text); }
.nav a.active { background: var(--excel-light); color: var(--excel-dark); font-weight: 600; }
.sidebar-foot { margin-top: auto; padding: 14px 18px; border-top: 1px solid var(--border); }
.foot-note { font-size: 11px; color: var(--text-dim); }
.auth-actions { display: grid; gap: 8px; margin-top: 12px; }
.auth-email { overflow: hidden; color: var(--text-dim); font-size: 11px; text-overflow: ellipsis; }
.auth-signout { justify-content: center; width: 100%; }

/* Authentication pages */
.auth-landing, .auth-page {
  min-height: 100vh;
  background: var(--bg);
}
.auth-landing-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px clamp(18px, 5vw, 72px);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.auth-landing-card {
  width: min(640px, calc(100% - 32px));
  margin: clamp(54px, 12vh, 120px) auto;
  padding: clamp(26px, 6vw, 52px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 8px 28px rgba(31,35,40,.08);
}
.auth-landing-logo { display: block; width: 48px; height: 48px; margin-bottom: 20px; }
.auth-eyebrow {
  margin: 0 0 8px;
  color: var(--excel-dark);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
}
.auth-landing-card h1 { margin: 0; font-size: clamp(28px, 5vw, 42px); line-height: 1.15; }
.auth-intro { max-width: 480px; margin: 16px 0 26px; color: var(--text-dim); font-size: 15px; }
.auth-landing-actions { display: flex; align-items: center; gap: 20px; flex-wrap: wrap; }
.auth-signup-link { color: var(--excel-dark); font-weight: 600; text-decoration: underline; text-underline-offset: 3px; }
.auth-page { display: grid; place-items: center; padding: 24px 16px; }

/* Content */
.content { flex: 1; padding: 24px 30px; max-width: 1280px; }
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; gap: 16px; flex-wrap: wrap; }
.page-head h1 { margin: 0; font-size: 22px; }
.page-head .sub { color: var(--text-dim); font-size: 13px; margin-top: 2px; }
.breadcrumb { color: var(--text-dim); font-size: 13px; margin-bottom: 8px; }
.breadcrumb a:hover { color: var(--excel); }

/* Cards & grid */
.grid { display: grid; gap: 14px; }
.cols-4 { grid-template-columns: repeat(4, 1fr); }
.cols-3 { grid-template-columns: repeat(3, 1fr); }
.cols-2 { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 1000px){ .cols-4{grid-template-columns:repeat(2,1fr)} .cols-3,.cols-2{grid-template-columns:1fr} }
@media (max-width: 720px){ .sidebar{width:60px} .brand-name,.brand-sub,.nav a span:not(.ico),.foot-note{display:none} .content{padding:16px} .cols-4{grid-template-columns:1fr} }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.card h3 { margin: 0 0 12px; font-size: 14px; }

.stat .label { color: var(--text-dim); font-size: 11.5px; text-transform: uppercase; letter-spacing: .5px; }
.stat .value { font-size: 24px; font-weight: 700; margin-top: 5px; font-variant-numeric: tabular-nums; }
.stat .value.sm { font-size: 19px; }
.stat .foot { font-size: 12px; color: var(--text-dim); margin-top: 4px; }
.stat .value.good { color: var(--excel); }
.stat .value.warn { color: var(--accent); }
.stat .value.bad { color: var(--danger); }

/* Tables (spreadsheet look) */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 11px; border: 1px solid var(--border); }
th { background: var(--grid-head); font-size: 11px; text-transform: uppercase; letter-spacing: .4px; color: var(--text-dim); font-weight: 600; position: sticky; top: 0; }
tbody tr:hover { background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: auto; }
.clickable { cursor: pointer; }
tfoot td { background: var(--surface-3); font-weight: 700; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 6px;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  font-weight: 600; font-size: 13px; cursor: pointer; transition: .12s;
}
.btn:hover { background: var(--surface-2); border-color: var(--text-dim); }
.btn.primary { background: var(--excel); border-color: var(--excel); color: #fff; }
.btn.primary:hover { background: var(--excel-dark); }
.btn.danger { background: var(--surface); border-color: #e5a1a5; color: var(--danger); }
.btn.danger:hover { background: var(--danger-light); }
.btn.sm { padding: 5px 10px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* Badges */
.badge { display: inline-block; padding: 2px 8px; border-radius: 20px; font-size: 11px; font-weight: 600; }
.badge.green { background: var(--cell-paid); color: var(--excel-dark); }
.badge.amber { background: var(--cell-partial); color: #8a6100; }
.badge.red { background: var(--cell-due); color: #a40e19; }
.badge.grey { background: var(--surface-3); color: var(--text-dim); }

/* Workbook sheet tabs */
.workbook { margin-top: 14px; }
.sheet-tabs { display: flex; gap: 2px; border-bottom: 2px solid var(--excel); flex-wrap: wrap; }
.sheet-tab {
  padding: 9px 18px; border: 1px solid var(--border); border-bottom: none;
  border-radius: 6px 6px 0 0; background: var(--surface-3); color: var(--text-dim);
  font-weight: 600; font-size: 13px; cursor: pointer; margin-bottom: -1px;
}
.sheet-tab:hover { background: var(--surface-2); color: var(--text); }
.sheet-tab.active { background: var(--surface); color: var(--excel-dark); border-color: var(--excel); border-bottom: 2px solid var(--surface); }
.sheet-body { background: var(--surface); border: 1px solid var(--border); border-top: none; border-radius: 0 0 var(--radius) var(--radius); padding: 18px; }
.sheet-toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.sheet-toolbar h3 { margin: 0; font-size: 16px; }

/* Collection grid */
.grid-scroll { overflow: auto; max-height: 70vh; border: 1px solid var(--border); border-radius: var(--radius); }
table.collection { border-collapse: separate; border-spacing: 0; min-width: 100%; }
table.collection th, table.collection td { border: 1px solid var(--border); padding: 0; white-space: nowrap; }
table.collection thead th { background: var(--grid-head); padding: 7px 8px; text-align: center; position: sticky; top: 0; z-index: 3; }
table.collection tbody th.rowhead, table.collection thead th.corner, table.collection tfoot th.rowhead {
  position: sticky; left: 0; z-index: 2; background: var(--grid-head); text-align: left; padding: 7px 10px; min-width: 150px; text-transform: none; letter-spacing: 0; font-size: 12.5px; color: var(--text);
}
table.collection thead th.corner { z-index: 4; }
table.collection td.cell { text-align: right; }
table.collection td.cell input {
  width: 100%; border: none; background: transparent; padding: 7px 8px; text-align: right;
  font-variant-numeric: tabular-nums; font-family: inherit; font-size: 13px; color: var(--text);
}
table.collection td.cell input:focus { outline: 2px solid var(--excel); outline-offset: -2px; background: #fff; }
table.collection td.paid { background: var(--cell-paid); }
table.collection td.partial { background: var(--cell-partial); }
table.collection td.due { background: var(--cell-due); }
table.collection td.future { background: var(--surface-2); }
table.collection td.total, table.collection tfoot td { text-align: right; font-weight: 700; background: var(--surface-3); font-variant-numeric: tabular-nums; padding: 7px 8px; }
table.collection tfoot th, table.collection tfoot td { position: sticky; bottom: 0; z-index: 2; }
.cell-win { box-shadow: inset 0 0 0 2px var(--accent); }

/* Editable cells in auction/members */
td.edit input, td.edit select {
  width: 100%; border: 1px solid transparent; background: transparent; padding: 5px 6px;
  font-family: inherit; font-size: 13px; color: var(--text); border-radius: 4px;
}
td.edit input:focus, td.edit select:focus { outline: none; border-color: var(--excel); background: #fff; }
td.edit input.num { text-align: right; font-variant-numeric: tabular-nums; }

/* Forms / modal */
#modal-root:empty { display: none; }
.modal-overlay { position: fixed; inset: 0; background: rgba(31,35,40,.45); display: grid; place-items: center; padding: 20px; z-index: 50; }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; width: 100%; max-width: 520px; box-shadow: var(--shadow); max-height: 90vh; overflow: auto; }
.modal.wide { max-width: 820px; }
.modal-head { padding: 16px 20px; border-bottom: 1px solid var(--border); display:flex; justify-content:space-between; align-items:center; }
.modal-head h2 { margin: 0; font-size: 17px; }
.modal-body { padding: 20px; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }
.close-x { background: none; border: none; color: var(--text-dim); font-size: 22px; cursor: pointer; line-height: 1; }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12px; color: var(--text-dim); margin-bottom: 5px; font-weight: 600; }
.field input, .field select, .field textarea { width: 100%; padding: 9px 11px; border-radius: 6px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); font-size: 14px; font-family: inherit; }
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--excel); box-shadow: 0 0 0 2px var(--excel-light); }
.field .hint { font-size: 11px; color: var(--text-dim); margin-top: 5px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.field-row.three { grid-template-columns: 1fr 1fr 1fr; }
.calc-preview { background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; padding: 13px; margin-top: 4px; font-size: 13px; }
.calc-preview .row { display: flex; justify-content: space-between; padding: 3px 0; }
.calc-preview .row.total { border-top: 1px solid var(--border); margin-top: 6px; padding-top: 7px; font-weight: 700; }
.checkbox-row { display: flex; align-items: center; gap: 8px; }
.checkbox-row input { width: auto; }

/* Misc */
.empty { text-align: center; padding: 44px 20px; color: var(--text-dim); }
.empty .big { font-size: 38px; margin-bottom: 10px; }
.money { font-variant-numeric: tabular-nums; }
.pos { color: var(--excel); } .neg { color: var(--danger); }
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.section-title { font-size: 12.5px; text-transform: uppercase; letter-spacing: .5px; color: var(--text-dim); margin: 22px 0 9px; font-weight: 700; }
#toast-root { position: fixed; bottom: 22px; right: 22px; display: flex; flex-direction: column; gap: 10px; z-index: 100; }
.toast { background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--excel); padding: 11px 16px; border-radius: 6px; box-shadow: var(--shadow); min-width: 230px; animation: slidein .2s; }
.toast.err { border-left-color: var(--danger); }
@keyframes slidein { from { transform: translateX(20px); opacity: 0 } }
.loading { padding: 40px; text-align: center; color: var(--text-dim); }
.progress { height: 7px; background: var(--surface-3); border-radius: 20px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--excel); }
.pill-legend { display: flex; gap: 14px; font-size: 12px; color: var(--text-dim); flex-wrap: wrap; }
.pill-legend span { display: inline-flex; align-items: center; gap: 5px; }
.swatch { width: 12px; height: 12px; border-radius: 3px; border: 1px solid var(--border); display: inline-block; }

/* Print (passbook) */
@media print {
  .sidebar, .sheet-tabs, .sheet-toolbar, .no-print, #toast-root { display: none !important; }
  .content { padding: 0; } .sheet-body { border: none; }
  body { background: #fff; }
}
