:root {
  --bg: #eef2f6;
  --surface: #ffffff;
  --surface-soft: #f7f9fc;
  --ink: #17202f;
  --muted: #647084;
  --line: #dbe2ea;
  --blue: #2255a4;
  --blue-strong: #183f7f;
  --green: #13795b;
  --amber: #b66a00;
  --red: #b42318;
  --shadow: 0 18px 45px rgba(24, 38, 62, 0.12);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: linear-gradient(135deg, rgba(34, 85, 164, 0.08), transparent 42%), var(--bg);
  font-family: "Segoe UI", Arial, sans-serif;
}
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
svg {
  width: 1.1rem;
  height: 1.1rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.app-shell {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  min-height: 100vh;
}
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 28px;
  color: #f8fbff;
  background: #17202f;
  display: flex;
  flex-direction: column;
  gap: 32px;
}
.brand { display: flex; gap: 14px; align-items: center; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 8px;
  color: #ffffff;
  background: var(--green);
}
.brand-mark svg { width: 28px; height: 28px; }
.brand h1, .topbar h2, .topbar p, .panel h3 { margin: 0; }
.brand h1 { font-size: 1.15rem; }
.brand-site-link {
  display: inline-block;
  margin-top: 4px;
  color: #b8c3d2;
  font-size: 0.88rem;
  text-decoration: none;
}
.brand-site-link:hover,
.brand-site-link:focus-visible { color: #ffffff; text-decoration: underline; }
.step-list { display: grid; gap: 8px; }
.step-link {
  color: #d8e1ed;
  text-decoration: none;
  padding: 11px 12px;
  border-radius: 8px;
}
.step-link:hover, .step-link.active { background: rgba(255, 255, 255, 0.12); color: #ffffff; }
.status-panel {
  margin-top: auto;
  padding: 16px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
}
.status-label { color: #c8d3e1; font-size: 0.82rem; }
.progress-track {
  height: 8px;
  margin: 12px 0 8px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.18);
}
.progress-track span {
  display: block;
  width: 0;
  height: 100%;
  background: #4bb58f;
  transition: width 180ms ease;
}

.workspace { min-width: 0; padding: 28px; }
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  margin-bottom: 22px;
}
.eyebrow {
  color: var(--blue);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}
.topbar h2 { max-width: 780px; margin-top: 5px; font-size: clamp(1.35rem, 2.2vw, 2.2rem); line-height: 1.12; }
.topbar-actions { display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.language-selector {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 800;
}
.language-selector select {
  min-width: 142px;
  min-height: 42px;
  padding: 8px 34px 8px 11px;
  color: var(--ink);
  background: var(--surface);
  font-weight: 700;
}
.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(23, 32, 47, 0.42);
  backdrop-filter: blur(3px);
}
.loading-overlay[hidden] { display: none; }
.loading-card {
  min-width: 180px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 18px 22px;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--blue-strong);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.loading-spinner {
  width: 22px;
  height: 22px;
  border: 3px solid #d8e3f3;
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: loading-spin 700ms linear infinite;
}
@keyframes loading-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .loading-spinner { animation: none; } }

.analysis-stage {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: -2px 0 16px;
  padding: 12px 14px;
  border: 1px solid #bfd2ef;
  border-radius: 8px;
  color: var(--blue-strong);
  background: #f2f7ff;
  font-weight: 750;
}
.analysis-stage[hidden] { display: none; }
.analysis-stage .loading-spinner { width: 18px; height: 18px; border-width: 2px; flex: 0 0 auto; }
.analysis-stage[data-state="warning"] {
  border-color: #e9c98f;
  color: #85520a;
  background: #fff8e8;
}
.analysis-stage[data-state="warning"] .loading-spinner { display: none; }

.analysis-grid { display: grid; grid-template-columns: 1fr; gap: 18px; }
.panel {
  min-width: 0;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.panel-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}
.panel-heading > div { display: flex; gap: 12px; align-items: center; }
.result-heading-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}
.section-number {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  color: var(--blue);
  background: #e8eef8;
  font-weight: 800;
  font-size: 0.78rem;
}
.badge {
  flex: 0 0 auto;
  padding: 6px 9px;
  border-radius: 999px;
  color: var(--green);
  background: #e7f5ef;
  font-size: 0.78rem;
  font-weight: 700;
}
.badge.muted { color: var(--muted); background: #eef2f6; }
.field-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}
.expanded-detail-fields {
  display: grid;
  gap: 14px;
  margin-top: 16px;
}
.stacked-detail-field textarea { min-height: 108px; }
label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 650;
}
input, select, textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid #cdd6e1;
  border-radius: 8px;
  padding: 11px 12px;
  color: var(--ink);
  background: #ffffff;
  outline: none;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(34, 85, 164, 0.14);
}
.stacked { margin-top: 16px; }

.primary-button, .ghost-button, .icon-button {
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform 140ms ease, background 140ms ease, border-color 140ms ease;
}
.primary-button { padding: 0 18px; color: #ffffff; background: var(--blue); }
.primary-button:hover { background: var(--blue-strong); }
.ghost-button, .icon-button { color: var(--ink); background: var(--surface); border-color: var(--line); }
.ghost-button { padding: 0 12px; }
.icon-button { width: 42px; }
.ghost-button:hover, .icon-button:hover { border-color: #b7c2d0; background: #f3f6fa; }
.primary-button:active, .ghost-button:active, .icon-button:active { transform: translateY(1px); }
.primary-button:disabled, .ghost-button:disabled { cursor: not-allowed; opacity: 0.62; }
.flow-actions, .report-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.report-actions { padding-top: 18px; border-top: 1px solid var(--line); }

.activity-list-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 20px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}
.activity-list-heading > div {
  display: flex;
  gap: 12px;
  align-items: center;
}
.attachment-area { margin-top: 14px; }
.attachment-dropzone {
  min-height: 180px;
  padding: 24px;
  border: 2px dashed #a9bdd7;
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-align: center;
  color: var(--muted);
  background: #f7faff;
  cursor: pointer;
  transition: border-color 140ms ease, background 140ms ease, transform 140ms ease;
}
.attachment-dropzone:hover,
.attachment-dropzone.dragging {
  border-color: var(--blue);
  background: #edf4ff;
}
.attachment-dropzone.dragging { transform: translateY(-1px); }
.attachment-dropzone svg {
  width: 34px;
  height: 34px;
  fill: none;
  stroke: var(--blue);
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.attachment-dropzone strong { color: var(--ink); font-size: 1rem; }
.attachment-dropzone > span:not(.attachment-button) { max-width: 620px; line-height: 1.45; }
.attachment-dropzone input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  clip-path: inset(50%);
}
.attachment-button {
  margin-top: 6px;
  padding: 9px 14px;
  border-radius: 8px;
  color: #ffffff;
  background: var(--blue);
  font-weight: 700;
}
.attachment-help { margin: 9px 0 0; color: var(--muted); font-size: 0.8rem; }
.attachment-error { min-height: 20px; margin-top: 4px; color: var(--red); font-size: 0.84rem; font-weight: 700; }
.attachment-list { display: grid; gap: 8px; margin: 4px 0 0; padding: 0; list-style: none; }
.attachment-item {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface-soft);
}
.attachment-item svg {
  width: 20px;
  height: 20px;
  flex: 0 0 auto;
  fill: none;
  stroke: var(--blue);
  stroke-width: 1.8;
}
.attachment-item-info { min-width: 0; flex: 1 1 auto; }
.attachment-item-info strong,
.attachment-item-info span { display: block; }
.attachment-item-info strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attachment-item-info span { margin-top: 2px; color: var(--muted); font-size: 0.78rem; }
.remove-attachment {
  width: 34px;
  height: 34px;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--muted);
  background: transparent;
}
.remove-attachment:hover { color: var(--red); background: #fff0ee; }
.detected-activities {
  margin: 14px 0 16px;
  padding: 14px 16px;
  border: 1px solid #c9d8ea;
  border-radius: 8px;
  background: #f7faff;
}
.detected-activities h4 { margin: 0 0 10px; color: var(--blue-strong); }
.detected-activities ol { margin: 0; padding-left: 22px; }
.detected-activities li + li { margin-top: 8px; }
.detected-activities span { display: block; margin-top: 2px; color: var(--muted); font-size: 0.84rem; }

.risk-map-table {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}
.risk-map-table table {
  width: 100%;
  min-width: 1180px;
  border-collapse: collapse;
}
.risk-map-table th,
.risk-map-table td {
  width: 16.666%;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 9px 10px;
  text-align: center;
  vertical-align: top;
  font-size: 0.84rem;
}
.risk-map-table th {
  color: #ffffff;
  font-weight: 900;
  text-transform: uppercase;
}
.risk-map-table td {
  background: #fafbfc;
}
.risk-map-table th:last-child,
.risk-map-table td:last-child {
  border-right: 0;
}
.risk-map-table tr:last-child td {
  border-bottom: 0;
}
.risk-group-green { background: #16803c; }
.risk-group-red { background: #d82121; }
.risk-group-brown { background: #7b2d26; }
.risk-group-yellow { background: #f1d100; color: #17202f !important; }
.risk-group-purple { background: #7c3aa8; }
.risk-group-blue { background: #244fce; }
.table-guide {
  margin-top: 16px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfe;
}
.table-guide p {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 0.9rem;
}
.table-guide dl {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px 14px;
  margin: 0;
}
.table-guide dl > div {
  display: grid;
  gap: 3px;
  min-width: 0;
}
.table-guide dt {
  color: var(--blue-strong);
  font-weight: 800;
  font-size: 0.84rem;
}
.table-guide dd {
  margin: 0;
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.35;
}
.risk-criteria {
  margin-top: 16px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}
.risk-criteria h4,
.criteria-card h5,
.risk-matrix-block h5 {
  margin: 0;
}
.risk-criteria > p,
.risk-matrix-block p {
  margin: 8px 0 14px;
  color: var(--muted);
  font-size: 0.9rem;
}
.criteria-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}
.criteria-card {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}
.criteria-card h5,
.risk-matrix-block h5 {
  color: var(--blue-strong);
  font-size: 0.92rem;
}
.criteria-card ul {
  display: grid;
  gap: 8px;
  margin: 10px 0 0;
  padding: 0;
  list-style: none;
}
.criteria-card li {
  display: grid;
  gap: 2px;
}
.criteria-card strong {
  color: var(--ink);
  font-size: 0.82rem;
}
.criteria-card span {
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.32;
}
.risk-matrix-block {
  margin-top: 14px;
}
.risk-matrix {
  width: 100%;
  border-collapse: collapse;
  overflow: hidden;
  border-radius: 8px;
  font-size: 0.84rem;
}
.risk-matrix th,
.risk-matrix td {
  border: 1px solid var(--line);
  padding: 8px 10px;
  text-align: center;
}
.risk-matrix th {
  color: var(--blue-strong);
  background: #eef4ff;
}
.matrix-Low {
  color: var(--green);
  background: #e7f5ef;
  font-weight: 800;
}
.matrix-Medium {
  color: var(--amber);
  background: #fff6e8;
  font-weight: 800;
}
.matrix-High,
.matrix-Critical {
  color: var(--red);
  background: #fff0ee;
  font-weight: 800;
}
.summary-box {
  min-height: auto;
  margin-bottom: 16px;
  place-items: start;
  text-align: left;
}
.empty-state {
  min-height: 120px;
  display: grid;
  place-items: center;
  padding: 22px;
  border: 1px dashed #bac6d4;
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
  background: var(--surface-soft);
}
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; }
.risk-table { width: 100%; min-width: 1680px; border-collapse: collapse; background: #ffffff; }
.risk-table th, .risk-table td {
  border-bottom: 1px solid var(--line);
  border-right: 1px solid var(--line);
  padding: 10px 11px;
  vertical-align: top;
  text-align: left;
  font-size: 0.86rem;
}
.risk-table th {
  position: sticky;
  top: 0;
  color: var(--blue-strong);
  background: #eef4ff;
  font-size: 0.78rem;
  text-transform: uppercase;
}
.risk-table tr:last-child td { border-bottom: 0; }
.risk-table th:last-child, .risk-table td:last-child { border-right: 0; }
.risk-table td:first-child { color: var(--blue-strong); font-weight: 800; }
.action-column,
.row-action-cell {
  width: 72px;
  min-width: 72px;
  text-align: center !important;
}
.remove-row-button {
  width: 32px;
  height: 32px;
  display: inline-grid;
  place-items: center;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--muted);
  background: transparent;
}
.remove-row-button:hover {
  color: var(--red);
  background: #fff0ee;
}
.editable-cell {
  cursor: text;
}
.editable-cell:focus {
  outline: 2px solid rgba(34, 85, 164, 0.35);
  outline-offset: -2px;
  background: #fffdf4;
}
.risk-select-cell { min-width: 78px; }
.risk-rating-select {
  min-width: 64px;
  padding: 6px 8px;
  border-radius: 6px;
  font-weight: 800;
}
.risk-grade-cell { min-width: 90px; font-weight: 800; }
.risk-rating { display: inline-flex; padding: 4px 8px; border-radius: 999px; font-weight: 800; }
.risk-Low { color: var(--green); background: #e7f5ef; }
.risk-Medium { color: var(--amber); background: #fff6e8; }
.risk-High, .risk-Critical { color: var(--red); background: #fff0ee; }

@media print {
  body { background: #ffffff; }
  .sidebar, .topbar-actions, .flow-actions, .report-actions, .risk-map-table, .table-guide, .risk-criteria { display: none !important; }
  .app-shell { display: block; }
  .workspace { padding: 0; }
  .panel { box-shadow: none; border: 0; padding: 0; }
  .risk-table { min-width: 0; font-size: 9px; }
  .risk-table th, .risk-table td { padding: 5px; }
}

@media (max-width: 1050px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; padding: 18px; }
  .step-list { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .status-panel { display: none; }
  .field-grid, .table-guide dl, .criteria-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 680px) {
  .workspace { padding: 16px; }
  .topbar { align-items: stretch; flex-direction: column; }
  .topbar-actions { justify-content: flex-end; }
  .flow-actions, .report-actions { align-items: stretch; flex-direction: column; }
  .result-heading-actions { width: 100%; }
  .result-heading-actions .ghost-button { flex: 1 1 100%; }
  .step-list, .field-grid, .table-guide dl, .criteria-grid { grid-template-columns: 1fr; }
  .panel { padding: 16px; }
}
