/* 民航运维工具风 — 浅色、专业、紧凑 */

:root {
  --bg: #eef2f6;
  --surface: #ffffff;
  --surface-muted: #f8fafc;
  --surface-hover: #f1f5f9;
  --text: #1e293b;
  --text-secondary: #475569;
  --text-dim: #64748b;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --primary: #0369a1;
  --primary-hover: #0284c7;
  --primary-dim: rgba(3, 105, 161, 0.08);
  --accent: #d97706;
  --normal: #059669;
  --explicit: #dc2626;
  --sequence: #ea580c;
  --boundary: #ca8a04;
  --incomplete: #7c3aed;
  --radius: 8px;
  --radius-sm: 6px;
  --font-ui: "Barlow", "PingFang SC", "Microsoft YaHei", sans-serif;
  --font-mono: "JetBrains Mono", "Consolas", monospace;
  --logo-size: 60px;
  --header-h: 64px;
  --transition: 0.2s ease;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: var(--font-ui);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  font-size: 15px;
  min-height: 100vh;
}

.page {
  max-width: 1240px;
  margin: 0 auto;
  padding: 12px 16px 24px;
}

/* ── Header ── */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  height: var(--header-h);
  padding: 0 16px;
  margin-bottom: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  border-top: 3px solid var(--accent);
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.06);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.logo-mark {
  width: var(--logo-size);
  height: var(--logo-size);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
}

.logo-mark img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.brand-text h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--text);
  line-height: 1.2;
}

.brand-tag {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.steps-inline {
  display: flex;
  align-items: center;
  gap: 0;
  flex-shrink: 0;
}

.step-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-dim);
  transition: all var(--transition);
}

.step-connector {
  width: 18px;
  height: 1px;
  background: var(--border-strong);
}

.step-num {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  background: var(--surface-muted);
  color: var(--text-dim);
  border: 1px solid var(--border);
}

.step-item.active {
  color: var(--primary);
  background: var(--primary-dim);
}

.step-item.active .step-num {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.step-item.done { color: var(--normal); }
.step-item.done .step-num {
  background: rgba(5, 150, 105, 0.12);
  color: var(--normal);
  border-color: rgba(5, 150, 105, 0.35);
}

/* ── Control Panel ── */
.control-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 10px;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.05);
}

.control-block {
  padding: 10px 14px;
}

.control-block + .control-block {
  border-top: 1px solid var(--border);
}

.upload-block {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.control-panel.is-loaded .upload-compact {
  flex: 0 0 auto;
  max-width: 320px;
  padding: 7px 12px;
  border-style: solid;
  background: var(--surface-muted);
}

.upload-compact {
  flex: 1;
  min-width: 200px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition);
  background: var(--surface-muted);
}

.upload-compact:hover,
.upload-compact.dragover {
  border-color: var(--primary);
  background: var(--primary-dim);
}

.upload-icon-sm {
  width: 18px;
  height: 18px;
  color: var(--primary);
  flex-shrink: 0;
}

.upload-label {
  font-size: 14px;
  color: var(--text-secondary);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.control-panel.is-loaded .upload-label {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.btn-text {
  background: none;
  border: none;
  color: var(--primary);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  font-family: var(--font-ui);
}

.btn-text:hover { background: var(--primary-dim); }

.meta-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  flex: 1;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--text-dim);
}

.chip strong {
  font-family: var(--font-mono);
  color: var(--text);
  font-weight: 600;
}

/* Filter — 单行布局 */
.filter-row {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: nowrap;
}

.field-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.field-label {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  white-space: nowrap;
}

.field-row input[type="datetime-local"],
.field-row .aircraft-combobox input {
  padding: 7px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: var(--font-mono);
  background: var(--surface);
  color: var(--text);
  height: 36px;
}

.field-row input[type="datetime-local"] {
  width: 196px;
  min-width: 196px;
}

.field-row input:focus,
.aircraft-combobox input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-dim);
}

/* 飞机号可搜索下拉 */
.aircraft-combobox {
  position: relative;
  width: 130px;
}

.aircraft-combobox input {
  width: 100%;
  padding-right: 28px;
}

.aircraft-clear {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  border-radius: 4px;
}

.aircraft-clear svg {
  width: 14px;
  height: 14px;
}

.aircraft-clear:hover {
  background: var(--surface-hover);
  color: var(--text-secondary);
}

.aircraft-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  max-height: 220px;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.1);
  z-index: 50;
}

.aircraft-option {
  display: block;
  width: 100%;
  padding: 7px 10px;
  border: none;
  background: none;
  text-align: left;
  font-family: var(--font-mono);
  font-size: 14px;
  color: var(--text);
  cursor: pointer;
}

.aircraft-option:hover,
.aircraft-option.highlighted {
  background: var(--primary-dim);
  color: var(--primary);
}

.aircraft-option-all {
  font-family: var(--font-ui);
  color: var(--text-dim);
  border-bottom: 1px solid var(--border);
}

.filter-actions {
  display: flex;
  gap: 8px;
  margin-left: auto;
  flex-shrink: 0;
}

button {
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  font-family: var(--font-ui);
  cursor: pointer;
  transition: all var(--transition);
}

.btn-primary {
  padding: 7px 18px;
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-ghost {
  padding: 7px 16px;
  background: var(--surface);
  color: var(--text-secondary);
  border: 1px solid var(--border-strong);
}

.btn-ghost:hover {
  background: var(--surface-hover);
  color: var(--text);
}

/* Error */
.error-box {
  padding: 9px 14px;
  border-radius: var(--radius-sm);
  background: #fef2f2;
  color: var(--explicit);
  border: 1px solid #fecaca;
  font-size: 14px;
  margin-bottom: 10px;
}

.hidden { display: none !important; }

/* ── Summary Filter Cards ── */
.summary-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
  margin-bottom: 10px;
}

.summary-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding: 10px 12px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all var(--transition);
  text-align: left;
  font-family: var(--font-ui);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.summary-card:hover {
  border-color: var(--border-strong);
  background: var(--surface-hover);
}

.summary-card.active {
  border-color: var(--primary);
  background: var(--primary-dim);
}

.summary-card .label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
}

.summary-card.active .label { color: var(--primary); }

.summary-card .value {
  font-family: var(--font-mono);
  font-size: 26px;
  font-weight: 600;
  line-height: 1.15;
}

.summary-card[data-filter="all"] .value { color: var(--text); }
.summary-card[data-filter="normal"] .value { color: var(--normal); }
.summary-card[data-filter="explicit"] .value { color: var(--explicit); }
.summary-card[data-filter="sequence"] .value { color: var(--sequence); }
.summary-card[data-filter="boundary"] .value { color: var(--boundary); }
.summary-card[data-filter="incomplete"] .value { color: var(--incomplete); }

.summary-card.active[data-filter="normal"] { border-color: var(--normal); background: rgba(5, 150, 105, 0.06); }
.summary-card.active[data-filter="explicit"] { border-color: var(--explicit); background: rgba(220, 38, 38, 0.06); }
.summary-card.active[data-filter="sequence"] { border-color: var(--sequence); background: rgba(234, 88, 12, 0.06); }
.summary-card.active[data-filter="boundary"] { border-color: var(--boundary); background: rgba(202, 138, 4, 0.06); }
.summary-card.active[data-filter="incomplete"] { border-color: var(--incomplete); background: rgba(124, 58, 237, 0.06); }

/* ── Results ── */
.results-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.05);
}

.results-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.results-head h2 {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
  color: var(--text-secondary);
}

.results-hint {
  font-size: 13px;
  color: var(--text-dim);
}

.results-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 8px;
}

.result-item {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  background: var(--surface-muted);
  transition: all var(--transition);
  animation: cardIn 0.3s ease backwards;
  cursor: pointer;
}

.result-item:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.result-item.severity-normal { border-left: 3px solid var(--normal); }
.result-item.severity-explicit { border-left: 3px solid var(--explicit); }
.result-item.severity-sequence { border-left: 3px solid var(--sequence); }
.result-item.severity-boundary { border-left: 3px solid var(--boundary); }
.result-item.severity-incomplete { border-left: 3px solid var(--incomplete); }

.result-item:hover {
  background: var(--surface-hover);
  border-color: var(--border-strong);
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.06);
}

.result-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.result-header .result-counts { margin-left: auto; }

.aircraft-id {
  font-family: var(--font-mono);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--primary);
}

.badge {
  padding: 2px 7px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}

.badge.normal { background: rgba(5, 150, 105, 0.12); color: var(--normal); }
.badge.explicit { background: rgba(220, 38, 38, 0.12); color: var(--explicit); }
.badge.sequence { background: rgba(234, 88, 12, 0.12); color: var(--sequence); }
.badge.boundary { background: rgba(202, 138, 4, 0.12); color: var(--boundary); }
.badge.incomplete { background: rgba(124, 58, 237, 0.12); color: var(--incomplete); }

.result-counts {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-dim);
  white-space: nowrap;
}

.result-message {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.4;
  margin-bottom: 6px;
}

.anomaly-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 6px;
}

.tag {
  background: var(--primary-dim);
  color: var(--primary);
  border: 1px solid rgba(3, 105, 161, 0.15);
  border-radius: 4px;
  padding: 2px 6px;
  font-size: 11px;
  font-weight: 600;
}

.result-action-hint {
  display: block;
  margin-top: 6px;
  font-size: 12px;
  color: var(--text-dim);
  transition: color var(--transition);
}

.result-item:hover .result-action-hint {
  color: var(--primary);
}

.empty-hint {
  grid-column: 1 / -1;
  color: var(--text-dim);
  font-size: 14px;
  text-align: center;
  padding: 28px;
}

/* ── Overlay ── */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.35);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.overlay-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px 40px;
  text-align: center;
  box-shadow: 0 12px 32px rgba(15, 23, 42, 0.12);
}

.spinner-ring {
  width: 40px;
  height: 40px;
  margin: 0 auto 16px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

#overlay-text {
  margin: 0;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
}

.fade-in { animation: fadeIn 0.3s ease forwards; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes cardIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ── Detail Drawer ── */
body.drawer-open { overflow: hidden; }

.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.35);
  z-index: 800;
  opacity: 0;
  transition: opacity 0.28s ease;
}

.drawer-backdrop.is-visible { opacity: 1; }

.detail-drawer {
  position: fixed;
  top: 0;
  left: 0;
  width: min(420px, 92vw);
  height: 100vh;
  background: var(--surface);
  border-right: 1px solid var(--border);
  box-shadow: 4px 0 24px rgba(15, 23, 42, 0.12);
  z-index: 900;
  display: flex;
  flex-direction: column;
  transform: translateX(-100%);
  transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
}

.detail-drawer.is-open { transform: translateX(0); }

.drawer-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.drawer-title-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.drawer-aircraft {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--primary);
}

.drawer-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  flex-shrink: 0;
}

.drawer-close svg { width: 16px; height: 16px; }

.drawer-close:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 14px 16px 24px;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}

.drawer-section + .drawer-section {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.drawer-section-title {
  margin: 0 0 10px;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-secondary);
  letter-spacing: 0.04em;
}

.drawer-desc {
  margin: 0 0 10px;
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.55;
}

.drawer-message {
  margin: 0 0 10px;
  padding: 8px 10px;
  background: var(--surface-muted);
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--primary);
  font-size: 14px;
  color: var(--text);
  line-height: 1.45;
}

.drawer-stats {
  margin: 10px 0 0;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-dim);
}

.drawer-empty {
  margin: 0;
  font-size: 14px;
  color: var(--text-dim);
  text-align: center;
  padding: 20px;
}

/* Detail timeline */
.detail-timeline {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.detail-timeline-item {
  display: flex;
  gap: 12px;
  min-height: 52px;
}

.detail-timeline-item.is-anomaly .detail-timeline-content {
  padding-bottom: 12px;
}

.detail-timeline-rail {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 14px;
  flex-shrink: 0;
  padding-top: 4px;
}

.detail-timeline-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  border: 2px solid var(--surface);
  box-shadow: 0 0 0 1px var(--border-strong);
}

.detail-timeline-dot.receive { background: #2563eb; }
.detail-timeline-dot.handover { background: #ea580c; }
.detail-timeline-dot.anomaly {
  background: var(--explicit);
  box-shadow: 0 0 0 2px rgba(220, 38, 38, 0.25);
}

.detail-timeline-line {
  flex: 1;
  width: 2px;
  min-height: 20px;
  background: var(--border);
  margin: 4px 0;
}

.detail-timeline-content {
  flex: 1;
  min-width: 0;
  padding-bottom: 16px;
}

.detail-timeline-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px;
}

.detail-timeline-type {
  font-weight: 700;
  font-size: 14px;
}

.detail-timeline-type.receive { color: #2563eb; }
.detail-timeline-type.handover { color: #ea580c; }

.detail-timeline-time {
  font-family: var(--font-mono);
  font-size: 14px;
  color: var(--text);
}

.detail-timeline-submitter {
  font-size: 13px;
  color: var(--text-secondary);
}

.detail-timeline-submitter::before {
  content: "提交人：";
  color: var(--text-dim);
  font-size: 12px;
}

.detail-timeline-serial {
  margin-top: 4px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-dim);
  line-height: 1.3;
}

.detail-anomaly-box {
  margin-top: 8px;
  padding: 8px 10px;
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: var(--radius-sm);
}

.detail-anomaly-type {
  display: block;
  font-size: 12px;
  font-weight: 700;
  color: var(--explicit);
  margin-bottom: 2px;
}

.detail-anomaly-msg {
  display: block;
  font-size: 13px;
  color: #991b1b;
  line-height: 1.4;
}

/* ── Back to Top ── */
.back-to-top {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 750;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid var(--border-strong);
  border-radius: 50%;
  background: var(--surface);
  color: var(--primary);
  box-shadow: 0 4px 14px rgba(15, 23, 42, 0.12);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0;
  visibility: hidden;
  transform: translateY(12px);
  transition: opacity 0.25s ease, visibility 0.25s ease, transform 0.25s ease, background 0.2s ease;
}

.back-to-top svg {
  width: 20px;
  height: 20px;
}

.back-to-top.is-visible {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.back-to-top:hover {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.back-to-top:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* ── Responsive ── */
@media (max-width: 960px) {
  .summary-grid { grid-template-columns: repeat(3, 1fr); }
  .filter-row { flex-wrap: wrap; }
  .filter-actions { margin-left: 0; width: 100%; }
  .results-grid { grid-template-columns: 1fr; }
}

@media (max-width: 600px) {
  .app-header {
    flex-direction: column;
    height: auto;
    padding: 10px 14px;
    gap: 10px;
  }
  .steps-inline { width: 100%; justify-content: center; }
  .summary-grid { grid-template-columns: repeat(2, 1fr); }
  .field-row { width: 100%; }
  .field-row input[type="datetime-local"],
  .aircraft-combobox { width: 100%; flex: 1; min-width: 0; }
  .control-panel.is-loaded .upload-compact { max-width: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
