:root {
  color-scheme: light;
  --bg: #f5f6f8;
  --panel: #ffffff;
  --ink: #1f2933;
  --muted: #64748b;
  --line: #d8dee8;
  --green: #1f7a4d;
  --teal: #1f5b9c;
  --amber: #a35b00;
  --red: #b42318;
  --blue: #1d4ed8;
  --soft-green: #e9f6ee;
  --soft-amber: #fff4df;
  --soft-red: #fdecea;
  --soft-blue: #eaf1ff;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: #eff3f7;
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  line-height: 1.5;
}

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

button,
.importButton {
  border: 1px solid var(--teal);
  background: var(--teal);
  color: #fff;
  border-radius: 6px;
  min-height: 36px;
  padding: 7px 12px;
  cursor: pointer;
  white-space: nowrap;
}

button:hover,
.importButton:hover {
  filter: brightness(0.96);
}

.ghost {
  background: #fff;
  color: var(--ink);
  border-color: var(--line);
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 8;
  display: flex;
  width: 178px;
  flex-direction: column;
  background: #092f4c;
  color: #dcebf6;
}

.brand {
  display: grid;
  gap: 4px;
  padding: 26px 20px 24px;
}

.brand strong {
  color: #fff;
  font-size: 24px;
  font-weight: 850;
  letter-spacing: .08em;
  line-height: 1.15;
}

.brand span {
  color: #9fc3da;
  font-size: 11px;
  font-weight: 650;
  letter-spacing: .015em;
  white-space: nowrap;
}

.sidebar nav { display: grid; gap: 5px; padding: 0 12px; }
.sidebar a { border-radius: 4px; color: #bed3e3; padding: 11px 13px; text-decoration: none; font-size: 14px; }
.sidebar a:hover, .sidebar a.active { background: #17619b; color: #fff; }
.sidebar p { margin: auto 20px 24px; border-top: 1px solid rgba(255,255,255,.16); padding-top: 16px; color: #9fc3da; font-size: 12px; line-height: 1.8; }

.appCanvas { margin-left: 178px; min-width: 0; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 30px;
  background: #fff;
  border-bottom: 1px solid var(--line);
  text-align: left;
  box-shadow: none;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 26px;
  line-height: 1.2;
  font-weight: 800;
  color: #0f172a;
}

.topbar p { color: #789; font-size: 13px; margin-top: 4px; }
.topbarMeta { display: grid; justify-items: end; gap: 4px; color: var(--muted); font-size: 12px; }
.topbarMeta strong { color: #1f5b9c; font-size: 13px; letter-spacing: .08em; }
.topbarMeta a { margin-left: 12px; border-left: 1px solid var(--line); padding-left: 12px; color: #1f5b9c; font-weight: 700; text-decoration: none; }
.topbarMeta a:hover { text-decoration: underline; }
.adminOnly { display: none !important; }
body.adminMode .batchBar { display: flex !important; }
body.adminMode th.adminOnly { display: table-cell !important; }
body.adminMode .footerActions .adminOnly { display: inline-flex !important; }
.plainDate { color: #334155; white-space: nowrap; }
.riskLabel { border-radius: 999px; padding: 3px 8px; background: #fff1df; color: #a35b00; font-size: 11px; font-weight: 700; }

h2 {
  font-size: 18px;
}

p {
  margin: 0;
}

.actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.importButton input {
  display: none;
}

.layout {
  width: min(1540px, calc(100% - 40px));
  margin: 18px auto 32px;
}

.summary {
  display: grid;
  grid-template-columns: repeat(5, minmax(140px, 1fr));
  gap: 0;
  margin-bottom: 14px;
}

.metric,
.toolbar,
.batchBar,
.unitBoard,
.recordsPanel,
dialog {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.metric {
  padding: 12px 18px;
  min-height: 76px;
  border-radius: 0;
  border-width: 0 1px 0 0;
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.metric b {
  display: block;
  margin-top: 8px;
  font-size: 28px;
}

.metric.strong { border-left: 3px solid #1f5b9c; }
.metric.ok, .metric.auto, .metric.warning, .metric.danger { background: #fff; }
.metric.ok b { color: var(--green); }.metric.warning b { color: var(--amber); }.metric.danger b { color: var(--red); }

.insightGrid { display: grid; grid-template-columns: minmax(420px, 1.22fr) minmax(330px, .9fr) 280px; gap: 0; margin-bottom: 14px; }
.trendPanel, .attentionPanel, .overduePanel { min-width: 0; background: #fff; border: 1px solid var(--line); padding: 16px; }
.trendPanel { border-radius: 6px 0 0 6px; }.attentionPanel { border-left: 0; }.overduePanel { border-left: 0; border-radius: 0 6px 6px 0; }
.panelTitle { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.panelTitle h2 { font-size: 16px; }.eyebrow { color: #6d8395; font-size: 12px; }.panelNote { color: #7b8a98; font-size: 12px; text-align: right; }.overduePanel .panelTitle b { color: var(--red); font-size: 22px; }
#trendCanvas { display: block; width: 100%; height: 214px; }
.attentionList, .overdueQueue { display: grid; gap: 0; }.attentionItem { display: grid; grid-template-columns: 9px minmax(0, 1fr) auto; align-items: center; gap: 9px; border-top: 1px solid #edf1f4; padding: 11px 0; }.attentionItem strong, .overdueItem strong { display: block; font-size: 13px; font-weight: 600; line-height: 1.4; }.attentionItem small, .overdueItem small { display: block; color: #8492a0; font-size: 12px; margin-top: 4px; }.statusDot { width: 7px; height: 7px; border-radius: 50%; }.statusDot.overdue { background: #df3b34; }.statusDot.pending { background: #e39c20; }.textButton { min-height: auto; padding: 3px 8px; border: 1px solid #81a6c9; border-radius: 3px; background: #fff; color: #1f5b9c; font-size: 12px; }.overdueItem { border-top: 1px solid #edf1f4; padding: 11px 0; }.overdueItem > div { display: flex; justify-content: space-between; align-items: center; margin-top: 6px; }.overdueItem em { color: var(--red); font-size: 12px; font-style: normal; }.emptyState { margin: 34px 0; color: #8795a5; font-size: 13px; text-align: center; }

.toolbar {
  display: grid;
  grid-template-columns: minmax(240px, 1.6fr) repeat(6, minmax(120px, 1fr)) auto;
  gap: 9px;
  padding: 12px;
  margin-bottom: 14px;
}

.batchBar {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 12px;
  margin-bottom: 14px;
}

.batchBar strong {
  display: block;
  font-size: 15px;
}

.batchBar span {
  color: var(--muted);
  font-size: 13px;
}

.batchControls {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  align-items: center;
}

.batchControls input {
  width: 155px;
}

.batchControls button,
.rowQuickDates button {
  background: #fff;
  color: var(--ink);
  border-color: var(--line);
}

#applyBatchDate {
  background: var(--teal);
  color: #fff;
  border-color: var(--teal);
}

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

textarea {
  resize: vertical;
}

.unitBoard,
.recordsPanel {
  padding: 16px;
  margin-bottom: 14px;
}

.pageFooter {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 14px 0 4px;
  color: var(--muted);
  font-size: 13px;
}

.footerActions {
  flex-shrink: 0;
}

.sectionHead {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.sectionHead span {
  color: var(--muted);
  font-size: 13px;
}

.unitTools {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.sortButtons {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.sortButtons button {
  min-height: 30px;
  padding: 4px 9px;
  font-size: 12px;
}

.sortButtons button.active {
  background: var(--teal);
  border-color: var(--teal);
  color: #fff;
}

.unitCards { overflow: auto; border: 1px solid var(--line); border-radius: 5px; }
.unitTableHead, .unitCard { display: grid; grid-template-columns: minmax(140px, 1.5fr) repeat(4, minmax(88px, 1fr)) minmax(170px, 1.25fr); align-items: center; min-width: 880px; }
.unitTableHead { background: #edf4f9; color: #587086; font-size: 12px; font-weight: 700; }.unitTableHead span, .unitCard > * { padding: 10px 12px; }
.unitCard { width: 100%; min-height: 46px; border: 0; border-radius: 0; border-top: 1px solid #e5edf3; background: #fff; color: var(--ink); cursor: pointer; text-align: left; }.unitCard:hover, .unitCard.active { background: #f1f7fc; }.unitCard strong { font-size: 13px; }.doneValue { color: var(--green); }.doingValue { color: var(--amber); }.overdueValue { color: var(--red); }.rateCell { display: flex; gap: 8px; align-items: center; }.bar { display: inline-block; width: 88px; height: 6px; overflow: hidden; border-radius: 999px; background: #dce6ed; }.bar i { display: block; height: 100%; background: #1f5b9c; }

.tableWrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 1180px;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 10px;
  text-align: left;
  vertical-align: top;
  font-size: 13px;
}

th {
  background: #eef2f5;
}

tr:last-child td {
  border-bottom: 0;
}

.recordRow {
  --row-bg: #fff;
  --row-accent: var(--teal);
  background: var(--row-bg);
}

.recordRow td:first-child {
  border-left: 5px solid var(--row-accent);
}

.recordRow.tone0,
.groupHeader.tone0 {
  --row-bg: #f5f9ff;
  --row-accent: #2563eb;
  --group-bg: #e6f0ff;
}

.recordRow.tone1,
.groupHeader.tone1 {
  --row-bg: #f4fbf7;
  --row-accent: #15803d;
  --group-bg: #e4f5eb;
}

.recordRow.tone2,
.groupHeader.tone2 {
  --row-bg: #fffaf0;
  --row-accent: #b45309;
  --group-bg: #fff0cf;
}

.recordRow.tone3,
.groupHeader.tone3 {
  --row-bg: #f1fbfb;
  --row-accent: #0f766e;
  --group-bg: #dff6f3;
}

.recordRow.tone4,
.groupHeader.tone4 {
  --row-bg: #f8f6ff;
  --row-accent: #6d5bd0;
  --group-bg: #ece8ff;
}

.recordRow.tone5,
.groupHeader.tone5 {
  --row-bg: #fff6f6;
  --row-accent: #c2410c;
  --group-bg: #ffe8e1;
}

.groupHeader td {
  padding: 0;
  background: var(--group-bg);
  border-top: 2px solid #cbd5e1;
  border-bottom: 1px solid var(--line);
}

.groupHeaderInner {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  min-height: 40px;
  padding: 9px 12px 9px 14px;
  border-left: 5px solid var(--row-accent);
}

.groupHeaderInner strong {
  font-size: 14px;
}

.groupHeaderInner span {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.problemCell {
  max-width: 360px;
}

.measureCell {
  max-width: 300px;
  color: #334155;
}

.noteCell {
  max-width: 240px;
  color: var(--muted);
}

.sourceLine {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
}

.unitName {
  display: block;
}

.itemIndex {
  color: var(--teal);
  font-weight: 700;
}

.tag {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.tag.done {
  color: var(--green);
  background: var(--soft-green);
}

.tag.autoDone {
  color: var(--blue);
  background: var(--soft-blue);
}

.tag.doing {
  color: var(--amber);
  background: var(--soft-amber);
}

.tag.notDone {
  color: var(--red);
  background: var(--soft-red);
}

.tag.pending {
  color: #475569;
  background: #eef2f5;
}

.rowActions {
  display: grid;
  gap: 6px;
}

.rowActions button {
  width: 100%;
  min-height: 32px;
  padding: 5px 8px;
}

.rowQuickDates {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(42px, 1fr));
  gap: 4px;
  margin-top: 6px;
}

.rowQuickDates button {
  min-height: 28px;
  padding: 3px 5px;
  font-size: 12px;
}

.dangerBtn {
  background: var(--red);
  border-color: var(--red);
}

.okBtn {
  background: var(--green);
  border-color: var(--green);
}

dialog {
  width: min(760px, calc(100% - 24px));
  padding: 0;
}

dialog::backdrop {
  background: rgba(15, 23, 42, 0.35);
}

#editForm {
  padding: 16px;
}

.dialogHead {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 12px;
}

.iconBtn {
  width: 34px;
  min-height: 34px;
  padding: 0;
  border-color: var(--line);
  background: #fff;
  color: var(--ink);
  font-size: 22px;
}

.readonlyBlock {
  border: 1px solid var(--line);
  background: #f8fafc;
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 12px;
}

.readonlyBlock span {
  color: var(--muted);
  font-size: 13px;
}

.readonlyBlock strong {
  display: block;
  margin: 6px 0;
}

.readonlyBlock p {
  color: #334155;
  font-size: 13px;
  margin-top: 6px;
}

.formGrid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

label {
  color: var(--muted);
  font-size: 13px;
}

label input,
label select,
label textarea {
  margin-top: 5px;
}

.wideLabel {
  display: block;
  margin-top: 10px;
}

.manualBox {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-top: 10px;
  background: #fff;
}

.manualBox label {
  color: var(--ink);
  display: flex;
  gap: 8px;
  align-items: center;
  font-weight: 700;
}

.manualBox input {
  width: 18px;
  min-height: 18px;
  margin: 0;
}

.manualBox span {
  color: var(--muted);
  font-size: 12px;
}

.quickDates {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 10px;
  color: var(--muted);
  font-size: 13px;
}

.quickDates button {
  background: #fff;
  color: var(--ink);
  border-color: var(--line);
  min-height: 32px;
  padding: 5px 9px;
}

.dialogActions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 14px;
}

@media (max-width: 1100px) {
  .sidebar { position: static; width: 100%; min-height: auto; }.sidebar nav { display: flex; overflow: auto; }.sidebar p { display: none; }.appCanvas { margin-left: 0; }
  .summary {
    grid-template-columns: repeat(3, 1fr);
  }

  .insightGrid { grid-template-columns: 1fr 1fr; }.overduePanel { grid-column: 1 / -1; border-left: 1px solid var(--line); border-radius: 0 0 6px 6px; }.trendPanel { border-radius: 6px 0 0 0; }

  .toolbar {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .batchBar {
    align-items: flex-start;
    flex-direction: column;
  }

  .batchControls {
    justify-content: flex-start;
  }
}

@media (max-width: 720px) {
  .topbar {
    position: static;
    padding: 18px 16px;
  }

  .topbarMeta { display: none; }.insightGrid { grid-template-columns: 1fr; }.trendPanel, .attentionPanel, .overduePanel { border: 1px solid var(--line); border-radius: 6px; }.insightGrid { gap: 10px; }.overduePanel { grid-column: auto; }

  h1 {
    font-size: 26px;
  }

  .layout {
    width: min(100% - 20px, 1500px);
    margin-top: 12px;
  }

  .summary,
  .toolbar,
  .formGrid {
    grid-template-columns: 1fr;
  }

  .batchControls input,
  .batchControls button {
    width: 100%;
  }

  .manualBox,
  .sectionHead,
  .unitTools,
  .pageFooter {
    align-items: flex-start;
    flex-direction: column;
  }

  .sortButtons {
    justify-content: flex-start;
  }

  .groupHeaderInner {
    align-items: flex-start;
    flex-direction: column;
    gap: 2px;
  }
}
