:root {
  --navy: #17365d;
  --navy2: #102a49;
  --blue: #4f81bd;
  --soft: #eaf1f8;
  --bg: #f3f6f9;
  --surface: #ffffff;
  --text: #1d2939;
  --muted: #667085;
  --line: #d0d5dd;
  --line-soft: #e4e7ec;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 Arial, sans-serif;
}

header {
  padding: 32px max(20px, calc((100% - 1180px) / 2));
  color: #fff;
  background: linear-gradient(120deg, var(--navy2), #24558a);
}

header h1 {
  margin: 4px 0;
  font-size: 32px;
  line-height: 1.15;
}

header p:last-child { margin-bottom: 0; }

.eyebrow {
  margin: 0;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .14em;
  color: #a9d5f5;
}

.header-inner,
main {
  max-width: 1180px;
  margin: auto;
}

main { padding: 24px 18px 40px; }

.card {
  margin-bottom: 18px;
  padding: 22px;
  background: var(--surface);
  border: 1px solid #e2e8f0;
  border-radius: 14px;
  box-shadow: 0 3px 12px #0f172a0d;
}

.title {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}

.title > span:first-child {
  display: grid;
  flex: 0 0 30px;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--navy);
  color: #fff;
  font-weight: 700;
}

.title h2 {
  flex: 1;
  margin: 0;
  color: var(--navy);
}

.grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
  font-weight: 700;
}

label small {
  color: var(--muted);
  font-weight: 400;
}

input,
select,
textarea {
  width: 100%;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  font: inherit;
}

input:focus,
select:focus,
textarea:focus,
button:focus-visible,
.btn:focus-visible {
  outline: 3px solid #4f81bd45;
  outline-offset: 2px;
  border-color: var(--blue);
}

textarea { resize: vertical; }
.comments { grid-column: 1 / -1; }

.upload {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  padding: 15px;
  background: #f8fafc;
  border: 1px dashed #98a2b3;
  border-radius: 10px;
}

.upload input {
  flex: 1 1 320px;
  min-width: 190px;
}

#status {
  flex: 1 1 220px;
  color: var(--muted);
  overflow-wrap: anywhere;
}

button,
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 10px 16px;
  border: 0;
  border-radius: 8px;
  background: var(--navy);
  color: #fff;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
}

button:hover,
.btn:hover { background: #204a78; }

.light {
  background: var(--soft);
  color: var(--navy);
}

.light:hover { background: #d9e7f4; }

button:disabled {
  opacity: .45;
  cursor: not-allowed;
}

.actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin: 18px 0;
}

/* Wide-table wrapper. Horizontal scrolling stays inside the card. */
.table {
  width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  border: 1px solid var(--line-soft);
  border-radius: 10px;
  background: #fff;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
}

/* Imported event table now has 10 columns and needs more working width. */
#events { font-variant-numeric: tabular-nums; }

.table > table:not(.results-table) {
  min-width: 1220px;
  table-layout: auto;
}

.table > table:not(.results-table) th:nth-child(1),
.table > table:not(.results-table) td:nth-child(1) { min-width: 64px; width: 64px; }
.table > table:not(.results-table) th:nth-child(2),
.table > table:not(.results-table) td:nth-child(2) { min-width: 150px; }
.table > table:not(.results-table) th:nth-child(3),
.table > table:not(.results-table) td:nth-child(3) { min-width: 190px; }
.table > table:not(.results-table) th:nth-child(4),
.table > table:not(.results-table) td:nth-child(4) { min-width: 135px; }
.table > table:not(.results-table) th:nth-child(5),
.table > table:not(.results-table) td:nth-child(5) { min-width: 140px; }
.table > table:not(.results-table) th:nth-child(6),
.table > table:not(.results-table) td:nth-child(6) { min-width: 105px; }
.table > table:not(.results-table) th:nth-child(7),
.table > table:not(.results-table) td:nth-child(7),
.table > table:not(.results-table) th:nth-child(8),
.table > table:not(.results-table) td:nth-child(8),
.table > table:not(.results-table) th:nth-child(9),
.table > table:not(.results-table) td:nth-child(9) { min-width: 112px; }
.table > table:not(.results-table) th:nth-child(10),
.table > table:not(.results-table) td:nth-child(10) { min-width: 105px; }

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--navy);
  color: #fff;
  text-align: left;
  white-space: nowrap;
}

th,
td {
  padding: 10px 11px;
  border-right: 1px solid var(--line-soft);
  border-bottom: 1px solid var(--line-soft);
  vertical-align: top;
}

th:last-child,
td:last-child { border-right: 0; }

tbody tr:last-child td { border-bottom: 0; }
tbody tr:nth-child(even) td { background: #f8fafc; }
tbody tr:hover td { background: #eef5fb; }

/* Numeric input/review fields are easier to scan when right-aligned. */
.table > table:not(.results-table) td:nth-child(1),
.table > table:not(.results-table) td:nth-child(6),
.table > table:not(.results-table) td:nth-child(7),
.table > table:not(.results-table) td:nth-child(8),
.table > table:not(.results-table) td:nth-child(9),
.table > table:not(.results-table) td:nth-child(10) {
  text-align: right;
  white-space: nowrap;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin: 18px 0;
}

.metric {
  min-width: 0;
  padding: 14px;
  background: #f8fafc;
  border-left: 4px solid var(--blue);
  border-radius: 8px;
}

.metric small {
  display: block;
  color: var(--muted);
}

.metric strong {
  display: block;
  margin-top: 2px;
  color: var(--navy);
  font-size: 20px;
  overflow-wrap: anywhere;
}

.results-table {
  min-width: 760px;
  font-variant-numeric: tabular-nums;
}

.results-table th:not(:first-child),
.results-table td:not(:first-child) { text-align: right; }

/* Risk contribution includes descriptive columns before the numeric outputs. */
#riskContribution .results-table { min-width: 960px; }
#riskContribution .results-table th:nth-child(1),
#riskContribution .results-table td:nth-child(1) { min-width: 180px; text-align: left; }
#riskContribution .results-table th:nth-child(2),
#riskContribution .results-table td:nth-child(2) { min-width: 130px; text-align: left; }

.section { margin-top: 24px; }
.section h3 { margin-bottom: 10px; color: var(--navy); }

#message {
  padding: 10px 12px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  color: var(--muted);
}

.method-note {
  margin: 14px 0 0;
  padding: 11px 13px;
  background: #f8fafc;
  border-left: 4px solid var(--blue);
  border-radius: 0 8px 8px 0;
  color: #475467;
}

#percentileMethod {
  margin: 0 0 12px;
  background: var(--soft);
  color: var(--navy);
}

.toggle {
  flex-direction: row;
  align-items: center;
  gap: 7px;
  white-space: nowrap;
}

.toggle input { width: auto; }

.curve {
  display: grid;
  grid-template-columns: minmax(160px, 220px) minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  margin: 12px 0;
}

.curve b {
  overflow-wrap: anywhere;
  color: #344054;
}

.curve small {
  display: block;
  margin-top: 5px;
  color: var(--muted);
}

.bar {
  height: 10px;
  overflow: hidden;
  background: #e5e7eb;
  border-radius: 10px;
}

.bar i {
  display: block;
  height: 100%;
  background: var(--blue);
  border-radius: 10px;
}

footer {
  padding: 24px;
  color: var(--muted);
  text-align: center;
}

@media (max-width: 900px) {
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .table > table:not(.results-table) { min-width: 1150px; }
}

@media (max-width: 650px) {
  header { padding-top: 24px; padding-bottom: 24px; }
  header h1 { font-size: 27px; }
  main { padding: 16px 12px 32px; }
  .card { padding: 16px; border-radius: 11px; }
  .grid,
  .metrics { grid-template-columns: 1fr; }
  .actions { display: grid; grid-template-columns: 1fr; }
  .actions button { width: 100%; }
  .curve { grid-template-columns: 1fr; }
  .title { flex-wrap: wrap; }
  .title h2 { min-width: calc(100% - 45px); }
  .title .btn { width: 100%; }
  .toggle { margin-left: 40px; }
  .upload button { width: 100%; }
  .table > table:not(.results-table) { min-width: 1080px; }
  th,
  td { padding: 9px; }
}
