:root {
  color-scheme: light;
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-muted: #f0f2f5;
  --border: #dfe3e8;
  --border-strong: #c9cfd7;
  --text: #171a21;
  --muted: #667080;
  --accent: #2864dc;
  --accent-hover: #1f52ba;
  --success: #1b7a4d;
  --warning: #946200;
  --danger: #b33a3a;
  --focus: #82a9f2;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; overflow-x: hidden; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: 14px; letter-spacing: 0; }
button, input, textarea, select { font: inherit; letter-spacing: 0; }
button, a { -webkit-tap-highlight-color: transparent; }
button:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--focus) 55%, transparent);
  outline-offset: 2px;
}
[hidden] { display: none !important; }
.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; }

.boot, .auth-gate { min-height: 100vh; display: grid; place-content: center; justify-items: center; gap: 14px; color: var(--muted); }
.spinner { width: 22px; height: 22px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.auth-gate h1 { margin: 6px 0 0; font-size: 22px; color: var(--text); }
.auth-gate p { margin: 0 0 8px; }
.auth-gate img { border-radius: 8px; }

.topbar { height: 58px; display: flex; align-items: center; justify-content: space-between; padding: 0 22px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20; }
.brand { display: flex; align-items: center; gap: 9px; color: var(--text); text-decoration: none; font-weight: 700; min-width: 0; }
.brand img { border-radius: 7px; }
.product-label { border-left: 1px solid var(--border); padding-left: 10px; color: var(--muted); font-weight: 500; }
.mode-badge { min-width: 58px; padding: 4px 7px; border: 1px solid #b8c9e9; border-radius: 999px; background: #f2f6ff; color: #31558f; font-size: 11px; font-weight: 700; text-align: center; }
.mode-badge.authenticated { border-color: #b9d9c8; background: #eff8f3; color: #286443; }
.top-actions { display: flex; align-items: center; gap: 8px; }
.locale-select { width: 72px; height: 34px; padding: 0 8px; border-color: var(--border); background: var(--surface); color: var(--muted); font-size: 12px; font-weight: 650; }
.balance { display: flex; align-items: baseline; gap: 7px; padding: 7px 10px; border-right: 1px solid var(--border); margin-right: 4px; color: var(--muted); font-size: 12px; }
.balance strong { color: var(--text); font-size: 14px; }
.account { display: flex; align-items: center; gap: 8px; margin-left: 4px; max-width: 180px; }
.account > span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.avatar { width: 30px; height: 30px; display: grid; place-items: center; flex: 0 0 auto; border-radius: 50%; background: #e8eddf; color: #3c5b31; font-size: 12px; font-weight: 700; }

.shell { display: grid; grid-template-columns: 188px minmax(0, 1fr); min-height: calc(100vh - 58px); }
.sidebar { border-right: 1px solid var(--border); background: #fafbfc; padding: 18px 12px; }
.nav-item { width: 100%; height: 38px; display: flex; align-items: center; gap: 10px; padding: 0 10px; border: 0; border-radius: 6px; background: transparent; color: var(--muted); cursor: pointer; }
.nav-item svg { width: 17px; height: 17px; }
.nav-item.active { background: #e9eef8; color: #173f91; font-weight: 650; }
.nav-item:disabled { opacity: .42; cursor: default; }

.content { min-width: 0; padding: 28px 32px 48px; max-width: 1500px; width: 100%; margin: 0 auto; }
.page-heading { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 22px; }
.page-heading h1 { margin: 0; font-size: 24px; line-height: 1.25; }
.page-heading p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.heading-actions { display: flex; align-items: center; gap: 8px; }

.button, .icon-button { border: 0; display: inline-flex; align-items: center; justify-content: center; text-decoration: none; cursor: pointer; }
.button { min-height: 38px; gap: 8px; border-radius: 6px; padding: 0 15px; font-weight: 650; }
.button.compact { min-height: 34px; padding: 0 11px; font-size: 12px; }
.help-link { white-space: nowrap; }
.button svg { width: 16px; height: 16px; }
.button.primary { background: var(--accent); color: #fff; }
.button.primary:hover { background: var(--accent-hover); }
.button.secondary { background: var(--surface-muted); color: var(--text); border: 1px solid var(--border); }
.button.warning { background: #fff3d5; color: #684800; border: 1px solid #e8c66c; }
.button.warning:hover { background: #ffe9ae; }
.button:disabled { opacity: .55; cursor: not-allowed; }
.icon-button { width: 36px; height: 36px; border-radius: 6px; color: var(--muted); background: transparent; }
.icon-button:hover { background: var(--surface-muted); color: var(--text); }
.icon-button.bordered { border: 1px solid var(--border); background: var(--surface); }
.icon-button svg { width: 17px; height: 17px; }

.notice { padding: 12px 14px; border: 1px solid; border-radius: 6px; margin-bottom: 18px; }
.notice.warning { color: #6e4b00; border-color: #e5c46c; background: #fff9e8; }
.notice.warning { display: flex; align-items: flex-start; gap: 9px; }
.notice.warning svg { width: 17px; height: 17px; flex: 0 0 auto; margin-top: 1px; }
.notice.preview { display: flex; align-items: center; justify-content: space-between; gap: 12px; color: #31558f; border-color: #b8c9e9; background: #f4f7fd; }
.notice.preview strong { color: #203f72; }
.composer { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; margin-bottom: 22px; }
.section-title { min-height: 62px; padding: 12px 16px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--border); }
.section-title h2 { margin: 0; font-size: 16px; }
.section-title span { display: block; margin-top: 4px; color: var(--muted); font-size: 12px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px 20px; padding: 20px; }
.field { min-width: 0; display: grid; align-content: start; gap: 7px; border: 0; padding: 0; margin: 0; }
.field > span, .field legend { color: #3d4654; font-size: 12px; font-weight: 650; }
.field-wide { grid-column: 1 / -1; }
.label-row { display: flex; justify-content: space-between; gap: 12px; }
input, textarea, select { width: 100%; border: 1px solid var(--border-strong); border-radius: 6px; background: #fff; color: var(--text); }
input, select { height: 38px; padding: 0 10px; }
textarea { min-height: 142px; padding: 10px 11px; resize: vertical; line-height: 1.5; }
input:hover, textarea:hover, select:hover { border-color: #aab2bd; }
.segmented { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; width: min(100%, 420px); height: 38px; border: 1px solid var(--border-strong); border-radius: 6px; padding: 3px; background: var(--surface-muted); }
.segment { border: 0; border-radius: 4px; background: transparent; color: var(--muted); cursor: pointer; }
.segment.active { background: #fff; color: var(--text); box-shadow: 0 1px 2px rgba(20, 28, 40, .12); font-weight: 650; }
.file-drop { min-height: 112px; display: grid; place-content: center; justify-items: center; gap: 6px; border: 1px dashed var(--border-strong); border-radius: 6px; background: #fafbfc; cursor: pointer; color: var(--muted); }
.file-drop:hover { border-color: var(--accent); background: #f5f8ff; }
.file-drop svg { width: 24px; height: 24px; color: var(--accent); }
.file-drop strong { color: var(--text); }
.file-drop span { font-size: 12px; }
.platform-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.platform-option { height: 40px; display: flex; align-items: center; gap: 9px; padding: 0 10px; border: 1px solid var(--border); border-radius: 6px; background: #fff; cursor: pointer; min-width: 0; }
.platform-option:hover { border-color: #aab2bd; }
.platform-option:has(input:checked) { border-color: #6e96e7; background: #f3f7ff; }
.platform-option:has(input:disabled) { opacity: .45; cursor: not-allowed; }
.platform-option input { width: 15px; height: 15px; margin: 0; accent-color: var(--accent); }
.platform-option span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.batch-control { display: grid; grid-template-columns: 92px minmax(0, 1fr); gap: 8px; }
.quick-values { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; }
.quick-values button { border: 1px solid var(--border); background: var(--surface-muted); border-radius: 5px; cursor: pointer; }
.quick-values button:hover { background: #e3e7ec; }
.composer-footer { min-height: 68px; padding: 12px 20px; border-top: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: 18px; }
.estimate { display: grid; grid-template-columns: auto auto auto; align-items: baseline; gap: 8px; color: var(--muted); font-size: 12px; }
.estimate strong { color: var(--text); font-size: 18px; }

.sample-label { display: inline-flex; align-items: center; margin-left: 7px; padding: 2px 5px; border: 1px solid #b8c9e9; border-radius: 4px; background: #f2f6ff; color: #31558f; font-size: 10px; font-weight: 700; text-transform: uppercase; vertical-align: 1px; }
.login-status { margin: 0 20px 14px; padding: 10px 12px; border: 1px solid #b8c9e9; border-radius: 6px; background: #f4f7fd; color: #31558f; }
.login-fallback { display: flex; gap: 8px; padding: 0 20px 14px; }

.jobs-section { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.admin-users-section { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.admin-metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1px; margin-bottom: 18px; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--border); }
.admin-metrics > div { min-height: 76px; padding: 14px 16px; background: var(--surface); }
.admin-metrics span { display: block; color: var(--muted); font-size: 11px; text-transform: uppercase; font-weight: 700; }
.admin-metrics strong { display: block; margin-top: 7px; font-size: 20px; }
.admin-users-table { min-width: 1480px; }
.admin-users-table td { height: 76px; line-height: 1.4; }
.admin-user-name { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 650; }
.admin-email { max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.billing-failures:not(:empty) { color: var(--danger); }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 850px; }
th { height: 42px; padding: 0 14px; background: #fafbfc; border-bottom: 1px solid var(--border); color: var(--muted); font-size: 11px; text-align: left; text-transform: uppercase; font-weight: 700; }
td { height: 58px; padding: 8px 14px; border-bottom: 1px solid #ebedf0; vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fafcff; }
.job-name { max-width: 310px; font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cell-muted { color: var(--muted); font-size: 12px; }
.status-badge { display: inline-flex; align-items: center; height: 24px; padding: 0 8px; border-radius: 5px; background: #edf0f4; color: #596372; font-size: 11px; font-weight: 700; text-transform: capitalize; white-space: nowrap; }
.status-badge.completed { color: #16603d; background: #e6f5ed; }
.status-badge.processing, .status-badge.pending, .status-badge.queued, .status-badge.submitting { color: #1c4e9c; background: #eaf1ff; }
.status-badge.partial_completed, .status-badge.needs_attention { color: #795300; background: #fff3d5; }
.status-badge.failed { color: #8f2f2f; background: #fbeaea; }
.status-badge.stopped { color: #684800; background: #fff3d5; }
.progress-cell { min-width: 130px; }
.progress-track { width: 92px; height: 5px; border-radius: 3px; background: #e5e8ed; overflow: hidden; display: inline-block; vertical-align: middle; margin-right: 7px; }
.progress-value { height: 100%; background: var(--success); }
.empty-state { min-height: 230px; display: grid; place-content: center; justify-items: center; color: var(--muted); }
.empty-state svg { width: 28px; height: 28px; }
.empty-state h2 { margin: 10px 0 0; font-size: 15px; color: var(--text); }

.dialog { border: 0; padding: 0; border-radius: 8px; width: min(620px, calc(100vw - 28px)); box-shadow: 0 24px 70px rgba(20, 28, 40, .25); }
.dialog::backdrop { background: rgba(17, 24, 34, .48); }
.dialog-panel { margin: 0; }
.dialog-header { padding: 18px 20px; display: flex; justify-content: space-between; gap: 14px; border-bottom: 1px solid var(--border); }
.dialog-header h2 { margin: 0; font-size: 18px; }
.dialog-header p { margin: 4px 0 0; color: var(--muted); }
.review-grid { display: grid; grid-template-columns: repeat(3, 1fr); margin: 0; padding: 20px; gap: 18px; }
.review-grid div { min-width: 0; }
.review-grid dt { color: var(--muted); font-size: 11px; text-transform: uppercase; font-weight: 700; }
.review-grid dd { margin: 5px 0 0; font-size: 17px; font-weight: 700; }
.dialog-actions { padding: 14px 20px; display: flex; justify-content: flex-end; gap: 8px; border-top: 1px solid var(--border); }
.dialog-copy { padding: 20px; color: var(--text); font-size: 14px; line-height: 1.55; }

.drawer { position: fixed; inset: 0; z-index: 50; pointer-events: none; visibility: hidden; overflow: hidden; contain: layout paint; }
.drawer.open { pointer-events: auto; visibility: visible; }
.drawer-backdrop { position: absolute; inset: 0; background: rgba(17, 24, 34, .36); opacity: 0; transition: opacity .18s ease; }
.drawer.open .drawer-backdrop { opacity: 1; }
.drawer-panel { position: absolute; top: 0; right: 0; width: min(720px, 100vw); height: 100%; background: var(--surface); transform: translateX(100%); transition: transform .2s ease; overflow: hidden; display: grid; grid-template-rows: auto auto 1fr; }
.drawer.open .drawer-panel { transform: translateX(0); }
.drawer-header { min-height: 70px; padding: 14px 18px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.drawer-header h2 { margin: 0; font-size: 18px; }
.drawer-header p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.drawer-actions { display: flex; align-items: center; gap: 8px; }
.menu-wrap { position: relative; }
.menu { position: absolute; right: 0; top: calc(100% + 6px); z-index: 5; width: 190px; padding: 5px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); box-shadow: 0 12px 30px rgba(17, 24, 34, .14); }
.menu button { width: 100%; min-height: 36px; display: flex; align-items: center; gap: 9px; border: 0; border-radius: 4px; padding: 0 10px; background: transparent; color: var(--text); cursor: pointer; text-align: left; }
.menu button:hover { background: var(--surface-muted); }
.menu svg { width: 15px; height: 15px; }
.drawer-summary { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1px; background: var(--border); border-bottom: 1px solid var(--border); }
.drawer-summary > div { padding: 12px 16px; background: #fafbfc; }
.drawer-summary span { display: block; color: var(--muted); font-size: 10px; text-transform: uppercase; font-weight: 700; }
.drawer-summary strong { display: block; margin-top: 4px; font-size: 15px; }
.drawer-body { position: relative; overflow: auto; padding: 18px; }
.drawer-body > h3 { margin: 0 0 10px; font-size: 13px; }
.run-list { display: grid; gap: 7px; }
.run-row { min-height: 54px; display: grid; grid-template-columns: minmax(0, 1fr) auto auto; align-items: center; gap: 12px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px; }
.run-row h4 { margin: 0; font-size: 13px; }
.run-row p { margin: 4px 0 0; color: var(--muted); font-size: 11px; }
.run-row .button { min-height: 32px; padding: 0 10px; font-size: 12px; }
.result-panel { position: absolute; inset: 0; background: var(--surface); padding: 18px; overflow: auto; }
.result-heading { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.result-heading h3 { margin: 0; font-size: 15px; }
.result-item { padding: 14px 0; border-bottom: 1px solid var(--border); }
.result-item:last-child { border-bottom: 0; }
.result-item header { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 9px; }
.result-item h4 { margin: 0; font-size: 13px; }
.result-answer { white-space: pre-wrap; line-height: 1.55; color: #323947; }
.result-references { margin: 10px 0 0; padding-left: 18px; }
.result-references a { color: var(--accent); overflow-wrap: anywhere; }

.toast { position: fixed; right: 20px; bottom: 20px; z-index: 100; max-width: min(420px, calc(100vw - 40px)); padding: 12px 14px; border-radius: 6px; background: #202632; color: #fff; box-shadow: 0 12px 30px rgba(20, 28, 40, .25); }
.toast.error { background: #8e3030; }

@media (max-width: 900px) {
  .shell { grid-template-columns: 58px minmax(0, 1fr); }
  .sidebar { padding: 14px 9px; }
  .nav-item { justify-content: center; padding: 0; }
  .nav-item span { display: none; }
  .content { padding: 22px 18px 40px; }
  .platform-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .admin-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 640px) {
  .switch-account span { display: none; }
  .topbar { padding: 0 12px; }
  .brand > span:first-of-type, .product-label, .balance span, .account > span:last-child { display: none; }
  .mode-badge { min-width: 54px; }
  .locale-select { width: 64px; }
  .balance { padding-left: 4px; }
  .shell { display: block; }
  .sidebar { display: none; }
  .content { padding: 18px 12px 40px; }
  .page-heading h1 { font-size: 21px; }
  .form-grid { grid-template-columns: 1fr; padding: 16px; }
  .field-wide { grid-column: auto; }
  .platform-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .composer-footer { align-items: stretch; flex-direction: column; }
  .notice.preview { align-items: flex-start; flex-direction: column; }
  .login-fallback { flex-direction: column; }
  .composer-footer .button { width: 100%; }
  .review-grid { grid-template-columns: repeat(2, 1fr); }
  .drawer-summary { grid-template-columns: repeat(2, 1fr); }
  .drawer-header { align-items: flex-start; }
  .drawer-actions { flex-wrap: wrap; justify-content: flex-end; }
  #stop-and-export span { display: none; }
  .run-row { grid-template-columns: minmax(0, 1fr) auto; }
  .run-row .button { grid-column: 1 / -1; }
  .jobs-table { min-width: 0; table-layout: fixed; }
  .jobs-table th, .jobs-table td { padding-left: 8px; padding-right: 8px; }
  .jobs-table th:nth-child(4), .jobs-table th:nth-child(5), .jobs-table th:nth-child(6),
  .jobs-table td:nth-child(4), .jobs-table td:nth-child(5), .jobs-table td:nth-child(6) { display: none; }
  .jobs-table th:nth-child(1) { width: 39%; }
  .jobs-table th:nth-child(2) { width: 27%; }
  .jobs-table th:nth-child(3) { width: 24%; }
  .jobs-table th:nth-child(7) { width: 10%; }
  .jobs-table th:nth-child(7), .jobs-table td:nth-child(7) { padding-left: 0; padding-right: 0; }
  .admin-metrics { grid-template-columns: 1fr; }
  .progress-cell { min-width: 0; }
  .progress-track { display: none; }
}

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