:root {
  --ink: #111827;
  --muted: #667085;
  --line: #d0d5dd;
  --ok: #166534;
  --ko: #b91c1c;
  --na: #475467;
  --ok-bg: #f0fdf4;
  --ko-bg: #fef2f2;
  --na-bg: #f8fafc;
  --accent: #0f766e;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  color: var(--ink);
  font-family: "Segoe UI", Tahoma, sans-serif;
  background:
    radial-gradient(circle at 10% 0%, #dbeafe 0%, transparent 35%),
    radial-gradient(circle at 90% 100%, #fde68a 0%, transparent 30%),
    linear-gradient(170deg, #f8fafc 0%, #f1f5f9 100%);
  min-height: 100vh;
}

.wrap {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px;
}

.card {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: 0 8px 18px rgba(15, 23, 42, 0.05);
}

h1 {
  margin: 0;
  color: var(--accent);
  font-size: 24px;
}

.sub {
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
}

.grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(4, minmax(120px, 1fr));
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
}

input,
textarea,
select,
button {
  font-family: inherit;
  font-size: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #fff;
}

input,
select,
button { padding: 8px 10px; }

textarea {
  width: 100%;
  min-height: 170px;
  padding: 10px;
  resize: vertical;
  line-height: 1.35;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-top: 10px;
}

button {
  cursor: pointer;
  transition: transform .08s ease, background .15s ease;
}

button:hover {
  background: #f1f5f9;
  transform: translateY(-1px);
}

.strong {
  background: #0f766e;
  border-color: #0f766e;
  color: #fff;
}

.strong:hover {
  background: #0b665f;
}

.link-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #fff;
  text-decoration: none;
  font-size: 14px;
  transition: transform .08s ease, background .15s ease;
}

.link-button:hover {
  background: #f1f5f9;
  transform: translateY(-1px);
}

.link-button.strong {
  color: #fff;
}

.stats {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.pill {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 12px;
  background: #fff;
  font-size: 13px;
}

.pill.ok { color: var(--ok); border-color: #86efac; background: var(--ok-bg); }
.pill.ko { color: var(--ko); border-color: #fca5a5; background: var(--ko-bg); }
.pill.na { color: var(--na); border-color: #cbd5e1; background: var(--na-bg); }

.rows {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.section-title {
  margin-top: 16px;
  margin-bottom: 8px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
  padding-bottom: 4px;
  font-weight: 700;
}

.row {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  display: grid;
  gap: 8px;
  grid-template-columns: 80px 44px 120px 1fr 220px auto;
  align-items: center;
  background: #fff;
}

.row.ok { border-color: #86efac; background: var(--ok-bg); }
.row.ko { border-color: #fca5a5; background: var(--ko-bg); }
.row.na { border-color: #cbd5e1; background: var(--na-bg); }

.id { font-weight: 700; color: #1d4ed8; }

.prio {
  font-size: 12px;
  text-align: center;
  border-radius: 4px;
  padding: 2px 4px;
  background: #f1f5f9;
  color: var(--muted);
}

.prio.P1 { background: #fee2e2; color: #b91c1c; }

.role {
  font-size: 12px;
  text-transform: uppercase;
  color: var(--muted);
}

.main {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.scenario { font-size: 14px; }
.steps,
.expected { font-size: 12px; color: var(--muted); }

.steps-list {
  margin: 4px 0 0 0;
  padding-left: 18px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.comment {
  width: 100%;
  padding: 6px 8px;
  background: #fff;
}

.btns {
  display: flex;
  gap: 5px;
}

.btn-res {
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 5px 9px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  opacity: .35;
}

.btn-res.sel { opacity: 1; }
.btn-ok { background: var(--ok-bg); color: var(--ok); border-color: #86efac; }
.btn-ko { background: var(--ko-bg); color: var(--ko); border-color: #fca5a5; }
.btn-na { background: var(--na-bg); color: var(--na); border-color: #cbd5e1; }

.small {
  color: var(--muted);
  font-size: 12px;
}

.biz-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: 1fr 1fr;
}

.biz-grid textarea {
  min-height: 110px;
}

.proof {
  display: none;
  grid-column: 1 / -1;
  border-top: 1px dashed var(--line);
  padding-top: 10px;
  margin-top: 2px;
  gap: 8px;
}

.proof.show {
  display: grid;
}

.proof-paste {
  border: 1px dashed #fca5a5;
  background: #fff;
  border-radius: 8px;
  padding: 10px;
  font-size: 13px;
  color: var(--ink);
  outline: none;
}

.proof-paste:focus {
  border-color: #ef4444;
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.12);
}

.proof-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.proof-preview {
  max-width: 320px;
  max-height: 200px;
  border: 1px solid var(--line);
  border-radius: 8px;
  object-fit: contain;
  background: #fff;
  display: none;
}

.proof-preview.show {
  display: block;
}

.intro-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: 1.2fr .8fr;
}

.builder-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.builder-row {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  background: #fff;
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.04);
}

.builder-row-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: 110px 90px 120px 1fr;
  margin-bottom: 10px;
}

.builder-row-grid textarea {
  min-height: 90px;
}

.builder-row-main {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: stretch;
}

.builder-row-main > label {
  border: 1px solid #d8dee8;
  border-radius: 12px;
  padding: 10px 12px;
  background: linear-gradient(180deg, #f8fafc 0%, #f1f5f9 100%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.75);
}

.builder-row-main > label > textarea {
  min-height: 220px;
  background: #fff;
  border-color: #c7d2e0;
}

.builder-row-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
}

.builder-row-index {
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: .06em;
}

.mono {
  font-family: Consolas, 'Courier New', monospace;
}

.preview-box {
  min-height: 420px;
}

.preview-box textarea {
  min-height: 420px;
}

.helper-list {
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.helper-list li + li {
  margin-top: 4px;
}

.stat-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(4, minmax(120px, 1fr));
}

.stat-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  padding: 12px;
}

.stat-card strong {
  display: block;
  font-size: 22px;
  color: var(--accent);
}

.stat-card span {
  font-size: 12px;
  color: var(--muted);
}

.modal-card {
  width: min(760px, 100%);
  max-height: calc(100vh - 48px);
  overflow: auto;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fff;
  box-shadow: 0 18px 42px rgba(15, 23, 42, 0.24);
}

.modal-card::backdrop {
  background: rgba(15, 23, 42, 0.45);
}

.modal-header,
.modal-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 20px;
}

.modal-header {
  border-bottom: 1px solid var(--line);
}

.modal-header h2 {
  margin: 0;
  color: var(--accent);
  font-size: 20px;
}

.modal-body {
  padding: 20px;
}

.modal-actions {
  border-top: 1px solid var(--line);
}

.modal-close {
  min-width: 40px;
  min-height: 40px;
  padding: 0;
  font-size: 18px;
  line-height: 1;
}

.tag-cloud {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tag {
  padding: 6px 10px;
  border: 1px solid #bfd6d3;
  border-radius: 999px;
  background: #f0fdfa;
  color: #0f766e;
  font-size: 12px;
  font-weight: 600;
}

.excel-columns-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.excel-col-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 10px 14px;
  border-radius: 10px;
  border: 2px solid;
  min-width: 100px;
  flex: 1;
}

.excel-col-required {
  border-color: var(--accent);
  background: #f0fdfa;
}

.excel-col-optional {
  border-color: var(--line);
  background: #f8fafc;
}

.excel-col-name {
  font-size: 13px;
  font-weight: 700;
  color: var(--ink);
}

.excel-col-required .excel-col-name {
  color: var(--accent);
}

.excel-col-desc {
  font-size: 11px;
  color: var(--muted);
  text-align: center;
}

.card-sticky {
  position: sticky;
  top: 8px;
  z-index: 20;
  backdrop-filter: blur(6px);
  background: rgba(255, 255, 255, 0.95);
}

/* ── Matrix view ──────────────────────────────────────────── */

.matrix-wrap {
  display: block;
  width: 100%;
  max-height: calc(100vh - 200px);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: 0 0 8px 8px;
  border: 1px solid var(--line);
  border-top: 0;
}

.matrix-scroll-top {
  width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  height: 14px;
  border: 1px solid var(--line);
  border-bottom: 0;
  border-radius: 8px 8px 0 0;
  background: #f8fafc;
}

.matrix-scroll-top-inner {
  height: 1px;
}

.matrix-table {
  width: max-content;
  min-width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  white-space: nowrap;
}

.matrix-table th,
.matrix-table td {
  border: 1px solid var(--line);
  padding: 6px 8px;
  vertical-align: middle;
}

.matrix-scenario-header {
  background: #f1f5f9;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .06em;
  min-width: 220px;
  position: sticky;
  top: 0;
  left: 0;
  z-index: 4;
  box-shadow: 2px 0 4px rgba(0,0,0,.06);
}

.matrix-role-header {
  background: var(--accent);
  color: #fff;
  text-align: center;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
  height: 38px;
  position: sticky;
  top: 0;
  z-index: 3;
}

.matrix-sub-header-cell {
  background: #f8fafc;
  color: var(--muted);
  font-size: 11px;
  text-align: center;
  font-weight: 600;
  white-space: nowrap;
  height: 30px;
  position: sticky;
  top: 38px;
  z-index: 3;
}

.matrix-section-row td {
  background: #1e293b;
  color: #fff;
  font-weight: 700;
  font-size: 12px;
  padding: 7px 10px;
  text-transform: uppercase;
  letter-spacing: .07em;
  position: sticky;
  left: 0;
  white-space: normal;
}

.matrix-scenario-cell {
  font-size: 13px;
  line-height: 1.4;
  min-width: 220px;
  max-width: 220px;
  white-space: normal;
  position: sticky;
  left: 0;
  background: #fff;
  z-index: 1;
  box-shadow: 2px 0 4px rgba(0,0,0,.06);
}

.matrix-scenario-title {
  font-weight: 600;
}

.matrix-scenario-meta {
  margin-top: 4px;
  font-size: 11px;
  color: var(--muted);
  line-height: 1.35;
}

.matrix-row:nth-child(even) .matrix-scenario-cell {
  background: #fafafa;
}

.matrix-cell {
  text-align: center;
  width: 90px;
  min-width: 90px;
  background: #fffbeb;
  vertical-align: middle;
}

.matrix-cell.ok  { background: var(--ok-bg); }
.matrix-cell.ko  { background: var(--ko-bg); }
.matrix-cell.na  { background: var(--na-bg); }
.matrix-cell.matrix-pending { background: #fffbeb; }
.matrix-cell.matrix-cell-empty  { background: #f1f5f9; color: var(--muted); font-size: 18px; }

.matrix-btns {
  display: flex;
  flex-direction: column;
  gap: 3px;
  align-items: stretch;
}

.matrix-btns .btn-res {
  font-size: 11px;
  padding: 3px 6px;
  width: 100%;
}

.matrix-comment-cell {
  min-width: 120px;
  width: 140px;
  vertical-align: middle;
}

.matrix-comment-cell.matrix-cell-empty {
  background: #f1f5f9;
}

.matrix-comment {
  width: 100%;
  padding: 4px 6px;
  font-size: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  font-family: inherit;
}

@media (max-width: 1024px) {
  .grid { grid-template-columns: 1fr 1fr; }
  .biz-grid { grid-template-columns: 1fr; }
  .row { grid-template-columns: 1fr; }
  .intro-grid { grid-template-columns: 1fr; }
  .builder-row-grid { grid-template-columns: 1fr 1fr; }
  .builder-row-main { grid-template-columns: 1fr; }
  .stat-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 640px) {
  .grid { grid-template-columns: 1fr; }
  .toolbar { flex-direction: column; align-items: stretch; }
  .toolbar button { width: 100%; }
  .toolbar .link-button { width: 100%; }
  .builder-row-grid { grid-template-columns: 1fr; }
  .builder-row-actions { flex-direction: column; align-items: stretch; }
  .stat-grid { grid-template-columns: 1fr; }
  .modal-header,
  .modal-actions,
  .modal-body { padding-left: 14px; padding-right: 14px; }
  .modal-actions { flex-direction: column; align-items: stretch; }
}
