:root {
  color-scheme: light;
  --bg: #f3f5f6;
  --panel: #fff;
  --ink: #19232d;
  --muted: #667581;
  --line: #d8e0e5;
  --line-strong: #bec9d1;
  --accent: #087f70;
  --accent-dark: #06685d;
  --accent-soft: #e5f4f0;
  --warning: #9a6308;
  --warning-soft: #fff3d8;
  --danger: #b42318;
  --danger-soft: #fff0ee;
  --ease-out: cubic-bezier(.23, 1, .32, 1);
  --ease-in-out: cubic-bezier(.77, 0, .175, 1);
  --focus-ring: rgba(8, 127, 112, .22);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

button, input, select { font: inherit; }
a { color: inherit; text-decoration: none; }
[hidden] { display: none !important; }

button, .header-actions a {
  transition: transform 140ms var(--ease-out), background-color 140ms ease, border-color 140ms ease, color 140ms ease, box-shadow 140ms ease;
}
button:not(:disabled):active, .header-actions a:active { transform: scale(.97); }
:where(button, a, input, select):focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
:where(input, select):focus-visible { outline: 0; }

.admin-shell {
  width: min(1480px, calc(100% - 36px));
  margin: 0 auto;
  padding: 22px 0 50px;
}

.login-view {
  display: grid;
  min-height: calc(100vh - 72px);
  place-items: center;
}

.login-panel {
  display: grid;
  gap: 18px;
  width: min(400px, 100%);
  padding: 26px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
}

h1, h2, p { letter-spacing: 0; }
h1 { margin: 0; font-size: 24px; }
h2 { margin: 0; font-size: 17px; }

.eyebrow {
  margin: 0 0 5px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

input, select {
  width: 100%;
  height: 38px;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  background: #fff;
  color: var(--ink);
  outline: 0;
  padding: 0 10px;
}

input:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--focus-ring);
}

button, .header-actions a {
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
}

button:disabled { cursor: not-allowed; opacity: .5; }

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

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

.form-error, .form-success, .form-note {
  min-height: 16px;
  margin: 0;
  font-size: 12px;
}

.form-error { color: var(--danger); }
.form-success { color: var(--accent-dark); }
.form-note { color: var(--muted); }

.admin-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 14px;
}

.header-actions { display: flex; align-items: center; gap: 8px; }
.header-actions a { display: inline-flex; align-items: center; }

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  overflow: hidden;
  margin-bottom: 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
}

.summary-item {
  min-width: 0;
  padding: 14px 16px;
  border-right: 1px solid var(--line);
}

.summary-item:last-child { border-right: 0; }
.summary-item span, .summary-item p { color: var(--muted); font-size: 11px; }
.summary-item strong { display: block; margin-top: 5px; font-size: 23px; }
.summary-item p { margin: 5px 0 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.workspace-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(320px, .75fr);
  gap: 14px;
  margin-bottom: 14px;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
}

.crawl-panel, .add-panel { padding: 16px; }

.ai-settings-panel, .classification-ai-settings-panel {
  margin-bottom: 14px;
  padding: 16px;
}

.classification-ai-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0; }
.classification-ai-form { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; min-width: 0; padding-right: 16px; }
.classification-ai-form + .classification-ai-form { padding-right: 0; padding-left: 16px; border-left: 1px solid var(--line); }
.classification-ai-title { display: flex; grid-column: 1 / -1; align-items: center; justify-content: space-between; gap: 10px; }
.classification-ai-title strong { font-size: 13px; }
.classification-ai-form > .check-label { align-self: end; }

.transit-admin-panel, .classification-panel { margin-bottom: 14px; padding: 16px; }
.transit-admin-panel > .panel-head > a { color: var(--accent-dark); font-size: 12px; font-weight: 700; }
.transit-admin-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.transit-form { min-width: 0; padding: 14px; border: 1px solid var(--line); border-radius: 5px; background: #fafcfc; }
.form-title { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.form-title strong { font-size: 13px; }
.form-title button { min-height: 30px; }
.form-columns { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; margin-top: 9px; }
.form-columns .wide-field { grid-column: 1 / -1; }
.check-row, .form-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 9px; margin-top: 11px; }
.form-actions button { min-height: 34px; }
.transit-form > .form-note { margin-top: 9px; }
.transit-offer-list { min-width: 900px; margin: 14px -16px -16px; border-top: 1px solid var(--line); }
.transit-admin-panel { overflow-x: auto; }
.transit-offer-head, .transit-offer-row { display: grid; grid-template-columns: minmax(150px,.8fr) minmax(260px,1.4fr) 120px 120px 90px 70px; align-items: center; gap: 12px; width: 100%; min-height: 44px; padding: 0 16px; text-align: left; }
.transit-offer-head { background: #f7f9fa; color: var(--muted); font-size: 10px; }
.transit-offer-row { border: 0; border-top: 1px solid #e8edef; background: #fff; color: var(--ink); font-size: 11px; }
.classification-head { align-items: end; }
.classification-filters { display: grid; grid-template-columns: minmax(220px,1fr) 130px auto auto auto; gap: 8px; }
.classification-list { margin: 0 -16px; border-top: 1px solid var(--line); }
.classification-row { display: grid; grid-template-columns: minmax(320px,1fr) minmax(260px,.7fr) 80px 60px; align-items: center; gap: 12px; min-height: 64px; padding: 8px 16px; border-bottom: 1px solid #e8edef; }
.classification-row > div { min-width: 0; }
.classification-row strong, .classification-row span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.classification-row > div span { margin-top: 4px; color: var(--muted); font-size: 10px; }
.classification-row select { min-width: 0; }
.classification-note { margin: 12px 0 0; }

.ai-settings-form {
  display: grid;
  grid-template-columns: minmax(240px, 1.3fr) minmax(160px, .7fr) minmax(220px, 1fr) auto;
  align-items: end;
  gap: 10px;
}

.ai-enable-label { padding-bottom: 5px; }
.ai-settings-actions { display: flex; grid-column: 1 / -1; gap: 8px; }
.ai-settings-message { grid-column: 1 / -1; }

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

.job-status, .status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 23px;
  padding: 0 7px;
  border-radius: 4px;
  background: #edf1f3;
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
}

.job-status.running, .status-pill.ready { background: var(--accent-soft); color: var(--accent-dark); }
.job-status.failed, .job-status.stopped { background: var(--danger-soft); color: var(--danger); }
.job-status.stopping, .status-pill.pending_parser { background: var(--warning-soft); color: var(--warning); }

.crawl-form {
  display: grid;
  grid-template-columns: 150px 170px auto auto 1fr;
  align-items: end;
  gap: 10px;
}

.check-label {
  display: flex;
  align-items: center;
  gap: 7px;
  min-height: 38px;
  color: var(--ink);
  white-space: nowrap;
}

.check-label input { width: 15px; height: 15px; }
.command-row { display: flex; justify-content: flex-end; gap: 8px; }

.progress-track {
  height: 5px;
  margin-top: 16px;
  overflow: hidden;
  border-radius: 3px;
  background: #e8edef;
}

.progress-track span { display: block; width: 100%; height: 100%; background: var(--accent); transform: scaleX(0); transform-origin: left center; transition: transform 200ms var(--ease-in-out); }
.progress-text { margin: 8px 0; color: var(--muted); font-size: 11px; }

.job-log {
  height: 180px;
  margin: 0;
  overflow: auto;
  border: 1px solid #26343c;
  border-radius: 5px;
  background: #142027;
  color: #d8e8e5;
  padding: 10px;
  font: 11px/1.55 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  white-space: pre-wrap;
}

.add-form { display: grid; gap: 12px; }

.domain-list {
  display: grid;
  gap: 6px;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.domain-item { display: flex; justify-content: space-between; gap: 10px; color: var(--muted); font-size: 11px; }
.domain-item strong { color: var(--accent-dark); font-weight: 600; }
.domain-item.pending strong { color: var(--warning); }

.shop-panel { overflow: hidden; }
.shop-panel-head { padding: 14px 16px; margin: 0; border-bottom: 1px solid var(--line); }
.shop-filters { display: grid; grid-template-columns: minmax(220px, 1fr) 180px 130px; gap: 8px; }

.shop-table { min-width: 850px; }
.shop-panel { overflow-x: auto; }
.shop-table-head, .shop-row {
  display: grid;
  grid-template-columns: minmax(280px, 1.5fr) 180px 90px 90px 65px 52px;
  align-items: center;
  gap: 12px;
  padding: 0 14px;
}

.shop-table-head {
  min-height: 36px;
  border-bottom: 1px solid var(--line);
  background: #f7f9fa;
  color: var(--muted);
  font-size: 11px;
}

.shop-row { min-height: 62px; border-bottom: 1px solid #e8edef; font-size: 12px; }
.shop-row:last-child { border-bottom: 0; }
.shop-identity { min-width: 0; }
.shop-identity strong, .shop-identity a { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.shop-identity strong { font-size: 12px; }
.shop-identity a { margin-top: 4px; color: var(--muted); font-size: 10px; }
code { color: #4053a3; font-size: 11px; }

.switch { position: relative; display: block; width: 34px; height: 20px; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch span { display: block; width: 100%; height: 100%; border-radius: 10px; background: #c8d1d7; cursor: pointer; transition: background-color 140ms ease; }
.switch span::after { content: ""; display: block; width: 16px; height: 16px; margin: 2px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(25, 35, 45, .18); transition: transform 180ms var(--ease-out); }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(14px); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.empty-row { margin: 0; padding: 28px; color: var(--muted); text-align: center; font-size: 12px; }

dialog {
  width: min(420px, calc(100% - 24px));
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0;
}
dialog::backdrop { background: rgba(20, 32, 39, .35); }
dialog form { display: grid; gap: 14px; padding: 18px; }
dialog .panel-head { margin: 0; }

@media (hover: hover) and (pointer: fine) {
  button:hover:not(:disabled), .header-actions a:hover { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-dark); }
  .primary-button:hover:not(:disabled) { background: var(--accent-dark); color: #fff; }
  .danger-button:hover:not(:disabled) { border-color: var(--danger); background: #fbe3e0; color: var(--danger); }
  .transit-offer-row:hover, .shop-row:hover { background: #f9fbfb; }
  .shop-identity a:hover, .transit-admin-panel > .panel-head > a:hover { color: var(--accent-dark); text-decoration: underline; text-underline-offset: 2px; }
}

@media (prefers-reduced-motion: reduce) {
  button, .header-actions a { transition-property: background-color, border-color, color, box-shadow; }
  button:not(:disabled):active, .header-actions a:active { transform: none; }
  .progress-track span, .switch span::after { transition-duration: 0ms; }
}

@media (max-width: 1050px) {
  .summary-grid { grid-template-columns: repeat(2, 1fr); }
  .summary-item:nth-child(2) { border-right: 0; }
  .summary-item:nth-child(-n + 2) { border-bottom: 1px solid var(--line); }
  .workspace-grid { grid-template-columns: 1fr; }
  .ai-settings-form { grid-template-columns: 1fr 1fr; }
  .ai-settings-form > label:first-child { grid-column: 1 / -1; }
  .crawl-form { grid-template-columns: 1fr 1fr auto auto; }
  .transit-admin-grid { grid-template-columns: 1fr; }
  .classification-ai-grid { grid-template-columns: 1fr; }
  .classification-ai-form { padding: 0; }
  .classification-ai-form + .classification-ai-form { margin-top: 16px; padding: 16px 0 0; border-top: 1px solid var(--line); border-left: 0; }
  .classification-head { align-items: stretch; flex-direction: column; }
  .classification-filters { grid-template-columns: 1fr 1fr; }
  .classification-filters input { grid-column: 1 / -1; }
  .command-row { grid-column: 1 / -1; justify-content: flex-start; }
}

@media (max-width: 680px) {
  .admin-shell { width: min(100% - 20px, 1480px); padding-top: 12px; }
  .admin-header { align-items: flex-start; flex-direction: column; }
  .header-actions { width: 100%; display: grid; grid-template-columns: repeat(3, 1fr); }
  .header-actions a { justify-content: center; }
  .summary-grid { grid-template-columns: 1fr 1fr; }
  .summary-item { padding: 12px; }
  .summary-item strong { font-size: 19px; }
  .crawl-form { grid-template-columns: 1fr 1fr; }
  .ai-settings-form { grid-template-columns: 1fr; }
  .ai-settings-form > label:first-child { grid-column: auto; }
  .ai-settings-actions { flex-wrap: wrap; }
  .classification-ai-form { grid-template-columns: 1fr; }
  .classification-ai-title, .classification-ai-form .ai-settings-actions, .classification-ai-form .ai-settings-message { grid-column: auto; }
  .check-label { min-height: 28px; }
  .shop-panel-head { align-items: stretch; flex-direction: column; }
  .shop-filters { grid-template-columns: 1fr 1fr; }
  .shop-filters input { grid-column: 1 / -1; }
  .form-columns { grid-template-columns: 1fr; }
  .form-columns .wide-field { grid-column: auto; }
  .classification-head { align-items: stretch; flex-direction: column; }
  .classification-filters { grid-template-columns: 1fr 1fr; }
  .classification-filters input { grid-column: 1 / -1; }
  .classification-row { grid-template-columns: 1fr 90px 56px; }
  .classification-row > div { grid-column: 1 / -1; }
}
