:root {
  --paper: #f4f0e7;
  --paper-raised: #fbf8f1;
  --paper-deep: #e8e1d4;
  --ink: #0f172a;
  --slate: #1e293b;
  --muted: #526070;
  --line: #b8b1a5;
  --line-strong: #7b746a;
  --brick: #9d3a2f;
  --brick-dark: #792c24;
  --brick-pale: #f0d8d3;
  --safe: #315f4d;
  --safe-pale: #dce8df;
  --radius-1: 4px;
  --radius-2: 6px;
  --radius-3: 8px;
  --radius-4: 12px;
  --shadow: 0 12px 32px rgba(30, 41, 59, 0.10);
  --focus: 0 0 0 2px rgba(157, 58, 47, 0.22);
  font-family: "Noto Sans SC", "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
  color: var(--ink);
  background: var(--paper);
  font-synthesis: none;
}

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

html { min-height: 100%; background: var(--paper); }

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(90deg, transparent 0, transparent calc(100% - 1px), rgba(30, 41, 59, 0.035) calc(100% - 1px)) 0 0 / 88px 100%,
    var(--paper);
  line-height: 1.55;
}

button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: inherit; }

:focus-visible {
  outline: 2px solid var(--brick);
  outline-offset: 2px;
  box-shadow: var(--focus);
}

.site-shell { width: min(1440px, 100%); min-height: 100vh; margin: 0 auto; background: rgba(244, 240, 231, 0.95); }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 10px clamp(18px, 4vw, 56px);
  color: #fff;
  background: var(--slate);
  box-shadow: 0 6px 20px rgba(15, 23, 42, 0.18);
}

.brand { display: inline-flex; align-items: center; gap: 12px; color: #fff; text-decoration: none; }
.brand-mark { display: grid; place-items: center; width: 40px; height: 40px; border: 1px solid rgba(255,255,255,.5); border-radius: var(--radius-2); font-weight: 800; }
.brand strong, .brand small { display: block; }
.brand strong { font-size: 1rem; letter-spacing: .02em; }
.brand small { margin-top: 1px; color: #d8dee8; font-size: .72rem; letter-spacing: .12em; }

.primary-nav { display: flex; align-items: center; gap: 4px; }
.primary-nav a, .nav-button {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  padding: 8px 13px;
  color: #e9edf4;
  background: transparent;
  border: 0;
  border-radius: var(--radius-2);
  text-decoration: none;
  cursor: pointer;
}
.primary-nav a:hover, .nav-button:hover { background: rgba(255,255,255,.09); color: #fff; }
.primary-nav a.active { color: #fff; background: var(--brick); }

.main-content { width: min(1220px, calc(100% - 36px)); margin: 0 auto; padding: clamp(30px, 5vw, 64px) 0 72px; }
.site-footer { display: flex; justify-content: space-between; gap: 16px; padding: 20px clamp(18px, 4vw, 56px); border-top: 1px solid var(--line); color: var(--muted); font-size: .82rem; }

h1, h2, p { margin-top: 0; }
h1 { max-width: 18ch; margin-bottom: 10px; font-size: clamp(2rem, 5vw, 3.7rem); line-height: 1.08; letter-spacing: -.035em; text-wrap: balance; }
h2 { margin-bottom: 4px; font-size: clamp(1.2rem, 2vw, 1.55rem); line-height: 1.25; letter-spacing: -.015em; }
p { color: var(--muted); }

.page-titlebar { display: flex; align-items: flex-end; justify-content: space-between; gap: 28px; margin-bottom: 28px; padding-bottom: 24px; border-bottom: 2px solid var(--slate); }
.page-titlebar p { max-width: 68ch; margin-bottom: 0; }
.page-titlebar .button { flex: 0 0 auto; }
.form-titlebar { align-items: center; }
.back-link { display: inline-block; margin-bottom: 12px; color: var(--brick-dark); font-weight: 700; text-decoration: none; }
.record-stamp { padding: 9px 12px; border: 1px solid var(--line-strong); border-radius: var(--radius-1); color: var(--slate); font-weight: 800; transform: rotate(-1deg); }

.button {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 16px;
  border: 1px solid transparent;
  border-radius: var(--radius-2);
  font-weight: 750;
  text-decoration: none;
  cursor: pointer;
  transition: background-color .16s ease-out, color .16s ease-out, transform .16s ease-out, box-shadow .16s ease-out;
}
.button:hover { transform: translateY(-1px); }
.button-primary { color: #fff; background: var(--brick); border-color: var(--brick); box-shadow: 0 7px 18px rgba(121,44,36,.18); }
.button-primary:hover { background: var(--brick-dark); }
.button-secondary { color: var(--slate); background: var(--paper-raised); border-color: var(--line-strong); }
.button-secondary:hover { color: var(--brick-dark); border-color: var(--brick); }
.button-quiet { color: var(--slate); background: transparent; border-color: var(--line); }
.button-quiet:hover { background: var(--paper-deep); }
.button-danger { color: var(--brick-dark); background: transparent; border-color: var(--brick); }
.button-danger:hover { color: #fff; background: var(--brick-dark); }
.button-wide { width: 100%; }
.text-button { padding: 5px 8px; color: var(--brick-dark); background: none; border: 0; font-weight: 700; cursor: pointer; }

.flash { width: min(1220px, calc(100% - 36px)); margin: 18px auto -10px; padding: 12px 15px; border-radius: var(--radius-2); font-weight: 650; }
.flash-success { color: #214637; background: var(--safe-pale); border: 1px solid #8cac9d; }
.flash-error { color: var(--brick-dark); background: var(--brick-pale); border: 1px solid #c78f86; }

.status-ledger {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  margin-bottom: 28px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-3);
  overflow: hidden;
  background: rgba(251, 248, 241, .75);
}
.status-ledger > div { min-height: 94px; display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 18px 22px; border-right: 1px solid var(--line); }
.status-ledger > div:last-child { border-right: 0; }
.status-ledger span { color: var(--muted); font-weight: 650; }
.status-ledger strong { font-size: clamp(1.8rem, 4vw, 2.7rem); line-height: 1; color: var(--slate); }
.status-ledger .status-risk strong { color: var(--brick); }

.filter-workbench, .records-section { margin-top: 26px; }
.filter-workbench { padding: 24px; background: var(--paper-deep); border-radius: var(--radius-3); }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 24px; margin-bottom: 20px; }
.section-heading p { margin-bottom: 0; font-size: .92rem; }
.compact-heading { margin-bottom: 14px; }
.export-actions { display: flex; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: 10px; }
.export-hint { max-width: 180px; color: var(--muted); font-size: .8rem; line-height: 1.3; text-align: right; }

.filter-grid { display: grid; grid-template-columns: 1.15fr 1.5fr repeat(3, 1fr) auto; gap: 12px; align-items: end; }
.grouped-filter { grid-template-columns: repeat(2, minmax(145px, .9fr)) repeat(3, minmax(130px, 1fr)) auto; }
.filter-buttons { display: flex; gap: 8px; }
.range-indicator { display: grid; gap: 1px; color: var(--muted); font-size: .82rem; line-height: 1.35; text-align: right; }
.range-indicator b { color: var(--slate); font-size: .72rem; letter-spacing: .08em; text-transform: uppercase; }
.field { display: grid; gap: 7px; color: var(--slate); font-weight: 700; }
.field > span { font-size: .9rem; }
.field > span b { color: var(--brick); }
.field small { color: var(--muted); font-weight: 500; }
.field input, .field select, .field textarea {
  width: 100%;
  min-height: 46px;
  padding: 10px 12px;
  color: var(--ink);
  background: var(--paper-raised);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-2);
  font-weight: 500;
}
.field textarea { min-height: 84px; resize: vertical; line-height: 1.55; }
.field input:disabled { color: var(--muted); background: #e5dfd3; }
.field input[aria-invalid="true"], .field select[aria-invalid="true"] { border-color: var(--brick); }
.field-error { color: var(--brick-dark) !important; font-size: .86rem; font-weight: 700 !important; }
.global-error { padding: 10px 12px; background: var(--brick-pale); border-radius: var(--radius-2); }

.table-scroll { overflow-x: auto; border-top: 2px solid var(--slate); border-bottom: 1px solid var(--line-strong); }
.records-table { width: 100%; border-collapse: collapse; background: rgba(251,248,241,.48); }
.records-table th { padding: 12px 14px; color: #fff; background: var(--slate); font-size: .82rem; text-align: left; letter-spacing: .03em; }
.records-table td { padding: 17px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.records-table tbody tr:last-child td { border-bottom: 0; }
.records-table tbody tr:hover { background: var(--paper-raised); }
.records-table td strong, .records-table td small { display: block; }
.records-table td small { color: var(--muted); margin-top: 2px; }
.row-action { text-align: right; white-space: nowrap; }
.row-action a { color: var(--brick-dark); font-weight: 800; text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 3px; }

.badge { display: inline-flex; align-items: center; min-height: 28px; padding: 3px 9px; border-radius: 999px; font-size: .8rem; font-weight: 800; white-space: nowrap; }
.badge-neutral { color: #344253; background: #e0ddd5; }
.badge-risk { color: var(--brick-dark); background: var(--brick-pale); }
.badge-safe { color: #214637; background: var(--safe-pale); }

.empty-state { padding: clamp(30px, 7vw, 70px) 20px; border-top: 2px solid var(--slate); border-bottom: 1px solid var(--line); text-align: center; }
.empty-state strong { display: block; font-size: 1.3rem; }
.empty-state p { margin: 8px auto 20px; }

.room-groups { display: grid; gap: 28px; }
.room-ledger { border-top: 3px solid var(--slate); background: rgba(251, 248, 241, .42); }
.room-ledger-header { display: grid; grid-template-columns: minmax(170px, .7fr) minmax(310px, 1fr) minmax(210px, .8fr); align-items: center; gap: 22px; padding: 16px 18px; border: 1px solid var(--line); border-top: 0; }
.room-name-block { display: flex; align-items: baseline; gap: 10px; }
.room-name-block h3 { margin: 0; color: var(--slate); font-size: 1.25rem; line-height: 1.2; }
.room-name-block span { color: var(--muted); font-size: .82rem; white-space: nowrap; }
.room-totals { display: grid; grid-template-columns: repeat(3, 1fr); margin: 0; }
.room-totals div { display: flex; align-items: baseline; justify-content: center; gap: 7px; padding: 2px 12px; border-left: 1px solid var(--line); }
.room-totals dt { color: var(--muted); font-size: .78rem; font-weight: 700; }
.room-totals dd { margin: 0; color: var(--slate); font-size: 1.15rem; font-weight: 850; }
.room-totals .has-risk dd { color: var(--brick); }
.room-export { display: flex; justify-content: flex-end; }
.room-export small { max-width: 190px; color: var(--muted); font-size: .78rem; line-height: 1.35; text-align: right; }
.room-export .button { min-height: 38px; padding: 7px 11px; font-size: .82rem; }
.room-table-scroll { border-top: 0; }
.grouped-records-table th { border-top: 0; }

.inspection-form { display: grid; gap: 18px; }
.form-section { display: grid; grid-template-columns: 54px 1fr; border-top: 1px solid var(--line-strong); background: rgba(251,248,241,.42); }
.section-index { display: flex; align-items: flex-start; justify-content: center; padding-top: 24px; color: #fff; background: var(--slate); font-size: 1.1rem; font-weight: 900; }
.section-index-risk { background: var(--brick); }
.form-section-body { min-width: 0; padding: 24px clamp(18px, 4vw, 34px) 30px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
.hazards-heading { align-items: flex-start; }
.toggle-field { display: flex; align-items: center; gap: 10px; min-height: 46px; padding: 10px 14px; background: var(--safe-pale); border: 1px solid #789d8b; border-radius: var(--radius-2); color: #214637; font-weight: 800; cursor: pointer; }
.toggle-field input { width: 19px; height: 19px; accent-color: var(--safe); }
.hazard-list { display: grid; gap: 16px; margin-bottom: 14px; }
.hazard-entry { padding: 18px; border: 1px solid var(--line-strong); border-radius: var(--radius-3); background: var(--paper-raised); }
.hazard-entry-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; padding-bottom: 10px; border-bottom: 1px solid var(--line); }
.hazard-entry-head strong { color: var(--brick-dark); }
.hazard-resolution { display: grid; grid-template-columns: minmax(150px, .5fr) 1.5fr; gap: 14px; margin-top: 14px; }
.form-actions { position: sticky; bottom: 0; z-index: 10; display: flex; justify-content: flex-end; gap: 10px; padding: 16px 0; background: linear-gradient(to top, var(--paper) 70%, rgba(244,240,231,0)); }
.danger-zone { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-top: 46px; padding: 22px 0; border-top: 1px solid var(--brick); }
.danger-zone h2 { color: var(--brick-dark); font-size: 1.05rem; }
.danger-zone p { margin: 0; font-size: .9rem; }

.login-stage { min-height: calc(100vh - 210px); display: grid; grid-template-columns: 1.25fr minmax(320px, .75fr); align-items: center; gap: clamp(40px, 8vw, 100px); padding: 40px 0; }
.login-copy h1 { max-width: 13ch; }
.login-copy > p { max-width: 56ch; font-size: 1.08rem; }
.login-facts { display: grid; grid-template-columns: repeat(3, 1fr); max-width: 580px; margin: 36px 0 0; border-top: 2px solid var(--slate); border-bottom: 1px solid var(--line-strong); }
.login-facts div { padding: 18px 12px 18px 0; }
.login-facts dt { color: var(--brick); font-size: 2.2rem; font-weight: 850; line-height: 1; }
.login-facts dd { margin: 7px 0 0; color: var(--muted); font-size: .85rem; }
.login-form { padding: 30px; background: var(--paper-raised); border-top: 5px solid var(--brick); box-shadow: var(--shadow); }
.form-heading { margin-bottom: 24px; }
.form-heading p, .form-note { margin-bottom: 0; font-size: .88rem; }
.login-form .field { margin-bottom: 16px; }
.login-form .button { margin-top: 6px; }
.form-note { margin-top: 15px; text-align: center; }

.error-page { min-height: 55vh; display: grid; place-items: center; align-content: center; text-align: center; }
.error-page h1 { max-width: none; margin: 16px 0 8px; }
.error-page p { max-width: 55ch; }
.error-symbol { display: grid; place-items: center; width: 62px; height: 62px; border: 2px solid var(--brick); border-radius: 50%; color: var(--brick); font-size: 2rem; font-weight: 900; }
.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; }

@media (max-width: 1000px) {
  .filter-grid { grid-template-columns: repeat(3, 1fr); }
  .grouped-filter { grid-template-columns: repeat(3, 1fr); }
  .filter-buttons { align-self: end; }
  .room-ledger-header { grid-template-columns: minmax(150px, .65fr) 1fr; }
  .room-export { grid-column: 1 / -1; justify-content: flex-start; }
  .room-export small { max-width: none; text-align: left; }
  .login-stage { grid-template-columns: 1fr 380px; gap: 40px; }
}

@media (max-width: 760px) {
  body { background: var(--paper); }
  .topbar { position: relative; min-height: auto; align-items: flex-start; padding: 14px 18px; }
  .brand small { display: none; }
  .primary-nav { align-items: stretch; }
  .primary-nav a, .nav-button { min-height: 40px; padding: 7px 9px; font-size: .86rem; }
  .main-content { width: min(100% - 28px, 1220px); padding: 30px 0 54px; }
  .page-titlebar, .section-heading, .danger-zone { align-items: stretch; flex-direction: column; }
  .page-titlebar .button { width: 100%; }
  .status-ledger { grid-template-columns: repeat(2, 1fr); }
  .status-ledger > div { min-height: 76px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
  .status-ledger > div:nth-child(2) { border-right: 0; }
  .status-ledger > div:nth-child(n+3) { border-bottom: 0; }
  .filter-workbench { padding: 18px 14px; }
  .export-actions { align-items: stretch; justify-content: flex-start; }
  .export-actions .button { flex: 1 1 150px; }
  .export-hint { flex-basis: 100%; max-width: none; text-align: left; }
  .range-indicator { flex-basis: 100%; text-align: left; }
  .filter-grid, .form-grid, .hazard-resolution { grid-template-columns: 1fr; }
  .filter-buttons .button { flex: 1; }

  .room-groups { gap: 34px; }
  .room-ledger-header { grid-template-columns: 1fr; gap: 14px; padding: 15px 12px; }
  .room-totals { border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
  .room-totals div { min-height: 50px; border-left: 0; border-right: 1px solid var(--line); }
  .room-totals div:last-child { border-right: 0; }
  .room-export { grid-column: auto; }
  .room-export .button { width: 100%; }

  .table-scroll { overflow: visible; border-bottom: 0; }
  .records-table, .records-table tbody, .records-table tr, .records-table td { display: block; width: 100%; }
  .records-table thead { display: none; }
  .records-table tr { display: grid; grid-template-columns: 1fr 1fr; padding: 16px 0; border-bottom: 1px solid var(--line-strong); }
  .records-table td { display: grid; grid-template-columns: 90px 1fr; align-items: start; padding: 6px 8px; border: 0; }
  .records-table td::before { content: attr(data-label); color: var(--muted); font-size: .78rem; font-weight: 750; }
  .records-table .row-action { grid-column: 1 / -1; display: block; padding-top: 11px; text-align: left; }

  .form-section { grid-template-columns: 36px 1fr; }
  .section-index { padding-top: 22px; }
  .form-section-body { padding: 20px 14px 24px; }
  .hazards-heading { gap: 14px; }
  .toggle-field { width: 100%; }
  .hazard-entry { padding: 14px; }
  .form-actions .button { flex: 1; }
  .form-actions { position: static; background: transparent; }

  .login-stage { min-height: auto; grid-template-columns: 1fr; gap: 34px; padding: 12px 0 32px; }
  .login-copy h1 { font-size: 2.35rem; }
  .login-copy > p { font-size: 1rem; }
  .login-facts { margin-top: 24px; }
  .login-form { padding: 24px 20px; }
  .site-footer { flex-direction: column; gap: 4px; }
}

@media (max-width: 480px) {
  .brand-mark { width: 36px; height: 36px; }
  .brand > span:last-child { display: none; }
  .primary-nav a:first-child { display: none; }
  .status-ledger span { font-size: .82rem; }
  .status-ledger strong { font-size: 1.8rem; }
  .records-table tr { grid-template-columns: 1fr; }
  .records-table .row-action { grid-column: 1; }
  .login-facts dd { font-size: .74rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; }
}
