:root {
  --teal: #003942;
  --teal-soft: #174f57;
  --gold: #c5a880;
  --paper: #f3f3f3;
  --ink: #222222;
  --muted: #5d6a6c;
  --line: #bfcdd0;
  --white: #ffffff;
  --danger: #8b2e2e;
  font-family: "Segoe UI", "Avenir Next", Avenir, sans-serif;
  color: var(--ink);
  background: var(--paper);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-width: 320px; background: var(--paper); }
button, input, select { font: inherit; }
h1, h2, .header-title, .eyebrow, .slot-index, .slot-title {
  font-family: Montserrat, "Avenir Next", "Segoe UI", sans-serif;
}
h1 { margin: .35rem 0 .65rem; font-size: clamp(2rem, 4vw, 3.4rem); line-height: 1.08; font-weight: 400; }
h2 { margin: 0 0 .35rem; font-size: 1.15rem; font-weight: 500; }
p { margin: 0; }
.small { font-size: .86rem; }
.muted { color: var(--muted); }
.eyebrow { margin: 0; color: var(--muted); font-size: .72rem; letter-spacing: .15em; text-transform: uppercase; font-weight: 600; }

.brand-header {
  min-height: 6.25rem;
  padding: .8rem clamp(1rem, 4vw, 3.5rem);
  display: grid;
  grid-template-columns: minmax(10rem, .8fr) minmax(11rem, 2fr) minmax(8rem, .8fr);
  align-items: center;
  gap: 1rem;
  background: var(--teal);
  color: var(--white);
}
.official-logo {
  display: block;
  width: 10rem;
  height: auto;
  max-width: 100%;
  filter: brightness(0) invert(1);
}
.brand-header.without-msg-logo { grid-template-columns: minmax(11rem, 1fr) auto; }
.brand-header.without-msg-logo .header-title { text-align: left; }
.header-title { text-align: center; font-size: .9rem; font-weight: 400; letter-spacing: .13em; text-transform: uppercase; }
.header-status { justify-self: end; padding: .42rem .72rem; border: 1px solid var(--white); border-radius: 999px; font-size: .76rem; }

.content { width: min(1180px, 100%); margin: 0 auto; padding: 1.5rem clamp(1rem, 4vw, 3.5rem) 2rem; }
.gold-rule { height: 1px; margin-bottom: 2rem; background: var(--gold); }
.hero { max-width: 48rem; margin-bottom: 2rem; }
.hero > .muted { font-size: 1.05rem; }

.profile-row, .period-row, .action-row, .result-card, footer { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.profile-row { padding: 1rem; margin-bottom: 1rem; border: 1px solid var(--gold); background: var(--white); }
.profile-copy { max-width: 42rem; }
.profile-copy h2 { margin-top: .25rem; }
.profile-row label { flex: 0 0 min(20rem, 42%); }
.profile-restriction { margin-top: .45rem; color: var(--teal); font-weight: 600; }
.period-row { align-items: end; padding: 1rem 0; margin-bottom: 1.4rem; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.period-copy { max-width: 31rem; }
.period-controls { display: flex; gap: .75rem; align-items: end; }
label { display: grid; gap: .42rem; color: var(--teal); font-size: .78rem; font-weight: 600; letter-spacing: .04em; }
select, dialog input, .registration-picker input { min-height: 2.75rem; padding: .55rem .8rem; border: 1px solid #93a7aa; border-radius: 2px; color: var(--ink); background: var(--white); }
select:focus, dialog input:focus, .registration-picker input:focus, button:focus-visible, a:focus-visible, .upload-slot:focus-within { outline: 3px solid rgba(197, 168, 128, .5); outline-offset: 2px; }

.stepper { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .9rem; padding: 0; margin: 0 0 1.4rem; list-style: none; }
.step { display: grid; gap: .18rem; padding-top: .7rem; border-top: 2px solid var(--line); color: var(--muted); }
.step strong { color: var(--ink); font-weight: 500; }
.step span { font-size: .82rem; }
.step.is-current { border-color: var(--teal); }
.step.is-current strong, .step.is-current span { color: var(--teal); }

.upload-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .9rem; }
.upload-slot { min-height: 13rem; padding: 1.1rem; display: flex; flex-direction: column; align-items: flex-start; gap: .65rem; border: 1px dashed #93a7aa; background: rgba(255, 255, 255, .68); cursor: pointer; transition: border-color .2s, background .2s; }
.upload-slot:hover, .upload-slot.has-file { border-color: var(--teal); background: var(--white); }
.slot-index { color: #9b7b52; font-weight: 600; }
.slot-title { color: var(--ink); font-size: 1.02rem; font-weight: 500; }
.upload-slot input { position: absolute; width: 1px; height: 1px; overflow: hidden; opacity: 0; }
.file-button { margin-top: auto; padding: .55rem .78rem; border: 1px solid var(--teal); color: var(--teal); font-size: .8rem; letter-spacing: .03em; }
.file-name { width: 100%; overflow: hidden; color: var(--muted); font-size: .76rem; text-overflow: ellipsis; white-space: nowrap; }

.erp-draft-action, .section-heading, .adjustment-action {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}
.erp-draft-action { margin-top: 1rem; padding: 1rem; border: 1px solid var(--line); background: var(--white); }
.secondary-button { min-height: 2.65rem; padding: .62rem 1rem; border: 1px solid var(--teal); background: transparent; color: var(--teal); cursor: pointer; }
.secondary-button:hover { background: rgba(0, 57, 66, .06); }
.secondary-button:disabled { opacity: .5; cursor: wait; }
.adjustment-section { margin-top: 1.2rem; padding: 1.25rem; border: 1px solid var(--gold); background: var(--white); }
.source-pill { padding: .42rem .68rem; border: 1px solid var(--line); color: var(--muted); font-size: .75rem; overflow-wrap: anywhere; }
.prototype-note { margin-top: .9rem; padding: .75rem .85rem; border-left: 3px solid var(--gold); background: #faf7f1; color: var(--teal); font-size: .86rem; }
.selection-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .8rem; margin-top: 1rem; }
.selection-grid select, .registration-picker input { width: 100%; }
.registration-picker { display: grid; align-content: start; gap: .42rem; }
.registration-match-count { min-height: 1.05rem; }
.preview-card { min-height: 7.5rem; margin-top: 1rem; padding: 1rem; border: 1px solid var(--line); background: var(--paper); }
.preview-placeholder { padding: 1.9rem 0; text-align: center; }
.preview-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1rem; margin: 0; }
.preview-grid div { min-width: 0; }
.preview-grid dt { color: var(--muted); font-size: .68rem; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; }
.preview-grid dd { margin: .25rem 0 0; overflow-wrap: anywhere; color: var(--ink); font-size: .88rem; }
.adjustment-action { margin-top: .9rem; }
.adjustment-summary { margin-top: 1.1rem; padding-top: 1rem; border-top: 1px solid var(--line); }
.existing-adjustments { margin: 1rem 0; padding: .9rem 1rem; border: 1px solid var(--line); background: var(--cream); }
.existing-adjustments summary { cursor: pointer; font-weight: 700; }
.existing-adjustments[open] summary { margin-bottom: .75rem; }
.existing-adjustment-detail { flex: 1; min-width: 0; }
.status-chip { display: inline-block; margin-left: .35rem; padding: .12rem .35rem; border: 1px solid var(--line); color: var(--muted); font-size: .68rem; }
.status-chip.is-active { border-color: var(--gold); color: var(--teal); }
.cancellation-summary { margin-top: 1rem; padding: .9rem; border-left: 3px solid var(--danger); background: #fff8f7; }
.cancellation-summary h3 { margin: 0; }
.summary-list { display: grid; gap: .5rem; margin: .7rem 0 0; padding: 0; list-style: none; }
.summary-list li { display: flex; align-items: center; justify-content: space-between; gap: .8rem; padding: .7rem .8rem; background: var(--paper); font-size: .82rem; }
.confirm-check { display: flex; align-items: flex-start; gap: .65rem; margin-top: .9rem; color: var(--ink); font-size: .84rem; font-weight: 500; letter-spacing: 0; }
.confirm-check input { flex: 0 0 auto; margin-top: .15rem; }

.action-row { margin-top: 1.2rem; }
.primary-button { display: inline-flex; min-height: 2.85rem; padding: .7rem 1.15rem; align-items: center; justify-content: center; border: 1px solid var(--teal); border-radius: 0; background: var(--teal); color: var(--white); text-decoration: none; cursor: pointer; }
.primary-button:hover { background: var(--teal-soft); }
.primary-button:disabled { opacity: .5; cursor: wait; }
.message { margin-top: 1rem; padding: .9rem 1rem; border-left: 3px solid var(--gold); background: var(--white); }
.message.error { border-color: var(--danger); color: var(--danger); }
.result-card { margin-top: 1.5rem; padding: 1.4rem; border: 1px solid var(--gold); background: var(--white); }
.warnings { margin: .7rem 0 0; padding-left: 1.2rem; color: var(--danger); font-size: .86rem; }
footer { margin-top: 2.2rem; padding-top: 1rem; border-top: 1px solid var(--line); color: var(--muted); font-size: .76rem; }
.text-button { border: 0; border-bottom: 1px solid currentColor; padding: .15rem 0; background: transparent; color: var(--teal); cursor: pointer; }

dialog { width: min(28rem, calc(100% - 2rem)); padding: 0; border: 0; box-shadow: 0 1.5rem 5rem rgba(0, 30, 35, .3); }
dialog::backdrop { background: rgba(0, 30, 35, .68); }
dialog form { display: grid; gap: 1rem; padding: 2rem; background: var(--paper); }
dialog .dialog-logo {
  width: 12rem;
  height: auto;
  max-width: 100%;
  margin: 0 auto .5rem;
}
dialog .primary-button { width: 100%; margin-top: .25rem; }
.cancellation-dialog { width: min(42rem, calc(100% - 2rem)); }
.cancellation-dialog .dialog-content { display: grid; gap: .9rem; padding: 1.6rem; background: var(--paper); }
.cancellation-dialog textarea { width: 100%; resize: vertical; }
.dialog-actions { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
.dialog-actions .secondary-button, .dialog-actions .primary-button { width: 100%; margin: 0; }
.form-error { color: var(--danger); font-size: .84rem; }

@media (max-width: 720px) {
  .brand-header { grid-template-columns: auto 1fr; }
  .brand-header.without-msg-logo { grid-template-columns: 1fr auto; }
  .official-logo { width: 9rem; }
  .header-title { text-align: right; }
  .header-status { grid-column: 1 / -1; justify-self: stretch; text-align: center; }
  .profile-row, .period-row, .result-card { align-items: stretch; flex-direction: column; }
  .profile-row label { flex-basis: auto; width: 100%; }
  .period-controls, .period-controls label { width: 100%; }
  .period-controls select { width: 100%; }
  .upload-grid, .stepper, .selection-grid { grid-template-columns: 1fr; }
  .preview-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dialog-actions { grid-template-columns: 1fr; }
  .erp-draft-action, .section-heading, .adjustment-action { align-items: stretch; flex-direction: column; }
  .upload-slot { min-height: 11rem; }
}

@media (max-width: 460px) {
  .action-row { align-items: stretch; flex-direction: column; }
  .primary-button, .secondary-button { width: 100%; }
  .preview-grid { grid-template-columns: 1fr; }
  .summary-list li { align-items: flex-start; flex-direction: column; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; transition: none !important; }
}
