:root {
  --bg: #f6f8fb;
  --panel: #ffffff;
  --panel-soft: #f9fafb;
  --sidebar: #111c2e;
  --sidebar-deep: #0b1322;
  --text: #111827;
  --muted: #667085;
  --line: #d8e0ea;
  --line-soft: #edf1f5;
  --accent: #147a8b;
  --accent-dark: #0e5e6d;
  --accent-soft: #e8f6f8;
  --danger-bg: #fff1f1;
  --danger: #a42121;
  --ok-bg: #edf8f1;
  --ok: #176b3a;
  --warning-bg: #fff8e6;
  --warning: #6e5311;
  --shadow: 0 10px 28px rgba(17, 24, 39, 0.06);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.45;
}

a { color: inherit; }

.app {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 244px minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, var(--sidebar) 0%, var(--sidebar-deep) 100%);
  color: #fff;
  padding: 18px 14px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 10px 18px;
  color: #fff;
  text-decoration: none;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.brand-mark,
.nav-icon {
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  font-weight: 800;
}

.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: #4fb4cf;
  color: #07111d;
}

.brand-text {
  display: grid;
  gap: 1px;
}

.brand-text strong {
  font-size: 15px;
}

.brand-text small {
  color: rgba(255, 255, 255, 0.56);
  font-size: 12px;
}

.side-nav {
  display: grid;
  gap: 6px;
  margin-top: 18px;
}

.side-nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 40px;
  color: rgba(255, 255, 255, 0.66);
  text-decoration: none;
  border-radius: 8px;
  padding: 0 11px;
  font-weight: 650;
  transition: background 0.15s ease, color 0.15s ease;
}

.side-nav a.active,
.side-nav a:hover {
  background: rgba(79, 180, 207, 0.16);
  color: #fff;
}

.nav-icon {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.08);
  font-size: 12px;
}

.content {
  min-width: 0;
  padding: 22px 26px 38px;
}

.content-inner {
  width: 100%;
  max-width: 1680px;
}

.shell {
  width: min(960px, calc(100vw - 32px));
  margin: 48px auto;
}

.shell-narrow {
  width: min(440px, calc(100vw - 32px));
}

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.page-head h2,
.panel h3,
.progress-card h2 {
  margin: 0;
}

.page-head h2 {
  font-size: 24px;
  line-height: 1.15;
  letter-spacing: 0;
}

.page-head p,
.panel-head p {
  margin: 6px 0 0;
}

.page-actions,
.actions,
.batch-actions,
.table-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.page-actions {
  justify-content: flex-end;
}

.muted {
  color: var(--muted);
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.metric-card {
  min-height: 78px;
  display: grid;
  align-content: center;
  gap: 4px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px 16px;
  box-shadow: var(--shadow);
}

.metric-card span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.metric-card strong {
  min-width: 0;
  overflow-wrap: anywhere;
  font-size: 22px;
  line-height: 1.1;
}

.grid {
  display: grid;
  gap: 16px;
  margin-bottom: 16px;
}

.grid > * {
  min-width: 0;
}

.grid.two {
  grid-template-columns: minmax(360px, 0.95fr) minmax(0, 1.25fr);
}

.panel {
  min-width: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.panel h3 {
  font-size: 16px;
  letter-spacing: 0;
}

form {
  display: grid;
  gap: 12px;
  margin: 0;
  min-width: 0;
}

label {
  display: grid;
  gap: 7px;
  font-weight: 700;
  min-width: 0;
}

input[type="file"],
input[type="password"],
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  min-height: 40px;
  padding: 9px 11px;
  font: inherit;
}

textarea {
  resize: vertical;
  line-height: 1.45;
}

textarea::placeholder {
  color: #b2bdc8;
  opacity: 1;
}

.field-compact span,
label > span {
  font-size: 13px;
}

.dropzone {
  position: relative;
  display: grid;
  place-items: center;
  gap: 6px;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  min-height: 150px;
  border: 1px dashed #9fb2c3;
  border-radius: 8px;
  background: #f8fbfd;
  color: var(--text);
  padding: 22px;
  text-align: center;
  cursor: pointer;
  overflow: hidden;
  transition: border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}

.dropzone.compact {
  min-height: 118px;
}

.dropzone:hover,
.dropzone.drag-active {
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 1px rgba(20, 122, 139, 0.08);
}

.dropzone-input {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
  min-height: 0;
}

.dropzone strong,
.dropzone span,
.dropzone small {
  min-width: 0;
  max-width: 100%;
  pointer-events: none;
}

.dropzone span,
.dropzone small {
  color: var(--muted);
}

.dropzone small {
  display: block;
  max-width: 100%;
  overflow-wrap: anywhere;
  word-break: break-word;
  font-weight: 500;
}

button,
.button,
.link-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  border-radius: 8px;
  border: 1px solid var(--accent);
  padding: 0 14px;
  font: inherit;
  font-size: 13px;
  font-weight: 800;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}

button,
.button {
  background: var(--accent);
  color: #fff;
}

button:hover,
.button:hover {
  background: var(--accent-dark);
  border-color: var(--accent-dark);
}

.link-button {
  background: #fff;
  color: var(--accent);
}

.link-button:hover {
  background: var(--accent-soft);
}

.button-sm {
  min-height: 30px;
  padding: 0 10px;
  font-size: 12px;
  border-radius: 7px;
}

button.danger {
  background: var(--danger);
  border-color: var(--danger);
}

button.danger:hover {
  background: #7d1717;
}

.danger-outline {
  background: #fff;
  border-color: #efc0c0;
  color: var(--danger);
}

.danger-outline:hover {
  background: var(--danger-bg);
  border-color: #e7a8a8;
  color: var(--danger);
}

.inline-action {
  display: inline-flex;
  margin: 0;
}

.flash {
  margin-bottom: 12px;
}

.uploader,
.tool-section {
  display: grid;
  gap: 12px;
  min-width: 0;
}

.uploader #ciq-status:empty,
#enm-status:empty,
#inbox-status:empty,
#generate-error:empty {
  display: none;
}

#generate-error {
  min-width: 0;
  max-width: 100%;
}

#enm-status,
#inbox-status {
  min-width: 0;
  max-width: 100%;
}

#generate-error > .flash {
  max-width: 100%;
  overflow-wrap: anywhere;
}

#enm-status > .flash,
#inbox-status > .flash {
  max-width: 100%;
  overflow-wrap: anywhere;
}

.ciq-choices {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
  margin: 0;
  display: grid;
  gap: 8px;
  max-height: 172px;
  overflow-y: auto;
}

.ciq-choices legend {
  font-weight: 800;
  padding: 0 6px;
}

.ciq-choices .checkbox,
.inbox-list .checkbox {
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 500;
  cursor: pointer;
}

.ciq-choices .checkbox input,
.inbox-list .checkbox input {
  width: auto;
  min-height: 0;
  margin: 0;
}

.resolution-panel {
  container-type: inline-size;
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
  border: 1px solid #ead59d;
  border-radius: 8px;
  background: #fffaf0;
  padding: 14px;
}

.resolution-panel h4 {
  margin: 0 0 6px;
}

.resolution-table-wrap,
.table-wrap {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
}

.resolution-table,
.data-table {
  width: 100%;
  border-collapse: collapse;
  border: 1px solid var(--line);
  background: #fff;
}

.resolution-table {
  table-layout: fixed;
  min-width: 0;
}

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

th {
  background: var(--panel-soft);
  color: #182230;
  font-size: 12px;
  font-weight: 800;
}

tbody tr:hover {
  background: #fbfdff;
}

.data-table .col-actions {
  width: 1%;
  white-space: nowrap;
}

.table-actions {
  justify-content: flex-end;
  min-width: 180px;
}

.wrap-strong {
  min-width: 220px;
  max-width: 520px;
  overflow-wrap: anywhere;
  font-weight: 800;
}

.file-cell {
  min-width: 0;
}

.file-cell strong {
  display: block;
  overflow-wrap: anywhere;
}

.file-cell span {
  display: block;
  margin-top: 3px;
}

.batch-site-cell {
  min-width: 240px;
  max-width: 420px;
}

.batch-site-details summary {
  cursor: pointer;
  color: var(--accent);
  font-weight: 800;
}

.batch-site-list {
  display: grid;
  gap: 6px;
  margin-top: 8px;
  max-height: 220px;
  overflow-y: auto;
}

.batch-site-item {
  display: grid;
  gap: 2px;
  border: 1px solid var(--line-soft);
  border-radius: 7px;
  background: #fff;
  padding: 7px 9px;
}

.batch-site-item strong,
.batch-site-item span {
  overflow-wrap: anywhere;
}

.batch-site-item small {
  color: var(--muted);
}

.nowrap {
  white-space: nowrap;
}

.empty-cell {
  color: var(--muted);
  padding: 18px 12px;
}

.resolution-table th:nth-child(1),
.resolution-table td:nth-child(1) {
  width: 18%;
}

.resolution-table th:nth-child(2),
.resolution-table td:nth-child(2) {
  width: 34%;
}

.resolution-table th:nth-child(3),
.resolution-table td:nth-child(3) {
  width: 48%;
}

.resolution-table select {
  width: 100%;
  min-width: 0;
}

.resolution-options {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 8px;
  overflow-wrap: anywhere;
}

.resolution-option {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 8px 10px;
}

@container (max-width: 620px) {
  .resolution-table,
  .resolution-table thead,
  .resolution-table tbody,
  .resolution-table tr,
  .resolution-table td {
    display: block;
  }

  .resolution-table thead {
    display: none;
  }

  .resolution-table tr {
    padding: 10px;
    border-bottom: 1px solid var(--line-soft);
  }

  .resolution-table tr:last-child {
    border-bottom: 0;
  }

  .resolution-table td {
    width: 100% !important;
    border-bottom: 0;
    padding: 4px 0;
  }

  .resolution-table td:nth-child(1) {
    margin-bottom: 4px;
  }

  .resolution-options {
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    margin-top: 6px;
  }
}

.summary-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  border: 1px solid #cfd7df;
  background: #eef2f5;
  color: #4a5562;
  padding: 3px 9px;
  font-size: 12px;
  font-weight: 800;
  text-transform: capitalize;
  white-space: nowrap;
}

.status-completed {
  background: var(--ok-bg);
  border-color: #bedfc9;
  color: var(--ok);
}

.status-failed,
.status-no_ciq_match {
  background: var(--danger-bg);
  border-color: #f3c5c5;
  color: var(--danger);
}

.compact-list {
  display: grid;
  gap: 8px;
}

.compact-row {
  min-width: 0;
  overflow-wrap: anywhere;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  padding: 10px 12px;
  font-weight: 700;
}

.attempts-table {
  min-width: 980px;
}

.attempts-table td:nth-child(4) {
  min-width: 380px;
}

.message-list {
  display: grid;
  gap: 7px;
  margin-top: 8px;
}

.message-list .note,
.message-list .alert {
  margin-top: 0;
  overflow-wrap: anywhere;
}

.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 3px 9px;
  font-size: 11px;
  font-weight: 800;
  border: 1px solid transparent;
  white-space: nowrap;
}

.badge-pass {
  background: #e8f7ee;
  color: #176b3a;
  border-color: #b6e0c4;
}

.badge-fail {
  background: #fdecec;
  color: #9f1d1d;
  border-color: #f3c5c5;
}

.badge-match {
  background: #e7f3fb;
  color: #115469;
  border-color: #bcdcec;
}

.badge-mismatch {
  background: #fff0e2;
  color: #a65512;
  border-color: #f3d2ab;
}

.badge-check {
  background: #f3ecfb;
  color: #5a2d8c;
  border-color: #d9c5ef;
}

.badge-undefined {
  background: #eceff2;
  color: #4a5562;
  border-color: #cfd7df;
}

.option-head {
  margin: 0;
  font-size: 14px;
}

.divider {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 16px 0;
}

.inbox-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.inbox-list {
  display: grid;
  gap: 8px;
  max-height: 230px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: var(--panel-soft);
}

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  background: rgba(12, 20, 28, 0.45);
  padding: 24px;
}

.progress-dock {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 50;
  width: min(360px, calc(100vw - 32px));
}

.modal-overlay[hidden],
.progress-dock[hidden] {
  display: none;
}

.modal-card {
  width: min(420px, 100%);
  background: #fff;
  border-radius: 8px;
  border: 1px solid var(--line);
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.25);
  padding: 22px;
}

.modal-card p {
  margin: 0 0 18px;
  overflow-wrap: anywhere;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.progress-card {
  overflow: hidden;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 18px 44px rgba(17, 24, 39, 0.18);
}

.progress-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border-bottom: 1px solid var(--line-soft);
  padding: 10px 12px;
}

.progress-title-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.progress-card h2 {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
}

.progress-body {
  display: grid;
  gap: 9px;
  padding: 12px;
}

.progress-body p {
  margin: 0;
  font-size: 12px;
}

.progress-close {
  width: 28px;
  min-height: 28px;
  padding: 0;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: #98a2b3;
  font-size: 16px;
}

.progress-close:hover {
  background: var(--panel-soft);
  color: var(--text);
}

.progress-icon {
  width: 16px;
  height: 16px;
  border-radius: 999px;
  border: 2px solid #cbd5e1;
  border-top-color: var(--accent);
  animation: progress-spin 0.8s linear infinite;
}

.progress-card[data-progress-state="complete"] .progress-icon {
  display: grid;
  place-items: center;
  border: 0;
  background: #22c55e;
  animation: none;
}

.progress-card[data-progress-state="complete"] .progress-icon::after {
  content: "";
  width: 7px;
  height: 4px;
  border-left: 2px solid #fff;
  border-bottom: 2px solid #fff;
  transform: rotate(-45deg) translate(1px, -1px);
}

.progress-card[data-progress-state="error"] .progress-icon {
  display: grid;
  place-items: center;
  border: 0;
  background: #ef4444;
  animation: none;
}

.progress-card[data-progress-state="error"] .progress-icon::after {
  content: "!";
  color: #fff;
  font-size: 11px;
  font-weight: 800;
  line-height: 1;
}

@keyframes progress-spin {
  to { transform: rotate(360deg); }
}

.progress-track {
  position: relative;
  height: 7px;
  overflow: hidden;
  border-radius: 999px;
  background: #e4ebf1;
}

.progress-bar {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 0.35s ease;
}

.progress-card[data-progress-state="complete"] .progress-bar {
  background: #22c55e;
}

.progress-card[data-progress-state="error"] .progress-bar {
  background: #ef4444;
}

.progress-percent {
  margin: 0;
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: var(--accent);
  font-size: 12px;
}

.progress-percent[hidden] {
  display: none;
}

.inline-progress-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
}

.inline-progress-head span:first-child {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.inline-progress-percent {
  flex: 0 0 auto;
  font-variant-numeric: tabular-nums;
  font-weight: 800;
}

.inline-progress-track {
  height: 7px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(23, 107, 58, 0.16);
  margin-top: 9px;
}

.inline-progress-bar {
  height: 100%;
  border-radius: inherit;
  background: var(--ok);
  transition: width 0.35s ease;
}

.progress-bar-indeterminate {
  position: absolute;
  width: 40%;
  left: -40%;
  animation: progress-indeterminate 1.2s infinite ease-in-out;
}

@keyframes progress-indeterminate {
  0% { left: -40%; }
  100% { left: 100%; }
}

.alert,
.ok,
.note {
  border-radius: 8px;
  margin-top: 8px;
  padding: 11px 12px;
}

.alert {
  background: var(--danger-bg);
  border: 1px solid #f3c5c5;
  color: var(--danger);
}

.ok {
  background: var(--ok-bg);
  border: 1px solid #bedfc9;
  color: var(--ok);
}

.note {
  background: var(--warning-bg);
  border: 1px solid #ead59d;
  color: var(--warning);
}

.note p,
.alert p {
  margin: 0 0 6px;
}

.note p:last-child,
.alert p:last-child {
  margin-bottom: 0;
}

ul {
  margin: 0;
  padding-left: 20px;
  overflow-wrap: anywhere;
}

.logout {
  margin-top: auto;
  padding-top: 16px;
}

.logout button {
  width: 100%;
  background: transparent;
  color: rgba(255, 255, 255, 0.74);
  border-color: rgba(255, 255, 255, 0.22);
}

.logout button:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.34);
  color: #fff;
}

@media (max-width: 1200px) {
  .grid.two {
    grid-template-columns: 1fr;
  }

  .metric-grid {
    grid-template-columns: repeat(2, minmax(140px, 1fr));
  }
}

@media (max-width: 760px) {
  .app {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    padding: 12px;
  }

  .brand {
    padding: 4px 6px 12px;
  }

  .brand-mark {
    width: 32px;
    height: 32px;
  }

  .side-nav {
    display: flex;
    margin-top: 12px;
  }

  .side-nav a {
    flex: 1;
  }

  .logout {
    margin-top: 10px;
    padding-top: 0;
  }

  .content {
    padding: 16px;
  }

  .page-head {
    display: grid;
  }

  .page-actions,
  .table-actions {
    justify-content: flex-start;
  }

  .metric-grid {
    grid-template-columns: 1fr;
  }

  .panel {
    padding: 14px;
  }

  .inline-action,
  .inline-action .button-sm,
  .page-actions .button,
  .page-actions .link-button {
    width: 100%;
  }
}
