@import url("https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&display=swap");
@import url("https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap");
:root {
  --green-900: #0c3823;
  --green-850: #103d27;
  --green-800: #154a30;
  --green-700: #1d5a3a;
  --green-600: #2a7048;
  --lime: #a6ce39;
  --lime-deep: #8bb22f;
  --navy: #3e5184;
  --navy-700: #33446e;
  --sage: #b7d6a3;
  --sage-deep: #9cc585;

  --page: #eceeea;
  --card: #ffffff;
  --line: #e1e5df;
  --line-soft: #eef1ed;
  --row-hover: #f4f7f3;

  --ink: #1d2922;
  --ink-2: #3c463f;
  --muted: #79837b;
  --muted-2: #9aa39b;
  --head-blue: #2d5288;

  --shadow-card: 0 1px 2px rgba(12,40,30,.04), 0 8px 28px rgba(12,40,30,.08);
  --radius: 12px;
  --radius-sm: 8px;
  --font: "Roboto", "Helvetica Neue", Helvetica, Arial, sans-serif;
  --serif: Georgia, "Times New Roman", serif;
  --nav-font: "Inter", "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: var(--page);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
#root { min-height: 100vh; }
button { font-family: inherit; cursor: pointer; }
.icon { display: inline-flex; align-items: center; justify-content: center; }
.icon svg { display: block; }

/* ============ HEADER ============ */
.app-header {
  background: var(--green-800);
  border-bottom: 3px solid var(--lime);
  position: sticky; top: 0; z-index: 40;
}
.app-header-inner {
  height: 72px;
  display: flex; align-items: center;
  padding: 0 30px;
  gap: 28px;
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand-mark { display: flex; gap: 3px; align-items: flex-end; height: 30px; }
.brand-mark i { display: block; width: 9px; border-radius: 1px; transform: skewX(-12deg); }
.brand-mark i:nth-child(1) { height: 18px; background: var(--lime); }
.brand-mark i:nth-child(2) { height: 30px; background: #fff; }
.brand-word {
  font-family: var(--serif);
  color: #fff; font-size: 25px; font-weight: 400;
  letter-spacing: 2.5px;
}
.brand-badge {
  background: var(--lime); color: var(--green-900);
  font-size: 10px; font-weight: 700; letter-spacing: .5px;
  padding: 3px 7px; border-radius: 5px; align-self: center;
}
.main-nav { display: flex; gap: 34px; margin: 0 auto; font-family: var(--nav-font); }
.nav-item {
  display: flex; align-items: center; gap: 7px;
  color: rgba(255,255,255,.9); background: none; border: 0;
  font-size: 14px; font-weight: 600; letter-spacing: 1.2px;
  padding: 8px 2px; position: relative;
}
.nav-item svg { opacity: .8; }
.nav-item.active { color: #fff; }
.nav-item.active::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: -2px;
  height: 2px; background: var(--lime); border-radius: 2px;
}
.header-tools { display: flex; align-items: center; gap: 20px; }
.tool-btn {
  background: none; border: 0; color: rgba(255,255,255,.85);
  padding: 4px; border-radius: 6px; display: inline-flex;
}
.tool-btn:hover { color: #fff; background: rgba(255,255,255,.1); }

/* ============ TOP CONTROL BAND ============ */
.control-band {
  background: var(--green-850);
  padding: 22px 0 70px;
}
.band-inner { max-width: 1640px; margin: 0 auto; padding: 0 30px; display: flex; align-items: center; gap: 16px; }
.band-pill {
  display: flex; align-items: center; gap: 10px;
  height: 48px; padding: 0 8px 0 20px;
  border-radius: 999px; white-space: nowrap;
  font-size: 15px; font-weight: 600;
}
.band-pill.light { background: #fff; color: var(--ink); padding-right: 16px; min-width: 240px; justify-content: space-between; }
.band-pill.light .label { color: var(--ink); }
.band-pill.light .pre { color: var(--muted); font-weight: 500; font-size: 12px; letter-spacing: .4px; text-transform: uppercase; }
.band-pill.ghost {
  background: rgba(255,255,255,.08); color: #fff;
  border: 1px solid rgba(255,255,255,.18); min-width: 215px; justify-content: space-between;
}
.band-pill.ghost:hover { background: rgba(255,255,255,.14); cursor: pointer; }
.circle-chev {
  width: 26px; height: 26px; border-radius: 50%;
  border: 1.5px solid rgba(255,255,255,.55);
  display: flex; align-items: center; justify-content: center; color: #fff;
}
.band-pill.light .circle-chev { border-color: rgba(0,0,0,.25); color: var(--ink-2); }
.run-btn {
  margin-left: 6px;
  height: 48px; padding: 0 34px;
  border-radius: 999px; border: 0;
  background: var(--sage); color: var(--green-900);
  font-size: 15px; font-weight: 700; letter-spacing: .3px;
  display: inline-flex; align-items: center; gap: 9px;
  transition: background .15s, transform .05s;
}
.run-btn:hover { background: var(--sage-deep); }
.run-btn:active { transform: translateY(1px); }
.run-btn.busy { background: var(--sage-deep); opacity: .85; }
.run-btn .spinner {
  width: 15px; height: 15px; border-radius: 50%;
  border: 2px solid rgba(12,56,35,.35); border-top-color: var(--green-900);
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.share-fab {
  margin-left: auto;
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--green-600); color: #fff; border: 0;
  display: inline-flex; align-items: center; justify-content: center;
}
.share-fab:hover { background: var(--green-700); }

/* ============ LAYOUT ============ */
.workspace {
  max-width: 1640px; margin: -52px auto 40px;
  padding: 0 30px;
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 22px;
  align-items: start;
}
@media (max-width: 1180px) { .workspace { grid-template-columns: 1fr; } }

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  display: flex; flex-direction: column;
  overflow: hidden;
}
.panel-h {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 22px 0;
}
.panel-title { color: var(--head-blue); font-size: 18px; font-weight: 700; letter-spacing: .2px; margin: 0; display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.panel-sub { color: var(--muted); font-size: 12.5px; margin-top: 3px; }

/* segmented toggle (Scope / Config) */
.seg {
  display: inline-flex; background: var(--line-soft);
  border-radius: 999px; padding: 4px; gap: 3px;
}
.seg button {
  border: 0; background: none; color: var(--muted);
  font-size: 13px; font-weight: 600; letter-spacing: .3px;
  padding: 7px 16px; border-radius: 999px;
  display: flex; align-items: center; gap: 7px; transition: .15s;
}
.seg button.on { background: var(--green-800); color: #fff; box-shadow: 0 1px 3px rgba(12,40,30,.2); }
.seg button:not(.on):hover { color: var(--ink); }

/* ============ SCOPE SIDE ============ */
.scope-tabs { display: flex; gap: 10px; padding: 16px 22px 14px; }
.scope-tab {
  display: flex; align-items: center; gap: 9px;
  border: 0; background: #eceef0; color: var(--ink-2);
  border-radius: 999px; padding: 8px 16px; font-size: 13.5px; font-weight: 600;
}
.scope-tab:hover { background: #e3e6e8; }
.scope-tab.on { background: var(--navy); color: #fff; }
.scope-tab .cnt {
  font-size: 11.5px; font-weight: 700; padding: 1px 8px; border-radius: 999px;
  background: rgba(0,0,0,.08); color: var(--ink-2);
}
.scope-tab.on .cnt { background: rgba(255,255,255,.22); color: #fff; }

.tree-wrap { margin: 0 22px 18px; border: 1px solid var(--line); border-radius: var(--radius-sm); overflow: hidden; display: flex; flex-direction: column; }
.tree-scroll { overflow-x: auto; overflow-y: scroll; max-height: 430px; scrollbar-gutter: stable; }
table.tree { border-collapse: collapse; width: 100%; min-width: 880px; font-size: 13px; }
.tree thead th {
  position: sticky; top: 0; z-index: 2;
  background: #f6f8f5; color: var(--ink-2);
  text-align: left; font-weight: 600; font-size: 12px;
  padding: 11px 12px; border-bottom: 1px solid var(--line);
  white-space: nowrap; vertical-align: middle;
}
.th-inner { display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.th-inner .th-tools { display: flex; gap: 6px; color: var(--muted-2); opacity: 0; transition: .12s; }
.tree thead th:hover .th-tools { opacity: 1; }
.th-tools .icon:hover { color: var(--ink); cursor: pointer; }
.col-div { border-left: 1px solid var(--line); }

.tree tbody td { padding: 0; border-bottom: 1px solid var(--line-soft); }
.tree tbody tr:hover { background: var(--row-hover); }
.row-cell { padding: 9px 12px; white-space: nowrap; color: var(--ink-2); }
.grouped-cell { display: flex; align-items: center; gap: 8px; }
.tw-toggle {
  width: 18px; height: 18px; border: 0; background: none; color: var(--muted);
  display: inline-flex; align-items: center; justify-content: center; flex: 0 0 auto;
  transition: transform .15s;
}
.tw-toggle.open { transform: rotate(90deg); }
.tw-spacer { width: 18px; flex: 0 0 auto; }
.cb {
  width: 16px; height: 16px; border: 1.5px solid #b6bfb7; border-radius: 3px;
  display: inline-flex; align-items: center; justify-content: center; flex: 0 0 auto;
  background: #fff; cursor: pointer; color: #fff;
}
.cb.checked { background: var(--green-700); border-color: var(--green-700); }
.cb.indet { background: var(--green-600); border-color: var(--green-600); }
.grp-name { font-weight: 600; color: var(--ink); }
.grp-name .cnt { color: var(--muted); font-weight: 500; margin-left: 5px; }
.leaf-name { color: var(--ink-2); }
.lvl-1 { padding-left: 14px; }
.lvl-2 { padding-left: 38px; }
.muted-cell { color: var(--muted-2); }

.tree-foot {
  display: flex; align-items: center; justify-content: space-between;
  padding: 9px 14px; border-top: 1px solid var(--line); background: #fafbf9;
  font-size: 12.5px; color: var(--muted);
}
.sel-pill { color: var(--green-700); font-weight: 600; }

/* ============ CONFIG SIDE ============ */
.config-scroll { overflow-x: hidden; overflow-y: scroll; max-height: 540px; padding: 8px 22px 22px; scrollbar-gutter: stable; }
.cfg-section { margin-top: 18px; }
.cfg-section:first-child { margin-top: 6px; }
.cfg-head {
  display: flex; align-items: center; gap: 9px;
  font-size: 13px; font-weight: 700; letter-spacing: .4px; text-transform: uppercase;
  color: var(--green-700); margin-bottom: 14px;
}
.cfg-head .bar { width: 4px; height: 15px; background: var(--lime-deep); border-radius: 2px; }

.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 16px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field.full { grid-column: 1 / -1; }
.field label { font-size: 11.5px; font-weight: 600; letter-spacing: .3px; color: var(--muted); text-transform: uppercase; }
.field label .req { color: var(--lime-deep); }
.sel, .txt {
  appearance: none; -webkit-appearance: none;
  height: 40px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: #fff; color: var(--ink); padding: 0 36px 0 13px; font-size: 14px; font-weight: 500;
  width: 100%;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%2379837b' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>");
  background-repeat: no-repeat; background-position: right 12px center;
}
.txt { background-image: none; padding-right: 13px; }
.sel:focus, .txt:focus { outline: none; border-color: var(--green-600); box-shadow: 0 0 0 3px rgba(42,112,72,.12); }
.field.disabled { opacity: .5; }
.field.disabled .sel, .field.disabled .txt { background: #f4f5f3; cursor: not-allowed; }
.field-hint { font-size: 11px; color: var(--muted-2); }

/* segmented inline control */
.iseg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius-sm); overflow: hidden; height: 40px; }
.iseg button {
  border: 0; background: #fff; color: var(--ink-2); font-size: 13px; font-weight: 600;
  padding: 0 14px; border-right: 1px solid var(--line); white-space: nowrap; flex: 1;
}
.iseg button:last-child { border-right: 0; }
.iseg button.on { background: var(--green-700); color: #fff; }
.iseg button:not(.on):hover { background: var(--row-hover); }

/* output chips */
.chip-group { margin-bottom: 14px; }
.chip-group .gl { font-size: 12px; font-weight: 700; color: var(--ink-2); margin-bottom: 9px; }
.chips { display: flex; flex-wrap: wrap; gap: 9px; }
.chip {
  border: 1.5px solid var(--line); background: #fff; color: var(--ink-2);
  border-radius: 999px; padding: 8px 15px 8px 12px; font-size: 13px; font-weight: 600;
  display: inline-flex; align-items: center; gap: 8px; transition: .12s;
}
.chip:hover { border-color: var(--green-600); }
.chip.on { background: rgba(42,112,72,.1); border-color: var(--green-600); color: var(--green-700); }
.chip .tick {
  width: 16px; height: 16px; border-radius: 50%; border: 1.5px solid #c2cbc3;
  display: inline-flex; align-items: center; justify-content: center; color: #fff;
}
.chip.on .tick { background: var(--green-600); border-color: var(--green-600); }

/* risk analysis checks */
.check-list { display: grid; grid-template-columns: 1fr 1fr; gap: 11px; }
.check-row {
  display: flex; align-items: center; gap: 11px; padding: 11px 13px;
  border: 1px solid var(--line); border-radius: var(--radius-sm); background: #fff;
  font-size: 13.5px; font-weight: 600; color: var(--ink-2); transition: .12s;
}
.check-row:hover { border-color: var(--green-600); background: var(--row-hover); }
.check-row.on { border-color: var(--green-600); background: rgba(42,112,72,.07); color: var(--green-700); }

/* ============ RIGHT PANEL ============ */
.rtabs { display: flex; gap: 4px; padding: 14px 22px 0; border-bottom: 1px solid var(--line); }
.rtab {
  border: 0; background: none; color: var(--muted); font-size: 14px; font-weight: 600;
  padding: 11px 16px; border-bottom: 2.5px solid transparent; margin-bottom: -1px;
  display: flex; align-items: center; gap: 8px;
}
.rtab:hover { color: var(--ink); }
.rtab.on { color: var(--head-blue); border-bottom-color: var(--head-blue); }
.rtab .badge { background: var(--green-700); color: #fff; font-size: 10.5px; font-weight: 700; padding: 1px 7px; border-radius: 999px; }
.rtab .badge.idle { background: #e3e6e1; color: var(--muted); }

.rbody { padding: 20px 22px 24px; overflow: auto; max-height: 560px; scrollbar-gutter: stable; }

/* config summary */
.sum-block { border: 1px solid var(--line); border-radius: var(--radius-sm); margin-bottom: 16px; overflow: hidden; transition: .15s; }
.sum-block.active { border-color: var(--green-600); box-shadow: 0 0 0 3px rgba(42,112,72,.08); }
.sum-bh {
  display: flex; align-items: center; justify-content: space-between;
  padding: 13px 16px; background: #f6f8f5; border-bottom: 1px solid var(--line);
}
.sum-bh .t { font-size: 13.5px; font-weight: 700; color: var(--ink); display: flex; align-items: center; gap: 9px; }
.sum-bh .live { font-size: 10.5px; font-weight: 700; letter-spacing: .5px; color: var(--green-700); background: rgba(42,112,72,.12); padding: 3px 9px; border-radius: 999px; text-transform: uppercase; }
.sum-body { padding: 14px 16px; }
.dl { display: grid; grid-template-columns: auto 1fr; gap: 9px 18px; font-size: 13px; }
.dl dt { color: var(--muted); font-weight: 500; }
.dl dd { margin: 0; color: var(--ink); font-weight: 600; text-align: right; }
.tag-row { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 4px; }
.tag { font-size: 12px; font-weight: 600; color: var(--green-700); background: rgba(42,112,72,.1); border-radius: 6px; padding: 4px 9px; }
.tag.none { color: var(--muted-2); background: #f0f2ef; }
.sum-sub { font-size: 11px; font-weight: 700; letter-spacing: .4px; text-transform: uppercase; color: var(--muted); margin: 14px 0 7px; }
.sum-sub:first-child { margin-top: 0; }

.scope-sum-list { display: flex; flex-direction: column; gap: 7px; }
.scope-sum-item { display: flex; align-items: center; justify-content: space-between; font-size: 13px; padding: 8px 11px; background: #f7f9f6; border-radius: 6px; }
.scope-sum-item .nm { font-weight: 600; color: var(--ink); }
.scope-sum-item .ct { color: var(--muted); font-size: 12px; }

/* output table */
.out-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.out-title { color: var(--head-blue); font-size: 17px; font-weight: 700; display: flex; align-items: center; gap: 7px; }
.out-meta { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.out-meta .m { font-size: 11.5px; font-weight: 600; color: var(--ink-2); background: #f1f3ef; border: 1px solid var(--line); border-radius: 6px; padding: 5px 10px; }
.out-meta .m b { color: var(--green-700); }
.otable-wrap { border: 1px solid var(--line); border-radius: var(--radius-sm); overflow: auto; }
table.otable { border-collapse: collapse; width: 100%; min-width: 720px; font-size: 12.5px; }
.otable thead th {
  position: sticky; top: 0; background: #f6f8f5; color: var(--ink-2);
  text-align: left; font-weight: 600; font-size: 11.5px; padding: 10px 12px;
  border-bottom: 1px solid var(--line); white-space: nowrap;
}
.otable thead th.num, .otable td.num { text-align: right; }
.otable td { padding: 10px 12px; border-bottom: 1px solid var(--line-soft); color: var(--ink-2); white-space: nowrap; }
.otable tbody tr:hover { background: var(--row-hover); }
.otable td.strong { font-weight: 700; color: var(--ink); }
.pill-type { display: inline-block; font-size: 11px; font-weight: 600; padding: 2px 9px; border-radius: 999px; }
.pt-market { background: #e8f1ff; color: #2d5288; }
.pt-credit { background: #fdeede; color: #9a6312; }
.pt-liq { background: #eae6fb; color: #5b46a8; }
.pt-op { background: #fde8ea; color: #a83246; }

/* empty state */
.empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 60px 24px; color: var(--muted);
  border: 1.5px dashed var(--line); border-radius: var(--radius-sm);
}
.empty .ring { width: 56px; height: 56px; border-radius: 50%; background: #f1f3ef; display: flex; align-items: center; justify-content: center; color: var(--muted-2); margin-bottom: 14px; }
.empty h4 { margin: 0 0 5px; color: var(--ink-2); font-size: 15px; }
.empty p { margin: 0; font-size: 13px; max-width: 280px; }
.empty .hint-run { margin-top: 4px; color: var(--green-700); font-weight: 600; }

.fade-in { animation: fade .22s ease both; }
@media (prefers-reduced-motion: no-preference) {
  @keyframes fade { from { transform: translateY(5px); } to { transform: none; } }
}
@media (prefers-reduced-motion: reduce) {
  @keyframes fade { from { transform: none; } to { transform: none; } }
}

/* ===== Viewport-fill app shell (two-column width only) ===== */
@media (min-width: 1181px) {
  html, body { height: 100%; }
  #root { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }
  .control-band { flex: 0 0 auto; }
  .workspace {
    flex: 1 1 auto; min-height: 0; width: 100%;
    margin: -52px auto 0; padding-bottom: 22px;
    grid-template-rows: minmax(0, 1fr); align-items: stretch;
  }
  .card { height: 100%; min-height: 0 !important; }
  .card > .fade-in { flex: 1; min-height: 0; display: flex; flex-direction: column; }
  .card > .config-scroll { flex: 1; min-height: 0; max-height: none; }
  .tree-wrap { flex: 1; min-height: 0; }
  .tree-scroll { flex: 1; min-height: 0; max-height: none; }
  .rbody { flex: 1; min-height: 0; max-height: none; }
}
