:root {
  --navy: #070529;
  --teal: #004466;
  --gold: #946F38;
  --burgundy: #50141B;
  --bg: #F5F6F8;
  --card: #FFFFFF;
  --line: #E3E6EB;
  --muted: #6B7280;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Encode Sans", system-ui, sans-serif;
  background: var(--bg);
  color: var(--navy);
  font-size: 15px;
}

header {
  background: var(--card);
  border-bottom: 3px solid var(--gold);
}
.header-inner {
  max-width: 1180px; margin: 0 auto; padding: 22px 24px;
  display: flex; justify-content: space-between; align-items: center;
}
h1 { margin: 0; font-size: 24px; font-weight: 800; letter-spacing: -0.3px; }
.sub { margin: 4px 0 0; color: var(--muted); font-size: 13.5px; }
.brandmark {
  width: 52px; height: 52px; border-radius: 12px;
  background: var(--navy); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 20px; letter-spacing: 1px;
}

main { max-width: 1180px; margin: 26px auto 60px; padding: 0 24px; }

.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: 14px; padding: 22px; margin-bottom: 22px;
  box-shadow: 0 1px 3px rgba(7,5,41,0.05);
}
h2 { margin: 0 0 14px; font-size: 16px; font-weight: 700; color: var(--teal); }
h2.mt { margin-top: 22px; }

/* upload */
#dropzone {
  border: 2px dashed #C4CBD6; border-radius: 12px;
  padding: 26px; text-align: center; cursor: pointer;
  transition: border-color .15s, background .15s;
}
#dropzone.drag { border-color: var(--gold); background: #FBF7F0; }
#dropzone p { margin: 4px 0; }
.linklike { color: var(--teal); text-decoration: underline; cursor: pointer; font-weight: 600; }
.hint { color: var(--muted); font-size: 12.5px; }
#fileList { list-style: none; padding: 0; margin: 10px 0 0; }
#fileList li {
  display: inline-flex; align-items: center; gap: 8px;
  background: #EFF2F6; border-radius: 8px; padding: 5px 10px;
  margin: 0 8px 8px 0; font-size: 13px;
}
#fileList button { border: 0; background: none; color: var(--burgundy); cursor: pointer; font-weight: 700; }

/* params */
.params { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 18px; margin: 18px 0; }
.field.span2 { grid-column: 1 / -1; }
.field label { display: block; font-size: 12.5px; font-weight: 600; margin-bottom: 5px; color: var(--navy); }
.field input[type="text"], .field input[type="number"], .field input[type="email"],
.field input[type="password"], .field select {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line);
  border-radius: 8px; font: inherit; background: #fff; color: var(--navy);
}
.radio-row { display: flex; gap: 18px; align-items: center; margin-bottom: 8px; flex-wrap: wrap; }
.radio-row label { display: inline-flex; gap: 6px; align-items: center; font-weight: 500; font-size: 13.5px; margin: 0; }
.radio-row input[type="number"] { max-width: 180px; }
.dim { color: var(--muted); }
.hidden { display: none !important; }

button {
  background: var(--navy); color: #fff; border: 0; border-radius: 9px;
  padding: 12px 26px; font: inherit; font-weight: 700; cursor: pointer;
}
button:disabled { opacity: .45; cursor: default; }
button.secondary { background: #fff; color: var(--teal); border: 1.5px solid var(--teal); padding: 9px 18px; }
.btn-row { display: flex; gap: 12px; margin-top: 14px; }

#busy { display: flex; gap: 10px; align-items: center; margin-top: 14px; color: var(--teal); font-weight: 600; }
.spinner {
  width: 18px; height: 18px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--gold);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
#error { margin-top: 14px; color: var(--burgundy); font-weight: 600; }

/* results */
#warnings { margin-bottom: 18px; }
.warn {
  background: #FFF7E8; border: 1px solid #EAD9AE; border-left: 4px solid var(--gold);
  border-radius: 8px; padding: 10px 14px; margin-bottom: 8px; font-size: 13.5px;
}
.summary-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 22px; }
.stat { text-align: center; padding: 18px 10px; }
.stat-label { display: block; font-size: 12px; font-weight: 700; letter-spacing: .8px; color: var(--muted); }
.stat-big { display: block; font-size: 34px; font-weight: 800; margin: 6px 0 2px; color: var(--navy); }
.stat-foot { display: block; font-size: 12px; color: var(--muted); }

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; }
.two-col .card { margin-bottom: 22px; }

/* tables */
table { border-collapse: collapse; width: 100%; font-size: 13.5px; }
th, td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--line); }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); }
.table-scroll { max-height: 420px; overflow-y: auto; }
#particleTable tbody tr { cursor: pointer; }
#particleTable tbody tr:hover { background: #F2F5F8; }
#particleTable tbody tr.sel { background: #FBF3E4; }

.swatch { display: inline-block; width: 12px; height: 12px; border-radius: 3px; }

.morph-flex { display: flex; gap: 22px; align-items: flex-start; }
.donut-holder { width: 200px; flex: 0 0 200px; }

/* viewer */
.tabs { display: flex; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.tabs button { background: #EFF2F6; color: var(--navy); padding: 7px 14px; font-weight: 600; font-size: 13px; }
.tabs button.active { background: var(--teal); color: #fff; }
#legend { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; font-size: 12.5px; }
#legend span { display: inline-flex; gap: 6px; align-items: center; }
#viewer { position: relative; }
#viewImg { width: 100%; display: block; border-radius: 10px; border: 1px solid var(--line); }
#viewCanvas { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }

footer { text-align: center; color: var(--muted); font-size: 12px; padding: 20px 0 40px; }

/* info button + modal */
.info-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 17px; height: 17px; padding: 0; margin-left: 4px;
  border-radius: 50%; background: var(--teal); color: #fff;
  font-size: 11px; font-weight: 800; font-style: italic;
  vertical-align: text-bottom; cursor: pointer;
}
.info-btn:hover { background: var(--navy); }
.modal-overlay {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(7, 5, 41, 0.55);
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
.modal {
  background: var(--card); border-radius: 14px; max-width: 680px;
  width: 100%; max-height: 85vh; display: flex; flex-direction: column;
  box-shadow: 0 12px 40px rgba(7, 5, 41, 0.35);
}
.modal-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 18px 22px 12px; border-bottom: 1px solid var(--line);
}
.modal-head h2 { margin: 0; }
.modal-head button {
  background: none; border: 0; color: var(--muted); font-size: 16px;
  padding: 4px 8px; cursor: pointer;
}
.modal-head button:hover { color: var(--burgundy); }
.modal-body { padding: 6px 22px 22px; overflow-y: auto; font-size: 14px; line-height: 1.55; }
.modal-body h3 { font-size: 13.5px; color: var(--gold); margin: 18px 0 6px; }
.modal-body ul { margin: 6px 0; padding-left: 20px; }
.modal-body li { margin-bottom: 6px; }
.modal-body .formula {
  background: #EFF2F6; border-radius: 8px; padding: 10px 14px;
  font-weight: 700; text-align: center;
}

/* email gate */
.consent-row {
  display: flex; gap: 10px; align-items: flex-start;
  font-size: 13px; margin-top: 6px; max-width: 620px;
}
.consent-row input { margin-top: 3px; }
.req { color: var(--burgundy); }

/* mode tabs */
.modetabs { display: flex; gap: 10px; margin-bottom: 20px; }
.modetabs button {
  background: #fff; color: var(--teal); border: 1.5px solid var(--line);
  padding: 10px 22px; font-weight: 700; font-size: 14px;
}
.modetabs button.active {
  background: var(--navy); color: #fff; border-color: var(--navy);
}

/* MPC module */
.mpc-summary { margin-top: 20px; grid-template-columns: 1fr 1fr; }
#mpcScaleStrip, #blotterScaleStrip { display: flex; border-radius: 8px; overflow: hidden; margin-bottom: 18px; }
#mpcScaleStrip .band, #blotterScaleStrip .band {
  flex: 1; text-align: center; padding: 8px 4px; color: #fff;
  font-size: 12px; font-weight: 700; opacity: 0.35;
}
#mpcScaleStrip .band.active, #blotterScaleStrip .band.active { opacity: 1; }
.field-label { display: block; font-size: 12.5px; font-weight: 600; margin-bottom: 6px; }
#blotterStats { max-width: 560px; }
#blotterStats td:last-child { font-weight: 700; text-align: right; }
.mpc-swatch-row { display: flex; gap: 10px; align-items: center; margin-bottom: 8px; }
.mpc-swatch {
  display: inline-block; width: 44px; height: 44px; border-radius: 8px;
  border: 1px solid var(--line);
}
.mpc-img { max-width: 100%; border-radius: 10px; border: 1px solid var(--line); }

/* calibration wizard */
.modal.wide { max-width: 860px; }
button.small { padding: 7px 14px; font-size: 13px; }
#calProfiles {
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px;
  font: inherit; font-size: 13px; background: #fff; color: var(--navy);
  max-width: 320px;
}
#wizDrop {
  border: 2px dashed #C4CBD6; border-radius: 12px; padding: 26px;
  text-align: center; cursor: pointer; margin-top: 10px;
}
#wizDrop.drag { border-color: var(--gold); background: #FBF7F0; }
#wizCanvasWrap {
  border: 1px solid var(--line); border-radius: 10px;
  overflow: hidden; background: #EFF2F6;
}
#wizCanvas { display: block; width: 100%; height: 440px; touch-action: none; cursor: crosshair; }
.wiz-controls { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-top: 12px; }
.wiz-controls label {
  font-size: 12.5px; font-weight: 600; display: flex; gap: 8px; align-items: center;
}
.wiz-controls input[type="number"], .wiz-controls input[type="text"] {
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; font: inherit;
}
.wiz-controls input[type="text"] { flex: 1; min-width: 240px; }
#wizResult .formula { margin: 12px 0 4px; }

@media (max-width: 900px) {
  .summary-row, .two-col, .params { grid-template-columns: 1fr; }
  .morph-flex { flex-direction: column; }
}
