:root {
  --bg: #f3f0f4;
  --surface: #ffffff;
  --surface-2: #faf8fb;
  --ink: #241023;
  --muted: #6d6270;
  --line: rgba(43, 19, 40, 0.12);
  --brand-a: #2b1328;
  --brand-b: #3a1c38;
  --accent: #f2622e;
  --accent-ink: #ffffff;
  --radius: 16px;
  --shadow: 0 10px 30px rgba(43, 19, 40, 0.10);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.4;
  padding-bottom: calc(24px + var(--safe-bottom));
}

/* ---------------------------------------------------------------- header */

.app-header {
  background: linear-gradient(135deg, var(--brand-a), var(--brand-b));
  padding: calc(10px + var(--safe-top)) 16px 12px;
  display: flex;
  justify-content: center;
}

.app-logo {
  width: min(230px, 62vw);
  height: auto;
  display: block;
}

/* ------------------------------------------------------------------ tabs */

.workflow-tabs {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  gap: 4px;
  padding: 8px 10px;
  background: rgba(243, 240, 244, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
}

.tab {
  flex: 1 0 auto;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  font-size: 0.95rem;
  font-weight: 600;
  padding: 9px 14px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}

.tab.is-active {
  background: var(--brand-a);
  color: #fff;
}

/* ------------------------------------------------------------------ main */

.app-main {
  max-width: 720px;
  margin: 0 auto;
  padding: 16px 14px;
}

.workflow-blurb {
  margin: 4px 2px 16px;
  color: var(--muted);
  font-size: 0.92rem;
}

.form-note,
.section-note {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 0.85rem;
}

.section-card,
.picker-section {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 14px 16px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}

.section-title {
  margin: 0 0 12px;
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  font-weight: 700;
}

.field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 12px;
}

.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }

.field-label {
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 600;
}

.field-control {
  display: flex;
  align-items: center;
  gap: 6px;
}

.field-control input,
.field-control select {
  width: 100%;
  min-width: 0;
  padding: 10px 11px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--surface-2);
  color: var(--ink);
  font-size: 1rem;
  font-family: inherit;
  appearance: none;
}

.field-control input:focus,
.field-control select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(242, 98, 46, 0.16);
}

.field-unit {
  flex: 0 0 auto;
  font-size: 0.78rem;
  color: var(--muted);
  white-space: nowrap;
}

/* full-width rows for selects */
.field:has(select) { grid-column: 1 / -1; }

/* --------------------------------------------------------------- buttons */

.run-button {
  position: sticky;
  bottom: calc(10px + var(--safe-bottom));
  width: 100%;
  margin-top: 4px;
  padding: 15px;
  border: none;
  border-radius: 14px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 1.05rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 8px 22px rgba(242, 98, 46, 0.32);
}

.run-button:disabled { opacity: 0.7; }

/* ---------------------------------------------------------- tool picker */

.picker-count {
  margin: 0 0 10px;
  font-size: 0.82rem;
  color: var(--muted);
  font-weight: 600;
}

.tool-list { display: flex; flex-direction: column; gap: 8px; }

.tool-item {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas: "name check" "meta check";
  align-items: center;
  gap: 0 10px;
  text-align: left;
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-2);
  cursor: pointer;
}

.tool-item.is-selected {
  border-color: var(--accent);
  background: rgba(242, 98, 46, 0.07);
}

.tool-item-name { grid-area: name; font-weight: 600; }
.tool-item-meta { grid-area: meta; font-size: 0.8rem; color: var(--muted); }
.tool-item-check {
  grid-area: check;
  width: 28px; height: 28px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--line);
  font-weight: 700;
  color: var(--muted);
}
.tool-item.is-selected .tool-item-check {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* --------------------------------------------------------------- results */

.results { margin-top: 20px; }

.results:empty { margin-top: 0; }

.results-title { margin: 6px 2px 10px; font-size: 1.25rem; }
.results-subtitle {
  margin: 20px 2px 10px;
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.score-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.score-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 8px;
  text-align: center;
  box-shadow: var(--shadow);
}

.score-card.is-big { grid-column: 1 / -1; }

.score-chip {
  display: grid;
  place-items: center;
  margin: 0 auto 6px;
  width: 54px; height: 54px;
  border-radius: 50%;
  color: #fff;
  font-size: 1.3rem;
  font-weight: 800;
}
.score-card.is-big .score-chip { width: 76px; height: 76px; font-size: 1.9rem; }
.score-chip.is-inline { width: 46px; height: 46px; margin: 0; font-size: 1.15rem; }

.score-label { font-size: 0.78rem; color: var(--muted); font-weight: 600; }

.chip-row { display: flex; flex-wrap: wrap; gap: 8px; }

.index-chip {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 12px;
  min-width: 68px;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
}
.index-value { font-size: 1.1rem; font-weight: 800; }
.index-label { font-size: 0.72rem; color: var(--muted); }

.kv-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
  box-shadow: var(--shadow);
}
.kv-table th, .kv-table td {
  padding: 11px 13px;
  text-align: left;
  font-size: 0.92rem;
  border-bottom: 1px solid var(--line);
}
.kv-table th { color: var(--muted); font-weight: 600; }
.kv-table td { text-align: right; font-variant-numeric: tabular-nums; }
.kv-table tr:last-child th, .kv-table tr:last-child td { border-bottom: none; }

.metric-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.metric-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 11px 12px;
  box-shadow: var(--shadow);
}
.metric-head { display: flex; justify-content: space-between; align-items: baseline; }
.metric-name { font-weight: 600; font-size: 0.9rem; }
.metric-value { font-size: 1.35rem; font-weight: 800; }
.metric-process { margin: 6px 0 0; font-size: 0.76rem; color: var(--muted); }

.tool-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 13px 14px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}
.tool-card-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.tool-card-title { display: flex; flex-direction: column; min-width: 0; }
.tool-card-name { font-weight: 700; }
.tool-card-sub { font-size: 0.8rem; color: var(--muted); }
.tool-card .chip-row { margin-top: 12px; }

.muted { color: var(--muted); font-size: 0.9rem; }
.muted.small { font-size: 0.8rem; margin: 12px 0 0; }
.error { color: #b3261e; font-weight: 600; background: #fdecea; border: 1px solid #f5c6c0; padding: 12px 14px; border-radius: 12px; }

/* ---------------------------------------------------------- misc / toast */

.spinner {
  width: 34px; height: 34px;
  margin: 24px auto;
  border: 3px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(80px + var(--safe-bottom));
  transform: translateX(-50%);
  background: var(--brand-a);
  color: #fff;
  padding: 11px 18px;
  border-radius: 999px;
  font-size: 0.9rem;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.25);
  z-index: 20;
  max-width: 90vw;
}

@media (min-width: 560px) {
  .score-row { grid-template-columns: repeat(4, 1fr); }
}

@media (max-width: 380px) {
  .field-grid { grid-template-columns: 1fr; }
  .score-row { grid-template-columns: repeat(2, 1fr); }
}
