:root {
  --bg: #f5f7f9;
  --bg-glow: rgba(31, 95, 139, 0.08);
  --surface: #ffffff;
  --panel-bg: rgba(255, 255, 255, 0.96);
  --surface-soft: #eef4f1;
  --ink: #17202a;
  --muted: #5e6b78;
  --line: #d8e0e6;
  --row-line: #edf1f4;
  --field-bg: #fbfcfd;
  --field-border: #cfd8df;
  --focus-ring: rgba(31, 95, 139, 0.14);
  --blue: #1f5f8b;
  --green: #27795f;
  --amber: #a46618;
  --red: #9d3131;
  --chip: #e9f2f8;
  --status-bg: #eaf5ef;
  --status-border: #b8d5c8;
  --status-text: #1b5b46;
  --check-bg: #eef4f1;
  --check-border: #d4e3da;
  --check-text: #244737;
  --internal-bg: #fff9ef;
  --internal-border: #e0c38f;
  --recommendation-bg: #eff7f2;
  --recommendation-warn-bg: #fff6e8;
  --recommendation-danger-bg: #fbefef;
  --remove-hover-bg: #f8eaea;
  --tag-warn-bg: #fff1d8;
  --tag-ok-bg: #e7f4ec;
  --theme-track-bg: #d9e2e8;
  --theme-track-active: #244737;
  --theme-knob-bg: #ffffff;
  --shadow: 0 18px 45px rgba(30, 45, 60, 0.08);
}

body[data-theme="dark"] {
  --bg: #151715;
  --bg-glow: rgba(115, 198, 156, 0.12);
  --surface: #202620;
  --panel-bg: rgba(32, 38, 32, 0.96);
  --surface-soft: #1b2c24;
  --ink: #f1eee8;
  --muted: #b8b3a7;
  --line: #394139;
  --row-line: #303730;
  --field-bg: #171b17;
  --field-border: #485248;
  --focus-ring: rgba(127, 179, 217, 0.18);
  --blue: #7fb3d9;
  --green: #73c69c;
  --amber: #e0b060;
  --red: #ef8b8b;
  --chip: #243848;
  --status-bg: #1e332a;
  --status-border: #3f765e;
  --status-text: #a7e0bf;
  --check-bg: #1b2c24;
  --check-border: #3b5f4d;
  --check-text: #d8e8dc;
  --internal-bg: #352b1f;
  --internal-border: #7d6235;
  --recommendation-bg: #1c3026;
  --recommendation-warn-bg: #34291a;
  --recommendation-danger-bg: #351f22;
  --remove-hover-bg: #382225;
  --tag-warn-bg: #3a2d18;
  --tag-ok-bg: #1d3628;
  --theme-track-bg: #3b433e;
  --theme-track-active: #7fb3d9;
  --theme-knob-bg: #f1eee8;
  --shadow: 0 18px 45px rgba(0, 0, 0, 0.34);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  overflow-x: hidden;
  color-scheme: light;
  background:
    linear-gradient(180deg, var(--bg-glow), rgba(31, 95, 139, 0) 280px),
    var(--bg);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  line-height: 1.45;
}

body[data-theme="dark"] {
  color-scheme: dark;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(1440px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 40px;
}

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

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

.eyebrow,
.section-kicker {
  margin: 0 0 4px;
  color: var(--green);
  font-size: 0.76rem;
  font-weight: 800;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(1.55rem, 2vw, 2.15rem);
  line-height: 1.12;
}

h2 {
  font-size: 1rem;
  line-height: 1.2;
}

.status-pill {
  white-space: nowrap;
  border: 1px solid var(--status-border);
  background: var(--status-bg);
  color: var(--status-text);
  border-radius: 999px;
  padding: 8px 12px;
  font-size: 0.86rem;
  font-weight: 800;
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  border-radius: 999px;
  padding: 5px 10px 5px 6px;
  font-weight: 800;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.theme-toggle:hover {
  border-color: var(--blue);
  background: var(--chip);
}

.theme-track {
  width: 42px;
  height: 24px;
  border-radius: 999px;
  background: var(--theme-track-bg);
  padding: 3px;
  transition: background 0.15s ease;
}

.theme-knob {
  display: block;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--theme-knob-bg);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.22);
  transition: transform 0.15s ease;
}

.theme-toggle[aria-pressed="true"] .theme-track {
  background: var(--theme-track-active);
}

.theme-toggle[aria-pressed="true"] .theme-knob {
  transform: translateX(18px);
}

.theme-label {
  min-width: 34px;
  font-size: 0.82rem;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(620px, 1.25fr) minmax(360px, 0.75fr);
  gap: 16px;
  align-items: start;
}

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

.guide-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 14px;
}

.guide-item {
  border-left: 3px solid var(--line);
  padding-left: 12px;
}

.guide-item strong,
.guide-item span {
  display: block;
}

.guide-item strong {
  margin-bottom: 5px;
}

.guide-item span {
  color: var(--muted);
  font-size: 0.9rem;
}

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

.wizard-steps {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 6px;
}

.wizard-step {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  padding: 6px 12px;
  font-weight: 800;
}

.wizard-step.active {
  border-color: var(--blue);
  background: var(--chip);
  color: var(--ink);
}

.wizard-body {
  margin-top: 14px;
}

.wizard-page {
  display: none;
}

.wizard-page.active {
  display: block;
}

.context-help {
  display: grid;
  gap: 4px;
  margin-bottom: 12px;
  border: 1px solid var(--line);
  border-left: 3px solid var(--blue);
  border-radius: 8px;
  background: var(--field-bg);
  padding: 10px 12px;
}

.context-help strong {
  color: var(--ink);
  font-size: 0.9rem;
}

.context-help span {
  color: var(--muted);
  font-size: 0.88rem;
}

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

.input-panel,
.assumption-panel,
.summary-panel,
.option-panel {
  padding: 16px;
}

.input-panel {
  grid-column: 1;
}

.assumption-panel {
  grid-column: 1;
}

.summary-panel {
  grid-column: 2;
  grid-row: 1 / span 2;
  position: sticky;
  top: 16px;
}

.option-panel {
  margin-top: 16px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  align-items: center;
  justify-items: center;
  padding: 20px;
  background: rgba(12, 18, 24, 0.5);
}

.modal-backdrop[hidden] {
  display: none;
}

.modal-panel {
  width: min(780px, 100%);
  max-height: min(720px, calc(100vh - 40px));
  overflow-y: auto;
  overflow-x: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-bg);
  box-shadow: var(--shadow);
  padding: 16px;
}

.modal-grid {
  grid-template-columns: repeat(3, minmax(150px, 1fr));
}

.modal-title-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.model-picker {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: min(320px, 100%);
}

.model-picker span {
  margin: 0;
  white-space: nowrap;
}

.model-picker select {
  min-width: 180px;
  max-width: 320px;
  min-height: 34px;
  border: 1px solid var(--field-border);
  background: var(--field-bg);
  color: var(--ink);
  border-radius: 6px;
  padding: 6px 8px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 14px;
}

.primary-button {
  border-color: var(--blue);
  background: var(--chip);
  color: var(--blue);
}

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

.button-group {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.summary-heading {
  align-items: flex-start;
}

.icon-button,
.text-button {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  border-radius: 6px;
  min-height: 36px;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.icon-button {
  width: 38px;
  font-size: 1.2rem;
  font-weight: 800;
}

.text-button {
  padding: 0 12px;
  font-weight: 800;
}

.icon-button:hover,
.text-button:hover {
  border-color: var(--blue);
  background: var(--chip);
}

.add-usage-button {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  white-space: nowrap;
}

.add-usage-button span {
  font-size: 1.05rem;
}

.table-wrap {
  overflow-x: hidden;
}

table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

th {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  text-align: left;
  text-transform: uppercase;
  border-bottom: 1px solid var(--line);
  padding: 9px 7px;
  white-space: normal;
}

td {
  border-bottom: 1px solid var(--row-line);
  padding: 8px 7px;
  vertical-align: middle;
  min-width: 0;
  overflow-wrap: anywhere;
}

.profile-table input,
.profile-table select,
.field-grid input,
.field-grid select {
  width: 100%;
  min-width: 0;
  min-height: 36px;
  border: 1px solid var(--field-border);
  background: var(--field-bg);
  color: var(--ink);
  border-radius: 6px;
  padding: 7px 8px;
  outline: none;
}

.profile-table select,
.field-grid select {
  text-overflow: ellipsis;
}

.profile-table input:focus,
.profile-table select:focus,
.field-grid input:focus,
.field-grid select:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px var(--focus-ring);
}

.profile-table th:nth-child(1),
.profile-table td:nth-child(1) {
  width: 22%;
}

.profile-table td.usage-cell {
  display: table-cell;
}

.profile-table th:nth-child(2),
.profile-table td:nth-child(2),
.profile-table th:nth-child(3),
.profile-table td:nth-child(3),
.profile-table th:nth-child(4),
.profile-table td:nth-child(4),
.profile-table th:nth-child(5),
.profile-table td:nth-child(5),
.profile-table th:nth-child(6),
.profile-table td:nth-child(6),
.profile-table th:nth-child(7),
.profile-table td:nth-child(7),
.profile-table th:nth-child(8),
.profile-table td:nth-child(8) {
  width: 9%;
}

.profile-table th:nth-child(9),
.profile-table td:nth-child(9) {
  width: 42px;
}

.remove-button {
  width: 34px;
  min-height: 34px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  border-radius: 6px;
  font-size: 1.1rem;
}

.remove-button:hover {
  color: var(--red);
  background: var(--remove-hover-bg);
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(120px, 1fr));
  gap: 12px;
}

.field-grid.compact {
  grid-template-columns: repeat(4, minmax(150px, 1fr));
}

.population-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 12px;
  flex-wrap: wrap;
}

.detail-row.inline {
  min-width: 260px;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  padding: 10px 12px;
}

label span {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-top: 12px;
  padding: 11px 12px;
  border: 1px solid var(--check-border);
  background: var(--check-bg);
  border-radius: 8px;
}

.check-row input {
  width: 18px;
  height: 18px;
}

.check-row span {
  margin: 0;
  color: var(--check-text);
}

.compact-check {
  min-height: 66px;
  align-items: center;
  justify-content: flex-start;
  margin-top: 0;
}

.masked-summary {
  display: grid;
  gap: 4px;
  border: 1px solid var(--check-border);
  background: var(--check-bg);
  border-radius: 8px;
  padding: 12px 13px;
}

.masked-summary strong {
  color: var(--check-text);
  font-size: 0.98rem;
}

.masked-summary span {
  color: var(--muted);
  font-size: 0.9rem;
}

.catalog-status {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.advanced-block.masked {
  display: none;
}

.internal-field input {
  border-color: var(--internal-border);
  background: var(--internal-bg);
}

.mini-visual {
  display: grid;
  grid-template-columns: repeat(3, 12px);
  gap: 5px;
  padding-top: 4px;
}

.mini-visual span {
  display: block;
  width: 12px;
  height: 38px;
  border-radius: 3px;
  background: linear-gradient(180deg, #1f5f8b, #27795f);
}

.mini-visual span:nth-child(2) {
  height: 30px;
  margin-top: 8px;
  background: linear-gradient(180deg, #a46618, #27795f);
}

.mini-visual span:nth-child(3) {
  height: 22px;
  margin-top: 16px;
}

.recommendation {
  border-left: 4px solid var(--green);
  background: var(--recommendation-bg);
  border-radius: 6px;
  padding: 12px 13px;
  margin-bottom: 14px;
}

.recommendation strong {
  display: block;
  font-size: 1.22rem;
  line-height: 1.2;
  margin-bottom: 5px;
}

.recommendation span {
  color: var(--muted);
  font-size: 0.93rem;
}

.recommendation.warn {
  border-color: var(--amber);
  background: var(--recommendation-warn-bg);
}

.recommendation.danger {
  border-color: var(--red);
  background: var(--recommendation-danger-bg);
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.kpi {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px;
  background: var(--field-bg);
}

.kpi span {
  display: block;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 800;
  text-transform: uppercase;
  margin-bottom: 4px;
}

.kpi strong {
  font-size: 1.3rem;
}

.detail-list {
  display: grid;
  gap: 8px;
}

.detail-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  border-top: 1px solid var(--row-line);
  padding-top: 8px;
  color: var(--muted);
  font-size: 0.92rem;
}

.detail-row strong {
  color: var(--ink);
  text-align: right;
}

.option-table td {
  color: var(--muted);
}

.option-table td:first-child,
.option-table td:nth-child(3) {
  color: var(--ink);
  font-weight: 800;
}

.tag {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 2px 9px;
  background: var(--chip);
  color: var(--blue);
  font-size: 0.78rem;
  font-weight: 800;
}

.tag.warn {
  background: var(--tag-warn-bg);
  color: var(--amber);
}

.tag.ok {
  background: var(--tag-ok-bg);
  color: var(--green);
}

.help-text {
  display: inline-block;
  margin: 5px 0 2px;
  color: var(--muted);
  font-size: 0.82rem;
}

@media (max-width: 1100px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .input-panel,
  .assumption-panel,
  .summary-panel {
    grid-column: 1;
  }

  .summary-panel {
    grid-row: auto;
    position: static;
  }

  .field-grid {
    grid-template-columns: repeat(3, minmax(120px, 1fr));
  }

  .field-grid.compact {
    grid-template-columns: repeat(2, minmax(150px, 1fr));
  }

  .modal-grid {
    grid-template-columns: repeat(2, minmax(150px, 1fr));
  }

  .guide-grid {
    grid-template-columns: repeat(2, minmax(150px, 1fr));
  }
}

@media (max-width: 720px) {
  .app-shell {
    width: min(100% - 20px, 1440px);
    padding-top: 18px;
  }

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

  .topbar-actions {
    justify-content: flex-start;
  }

  .status-pill {
    display: inline-flex;
  }

  .field-grid,
  .kpi-grid {
    grid-template-columns: 1fr;
  }

  .field-grid.compact {
    grid-template-columns: 1fr;
  }

  .modal-title-row,
  .model-picker {
    align-items: stretch;
  }

  .model-picker {
    display: grid;
    gap: 5px;
    min-width: 0;
    width: 100%;
  }

  .model-picker select {
    max-width: none;
    width: 100%;
  }

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

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

  .wizard-steps {
    width: 100%;
  }

  .wizard-step {
    flex: 1;
  }

  .input-panel,
  .assumption-panel,
  .summary-panel,
  .option-panel {
    padding: 13px;
  }
}
