:root {
  --canvas: #f3f5f8;
  --surface: #ffffff;
  --surface-soft: #f7f9fc;
  --ink: #172033;
  --muted: #5b6678;
  --border: #dce2ea;
  --border-strong: #c7d0dc;
  --blue: #2457a6;
  --blue-dark: #1c4687;
  --blue-soft: #eaf1fb;
  --navy: #112b62;
  --navy-deep: #0c204a;
  --success: #176448;
  --success-soft: #e5f5ed;
  --warning: #7a4a10;
  --warning-soft: #fff1da;
  --error: #963442;
  --error-soft: #fce9ec;
  --radius-card: 14px;
  --radius-control: 9px;
  --font: "Segoe UI", "SF Pro Text", -apple-system, BlinkMacSystemFont, sans-serif;
}

* { box-sizing: border-box; }
html { background: var(--canvas); color: var(--ink); font-family: var(--font); }
body { margin: 0; min-width: 320px; background: var(--canvas); font-size: 16px; }
button, input { font: inherit; }
body.modal-open { overflow: hidden; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .58; }
::selection { background: #c9daf5; color: #10264d; }
:focus-visible { outline: 3px solid rgba(36, 87, 166, .32); outline-offset: 2px; }
.skip-link { position: fixed; z-index: 100; top: 8px; left: 8px; padding: 10px 14px; background: #fff; color: var(--blue); transform: translateY(-150%); }
.skip-link:focus { transform: translateY(0); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 292px minmax(0, 1fr); transition: grid-template-columns .22s cubic-bezier(.16,1,.3,1); }
.app-shell.sidebar-collapsed { grid-template-columns: 78px minmax(0, 1fr); }
.batch-rail { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; padding: 22px 16px 18px; color: #eef4ff; background: var(--navy-deep); }
.brand-block { display: flex; align-items: center; gap: 11px; padding: 0 4px 24px; border-bottom: 1px solid rgba(255,255,255,.14); }
.brand-mark { display: grid; place-items: center; width: 40px; height: 40px; flex: 0 0 auto; border-radius: 11px; background: #fff; }
.brand-mark img { width: 32px; height: 32px; display: block; }
.brand-block strong, .brand-block span { display: block; }
.brand-block strong { font-size: 16px; white-space: nowrap; }
.brand-block span { margin-top: 2px; color: #b9c9e9; font-size: 13px; }
.sidebar-toggle { display: grid; place-items: center; width: 38px; height: 38px; margin-left: auto; border: 1px solid rgba(255,255,255,.18); border-radius: 10px; color: #e8f0ff; background: rgba(255,255,255,.08); }
.sidebar-toggle:hover { background: rgba(255,255,255,.15); }
.sidebar-toggle svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; transition: transform .22s cubic-bezier(.16,1,.3,1); }
.sidebar-collapsed .sidebar-toggle svg { transform: rotate(180deg); }
.sidebar-collapsed .batch-rail { padding-inline: 10px; }
.sidebar-collapsed .brand-copy,
.sidebar-collapsed .rail-heading h2,
.sidebar-collapsed .rail-add,
.sidebar-collapsed .batch-item span,
.sidebar-collapsed .batch-item small,
.sidebar-collapsed .rail-foot { display: none; }
.sidebar-collapsed .brand-block { justify-content: center; gap: 4px; padding-inline: 0; }
.sidebar-collapsed .brand-mark { width: 30px; height: 30px; }
.sidebar-collapsed .brand-mark img { width: 24px; height: 24px; }
.sidebar-collapsed .sidebar-toggle { width: 20px; height: 30px; margin-left: 0; border: 0; background: transparent; }
.sidebar-collapsed .rail-heading { justify-content: center; min-height: 32px; padding-inline: 0; }
.sidebar-collapsed .batch-item { place-items: center; padding: 12px 4px; }
.sidebar-collapsed .batch-item strong { font-size: 0; }
.sidebar-collapsed .batch-item strong::after { content: attr(data-short); font-size: 13px; }
.rail-heading { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 24px 6px 12px; }
.rail-heading h2 { margin: 0; font-size: 14px; font-weight: 700; }
.rail-add { min-height: 34px; border: 0; padding: 5px 9px; border-radius: 7px; color: #dce8ff; background: rgba(255,255,255,.09); font-size: 13px; font-weight: 700; }
.rail-add:hover { background: rgba(255,255,255,.16); }
.batch-list { display: grid; gap: 8px; }
.batch-item { width: 100%; display: grid; gap: 4px; padding: 12px; border: 1px solid transparent; border-radius: 11px; color: #dce7fa; background: transparent; text-align: left; }
.batch-item:hover { background: rgba(255,255,255,.07); }
.batch-item.is-active { border-color: rgba(255,255,255,.18); background: rgba(255,255,255,.13); color: #fff; }
.batch-item strong { font-size: 14px; }
.batch-item span { color: #b9c9e9; font-size: 13px; line-height: 1.4; }
.batch-item small { justify-self: start; margin-top: 3px; padding: 4px 7px; border-radius: 999px; color: #cfe2ff; background: rgba(98, 154, 238, .18); font-size: 12px; }
.rail-foot { margin-top: auto; padding: 14px; border-radius: 11px; background: rgba(255,255,255,.07); }
.rail-foot strong { font-size: 13px; }
.rail-foot p { margin: 6px 0 0; color: #b9c9e9; font-size: 13px; line-height: 1.5; }

.workspace { min-width: 0; padding: 0 32px 48px; }
.topbar { min-height: 64px; display: flex; align-items: center; justify-content: space-between; gap: 16px; color: var(--muted); border-bottom: 1px solid var(--border); font-size: 14px; }
.workspace-label { color: var(--ink); font-weight: 700; }
.separator { padding: 0 7px; color: #9aa5b5; }
.operator { display: flex; align-items: center; gap: 8px; color: var(--ink); font-weight: 650; }
.operator-dot { width: 8px; height: 8px; border-radius: 50%; background: #3aa475; box-shadow: 0 0 0 3px #dff3e9; }
.notice { margin-top: 20px; display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 12px 14px; border: 1px solid #efcf9d; border-radius: 11px; color: #684214; background: #fff8e9; }
.notice strong, .notice span { display: block; }
.notice strong { font-size: 14px; }
.notice div span { margin-top: 3px; color: #795d34; font-size: 13px; }
.notice-tag { flex: 0 0 auto; padding: 6px 9px; border-radius: 999px; background: #f5dfb8; font-size: 12px; font-weight: 800; letter-spacing: .04em; }
.page-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; padding: 28px 0 22px; }
.page-heading h1 { margin: 0; font-size: 34px; line-height: 1.15; letter-spacing: -.025em; }
.page-heading p { max-width: 720px; margin: 9px 0 0; color: var(--muted); font-size: 15px; line-height: 1.55; }
.heading-actions, .candidate-actions { display: flex; gap: 9px; }
.button { min-height: 44px; padding: 0 16px; border-radius: var(--radius-control); font-size: 14px; font-weight: 750; transition: background-color .18s ease, border-color .18s ease, transform .18s ease; }
.button:active { transform: translateY(1px); }
.button.primary { border: 1px solid var(--blue); color: #fff; background: var(--blue); }
.button.primary:hover { border-color: var(--blue-dark); background: var(--blue-dark); }
.button.secondary { border: 1px solid var(--border-strong); color: var(--ink); background: #fff; }
.button.secondary:hover { border-color: #9bb0cd; background: #f8fbff; }

.workflow-steps { display: grid; grid-template-columns: repeat(3, 1fr); margin: 0 0 18px; padding: 0; list-style: none; border: 1px solid var(--border); border-radius: var(--radius-card); background: #fff; overflow: hidden; }
.workflow-steps li { position: relative; display: flex; align-items: center; gap: 10px; padding: 13px 16px; border-right: 1px solid var(--border); }
.workflow-steps li:last-child { border-right: 0; }
.workflow-steps li > span { display: grid; place-items: center; width: 30px; height: 30px; flex: 0 0 auto; border-radius: 50%; color: var(--muted); background: #edf1f5; font-size: 13px; font-weight: 800; }
.workflow-steps strong, .workflow-steps small { display: block; }
.workflow-steps strong { font-size: 14px; }
.workflow-steps small { margin-top: 3px; color: var(--muted); font-size: 12px; }
.workflow-steps .is-complete > span { color: var(--success); background: var(--success-soft); }
.workflow-steps .is-current { background: #f5f8fd; }
.workflow-steps .is-current > span { color: #fff; background: var(--blue); }

.terms-section, .candidate-section, .result-section { margin-top: 18px; border: 1px solid var(--border); border-radius: var(--radius-card); background: var(--surface); overflow: hidden; }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 17px 20px; background: var(--surface-soft); border-bottom: 1px solid var(--border); }
.section-heading h2 { margin: 0; font-size: 19px; letter-spacing: -.01em; }
.section-title, .candidate-title-group { display: flex; align-items: center; gap: 12px; min-width: 0; }
.section-number { display: grid; place-items: center; width: 34px; height: 34px; flex: 0 0 auto; border-radius: 8px; color: var(--blue); background: var(--blue-soft); font-size: 12px; font-weight: 700; }
.required-note { color: var(--muted); font-size: 12px; }
.batch-title-field { display: grid; gap: 6px; max-width: 440px; padding: 20px 20px 0; }
.batch-title-field label, .modal-body label { display: block; font-size: 13px; font-weight: 600; }
.batch-title-field label span, .modal-body label span { color: var(--error); }
.batch-title-field small, .modal-body small { color: var(--muted); font-size: 12px; }
.field-error { min-height: 0; color: var(--error); font-size: 12px; }
.field-error:empty { display: none; }
.section-heading p { margin: 5px 0 0; color: var(--muted); font-size: 14px; line-height: 1.5; }
.pack-id { flex: 0 0 auto; color: var(--blue); font-size: 13px; font-weight: 500; }
.generated-actions { display: flex; gap: 9px; }
.terms-grid { display: grid; grid-template-columns: repeat(3, minmax(170px, 1fr)); gap: 16px 18px; padding: 20px; }
label { display: grid; gap: 7px; color: var(--ink); font-size: 13px; font-weight: 500; }
input { width: 100%; min-height: 44px; padding: 9px 11px; border: 1px solid var(--border-strong); border-radius: var(--radius-control); color: var(--ink); background: #fff; font-size: 14px; font-weight: 400; }
input:hover { border-color: #9fb1c8; }
input:focus { border-color: var(--blue); outline: 3px solid rgba(36,87,166,.14); }
input[aria-invalid="true"] { border-color: var(--error); background: #fffafb; }
.inline-errors { padding: 0 20px 16px; color: var(--error); font-size: 13px; }
.inline-errors ul { margin: 0; padding-left: 18px; }

.csv-guidance { margin: 16px 20px 0; padding: 13px 14px; border: 1px solid #cfdcf0; border-radius: 11px; color: #273b5c; background: #f2f6fc; }
.csv-guidance strong { font-size: 14px; }
.csv-guidance p { margin: 6px 0 9px; color: #52647f; font-size: 13px; line-height: 1.5; }
.csv-guidance code { display: block; overflow-x: auto; padding: 9px 11px; border-radius: 7px; color: #33435a; background: #fff; font-size: 12px; }
.table-wrap { overflow-x: auto; }
.candidate-table { width: 100%; min-width: 1320px; border-collapse: collapse; table-layout: fixed; }
.selection-column { width: 46px; }
.candidate-table th:first-child, .candidate-table td:first-child { width: 46px; text-align: center; }
.candidate-table input[type="checkbox"] { width: 17px; height: 17px; min-height: 17px; padding: 0; accent-color: var(--blue); cursor: pointer; }
.candidate-table th { padding: 12px; color: var(--muted); background: #fff; border-bottom: 1px solid var(--border); text-align: left; font-size: 12px; font-weight: 500; }
.candidate-table td { padding: 12px; border-bottom: 1px solid #e8edf3; vertical-align: top; }
.candidate-table tbody tr:last-child td { border-bottom: 0; }
.candidate-table tbody tr[data-status="error"] { background: #fffafb; }
.candidate-table tbody tr[data-status="manually-edited"] { background: #fffdf8; }
.candidate-table input { min-height: 40px; padding: 7px 9px; font-size: 13px; }
.candidate-column { width: 450px; }
.candidate-primary { display: grid; gap: 7px; }
.candidate-primary .name { font-weight: 700; }
.file-name-row { display: grid; grid-template-columns: max-content minmax(0, 1fr); align-items: center; gap: 8px; color: var(--muted); font-size: 12px; font-weight: 500; }
.candidate-primary .file-name { min-width: 0; color: var(--muted); font-size: 12px; }
.status-cell { min-width: 164px; }
.status-pill { display: inline-flex; align-items: center; gap: 6px; padding: 6px 9px; border-radius: 999px; font-size: 12px; font-weight: 500; }
.status-pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.status-pill.ready { color: var(--success); background: var(--success-soft); }
.status-pill.manually-edited { color: var(--warning); background: var(--warning-soft); }
.status-pill.error { color: var(--error); background: var(--error-soft); }
.row-messages { display: grid; gap: 4px; margin-top: 8px; color: var(--muted); font-size: 12px; line-height: 1.4; }
.row-messages .error-text { color: var(--error); }
.row-messages .manual-edit-text { color: var(--warning); }
.action-column { width: 42px; }
.candidate-table th:last-child, .candidate-table td:last-child { width: 42px; padding-left: 0; padding-right: 8px; text-align: right; }
.remove-button { display: grid; place-items: center; width: 30px; min-height: 30px; margin-left: auto; border: 0; padding: 4px; border-radius: 6px; color: var(--muted); background: transparent; }
.remove-button:hover { color: var(--error); background: var(--error-soft); }
.remove-button i { font-size: 14px; line-height: 1; }
.validation-bar { display: flex; align-items: center; padding: 14px 20px; border-top: 1px solid var(--border); background: var(--surface-soft); }
.status-counts { display: flex; flex-wrap: wrap; gap: 8px; }
.count-chip { padding: 6px 9px; border-radius: 999px; font-size: 12px; font-weight: 500; }
.count-chip.ready { color: var(--success); background: var(--success-soft); }
.count-chip.manually-edited { color: var(--warning); background: var(--warning-soft); }
.count-chip.error { color: var(--error); background: var(--error-soft); }
.selection-summary { padding: 11px 20px; border-top: 1px solid var(--border); color: var(--muted); background: var(--surface-soft); font-size: 12px; }

.modal-backdrop { position: fixed; inset: 0; z-index: 90; display: grid; place-items: center; padding: 20px; background: rgba(12, 32, 74, .45); }
.modal-backdrop[hidden] { display: none; }
.confirm-dialog { position: relative; width: min(100%, 480px); border: 1px solid var(--border); border-radius: 15px; background: #fff; box-shadow: 0 24px 70px rgba(11, 29, 61, .25); }
.modal-close { position: absolute; right: 14px; top: 10px; width: 32px; height: 32px; border: 0; border-radius: 7px; color: var(--muted); background: transparent; font-size: 24px; line-height: 1; }
.modal-close:hover { background: var(--surface-soft); }
.modal-heading { display: flex; gap: 14px; align-items: center; padding: 28px 26px 22px; }
.modal-icon { display: grid; place-items: center; width: 56px; height: 56px; flex: 0 0 auto; border-radius: 50%; color: var(--blue); background: var(--blue-soft); font-size: 24px; }
.modal-heading h2 { margin: 0; color: var(--navy); font-size: 20px; }
.modal-heading p { margin: 6px 0 0; color: var(--muted); font-size: 12px; line-height: 1.45; }
.modal-body { display: grid; gap: 7px; padding: 0 26px 22px; }
.confirmation-summary { display: grid; gap: 13px; margin-top: 14px; padding: 16px; border-radius: 9px; background: #f3f7fc; font-size: 12px; }
.confirmation-summary div { display: grid; grid-template-columns: 130px 1fr; gap: 8px; }
.confirmation-summary span { color: var(--muted); }
.confirmation-summary strong { color: var(--navy); font-weight: 600; }
.modal-actions { display: flex; justify-content: flex-end; gap: 9px; padding: 18px 26px; border-top: 1px solid var(--border); }

.progress-block { padding: 18px 20px 2px; }
.progress-block > div:first-child { display: flex; justify-content: space-between; color: var(--muted); font-size: 13px; }
.progress-block strong { color: var(--ink); }
.progress-track { height: 8px; margin-top: 9px; overflow: hidden; border-radius: 999px; background: #e5eaf0; }
.progress-track span { display: block; width: 0; height: 100%; background: var(--blue); transition: width .45s cubic-bezier(.16,1,.3,1); }
.result-list { display: grid; }
.result-row { display: grid; grid-template-columns: minmax(280px, 1.25fr) 145px minmax(240px, 1fr) auto; gap: 18px; align-items: center; padding: 16px 20px; border-top: 1px solid #e8edf3; font-size: 13px; }
.result-row:first-child { border-top: 0; }
.result-row strong, .result-row span { display: block; }
.result-row strong { overflow-wrap: anywhere; font-size: 14px; }
.result-row small { margin-top: 4px; color: var(--muted); font-size: 12px; }
.result-row p { margin: 0; color: var(--muted); line-height: 1.45; }
.result-status { justify-self: start; padding: 6px 9px; border-radius: 999px; font-size: 12px; font-weight: 500; }
.result-status.draft-ready { color: var(--success); background: var(--success-soft); }
.result-status.failed { color: var(--error); background: var(--error-soft); }
.result-status.not-generated { color: var(--muted); background: #edf1f5; }
.download-button { min-width: 108px; border: 1px solid var(--blue); color: var(--blue); background: #fff; }
.download-button:hover:not(:disabled) { color: #fff; background: var(--blue); }
.download-button:disabled { border-color: var(--border-strong); color: #8b95a4; background: #f3f5f7; }
.download-control { position: relative; justify-self: end; cursor: not-allowed; }
.download-control .download-button { pointer-events: none; }
.download-tooltip { position: absolute; right: 0; bottom: calc(100% + 8px); z-index: 2; width: max-content; max-width: 220px; padding: 8px 10px; border-radius: 7px; color: #fff; background: #172033; box-shadow: 0 6px 16px rgba(0,0,0,.18); font-size: 12px; line-height: 1.35; opacity: 0; pointer-events: none; transform: translateY(3px); transition: opacity .15s ease, transform .15s ease; }
.download-control:hover .download-tooltip, .download-control:focus .download-tooltip { opacity: 1; transform: translateY(0); }
.toast { position: fixed; right: 24px; bottom: 24px; z-index: 50; max-width: 400px; padding: 13px 15px; border-radius: 10px; color: #fff; background: #172033; box-shadow: 0 10px 28px rgba(0,0,0,.18); font-size: 14px; }

@media (max-width: 1180px) {
  .terms-grid { grid-template-columns: repeat(2, minmax(180px, 1fr)); }
  .workflow-steps small { display: none; }
  .candidate-title-group { flex-wrap: wrap; }
}

@media (max-width: 820px) {
  .app-shell { grid-template-columns: 1fr; }
  .app-shell.sidebar-collapsed { grid-template-columns: 1fr; }
  .batch-rail { position: static; height: auto; padding: 16px; }
  .sidebar-collapsed .batch-rail { padding: 16px; }
  .brand-block { padding-bottom: 14px; }
  .sidebar-toggle { display: none; }
  .sidebar-collapsed .brand-copy,
  .sidebar-collapsed .rail-heading h2,
  .sidebar-collapsed .rail-add,
  .sidebar-collapsed .batch-item span,
  .sidebar-collapsed .batch-item small { display: block; }
  .sidebar-collapsed .brand-block { justify-content: flex-start; gap: 11px; }
  .sidebar-collapsed .brand-mark { width: 40px; height: 40px; }
  .sidebar-collapsed .brand-mark img { width: 32px; height: 32px; }
  .sidebar-collapsed .batch-item { place-items: initial; padding: 12px; }
  .sidebar-collapsed .batch-item strong { font-size: 14px; }
  .sidebar-collapsed .batch-item strong::after { content: none; }
  .rail-heading { padding-top: 16px; }
  .batch-list { grid-template-columns: repeat(3, minmax(180px, 1fr)); overflow-x: auto; padding-bottom: 4px; }
  .rail-foot { display: none; }
  .workspace { padding: 0 18px 36px; }
  .page-heading { align-items: flex-start; flex-direction: column; }
  .result-row { grid-template-columns: minmax(0, 1fr) auto; }
  .result-row .contract-file { grid-column: 1; grid-row: 1; }
  .result-row .result-status { grid-column: 1; grid-row: 2; }
  .result-row p { grid-column: 1; grid-row: 3; }
  .result-row .download-button { grid-column: 2; grid-row: 1/4; align-self: center; }
}

@media (max-width: 620px) {
  .topbar { align-items: flex-start; flex-direction: column; justify-content: center; padding: 12px 0; }
  .notice { align-items: flex-start; }
  .notice-tag { display: none; }
  .page-heading h1 { font-size: 30px; }
  .heading-actions, .candidate-actions, .generated-actions { width: 100%; }
  .heading-actions .button, .candidate-actions .button, .generated-actions .button { flex: 1; }
  .workflow-steps { grid-template-columns: 1fr; }
  .workflow-steps li { border-right: 0; border-bottom: 1px solid var(--border); }
  .workflow-steps li:last-child { border-bottom: 0; }
  .terms-grid { grid-template-columns: 1fr; }
  .candidate-title-group { align-items: flex-start; flex-direction: column; }
  .section-heading { align-items: flex-start; flex-direction: column; }
  .pack-id { align-self: flex-start; }
  .candidate-table { min-width: 0; }
  .candidate-table thead { display: none; }
  .candidate-table, .candidate-table tbody, .candidate-table tr, .candidate-table td { display: block; width: 100%; }
  .candidate-table tr { padding: 8px 14px 14px; border-bottom: 1px solid var(--border); }
  .candidate-table tr:last-child { border-bottom: 0; }
  .candidate-table td { display: grid; grid-template-columns: 108px minmax(0, 1fr); gap: 10px; padding: 8px 0; border: 0; }
  .candidate-table td::before { content: attr(data-label); color: var(--muted); font-size: 12px; font-weight: 500; }
  .candidate-table td:last-child { display: flex; justify-content: flex-end; }
  .candidate-table td:first-child { display: flex; justify-content: flex-start; width: 100%; }
  .validation-bar { align-items: stretch; flex-direction: column; }
  .result-row { grid-template-columns: 1fr; gap: 7px; }
  .result-row .contract-file,
  .result-row .result-status,
  .result-row p,
  .result-row .download-button { grid-column: 1; grid-row: auto; }
  .result-row .download-button { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; }
}
