/* ========== BigAuto 管理后台样式（手机优先） ========== */
* { box-sizing: border-box; margin: 0; padding: 0; }

/* 保证 hidden 属性在任何自定义 display 规则下仍然生效 */
[hidden] { display: none !important; }

:root {
  --dark: #1f2937;
  --dark-2: #111827;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --green: #16a34a;
  --orange: #ea580c;
  --red: #dc2626;
  --gray: #6b7280;
  --line: #e5e7eb;
  --bg: #f3f4f6;
  --radius: 10px;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: #111827;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  -webkit-text-size-adjust: 100%;
}

button { font-family: inherit; cursor: pointer; }
input, select { font-family: inherit; font-size: 16px; } /* 16px 防 iOS 聚焦放大 */

.muted { color: var(--gray); font-size: 13px; }
.text-green { color: var(--green); }
.text-orange { color: var(--orange); }
.text-gray { color: var(--gray); }

/* ---------- 按钮 ---------- */
.btn {
  min-height: 40px;
  padding: 8px 16px;
  border: 1px solid transparent;
  border-radius: 8px;
  font-size: 15px;
  background: #e5e7eb;
  color: #111827;
  transition: opacity .15s, background .15s;
}
.btn:active { opacity: .8; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-success { background: var(--green); color: #fff; }
.btn-danger  { background: var(--red); color: #fff; }
.btn-outline { background: #fff; border-color: #d1d5db; color: #374151; }
.btn-ghost { background: transparent; border-color: rgba(255,255,255,.35); color: #fff; }
.btn-sm { min-height: 36px; padding: 6px 12px; font-size: 14px; }
.btn-block { width: 100%; }

/* ---------- 登录页 ---------- */
.login-view {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: #fff;
  border-radius: 14px;
  padding: 28px 22px;
  box-shadow: 0 8px 30px rgba(0,0,0,.08);
}
.login-title { font-size: 22px; text-align: center; }
.login-sub { text-align: center; color: var(--gray); font-size: 14px; margin: 8px 0 22px; }
.field { display: block; margin-bottom: 16px; }
.field-label { display: block; font-size: 14px; color: #374151; margin-bottom: 6px; }
.field input {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  background: #fff;
}
.field input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.15); }
.login-error {
  background: #fef2f2;
  color: var(--red);
  border: 1px solid #fecaca;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 14px;
  margin-bottom: 16px;
  word-break: break-all;
}

/* ---------- 顶部标题栏 ---------- */
.topbar { background: var(--dark); color: #fff; position: sticky; top: 0; z-index: 20; }
.topbar-inner {
  max-width: 960px;
  margin: 0 auto;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.brand { font-size: 17px; font-weight: 600; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.admin-name { font-size: 14px; color: #d1d5db; }

.tabs {
  max-width: 960px;
  margin: 0 auto;
  display: flex;
  padding: 0 8px;
  gap: 4px;
}
.tab {
  flex: 1;
  min-height: 44px;
  background: transparent;
  border: none;
  color: #9ca3af;
  font-size: 15px;
  border-bottom: 3px solid transparent;
}
.tab.active { color: #fff; border-bottom-color: #60a5fa; font-weight: 600; }

/* ---------- 内容区 ---------- */
.content { max-width: 960px; margin: 0 auto; padding: 16px 12px 40px; }
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}
.panel-head h2 { font-size: 19px; }
.refresh-bar { display: flex; align-items: center; gap: 10px; }

/* 统计卡 */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}
.stat-card {
  background: #fff;
  border-radius: var(--radius);
  padding: 16px 14px;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
}
.stat-num { font-size: 30px; font-weight: 700; line-height: 1.1; }
.stat-label { color: var(--gray); font-size: 13px; margin-top: 6px; }
.stat-warn { background: #fff7ed; }

/* 卡片容器 */
.card {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
  overflow: hidden;
}
.card-head { padding: 12px 14px; border-bottom: 1px solid var(--line); }
.card-head h3 { font-size: 15px; }

/* 工具条 */
.toolbar { display: flex; gap: 8px; margin-bottom: 12px; }
.toolbar-wrap { flex-wrap: wrap; }
.input {
  flex: 1;
  min-width: 0;
  min-height: 40px;
  padding: 8px 12px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  background: #fff;
}
.input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.15); }
.select-sm { flex: 0 0 auto; min-height: 40px; padding: 6px 8px; }

/* 日期快捷筛选 */
.preset-group { display: flex; gap: 6px; flex-wrap: wrap; }
.preset {
  min-height: 36px;
  padding: 4px 14px;
  border-radius: 999px;
  border: 1px solid #d1d5db;
  background: #fff;
  color: #374151;
  font-size: 14px;
}
.preset.active { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }
.date-range { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.date-range .input { flex: 1; min-width: 130px; }

/* 设备详情弹窗 */
.detail-list { display: flex; flex-direction: column; gap: 0; }
.detail-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}
.detail-row:last-child { border-bottom: none; }
.detail-row .k { color: var(--gray); flex: 0 0 auto; }
.detail-row .v { text-align: right; word-break: break-all; }
.detail-section-title { font-weight: 600; font-size: 14px; margin: 14px 0 6px; }
.change-pwd-tip { color: var(--gray); font-size: 13px; margin-top: 8px; }

/* 子标签 */
.subtabs { display: flex; gap: 6px; margin-bottom: 14px; }
.subtab {
  min-height: 40px;
  padding: 6px 18px;
  border-radius: 8px;
  border: 1px solid #d1d5db;
  background: #fff;
  color: #374151;
}
.subtab.active { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }

/* ---------- 设备表格（宽屏表格 / 窄屏卡片） ---------- */
.table-wrap { overflow-x: auto; }
table.device-table { width: 100%; border-collapse: collapse; min-width: 920px; }
.device-table th, .device-table td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
  vertical-align: middle;
}
.device-table th { color: var(--gray); font-weight: 600; white-space: nowrap; background: #fafafa; }
.device-table tr:last-child td { border-bottom: none; }
.device-code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }
.op-btns { display: flex; gap: 6px; flex-wrap: nowrap; }

/* 状态标签 */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 13px;
  white-space: nowrap;
}
.badge-green  { background: #dcfce7; color: #166534; }
.badge-gray   { background: #f3f4f6; color: #4b5563; }
.badge-orange { background: #ffedd5; color: #9a3412; }
.badge-red    { background: #fee2e2; color: #991b1b; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; display: inline-block; }
.dot-off { background: #d1d5db; }

/* 简单列表（仪表盘/记录页） */
.simple-list { padding: 4px 0; }
.list-row {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.list-row:last-child { border-bottom: none; }
.list-row .row-line1 { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.list-row .row-line2 { color: var(--gray); font-size: 13px; display: flex; gap: 12px; flex-wrap: wrap; }
.list-footer { padding: 12px; }

.loading-tip { padding: 24px; text-align: center; color: var(--gray); }
.error-tip { padding: 20px 14px; text-align: center; color: var(--red); }
.empty-tip { padding: 24px; text-align: center; color: var(--gray); }

/* ---------- 弹窗 ---------- */
.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(17,24,39,.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  z-index: 50;
}
.modal {
  width: 100%;
  max-width: 420px;
  background: #fff;
  border-radius: 14px;
  overflow: hidden;
}
.modal-head { padding: 16px 18px 0; }
.modal-head h3 { font-size: 17px; }
.modal-body { padding: 14px 18px; font-size: 15px; line-height: 1.6; }
.modal-body .modal-device {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: #f3f4f6;
  border-radius: 6px;
  padding: 8px 10px;
  margin: 8px 0;
  word-break: break-all;
  font-size: 14px;
}
.modal-body select {
  width: 100%;
  min-height: 44px;
  margin-top: 10px;
  padding: 8px 10px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
}
.modal-warn { color: var(--red); font-size: 14px; margin-top: 8px; }
.modal-foot { padding: 0 18px 18px; display: flex; gap: 10px; }
.modal-foot .btn { flex: 1; }

/* ---------- 轻提示 ---------- */
.toast-box {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: calc(100% - 32px);
  max-width: 420px;
  pointer-events: none;
}
.toast {
  padding: 12px 16px;
  border-radius: 10px;
  color: #fff;
  font-size: 14px;
  text-align: center;
  box-shadow: 0 6px 20px rgba(0,0,0,.18);
  word-break: break-all;
  animation: toast-in .2s ease;
}
.toast-ok { background: #166534; }
.toast-err { background: #991b1b; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }

/* ---------- 可点击统计卡 / 快捷入口 ---------- */
.stat-clickable { cursor: pointer; transition: box-shadow .15s, transform .1s; border: 1px solid transparent; }
.stat-clickable:hover { box-shadow: 0 3px 10px rgba(0,0,0,.12); border-color: #dbe3f0; }
.stat-clickable:active { transform: scale(.98); }

.quick-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}
.quick-btn {
  min-height: 48px;
  border: 1px solid #dbe3f0;
  background: #fff;
  border-radius: var(--radius);
  font-size: 14px;
  color: #1f2937;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
}
.quick-btn:active { background: #eff6ff; }

/* ---------- 小统计卡（数据页/卡密概况） ---------- */
.mini-stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(104px, 1fr));
  gap: 8px;
  padding: 12px 14px 4px;
}
.mini-stat {
  background: #f9fafb;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  text-align: center;
}
.mini-num { font-size: 22px; font-weight: 700; line-height: 1.15; }
.mini-label { font-size: 12px; color: var(--gray); margin-top: 4px; }

/* ---------- 时长分布条 ---------- */
.duration-dist { padding: 10px 14px 14px; }
.dist-row { margin-top: 8px; }
.dist-head {
  display: flex; justify-content: space-between; gap: 8px;
  font-size: 13px; margin-bottom: 4px; flex-wrap: wrap;
}
.dist-bar {
  display: flex;
  height: 10px;
  border-radius: 5px;
  background: #e5e7eb;
  overflow: hidden;
}
.dist-seg { display: block; height: 100%; }
.seg-used { background: var(--green); }
.seg-void { background: var(--orange); }

/* ---------- 图表 ---------- */
.chart-box { padding: 10px 8px 6px; }
.chart-svg { width: 100%; height: auto; display: block; }
.chart-legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--gray); }
.legend-dot { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 5px; vertical-align: 0; }

/* ---------- 数据页漏斗三板块 ---------- */
.funnel-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}
.funnel-card { display: flex; flex-direction: column; }
.funnel-card .funnel-sub { margin-top: 6px; line-height: 1.6; }
.funnel-card .mini-stat-grid { padding: 12px 14px 4px; }
.funnel-foot {
  margin-top: auto;
  padding: 12px 14px;
  border-top: 1px solid var(--line);
  font-size: 13px;
}

/* 激活记录的首激/续期徽章 */
.badge-group { display: inline-flex; gap: 6px; flex-wrap: wrap; }
.badge-kind-first { background: #dbeafe; color: #1e40af; }
.badge-kind-renewal { background: #ffedd5; color: #9a3412; }

@media (max-width: 860px) {
  .funnel-grid { grid-template-columns: 1fr; }
}

/* ---------- 卡密明文框 ---------- */
.card-plain {
  width: 100%;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 14px;
  line-height: 1.7;
  padding: 10px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  background: #f9fafb;
  color: #111827;
  white-space: pre;
}

/* ---------- 数据同步页 ---------- */
.sync-card { margin-bottom: 14px; }
/* 同步状态格：电脑端一行 4 格，手机端一行 2 格（共 8 项：电脑 4+4，手机 2×4） */
.sync-status-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1px;
  background: var(--line);
  border-bottom: 1px solid var(--line);
}
.sync-kv { background: #fff; padding: 10px 14px; }
.sync-kv .k { color: var(--gray); font-size: 12px; margin-bottom: 3px; }
.sync-kv .v { font-size: 14px; word-break: break-all; }
.sync-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  padding: 12px 14px 4px;
}
.sync-interval-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 14px; }
.sync-interval-input { flex: 0 0 90px; width: 90px; min-width: 90px; min-height: 40px; }
.sync-tip { padding: 8px 14px 14px; font-size: 12px; line-height: 1.6; }

/* 四张清单卡：2×2 方块布局，窄屏回落单列 */
.sync-lists {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 14px;
}
.sync-list-card { display: flex; flex-direction: column; }
.sync-list-card .sync-editor { flex: 1; display: flex; flex-direction: column; padding-top: 12px; }
.sync-list-card .sync-editor-foot { margin-top: auto; padding-top: 12px; }
.sync-list-card .sync-textarea { flex: 1; }
.sync-list-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  padding: 12px 14px 0;
}
.sync-list-head h3 { font-size: 15px; }

/* 标题下方的档位开关行（四张卡位置统一），底部分隔线 */
.sync-mode-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 10px 14px 12px;
  border-bottom: 1px solid var(--line);
}
.sync-mode-hint { font-size: 12px; }
.mode-switch { display: inline-flex; border: 1px solid #d1d5db; border-radius: 8px; overflow: hidden; }
.mode-btn {
  min-height: 34px;
  padding: 4px 14px;
  border: none;
  background: #fff;
  color: #374151;
  font-size: 13px;
}
.mode-btn + .mode-btn { border-left: 1px solid #d1d5db; }
.mode-btn.active { background: var(--primary); color: #fff; font-weight: 600; }
.mode-btn:disabled { opacity: .55; cursor: not-allowed; }
.mode-fixed {
  display: inline-flex; align-items: center;
  padding: 5px 12px; border-radius: 999px;
  background: #f3f4f6; color: #4b5563; font-size: 12px;
}
.sync-editor { padding: 12px 14px; }
.sync-textarea {
  width: 100%;
  min-height: 150px;
  padding: 10px 12px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  font-size: 14px;
  line-height: 1.7;
  resize: vertical;
}
.sync-textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.15); }
.sync-textarea:disabled { background: #f9fafb; color: #374151; }
.sync-station-row { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.sync-station-row:last-child { margin-bottom: 0; }
.sync-station-name { flex: 0 0 72px; font-size: 14px; color: #374151; }
.sync-station-row .input { flex: 1; min-height: 40px; }
.sync-editor-foot {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; flex-wrap: wrap; margin-top: 10px;
}

.sync-raw { padding: 8px 14px 14px; }
.sync-raw details { border: 1px solid var(--line); border-radius: 8px; margin-top: 8px; }
.sync-raw summary {
  cursor: pointer;
  padding: 9px 12px;
  font-size: 14px;
  font-weight: 600;
  list-style: revert;
  user-select: none;
}
.sync-raw details details { margin: 8px 10px; }
.sync-raw .raw-table-wrap { overflow-x: auto; padding: 0 10px 10px; }
.sync-raw table { width: 100%; border-collapse: collapse; min-width: 360px; }
.sync-raw th, .sync-raw td {
  padding: 7px 10px;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
  text-align: left;
  white-space: nowrap;
}
.sync-raw th { color: var(--gray); background: #fafafa; }
.sync-raw th.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
.sync-raw th.sortable:hover { color: #111827; background: #f3f4f6; }
.sync-raw .sort-mark { font-size: 10px; margin-left: 2px; color: var(--primary); }
.sync-raw .sort-idle { font-size: 10px; margin-left: 2px; color: #d1d5db; }
.sync-raw .raw-num { text-align: right; font-variant-numeric: tabular-nums; }
.sync-raw .raw-pos { color: var(--green); font-weight: 600; }

/* 四工作台切换 tab */
.station-tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  padding: 10px 12px 4px;
}
.station-tab {
  min-height: 38px;
  padding: 6px 16px;
  border-radius: 8px;
  border: 1px solid #d1d5db;
  background: #fff;
  color: #374151;
  font-size: 14px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
}
.station-tab.active { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }
.station-tab-count {
  font-size: 12px;
  background: #f3f4f6;
  color: #4b5563;
  border-radius: 999px;
  padding: 1px 8px;
  font-variant-numeric: tabular-nums;
}
.station-tab.active .station-tab-count { background: rgba(255,255,255,.22); color: #fff; }
.sync-raw .raw-neg { color: var(--red); }
.sync-raw tr.raw-row-pick td { background: #f0fdf4; }

/* 屏太窄时两卡并排太挤，回落上下竖排 */
@media (max-width: 860px) {
  .sync-lists { grid-template-columns: 1fr; }
}

/* ---------- 窄屏：设备表变卡片 ---------- */
@media (max-width: 719px) {
  /* 同步状态手机端一行两格，收紧间距和字号防止挤压 */
  .sync-status-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .sync-kv { padding: 8px 8px; }
  .sync-kv .k { font-size: 11px; }
  .sync-kv .v { font-size: 12px; }

  /* 5 个标签时允许横向滑动，不挤压文字 */
  .tabs { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .tab { flex: 0 0 auto; padding: 0 16px; }

  .quick-grid { grid-template-columns: 1fr; }
  /* 审计筛选条三行排布，避免输入框被压扁 */
  .toolbar-wrap { flex-direction: column; align-items: stretch; }
  .toolbar-wrap .input,
  .toolbar-wrap .select-sm { width: 100%; flex: none; }
  .toolbar-wrap .btn { width: 100%; }

  table.device-table { min-width: 0; }
  .device-table thead { display: none; }
  .device-table, .device-table tbody, .device-table tr, .device-table td { display: block; width: 100%; }
  .device-table tr {
    padding: 10px 14px;
    border-bottom: 8px solid var(--bg);
  }
  .device-table td {
    border-bottom: none;
    padding: 4px 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 14px;
    text-align: right;
  }
  .device-table td::before {
    content: attr(data-label);
    color: var(--gray);
    font-size: 13px;
    text-align: left;
    flex: 0 0 auto;
  }
  .device-table td.cell-code { display: block; text-align: left; }
  .device-table td.cell-code::before { display: none; }
  .device-table td.cell-ops { justify-content: stretch; margin-top: 6px; }
  .device-table td.cell-ops::before { display: none; }
  .op-btns { width: 100%; flex-wrap: wrap; }
  .op-btns .btn { flex: 1 1 42%; }
  .admin-name { display: none; }
}
