:root {
  --bg: #f3efe6;
  --paper: #fffdf8;
  --ink: #1f1a14;
  --muted: #6e6458;
  --line: #e3d9c8;
  --brand: #1f4d3a;
  --copper: #9a4e24;
  --danger: #8d2f2f;
  --warn: #8a5a10;
  --shadow: 0 10px 30px rgba(60, 40, 10, 0.06);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  line-height: 1.5;
}

a { color: var(--brand); }

h1, h2 { line-height: 1.25; margin: 0 0 8px; }

.num { font-variant-numeric: tabular-nums; }

.muted { color: var(--muted); font-size: 14px; }

.topbar, .public-bar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 20px;
  padding-top: calc(14px + env(safe-area-inset-top));
  background: var(--brand);
  color: white;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
}

.public-bar { font-weight: 650; }

.brand, .topbar a, .linkish {
  color: white;
  text-decoration: none;
}

.topbar nav {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  flex: 1;
}

.topbar nav a {
  padding: 6px 10px;
  border-radius: 999px;
  white-space: nowrap;
}

.topbar nav a:hover,
.topbar nav a[aria-current="page"] {
  background: white;
  color: var(--brand);
}

.linkish, button.danger, button {
  font: inherit;
  cursor: pointer;
}

.linkish {
  background: transparent;
  border: 0;
  padding: 6px 0;
}

main { padding: 20px; max-width: 1180px; margin: 0 auto; }

.page-head, .tools, .actions, .filters {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
}

.page-head { margin-bottom: 16px; }

.page-head p { margin: 0; }

.tools a:not(.button) {
  padding: 8px 12px;
  background: white;
  border: 1px solid var(--line);
  border-radius: 999px;
  text-decoration: none;
}

.tools, .actions, .filters { justify-content: flex-start; }

.filters { margin-bottom: 16px; }

.filter-row {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}

.room-search { display: block; margin: 0 0 16px; }

.room-search input { width: 220px; max-width: 100%; }

.filters .room-search { margin: 0; }

[data-room][hidden],
[data-room-list][hidden],
[data-room-empty][hidden] { display: none !important; }

.panel, .flash {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px;
  box-shadow: var(--shadow);
}

.flash { margin-bottom: 16px; }

.flash.error { background: #fdecec; color: var(--danger); }

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin: 16px 0;
}

.stats article {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px;
}

.stats strong { display: block; font-size: 28px; }

.stats em { color: var(--muted); font-style: normal; }

.button, button.primary, .primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 999px;
  padding: 10px 16px;
  background: var(--brand);
  color: white;
  text-decoration: none;
  font: inherit;
  cursor: pointer;
}

button { border-radius: 999px; padding: 8px 14px; border: 1px solid var(--line); background: white; }

button.danger { border: 0; background: transparent; color: var(--danger); padding-inline: 8px; }

.field { display: flex; flex-direction: column; gap: 6px; margin: 12px 0; }

.file-pick {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 44px;
}

.file-pick input {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  border: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

.file-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  min-height: 40px;
  padding: 8px 16px;
  border: 1px solid var(--brand);
  border-radius: 999px;
  background: white;
  color: var(--brand);
  font-weight: 650;
  cursor: pointer;
}

.file-pick:hover .file-btn,
.file-pick:focus-within .file-btn {
  background: var(--brand);
  color: white;
}

.file-name {
  min-width: 0;
  color: var(--muted);
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

input, select {
  font: inherit;
  font-size: 16px;
  color: var(--ink);
  background: white;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  width: 100%;
}

.filters input[type="month"],
.filters select {
  width: fit-content;
  max-width: 100%;
  justify-self: start;
  field-sizing: content;
  min-height: 44px;
  padding-right: 2.2rem;
}

.filters input[type="month"] {
  position: relative;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236e6458' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='5' width='18' height='16' rx='2'/%3E%3Cpath d='M3 10h18M8 3v4M16 3v4'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 1.05rem;
}

.filters input[type="month"]::-webkit-calendar-picker-indicator {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  cursor: pointer;
  opacity: 0;
}

.filters select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236e6458' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 1rem;
}

.form-narrow, .narrow {
  width: min(560px, 100%);
  margin-inline: auto;
}

.center-page {
  min-height: calc(100vh - 90px);
  display: grid;
  place-items: center;
}

.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.sheet { overflow-x: auto; background: var(--paper); border: 1px solid var(--line); border-radius: 16px; }

table.data { border-collapse: collapse; width: 100%; }

table.data th, table.data td {
  border-bottom: 1px solid var(--line);
  padding: 12px 10px;
  text-align: left;
  vertical-align: middle;
  background: var(--paper);
}

table.data tr:last-child td { border-bottom: 0; }

table.data th { color: var(--muted); font-size: 13px; font-weight: 600; }

td.sticky, th.sticky { position: sticky; left: 0; z-index: 1; }

table input { width: 96px; }

@media (min-width: 761px) {
  main.page-wide {
    max-width: 1440px;
    padding: 24px 28px 40px;
  }

  .page-wide .sheet { margin-bottom: 20px; }

  .page-wide table.data th:first-child,
  .page-wide table.data td:first-child { padding-left: 18px; }

  .page-wide table.data th:last-child,
  .page-wide table.data td:last-child { padding-right: 18px; }

  table.rooms th,
  table.rooms td.num,
  table.rooms td.actions { white-space: nowrap; }

  table.rooms td.actions {
    display: flex;
    gap: 14px;
    align-items: center;
  }

  table.rooms td.actions form { margin: 0; }

  table.meters {
    table-layout: fixed;
    font-size: 14px;
  }

  table.meters th { white-space: nowrap; }

  table.meters th:nth-child(1) { width: 6.5%; }
  table.meters th:nth-child(2) { width: 6.5%; }
  table.meters th:nth-child(3) { width: 5.5%; }
  table.meters th:nth-child(4) { width: 5.5%; }
  table.meters th:nth-child(5) { width: 9.5%; }
  table.meters th:nth-child(6) { width: 9.5%; }
  table.meters th:nth-child(7) { width: 5.5%; }
  table.meters th:nth-child(8) { width: 9.5%; }
  table.meters th:nth-child(9) { width: 9.5%; }
  table.meters th:nth-child(10) { width: 7%; }
  table.meters th:nth-child(11) { width: 8.5%; }
  table.meters th:nth-child(12) { width: 10%; }
  table.meters th:nth-child(13) { width: 7%; }

  table.meters input:not([type="hidden"]) {
    width: 100%;
    min-width: 0;
    padding: 6px 4px;
  }

  table.meters td.usage {
    font-size: 13px;
    line-height: 1.35;
  }
}

tr.locked td { color: var(--muted); }

.name-inline { display: none; }

.hint { color: var(--muted); font-size: 14px; }

.bill-list { display: grid; gap: 12px; }

.bill-card header, .open-list a {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.total-line { margin-left: auto; font-size: 20px; }

.pill {
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 13px;
  background: #f3efe6;
}

.pill.unpaid { color: var(--danger); background: #fdecec; }
.pill.pending { color: var(--warn); background: #fff3d8; }
.pill.paid { color: var(--brand); background: #e7f2ec; }

.open-list { list-style: none; padding: 0; margin: 0; }
.open-list a { text-decoration: none; color: inherit; padding: 8px 0; border-bottom: 1px solid var(--line); }
.open-list strong { margin-left: auto; }

.room-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.room-tile[hidden] { display: none !important; }

.room-tile {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 72px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 14px;
  color: var(--ink);
  text-decoration: none;
  font-size: 22px;
  font-weight: 650;
}

.search { margin-top: 8px; }

.tenant { max-width: 640px; margin: 0 auto; }

.total-block, .pending-block {
  border-radius: 18px;
  padding: 18px;
  margin: 12px 0;
}

.total-block { background: var(--brand); color: white; }
.total-block strong { display: block; font-size: 42px; letter-spacing: -0.03em; }
.pending-block { background: #fff3d8; color: var(--warn); }

.pay-qr { width: min(220px, 70vw); height: auto; display: block; margin: 12px 0; background: white; }

button.pay-qr-open {
  display: block;
  width: min(220px, 70vw);
  margin: 12px 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: white;
  cursor: zoom-in;
}

button.pay-qr-open .pay-qr { width: 100%; margin: 0; }

.pay-zoom {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 56px 20px 24px;
  background: rgba(31, 26, 20, 0.86);
}

.pay-zoom[hidden] { display: none !important; }

.pay-zoom img {
  width: min(92vw, 520px);
  max-height: calc(100vh - 96px);
  height: auto;
  object-fit: contain;
  background: white;
  border-radius: 12px;
}

button.pay-zoom-close {
  position: absolute;
  top: calc(12px + env(safe-area-inset-top));
  right: 16px;
  padding: 8px 4px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: white;
  font: inherit;
  font-size: 16px;
}

.qr-sheet { max-width: 420px; text-align: center; margin: 0 auto 16px; }
.center-action { text-align: center; margin: 16px 0 0; }

.wide-action .primary { min-width: 220px; padding-inline: 40px; }
.qr-sheet img { width: min(320px, 80vw); height: auto; }
.eyebrow { letter-spacing: 0.08em; color: var(--copper); font-size: 13px; }
.url { overflow-wrap: anywhere; color: var(--muted); }

.line-total { font-size: 18px; }

ul { padding-left: 18px; }

.check { display: flex; gap: 8px; align-items: center; }
.check input { width: auto; }

@media (max-width: 760px) {
  .row2 { grid-template-columns: 1fr; }

  main {
    padding: 14px 14px 28px;
  }

  .brand { flex: 1; min-width: 0; }

  .topbar {
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px 12px;
    padding-top: calc(10px + env(safe-area-inset-top));
  }

  .topbar form { order: 1; }

  .topbar nav {
    order: 2;
    flex: 1 0 100%;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
  }

  .topbar nav a {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    background: rgba(255, 255, 255, 0.14);
  }

  .topbar nav a[aria-current="page"] {
    background: white;
    color: var(--brand);
  }

  .linkish { min-height: 40px; min-width: 44px; }

  .page-head { flex-direction: column; align-items: stretch; gap: 8px; margin-bottom: 12px; }

  .tools { width: 100%; }

  .page-head > .button,
  .tools .button,
  .filters button,
  .form-narrow > .primary,
  .form-narrow > .center-action .primary,
  .submit-bar {
    width: 100%;
    min-height: 48px;
  }

  .filters { display: grid; grid-template-columns: 1fr; gap: 10px; }

  .filter-row { flex-wrap: nowrap; min-width: 0; }

  .room-search {
    position: sticky;
    top: var(--topbar-height, 108px);
    z-index: 15;
    width: auto;
    margin: 0 0 8px;
    padding: 8px 0;
    background: transparent;
  }

  .room-search::before {
    content: "";
    position: absolute;
    z-index: -1;
    left: -14px;
    right: -14px;
    top: 0;
    bottom: 0;
    background: var(--bg);
  }

  .room-search input {
    width: 100%;
    max-width: none;
  }

  .filters .room-search { margin-bottom: 0; }

  .filters input[type="month"] {
    color: var(--ink);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236e6458' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='5' width='18' height='16' rx='2'/%3E%3Cpath d='M3 10h18M8 3v4M16 3v4'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 1.05rem;
  }

  .filters input[type="month"]::-webkit-calendar-picker-indicator {
    position: static !important;
    inset: auto !important;
    width: 1px !important;
    height: 1px !important;
    margin: 0;
    padding: 0;
    opacity: 0;
    pointer-events: none;
  }

  table.rooms tr.is-foldable,
  table.meters tr.is-foldable,
  .bill-card.is-foldable > .fold-summary { cursor: pointer; }

  table.rooms tr.is-folded,
  table.meters tr.is-folded {
    position: relative;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
    padding: 12px 28px 12px 14px;
  }

  table.meters tr.is-folded { grid-template-columns: minmax(0, 1fr) auto; }

  table.rooms tr.is-folded > :not(.fold-summary),
  table.meters tr.is-folded > :not(.fold-summary),
  .bill-card.is-folded > :not(.fold-summary) { display: none !important; }

  table.rooms tr.is-folded td,
  table.meters tr.is-folded td {
    grid-column: auto;
    padding: 0;
  }

  tr.is-folded td.sticky { font-size: 18px; }

  tr.is-folded td[data-label]::before { content: none; }

  tr.is-folded .muted { display: none; }

  tr.is-folded .fold-side,
  .bill-card.is-folded .total-line {
    font-size: 16px;
    white-space: nowrap;
  }

  table.rooms tr.is-folded td.fold-summary:nth-child(2) {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  tr.is-foldable::after,
  .bill-card.is-foldable > .fold-summary::after {
    content: "";
    width: 8px;
    height: 8px;
    border-right: 2px solid var(--muted);
    border-bottom: 2px solid var(--muted);
    transform: rotate(45deg);
  }

  tr.is-foldable::after {
    position: absolute;
    right: 12px;
    top: 50%;
    margin-top: -6px;
  }

  tr.is-foldable:not(.is-folded)::after,
  .bill-card.is-foldable:not(.is-folded) > .fold-summary::after {
    top: 22px;
    margin-top: 0;
    transform: rotate(225deg);
  }

  .bill-card.is-foldable > .fold-summary {
    position: relative;
    padding-right: 16px;
  }

  .bill-card.is-foldable > .fold-summary::after {
    position: absolute;
    right: 0;
    top: 50%;
  }

  .bill-card.is-folded { padding: 12px 14px; }

  .meter-form { padding-bottom: 76px; }

  .submit-bar {
    position: fixed;
    left: 14px;
    right: 14px;
    bottom: calc(12px + env(safe-area-inset-bottom));
    width: auto;
    z-index: 16;
    box-shadow: 0 8px 24px rgba(60, 40, 10, 0.18);
  }

  .stats { grid-template-columns: 1fr; }

  .sheet {
    overflow: visible;
    border: 0;
    background: transparent;
    box-shadow: none;
  }

  table.rooms,
  table.meters { min-width: 0; }

  table.rooms thead,
  table.meters thead,
  .desk-only { display: none; }

  table.rooms,
  table.meters,
  table.rooms tbody,
  table.meters tbody { display: block; }

  table.rooms tr,
  table.meters tr {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px 12px;
    margin-bottom: 12px;
    padding: 14px;
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: 16px;
  }

  table.rooms td,
  table.meters td {
    display: block;
    width: auto;
    border: 0;
    padding: 4px 0;
    background: transparent;
  }

  table.rooms td.desk-only,
  table.meters td.desk-only { display: none; }

  table.rooms td.actions {
    display: flex;
    grid-column: 1 / -1;
    gap: 8px;
    align-items: center;
  }

  td.sticky,
  th.sticky { position: static; }

  td.span-2 { grid-column: 1 / -1; }

  td.sticky { font-size: 20px; font-weight: 700; }

  .name-inline {
    display: inline;
    margin-left: 8px;
    color: var(--muted);
    font-size: 14px;
    font-weight: 400;
  }

  td[data-label]:not([data-label=""])::before {
    content: attr(data-label);
    display: block;
    color: var(--muted);
    font-size: 12px;
    font-weight: 400;
  }

  table input { width: 100%; min-height: 44px; }

  td.preview { font-size: 22px; }

  .actions { width: 100%; }

  td.actions > a,
  .actions form { flex: 1; }

  .actions button,
  .actions a {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    width: 100%;
  }

  .open-list a { min-height: 48px; }

  .bill-card header { align-items: flex-start; }

  .total-line { width: 100%; margin-left: 0; }

}

.month-sheet {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: flex-end;
  background: rgba(31, 26, 20, 0.35);
}

.month-sheet[hidden] { display: none; }

.month-sheet-panel {
  width: 100%;
  background: var(--paper);
  border-radius: 16px 16px 0 0;
  padding-bottom: env(safe-area-inset-bottom);
}

.month-sheet-bar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}

.month-sheet-bar strong { text-align: center; }

.month-sheet-bar button {
  border: 0;
  background: none;
  color: var(--brand);
  font: inherit;
  font-size: 16px;
  padding: 6px 0;
}

.month-sheet-bar [data-cancel] { justify-self: start; }

.month-sheet-bar [data-ok] { justify-self: end; font-weight: 700; }

.month-wheels {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  height: 220px;
}

.month-wheels::before,
.month-wheels::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  height: 78px;
  z-index: 1;
  pointer-events: none;
}

.month-wheels::before {
  top: 0;
  background: linear-gradient(var(--paper), transparent);
}

.month-wheels::after {
  bottom: 0;
  background: linear-gradient(transparent, var(--paper));
}

.month-highlight {
  position: absolute;
  left: 16px;
  right: 16px;
  top: 50%;
  height: 44px;
  transform: translateY(-50%);
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  pointer-events: none;
}

.month-wheel {
  height: 220px;
  overflow-y: auto;
  scroll-snap-type: y mandatory;
  scrollbar-width: none;
}

.month-wheel::-webkit-scrollbar { display: none; }

.month-pad { height: 88px; }

.month-item {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 44px;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: none;
  color: var(--ink);
  font: inherit;
  font-size: 18px;
  line-height: 1;
  text-align: center;
  scroll-snap-align: center;
}

@media print {
  .topbar, .no-print, .flash { display: none !important; }
  body, .qr-sheet { background: white; box-shadow: none; }
}
