:root {
  --primary: #3b82f6;
  --primary-dark: #2563eb;
  --success: #10b981;
  --warning: #f59e0b;
  --error: #ef4444;
  --text: #1e293b;
  --text-title: #374151;
  --text-body: #6b7280;
  --text-muted: #94a3b8;
  --border: #e5e7eb;
  --border-slate: #e2e8f0;
  --surface: #f8fafc;
  --surface-muted: #f9fafb;
  --sidebar-w: 240px;
  --radius: 6px;
  --radius-card: 12px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.06);
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: Inter, "PingFang SC", "Noto Sans SC", system-ui, sans-serif;
  color: var(--text);
  background: #fff;
  font-size: 14px;
  line-height: 1.5;
}
button, input, select, textarea { font: inherit; }
a { color: var(--primary); text-decoration: none; }
button { cursor: pointer; }
#app { height: 100%; }

/* —— Auth —— */
.login-screen {
  height: 100%;
  background: radial-gradient(circle, #47c2ff, #478bff);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}
.login-lang {
  position: absolute;
  top: 1rem;
  right: 1rem;
  color: #fff;
  background: transparent;
  border: 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
}
.login-wrap { width: 80%; max-width: 500px; margin-top: -30px; }
.login-logo {
  display: flex;
  justify-content: center;
  margin-bottom: 16px;
}
.login-logo-mark {
  width: 64px;
  height: 64px;
  border-radius: 12px;
  background: var(--primary);
  display: grid;
  place-items: center;
  box-shadow: 0 8px 20px rgba(37, 99, 235, 0.35);
}
.login-card {
  background: #fff;
  padding: 20px;
  border-radius: 16px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  text-align: center;
}
.login-card h3 {
  margin: 0 0 16px;
  font-size: 18px;
  font-weight: 600;
  color: var(--text-title);
}
.field {
  position: relative;
  margin: 12px 0 8px;
  text-align: left;
}
.field input, .field select, .field textarea {
  width: 100%;
  min-height: 48px;
  padding: 12px 14px;
  border: 1px solid #d1d5db;
  border-radius: var(--radius);
  background: #fff;
  color: var(--text);
  outline: none;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.12);
}
.field label {
  position: absolute;
  top: -8px;
  left: 10px;
  padding: 0 4px;
  background: #fff;
  font-size: 12px;
  color: var(--text-body);
}
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 0;
  border-radius: var(--radius);
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 500;
  line-height: 1.4;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-ghost { background: transparent; color: var(--primary); }
.btn-outline {
  background: transparent;
  color: var(--primary);
  border: 1px solid var(--primary);
}
.btn-block { width: 100%; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-danger, .btn-danger-text { color: var(--error); background: transparent; border: 0; }
.mt-8 { margin-top: 8px; }
.mt-12 { margin-top: 12px; }

/* —— App shell —— */
.app-layout { display: flex; height: 100%; background: #fff; }
.app-sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 24px 20px;
  background: var(--surface);
  border-right: 1px solid var(--border-slate);
  overflow-y: auto;
}
.brand {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
}
.brand span { color: var(--primary); }
.sidebar-conn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px;
  background: #fff;
  border: 1px solid var(--border-slate);
  border-radius: var(--radius-card);
}
.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.dot-off { background: #94a3b8; }
.dot-on { background: var(--success); }
.sidebar-conn h4 { margin: 0; font-size: 13px; font-weight: 600; }
.sidebar-nav { display: flex; flex-direction: column; gap: 4px; }
.sidebar-nav-label {
  margin: 0 0 8px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.5px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 8px;
  color: #475569;
  font-size: 14px;
  font-weight: 500;
}
.nav-item:hover { background: #e2e8f0; }
.nav-item.active { background: #3b82f620; color: var(--primary); }
.nav-item svg { width: 20px; height: 20px; flex-shrink: 0; }
.main-content { flex: 1; min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.content { flex: 1; min-height: 0; overflow-y: auto; background: #fff; display: flex; flex-direction: column; }
.app-layout.diagnosis .app-sidebar { display: none; }

.dash-header {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 32px;
  min-height: 72px;
  background: linear-gradient(180deg, #3b82f6 0%, #2563eb 100%);
  color: #fff;
}
.dash-header-title { display: flex; align-items: center; gap: 8px; min-width: 0; }
.back-btn {
  color: #fff;
  background: transparent;
  border: 0;
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  padding: 0;
}
.back-btn:hover { background: rgba(255,255,255,0.12); }
.header-primary { font-size: 20px; font-weight: 700; line-height: 1.25; }
.header-secondary { font-size: 12px; color: rgba(255,255,255,0.85); }
.header-pills { display: flex; align-items: center; gap: 8px; flex-shrink: 0; flex-wrap: wrap; }
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 28px;
  padding: 0 12px;
  border-radius: 16px;
  font-size: 12px;
  background: rgba(255,255,255,0.16);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.35);
  white-space: nowrap;
}
.pill-solid { background: #fff; color: var(--primary-dark); border-color: #fff; }

/* —— Dashboard —— */
.page { padding: 24px 32px; }
.page-home { padding: 24px 32px; }
.section-label {
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.5px;
  margin-bottom: 16px;
}
.primary-cards { display: flex; gap: 16px; margin-bottom: 24px; }
.primary-card {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 28px 20px;
  border: 0;
  border-radius: 16px;
  color: #fff;
  text-align: left;
}
.primary-card.blue { background: var(--primary); }
.primary-card.green { background: var(--success); }
.primary-card-icon {
  width: 44px; height: 44px; border-radius: 12px;
  background: rgba(255,255,255,0.2);
  display: grid; place-items: center;
}
.primary-card h3 { margin: 0 0 2px; font-size: 15px; font-weight: 700; }
.primary-card p { margin: 0; font-size: 11px; opacity: 0.8; }
.primary-card .chev { margin-left: auto; opacity: 0.6; }
.grid-row { display: flex; gap: 16px; margin-bottom: 16px; }
.grid-item {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 20px;
  border: 1px solid #f1f5f9;
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  text-align: left;
}
.grid-icon {
  width: 40px; height: 40px; border-radius: 10px;
  display: grid; place-items: center; flex-shrink: 0;
}
.grid-icon.blue { background: #eff6ff; color: var(--primary); }
.grid-icon.purple { background: #f5f3ff; color: #7c3aed; }
.grid-icon.yellow { background: #fffbeb; color: var(--warning); }
.grid-icon.green { background: #ecfdf5; color: var(--success); }
.grid-icon svg, .device-row .grid-icon svg { width: 20px; height: 20px; }
.primary-card-icon svg { width: 24px; height: 24px; stroke: #fff; }
.app-layout.diagnosis .content { background: #f5f7fa; }
.grid-item h4 { margin: 0 0 2px; font-size: 14px; font-weight: 600; }
.grid-item p { margin: 0; font-size: 12px; color: var(--text-muted); }
.device-section { margin-top: 28px; }
.device-card {
  padding: 24px 20px;
  background: var(--surface);
  border: 1px solid #f1f5f9;
  border-radius: 16px;
}
.device-row {
  display: flex; align-items: center; gap: 14px;
  padding: 16px 0; border-bottom: 1px solid #f1f5f9;
}
.device-row:first-child { padding-top: 0; }
.device-row:last-child { border-bottom: 0; padding-bottom: 0; }
.device-row-text { display: flex; flex-direction: column; gap: 2px; }
.device-row-label { font-size: 12px; color: var(--text-muted); }
.device-row-value { font-size: 14px; font-weight: 600; color: var(--text); }

/* —— Cards / lists / tables —— */
.card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow);
}
.card-pad { padding: 20px; }
.card-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  color: var(--text-title);
}
.card-head .link { margin-left: auto; font-weight: 500; font-size: 13px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.row-list { list-style: none; margin: 0; padding: 0; }
.row-list li, .row-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 14px 20px;
  border: 0;
  border-bottom: 1px solid var(--border);
  background: #fff;
  text-align: left;
  color: inherit;
}
.row-list li:last-child, .row-btn:last-child { border-bottom: 0; }
.row-btn:hover { background: #f8fafc; }
.row-title { font-size: 14px; font-weight: 500; color: var(--text); }
.row-sub { font-size: 12px; color: var(--text-body); }
.row-main { flex: 1; min-width: 0; }
.chev-muted { color: var(--text-muted); margin-left: auto; }
.kv-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.kv-row:last-child { border-bottom: 0; }
.kv-label { color: var(--text-title); }
.kv-value { color: var(--text-body); }
.list-card { overflow: hidden; }
.list-sub {
  padding: 12px 16px;
  background: var(--surface-muted);
  color: var(--text-body);
  font-size: 13px;
  font-weight: 600;
  border-bottom: 1px solid var(--border);
}

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 80px 24px;
  color: var(--text-muted);
}
.empty svg { width: 72px; height: 72px; opacity: 0.45; }

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.table th, .table td {
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.table th {
  background: var(--surface-muted);
  color: var(--text-body);
  font-weight: 600;
  white-space: nowrap;
}
.chip {
  display: inline-flex;
  align-items: center;
  height: 22px;
  padding: 0 8px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 500;
}
.chip-info { color: #0288d1; border: 1px solid #81d4fa; background: #e1f5fe; }
.chip-ok { color: #047857; background: #d1fae5; }
.chip-off { color: #6b7280; background: #f3f4f6; }
.chip-warn { color: #b45309; background: #fef3c7; }
.chip-err { color: #b91c1c; background: #fee2e2; }

.form-card { max-width: 720px; margin: 0 auto; padding: 28px 32px; }
.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.stack-btns { display: flex; flex-direction: column; gap: 12px; margin-top: 20px; }

.tabs { display: flex; gap: 0; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.tab {
  padding: 12px 16px;
  border: 0;
  background: transparent;
  color: var(--text-body);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }

.search {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 24px;
  background: var(--surface-muted);
  margin: 12px 20px 16px;
}
.search input { border: 0; background: transparent; outline: none; flex: 1; min-width: 0; }
.action-card {
  margin: 0 20px 12px;
  padding: 16px 18px;
  background: var(--surface);
  border-radius: 12px;
  border: 0;
  width: calc(100% - 40px);
  text-align: left;
}
.action-card h4 { margin: 0 0 4px; font-size: 14px; }
.action-card p { margin: 0; font-size: 12px; color: var(--text-body); }

.stepper { display: flex; flex-direction: column; gap: 12px; }
.step {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 12px; border-radius: 8px; background: var(--surface);
}
.step-num {
  width: 24px; height: 24px; border-radius: 50%;
  background: #e5e7eb; color: #374151;
  display: grid; place-items: center; font-size: 12px; font-weight: 700;
}
.step.done .step-num { background: var(--success); color: #fff; }
.step.active .step-num { background: var(--primary); color: #fff; }
.progress {
  height: 8px; background: #e5e7eb; border-radius: 8px; overflow: hidden;
}
.progress > span { display: block; height: 100%; background: var(--primary); }

.hex-box {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
  letter-spacing: 0.04em;
  min-height: 88px;
  resize: vertical;
}

.accordion {
  border: 1px solid var(--border);
  border-radius: 4px;
  margin-bottom: 8px;
  overflow: hidden;
  background: #fff;
}
.accordion-head {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  background: #fff;
  border: 0;
  text-align: left;
}
.accordion-head-name { font-size: 14px; font-weight: 500; }
.accordion-head-end {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}
.accordion-expand {
  width: 24px;
  height: 24px;
  color: #6b7280;
  transition: transform 0.2s;
}
.accordion.open .accordion-expand { transform: rotate(180deg); }
.accordion-body { padding: 8px 16px 16px; display: none; }
.accordion.open .accordion-body { display: block; }
.card-outlined {
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: none;
}
.table-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.chip-count {
  min-width: 22px;
  justify-content: center;
  font-weight: 700;
  color: #fff;
}
.chip-count-zero { background: var(--primary); }
.chip-count-err { background: #d32f2f; }
.dtc-layout {
  min-height: 100%;
  flex: 1;
  display: flex;
  flex-direction: column;
}
.dtc-body { flex: 1; padding: 24px 32px 88px; }
.dtc-bottom-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  display: flex;
  gap: 16px;
  padding: 12px 16px;
  background: #fff;
  box-shadow: 0 -2px 4px rgba(0, 0, 0, 0.1);
}
.dtc-bottom-bar .btn { flex: 1; }

.toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }

/* —— Overlay —— */
.card-head svg { width: 20px; height: 20px; flex-shrink: 0; }
.toast-host {
  position: fixed;
  top: auto;
  bottom: 88px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 80;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  min-width: 240px;
  padding: 10px 16px;
  border-radius: 8px;
  color: #fff;
  background: #323232;
  box-shadow: 0 8px 24px rgba(0,0,0,0.18);
  font-size: 13px;
  text-align: center;
}
.toast.success { background: #059669; }
.toast.error { background: #dc2626; }
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 70;
  padding: 24px;
}
.overlay.show { display: flex; }
.dialog {
  width: 100%;
  max-width: 420px;
  background: #fff;
  border-radius: var(--radius-card);
  box-shadow: 0 16px 48px rgba(0,0,0,0.2);
  overflow: hidden;
}
.dialog.wide { max-width: 640px; }
.dialog-title { padding: 16px 20px 8px; font-size: 16px; font-weight: 600; }
.dialog-body { padding: 8px 20px 16px; color: var(--text-body); max-height: 60vh; overflow: auto; }
.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 16px 16px;
}
.radio {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  cursor: pointer;
  color: var(--text);
}
.pdf-frame {
  height: 360px;
  border: 1px dashed var(--border);
  border-radius: 8px;
  display: grid;
  place-items: center;
  color: var(--text-muted);
  background: var(--surface);
}

.select-mini {
  min-width: 140px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0 8px;
  background: #fff;
}

.license-card {
  max-width: 560px;
  margin: 24px auto;
  padding: 28px;
  border-radius: 16px;
  background: linear-gradient(180deg, #eff6ff, #fff);
  border: 1px solid #dbeafe;
}
.license-status { font-size: 18px; font-weight: 700; margin: 8px 0; }
.fn-page { padding: 16px 24px 24px; }
.fn-title {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0 0 8px;
  font-size: 16px;
  font-weight: 600;
  color: var(--text-title);
}
.fn-title svg { width: 22px; height: 22px; }
.fn-divider { border: 0; border-top: 1px solid var(--border); margin: 0 0 16px; }
.fn-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
}
.fn-card {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 96px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  text-align: center;
  line-height: 1.4;
  word-break: break-word;
}
.fn-card:hover { background: #f8fafc; }

.log-stack { display: flex; flex-direction: column; gap: 16px; max-width: 920px; margin: 0 auto; }
.log-card-title { margin: 0 0 6px; font-size: 16px; font-weight: 600; color: var(--text-title); }
.log-hint { margin: 0 0 14px; font-size: 13px; color: var(--text-body); line-height: 1.55; }
.log-check { display: flex; align-items: center; gap: 8px; cursor: pointer; color: var(--text); }
.log-check input { width: 16px; height: 16px; }
.log-time-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.log-time-row input { min-width: 200px; }
.log-sep { color: var(--text-muted); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #059669; }
.btn-success:disabled { opacity: 0.45; cursor: not-allowed; }
.log-actions { display: flex; gap: 12px; margin-top: 16px; }
.log-empty { padding: 28px 16px; text-align: center; color: var(--text-muted); }

.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 90;
}
.loading-overlay.show { display: flex; }
.loading-box {
  background: #fff;
  border-radius: 12px;
  padding: 28px 36px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  min-width: 220px;
  box-shadow: 0 16px 48px rgba(0,0,0,0.2);
}
.loading-box p { margin: 0; color: var(--text-title); font-size: 14px; }
.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid #dbeafe;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 900px) {
  .app-sidebar { display: none; }
  .two-col, .primary-cards, .grid-row, .form-grid-2 { grid-template-columns: 1fr; flex-direction: column; }
  .fn-grid { grid-template-columns: repeat(2, 1fr); }
  .page, .page-home { padding: 16px; }
  .dash-header { padding: 16px 20px; flex-wrap: wrap; }
}
