:root {
  --paper-edge: #ddded8;
  --paper: #f8f7f1;
  --paper-deep: #ecebe5;
  --ink: #1f302b;
  --muted: #65706b;
  --line: #c9cbc4;
  --line-strong: #89928e;
  --vermilion: #b7462f;
  --good: #28745c;
  --fixed: #89651f;
  --bad: #9f2f3d;
  --serif: "Iowan Old Style", "Noto Serif TC", "Songti TC", serif;
  --sans: "PingFang TC", "Noto Sans TC", "Heiti TC", sans-serif;
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(90deg, rgba(31, 48, 43, .025) 1px, transparent 1px) 0 0 / 8px 8px,
    var(--paper-edge);
  font-family: var(--sans);
  font-size: 15px;
}

button, input, select { font: inherit; }
button { color: inherit; }

button:focus-visible, input:focus-visible, select:focus-visible, a:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--vermilion) 45%, transparent);
  outline-offset: 2px;
}

.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;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 214px minmax(520px, 1fr) minmax(330px, 410px);
  max-width: 1700px;
  margin: 0 auto;
  background: var(--paper);
  box-shadow: 0 0 42px rgba(31, 48, 43, .12);
}

.source-index {
  min-width: 0;
  padding: 28px 18px 22px;
  background: var(--ink);
  color: #f4f1e9;
  display: flex;
  flex-direction: column;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 8px 27px;
  border-bottom: 1px solid rgba(255, 255, 255, .17);
}

.brand-mark {
  width: 35px;
  height: 35px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, .7);
  border-radius: 50%;
  font: 700 18px/1 var(--serif);
}

.brand strong, .brand small { display: block; }
.brand strong { font: 700 15px/1.25 var(--serif); }
.brand small { color: #aeb9b4; margin-top: 5px; font-size: 11px; }

.index-nav { display: grid; gap: 4px; padding-top: 26px; }

.index-link {
  width: 100%;
  border: 0;
  border-left: 3px solid transparent;
  background: transparent;
  color: #cbd1ce;
  padding: 11px 9px 11px 13px;
  display: flex;
  justify-content: space-between;
  text-align: left;
  cursor: pointer;
}

.index-link b { font-variant-numeric: tabular-nums; font-weight: 600; color: #8d9b95; }
.index-link:hover { color: white; background: rgba(255, 255, 255, .05); }
.index-link.is-active { border-left-color: var(--vermilion); color: white; background: rgba(255, 255, 255, .08); }
.index-link.needs-attention b { color: #f08a7d; }

.inspection-note {
  margin-top: 28px;
  padding: 18px 9px 0;
  border-top: 1px solid rgba(255, 255, 255, .17);
  color: #adb9b4;
  font-size: 12px;
  line-height: 1.55;
}

.inspection-note h2 { color: white; font-size: 12px; margin: 0 0 8px; }
.inspection-note p { margin: 7px 0; }

.journal {
  min-width: 0;
  padding: 31px 32px 52px;
  background:
    linear-gradient(90deg, transparent 0 31px, rgba(183, 70, 47, .16) 31px 32px, transparent 32px),
    var(--paper);
}

.journal-heading {
  display: grid;
  grid-template-columns: 74px minmax(0, 1fr) auto;
  gap: 20px;
  align-items: start;
  padding-bottom: 25px;
  border-bottom: 2px solid var(--ink);
}

.date-stamp {
  min-height: 78px;
  border: 1px solid var(--ink);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #fffefa;
}

.date-stamp strong { font: 700 34px/.9 var(--serif); font-variant-numeric: tabular-nums; }
.date-stamp span { margin-top: 8px; font-size: 10px; color: var(--muted); }
.ledger-label { margin: 1px 0 7px; color: var(--vermilion); font-size: 12px; }
.heading-copy h1 { margin: 0; font: 700 clamp(27px, 3vw, 38px)/1.05 var(--serif); letter-spacing: -.03em; }
.heading-copy > p:last-child { margin: 11px 0 0; color: var(--muted); font-size: 12px; }

.check-button {
  border: 1px solid var(--ink);
  background: transparent;
  padding: 10px 13px;
  cursor: pointer;
}

.check-button:hover { background: var(--ink); color: white; }
.check-button[aria-busy="true"] { cursor: wait; opacity: .58; }

.status-ledger {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border-bottom: 1px solid var(--line-strong);
}

.status-ledger button {
  border: 0;
  border-right: 1px solid var(--line);
  background: transparent;
  padding: 18px 16px 17px 0;
  text-align: left;
  cursor: pointer;
}

.status-ledger button + button { padding-left: 18px; }
.status-ledger button:last-child { border-right: 0; }
.status-ledger span { display: block; color: var(--muted); font-size: 11px; min-height: 31px; }
.status-ledger strong { display: block; margin-top: 3px; font: 700 28px/1 var(--serif); font-variant-numeric: tabular-nums; }
.status-ledger button:nth-child(1) strong { color: var(--good); }
.status-ledger button:nth-child(2) strong { color: var(--fixed); }
.status-ledger button:nth-child(3) strong { color: var(--bad); }
.status-ledger button:hover span { color: var(--ink); }

.toolbar {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) auto auto;
  gap: 8px;
  padding: 18px 0 12px;
}

.toolbar input, .toolbar select {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 0;
  background: #fffefa;
  color: var(--ink);
  padding: 8px 10px;
}

.search-field { min-width: 0; }
.journal-list { border-top: 1px solid var(--line); }

.journal-entry {
  width: 100%;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  display: grid;
  grid-template-columns: 72px minmax(210px, 1fr) 124px;
  gap: 15px;
  padding: 17px 8px 17px 0;
  text-align: left;
  cursor: pointer;
  position: relative;
}

.journal-entry::before {
  content: "";
  position: absolute;
  left: -32px;
  top: 0;
  bottom: -1px;
  width: 1px;
  background: rgba(183, 70, 47, .18);
}

.journal-entry:hover, .journal-entry.is-selected { background: #fffdf6; }
.journal-entry.is-selected { box-shadow: inset 3px 0 var(--vermilion); padding-left: 11px; }
.entry-time { color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.entry-time strong { display: block; color: var(--ink); font: 700 18px/1 var(--serif); margin-bottom: 4px; }
.entry-body { min-width: 0; }
.entry-body h2 { margin: 0; font-size: 14px; line-height: 1.35; }
.entry-body p { margin: 6px 0 0; color: var(--muted); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.entry-body small { display: block; margin-top: 8px; color: var(--muted); font-size: 10px; }

.health-badge {
  justify-self: end;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 11px;
  line-height: 1.3;
}

.health-badge::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--good);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--good) 14%, transparent);
}

.health-badge.fixed::before { background: var(--fixed); box-shadow: 0 0 0 3px color-mix(in srgb, var(--fixed) 14%, transparent); }
.health-badge.broken::before { background: var(--bad); box-shadow: 0 0 0 3px color-mix(in srgb, var(--bad) 14%, transparent); }
.health-badge.unknown::before { background: var(--line-strong); box-shadow: 0 0 0 3px color-mix(in srgb, var(--line-strong) 14%, transparent); }
.health-badge.inactive::before { background: var(--muted); box-shadow: none; }
.health-badge.inactive { color: var(--muted); }
.view-note { color: var(--muted); font-size: 12px; line-height: 1.6; }
.candidate-section { margin-top: 26px; border-top: 1px solid var(--line); }
.candidate-section > p { font-size: 12px; line-height: 1.7; color: var(--muted); }
summary { cursor: pointer; padding: 14px 0; font-size: 13px; }
.project-link { display: block; margin: 15px 0; color: var(--vermilion); font-size: 13px; }
.dialog-buttons { display: flex; gap: 12px; margin-top: 18px; }
.dialog-content label { display: block; font-size: 12px; }
.dialog-content [hidden] { display: none; }
.dialog-content input, .dialog-content textarea { width: 100%; margin-top: 8px; padding: 10px; border: 1px solid var(--line); font: inherit; background: #fffefa; }
#dialogError, .danger { color: var(--bad); }
button:disabled { opacity: .5; cursor: wait; }
.agent-result { border-top: 1px solid var(--line); padding: 12px 0; font-size: 12px; }
.agent-result time { display: block; margin-top: 4px; color: var(--muted); font-size: 10px; }
.agent-result pre { white-space: pre-wrap; overflow-wrap: anywhere; font: inherit; line-height: 1.6; }

.gas-notice { margin: 13px 0 5px; padding: 13px 15px; border-left: 3px solid var(--fixed); background: #ece8dc; }
.gas-notice strong { font-size: 12px; }
.gas-notice p { margin: 5px 0 0; color: var(--muted); font-size: 11px; line-height: 1.55; }

.evidence-panel {
  min-width: 0;
  padding: 31px 28px 44px;
  border-left: 1px solid var(--line);
  background: #f0efe9;
  overflow-y: auto;
  max-height: 100vh;
  position: sticky;
  top: 0;
}

.detail-close { display: none; }

.empty-detail { min-height: 70vh; display: grid; place-content: center; text-align: center; color: var(--muted); }
.empty-seal { width: 54px; height: 54px; margin: 0 auto 15px; display: grid; place-items: center; border: 1px solid var(--line-strong); border-radius: 50%; font: 700 24px var(--serif); }
.empty-detail h2 { margin: 0; color: var(--ink); font: 700 21px var(--serif); }
.empty-detail p { max-width: 240px; margin: 9px auto; font-size: 12px; line-height: 1.6; }

.detail-head { padding-bottom: 18px; border-bottom: 2px solid var(--ink); }
.detail-head .health-badge { justify-self: start; }
.detail-head h2 { margin: 13px 0 0; font: 700 25px/1.2 var(--serif); letter-spacing: -.02em; }
.detail-head > p { margin: 12px 0 0; color: var(--muted); line-height: 1.65; font-size: 13px; }
.validation-note { margin: 13px 0 0; padding: 9px 10px; border-left: 3px solid var(--fixed); background: #e8e4d8; font-size: 11px; line-height: 1.5; }

.facts { display: grid; grid-template-columns: 1fr 1fr; border-bottom: 1px solid var(--line); }
.fact { min-width: 0; padding: 14px 10px 14px 0; border-bottom: 1px solid var(--line); }
.fact:nth-child(odd) { border-right: 1px solid var(--line); }
.fact:nth-child(even) { padding-left: 13px; }
.fact span { display: block; color: var(--muted); font-size: 10px; margin-bottom: 5px; }
.fact strong { display: block; font-size: 12px; line-height: 1.4; overflow-wrap: anywhere; }

.detail-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; margin: 17px 0 4px; }
.detail-actions button { min-height: 38px; border: 1px solid var(--ink); background: transparent; cursor: pointer; font-size: 12px; }
.detail-actions button:hover { background: var(--ink); color: white; }
.detail-actions .fix-action { grid-column: 1 / -1; background: var(--ink); color: white; }
.detail-actions .fix-action:hover { background: var(--vermilion); border-color: var(--vermilion); }
.phase-note { margin: 9px 0 0; color: var(--muted); font-size: 10px; line-height: 1.5; }

.detail-section { margin-top: 27px; }
.detail-section h3 { margin: 0 0 12px; font: 700 16px var(--serif); }
.timeline { border-left: 1px solid var(--line-strong); margin-left: 4px; }
.timeline-event { position: relative; padding: 0 0 19px 17px; }
.timeline-event::before { content: ""; position: absolute; left: -4px; top: 3px; width: 7px; height: 7px; border-radius: 50%; background: var(--good); }
.timeline-event.error::before { background: var(--bad); }
.timeline-event time { display: block; color: var(--muted); font-size: 10px; }
.timeline-event strong { display: block; margin-top: 3px; font-size: 12px; }
.timeline-event p { margin: 5px 0 0; color: var(--muted); font-size: 11px; line-height: 1.55; }

.artifact-list { border-top: 1px solid var(--line); }
.artifact { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; align-items: center; padding: 11px 0; border-bottom: 1px solid var(--line); }
.artifact strong, .artifact small { display: block; }
.artifact strong { font-size: 11px; overflow-wrap: anywhere; }
.artifact small { color: var(--muted); margin-top: 3px; font-size: 9px; }
.artifact a, .artifact button { border: 0; background: transparent; color: var(--vermilion); font-size: 11px; font-weight: 700; text-decoration: none; cursor: pointer; padding: 5px; }

.path-row { padding: 9px 0; border-bottom: 1px solid var(--line); }
.path-row span { display: block; color: var(--muted); font-size: 9px; }
.path-row code { display: block; margin-top: 4px; color: var(--ink); font: 10px/1.55 ui-monospace, SFMono-Regular, Menlo, monospace; overflow-wrap: anywhere; }
.path-row button { margin-top: 6px; padding: 0; border: 0; background: transparent; color: var(--vermilion); cursor: pointer; font-size: 10px; }

.loading-state, .empty-list { padding: 45px 10px; text-align: center; color: var(--muted); }
.empty-list span { display: block; color: var(--ink); font: 700 18px var(--serif); }
.empty-list p { margin: 8px 0; font-size: 12px; }
.error-state { padding: 20px; border-left: 3px solid var(--bad); background: #f5e6e7; color: var(--bad); line-height: 1.6; }

dialog { width: min(420px, calc(100vw - 30px)); padding: 0; border: 1px solid var(--ink); border-radius: 0; background: var(--paper); color: var(--ink); box-shadow: 18px 18px 0 rgba(31, 48, 43, .18); }
dialog::backdrop { background: rgba(31, 48, 43, .62); }
.dialog-content { padding: 26px; }
.dialog-kicker { color: var(--vermilion); font-size: 11px; }
.dialog-content h2 { margin: 8px 0; font: 700 24px var(--serif); }
.dialog-content p { color: var(--muted); font-size: 13px; line-height: 1.65; }
.dialog-content button { display: block; margin-left: auto; border: 1px solid var(--ink); background: var(--ink); color: white; padding: 9px 17px; cursor: pointer; }

@media (max-width: 1120px) {
  .app-shell { grid-template-columns: 194px minmax(480px, 1fr); }
  .evidence-panel { position: fixed; right: 0; top: 0; bottom: 0; width: min(410px, 92vw); z-index: 20; box-shadow: -18px 0 42px rgba(31, 48, 43, .2); transform: translateX(100%); transition: transform .18s ease-out; }
  .evidence-panel.is-open { transform: translateX(0); }
  .evidence-panel:not(.is-open) { visibility: hidden; }
  .detail-close { display: block; margin: 0 0 17px auto; padding: 5px 0; border: 0; border-bottom: 1px solid var(--ink); background: transparent; cursor: pointer; font-size: 11px; }
}

@media (max-width: 760px) {
  .app-shell { display: block; min-height: 100vh; }
  .source-index { padding: 18px 16px 11px; }
  .brand { padding-bottom: 15px; }
  .index-nav { padding-top: 12px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .index-link[data-view="apps-script"] { grid-column: 1 / -1; }
  .index-link { border-left: 0; border-bottom: 2px solid transparent; padding: 9px 10px; gap: 8px; white-space: nowrap; }
  .index-link.is-active { border-bottom-color: var(--vermilion); }
  .inspection-note { display: none; }
  .journal { padding: 20px 18px 44px; background: var(--paper); }
  .journal-heading { grid-template-columns: 58px 1fr; gap: 13px; }
  .date-stamp { min-height: 64px; }
  .date-stamp strong { font-size: 28px; }
  .check-button { grid-column: 1 / -1; width: 100%; }
  .status-ledger span { min-height: 44px; }
  .toolbar { grid-template-columns: 1fr 1fr; }
  .toolbar .search-field { grid-column: 1 / -1; }
  .journal-entry { grid-template-columns: 55px minmax(150px, 1fr); }
  .health-badge { justify-self: start; grid-column: 2; }
  .journal-entry::before { display: none; }
}

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