*, *::before, *::after { box-sizing: border-box }

body {
  font-family: Arial, sans-serif;
  background: #f4f7fb;
  margin: 0;
  color: #222;
  -webkit-text-size-adjust: 100%;
}

/* ── Header ── */
header {
  background: #163b63;
  color: white;
  padding: 20px 16px;
  text-align: center;
}

header h1 {
  margin: 0 0 4px;
  font-size: clamp(20px, 5vw, 28px)
}

header p {
  margin: 0;
  opacity: .85;
  font-size: clamp(13px, 3vw, 16px)
}

/* ── Main container ── */
main {
  max-width: 900px;
  margin: 24px auto;
  background: white;
  border-radius: 12px;
  padding: clamp(16px, 4vw, 36px);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.09);
}

/* ── Progress bar ── */
#progressWrap {
  position: sticky;
  top: 0;
  background: white;
  z-index: 10;
  padding: 10px 0 14px;
  border-bottom: 1px solid #e5e9ef;
  margin-bottom: 20px;
}

#progressLabel {
  font-size: 13px;
  color: #555;
  margin-bottom: 6px
}

#progressBar {
  width: 100%;
  height: 8px;
  background: #e5e9ef;
  border-radius: 8px;
  overflow: hidden;
}

#progressFill {
  height: 100%;
  width: 0%;
  background: #163b63;
  border-radius: 8px;
  transition: width .3s;
}

/* ── Section headings ── */
h2 {
  color: #163b63;
  border-bottom: 2px solid #e5e5e5;
  padding-bottom: 8px;
  margin-top: 32px;
  font-size: clamp(15px, 3.5vw, 19px);
  display: flex;
  align-items: center;
  gap: 8px;
}

h2 .section-score-badge {
  margin-left: auto;
  font-size: 12px;
  font-weight: normal;
  background: #163b63;
  color: white;
  padding: 3px 10px;
  border-radius: 20px;
  white-space: nowrap;
  display: none;
}

/* ── Question card ── */
.question {
  margin: 16px 0;
  padding: 16px;
  border: 1px solid #dfe5ec;
  border-radius: 10px;
  background: #fafbfd;
  transition: border-color .2s;
}

.question.answered { border-color: #163b63 }

.question-title {
  font-weight: bold;
  margin-bottom: 12px;
  font-size: clamp(14px, 3vw, 16px);
  display: flex;
  align-items: flex-start;
  gap: 10px;
  line-height: 1.4;
}

/* ── Tooltip – click-based, mobile-friendly ── */
.tooltip-btn {
  flex-shrink: 0;
  cursor: pointer;
  background: #163b63;
  color: white;
  width: 22px;
  height: 22px;
  text-align: center;
  border-radius: 50%;
  font-size: 12px;
  line-height: 22px;
  border: none;
  padding: 0;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.tooltip-body {
  display: none;
  margin-top: 10px;
  background: #163b63;
  color: #fff;
  border-radius: 8px;
  padding: 12px 14px;
  font-size: 13px;
  font-weight: normal;
  line-height: 1.55;
}

.tooltip-body.open { display: block }

.tooltip-body ul { margin: 6px 0 0; padding-left: 18px }
.tooltip-body li  { margin-bottom: 4px }

/* ── Radio options ── */
.option {
  display: flex;
  align-items: flex-start;
  margin: 7px 0;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1.5px solid #d5dce5;
  background: white;
  cursor: pointer;
  font-size: clamp(13px, 2.8vw, 15px);
  transition: background .15s, border-color .15s;
  -webkit-tap-highlight-color: transparent;
  flex-direction: column;
  gap: 0;
}

.option:hover { background: #f0f5fb }

.option.selected {
  background: #eaf1fb;
  border-color: #163b63;
}

.option-header {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
}

.option-header input[type=radio] {
  accent-color: #163b63;
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  cursor: pointer;
  margin: 0;
}

.option-label {
  font-weight: bold;
  font-size: clamp(13px, 2.8vw, 15px);
  line-height: 1.4;
}

.option.selected .option-label { color: #163b63 }

/* Option detail – revealed when selected */
.option-detail {
  display: none;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid #dfe5ec;
  width: 100%;
  font-size: 13px;
  color: #333;
  line-height: 1.6;
}

.option.selected .option-detail { display: block }

.option-detail ul { margin: 4px 0 8px; padding-left: 18px }
.option-detail li { margin-bottom: 3px }

.option-hint {
  background: #f0f5fb;
  border-left: 3px solid #163b63;
  padding: 7px 10px;
  border-radius: 0 6px 6px 0;
  font-size: 12.5px;
  color: #163b63;
  margin-top: 6px;
}

/* ── Textarea ── */
textarea {
  width: 100%;
  min-height: 100px;
  padding: 12px;
  border-radius: 8px;
  border: 1px solid #ccd3db;
  margin-top: 8px;
  font-size: 14px;
  resize: vertical;
}

/* ── Buttons ── */
.btn-primary {
  display: block;
  width: 100%;
  margin-top: 28px;
  background: #163b63;
  color: white;
  border: none;
  padding: 16px 24px;
  border-radius: 10px;
  font-size: clamp(15px, 3.5vw, 17px);
  cursor: pointer;
  transition: background .2s;
}

.btn-primary:hover { background: #102b49 }

.btn-secondary {
  display: block;
  width: 100%;
  margin-top: 12px;
  background: transparent;
  color: #163b63;
  border: 2px solid #163b63;
  padding: 13px 24px;
  border-radius: 10px;
  font-size: clamp(14px, 3vw, 16px);
  cursor: pointer;
  transition: background .2s;
}

.btn-secondary:hover { background: #f0f5fb }

.btn-json {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  margin-top: 12px;
  background: #0d2d4a;
  color: #7dd3fc;
  border: 2px solid #164e75;
  padding: 13px 24px;
  border-radius: 10px;
  font-size: clamp(14px, 3vw, 16px);
  cursor: pointer;
  font-family: 'Courier New', monospace;
  font-weight: bold;
  letter-spacing: 0.5px;
  transition: background .2s, border-color .2s;
}

.btn-json:hover { background: #163b63; border-color: #7dd3fc }

/* ── Toast ── */
#jsonToast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: #0d2d4a;
  color: #7dd3fc;
  padding: 12px 24px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: bold;
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
  border: 1px solid #164e75;
  z-index: 9999;
  transition: transform .35s cubic-bezier(.34,1.56,.64,1), opacity .35s;
  opacity: 0;
  white-space: nowrap;
}

#jsonToast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

/* ── Results ── */
#result { display: none; margin-top: 32px }

.result-header {
  border-radius: 12px;
  padding: 24px;
  text-align: center;
  margin-bottom: 24px;
}

.result-header .score {
  font-size: clamp(28px, 7vw, 44px);
  font-weight: bold;
  margin-bottom: 8px;
}

.result-header .status-label {
  font-size: clamp(16px, 3.5vw, 20px);
  font-weight: bold;
}

.result-header p { margin: 8px 0 0; font-size: 14px }

.low    { background: #ffe5e5; color: #7a1d1d }
.medium { background: #fff5d9; color: #7b5c12 }
.high   { background: #e3f7e6; color: #1f6b2b }

/* ── Section breakdown ── */
.breakdown-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
  margin-bottom: 28px;
}

.breakdown-card {
  border-radius: 10px;
  padding: 16px;
  border: 1px solid #dfe4ea;
}

.breakdown-card h4 { margin: 0 0 8px; font-size: 15px; color: #163b63 }

.breakdown-card .bar-wrap {
  background: #e5e9ef;
  border-radius: 6px;
  height: 10px;
  overflow: hidden;
  margin-bottom: 8px;
}

.breakdown-card .bar-fill { height: 100%; border-radius: 6px; transition: width .4s }

.bar-low  { background: #e05252 }
.bar-med  { background: #e0a030 }
.bar-high { background: #28a745 }

.breakdown-card .rec { font-size: 12.5px; color: #444; line-height: 1.5 }
.breakdown-card .rec strong { display: block; margin-bottom: 3px; color: #163b63 }

/* ── Action plan ── */
.action-plan { margin-bottom: 28px }
.action-plan h3 { color: #163b63; margin-bottom: 14px; font-size: 17px }

.action-item {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 10px 12px;
  border-radius: 8px;
  background: #f7f9fc;
  border-left: 4px solid #163b63;
  margin-bottom: 8px;
  font-size: 13.5px;
  transition: box-shadow .15s, opacity .2s;
  position: relative;
}

.action-item.dragging  { opacity: .4; box-shadow: 0 4px 18px rgba(22,59,99,.18) }
.action-item.drag-over { border-top: 2px solid #163b63 }

.ai-handle {
  flex-shrink: 0;
  cursor: grab;
  color: #b0bec5;
  font-size: 16px;
  line-height: 1;
  padding: 4px 2px;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.ai-handle:active { cursor: grabbing }

.action-item .priority {
  flex-shrink: 0;
  font-size: 10px;
  font-weight: bold;
  padding: 3px 8px;
  border-radius: 20px;
  margin-top: 4px;
  white-space: nowrap;
}

.pri-high { background: #ffd5d5; color: #7a1d1d }
.pri-med  { background: #fff3cd; color: #7b5c12 }
.pri-low  { background: #d4edda; color: #155724 }

.ai-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.ai-cat { font-size: 11px; color: #888; display: flex; align-items: center; gap: 6px }

.ai-cat select {
  font-size: 11px;
  border: 1px solid #d5dce5;
  border-radius: 6px;
  padding: 2px 6px;
  color: #163b63;
  background: white;
  cursor: pointer;
  max-width: 220px;
}

.ai-text {
  outline: none;
  border-radius: 5px;
  padding: 3px 6px;
  line-height: 1.5;
  transition: background .15s;
  word-break: break-word;
}

.ai-text:focus { background: white; box-shadow: 0 0 0 2px #163b6340 }
.ai-text:empty::before { content: attr(data-placeholder); color: #aaa }

.ai-del {
  flex-shrink: 0;
  background: none;
  border: none;
  cursor: pointer;
  color: #c0c8d2;
  font-size: 17px;
  line-height: 1;
  padding: 2px 4px;
  border-radius: 5px;
  transition: color .15s, background .15s;
  margin-top: 1px;
}

.ai-del:hover { color: #e05252; background: #fff0f0 }

.ai-add-btn {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-top: 8px;
  background: none;
  border: 2px dashed #b0bec5;
  color: #607d8b;
  padding: 9px 16px;
  border-radius: 8px;
  font-size: 13.5px;
  cursor: pointer;
  width: 100%;
  justify-content: center;
  transition: border-color .15s, color .15s, background .15s;
}

.ai-add-btn:hover { border-color: #163b63; color: #163b63; background: #f0f5fb }

/* ── Legend table ── */
.legend-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 8px;
  font-size: 14px;
}

.legend-table th,
.legend-table td {
  border: 1px solid #dfe4ea;
  padding: 9px 12px;
  text-align: left;
}

.legend-table th { background: #f1f5f9 }

@media (max-width: 520px) {
  .breakdown-grid { grid-template-columns: 1fr }
}
