:root {
  color-scheme: light;
  --bg: #f5f7f4;
  --panel: #ffffff;
  --panel-soft: #eef5ef;
  --panel-strong: #e4ece6;
  --ink: #18211d;
  --muted: #5f6f68;
  --subtle: #819089;
  --line: #d7e0da;
  --brand: #236457;
  --brand-strong: #17493f;
  --accent: #c46a3a;
  --accent-soft: #f5e4da;
  --warn: #b54730;
  --warn-soft: #fde9df;
  --ok: #28724f;
  --ok-soft: #e0f1e8;
  --shadow: 0 18px 50px rgba(34, 48, 42, 0.08);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  letter-spacing: 0;
}

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

button {
  cursor: pointer;
}

.shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 244px minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 24px 18px;
  border-right: 1px solid var(--line);
  background: #fbfcfa;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 28px;
}

.brand-mark {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border-radius: 8px;
  background: var(--brand);
  color: white;
  font-weight: 800;
}

.brand-title {
  margin: 0;
  font-size: 16px;
  line-height: 1.2;
}

.brand-subtitle {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 12px;
}

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

.nav-button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  min-height: 40px;
  padding: 10px 12px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  text-align: left;
}

.nav-button:hover {
  background: var(--panel-soft);
  color: var(--ink);
}

.nav-button.active {
  border-color: #bfd3ca;
  background: #e7f0ea;
  color: var(--brand-strong);
  font-weight: 700;
}

.nav-count {
  color: var(--subtle);
  font-size: 12px;
}

.sidebar-note {
  position: absolute;
  right: 18px;
  bottom: 20px;
  left: 18px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.main {
  min-width: 0;
  padding: 28px;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 22px;
}

.topbar > div {
  min-width: 0;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--brand);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 6px;
  font-size: 32px;
  line-height: 1.15;
}

h2 {
  margin-bottom: 14px;
  font-size: 20px;
  line-height: 1.2;
}

h3 {
  margin-bottom: 10px;
  font-size: 15px;
  line-height: 1.3;
}

.page-description {
  max-width: 720px;
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.6;
  overflow-wrap: anywhere;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 38px;
  padding: 9px 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--ink);
  text-decoration: none;
  white-space: nowrap;
}

.button.primary {
  border-color: var(--brand);
  background: var(--brand);
  color: white;
}

.button.warning {
  border-color: #efc6b4;
  background: var(--warn-soft);
  color: var(--warn);
}

.button.subtle {
  background: transparent;
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.tab-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.tab-button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  min-height: 36px;
  padding: 8px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--muted);
  font-weight: 700;
}

.tab-button > span:first-child {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tab-button.active {
  border-color: var(--brand);
  background: var(--brand-soft);
  color: var(--brand);
}

.tab-count {
  display: inline-grid;
  min-width: 22px;
  min-height: 22px;
  place-items: center;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--panel-strong);
  color: var(--muted);
  font-size: 12px;
}

.tab-button.active .tab-count {
  background: white;
  color: var(--brand);
}

.icon-button {
  display: inline-grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--ink);
}

.grid {
  display: grid;
  min-width: 0;
  gap: 16px;
}

.grid.metrics {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-bottom: 18px;
}

.grid.two {
  grid-template-columns: minmax(0, 1.35fr) minmax(320px, 0.65fr);
}

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

.panel,
.card {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.panel {
  padding: 18px;
}

.scroll-area {
  overflow: auto;
  overscroll-behavior: contain;
  padding-right: 4px;
}

.task-scroll {
  max-height: 340px;
}

.task-list-scroll {
  max-height: 650px;
}

.table-scroll {
  max-height: none;
  overflow: visible;
  padding-right: 0;
}

.table-scroll .table-wrap {
  max-height: 420px;
  overflow: auto;
}

.cell-detail-scroll {
  max-height: 760px;
}

.form-scroll {
  max-height: 760px;
}

.protocol-scroll {
  max-height: 720px;
  padding-right: 6px;
}

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

.panel-header h2,
.panel-header h3 {
  margin-bottom: 0;
}

.metric {
  min-height: 106px;
  padding: 16px;
}

.metric-label {
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 13px;
}

.metric-value {
  margin-bottom: 6px;
  font-size: 30px;
  font-weight: 800;
}

.metric-detail {
  color: var(--subtle);
  font-size: 12px;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-bottom: 14px;
}

.toolbar .field {
  min-width: 170px;
  flex: 1;
}

.app-notice {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  padding: 12px 14px;
  border: 1px solid #c8dacd;
  border-radius: 8px;
  background: #eff8f0;
  color: #315b41;
  font-size: 13px;
  line-height: 1.45;
}

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

.field label,
.checkbox-group legend {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

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

.select-add-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 38px;
  gap: 8px;
  align-items: center;
}

.select-add-row select {
  min-width: 0;
}

.add-option-button {
  width: 38px;
  height: 38px;
  font-size: 18px;
  font-weight: 800;
}

textarea {
  min-height: 86px;
  resize: vertical;
}

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

.form-grid .full {
  grid-column: 1 / -1;
}

.checkbox-group {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  border: 0;
}

.check-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.check-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 34px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
  color: var(--ink);
  font-size: 13px;
}

.check-pill input {
  width: 14px;
  height: 14px;
  min-height: 0;
  margin: 0;
}

.task-cell-list {
  display: grid;
  gap: 8px;
  max-height: 180px;
  overflow: auto;
  padding-right: 4px;
}

.task-cell-pill {
  display: grid;
  grid-template-columns: 16px minmax(0, 1fr);
  gap: 8px;
  align-items: start;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
}

.task-cell-pill input {
  width: 14px;
  height: 14px;
  min-height: 0;
  margin: 3px 0 0;
}

.task-cell-pill span {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.task-cell-pill strong {
  overflow-wrap: anywhere;
}

.task-cell-pill small {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.table-wrap {
  overflow: auto;
}

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

th,
td {
  padding: 12px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--panel);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  box-shadow: inset 0 -1px 0 var(--line);
}

td {
  font-size: 14px;
}

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

.link-button {
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--brand);
  font-weight: 700;
}

.stack {
  display: grid;
  gap: 12px;
}

.task-row,
.history-row,
.protocol-row,
.recipe-row,
.member-row {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
}

.task-row.overdue {
  border-color: #edc1ad;
  background: #fff6f1;
}

.task-cell-title {
  margin-bottom: 2px;
  overflow-wrap: anywhere;
  font-size: 18px;
  font-weight: 850;
  line-height: 1.25;
}

.task-action-title {
  margin-bottom: 4px;
  color: var(--brand);
  font-size: 14px;
  font-weight: 800;
}

.row-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.row-top > div {
  min-width: 0;
}

.row-title {
  margin-bottom: 3px;
  font-weight: 800;
}

.row-meta {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--panel-strong);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.badge.ok {
  background: var(--ok-soft);
  color: var(--ok);
}

.badge.warn {
  background: var(--warn-soft);
  color: var(--warn);
}

.badge.accent {
  background: var(--accent-soft);
  color: var(--accent);
}

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

.detail-item {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
}

.detail-label {
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.detail-value {
  font-weight: 800;
}

.empty {
  padding: 28px 16px;
  border: 1px dashed #b8c8bf;
  border-radius: 8px;
  background: #fbfcfa;
  color: var(--muted);
  text-align: center;
}

.mobile-nav {
  display: none;
  margin-bottom: 18px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(14, 22, 18, 0.42);
}

.modal {
  width: min(880px, 100%);
  max-height: calc(100vh - 40px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  box-shadow: 0 28px 90px rgba(0, 0, 0, 0.22);
}

.compact-modal {
  width: min(560px, 100%);
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.modal-body {
  padding: 18px;
}

.notice {
  margin-bottom: 14px;
  padding: 12px;
  border: 1px solid #c8dacd;
  border-radius: 8px;
  background: #eff8f0;
  color: #315b41;
  font-size: 13px;
  line-height: 1.55;
}

.split-preview {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.split-card {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
}

.footer {
  margin-top: 18px;
  color: var(--subtle);
  font-size: 12px;
}

pre.row-meta {
  margin: 0;
  white-space: pre-wrap;
}

.hidden {
  display: none !important;
}

@media (max-width: 1080px) {
  .grid.metrics,
  .grid.three {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .grid.two {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 780px) {
  .shell {
    display: block;
  }

  .sidebar {
    display: none;
  }

  .main {
    padding: 18px;
  }

  .mobile-nav {
    display: block;
  }

  .topbar {
    display: grid;
  }

  .topbar .page-description {
    display: none;
  }

  .actions {
    display: grid;
    justify-content: stretch;
  }

  h1 {
    font-size: 26px;
  }

  .grid.metrics,
  .grid.three,
  .form-grid,
  .detail-list {
    grid-template-columns: 1fr;
  }

  .toolbar {
    display: grid;
  }

  .toolbar .field {
    min-width: 0;
  }

  .button {
    width: 100%;
  }

  .tab-list {
    display: grid;
    grid-template-columns: 1fr;
  }

  .tab-button {
    justify-content: center;
    width: 100%;
    padding-inline: 8px;
  }

  .row-top {
    display: grid;
  }

  .modal-backdrop {
    align-items: stretch;
    padding: 10px;
  }

  .modal-header {
    display: grid;
  }

  .task-scroll,
  .task-list-scroll,
  .cell-detail-scroll,
  .form-scroll,
  .protocol-scroll {
    max-height: 70vh;
  }

  .table-scroll {
    max-height: none;
  }

  .table-scroll .table-wrap {
    max-height: 70vh;
  }
}
