:root {
  --bg: #ffffff;
  --surface: #ffffff;
  --soft: #f6f7f9;
  --soft-2: #eef1f4;
  --border: #e1e5ea;
  --text: #17202a;
  --muted: #6d7785;
  --accent: #1769e0;
  --accent-hover: #0f5bc8;
  --accent-soft: #edf5ff;
  --success: #198754;
  --danger: #c53434;
  --danger-soft: #fff1f1;
  --shadow: 0 8px 30px rgba(25, 40, 60, .07);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.45; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.login-page { min-height: 100vh; display: grid; place-items: center; background: #fafbfc; }
.login-shell { width: 100%; padding: 24px; }
.login-card { width: min(420px, 100%); margin: 0 auto; padding: 34px; border: 1px solid var(--border); border-radius: 18px; background: #fff; box-shadow: var(--shadow); }
.login-card h1 { margin: 18px 0 4px; font-size: 26px; }
.login-card .muted { margin: 0 0 24px; }
.brand-mark { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 12px; background: var(--accent); color: #fff; font-weight: 800; font-size: 20px; }
.brand-mark.small { width: 34px; height: 34px; border-radius: 9px; font-size: 16px; }
.login-form { display: grid; gap: 16px; }
.login-form label, .field-label { display: grid; gap: 7px; font-weight: 650; font-size: 13px; }
.input, .select, .login-form input, .article-input { width: 100%; border: 1px solid #cfd5dc; border-radius: 10px; background: #fff; color: var(--text); outline: none; transition: .15s border-color, .15s box-shadow; }
.input, .select, .login-form input { height: 44px; padding: 0 12px; }
.article-input { min-height: 188px; resize: vertical; padding: 12px; line-height: 1.55; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.input:focus, .select:focus, .login-form input:focus, .article-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(23,105,224,.12); }
.button { min-height: 42px; border-radius: 10px; border: 1px solid transparent; padding: 0 16px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; font-weight: 700; transition: .15s; }
.button:disabled { opacity: .5; cursor: not-allowed; }
.button-primary { background: var(--accent); color: white; }
.button-primary:hover:not(:disabled) { background: var(--accent-hover); }
.button-ghost { background: #fff; border-color: var(--border); color: #394555; }
.button-ghost:hover { background: var(--soft); }
.button-wide { width: 100%; }
.button.compact { min-height: 36px; padding: 0 12px; font-size: 13px; }
.link-button { border: 0; background: none; padding: 0; color: var(--accent); font-weight: 650; }
.alert { padding: 11px 13px; border-radius: 9px; margin: 12px 0; font-size: 14px; }
.alert-error { background: var(--danger-soft); color: #9d2626; border: 1px solid #ffd6d6; }
.topbar { border-bottom: 1px solid var(--border); background: rgba(255,255,255,.96); position: sticky; top: 0; z-index: 10; }
.topbar-inner { width: min(1280px, calc(100% - 40px)); min-height: 66px; margin: 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.brand-inline, .topbar-actions { display: flex; align-items: center; gap: 11px; }
.brand-inline > div:last-child { display: grid; }
.brand-inline span { color: var(--muted); font-size: 11px; }
.user-label { color: var(--muted); font-size: 13px; }
.page-shell { width: min(1280px, calc(100% - 40px)); margin: 0 auto; padding: 34px 0 60px; }
.page-shell.narrow { width: min(760px, calc(100% - 40px)); }
.page-heading { display: flex; justify-content: space-between; gap: 20px; align-items: flex-start; margin-bottom: 24px; }
.page-heading h1 { margin: 0 0 6px; font-size: 30px; letter-spacing: -.02em; }
.page-heading p { margin: 0; color: var(--muted); max-width: 720px; }
.source-strip { display: grid; grid-template-columns: minmax(260px, 350px) minmax(260px, 1fr); gap: 12px; margin-bottom: 18px; }
.source-card, .source-placeholder { min-height: 76px; border: 1px solid var(--border); border-radius: 14px; padding: 14px 16px; display: flex; align-items: center; gap: 13px; background: #fff; text-align: left; }
.source-card.active { border-color: #9cc4ff; box-shadow: inset 0 0 0 1px #d7e9ff; }
.source-icon { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 10px; background: var(--accent-soft); color: var(--accent); font-weight: 800; }
.source-card > span:nth-child(2), .source-placeholder > div { display: grid; gap: 2px; flex: 1; }
.source-card small, .source-placeholder small { color: var(--muted); }
.status-dot { display: inline-flex; align-items: center; gap: 6px; color: var(--success); font-size: 12px; font-weight: 700; }
.status-dot i { width: 7px; height: 7px; border-radius: 50%; background: var(--success); }
.source-placeholder { color: #778291; background: #fbfcfd; }
.source-placeholder > span { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 10px; background: var(--soft-2); font-size: 23px; }
.workspace-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.panel { border: 1px solid var(--border); border-radius: 14px; background: var(--surface); padding: 20px; }
.panel-title { display: flex; gap: 12px; align-items: flex-start; margin-bottom: 16px; }
.panel-title h2 { margin: 0 0 3px; font-size: 18px; }
.panel-title p { margin: 0; color: var(--muted); font-size: 13px; }
.step-badge { flex: 0 0 auto; width: 27px; height: 27px; display: grid; place-items: center; border-radius: 8px; background: var(--soft-2); color: #4c5968; font-weight: 800; font-size: 12px; }
.input-meta { min-height: 28px; display: flex; justify-content: space-between; align-items: end; color: var(--muted); font-size: 12px; }
.segmented { display: grid; grid-template-columns: repeat(3, 1fr); background: var(--soft); padding: 3px; border-radius: 10px; margin-bottom: 16px; }
.segment { border: 0; background: transparent; min-height: 36px; border-radius: 8px; color: #596574; font-weight: 700; }
.segment.active { background: #fff; color: var(--text); box-shadow: 0 1px 4px rgba(20,30,45,.10); }
.region-loading, .all-regions-note { color: var(--muted); font-size: 13px; padding: 12px 0; }
.region-toolbar { display: grid; grid-template-columns: 1fr auto auto; gap: 8px; margin-bottom: 10px; }
.region-checklist { border: 1px solid var(--border); border-radius: 10px; max-height: 200px; overflow: auto; padding: 6px; }
.region-option { display: flex; align-items: center; gap: 9px; min-height: 36px; padding: 0 8px; border-radius: 7px; }
.region-option:hover { background: var(--soft); }
.region-option input { accent-color: var(--accent); }
.action-panel { margin-top: 18px; border: 1px solid var(--border); border-radius: 14px; padding: 17px 20px; display: flex; align-items: center; justify-content: space-between; gap: 20px; background: #fbfcfd; }
.action-panel > div:first-child { display: grid; gap: 3px; }
.action-panel span { color: var(--muted); font-size: 12px; }
.action-buttons { display: flex; gap: 9px; }
.progress-panel { margin-top: 18px; }
.progress-head, .progress-foot { display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.progress-head > div { display: grid; gap: 3px; }
.progress-head span, .progress-foot { color: var(--muted); font-size: 12px; }
.progress-track { margin: 14px 0 9px; height: 9px; border-radius: 99px; background: var(--soft-2); overflow: hidden; }
.progress-bar { width: 0; height: 100%; border-radius: inherit; background: var(--accent); transition: width .2s ease; }
.results-section { margin-top: 28px; }
.results-heading { display: flex; align-items: end; justify-content: space-between; gap: 20px; margin-bottom: 12px; }
.results-heading h2 { margin: 0 0 3px; font-size: 22px; }
.results-heading p { margin: 0; color: var(--muted); font-size: 13px; }
.results-list { display: grid; gap: 10px; }
.result-card { border: 1px solid var(--border); border-radius: 13px; overflow: hidden; background: #fff; }
.result-summary { width: 100%; border: 0; background: #fff; padding: 16px; display: grid; grid-template-columns: minmax(250px, 1fr) 150px 170px 32px; gap: 18px; align-items: center; text-align: left; }
.result-summary:hover { background: #fcfdfe; }
.result-name { min-width: 0; }
.result-name strong { display: block; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.result-name small { color: var(--muted); }
.metric { display: grid; gap: 2px; }
.metric span { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .03em; }
.metric strong { font-size: 16px; }
.metric .subtle { font-size: 12px; color: var(--muted); font-weight: 600; }
.chevron { font-size: 20px; color: var(--muted); transition: transform .15s; }
.result-card.open .chevron { transform: rotate(180deg); }
.result-details { display: none; border-top: 1px solid var(--border); background: #fbfcfd; padding: 0 16px 12px; }
.result-card.open .result-details { display: block; }
.region-row { display: grid; grid-template-columns: minmax(220px, 1fr) 150px 170px 120px; gap: 18px; align-items: center; min-height: 44px; border-bottom: 1px solid #edf0f3; font-size: 13px; }
.region-row:last-child { border-bottom: 0; }
.region-row .error-text { color: var(--danger); grid-column: 2 / -1; }
.badge { display: inline-flex; align-items: center; min-height: 24px; padding: 0 8px; border-radius: 99px; background: var(--soft-2); color: #55606e; font-size: 11px; font-weight: 700; }
.badge.success { background: #eaf7f0; color: #207248; }
.badge.error { background: var(--danger-soft); color: #a52a2a; }
.diag-table { width: 100%; border-collapse: collapse; }
.diag-table th, .diag-table td { padding: 12px; border-bottom: 1px solid var(--border); text-align: left; }
.diag-table th { width: 40%; color: var(--muted); }
@media (max-width: 850px) {
  .workspace-grid, .source-strip { grid-template-columns: 1fr; }
  .result-summary { grid-template-columns: 1fr 1fr 32px; }
  .result-name { grid-column: 1 / -1; }
  .region-row { grid-template-columns: 1fr 1fr; gap: 6px 16px; padding: 9px 0; }
  .region-row > :last-child { justify-self: start; }
}
@media (max-width: 620px) {
  .page-shell, .topbar-inner { width: min(100% - 24px, 1280px); }
  .page-heading, .action-panel { flex-direction: column; align-items: stretch; }
  .region-toolbar { grid-template-columns: 1fr; }
  .action-buttons { width: 100%; }
  .action-buttons .button { flex: 1; }
  .result-summary { grid-template-columns: 1fr 32px; }
  .metric { grid-column: 1; }
  .chevron { grid-column: 2; grid-row: 2 / span 2; }
  .topbar-actions .user-label { display: none; }
}
