:root {
  --ink: #14263a;
  --muted: #6e7c8c;
  --paper: #f4f1ea;
  --paper-deep: #e9e5dc;
  --white: #fffdf8;
  --line: #d9d9d2;
  --blue: #173753;
  --blue-soft: #dbe7ea;
  --red: #bb3f37;
  --red-soft: #f7deda;
  --green: #2d6952;
  --green-soft: #dcece2;
  --gold: #bb8d3f;
  --shadow: 0 18px 45px rgba(20, 38, 58, .11);
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { background: var(--paper); scroll-behavior: smooth; }
body { margin: 0; background: var(--paper); color: var(--ink); min-width: 320px; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
a { color: inherit; }

.app-shell { min-height: 100vh; }
.loading-shell, .boot-error { min-height: 100vh; display: grid; place-items: center; text-align: center; padding: 24px; color: var(--muted); }
.loading-shell { gap: 14px; align-content: center; }
.loading-mark { display: block; width: 22px; height: 22px; border: 2px solid var(--blue-soft); border-top-color: var(--red); border-radius: 50%; animation: spin 1s linear infinite; }
.boot-error { align-content: center; background: var(--blue); color: var(--white); }
.boot-error h1 { max-width: 560px; font-family: Georgia, serif; font-weight: 500; font-size: clamp(2rem, 4vw, 4rem); line-height: 1.02; margin: 16px auto; }
.boot-error p { color: #c7d2d8; }
@keyframes spin { to { transform: rotate(360deg); } }
.auth-gate { min-height: 100vh; display: grid; place-items: center; align-content: center; gap: 18px; padding: 28px; background: var(--blue); color: var(--white); }
.auth-gate-inner { width: min(430px, 100%); background: var(--white); color: var(--ink); padding: 34px; box-shadow: var(--shadow); }
.auth-gate-inner .brand-mark { margin-bottom: 26px; border-color: var(--red); }
.auth-gate-inner h1 { margin: 12px 0 10px; font-family: Georgia, serif; font-size: 43px; line-height: .98; font-weight: 500; }
.auth-gate-inner p { color: var(--muted); font-size: 13px; line-height: 1.55; margin: 0 0 22px; }
.auth-gate-inner .modal { width: auto; padding: 0; box-shadow: none; }
.auth-gate-inner .modal h2, .auth-gate-inner .modal p { display: none; }
.auth-gate-inner .modal-close { display: none; }
.auth-gate-note { color: #b7c7ce; font-size: 12px; text-align: center; }

.topbar { height: 74px; display: flex; align-items: center; justify-content: space-between; padding: 0 clamp(18px, 4vw, 64px); background: var(--blue); color: var(--white); position: sticky; top: 0; z-index: 20; box-shadow: 0 1px 0 rgba(255,255,255,.08); }
.brand { display: inline-flex; align-items: center; gap: 12px; text-decoration: none; }
.brand-mark { width: 27px; height: 27px; border: 1px solid #f2c9bd; display: grid; place-items: center; transform: rotate(45deg); }
.brand-mark::after { content: ""; width: 8px; height: 8px; border-radius: 50%; background: #f2c9bd; }
.brand-copy { display: grid; gap: 2px; }
.brand-name { font-size: 12px; letter-spacing: .13em; text-transform: uppercase; font-weight: 700; }
.brand-sub { color: #b7c7ce; font-size: 11px; }
.topbar-actions { display: flex; align-items: center; gap: 16px; }
.header-admin-actions { display: flex; align-items: center; gap: 7px; }
.topbar .button.ghost { color: var(--white); border-color: rgba(255,255,255,.55); }
.topbar .button.ghost:hover { color: var(--white); background: rgba(255,255,255,.14); border-color: rgba(255,255,255,.9); }
.sync-note { color: #b7c7ce; font-size: 12px; display: none; }
.user-menu { display: flex; align-items: center; gap: 9px; color: #d9e6e8; font-size: 12px; }
.user-dot { width: 7px; height: 7px; background: #e3ae67; border-radius: 50%; }

.page { width: min(1520px, calc(100% - 40px)); margin: 0 auto; padding: 62px 0 100px; }
.intro { display: grid; grid-template-columns: minmax(0, 1.45fr) minmax(270px, .7fr); gap: clamp(28px, 7vw, 110px); align-items: end; padding-bottom: 42px; animation: rise .55s ease both; }
.eyebrow { font-size: 11px; letter-spacing: .16em; text-transform: uppercase; color: var(--red); font-weight: 800; }
.intro h1 { max-width: 850px; margin: 13px 0 18px; font-family: Georgia, "Times New Roman", serif; font-size: clamp(3.4rem, 7vw, 7rem); line-height: .92; font-weight: 500; letter-spacing: -.055em; }
.intro p { max-width: 660px; color: #536778; font-size: 16px; line-height: 1.65; margin: 0; }
.intro-note { border-top: 1px solid var(--line); padding-top: 18px; color: var(--muted); font-size: 13px; line-height: 1.55; }
.intro-note strong { display: block; color: var(--ink); font-size: 22px; font-family: Georgia, serif; font-weight: 500; margin-bottom: 6px; }
@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: translateY(0); } }

.metrics { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); border-top: 1px solid var(--ink); border-bottom: 1px solid var(--line); margin-bottom: 42px; animation: rise .6s .05s ease both; }
.metric { min-height: 116px; padding: 20px 20px 17px 0; border-right: 1px solid var(--line); margin-right: 20px; }
.metric:last-child { border-right: 0; margin-right: 0; }
.metric-label { display: block; color: var(--muted); font-size: 11px; letter-spacing: .08em; text-transform: uppercase; margin-bottom: 13px; }
.metric-value { display: block; font-family: Georgia, serif; font-size: clamp(2.2rem, 4vw, 3.4rem); line-height: .9; font-weight: 500; }
.metric-value.red { color: var(--red); }
.metric-value.green { color: var(--green); }
.metric-note { color: var(--muted); font-size: 11px; margin-top: 10px; }

.navline { display: flex; align-items: center; justify-content: space-between; gap: 18px; border-bottom: 1px solid var(--line); padding-bottom: 11px; margin-bottom: 18px; }
.nav-tabs { display: flex; gap: 21px; flex-wrap: wrap; }
.nav-tab { border: 0; background: transparent; color: var(--muted); padding: 0 0 8px; border-bottom: 2px solid transparent; font-size: 13px; }
.nav-tab:hover, .nav-tab.active { color: var(--ink); border-bottom-color: var(--red); }
.admin-actions { display: flex; gap: 9px; align-items: center; }
.global-search { display: grid; grid-template-columns: auto minmax(260px, 560px); gap: 13px; align-items: center; padding: 13px 0 20px; }
.search-label { color: var(--muted); font-size: 11px; letter-spacing: .08em; text-transform: uppercase; white-space: nowrap; }

.button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid var(--blue); background: var(--blue); color: var(--white); border-radius: 999px; padding: 10px 16px; font-size: 12px; font-weight: 700; letter-spacing: .02em; transition: transform .18s ease, background .18s ease, color .18s ease; }
.button:hover { transform: translateY(-1px); background: #244b6a; }
.button.ghost { background: transparent; color: var(--blue); }
.button.ghost:hover { color: var(--white); }
.button.small { padding: 8px 12px; font-size: 11px; }
.button.danger { border-color: var(--red); background: var(--red); }
.button.link { border: 0; background: transparent; color: var(--red); padding: 0; border-radius: 0; }
.button[disabled] { opacity: .5; cursor: wait; transform: none; }

.toolbar { display: grid; grid-template-columns: minmax(240px, 1fr) 200px 190px auto; gap: 10px; align-items: center; margin: 12px 0 25px; }
.places-toolbar { grid-template-columns: 200px 190px auto; }
.input, .select, .edit-input, .edit-textarea { width: 100%; border: 1px solid var(--line); background: rgba(255,253,248,.72); color: var(--ink); padding: 11px 13px; border-radius: 4px; outline: none; }
.input:focus, .select:focus, .edit-input:focus, .edit-textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(23,55,83,.1); }
.toolbar-caption { color: var(--muted); font-size: 12px; text-align: right; }

.section-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 18px; margin: 0 0 13px; }
.section-heading h2 { font-family: Georgia, serif; font-weight: 500; font-size: 28px; margin: 0; }
.section-heading p { color: var(--muted); font-size: 12px; margin: 0; }
.table-wrap { overflow: auto; border-top: 1px solid var(--ink); border-bottom: 1px solid var(--line); background: var(--white); box-shadow: var(--shadow); }
.data-table { width: 100%; border-collapse: collapse; min-width: 940px; font-size: 13px; }
.data-table th { text-align: left; font-size: 10px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); background: #f7f5ef; padding: 12px 13px; border-bottom: 1px solid var(--line); white-space: nowrap; position: sticky; top: 0; z-index: 1; }
.data-table th[data-sort] { cursor: pointer; user-select: none; -webkit-tap-highlight-color: transparent; }
.data-table th[data-sort]:hover { color: var(--ink); background: #efede5; }
.data-table th[data-sort] > span:first-child { margin-right: 6px; }
.sort-indicator { color: var(--red); font-size: 12px; letter-spacing: 0; }
.data-table td { padding: 15px 13px; border-bottom: 1px solid #e8e6df; vertical-align: top; }
.data-table tbody tr { transition: background .18s ease; }
.data-table tbody tr:hover { background: #f7f3ea; }
.data-table tbody tr.clickable { cursor: pointer; }
.code { color: var(--red); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.place-name { font-weight: 700; color: var(--ink); }
.subline { color: var(--muted); font-size: 11px; margin-top: 4px; line-height: 1.35; }
.operational-total { color: var(--red); font-weight: 800; }
.number { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.number.emphasis { font-size: 17px; font-weight: 700; }
.status { display: inline-flex; align-items: center; gap: 7px; font-size: 11px; white-space: nowrap; }
.status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.status.available { color: var(--red); }
.status.available::before { background: var(--red); }
.status.covered { color: var(--green); }
.status.covered::before { background: var(--green); }
.status.process { color: var(--gold); }
.status.process::before { background: var(--gold); }
.edited-value { color: var(--red) !important; font-weight: 800; }
.edited-row td:first-child { box-shadow: inset 3px 0 0 var(--red); }
.edited-chip { color: var(--red); font-size: 10px; letter-spacing: .08em; text-transform: uppercase; margin-left: 7px; }
.comment-button { display: inline-flex; align-items: center; gap: 3px; border: 0; background: transparent; color: var(--red); padding: 0 3px; margin-left: 6px; vertical-align: middle; }
.comment-button:hover { color: var(--blue); }
.notebook-icon { display: inline-block; width: 14px; height: 16px; border: 1.5px solid currentColor; border-radius: 2px; position: relative; }
.notebook-icon::before { content: ""; position: absolute; left: 4px; right: 2px; top: 4px; height: 1px; background: currentColor; box-shadow: 0 3px 0 currentColor, 0 6px 0 currentColor; }
.notebook-icon::after { content: ""; position: absolute; left: -4px; top: 3px; width: 3px; height: 9px; border-top: 1px solid currentColor; border-bottom: 1px solid currentColor; }
.comment-count { font-size: 10px; font-weight: 800; }
.comment-row td { padding: 0 13px 14px 36px; background: #fbf1ed; border-bottom: 1px solid #e8d2cc; }
.comment-line { display: flex; align-items: flex-start; gap: 13px; flex-wrap: wrap; border-left: 2px solid var(--red); padding: 10px 0 0 13px; }
.comment-line-label { color: var(--red); font-size: 10px; letter-spacing: .1em; text-transform: uppercase; font-weight: 800; }
.comment-list { display: grid; gap: 8px; flex: 1 1 360px; }
.comment-item { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; font-size: 12px; line-height: 1.45; }
.comment-body { color: var(--ink); }
.comment-meta { color: var(--muted); font-size: 10px; white-space: nowrap; }
.comment-delete { margin-left: auto; border: 0; background: transparent; color: var(--muted); cursor: pointer; font-size: 18px; line-height: 1; padding: 0 3px; }
.comment-delete:hover { color: var(--red); }
.comment-delete:disabled { opacity: .45; cursor: wait; }
.empty-state { padding: 54px 24px; color: var(--muted); text-align: center; }
.empty-state strong { display: block; font-family: Georgia, serif; color: var(--ink); font-size: 25px; font-weight: 500; margin-bottom: 8px; }

.content-grid { display: grid; grid-template-columns: minmax(0, 1fr) 310px; gap: 28px; align-items: start; }
.side-note { border-left: 2px solid var(--red); padding-left: 17px; color: var(--muted); font-size: 12px; line-height: 1.65; }
.side-note h3 { color: var(--ink); font-family: Georgia, serif; font-size: 23px; font-weight: 500; margin: 0 0 7px; }
.side-note p { margin: 0 0 16px; }
.source-list { list-style: none; margin: 0; padding: 0; }
.source-list li { border-bottom: 1px solid var(--line); padding: 14px 0; }
.source-list strong { display: block; color: var(--ink); font-size: 13px; margin-bottom: 4px; }
.source-list span { display: block; color: var(--muted); font-size: 11px; line-height: 1.45; }
.source-list a { color: var(--red); font-size: 11px; display: inline-block; margin-top: 6px; text-decoration: none; }
.source-list a:hover { text-decoration: underline; }
.source-subtabs { display: flex; gap: 8px; flex-wrap: wrap; border-bottom: 1px solid var(--line); margin: 0 0 18px; }
.source-tab { appearance: none; border: 0; border-bottom: 2px solid transparent; background: transparent; color: var(--muted); padding: 11px 14px 12px; cursor: pointer; font: inherit; font-size: 12px; text-align: left; }
.source-tab:hover, .source-tab.active { color: var(--ink); border-bottom-color: var(--red); }
.source-tab small { color: var(--red); font-size: 10px; margin-left: 5px; }
.independent-toolbar { grid-template-columns: 1fr; }
.source-chip { color: var(--red); font-size: 11px; line-height: 1.35; }
.independent-table { min-width: 1240px; }
.update-chip { display: inline-block; color: #17614f; background: #e6f1eb; border: 1px solid #b9d8c9; border-radius: 999px; padding: 4px 8px; font-size: 10px; white-space: nowrap; }
.update-summary { display: inline-flex; align-items: baseline; gap: 10px; border-left: 3px solid var(--red); padding: 8px 14px; margin: 0 0 18px; background: #fffaf3; color: var(--muted); font-size: 12px; }
.update-summary strong { color: var(--red); font-family: Georgia, serif; font-size: 27px; font-weight: 500; }
.updates-table { min-width: 1360px; }
.source-link { color: var(--red); text-decoration: none; font-size: 11px; line-height: 1.35; }
.source-link:hover { text-decoration: underline; }

.drawer-backdrop { position: fixed; inset: 0; background: rgba(12, 23, 33, .34); z-index: 40; opacity: 0; pointer-events: none; transition: opacity .24s ease; }
.drawer-backdrop.open { opacity: 1; pointer-events: auto; }
.drawer { position: fixed; z-index: 41; right: 0; top: 0; bottom: 0; width: min(620px, 100%); background: var(--white); box-shadow: -20px 0 60px rgba(20,38,58,.18); transform: translateX(100%); transition: transform .28s cubic-bezier(.22,.8,.24,1); overflow-y: auto; }
.drawer.open { transform: translateX(0); }
.drawer-inner { padding: 27px clamp(20px, 4vw, 42px) 48px; }
.drawer-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; border-bottom: 1px solid var(--line); padding-bottom: 19px; }
.drawer-top h2 { margin: 8px 0 0; font-family: Georgia, serif; font-weight: 500; font-size: 33px; line-height: .98; }
.close-button { border: 0; background: var(--paper); width: 35px; height: 35px; border-radius: 50%; color: var(--ink); font-size: 18px; }
.drawer-section { padding: 21px 0; border-bottom: 1px solid var(--line); }
.drawer-section h3 { margin: 0 0 13px; font-size: 11px; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); }
.detail-meta { display: grid; gap: 12px; }
.meta-row { display: grid; grid-template-columns: 135px minmax(0,1fr); gap: 12px; font-size: 13px; line-height: 1.45; }
.meta-row dt { color: var(--muted); }
.meta-row dd { margin: 0; color: var(--ink); }
.place-mini { display: grid; grid-template-columns: minmax(0,1fr) repeat(4, auto); gap: 10px; align-items: center; border-top: 1px solid var(--line); padding: 12px 0; font-size: 12px; }
.place-mini:first-of-type { border-top: 0; }
.place-mini-name { font-weight: 700; }
.place-mini small { display: block; color: var(--muted); font-size: 10px; margin-top: 3px; }
.candidate-list { columns: 2; column-gap: 26px; margin: 0; padding-left: 20px; color: var(--ink); font-size: 12px; line-height: 1.7; }
.candidate-list li { break-inside: avoid; padding-left: 3px; }
.cross-list { display: grid; gap: 10px; }
.cross-item { padding: 12px 14px; background: var(--paper); border-left: 3px solid var(--gold); font-size: 12px; line-height: 1.45; }
.cross-item strong { display: block; font-size: 13px; margin-bottom: 4px; }
.cross-item small { color: var(--muted); display: block; }
.drawer-footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-top: 21px; }
.tiny-note { color: var(--muted); font-size: 11px; line-height: 1.45; }
.tiny-note.edited { color: var(--red); }

.edit-form { display: grid; gap: 14px; }
.edit-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.field-label { display: grid; gap: 6px; color: var(--muted); font-size: 11px; }
.field-label span { text-transform: uppercase; letter-spacing: .06em; }
.edit-textarea { min-height: 95px; resize: vertical; }
.edit-actions { display: flex; gap: 8px; align-items: center; }

.modal-backdrop { position: fixed; inset: 0; z-index: 50; background: rgba(12, 23, 33, .5); display: grid; place-items: center; padding: 20px; opacity: 0; pointer-events: none; transition: opacity .2s ease; }
.modal-backdrop.open { opacity: 1; pointer-events: auto; }
.modal { width: min(430px, 100%); background: var(--white); padding: 30px; box-shadow: var(--shadow); transform: translateY(12px); transition: transform .2s ease; }
.modal-backdrop.open .modal { transform: translateY(0); }
.modal h2 { font-family: Georgia, serif; font-size: 31px; font-weight: 500; margin: 0 0 8px; }
.modal p { color: var(--muted); font-size: 13px; line-height: 1.5; margin: 0 0 20px; }
.login-form { display: grid; gap: 12px; }
.login-error { color: var(--red); font-size: 12px; min-height: 18px; }
.modal-close { border: 0; background: none; color: var(--muted); padding: 0; font-size: 12px; margin-top: 13px; }
.modal-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.modal-heading h2 { margin: 8px 0 0; }
.comment-modal, .users-modal { width: min(620px, 100%); max-height: min(720px, calc(100vh - 40px)); overflow: auto; }
.audit-modal { width: min(820px, 100%); max-height: min(760px, calc(100vh - 40px)); overflow: auto; }
.comment-modal-list { display: grid; gap: 11px; padding: 14px 0 18px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); margin-bottom: 18px; }
.comment-modal-list .comment-item { display: grid; gap: 4px; padding-left: 12px; border-left: 2px solid var(--red); }
.empty-comment { color: var(--muted); font-size: 13px; padding: 8px 0 16px; }
.user-form { display: grid; gap: 12px; padding: 16px 0 22px; border-bottom: 1px solid var(--line); }
.user-form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.user-list { padding-top: 18px; }
.user-list h3 { margin: 0 0 9px; font-size: 11px; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); }
.user-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 11px 0; border-top: 1px solid var(--line); font-size: 12px; }
.user-row strong { display: block; }
.user-row small { color: var(--red); text-transform: uppercase; letter-spacing: .08em; font-size: 9px; }
.audit-list { border-top: 1px solid var(--line); }
.audit-row { display: grid; grid-template-columns: minmax(150px, .8fr) minmax(230px, 1.4fr) auto; gap: 15px; align-items: baseline; padding: 12px 0; border-bottom: 1px solid var(--line); font-size: 12px; }
.audit-row strong { display: block; }
.audit-row span { display: block; color: var(--red); font-size: 10px; margin-top: 3px; text-transform: uppercase; letter-spacing: .06em; }
.audit-detail { color: var(--muted); line-height: 1.4; }
.audit-row time { color: var(--muted); white-space: nowrap; font-size: 10px; }
.toast { position: fixed; bottom: 24px; left: 50%; z-index: 60; transform: translate(-50%, 20px); opacity: 0; pointer-events: none; background: var(--blue); color: var(--white); padding: 12px 17px; font-size: 12px; box-shadow: var(--shadow); transition: opacity .2s ease, transform .2s ease; }
.toast.open { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--red); }

@media (max-width: 1050px) {
  .metrics { grid-template-columns: repeat(3, 1fr); }
  .metric:nth-child(3) { border-right: 0; }
  .metric:nth-child(n+4) { border-top: 1px solid var(--line); }
  .content-grid { grid-template-columns: 1fr; }
  .side-note { margin-top: 28px; }
}
@media (max-width: 760px) {
  .topbar { height: 66px; }
  .brand-sub, .sync-note { display: none; }
  .page { width: min(100% - 28px, 1520px); padding-top: 39px; }
  .intro { grid-template-columns: 1fr; gap: 25px; }
  .intro h1 { font-size: clamp(3rem, 16vw, 5.5rem); }
  .metrics { grid-template-columns: repeat(2, 1fr); }
  .metric:nth-child(3) { border-right: 1px solid var(--line); }
  .metric:nth-child(2n) { border-right: 0; margin-right: 0; }
  .toolbar { grid-template-columns: 1fr 1fr; }
  .global-search { grid-template-columns: 1fr; gap: 7px; padding-top: 10px; }
  .places-toolbar { grid-template-columns: 1fr 1fr; }
  .independent-toolbar { grid-template-columns: 1fr; }
  .toolbar .input { grid-column: 1 / -1; }
  .toolbar-caption { text-align: left; grid-column: 1 / -1; }
  .navline { align-items: flex-start; flex-direction: column; }
  .topbar-actions { gap: 7px; }
  .header-admin-actions { gap: 3px; }
  .header-admin-actions .button { padding-left: 8px; padding-right: 8px; }
  .section-heading { align-items: flex-start; flex-direction: column; gap: 7px; }
  .drawer-inner { padding: 22px 20px 40px; }
  .meta-row { grid-template-columns: 1fr; gap: 2px; }
  .place-mini { grid-template-columns: minmax(0, 1fr) repeat(2, auto); }
  .place-mini .optional-mini { display: none; }
  .candidate-list { columns: 1; }
  .edit-grid { grid-template-columns: 1fr; }
  .audit-row { grid-template-columns: 1fr; gap: 4px; }
}
