:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --text: #172033;
  --muted: #657087;
  --line: #e2e7f0;
  --primary: #1769e0;
  --primary-dark: #0f57c1;
  --primary-soft: #eef5ff;
  --success: #11825b;
  --success-soft: #eaf9f2;
  --danger: #c1373e;
  --danger-soft: #fff1f1;
  --warning: #9c6810;
  --warning-soft: #fff8e8;
  --shadow: 0 14px 38px rgba(25, 44, 82, 0.08);
  --radius: 18px;
  font-family: Inter, "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", system-ui, -apple-system, sans-serif;
  font-synthesis: none;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--bg);
  color: var(--text);
}

body {
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(circle at 85% -10%, rgba(43, 126, 238, 0.1), transparent 32rem),
    var(--bg);
}

button,
input {
  font: inherit;
}

button,
label[for] {
  -webkit-tap-highlight-color: transparent;
}

button {
  cursor: pointer;
}

button:disabled,
input:disabled {
  cursor: not-allowed;
  opacity: 0.62;
}

svg {
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

[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;
}

.skip-link {
  position: fixed;
  z-index: 100;
  top: 8px;
  left: 8px;
  padding: 10px 14px;
  border-radius: 8px;
  color: #fff;
  background: var(--primary);
  transform: translateY(-160%);
}

.skip-link:focus {
  transform: translateY(0);
}

.topbar {
  position: sticky;
  z-index: 20;
  top: 0;
  border-bottom: 1px solid rgba(226, 231, 240, 0.9);
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(14px);
}

.topbar__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: min(1180px, calc(100% - 40px));
  min-height: 72px;
  margin: 0 auto;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  color: inherit;
  text-decoration: none;
}

.brand__mark {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border-radius: 11px;
  color: #fff;
  background: linear-gradient(145deg, #1676ee, #1254bf);
  box-shadow: 0 7px 18px rgba(23, 105, 224, 0.25);
  font-weight: 800;
}

.brand strong,
.brand small {
  display: block;
}

.brand strong {
  font-size: 15px;
  letter-spacing: 0.04em;
}

.brand small {
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
}

.connection-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 32px;
  padding: 0 12px;
  border-radius: 999px;
  color: var(--muted);
  background: #f1f4f8;
  font-size: 12px;
  font-weight: 650;
}

.connection-badge__dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #9aa4b5;
}

.connection-badge--success {
  color: var(--success);
  background: var(--success-soft);
}

.connection-badge--success .connection-badge__dot {
  background: var(--success);
}

.connection-badge--loading {
  color: var(--primary);
  background: var(--primary-soft);
}

.connection-badge--loading .connection-badge__dot {
  background: var(--primary);
  animation: pulse 1s ease-in-out infinite;
}

.connection-badge--error {
  color: var(--danger);
  background: var(--danger-soft);
}

.connection-badge--error .connection-badge__dot {
  background: var(--danger);
}

.page-shell {
  width: min(1180px, calc(100% - 40px));
  margin: 0 auto;
  padding: 52px 0 48px;
}

.hero {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 32px;
  margin-bottom: 30px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--primary);
  font-size: 12px;
  font-weight: 750;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 12px;
  font-size: clamp(28px, 4vw, 40px);
  line-height: 1.18;
  letter-spacing: -0.035em;
}

h2 {
  margin-bottom: 0;
  font-size: 20px;
  line-height: 1.35;
  letter-spacing: -0.015em;
}

.hero__description {
  max-width: 700px;
  margin-bottom: 0;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.75;
}

.hero__actions {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 8px;
  padding-top: 22px;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: 11px;
  font-size: 14px;
  font-weight: 700;
  transition: background 150ms ease, border-color 150ms ease, box-shadow 150ms ease, transform 150ms ease;
}

.button:not(:disabled):active {
  transform: translateY(1px);
}

.button svg {
  width: 17px;
  height: 17px;
}

.button--primary {
  color: #fff;
  background: var(--primary);
  box-shadow: 0 8px 18px rgba(23, 105, 224, 0.18);
}

.button--primary:not(:disabled):hover {
  background: var(--primary-dark);
  box-shadow: 0 10px 24px rgba(23, 105, 224, 0.25);
}

.button--secondary {
  border-color: var(--line);
  color: #354057;
  background: var(--surface);
}

.button--secondary:not(:disabled):hover {
  border-color: #c9d3e3;
  background: #fbfcfe;
}

.button--ghost {
  color: var(--muted);
  background: transparent;
}

.button--ghost:not(:disabled):hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.72);
}

.button--large {
  min-height: 48px;
  padding-inline: 22px;
}

.button:focus-visible,
input:focus-visible,
.drop-zone:focus-within,
.icon-button:focus-visible {
  outline: 3px solid rgba(23, 105, 224, 0.2);
  outline-offset: 2px;
}

.button__spinner {
  display: none;
  width: 15px;
  height: 15px;
  border: 2px solid rgba(255, 255, 255, 0.42);
  border-top-color: #fff;
  border-radius: 50%;
}

.button.is-loading .button__spinner {
  display: block;
  animation: spin 0.7s linear infinite;
}

.stats-grid {
  display: grid;
  grid-template-columns: 2fr repeat(3, 1fr);
  gap: 14px;
  margin-bottom: 18px;
}

.stat-card,
.panel,
.auth-card {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
}

.stat-card {
  display: flex;
  min-height: 136px;
  flex-direction: column;
  justify-content: center;
  padding: 22px;
  border-radius: 16px;
}

.stat-card__label {
  margin-bottom: 9px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.stat-card__value {
  font-size: 30px;
  line-height: 1.05;
  font-variant-numeric: tabular-nums;
}

.stat-card__file {
  max-width: 100%;
  margin-bottom: 5px;
  overflow: hidden;
  font-size: 16px;
  line-height: 1.45;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stat-card__meta {
  margin-top: 7px;
  color: #8791a3;
  font-size: 11px;
  line-height: 1.45;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.65fr) minmax(280px, 0.8fr);
  gap: 18px;
  margin-bottom: 18px;
}

.panel {
  border-radius: var(--radius);
  padding: 26px;
}

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

.format-chip {
  flex: 0 0 auto;
  padding: 6px 10px;
  border-radius: 999px;
  color: var(--primary);
  background: var(--primary-soft);
  font-size: 11px;
  font-weight: 700;
}

.drop-zone {
  display: flex;
  min-height: 245px;
  padding: 28px;
  border: 1.5px dashed #b8c5d9;
  border-radius: 16px;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  color: var(--muted);
  background: var(--surface-soft);
  text-align: center;
  transition: border-color 150ms ease, background 150ms ease, transform 150ms ease;
  cursor: pointer;
}

.drop-zone:hover,
.drop-zone.is-dragging {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.drop-zone.is-dragging {
  transform: scale(1.006);
}

.drop-zone input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  opacity: 0;
}

.drop-zone__icon {
  display: grid;
  width: 54px;
  height: 54px;
  margin-bottom: 15px;
  place-items: center;
  border-radius: 16px;
  color: var(--primary);
  background: #fff;
  box-shadow: 0 7px 22px rgba(25, 44, 82, 0.1);
}

.drop-zone__icon svg {
  width: 28px;
  height: 28px;
}

.drop-zone strong {
  margin-bottom: 7px;
  color: var(--text);
  font-size: 16px;
}

.drop-zone > span:not(.drop-zone__icon) {
  font-size: 13px;
}

.drop-zone small {
  max-width: 440px;
  margin-top: 17px;
  color: #8d97a8;
  font-size: 11px;
  line-height: 1.65;
}

.selected-file {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 13px;
  padding: 12px 14px;
  border: 1px solid #d9e7fb;
  border-radius: 12px;
  background: #f6faff;
}

.selected-file__icon {
  display: grid;
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 9px;
  color: var(--success);
  background: var(--success-soft);
  font-size: 10px;
  font-weight: 800;
}

.selected-file__details {
  min-width: 0;
  flex: 1;
}

.selected-file__details strong,
.selected-file__details small {
  display: block;
}

.selected-file__details strong {
  overflow: hidden;
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.selected-file__details small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
}

.icon-button {
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 8px;
  color: var(--muted);
  background: transparent;
  font-size: 22px;
  line-height: 1;
}

.icon-button:hover {
  color: var(--danger);
  background: var(--danger-soft);
}

.upload-actions {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-top: 18px;
}

.upload-note {
  margin: 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.55;
}

.notice {
  margin-top: 16px;
  padding: 13px 15px;
  border: 1px solid var(--line);
  border-radius: 11px;
  color: var(--muted);
  background: var(--surface-soft);
  font-size: 13px;
  line-height: 1.55;
}

.notice--success {
  border-color: #bee9d7;
  color: var(--success);
  background: var(--success-soft);
}

.notice--error {
  border-color: #f4c9cb;
  color: var(--danger);
  background: var(--danger-soft);
}

.notice--progress {
  border-color: #ccddf8;
  color: var(--primary);
  background: var(--primary-soft);
}

.process-list {
  display: grid;
  gap: 20px;
  padding: 0;
  margin: 4px 0 25px;
  list-style: none;
}

.process-list li {
  display: grid;
  grid-template-columns: 34px 1fr;
  gap: 12px;
}

.process-list li > span {
  display: grid;
  width: 32px;
  height: 32px;
  place-items: center;
  border-radius: 10px;
  color: var(--primary);
  background: var(--primary-soft);
  font-size: 12px;
  font-weight: 800;
}

.process-list strong {
  display: block;
  margin-top: 1px;
  font-size: 14px;
}

.process-list p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.55;
}

.security-note {
  display: grid;
  grid-template-columns: 24px 1fr;
  gap: 10px;
  padding: 15px;
  border-radius: 13px;
  color: #49617d;
  background: #f4f8fc;
}

.security-note svg {
  width: 21px;
  height: 21px;
  color: var(--success);
}

.security-note p {
  margin: 0;
  font-size: 11px;
  line-height: 1.65;
}

.factories-panel {
  margin-top: 0;
}

.search-box {
  display: flex;
  width: min(280px, 100%);
  min-height: 42px;
  align-items: center;
  gap: 9px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 11px;
  color: #8b96a8;
  background: var(--surface-soft);
}

.search-box:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(23, 105, 224, 0.12);
}

.search-box svg {
  width: 17px;
  height: 17px;
  flex: 0 0 auto;
}

.search-box input {
  width: 100%;
  border: 0;
  outline: 0;
  color: var(--text);
  background: transparent;
  font-size: 13px;
}

.search-box input::placeholder {
  color: #98a2b3;
}

.factory-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.factory-card {
  display: flex;
  min-width: 0;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 15px 16px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--surface-soft);
}

.factory-card__identity {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 11px;
}

.factory-card__mark {
  display: grid;
  width: 36px;
  height: 36px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 10px;
  color: var(--primary);
  background: var(--primary-soft);
  font-size: 13px;
  font-weight: 800;
}

.factory-card__identity strong,
.factory-card__identity small {
  display: block;
}

.factory-card__identity strong {
  overflow: hidden;
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.factory-card__identity small {
  margin-top: 4px;
  color: #949dad;
  font-size: 10px;
}

.factory-card__metrics {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 6px;
}

.factory-card__metrics > span {
  display: flex;
  min-width: 64px;
  padding: 7px 9px;
  border-radius: 9px;
  align-items: baseline;
  justify-content: center;
  gap: 4px;
  background: #fff;
}

.factory-card__metrics strong {
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.factory-card__metrics small {
  color: var(--muted);
  font-size: 9px;
}

.factory-empty {
  display: flex;
  min-height: 210px;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  color: var(--muted);
  text-align: center;
}

.factory-empty > span {
  display: grid;
  width: 48px;
  height: 48px;
  margin-bottom: 12px;
  place-items: center;
  border-radius: 14px;
  color: #8591a5;
  background: #edf1f6;
  font-weight: 800;
}

.factory-empty strong {
  color: var(--text);
  font-size: 14px;
}

.factory-empty p {
  max-width: 420px;
  margin: 7px 0 0;
  font-size: 12px;
  line-height: 1.6;
}

.factory-result-note {
  margin: 13px 0 0;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.auth-card {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr);
  gap: 24px;
  width: min(720px, 100%);
  margin: 7vh auto;
  padding: 34px;
  border-radius: 22px;
}

.auth-card__icon {
  display: grid;
  width: 64px;
  height: 64px;
  place-items: center;
  border-radius: 18px;
  color: var(--primary);
  background: var(--primary-soft);
}

.auth-card__icon svg {
  width: 31px;
  height: 31px;
}

.auth-card h1 {
  margin-bottom: 9px;
  font-size: 27px;
}

.muted {
  margin-bottom: 24px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.65;
}

.token-form label {
  display: block;
  margin-bottom: 8px;
  font-size: 12px;
  font-weight: 700;
}

.token-form__row {
  display: flex;
  gap: 10px;
}

.token-form input {
  min-width: 0;
  min-height: 46px;
  flex: 1;
  padding: 0 13px;
  border: 1px solid #cfd7e4;
  border-radius: 11px;
  outline: 0;
  color: var(--text);
  background: #fff;
}

.token-form input:focus {
  border-color: var(--primary);
}

.form-message {
  margin: 10px 0 0;
  font-size: 12px;
}

.form-message--error {
  color: var(--danger);
}

.footer {
  display: flex;
  width: min(1180px, calc(100% - 40px));
  min-height: 70px;
  margin: 0 auto;
  border-top: 1px solid var(--line);
  align-items: center;
  justify-content: space-between;
  color: #919aaa;
  font-size: 11px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@keyframes pulse {
  50% { opacity: 0.4; }
}

@media (max-width: 900px) {
  .stats-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  .stat-card--wide {
    grid-column: 1 / -1;
  }

  .content-grid {
    grid-template-columns: 1fr;
  }

  .guide-panel {
    order: 2;
  }
}

@media (max-width: 680px) {
  .topbar__inner,
  .page-shell,
  .footer {
    width: min(100% - 24px, 1180px);
  }

  .topbar__inner {
    min-height: 62px;
  }

  .page-shell {
    padding-top: 30px;
  }

  .hero {
    display: block;
    margin-bottom: 22px;
  }

  .hero__actions {
    justify-content: flex-start;
    padding-top: 16px;
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }

  .stat-card,
  .panel {
    padding: 18px;
  }

  .stat-card {
    min-height: 118px;
  }

  .stat-card--wide {
    grid-column: 1 / -1;
  }

  .content-grid {
    gap: 12px;
  }

  .panel__header--responsive {
    align-items: stretch;
    flex-direction: column;
  }

  .search-box {
    width: 100%;
  }

  .factory-list {
    grid-template-columns: 1fr;
  }

  .upload-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .upload-actions .button {
    width: 100%;
  }

  .auth-card {
    display: block;
    margin-top: 3vh;
    padding: 24px;
  }

  .auth-card__icon {
    margin-bottom: 20px;
  }

  .token-form__row {
    align-items: stretch;
    flex-direction: column;
  }

  .footer {
    min-height: 82px;
    align-items: flex-start;
    justify-content: center;
    flex-direction: column;
    gap: 4px;
  }
}

@media (max-width: 420px) {
  .brand small {
    display: none;
  }

  .stats-grid {
    grid-template-columns: 1fr 1fr;
  }

  .stat-card {
    min-height: 108px;
    padding: 15px;
  }

  .stat-card__value {
    font-size: 25px;
  }

  .drop-zone {
    min-height: 218px;
    padding: 20px 14px;
  }

  .factory-card {
    align-items: flex-start;
    flex-direction: column;
  }

  .factory-card__metrics {
    width: 100%;
  }

  .factory-card__metrics > span {
    flex: 1;
  }
}

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

.automation-panel { margin-bottom: 24px; }
.automation-summary { display: grid; gap: 8px; padding: 18px; margin: 20px 0; background: #f5f7fb; border-radius: 12px; }
.automation-summary strong { color: #153a63; }
.automation-summary span { color: #53647b; font-size: 14px; }
.automation-actions { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.mes-settings { margin-top: 20px; border-top: 1px solid #e4eaf2; padding-top: 16px; }
.mes-settings summary, .manual-fallback summary { cursor: pointer; color: #23456a; font-weight: 600; padding: 8px 0; }
.mes-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; margin: 18px 0; }
.mes-fields label { display: grid; gap: 8px; font-size: 14px; font-weight: 600; }
.mes-fields input { width: 100%; padding: 12px; border: 1px solid #cdd9e7; border-radius: 8px; background: white; font: inherit; }
.mes-enabled { display: flex; align-items: center; gap: 8px; }
.mes-enabled input { width: 18px; height: 18px; }
.automation-history article { padding: 12px 0; border-bottom: 1px solid #e4eaf2; }
.automation-history article span { display: block; font-size: 13px; color: #53647b; margin-top: 5px; }
.manual-fallback { margin-bottom: 24px; }
.manual-fallback .content-grid { margin-top: 12px; }
@media (max-width: 680px) { .mes-fields { grid-template-columns: 1fr; } }
