:root {
  color-scheme: light;
  font-family: Inter, "Segoe UI", "Microsoft YaHei", sans-serif;
  color: #17213a;
  background: #f3f6fb;
  --navy: #17213a;
  --blue: #315efb;
  --blue-dark: #2448c7;
  --line: #dfe5ef;
  --muted: #667085;
  --green: #087e61;
  --amber: #9a6700;
  --red: #b42318;
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: radial-gradient(circle at 10% 0, #e8efff 0, transparent 30rem), #f3f6fb; }
button, input { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .5; }

.topbar { min-height: 76px; padding: 14px clamp(18px, 4vw, 48px); display: flex; align-items: center; justify-content: space-between; color: white; background: var(--navy); box-shadow: 0 3px 16px #17213a30; }
.topbar h1 { margin: 2px 0 0; font-size: clamp(20px, 3vw, 27px); letter-spacing: .02em; }
.eyebrow { margin: 0; color: #6b85d8; font-size: 11px; font-weight: 800; letter-spacing: .16em; text-transform: uppercase; }
.topbar .eyebrow { color: #a9b9ed; }
.user-chip { padding: 8px 13px; border: 1px solid #ffffff35; border-radius: 999px; color: #eaf0ff; font-size: 13px; }

main { width: min(1180px, calc(100% - 32px)); margin: 0 auto; padding: 34px 0 64px; }
.gate { min-height: 360px; display: grid; place-content: center; justify-items: center; text-align: center; }
.gate h2 { margin: 20px 0 6px; }
.gate p, .intro p, .muted { color: var(--muted); }
.gate.error .spinner { display: none; }
.gate.error h2 { color: var(--red); }
.spinner { width: 32px; height: 32px; border: 3px solid #cdd7ef; border-top-color: var(--blue); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.intro h2 { margin: 7px 0 5px; font-size: 28px; }
.intro p:last-child { margin-top: 0; }
.company-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; margin-top: 24px; }
.company-card { min-height: 184px; padding: 22px; display: flex; flex-direction: column; align-items: flex-start; background: #fff; border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 8px 24px #2435530a; }
.company-card.enabled { border-top: 4px solid var(--blue); }
.company-card.disabled { background: #f8f9fc; color: #8b95a7; }
.company-index { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 9px; background: #edf1ff; color: var(--blue); font-weight: 800; }
.company-card h3 { margin: 18px 0 5px; font-size: 19px; }
.company-card p { margin: 0 0 20px; color: var(--muted); font-size: 13px; }
.company-card button, .company-state { margin-top: auto; }

.workspace { margin-top: 26px; }
.workspace-heading { margin-bottom: 18px; display: flex; align-items: flex-end; justify-content: space-between; }
.workspace-heading h2 { margin: 6px 0 0; font-size: 27px; }
.text-button { margin-bottom: 18px; padding: 0; border: 0; background: transparent; color: var(--blue); }
.state-pill, .status { display: inline-flex; align-items: center; width: fit-content; padding: 5px 9px; border-radius: 999px; background: #eef2f8; color: #526077; font-size: 12px; font-weight: 700; }
.state-pill.ready, .status.ready_to_upload, .status.uploaded { background: #e8f7f1; color: var(--green); }
.status.running, .status.created, .status.validating_confirm, .status.uploading { background: #edf1ff; color: var(--blue-dark); }
.status.matching_failed, .status.confirm_validation_failed, .status.upload_failed, .status.upload_reconciliation_required { background: #fef0ed; color: var(--red); }
.status.waiting_business_confirm { background: #fff5db; color: var(--amber); }

.workspace-grid { display: grid; grid-template-columns: minmax(300px, .78fr) minmax(0, 1.4fr); gap: 18px; align-items: start; }
.panel { background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 22px; box-shadow: 0 8px 24px #2435530a; }
.panel h3 { margin: 0; }
.panel-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
.panel-heading p { margin: 5px 0 0; font-size: 13px; }
label { display: grid; gap: 7px; color: #344054; font-size: 13px; font-weight: 700; }
input[type="date"], input[type="file"], input[type="text"], dialog input { width: 100%; min-height: 42px; padding: 8px 10px; border: 1px solid #c9d2e1; border-radius: 8px; background: #fff; color: var(--navy); }
input:focus { outline: 3px solid #315efb25; border-color: var(--blue); }
.date-grid { margin-top: 18px; display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.file-fields { margin: 15px 0 18px; display: grid; gap: 12px; }
.file-source { padding: 12px; border-radius: 9px; background: #f7f9fc; }
.file-source span { display: block; margin-bottom: 7px; }
.primary-button, .secondary-button, .danger-button { min-height: 40px; padding: 0 15px; border-radius: 8px; font-weight: 750; }
.primary-button { border: 0; background: var(--blue); color: #fff; }
.primary-button:hover { background: var(--blue-dark); }
.secondary-button { border: 1px solid #c9d2e1; background: #fff; color: #344054; }
.danger-button { border: 0; background: var(--red); color: #fff; }
.new-job-panel .primary-button { width: 100%; }
.message { margin-top: 14px; padding: 11px 12px; border-radius: 8px; background: #eef4ff; color: var(--blue-dark); font-size: 13px; }
.message.error { background: #fef0ed; color: var(--red); }

.task-list { margin-top: 17px; display: grid; gap: 10px; }
.empty { padding: 28px 12px; text-align: center; color: var(--muted); border: 1px dashed #cbd4e2; border-radius: 9px; }
.task-row { width: 100%; padding: 13px; display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, .8fr) auto; gap: 12px; align-items: center; text-align: left; border: 1px solid var(--line); border-radius: 9px; background: #fff; color: inherit; }
.task-row:hover { border-color: #9aade8; background: #fafbff; }
.task-id { font-weight: 800; }
.task-meta { margin-top: 4px; color: var(--muted); font-size: 12px; }
.task-count { text-align: right; color: #526077; font-size: 12px; }
.detail-panel { margin-top: 18px; }
.detail-head { display: flex; justify-content: space-between; gap: 18px; align-items: flex-start; }
.detail-head h3 { margin: 5px 0 0; }
.metric-grid { margin: 18px 0; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.metric { padding: 13px; border-radius: 9px; background: #f6f8fc; }
.metric span { display: block; color: var(--muted); font-size: 12px; }
.metric strong { display: block; margin-top: 5px; font-size: 20px; }
.action-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.download-link { display: inline-flex; min-height: 40px; align-items: center; padding: 0 14px; border: 1px solid #c9d2e1; border-radius: 8px; color: var(--blue-dark); text-decoration: none; font-weight: 700; font-size: 13px; }
.confirm-form { margin-top: 16px; padding: 15px; display: grid; gap: 11px; border: 1px solid #f1d58b; border-radius: 9px; background: #fffaf0; }
.summary-box { margin: 15px 0; padding: 14px; border-radius: 9px; background: #f6f8fc; color: #344054; line-height: 1.7; }
.error-list { margin: 14px 0 0; padding-left: 20px; color: var(--red); font-size: 13px; }
.history-panel { margin-top: 18px; }
.history-panel summary { cursor: pointer; font-weight: 800; }

dialog { width: min(520px, calc(100% - 28px)); border: 0; border-radius: 14px; padding: 25px; color: var(--navy); box-shadow: 0 24px 80px #0c173955; }
dialog::backdrop { background: #10182899; backdrop-filter: blur(2px); }
dialog h2 { margin: 7px 0 0; }
.dialog-actions { margin-top: 20px; display: flex; justify-content: flex-end; gap: 10px; }

@media (max-width: 820px) {
  .company-grid, .workspace-grid { grid-template-columns: 1fr; }
  .company-card { min-height: 155px; }
  .metric-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 520px) {
  main { width: min(100% - 20px, 1180px); padding-top: 22px; }
  .topbar { padding-inline: 14px; }
  .topbar .eyebrow, .user-chip { display: none; }
  .date-grid { grid-template-columns: 1fr; }
  .task-row { grid-template-columns: 1fr auto; }
  .task-row .status { grid-column: 2; grid-row: 1; }
  .task-count { grid-column: 1 / -1; text-align: left; }
}
