:root {
  --bg: #f3efe6;
  --ink: #1c2420;
  --muted: #5d675f;
  --panel: #fffdf8;
  --line: #d7d0c3;
  --accent: #0f6b5c;
  --ok: #255f3a;
  --err: #8a2f2f;
  --shadow: 0 18px 40px rgba(28, 36, 32, 0.08);
  font-family: "Segoe UI", "Helvetica Neue", sans-serif;
}

* { box-sizing: border-box; }
html, body {
  max-width: 100%;
  overflow-x: clip;
}
body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(15, 107, 92, 0.12), transparent 40%),
    linear-gradient(180deg, #ebe4d7 0%, var(--bg) 45%, #e7efe9 100%);
  min-height: 100vh;
}

.top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 253, 248, 0.7);
  backdrop-filter: blur(8px);
  gap: 0.75rem;
}

.top-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  justify-content: flex-end;
}

.account-meta {
  font-size: 0.82rem;
  color: var(--muted);
  max-width: 16rem;
}

form.inline-logout {
  display: inline;
  margin: 0;
}

button.pill-btn {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 999px;
  padding: 0.45rem 0.9rem;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
}

.row-form {
  display: inline;
  margin: 0;
}

.row-form input[type="text"],
.row-form select {
  max-width: 14rem;
}

.brand {
  margin: 0;
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.tag, .muted, .lede { color: var(--muted); }
.tag { margin: 0.15rem 0 0; font-size: 0.95rem; }

.pill {
  text-decoration: none;
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 999px;
  padding: 0.45rem 0.9rem;
  font-size: 0.9rem;
}

.wrap {
  width: min(90vw, 1400px);
  max-width: 1400px;
  margin: 1.5rem auto 3rem;
  display: grid;
  gap: 1rem;
  min-width: 0;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 1.25rem 1.4rem;
  box-shadow: var(--shadow);
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
}

h1, h2 { margin-top: 0; }
.actions {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  margin-top: 1rem;
}

button {
  background: var(--accent);
  color: white;
  border: 0;
  border-radius: 10px;
  padding: 0.7rem 1rem;
  font-weight: 600;
  cursor: pointer;
}

.upload {
  display: grid;
  gap: 0.55rem;
  padding: 1rem;
  border: 1px dashed var(--line);
  border-radius: 14px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}

th, td {
  text-align: left;
  padding: 0.55rem 0.35rem;
  border-bottom: 1px solid var(--line);
}

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0.75rem;
  margin-top: 1rem;
}

.stats div {
  padding: 0.9rem;
  border-radius: 12px;
  background: #f5faf7;
  border: 1px solid #d9e8e1;
}

.stats span {
  display: block;
  color: var(--muted);
  font-size: 0.85rem;
}

.stats strong {
  font-size: 1.2rem;
}

.banner {
  padding: 0.8rem 1rem;
  border-radius: 12px;
  margin: 0;
}
.banner.ok { background: #e5f5ea; color: var(--ok); }
.banner.err { background: #f8e8e8; color: var(--err); }

pre {
  white-space: pre-wrap;
  background: #f7f4ee;
  padding: 0.9rem;
  border-radius: 10px;
  overflow: auto;
}

.button-link {
  display: inline-block;
  background: var(--accent);
  color: white;
  text-decoration: none;
  border-radius: 10px;
  padding: 0.7rem 1rem;
  font-weight: 600;
}

.inline-form {
  display: grid;
  gap: 0.55rem;
  max-width: 420px;
}

.copy-rules-form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: end;
}

.copy-rules-form label {
  display: grid;
  gap: 0.35rem;
  flex: 1 1 16rem;
  font-size: 0.9rem;
  color: var(--muted);
}

.copy-rules-form select {
  width: 100%;
}

.copy-preview {
  margin-top: 0.85rem;
  padding: 0.85rem 1rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #f7f4ee;
}

.copy-preview[hidden] {
  display: none;
}

.copy-preview ul {
  margin: 0.35rem 0 0;
  padding-left: 1.15rem;
}

.copy-preview .copy-actions {
  margin-top: 0.75rem;
}

.cpi-panel {
  margin-top: 1rem;
  padding: 1rem 1.1rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(15, 107, 92, 0.04);
}

.cpi-panel h2 {
  font-size: 1.05rem;
  margin-bottom: 0.35rem;
}

.cpi-form {
  margin: 0.75rem 0;
}

.loan-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  align-items: end;
  margin: 0.75rem 0 0.5rem;
}

.loan-picker label {
  display: grid;
  gap: 0.3rem;
  font-size: 0.9rem;
  color: var(--muted);
  min-width: min(100%, 28rem);
  flex: 1 1 18rem;
}

.loan-picker select {
  width: 100%;
}

.loan-schedule-scroll {
  max-height: min(70vh, 720px);
}

.compact-table th,
.compact-table td {
  padding: 0.35rem 0.55rem;
}

input[type="text"], select {
  padding: 0.55rem 0.65rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
}

button.secondary {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  max-width: 100%;
}

.chip {
  background: #eef6f3;
  border: 1px solid #cfe0d9;
  border-radius: 999px;
  padding: 0.25rem 0.65rem;
  font-size: 0.85rem;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.muted-chip {
  background: #f3f1eb;
  border-color: var(--line);
  color: var(--muted);
}

.sample-frame,
.table-scroll {
  width: 100%;
  max-width: 100%;
  max-height: 280px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fbfaf6;
}

.sample-frame table,
.table-scroll table {
  width: max-content;
  min-width: 100%;
  margin: 0;
}

.sample-frame th,
.sample-frame td,
.table-scroll th,
.table-scroll td {
  white-space: nowrap;
  font-size: 0.85rem;
}

.mapping-form {
  display: grid;
  gap: 0.85rem;
  margin-top: 1rem;
}

.mapping-table select {
  min-width: 180px;
}

.user-field-opts {
  display: grid;
  gap: 0.35rem;
  min-width: 180px;
}

.user-field-opts input,
.user-field-opts select {
  width: 100%;
  min-width: 0;
}

.row-mapped-elsewhere td {
  background: #f3f8f5;
}

.req {
  color: var(--accent);
  font-size: 0.75rem;
  margin-inline-start: 0.35rem;
}

.small { font-size: 0.8rem; }

.template-form {
  display: grid;
  gap: 0.55rem;
  max-width: 520px;
}

.template-form textarea {
  padding: 0.55rem 0.65rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
  resize: vertical;
  min-height: 3.2rem;
}

.template-list {
  margin: 0 0 1rem;
  padding: 0.85rem 1rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #f8f6f0;
}

.template-list h3 {
  margin: 0 0 0.55rem;
  font-size: 1rem;
}

.template-items {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.65rem;
}

.template-items li {
  padding-bottom: 0.55rem;
  border-bottom: 1px solid var(--line);
}

.template-items li:last-child {
  padding-bottom: 0;
  border-bottom: 0;
}

.template-item-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
}

.template-item-meta {
  min-width: 0;
  flex: 1;
}

.template-delete-form {
  flex-shrink: 0;
  margin: 0;
}

.template-delete-form button {
  padding: 0.25rem 0.55rem;
  font-size: 0.85rem;
}

code {
  background: #f3f1eb;
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
}

.sticky-chrome {
  position: sticky;
  top: 0.75rem;
  z-index: 40;
  display: grid;
  gap: 1rem;
  align-self: start;
  background: var(--bg);
  padding-bottom: 0.15rem;
}

.metrics-ribbon {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0.75rem;
  padding: 1rem 1.1rem;
  background: #0f6b5c;
  color: #f4fffb;
  border-radius: 16px;
  box-shadow: 0 12px 28px rgba(28, 36, 32, 0.18);
}

.metrics-ribbon.remaining {
  background: #3c4f6b;
}

.metrics-ribbon .metric span {
  display: block;
  font-size: 0.8rem;
  opacity: 0.85;
}

.metrics-ribbon .metric strong {
  display: block;
  font-size: 1.35rem;
  margin-top: 0.2rem;
}

.metric-sub {
  display: block;
  font-style: normal;
  font-size: 0.75rem;
  opacity: 0.75;
  margin-top: 0.2rem;
}

.rule-tree {
  display: grid;
  gap: 0.75rem;
}

.rule-group {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.75rem;
  background: #fbfaf6;
  display: grid;
  gap: 0.65rem;
}

.rule-group .rule-group {
  background: #fffdf8;
}

.rule-group-head {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  font-weight: 600;
}

.rule-group-items {
  display: grid;
  gap: 0.5rem;
}

.rule-group-tools,
.rule-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.rule-toolbar {
  margin-top: 1rem;
}

.rule-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  margin: 0 0 0.85rem;
}

.rule-presets button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.rule-row {
  display: grid;
  grid-template-columns: minmax(160px, 1.4fr) minmax(90px, 0.7fr) minmax(120px, 1fr) auto;
  gap: 0.45rem;
  align-items: center;
}

.rule-row select,
.rule-row input {
  width: 100%;
  min-width: 0;
}

.flow-banner {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0.75rem 1rem;
  box-shadow: var(--shadow);
  overflow-x: auto;
  position: sticky;
  top: 0.75rem;
  z-index: 41;
  align-self: start;
}

.sticky-chrome .flow-banner {
  position: static;
}

.flow-steps {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  align-items: stretch;
  gap: 0;
  min-width: max-content;
}

.flow-step {
  display: flex;
  align-items: center;
  flex: 1 1 auto;
  min-width: 0;
}

.flow-step-inner {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  text-decoration: none;
  color: inherit;
  padding: 0.25rem 0.35rem;
  border-radius: 8px;
  max-width: 11rem;
}

a.flow-step-inner:hover {
  background: rgba(15, 107, 92, 0.06);
}

.flow-marker {
  flex-shrink: 0;
  width: 1.55rem;
  height: 1.55rem;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
  border: 2px solid var(--line);
  background: #f3f1eb;
  color: var(--muted);
}

.flow-label {
  font-size: 0.82rem;
  font-weight: 600;
  line-height: 1.2;
  color: var(--muted);
}

.flow-hint {
  display: block;
  font-style: normal;
  font-weight: 500;
  font-size: 0.7rem;
  opacity: 0.85;
}

.flow-connector {
  width: 1.25rem;
  height: 2px;
  margin: 0 0.15rem;
  background: var(--line);
  flex-shrink: 0;
}

/* Upcoming — not available yet */
.flow-upcoming .flow-marker {
  background: #eceae4;
  border-color: #cfc8bb;
  color: #9a958c;
}
.flow-upcoming .flow-label {
  color: #9a958c;
  font-weight: 500;
}

/* Todo — available, not finished */
.flow-todo .flow-marker {
  background: #fff;
  border-color: #a8b5af;
  color: var(--muted);
}
.flow-todo .flow-label {
  color: var(--ink);
  font-weight: 600;
}

/* Current — you are here */
.flow-current .flow-marker {
  background: var(--accent);
  border-color: var(--accent);
  color: #f4fffb;
}
.flow-current .flow-label {
  color: var(--accent);
  font-weight: 700;
}
.flow-current .flow-step-inner {
  background: rgba(15, 107, 92, 0.08);
}

/* Done */
.flow-done .flow-marker {
  background: #e7f3eb;
  border-color: var(--ok);
  color: var(--ok);
}
.flow-done .flow-label {
  color: var(--ok);
}
.flow-done + .flow-step .flow-connector,
.flow-step.flow-done .flow-connector {
  background: #b7d4c0;
}

/* Skipped (optional cut-off) */
.flow-skipped .flow-marker {
  background: #eef6f3;
  border-color: #7aa890;
  color: #3d6b54;
}
.flow-skipped .flow-label {
  color: #3d6b54;
}

button.danger-lite {
  color: var(--err);
  border-color: #d7b0b0;
}

.session-actions {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  white-space: nowrap;
}

.inline-delete {
  display: inline;
  margin: 0;
}

button.linkish {
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  color: var(--accent);
  cursor: pointer;
  text-decoration: underline;
}

button.linkish.danger-lite {
  color: var(--err);
}

.panel-heading-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 0.75rem;
}

.panel-heading-row h2 {
  margin: 0;
}

a.secondary-link {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
}

.lock-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 1rem;
  align-items: center;
}

.sanity-list {
  margin: 0.75rem 0 0;
  padding-left: 1.2rem;
  display: grid;
  gap: 0.55rem;
}
.sanity-list li { line-height: 1.35; }

.lock-table {
  width: 100%;
  font-size: 0.92rem;
  border-collapse: separate;
  border-spacing: 0;
}

.lock-table th,
.lock-table td {
  vertical-align: middle;
}

.table-scroll.lock-scroll {
  max-height: min(60vh, 560px);
}

.table-scroll.lock-scroll thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #f3f1eb;
  box-shadow: inset 0 -1px 0 var(--line);
}

.rule-toolbar .button-link {
  margin-left: auto;
}

.flow-step.flow-skipped .flow-marker {
  background: var(--ok-soft, #e8f5e9);
  border-color: var(--ok, #2e7d32);
  color: var(--ok, #2e7d32);
}

.stress-subnav {
  margin: 0.75rem 0 1.25rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--line);
}

.stress-subnav-steps {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.25rem;
  list-style: none;
  margin: 0;
  padding: 0;
}

.stress-subnav-steps a,
.stress-subnav-steps span {
  font-size: 0.95rem;
  text-decoration: none;
  color: var(--ink-muted, #555);
}

.stress-sub-current span {
  font-weight: 600;
  color: var(--accent, #0f6b5c);
  border-bottom: 2px solid var(--accent, #0f6b5c);
  padding-bottom: 0.15rem;
}

.stress-sub-done a {
  color: var(--ok, #2e7d32);
}

.stress-sub-skipped span {
  color: var(--ok, #2e7d32);
}

.stress-sub-upcoming span {
  opacity: 0.45;
}

.settings-json {
  width: 100%;
  max-width: 100%;
  font-family: ui-monospace, monospace;
  font-size: 0.85rem;
  margin: 0.5rem 0 1rem;
  padding: 0.75rem;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.meta-dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.35rem 1rem;
  margin: 0.5rem 0;
}

.meta-dl dt {
  font-weight: 600;
}

@media (max-width: 720px) {
  .rule-row {
    grid-template-columns: 1fr;
  }
}

.stress-mode-row {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem 1.5rem;
  margin: 0.75rem 0 1rem;
}

.stress-mode-row label {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.95rem;
}

.stress-inline {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  margin: 0.5rem 0;
}

.stress-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 0.75rem 1rem;
}

.stress-grid label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.9rem;
}

.panel-inset {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.75rem 1rem;
  margin-bottom: 0.75rem;
  background: rgba(255, 253, 248, 0.6);
}

.mult-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 0.5rem;
}

.stress-chart-wrap {
  margin-top: 1rem;
  max-width: 100%;
  overflow-x: auto;
}

.stress-chart-wrap canvas {
  max-width: 100%;
  height: auto;
}

.security-choices {
  display: grid;
  gap: 0.65rem;
  margin: 0.2rem 0 0.35rem;
  padding: 0;
  border: 0;
}

.security-choices legend {
  font-weight: 600;
  margin-bottom: 0.15rem;
}

.security-choice {
  display: flex;
  gap: 0.65rem;
  align-items: flex-start;
  padding: 0.7rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f7f4ee;
  cursor: pointer;
}

.security-choice input {
  margin-top: 0.25rem;
}

.security-choice.compact {
  padding: 0.45rem 0.6rem;
  background: transparent;
}

.security-inline {
  display: grid;
  gap: 0.5rem;
  max-width: 36rem;
  margin-top: 0.75rem;
}

