:root {
  --bg: #f3f6f4;
  --card: #fff;
  --ink: #1c2420;
  --muted: #5c6b63;
  --line: #d5e0da;
  --accent: #1c7a40;
  --danger: #b42318;
  --radius: 14px;
  --excel: #217346;
  --excel-dark: #1a5c38;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Segoe UI", Tahoma, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.35;
}

.top {
  background: #1b3a2f;
  color: #fff;
  padding: 0.35rem 0.75rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.35rem 0.75rem;
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand { font-weight: 700; line-height: 1.15; margin-right: auto; }
.brand a { color: #fff; text-decoration: none; }
.who { font-weight: 650; color: #fff; }
.top nav { display: flex; flex-wrap: wrap; justify-content: flex-end; align-items: center; gap: 0.2rem 0.65rem; line-height: 1.2; font-size: 0.92rem; }
.top nav a { color: #d7ebe0; text-decoration: none; }
.top nav a:hover { color: #fff; }
.appbar a.site-home {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #e7c56a;
  color: #1b2430 !important;
  text-decoration: none;
  font-weight: 700;
  font-size: 0.82rem;
  line-height: 1;
  border-radius: 999px;
  padding: 0.38rem 0.72rem;
}
.appbar a.site-home:hover { background: #f0d48a; }

.wrap { padding: 0.75rem 0.85rem 2rem; max-width: 920px; margin: 0 auto; }
body.sheet-page .wrap { max-width: none; }

h1 { font-size: 1.35rem; margin: 0; line-height: 1.2; }
h2 { font-size: 1.05rem; margin: 0 0 0.35rem; }
p { margin: 0.2rem 0; }
a { color: #146b38; }

.page-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.7rem;
  margin-bottom: 0.7rem;
}
.muted { color: var(--muted); }
.field-hint { color: var(--muted); font-size: 0.82rem; margin: 0; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.85rem 0.95rem;
  margin-bottom: 0.7rem;
}

form { display: grid; gap: 0.65rem; }
label { display: grid; gap: 0.2rem; font-size: 0.92rem; color: var(--muted); }
.field-label { display: block; font-size: 0.92rem; color: var(--muted); margin-bottom: 0.2rem; }
input, select, textarea {
  font: inherit;
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  width: 100%;
  min-width: 0;
}
textarea { min-height: 6.5rem; resize: vertical; line-height: 1.4; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0.7rem; }
fieldset {
  border: 1px solid var(--line);
  border-radius: 10px;
  margin: 0;
  padding: 0.45rem 0.75rem 0.7rem;
}
legend { font-size: 0.92rem; color: var(--muted); padding: 0 0.25rem; }
.choices { display: flex; flex-wrap: wrap; gap: 0.75rem 1.3rem; }
.choices label { display: flex; align-items: center; gap: 0.4rem; color: var(--ink); font-weight: 650; }
.choices input { width: auto; }

.btn, button, input[type=submit] {
  font: inherit;
  font-size: 0.95rem;
  font-weight: 650;
  border: 0;
  border-radius: 10px;
  padding: 0.45rem 0.75rem;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
  text-align: center;
}
.btn.secondary, button.secondary { background: #5c6b63; }
.btn.danger, button.danger { background: var(--danger); }
.btn.tiny { padding: 0.18rem 0.45rem; font-size: 0.78rem; border-radius: 6px; }
.actions { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
form.allocate { display: flex; flex-wrap: wrap; gap: 0.45rem; align-items: end; }
form.allocate label { flex: 1 1 12rem; margin: 0; }
button:disabled { opacity: 0.6; cursor: default; }

.error, .notice { padding: 0.7rem 0.85rem; border-radius: 10px; margin: 0 0 0.7rem; }
.error { background: #fde8e6; color: #8a1c13; }
.notice { background: #e5f6ea; color: #146b38; }

.login-wrap {
  min-height: calc(100dvh - 64px);
  display: grid;
  place-items: center;
  padding: 1rem 0 2rem;
}
.login-card {
  width: min(420px, 100%);
  background: #fff;
  border: 1px solid #e6e1d6;
  border-radius: 16px;
  box-shadow: 0 16px 40px rgba(27, 36, 48, 0.12);
  padding: 1.4rem 1.3rem 1.2rem;
}
.login-card h1 { font-size: 1.5rem; margin-bottom: 0.35rem; }
.login-card button[type="submit"] { width: 100%; margin-top: 0.25rem; background: #1b2430; padding: 0.7rem 1rem; }
.password-line { position: relative; display: block; }
.password-line input { width: 100%; padding-right: 4.4rem; }
.password-reveal {
  position: absolute;
  right: 0.3rem;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  color: var(--accent);
  padding: 0.15rem 0.4rem;
  font-size: 0.8rem;
}
.person { display: flex; justify-content: space-between; gap: 0.8rem; align-items: flex-start; padding: 0.7rem 0; border-top: 1px solid var(--line); }
.person:first-of-type { border-top: 0; }
.person-tools { flex: 1 1 16rem; max-width: 22rem; }
.person-tools form + form { margin-top: 0.45rem; }
.wipe-card { border-color: #f0c2be; }
.wipe-card h2 { color: var(--danger); }

.workbook {
  background: #fff;
  border: 1px solid #b7b7b7;
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(27, 36, 48, 0.06);
}
.sheet-meta {
  padding: 0.75rem 0.85rem 0.65rem;
  background: #f3f3f3;
  border-bottom: 1px solid #d0d0d0;
  border-radius: 12px 12px 0 0;
}
.meta-top {
  display: flex;
  justify-content: space-between;
  gap: 0.8rem 1.2rem;
  align-items: flex-end;
  flex-wrap: wrap;
}
.title-read h1 { font-size: 1.45rem; }
.appetite-read { margin: 0.25rem 0 0; }
.title-form { display: flex; flex-wrap: wrap; gap: 0.55rem 0.8rem; align-items: end; flex: 1 1 28rem; }
.title-form label.title { flex: 1 1 16rem; }
.title-form label.appetite { flex: 0 1 9rem; }
.title-form input[name="title"] {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--ink);
}
.updated { margin: 0; color: var(--muted); white-space: nowrap; }
.stats { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.7rem; }
.stat {
  background: #fff;
  border: 1px solid #d0d0d0;
  border-radius: 8px;
  padding: 0.32rem 0.6rem;
  min-width: 7.2rem;
}
.stat span {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}
.stat strong { font-size: 0.98rem; }
.sheet-extra { margin: 0.45rem 0 0; font-size: 0.85rem; }
.toolbar { display: flex; flex-wrap: wrap; gap: 0.45rem; align-items: flex-start; margin-top: 0.7rem; }
.toolbar form { display: inline; }
details.ask { background: transparent; }
summary.as-btn {
  list-style: none;
  background: var(--accent);
  color: #fff;
  border-radius: 10px;
  padding: 0.45rem 0.75rem;
  font-weight: 650;
  cursor: pointer;
  display: inline-block;
}
summary.as-btn.secondary { background: #5c6b63; }
summary.as-btn::-webkit-details-marker { display: none; }
details.ask .ask-body {
  margin-top: 0.45rem;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.75rem;
  width: min(320px, 100%);
  display: grid;
  gap: 0.5rem;
  box-shadow: 0 10px 24px rgba(27, 36, 48, 0.08);
}
details.definitions[open] { flex: 1 0 100%; width: 100%; }
details.ask.definitions .ask-body { width: 100%; max-width: none; }
details.definitions .scale-key { padding: 0; gap: 0.8rem 2.5rem; }
.review-banner {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.55rem 0.8rem;
  align-items: center;
  padding: 0.55rem 0.85rem;
  background: #e5f6ea;
  border-bottom: 1px solid #b7dfc4;
}
.review-banner p { margin: 0; }
.review-banner .actions form { display: inline; }

.sheet-scroll {
  overflow-x: scroll;
  overflow-y: auto;
  max-height: min(70dvh, 46rem);
  min-height: 16rem;
  background: #fff;
  scrollbar-color: #1a5c38 #e4e4e4;
  scrollbar-width: auto;
}
.sheet-scroll::-webkit-scrollbar { height: 16px; width: 16px; }
.sheet-scroll::-webkit-scrollbar-track { background: #e4e4e4; }
.sheet-scroll::-webkit-scrollbar-thumb {
  background: #1a5c38;
  border: 3px solid #e4e4e4;
  border-radius: 8px;
}
.scroll-hint { font-weight: 650; color: var(--ink); }
td .activity-ol { white-space: normal; margin: 0; padding-left: 1.25rem; }
td .activity-ol li { margin: 0.12rem 0; }
.activity-editor { display: grid; gap: 0.45rem; }
.activity-rows { counter-reset: act; display: grid; gap: 0.35rem; }
.activity-row { counter-increment: act; display: flex; gap: 0.4rem; align-items: center; }
.activity-num { flex: 0 0 1.6rem; color: var(--muted); font-weight: 650; }
.activity-num::before { content: counter(act) "."; }
.activity-row input { flex: 1 1 auto; }
button.tiny { padding: 0.18rem 0.45rem; font-size: 0.78rem; border-radius: 6px; }
.grid {
  border-collapse: separate;
  border-spacing: 0;
  font-family: Calibri, "Segoe UI", sans-serif;
  font-size: 13.5px;
  line-height: 1.3;
  width: max-content;
  min-width: 108rem;
}
.grid th, .grid td {
  border-right: 1px solid #d4d4d4;
  border-bottom: 1px solid #d4d4d4;
  padding: 0.28rem 0.4rem;
  vertical-align: top;
  background: #fff;
}
.grid thead th { position: sticky; z-index: 3; }
.grid thead tr.letters th {
  top: 0;
  height: 22px;
  background: #f3f3f3;
  color: #666;
  font-weight: 650;
  text-align: center;
  font-size: 12px;
  padding: 0 0.3rem;
}
.grid thead tr.names th {
  top: 22px;
  background: var(--excel);
  color: #fff;
  font-weight: 650;
  text-align: left;
  white-space: nowrap;
  border-right-color: var(--excel-dark);
  border-bottom-color: var(--excel-dark);
}
.grid th .grp {
  display: block;
  font-size: 10px;
  font-weight: 650;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  opacity: 0.8;
}
.grid .rownum {
  position: sticky;
  left: 0;
  width: 2.5rem;
  min-width: 2.5rem;
  max-width: 2.5rem;
  text-align: center;
  color: #666;
  background: #f3f3f3;
  z-index: 2;
}
.grid .c-cat {
  position: sticky;
  left: 2.5rem;
  width: 9.5rem;
  min-width: 9.5rem;
  max-width: 9.5rem;
  z-index: 2;
}
.grid thead .rownum,
.grid thead .c-cat { z-index: 5; }
.grid thead tr.names .rownum,
.grid thead tr.names .c-cat { background: var(--excel); color: #fff; }
.grid thead tr.letters .rownum,
.grid thead tr.letters .c-cat { background: #f3f3f3; color: #666; }
.c-text { min-width: 11rem; max-width: 16rem; white-space: pre-wrap; overflow-wrap: anywhere; }
.c-risk { min-width: 12rem; max-width: 16rem; }
.c-long { min-width: 13rem; max-width: 18rem; white-space: pre-wrap; overflow-wrap: anywhere; }
.c-num, .c-level { text-align: center; white-space: nowrap; font-variant-numeric: tabular-nums; }
.c-scale { text-align: left; min-width: 8.5rem; }
.scale-key {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.35rem 1.2rem;
  padding: 0.15rem 0.85rem 0.35rem;
  font-size: 0.86rem;
}
.scale-key h2 { margin: 0 0 0.2rem; font-size: 0.78rem; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); }
.scale-key ol { margin: 0; padding-left: 1.2rem; }
.scale-key li { margin: 0.12rem 0; }
.c-edit { text-align: center; white-space: nowrap; min-width: 9rem; }
.c-edit form { display: inline; margin: 0; }
.c-edit form button { margin-left: 0.25rem; }
.grid td.sc-low, .grid td.lv-accept { background: #e7f6ec; color: #146b38; font-weight: 700; }
.grid td.sc-mid, .grid td.lv-manage { background: #fff1df; color: #8a4b08; font-weight: 700; }
.grid td.sc-high { background: #fde8e6; color: #8a1c13; font-weight: 700; }
.grid td.override {
  background: #fff2cc;
  color: #6b5300;
  font-weight: 700;
  box-shadow: inset 0 0 0 2px #e0b000;
}
.grid tr.cat-break td { border-top: 2px solid #9a9a9a; }
.grid tr.is-closed td { background: #fff4d6; color: #5c5340; }
.grid tr.is-closed td.rownum { background: #f0d48a; color: #1b2430; font-weight: 700; }
.grid tr.is-closed td.c-cat { background: #fff4d6; }
.grid tr:hover td { background: #e8f2fb; }
.grid tr:hover td.rownum { background: #d5e4f2; }
.grid tr:hover td.sc-low, .grid tr:hover td.lv-accept { background: #d3f0dc; }
.grid tr:hover td.sc-mid, .grid tr:hover td.lv-manage { background: #ffe0c2; }
.grid tr:hover td.sc-high { background: #f8d0cc; }
.grid tr:hover td.override { background: #ffe58a; }
.grid tr.is-closed:hover td, .grid tr.is-closed:hover td.c-cat { background: #ffe8a3; }
.grid tr.is-closed:hover td.rownum { background: #e7c56a; }
.empty-row { text-align: center; color: var(--muted); padding: 1.2rem 0.6rem; }
.tag {
  display: inline-block;
  margin-left: 0.3rem;
  background: #e7c56a;
  color: #1b2430;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  border-radius: 999px;
  padding: 0.05rem 0.35rem;
  vertical-align: 1px;
  white-space: nowrap;
}
.sheet-note {
  margin: 0;
  padding: 0.45rem 0.85rem 0.6rem;
  color: var(--muted);
  font-size: 0.82rem;
  background: #fafafa;
  border-radius: 0 0 12px 12px;
}

.calc {
  background: #f4f7f5;
  border-radius: 10px;
  padding: 0.55rem 0.75rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.7rem 1.4rem;
}
.calc span { color: var(--muted); font-size: 0.78rem; display: block; }
.calc strong { font-size: 1.15rem; }
.override-note { color: #8a5a00; font-weight: 650; }

.log-wrap { overflow-x: auto; }
.log-table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
.log-table th, .log-table td { text-align: left; vertical-align: top; padding: 0.45rem 0.5rem; border-bottom: 1px solid var(--line); }
.log-table th { color: var(--muted); font-size: 0.78rem; letter-spacing: 0.03em; text-transform: uppercase; }
.log-table .when { white-space: nowrap; }

@media (max-width: 720px) {
  .row2 { grid-template-columns: 1fr; }
  .updated { white-space: normal; }
  .person { flex-direction: column; }
  .scale-key { grid-template-columns: 1fr; }
}

@media print {
  .top, .toolbar, .review-banner, .c-edit, .no-print { display: none !important; }
  .sheet-scroll { max-height: none; overflow: visible; }
  .grid thead th, .grid .rownum, .grid .c-cat { position: static; }
  body { background: #fff; }
  .workbook { box-shadow: none; }
}
