:root {
  --bg: #f4f5f1;
  --surface: #ffffff;
  --surface-2: #edf1ee;
  --ink: #17211d;
  --muted: #65706a;
  --line: #d9ded8;
  --accent: #4f7f74;
  --accent-strong: #24352f;
  --gold: #d0a84f;
  --danger: #b84c4c;
  --warn: #a96d2f;
  --info: #486f93;
  --shadow: 0 18px 55px rgba(34, 45, 39, 0.1);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--bg);
  overflow-x: hidden;
}

body {
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(79, 127, 116, 0.12), rgba(244, 245, 241, 0) 240px),
    var(--bg);
  font-family: "Segoe UI", Arial, sans-serif;
  letter-spacing: 0;
  overflow-x: hidden;
}

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

button {
  cursor: pointer;
}

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

.sidebar {
  min-height: 100vh;
  padding: 18px;
  background: #24352f;
  color: #eef4ef;
  position: sticky;
  top: 0;
  align-self: start;
}

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

.brand img {
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
}

.brand-title {
  font-weight: 750;
  line-height: 1.1;
}

.brand-subtitle {
  margin-top: 3px;
  color: #b9c9c1;
  font-size: 12px;
}

.nav {
  display: grid;
  gap: 6px;
  margin: 18px 0;
}

.nav button,
.case-link,
.icon-button,
.primary-button,
.secondary-button,
.ghost-button,
.danger-button {
  min-height: 38px;
  border: 1px solid transparent;
  border-radius: 8px;
  transition: background 0.16s ease, border-color 0.16s ease, transform 0.16s ease;
}

.nav button {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 10px;
  color: #edf5f0;
  background: transparent;
  text-align: left;
}

.nav button:hover,
.nav button.active {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.18);
}

.nav-icon,
.button-icon {
  display: inline-grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.12);
  font-weight: 700;
  font-size: 12px;
}

.side-label {
  margin: 18px 0 8px;
  color: #b9c9c1;
  font-size: 12px;
  text-transform: uppercase;
}

.case-stack {
  display: grid;
  gap: 8px;
}

.case-link {
  width: 100%;
  padding: 10px;
  background: rgba(255, 255, 255, 0.08);
  color: #f7fbf8;
  text-align: left;
}

.case-link.active,
.case-link:hover {
  border-color: rgba(208, 168, 79, 0.55);
  background: rgba(208, 168, 79, 0.13);
}

.case-link-title {
  display: block;
  font-size: 13px;
  font-weight: 650;
  line-height: 1.25;
}

.case-link-meta {
  display: block;
  margin-top: 4px;
  color: #c5d2cb;
  font-size: 12px;
}

.sidebar-note {
  margin-top: 18px;
  padding: 12px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  color: #cfe0d7;
  font-size: 12px;
  line-height: 1.45;
}

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

.topbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 16px;
  align-items: start;
  margin-bottom: 18px;
}

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

.eyebrow {
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 4px;
  overflow-wrap: anywhere;
}

h1,
h2,
h3 {
  margin: 0;
  line-height: 1.16;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(26px, 4vw, 44px);
  overflow-wrap: anywhere;
}

h2 {
  font-size: 24px;
}

h3 {
  font-size: 17px;
}

p {
  margin: 0;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.top-actions,
.button-row,
.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.primary-button,
.secondary-button,
.ghost-button,
.danger-button,
.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 12px;
  white-space: nowrap;
  min-width: 0;
}

.primary-button {
  background: var(--accent-strong);
  color: #fff;
  border-color: var(--accent-strong);
}

.primary-button:hover {
  background: #1d2c27;
}

.secondary-button {
  background: var(--surface);
  color: var(--accent-strong);
  border-color: var(--line);
}

.secondary-button:hover {
  border-color: var(--accent);
}

.ghost-button {
  background: transparent;
  color: var(--accent-strong);
  border-color: transparent;
}

.ghost-button:hover {
  background: var(--surface-2);
}

.danger-button {
  background: #fff6f5;
  color: var(--danger);
  border-color: #f0cdca;
}

.icon-button {
  width: 40px;
  padding: 0;
  background: var(--surface);
  border-color: var(--line);
  color: var(--accent-strong);
}

.section {
  margin: 18px 0;
}

.grid {
  display: grid;
  gap: 14px;
}

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

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

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

.panel,
.tool-panel {
  padding: 16px;
}

.card {
  padding: 14px;
}

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

.muted {
  color: var(--muted);
  overflow-wrap: anywhere;
}

.small {
  font-size: 12px;
}

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

.kpi {
  padding: 13px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.kpi-value {
  font-size: 23px;
  font-weight: 760;
}

.kpi-label {
  color: var(--muted);
  font-size: 12px;
}

.scenario-grid,
.model-grid,
.doc-grid {
  display: grid;
  gap: 12px;
}

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

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

.scenario-card,
.model-card,
.doc-card,
.run-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}

.scenario-card {
  text-align: left;
}

.scenario-card:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
}

.card-title {
  font-weight: 720;
  margin-bottom: 6px;
}

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

.chip {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--accent-strong);
  font-size: 12px;
}

.chip.gold {
  background: #fbf2dc;
  color: #74531a;
}

.chip.warn {
  background: #fff0e3;
  color: var(--warn);
}

.chip.danger {
  background: #fff0f0;
  color: var(--danger);
}

.chip.info {
  background: #e9f1f7;
  color: var(--info);
}

.timeline {
  display: grid;
  gap: 10px;
}

.timeline-item {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr);
  gap: 10px;
}

.timeline-step {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--accent-strong);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
}

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

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

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

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

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

textarea {
  resize: vertical;
  min-height: 128px;
  line-height: 1.45;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(79, 127, 116, 0.14);
}

.result-box {
  min-height: 220px;
  padding: 14px;
  background: #18221f;
  color: #f5f9f5;
  border-radius: 8px;
  overflow: auto;
}

.result-box pre {
  margin: 0;
  white-space: pre-wrap;
  font-family: "Segoe UI", Arial, sans-serif;
  line-height: 1.48;
}

.route-line {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.route-node {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  padding: 7px 9px;
  border-radius: 8px;
  background: var(--surface-2);
  font-size: 13px;
  white-space: normal;
  overflow-wrap: anywhere;
}

.route-arrow {
  color: var(--muted);
}

.empty {
  padding: 20px;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.54);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  z-index: 20;
  max-width: min(560px, calc(100vw - 24px));
  padding: 11px 14px;
  border-radius: 8px;
  background: #17211d;
  color: #fff;
  box-shadow: var(--shadow);
}

.hidden {
  display: none !important;
}

.mobile-tabs {
  display: none;
}

@media (max-width: 1060px) {
  .app-shell {
    grid-template-columns: minmax(0, 1fr);
    width: 100vw;
    max-width: 100vw;
    overflow-x: hidden;
  }

  .sidebar {
    position: static;
    min-height: auto;
  }

  .nav,
  .case-stack,
  .side-label,
  .sidebar-note {
    display: none;
  }

  .mobile-tabs {
    position: sticky;
    bottom: 0;
    z-index: 10;
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 4px;
    padding: 8px;
    background: rgba(244, 245, 241, 0.94);
    border-top: 1px solid var(--line);
    backdrop-filter: blur(10px);
  }

  .mobile-tabs button {
    min-height: 42px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    color: var(--accent-strong);
    font-size: 12px;
  }

  .mobile-tabs button.active {
    background: var(--accent-strong);
    color: #fff;
  }
}

@media (max-width: 860px) {
  .main {
    padding: 14px;
    width: 100%;
  }

  .main h1,
  .main h2,
  .main h3,
  .main p,
  .eyebrow {
    max-width: calc(100vw - 28px);
  }

  .main p,
  .eyebrow {
    width: min(100%, 320px);
  }

  .topbar > :first-child,
  .section,
  .panel,
  .tool-panel,
  .card,
  .scenario-card,
  .model-card,
  .doc-card,
  .run-card,
  .kpi {
    width: 100%;
    max-width: calc(100vw - 28px);
  }

  .topbar,
  .grid.two,
  .grid.three,
  .scenario-grid,
  .model-grid,
  .kpi-row,
  .form-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .main {
    max-width: 100vw;
    overflow: hidden;
  }

  .top-actions {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    width: 100%;
  }

  .top-actions > * {
    min-width: 0;
    width: 100%;
    white-space: normal;
  }

  h1 {
    font-size: 24px;
    line-height: 1.18;
  }

  .panel-header {
    display: grid;
  }
}

@media (max-width: 480px) {
  .button-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    width: 100%;
  }

  .button-row > * {
    width: 100%;
    min-width: 0;
    white-space: normal;
  }

  .primary-button,
  .secondary-button,
  .ghost-button,
  .danger-button {
    justify-content: center;
  }
}
