:root {
  --bg: #f5f6f3;
  --panel: #ffffff;
  --text: #202421;
  --muted: #69736f;
  --line: #d9ded8;
  --nav: #1f2f2b;
  --accent: #0f6b57;
  --warn: #f2bd42;
  --danger: #b84a4a;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  height: 100vh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
}

.topbar {
  min-height: 64px;
  background: var(--nav);
  color: #fff;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 20px;
  gap: 16px;
}

.brand { font-size: 18px; font-weight: 750; }
.subtitle { color: #cad6d1; font-size: 12px; margin-top: 2px; }

.top-status {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
  color: #e6ece9;
}

.logout-form { margin: 0; }
.logout-button {
  border-color: #9fb0aa;
  background: transparent;
  color: #eef7f4;
  padding: 5px 9px;
}

.shell {
  min-height: 0;
  height: 100%;
  display: grid;
  grid-template-columns: 230px minmax(0, 1fr);
  overflow: hidden;
}

.sidebar {
  background: #ffffff;
  border-right: 1px solid var(--line);
  padding: 16px 10px;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.nav-section {
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid #edf1ee;
}

.nav-section:last-child {
  border-bottom: 0;
}

.nav-section-title {
  color: #76837e;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
  padding: 7px 12px 5px;
}

.sidebar a {
  display: block;
  color: #26302c;
  text-decoration: none;
  padding: 8px 12px;
  border-radius: 6px;
  margin-bottom: 2px;
}

.sidebar a.active,
.sidebar a:hover {
  background: #e8f0ec;
  color: var(--accent);
}

.content {
  padding: 22px;
  min-width: 0;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.page-header {
  margin-bottom: 18px;
}

h1, h2 { margin: 0; line-height: 1.2; }
h1 { font-size: 28px; }
h2 { font-size: 17px; margin-bottom: 12px; }
p { margin: 6px 0 0; color: var(--muted); }

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.cards.compact { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }

.card, .panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
}

.card { padding: 14px; }
.card span { display: block; color: var(--muted); text-transform: capitalize; }
.card strong { display: block; font-size: 30px; margin-top: 8px; }

.panel {
  padding: 16px;
  margin-bottom: 16px;
}

.panel-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 16px;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.summary-grid div,
.metric-card {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
  background: #f8faf8;
}

.summary-grid span,
.metric-card span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 5px;
}

.summary-grid strong,
.metric-card strong {
  overflow-wrap: anywhere;
}

.section-title-row,
.stacked-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.filters {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px;
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 10px;
  margin-bottom: 14px;
}

.filters label { display: grid; gap: 4px; color: var(--muted); }
.filters input {
  width: 150px;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 7px 8px;
  color: var(--text);
}

button, .ghost-button {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  border-radius: 4px;
  padding: 8px 12px;
  text-decoration: none;
  cursor: pointer;
}

button:disabled,
.disabled-action {
  border-color: #c9d0cc;
  background: #eef1ef;
  color: #6e7974;
  cursor: not-allowed;
}

.ghost-button {
  background: #fff;
  color: var(--accent);
}

.action-strip {
  background: #fff;
  border: 1px dashed #c8d2cd;
  border-radius: 6px;
  padding: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 14px;
}

.notice {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  margin-bottom: 14px;
  font-weight: 700;
}

.notice.ok {
  background: #dceee6;
  color: #136345;
}

.notice.danger {
  background: #f4dddd;
  color: var(--danger);
}

.flag-list {
  min-width: 210px;
}

.flag-list .badge {
  margin: 0 4px 4px 0;
}

.strip-label {
  color: var(--muted);
  font-weight: 700;
  margin-right: 4px;
}

.action-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.row-actions {
  min-width: 220px;
}

.disabled-action.mini {
  padding: 4px 7px;
  font-size: 12px;
  margin: 0 4px 4px 0;
}

.table-wrap {
  overflow-x: auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
}

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

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

th {
  background: #eef2ef;
  font-size: 12px;
  text-transform: uppercase;
  color: #44514c;
}

td { line-height: 1.35; }
.empty { color: var(--muted); text-align: center; padding: 24px; }

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

.badge.ok { background: #dceee6; color: #136345; }
.badge.warning { background: var(--warn); color: #1f1a0c; }
.badge.neutral { background: #e6eaed; color: #374047; }
.badge.muted { background: #eeeeee; color: #69736f; }
.badge.danger { background: #f4dddd; color: var(--danger); }

.kv {
  display: grid;
  grid-template-columns: minmax(150px, 220px) 1fr;
  gap: 8px 12px;
  margin: 0;
}

.kv.wide {
  grid-template-columns: minmax(180px, 280px) minmax(0, 1fr);
}

.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 650; min-width: 0; overflow-wrap: anywhere; }

pre {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  background: #101817;
  color: #eef7f4;
  border-radius: 6px;
  padding: 14px;
  overflow-x: auto;
}

.file-content {
  max-height: 70vh;
  overflow: auto;
}

.path {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color: #52615b;
  margin-bottom: 12px;
}

.link-list {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.link-list a {
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 7px 10px;
  background: #f8faf8;
  text-decoration: none;
}

.contract-link {
  display: inline-flex;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  color: #52615b;
  text-decoration: none;
  border-bottom: 1px dotted #8fa099;
  margin-right: 8px;
  margin-bottom: 6px;
}

.plain-list {
  margin: 0;
  padding-left: 18px;
  color: #3a4641;
  line-height: 1.7;
}

.workflow-list {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.workflow-list li {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
  background: #fff;
}

.step-number {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 999px;
  background: #e8f0ec;
  color: var(--accent);
  font-weight: 800;
}

.danger-text { color: var(--danger); }

.inventory-tree {
  display: grid;
  gap: 10px;
}

.tree-node {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  margin-bottom: 8px;
}

.tree-node > summary {
  cursor: pointer;
  padding: 10px 12px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.tree-children {
  padding: 0 10px 10px 18px;
}

.tree-signal-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 5px;
}

.tree-signal-list li {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  padding: 6px 8px;
  border-radius: 6px;
  background: #f8faf8;
}

.tree-counts {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 4px;
  justify-content: flex-end;
}

a { color: var(--accent); }

.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
  background: var(--bg);
}

.login-card {
  width: min(420px, 100%);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 24px;
  box-shadow: 0 12px 28px rgba(31, 47, 43, 0.08);
}

.login-brand {
  color: var(--nav);
  margin-bottom: 8px;
}

.login-form {
  display: grid;
  gap: 12px;
  margin-top: 18px;
}

.login-form label {
  display: grid;
  gap: 5px;
  color: var(--muted);
}

.login-form input {
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 10px;
  font: inherit;
}

.login-error {
  margin-top: 14px;
  padding: 10px;
  border-radius: 4px;
  background: #f4dddd;
  color: var(--danger);
  font-weight: 700;
}

.login-note {
  font-size: 12px;
}

@media (max-width: 820px) {
  .topbar { align-items: flex-start; flex-direction: column; }
  .shell { grid-template-columns: 1fr; }
  .sidebar {
    display: flex;
    overflow-x: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .nav-section {
    min-width: 190px;
    border-bottom: 0;
    border-right: 1px solid var(--line);
    margin-bottom: 0;
  }
  .sidebar a { white-space: nowrap; }
  .content { padding: 16px; }
  .page-head { flex-direction: column; }
}

.tree-review-progress {display:flex;gap:8px;align-items:center;flex-wrap:wrap;font-size:12px;margin:6px 0;}
progress {max-width:100%;height:12px;accent-color:#167e66;}
.knowledge-page section { margin: 20px 0; }
.knowledge-page dl { display: grid; grid-template-columns: 180px minmax(0, 1fr); gap: 8px 16px; }
.knowledge-page dd { margin: 0; overflow-wrap: anywhere; }
.knowledge-page dt { color: #53605b; }
.knowledge-page pre { white-space: pre-wrap; overflow-wrap: anywhere; }
.knowledge-editor { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 20px; }
.knowledge-editor label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; }
.knowledge-editor textarea, .knowledge-editor input:not([type=checkbox]), .knowledge-editor select {
    width: 100%; min-width: 0; padding: 8px; border: 1px solid #cad2d0; border-radius: 4px; font: inherit;
}
.knowledge-editor textarea { resize: vertical; }
.knowledge-editor button { justify-self: start; align-self: end; }
@media (max-width: 760px) {
    .knowledge-editor { grid-template-columns: minmax(0, 1fr); }
    .knowledge-page dl { grid-template-columns: minmax(0, 1fr); }
}
