/* =========================================================
   史丹演练服务站 · 响应式样式
   断点：>=1024 桌面侧栏 / 768-1023 平板 / <768 手机 + App
   适配：安全区 env(safe-area-inset-*) 、44px 触控目标、无横向滚动
   ========================================================= */

:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #fbfbfd;
  --line: #e8eaf0;
  --line-strong: #d9dde8;
  --ink: #1b1f2a;
  --ink-2: #4a5163;
  --ink-3: #868da1;
  --brand: #5b5bd6;
  --brand-soft: #eef0ff;
  --pink: #f0559a;
  --ok: #16a34a;
  --ok-soft: #e8f8ee;
  --warn: #d97706;
  --warn-soft: #fef3e2;
  --err: #dc2626;
  --err-soft: #fdecec;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(20, 24, 40, .04), 0 8px 24px -12px rgba(20, 24, 40, .16);
  --shadow-lg: 0 24px 60px -28px rgba(20, 24, 40, .4);
  --tabbar-h: 62px;
  --pad: 16px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  font-family: var(--font);
  overflow-x: hidden;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand); text-decoration: none; }

/* ---------- 启动占位 ---------- */
.boot { min-height: 100vh; display: grid; place-content: center; justify-items: center; gap: 14px; color: var(--ink-3); font-size: 13px; }
.boot-mark {
  width: 56px; height: 56px; border-radius: 18px; display: grid; place-items: center;
  font-size: 24px; font-weight: 800; color: #fff;
  background: linear-gradient(135deg, var(--brand), var(--pink));
  box-shadow: 0 16px 32px -18px rgba(91, 91, 214, .9);
  animation: bootPulse 1.4s ease-in-out infinite;
}
@keyframes bootPulse { 50% { transform: translateY(-6px) scale(1.04); } }

/* ---------- 布局骨架 ---------- */
.shell { min-height: 100vh; display: flex; }

.side {
  width: 232px; flex: 0 0 232px;
  padding: 22px 16px;
  background: var(--surface);
  border-right: 1px solid var(--line);
  position: sticky; top: 0; height: 100vh; height: 100dvh;
  display: flex; flex-direction: column; gap: 6px;
}
.brand { display: flex; align-items: center; gap: 11px; padding: 6px 8px 18px; }
.brand-mark {
  width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center;
  color: #fff; font-weight: 800; font-size: 17px;
  background: linear-gradient(135deg, var(--brand), var(--pink));
  box-shadow: 0 10px 22px -14px rgba(91, 91, 214, .9);
}
.brand-name { font-size: 15px; font-weight: 800; letter-spacing: .2px; }
.brand-sub { font-size: 11px; color: var(--ink-3); margin-top: 2px; }

.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 12px; border-radius: 11px; border: 0; background: transparent;
  color: var(--ink-2); font-size: 14px; font-weight: 600; cursor: pointer;
  text-align: left; width: 100%; transition: background .15s, color .15s;
}
.nav-item:hover { background: var(--surface-2); color: var(--ink); }
.nav-item.active { background: var(--brand-soft); color: var(--brand); font-weight: 700; }
.nav-item .ico { width: 18px; text-align: center; font-size: 15px; }
.side-foot { margin-top: auto; padding: 12px 10px 0; font-size: 11px; color: var(--ink-3); line-height: 1.7; border-top: 1px solid var(--line); }

.main { flex: 1; min-width: 0; padding: 26px 30px 60px; }
.main-inner { max-width: 1120px; margin: 0 auto; }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-title { font-size: 22px; font-weight: 800; letter-spacing: -.2px; }
.page-desc { font-size: 13px; color: var(--ink-3); margin-top: 5px; }

/* ---------- 卡片 / 栅格 ---------- */
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px;
}
.card + .card { margin-top: 14px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.card-title { font-size: 15px; font-weight: 800; }
.card-sub { font-size: 12px; color: var(--ink-3); margin-top: 3px; }

.grid { display: grid; gap: 12px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

/* ---------- 指标 ---------- */
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 14px 15px; }
.stat-label { font-size: 12px; color: var(--ink-3); display: flex; align-items: center; gap: 6px; }
.stat-value { font-size: 24px; font-weight: 800; letter-spacing: -.5px; margin-top: 6px; font-variant-numeric: tabular-nums; }
.stat-value small { font-size: 12px; font-weight: 600; color: var(--ink-3); margin-left: 4px; }
.stat-foot { font-size: 11px; color: var(--ink-3); margin-top: 4px; }

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  min-height: 40px; padding: 0 18px; border-radius: 10px; border: 1px solid transparent;
  background: var(--brand); color: #fff; font-size: 14px; font-weight: 700;
  cursor: pointer; transition: filter .15s, transform .1s, background .15s;
  white-space: nowrap;
}
.btn:hover { filter: brightness(1.06); }
.btn:active { transform: scale(.985); }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.btn-ghost { background: var(--surface); color: var(--ink-2); border-color: var(--line-strong); }
.btn-ghost:hover { background: var(--surface-2); color: var(--ink); }
.btn-soft { background: var(--brand-soft); color: var(--brand); }
.btn-danger { background: var(--err); }
.btn-sm { min-height: 32px; padding: 0 12px; font-size: 12px; border-radius: 8px; }
.btn-block { width: 100%; }

/* ---------- 表单 ---------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field > label { font-size: 12px; font-weight: 700; color: var(--ink-2); }
.input, .select {
  width: 100%; min-height: 42px; padding: 0 13px;
  border: 1px solid var(--line-strong); border-radius: 10px;
  background: var(--surface); font-size: 15px; outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.input:focus, .select:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.input::placeholder { color: #b3b9c7; }
.hint { font-size: 11px; color: var(--ink-3); line-height: 1.6; }

.badge {
  display: inline-flex; align-items: center; padding: 2px 7px; border-radius: 6px;
  font-size: 10px; font-weight: 800; background: #fff4e5; color: #b45309;
}
.badge-blue { background: var(--brand-soft); color: var(--brand); }
.badge-green { background: var(--ok-soft); color: var(--ok); }
.badge-red { background: var(--err-soft); color: var(--err); }
.badge-gray { background: #f1f2f6; color: var(--ink-3); }

/* ---------- 进度条 ---------- */
.bar { height: 8px; border-radius: 999px; background: #eceef5; overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--brand), var(--pink)); transition: width .5s ease; }
.bar.thin { height: 5px; }

/* ---------- 表格 ---------- */
.table-wrap { overflow-x: auto; border-radius: var(--radius-sm); -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
  text-align: left; padding: 9px 10px; font-size: 11px; font-weight: 700;
  color: var(--ink-3); border-bottom: 1px solid var(--line); white-space: nowrap; background: var(--surface-2);
}
tbody td { padding: 11px 10px; border-bottom: 1px solid #f1f2f6; vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fafbff; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; }
.num { font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }
.ellipsis { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- 提示 / 空态 ---------- */
.alert { padding: 11px 13px; border-radius: 10px; font-size: 13px; line-height: 1.6; }
.alert-ok { background: var(--ok-soft); color: #14803c; }
.alert-warn { background: var(--warn-soft); color: #a35a06; }
.alert-err { background: var(--err-soft); color: #b91c1c; }
.alert-info { background: var(--brand-soft); color: #4343b8; }

.empty { text-align: center; padding: 36px 16px; color: var(--ink-3); font-size: 13px; }
.empty .emoji { font-size: 32px; display: block; margin-bottom: 8px; opacity: .8; }

.toast-wrap {
  position: fixed; left: 50%; top: 18px; transform: translateX(-50%);
  z-index: 300; display: flex; flex-direction: column; gap: 8px; align-items: center;
  pointer-events: none; width: calc(100% - 32px); max-width: 420px;
}
.toast {
  padding: 10px 16px; border-radius: 10px; font-size: 13px; font-weight: 600;
  background: #1b1f2a; color: #fff; box-shadow: var(--shadow-lg);
  animation: toastIn .22s ease; max-width: 100%;
}
.toast.ok { background: #15803d; }
.toast.err { background: #b91c1c; }
@keyframes toastIn { from { opacity: 0; transform: translateY(-8px); } }

/* ---------- 弹层 ---------- */
.mask {
  position: fixed; inset: 0; background: rgba(17, 20, 30, .45);
  display: grid; place-items: center; padding: 16px; z-index: 200;
  backdrop-filter: blur(2px);
}
.modal {
  width: 100%; max-width: 460px; background: var(--surface); border-radius: 18px;
  box-shadow: var(--shadow-lg); padding: 22px; max-height: 86vh; overflow: auto;
  animation: modalIn .2s ease;
}
@keyframes modalIn { from { opacity: 0; transform: translateY(12px) scale(.98); } }
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.modal-title { font-size: 17px; font-weight: 800; }
.modal-close { border: 0; background: #f1f2f6; width: 30px; height: 30px; border-radius: 50%; cursor: pointer; color: var(--ink-3); flex: 0 0 auto; }
.modal-actions { display: flex; gap: 10px; margin-top: 18px; }
.modal-actions .btn { flex: 1; }

/* 订单号大字展示 */
.order-no {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 22px; font-weight: 800; letter-spacing: 1px;
  padding: 14px; border-radius: 12px; background: var(--brand-soft); color: var(--brand);
  text-align: center; word-break: break-all;
}

/* ---------- 记录列表 ---------- */
.rec { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid #f1f2f6; font-size: 12px; }
.rec:last-child { border-bottom: 0; }
.dot { width: 7px; height: 7px; border-radius: 50%; flex: 0 0 auto; background: var(--ink-3); }
.dot.ok { background: var(--ok); }
.dot.err { background: var(--err); }

/* ---------- 后台筛选行 ---------- */
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.filters .input, .filters .select { min-height: 36px; font-size: 13px; width: auto; min-width: 150px; }

/* ---------- 手机 / App 端 ---------- */
.mobile-top { display: none; }
.tabbar { display: none; }

@media (max-width: 1023px) {
  .side { display: none; }
  .main {
    padding: 0 var(--pad) calc(var(--tabbar-h) + 26px + env(safe-area-inset-bottom));
  }

  .mobile-top {
    display: flex; align-items: center; gap: 10px;
    position: sticky; top: 0; z-index: 60;
    margin: 0 calc(var(--pad) * -1) 16px;
    padding: calc(10px + env(safe-area-inset-top)) var(--pad) 10px;
    background: rgba(255, 255, 255, .92); backdrop-filter: saturate(180%) blur(14px);
    border-bottom: 1px solid var(--line);
  }
  .mobile-top .brand { padding: 0; flex: 1; }
  .mobile-top .brand-mark { width: 32px; height: 32px; border-radius: 10px; font-size: 15px; }
  .mobile-top .brand-name { font-size: 14px; }
  .mobile-top .brand-sub { display: none; }

  .tabbar {
    display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 80;
    height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: rgba(255, 255, 255, .96);
    backdrop-filter: saturate(180%) blur(16px);
    border-top: 1px solid var(--line);
  }
  .tab {
    border: 0; background: transparent; display: flex; flex-direction: column;
    align-items: center; justify-content: center; gap: 3px;
    font-size: 10px; font-weight: 700; color: var(--ink-3); cursor: pointer;
    padding-top: 6px;
  }
  .tab .ico { font-size: 18px; line-height: 1; }
  .tab.active { color: var(--brand); }

  .page-title { font-size: 19px; }
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 640px) {
  :root { --pad: 14px; }
  .grid-2, .grid-3 { grid-template-columns: minmax(0, 1fr); }
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .card { padding: 15px; border-radius: 14px; }
  .stat { padding: 12px; }
  .stat-value { font-size: 20px; }
  .modal { padding: 18px; border-radius: 16px; max-height: 90vh; }
  .order-no { font-size: 18px; letter-spacing: .5px; }
  .filters .input, .filters .select { flex: 1; min-width: 0; }
  .table-wrap { margin: 0 -15px; padding: 0 15px; }
  /* 窄屏表格转为横向滚动，避免挤压 */
  table { min-width: 560px; }
}

@media (max-width: 360px) {
  .grid-4 { grid-template-columns: minmax(0, 1fr); }
  table { min-width: 520px; }
}

/* 触屏优化：可点区域不小于 44px */
@media (hover: none) {
  .nav-item, .btn, .tab { touch-action: manipulation; }
  .btn { min-height: 44px; }
  .btn-sm { min-height: 36px; }
}

/* 深色模式（跟随系统），App 内嵌同样生效 */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1116; --surface: #171a21; --surface-2: #1c2029;
    --line: #262b36; --line-strong: #333a48;
    --ink: #eef1f7; --ink-2: #b9c0ce; --ink-3: #7d8798;
    --brand-soft: #232544; --shadow: 0 1px 2px rgba(0,0,0,.4), 0 10px 28px -16px rgba(0,0,0,.8);
  }
  body { background: var(--bg); }
  .side, .mobile-top, .tabbar { background: var(--surface); }
  .mobile-top { background: rgba(23, 26, 33, .94); }
  .tabbar { background: rgba(23, 26, 33, .96); }
  tbody tr:hover { background: #1b1f28; }
  .input, .select { background: var(--surface-2); }
  .badge { background: #3a2a17; color: #f0b062; }
  .badge-blue { background: var(--brand-soft); color: #a9a9ff; }
  .badge-green { background: #12351f; color: #7ee2a0; }
  .badge-red { background: #3a1717; color: #ff9c9c; }
  .badge-gray { background: #23262f; color: var(--ink-3); }
  .bar { background: #262b36; }
  .alert-ok { background: #12351f; color: #7ee2a0; }
  .alert-warn { background: #35280f; color: #f0b062; }
  .alert-err { background: #3a1717; color: #ff9c9c; }
  .alert-info { background: var(--brand-soft); color: #a9a9ff; }
  .order-no { background: var(--brand-soft); color: #b9b9ff; }
  .toast { background: #2a2f3b; }
}

/* 独立后台布局 */
.admin-standalone { min-height: 100vh; display: flex; background: var(--bg); }
.admin-standalone .admin-side { position: sticky; top: 0; height: 100vh; }
.admin-standalone .admin-main { width: calc(100% - 236px); }
.admin-standalone .admin-main .main-inner { max-width: 1180px; }
@media (max-width: 900px) {
  .admin-standalone { display: block; }
  .admin-standalone .admin-side { display: none; }
  .admin-standalone .admin-main { width: 100%; }
}
