:root {
  --bg: #fafafa;
  --fg: #171717;
  --muted: #4d4d4d;
  --faint: #808080;
  --line: rgba(0, 0, 0, 0.08);
  --card: #ffffff;
  --blue: #0068d6;
  --blue-bg: #ebf5ff;
  --red: #b42318;
  --red-bg: #fee4e2;
  --green: #067647;
  --green-bg: #ecfdf3;
  --amber: #854d0e;
  --amber-bg: #fef9c3;
  --shadow: rgba(0, 0, 0, 0.08) 0 0 0 1px, rgba(0, 0, 0, 0.04) 0 2px 2px, #fafafa 0 0 0 0;
  --shadow-hover: rgba(0, 0, 0, 0.08) 0 0 0 1px, rgba(0, 0, 0, 0.04) 0 2px 2px, rgba(0, 0, 0, 0.04) 0 8px 8px -8px;
  --font: "Geist", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "Geist Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--fg); font-family: var(--font); font-feature-settings: "liga", "tnum"; }
body { min-height: 100vh; }

.top {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 12px 28px;
  background: #fff;
  box-shadow: rgba(0,0,0,0.08) 0 0 0 1px;
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand { display: flex; gap: 10px; align-items: center; min-width: 180px; }
.mark {
  width: 10px; height: 10px; border-radius: 99px; background: #171717;
}
.brand-name { font-weight: 600; letter-spacing: -0.32px; font-size: 14px; }
.brand-sub { font-size: 11px; color: var(--faint); font-family: var(--mono); letter-spacing: 0.02em; }
.tabs { display: flex; gap: 4px; background: #fafafa; padding: 3px; border-radius: 999px; box-shadow: rgb(235,235,235) 0 0 0 1px; }
.tabs button {
  border: 0; background: transparent; color: var(--muted);
  font: 500 13px/1 var(--font); padding: 7px 14px; border-radius: 999px; cursor: pointer;
}
.tabs button.on { background: #171717; color: #fff; }
.top-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.who { font-size: 13px; color: var(--muted); }

button { font-family: inherit; }
.ghost, .primary, .tick-grid button {
  border: 0; border-radius: 6px; cursor: pointer; font: 500 13px/1 var(--font);
}
.ghost { background: #fff; color: #171717; padding: 8px 12px; box-shadow: rgb(235,235,235) 0 0 0 1px; }
.ghost:hover { background: #fafafa; }
.primary { background: #171717; color: #fff; padding: 8px 14px; }
.primary:hover { background: #000; }
.primary:disabled { opacity: 0.4; cursor: default; }

main { padding: 28px 32px 80px; max-width: 1280px; }
.view { display: none; }
.view.on { display: block; }

h1 { font-size: 24px; font-weight: 600; letter-spacing: -0.96px; margin: 0 0 4px; }
.row-head { margin-bottom: 20px; display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; }
.split { display: grid; grid-template-columns: minmax(260px, 0.9fr) minmax(360px, 1.3fr); gap: 16px; margin-top: 22px; }
.tree-panel { max-height: 640px; overflow: auto; padding: 10px 12px; font-size: 12px; }
.tn { list-style: none; margin: 0; padding: 0 0 0 12px; }
.tn.root { padding-left: 0; }
.tn > li { margin: 2px 0; }
.tn .row { display: flex; align-items: baseline; gap: 6px; padding: 3px 0; }
.tn .nm { color: var(--fg); font-weight: 500; }
.tn .meta { color: var(--faint); font-family: var(--mono); font-size: 10px; }
.tn .type { font-family: var(--mono); font-size: 10px; letter-spacing: 0.04em; text-transform: uppercase; color: var(--faint); min-width: 52px; }
.pill.sup { background: #f4f4f4; color: #808080; text-decoration: line-through; }
.pill.can { background: var(--amber-bg); color: var(--amber); }
.muted { margin: 0; color: var(--muted); font-size: 14px; }

.table-wrap {
  background: #fff; border-radius: 8px;
  box-shadow: var(--shadow); overflow: auto;
}
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; font-weight: 500; color: var(--faint); font-size: 11px; letter-spacing: 0.04em; text-transform: uppercase; font-family: var(--mono); padding: 10px 12px; }
td { padding: 12px; border-top: 1px solid #f2f2f2; vertical-align: middle; }
th.num, td.num { text-align: right; font-variant-numeric: tabular-nums; font-family: var(--mono); font-size: 12px; }
tr.pick { cursor: pointer; }
tr.pick:hover td { background: #fafafa; }
.name { font-weight: 500; }
.sub { color: var(--faint); font-size: 11px; font-family: var(--mono); }

.pill {
  display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 999px;
  font-size: 12px; font-weight: 500; line-height: 1.4;
}
.pill.blue { background: var(--blue-bg); color: var(--blue); }
.pill.red { background: var(--red-bg); color: var(--red); }
.pill.green { background: var(--green-bg); color: var(--green); }
.pill.amber { background: var(--amber-bg); color: var(--amber); }
.pill.gray { background: #f4f4f4; color: #4d4d4d; }

.filters { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 16px; }
.filters button {
  border: 0; background: #fff; color: #171717; padding: 5px 10px; border-radius: 999px;
  font: 500 12px/1.4 var(--font); cursor: pointer; box-shadow: rgb(235,235,235) 0 0 0 1px;
}
.filters button.on { background: #171717; color: #fff; box-shadow: none; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.card {
  background: #fff; border-radius: 8px; padding: 16px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 8px;
}
.card:hover { box-shadow: var(--shadow-hover); }
.card h3 { margin: 0; font-size: 15px; font-weight: 600; letter-spacing: -0.2px; }
.card p { margin: 0; color: var(--muted); font-size: 13px; }
.card .meta { font-family: var(--mono); font-size: 11px; color: var(--faint); }
.card .row { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; }

.ruler {
  display: flex; gap: 4px; margin-bottom: 22px; overflow-x: auto; padding-bottom: 4px;
}
.rung {
  flex: 1; min-width: 110px; background: #fff; border-radius: 8px; padding: 12px;
  box-shadow: var(--shadow); cursor: pointer;
}
.rung.on { box-shadow: #171717 0 0 0 1.5px; }
.rung .code { font-family: var(--mono); font-size: 11px; color: var(--faint); }
.rung .range { font-size: 13px; font-weight: 500; margin-top: 4px; }
.rung .n { font-size: 11px; color: var(--muted); margin-top: 6px; }

.pack-grid { display: grid; grid-template-columns: 1.3fr 0.9fr; gap: 20px; }
.section-label {
  font-family: var(--mono); font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--faint); margin-bottom: 8px;
}
.stack { display: flex; flex-direction: column; gap: 8px; }
.rule {
  background: #fff; border-radius: 8px; padding: 12px 14px; box-shadow: var(--shadow);
}
.rule .topr { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; }
.rule .nm { font-size: 13px; font-weight: 500; }
.rule .ast { font-family: var(--mono); font-size: 12px; color: var(--muted); margin-top: 4px; }
.rule.off { opacity: 0.45; }

.sim-layout { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.panel { background: #fff; border-radius: 8px; padding: 16px; box-shadow: var(--shadow); }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--muted); }
select, input {
  font: 500 14px/1.4 var(--font); padding: 8px 10px; border: 0; border-radius: 6px;
  box-shadow: rgb(235,235,235) 0 0 0 1px; background: #fff; color: #171717;
}
select:focus, input:focus { outline: 2px solid hsla(212,100%,48%,1); outline-offset: 1px; }
.kpi { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 14px 0; }
.kpi div { background: #fafafa; border-radius: 6px; padding: 8px 10px; }
.kpi b { display: block; font-size: 16px; letter-spacing: -0.4px; }
.kpi span { font-size: 11px; color: var(--faint); font-family: var(--mono); }
.tick-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.tick-grid button { background: #fff; color: #171717; padding: 9px 10px; box-shadow: rgb(235,235,235) 0 0 0 1px; text-align: left; }
.tick-grid button:hover { background: #fafafa; }
.row-actions { display: flex; gap: 8px; margin-top: 12px; }

.decision-card { background: #fafafa; border-radius: 8px; padding: 14px; font-size: 14px; margin-bottom: 16px; }
.decision-card.empty { color: var(--faint); }
.decision-card .act { font-weight: 600; letter-spacing: -0.3px; font-size: 18px; margin-bottom: 4px; }
.log { list-style: none; padding: 0; margin: 0; max-height: 360px; overflow: auto; }
.log li { padding: 8px 0; border-top: 1px solid #f2f2f2; font-size: 12px; }
.log time { font-family: var(--mono); color: var(--faint); margin-right: 8px; }

.chat {
  position: fixed; top: 57px; right: 0; bottom: 0; width: 380px;
  background: #fff; box-shadow: rgba(0,0,0,0.08) -1px 0 0 0; display: flex; flex-direction: column;
  z-index: 15;
}
.chat[hidden] { display: none !important; }
.chat-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px; box-shadow: rgba(0,0,0,0.06) 0 1px 0 0; }
.chat-log { flex: 1; overflow: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.bubble { max-width: 92%; padding: 8px 10px; border-radius: 8px; font-size: 13px; line-height: 1.45; white-space: pre-wrap; }
.bubble.user { align-self: flex-end; background: #171717; color: #fff; }
.bubble.assistant { align-self: flex-start; background: #f4f4f4; color: #171717; }
.chat-plan { margin: 0 16px 8px; padding: 10px; background: #ebf5ff; border-radius: 8px; font-size: 12px; }
.chat-form { display: flex; gap: 6px; padding: 10px 16px; }
.chat-form input { flex: 1; }
.hints { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 16px 16px; }
.hints button {
  border: 0; background: #fafafa; color: #4d4d4d; border-radius: 999px; padding: 4px 8px;
  font: 500 11px/1.4 var(--font); cursor: pointer; box-shadow: rgb(235,235,235) 0 0 0 1px;
}

@media (max-width: 900px) {
  .pack-grid, .sim-layout, .split { grid-template-columns: 1fr; }
  main { padding: 16px; }
  .chat { width: 100%; }
  .kpi { grid-template-columns: 1fr 1fr; }
}
