:root {
  --ink:        #1c2631;   /* logo navy — topbar, headings, text */
  --ink-deep:   #0b1b29;   /* logo gauge navy — meter readouts */
  --ink-soft:   #47585f;
  --teal:       #2a6e6b;   /* primary actions */
  --teal-dark:  #1d5250;
  --accent:      #4f7e80;  /* muted teal accent (from logo) */
  --accent-soft: #a7c6c6;  /* light teal — active states, readouts */
  --mist:       #eef2f2;
  --paper:      #fbfcfc;
  --line:       #d4dcdb;
  --line-soft:  #e6ecec;
  --danger:     #b04532;
  --ok:         #2a6e6b;
  --shadow:     0 1px 2px rgba(11,27,41,.05), 0 8px 24px rgba(11,27,41,.07);
  --radius:     10px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--mist);
  color: var(--ink);
  font-family: "Inter", -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px; line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
.muted { color: var(--ink-soft); margin: 0; }

h1, h2, h3 { font-family: "Inter", -apple-system, "Segoe UI", Roboto, sans-serif; font-weight: 600; letter-spacing: -0.01em; }

/* ---------- buttons ---------- */
.btn { font: inherit; font-weight: 500; border: 1px solid transparent; border-radius: 8px; padding: 9px 16px; cursor: pointer; transition: background .15s, border-color .15s, transform .05s; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--teal); color: #fff; }
.btn.primary:hover { background: var(--teal-dark); }
.btn.ghost { background: transparent; color: var(--ink-soft); border-color: var(--line); }
.btn.ghost:hover { border-color: var(--ink-soft); color: var(--ink); }
.btn.small { padding: 5px 11px; font-size: 13px; }
.btn.danger { color: var(--danger); border-color: transparent; background: transparent; }
.btn.danger:hover { background: #f6e7e3; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: radial-gradient(120% 90% at 50% -10%, #dbe9e6 0%, var(--mist) 55%); }
.login-card { background: var(--paper); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); padding: 40px 36px; width: 100%; max-width: 400px; text-align: center; }
.login-card .login-logo { width: 112px; height: 112px; display: block; margin: 0 auto 18px; }
.login-card h1 { font-family: "Inter", -apple-system, "Segoe UI", Roboto, sans-serif; font-weight: 700; letter-spacing: -0.01em; font-size: 26px; margin: 4px 0 2px; }
.login-card h1 span { display: block; font-size: 15px; color: var(--accent); font-weight: 500; letter-spacing: .04em; text-transform: uppercase; font-family: "Inter", sans-serif; }
.login-card label { display: block; text-align: left; font-size: 13px; font-weight: 500; margin: 22px 0 6px; }
.login-card input { width: 100%; }
.login-card .btn.primary { width: 100%; margin-top: 18px; }
.sent-note p { color: var(--ink); margin: 24px 0 16px; }
.error { color: var(--danger); font-size: 13px; min-height: 18px; margin: 12px 0 0; }

/* ---------- inputs ---------- */
input, select, textarea { font: inherit; color: var(--ink); background: var(--paper); border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); outline-offset: 1px; border-color: var(--accent); }
textarea { width: 100%; resize: vertical; font-family: "IBM Plex Mono", monospace; font-size: 13.5px; line-height: 1.55; }

/* ---------- topbar ---------- */
.topbar { display: flex; align-items: center; gap: 20px; padding: 12px 24px; background: var(--ink); color: #dfe9e7; position: sticky; top: 0; z-index: 10; }
.brand { display: flex; align-items: center; gap: 11px; text-decoration: none; color: inherit; cursor: pointer; }
.brand:hover { opacity: .85; }
.brand-logo { width: 40px; height: 40px; display: block; }
.brand strong { display: block; font-family: "Inter", -apple-system, "Segoe UI", Roboto, sans-serif; font-weight: 700; font-size: 17px; letter-spacing: -0.01em; color: #fff; line-height: 1.1; }
.brand span { font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: var(--accent-soft); }
.tabs { display: flex; gap: 2px; margin-left: 12px; flex-wrap: wrap; }
.nav-menu { display: flex; flex: 1; align-items: center; }
.nav-toggle { display: none; background: none; border: none; color: var(--accent-soft); cursor: pointer; padding: 6px; border-radius: 8px; align-items: center; }
.nav-toggle:hover { background: rgba(255,255,255,.08); color: #fff; }
.nav-toggle .icon-close { display: none; }
.topbar.nav-open .nav-toggle .icon-bars { display: none; }
.topbar.nav-open .nav-toggle .icon-close { display: block; }
.tabs button { font: inherit; font-size: 14px; background: transparent; border: none; cursor: pointer; color: #9fb6b2; padding: 7px 13px; border-radius: 7px; }
.tabs button:hover { color: #fff; background: rgba(255,255,255,.06); }
.tabs button.active { color: var(--ink); background: var(--accent-soft); }
.account { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.who { font-size: 12.5px; color: #9fb6b2; max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#logout { color: #9fb6b2; border-color: rgba(255,255,255,.15); }
#logout:hover { color: #fff; border-color: rgba(255,255,255,.4); }

/* ---------- layout ---------- */
main { max-width: 980px; margin: 0 auto; padding: 30px 24px 80px; }
.section-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 20px; margin-bottom: 22px; flex-wrap: wrap; }
.section-head h2 { font-size: 24px; margin: 0 0 4px; }
.subhead { font-size: 16px; margin: 34px 0 4px; color: var(--ink); }
.panel .subhead:first-child { margin-top: 0; }
.date-field { display: flex; flex-direction: column; gap: 5px; }
.date-field label { font-size: 12px; font-weight: 500; color: var(--ink-soft); letter-spacing: .02em; }

.action-bar { display: flex; align-items: center; gap: 16px; margin-top: 22px; }
.feedback { font-size: 14px; color: var(--ink-soft); }
.feedback.ok { color: var(--ok); }
.feedback.err { color: var(--danger); }

/* ---------- cards / tables ---------- */
.card { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
table { width: 100%; border-collapse: collapse; }
thead th { text-align: left; font-size: 11.5px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-soft); padding: 13px 16px; background: var(--line-soft); border-bottom: 1px solid var(--line); }
tbody td { padding: 12px 16px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
th.num, td.num { text-align: right; }
.cottage-name { font-weight: 500; }
.sub { font-size: 12.5px; color: var(--ink-soft); }

/* meter readout — mono digits on a dark dial panel */
.readout { font-family: "IBM Plex Mono", monospace; font-size: 14px; letter-spacing: .04em; background: var(--ink-deep); color: var(--accent-soft); padding: 3px 9px; border-radius: 5px; display: inline-block; min-width: 62px; text-align: right; }
.readout.plain { background: transparent; color: var(--ink); padding: 0; }
.amount { font-family: "IBM Plex Mono", monospace; font-weight: 500; }
.reading-input { width: 108px; text-align: right; font-family: "IBM Plex Mono", monospace; }
.tag-irr { font-size: 11px; font-weight: 600; color: var(--teal-dark); background: #dcece9; border-radius: 999px; padding: 1px 8px; margin-left: 8px; letter-spacing: .02em; white-space: nowrap; }
.tag-row { display: flex; flex-wrap: nowrap; gap: 6px; margin-top: 5px; }
.tag-row .tag-irr { margin-left: 0; }

.pill { font-size: 11.5px; font-weight: 600; padding: 2px 9px; border-radius: 999px; letter-spacing: .03em; font-family: "Inter", sans-serif; }
.pill.sent { background: #dcece9; color: var(--teal-dark); }
.pill.failed { background: #f6e0da; color: var(--danger); }
.pill.skipped { background: #eceef0; color: var(--ink-soft); }
.pill.none { background: #f2eee4; color: #8a6a1e; }

/* ---------- panels / forms ---------- */
.panel { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px 22px; margin-bottom: 18px; box-shadow: var(--shadow); }
.panel label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 14px; }
.panel label input, .panel label textarea { display: block; width: 100%; margin-top: 6px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 20px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0 16px; }
.hint { font-size: 12.5px; color: var(--ink-soft); margin: 2px 0 0; }
.chips { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 12px; }
.chip { font-family: "IBM Plex Mono", monospace; font-size: 12.5px; background: var(--mist); border: 1px solid var(--line); border-radius: 6px; padding: 4px 9px; cursor: pointer; }
.chip:hover { border-color: var(--accent); background: #fff; }

.check-row { display: flex !important; align-items: center; gap: 10px; margin: 0 0 14px; font-weight: 400 !important; cursor: pointer; }
.check-row input[type="checkbox"] { width: 18px; height: 18px; flex: 0 0 auto; margin: 0; padding: 0; border: none; background: none; accent-color: var(--teal); }

/* ---------- modal ---------- */
.modal { position: fixed; inset: 0; background: rgba(15,40,48,.45); display: grid; place-items: center; z-index: 50; padding: 20px; }
.modal-card { background: var(--paper); border-radius: 14px; padding: 28px; width: 100%; max-width: 440px; box-shadow: 0 20px 60px rgba(15,40,48,.3); }
.modal-card h3 { font-size: 20px; margin: 0 0 18px; }
.modal-card label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 14px; }
.modal-card label input { display: block; width: 100%; margin-top: 6px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }
.confirm-message { color: var(--ink-soft); line-height: 1.6; margin: 0; white-space: pre-line; }
.btn.danger-solid { background: var(--danger); color: #fff; }
.btn.danger-solid:hover { background: #97392a; }

/* ---------- toast / empty ---------- */
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 12px 20px; border-radius: 10px; box-shadow: var(--shadow); font-size: 14px; z-index: 60; max-width: 90vw; }
.toast.err { background: var(--danger); }
.empty { text-align: center; padding: 48px 20px; color: var(--ink-soft); }
.empty strong { display: block; color: var(--ink); font-family: "Inter", -apple-system, "Segoe UI", Roboto, sans-serif; font-size: 18px; margin-bottom: 6px; }
.row-actions { display: flex; gap: 4px; justify-content: flex-end; }

/* ---------- scrollable table with pinned first column (Take readings) ---------- */
.card.scroll-x { overflow-x: auto; overflow-y: hidden; }
table.pinned { min-width: 100%; border-collapse: separate; border-spacing: 0; }
table.pinned th { white-space: nowrap; }
table.pinned th, table.pinned td { border-bottom: 1px solid var(--line-soft); }
table.pinned tbody tr:last-child td { border-bottom: none; }
table.pinned .sticky-col {
  position: sticky; left: 0; z-index: 2;
  background: var(--paper); box-shadow: 1px 0 0 var(--line);
}
table.pinned thead .sticky-col { z-index: 3; background: var(--line-soft); }
table.pinned tbody tr:hover td { background: #f5f9f8; }
table.pinned tbody tr:hover .sticky-col { background: #eef4f3; }

/* ---------- history matrix ---------- */
.card.matrix-wrap { overflow-x: auto; overflow-y: hidden; }
table.matrix {
  min-width: 100%;
  border-collapse: separate;  /* sticky columns require separate, not collapse */
  border-spacing: 0;
}
/* re-add horizontal rules manually (separate borders don't merge like collapse) */
table.matrix th, table.matrix td { border-bottom: 1px solid var(--line-soft); }
table.matrix tbody tr:last-child td { border-bottom: none; }

table.matrix th.year-group {
  text-align: center; text-transform: none; letter-spacing: 0;
  font-family: "Inter", -apple-system, "Segoe UI", Roboto, sans-serif; font-size: 15px; color: var(--ink);
  border-left: 2px solid var(--line); border-bottom: 1px solid var(--line);
}
table.matrix th.sub-col { font-size: 10.5px; padding: 8px 14px; white-space: nowrap; }
table.matrix td.sub-col { padding: 11px 14px; white-space: nowrap; font-family: "IBM Plex Mono", monospace; font-size: 13px; }
table.matrix td.sub-col .readout, table.matrix td.sub-col .amount { font-size: 13px; }
table.matrix th.sub-col.group-start,
table.matrix td.sub-col.group-start { border-left: 2px solid var(--line); }
table.matrix .dim { color: var(--ink-soft); opacity: .55; }

/* pinned first column — sticks to the left edge of the scroll container */
table.matrix .sticky-col {
  position: sticky; left: 0; z-index: 2;
  background: var(--paper);
  box-shadow: 1px 0 0 var(--line);  /* divider that scrolls-proof, unlike a border */
}
table.matrix thead .sticky-col { z-index: 3; background: var(--line-soft); }
table.matrix tbody tr:hover td { background: #f5f9f8; }
table.matrix tbody tr:hover .sticky-col { background: #eef4f3; }

/* ---------- responsive ---------- */
/* ---------- left sub-menu (Bills) ---------- */
.subnav-layout { display: flex; gap: 26px; align-items: flex-start; }
.subnav { display: flex; flex-direction: column; gap: 2px; flex: 0 0 170px; }
.subnav button {
  font: inherit; font-size: 14px; text-align: left; cursor: pointer;
  background: transparent; border: none; color: var(--ink-soft);
  padding: 10px 14px; border-radius: 8px;
}
.subnav button:hover { background: var(--line-soft); color: var(--ink); }
.subnav button.active {
  background: var(--mist); color: var(--ink); font-weight: 600;
  box-shadow: inset 3px 0 0 var(--accent);
}
.subnav-content { flex: 1; min-width: 0; }
.filter-input { width: 100%; max-width: 340px; margin-bottom: 16px; }
/* consistent mono numbers in the bills preview (scoped so it doesn't hit the readings inputs) */
#bills-preview td.num { font-family: "IBM Plex Mono", monospace; font-size: 13px; }
#bills-preview td.num .readout, #bills-preview td.num .amount { font-size: 13px; }

@media (max-width: 760px) {
  .nav-toggle { display: flex; margin-left: auto; }
  .topbar { gap: 12px; }
  .nav-menu {
    display: none;
    position: absolute; top: 100%; left: 0; right: 0;
    flex-direction: column; align-items: stretch;
    background: var(--ink);
    padding: 8px; gap: 3px;
    border-top: 1px solid rgba(255,255,255,.12);
    box-shadow: 0 14px 28px rgba(15,40,48,.32);
  }
  .topbar.nav-open .nav-menu { display: flex; }
  .tabs { flex-direction: column; width: 100%; margin-left: 0; gap: 3px; }
  .tabs button { text-align: left; width: 100%; padding: 12px 14px; font-size: 15px; }
  .account { width: 100%; margin: 4px 0 0; padding: 12px 14px 6px; justify-content: space-between; border-top: 1px solid rgba(255,255,255,.12); }
  .who { max-width: none; }
  .subnav-layout { flex-direction: column; gap: 16px; }
  .subnav { flex-direction: row; flex-basis: auto; gap: 4px; }
  .subnav button { flex: 1; text-align: center; }
  .subnav button.active { box-shadow: inset 0 -3px 0 var(--accent); }
  .grid-2, .grid-4 { grid-template-columns: 1fr; }
  main { padding: 22px 14px 70px; }
  .hide-sm { display: none; }
}

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
