:root {
  color-scheme: light;
  --primary: #0066cc;
  --primary-hover: #0052a3;
  --primary-soft: #ebf4ff;
  --primary-border: #bfdbfe;
  --green: #10b981;
  --green-hover: #059669;
  --danger: #dc2626;
  --bg: #f5f7fb;
  --card: #ffffff;
  --ink: #0f172a;
  --ink-2: #334155;
  --muted: #64748b;
  --line: #e5ebf3;
  --input-border: #cbd5e1;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 6px 20px rgba(15, 23, 42, .03);
  font-family: "Microsoft YaHei UI", -apple-system, BlinkMacSystemFont, "PingFang SC", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--ink); min-height: 100%; font-size: 14px; }
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; }

/* Toast */
.toast {
  position: fixed; top: 18px; left: 50%; transform: translateX(-50%);
  z-index: 999; background: #0f172a; color: #fff; padding: 10px 18px; border-radius: 999px;
  font-size: 13px; max-width: calc(100vw - 32px); opacity: 0; pointer-events: none; transition: opacity .2s;
  box-shadow: 0 8px 24px rgba(15, 23, 42, .2);
}
.toast.show { opacity: 1; }
.toast.error { background: var(--danger); }

/* 纯净登录页 */
.login-view {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px;
  background: radial-gradient(circle at top center, #e8f3ff 0%, #f5f7fb 55%);
}
.login-card {
  width: 100%; max-width: 390px; background: var(--card); border: 1px solid var(--line);
  border-radius: 16px; padding: 38px 32px 34px; box-shadow: 0 14px 38px rgba(0, 102, 204, .09);
  text-align: center;
}
.login-logo { height: 44px; width: auto; max-width: 220px; object-fit: contain; margin-bottom: 14px; }
.login-card h1 { margin: 0 0 26px; font-size: 20px; font-weight: 700; color: var(--ink); }
.login-form { display: flex; flex-direction: column; gap: 16px; text-align: left; }
.login-error { margin: 0; font-size: 12.5px; color: var(--danger); }

/* 表单与控件 */
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 13px; font-weight: 600; color: var(--ink-2); }
.field-label-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.field .check-inline {
  display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 500;
  color: var(--muted); cursor: pointer; user-select: none; white-space: nowrap;
}
.check-inline input[type="checkbox"] {
  width: 14px; height: 14px; margin: 0; padding: 0; accent-color: var(--primary);
  cursor: pointer; flex-shrink: 0; box-shadow: none;
}
input, select, textarea {
  width: 100%; border: 1px solid var(--input-border); border-radius: 8px;
  padding: 10px 12px; background: #fff; color: var(--ink); font-size: 14px; outline: none;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--primary); box-shadow: 0 0 0 3px rgba(0, 102, 204, .12);
}
.input-code {
  color: var(--primary); font-weight: 700; letter-spacing: .04em;
  font-family: Consolas, ui-monospace, SFMono-Regular, Menlo, monospace;
}

.btn {
  border: 0; border-radius: 8px; padding: 9px 16px; font-size: 13.5px; font-weight: 600;
  cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  transition: background .15s, border-color .15s, opacity .15s; white-space: nowrap;
}
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-green { background: var(--green); color: #fff; }
.btn-green:hover:not(:disabled) { background: var(--green-hover); }
.btn-ghost { background: #fff; color: var(--ink-2); border: 1px solid var(--input-border); }
.btn-ghost:hover:not(:disabled) { background: #f8fafc; border-color: #94a3b8; }
.btn-danger-ghost { background: #fff; color: var(--danger); border: 1px solid #fecaca; }
.btn-danger-ghost:hover:not(:disabled) { background: #fef2f2; }
.btn-sm { padding: 6px 11px; font-size: 12.5px; border-radius: 6px; }
.btn-block { width: 100%; height: 42px; font-size: 14.5px; }
.btn-lg { width: 100%; height: 44px; font-size: 15px; }
.link-btn {
  border: 0; background: transparent; color: var(--primary); font-size: 13px; font-weight: 600;
  cursor: pointer; padding: 2px 4px;
}
.file-btn { position: relative; overflow: hidden; }

/* 登录后全屏现代 Web 布局 */
.app-shell {
  min-height: 100vh; display: flex; background: var(--bg);
}

/* 左侧明亮蓝色风格导航栏 */
.sidebar {
  width: 232px; flex-shrink: 0; background: var(--card); border-right: 1px solid var(--line);
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column;
  padding: 20px 14px 18px;
}
.sidebar-brand {
  display: flex; flex-direction: column; align-items: flex-start; gap: 8px;
  padding: 4px 10px 20px; border-bottom: 1px solid var(--line); margin-bottom: 16px;
}
.brand-logo { height: 34px; width: auto; max-width: 180px; object-fit: contain; }
.sidebar-brand span { font-size: 15px; font-weight: 700; color: var(--ink); letter-spacing: .01em; }

.side-nav { display: flex; flex-direction: column; gap: 4px; }
.nav-btn {
  border: 0; background: transparent; color: #475569; padding: 11px 12px; border-radius: 9px;
  display: flex; align-items: center; gap: 10px; font-size: 14px; font-weight: 500; cursor: pointer;
  transition: background .15s, color .15s; text-align: left;
}
.nav-btn svg {
  width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2;
  stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0;
}
.nav-btn:hover { background: #f1f6fd; color: var(--primary); }
.nav-btn.active { background: var(--primary-soft); color: var(--primary); font-weight: 700; }

.sidebar-footer {
  margin-top: auto; padding-top: 14px; border-top: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 10px;
}
.user-card { display: flex; align-items: center; gap: 10px; padding: 0 4px; }
.user-avatar {
  width: 34px; height: 34px; border-radius: 50%; background: var(--primary); color: #fff;
  display: grid; place-items: center; font-weight: 700; font-size: 14px; flex-shrink: 0;
}
.user-meta { min-width: 0; display: flex; flex-direction: column; }
.user-meta strong { font-size: 13.5px; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-meta small { font-size: 11.5px; color: var(--muted); }

/* 移动端顶栏（PC 隐藏） */
.mobile-header { display: none; }

/* 右侧宽屏流体主工作区 */
.workspace {
  flex: 1; min-width: 0; padding: 24px 30px 36px; max-width: 1440px; margin: 0 auto; width: 100%;
}
.panel { display: none; }
.panel.active { display: block; }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px 22px; box-shadow: var(--shadow);
}
.panel-head {
  display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 16px;
}
.panel-head h2, .card h2 { margin: 0; font-size: 16px; font-weight: 700; color: var(--ink); }
.card-head-pad {
  display: flex; justify-content: space-between; align-items: center; padding: 16px 20px;
  border-bottom: 1px solid var(--line);
}
.card-head-pad h2 { margin: 0; font-size: 15.5px; font-weight: 700; }

/* 顶部指标条 */
.kpi-strip {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 18px;
}
.kpi-card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 20px; box-shadow: var(--shadow); display: flex; justify-content: space-between; align-items: baseline;
}
.kpi-card span { font-size: 13.5px; color: var(--muted); font-weight: 500; }
.kpi-card strong { font-size: 26px; font-weight: 800; color: var(--primary); font-variant-numeric: tabular-nums; }

/* 发码双栏工作台 */
.workbench-grid {
  display: grid; grid-template-columns: 1.15fr 0.85fr; gap: 18px; align-items: start;
}
.form-panel { display: flex; flex-direction: column; gap: 15px; }
.field-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.lookup-pill {
  background: var(--primary-soft); color: var(--primary); border: 1px solid var(--primary-border);
  border-radius: 999px; padding: 3px 10px; font-size: 12px; font-weight: 600;
}

.mode-tabs-box { display: flex; flex-direction: column; }
.mode-tab-bar { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; padding: 0 10px; }
.seg-btn {
  border: 1px solid var(--line); border-bottom: 0; border-radius: 9px 9px 0 0;
  background: #eef3f9; color: #52637a; padding: 9px 6px 8px;
  font-size: 13.5px; font-weight: 600; cursor: pointer; position: relative;
  transition: background .15s, color .15s, border-color .15s;
}
.seg-btn:hover:not(.active) { background: #e3eefc; color: var(--primary); }
.seg-btn.active {
  background: #f7fbff; color: var(--primary); font-weight: 700;
  border-color: var(--primary-border); border-top: 3px solid var(--primary);
  padding-top: 7px; margin-bottom: -1px; z-index: 2;
  box-shadow: 0 -2px 8px rgba(0, 102, 204, .06);
}
.mode-tab-body {
  background: #f7fbff; border: 1px solid var(--primary-border); border-radius: 10px;
  padding: 14px 16px 16px; position: relative; z-index: 1;
}

.mode-section { display: flex; flex-direction: column; gap: 12px; }
.preset-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.preset-tile {
  border: 1px solid #d8e3f0; background: #fff; color: var(--ink-2);
  padding: 9px 6px; border-radius: 8px; font-size: 12.5px; font-weight: 600; cursor: pointer;
}
.preset-tile.active {
  background: var(--primary-soft); color: var(--primary); border-color: var(--primary);
}
.perpetual-badge {
  background: #ecfdf5; border: 1px solid #a7f3d0; color: #047857;
  padding: 12px 14px; border-radius: 8px; font-size: 13.5px; font-weight: 600; text-align: center;
}

/* 右侧结果卡 + 最近 5 条 */
.right-stack { display: flex; flex-direction: column; gap: 16px; }
.meta-text { font-size: 12.5px; color: var(--muted); }
.code-display-box {
  background: linear-gradient(135deg, #eef6ff 0%, #f8fbff 100%);
  border: 1px solid var(--primary-border); border-radius: 10px;
  padding: 18px; text-align: center; margin-bottom: 14px;
}
.hero-code {
  font-size: 36px; font-weight: 800; color: var(--primary); letter-spacing: .06em;
  font-family: Consolas, ui-monospace, SFMono-Regular, Menlo, monospace; margin-bottom: 14px;
}
.hero-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.wechat-preview {
  width: 100%; min-height: 76px; padding: 12px 14px; border: 1px solid var(--input-border);
  border-radius: 8px; background: #f8fafc; color: var(--ink);
  font-family: Consolas, "Microsoft YaHei UI", monospace;
  font-size: 12.5px; line-height: 1.6; white-space: pre-wrap; word-break: break-word;
  user-select: text;
}
.wechat-preview:empty::before { content: attr(data-placeholder); color: var(--muted); }

.recent-list { display: flex; flex-direction: column; }
.recent-item {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 10px 0; border-bottom: 1px solid #f1f5f9;
}
.recent-item:last-child { border-bottom: 0; padding-bottom: 0; }
.recent-info { min-width: 0; }
.recent-title { font-size: 13.5px; font-weight: 600; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.recent-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.recent-code {
  font-family: Consolas, ui-monospace, monospace; font-weight: 700; color: var(--primary); font-size: 13.5px;
}

/* 工具栏与表格 */
.page-toolbar {
  display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; flex-wrap: wrap;
}
.toolbar-left { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 240px; flex-wrap: wrap; }
.toolbar-left input[type=search] { max-width: 320px; }
.toolbar-right { display: flex; gap: 8px; }

.filter-pills { display: inline-flex; gap: 4px; background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 3px; }
.filter-pill {
  border: 0; background: transparent; color: var(--muted); padding: 5px 12px; border-radius: 6px;
  font-size: 12.5px; font-weight: 600; cursor: pointer;
}
.filter-pill.active { background: var(--primary); color: #fff; }

.table-card { padding: 0; overflow: hidden; }
.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.data-table th {
  background: #f8fafc; color: var(--ink-2); font-weight: 600; padding: 12px 14px;
  border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap;
}
.data-table td {
  padding: 12px 14px; border-bottom: 1px solid #f1f5f9; vertical-align: middle;
}
.data-table tbody tr:hover td { background: #f8fbff; }
.code-cell { color: var(--primary); font-weight: 700; font-family: Consolas, ui-monospace, monospace; white-space: nowrap; }
.row-actions { display: inline-flex; gap: 6px; white-space: nowrap; }

.pill {
  display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 600;
  background: var(--primary-soft); color: var(--primary); white-space: nowrap;
}
.pill.ok { background: #ecfdf5; color: #059669; }
.pill.danger { background: #fee2e2; color: var(--danger); }

/* 管理中心布局 */
.manage-layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 18px; align-items: start; }
.manage-layout.single { grid-template-columns: minmax(0, 560px); }
.manage-main, .manage-side { display: flex; flex-direction: column; gap: 18px; min-width: 0; }
.head-title { display: flex; align-items: center; gap: 8px; }
.inline-create {
  display: grid; grid-template-columns: minmax(0, .9fr) minmax(0, 1.3fr) 130px auto; gap: 10px; align-items: end;
  padding: 16px 20px; background: #f8fbff; border-bottom: 1px solid var(--line);
}
.inline-create .actions { display: flex; gap: 8px; }
.inline-create .actions .btn { height: 40px; }
.data-table select.select-sm { width: auto; min-width: 120px; padding: 6px 10px; font-size: 13px; }
.data-table .th-actions, .data-table td.td-actions { text-align: right; }
.muted-cell { color: var(--muted); }
.self-tag {
  display: inline-block; margin-left: 6px; padding: 2px 7px; border-radius: 999px;
  font-size: 11px; font-weight: 600; background: var(--primary-soft); color: var(--primary);
}
.stack-form { display: flex; flex-direction: column; gap: 14px; }
.recycle-list { display: flex; flex-direction: column; gap: 8px; max-height: 240px; overflow-y: auto; }
.recycle-item {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 9px 12px; font-size: 13px;
}
.recycle-item span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty-text { text-align: center; color: var(--muted); padding: 24px 12px; font-size: 13px; }
.pwd-dialog {
  border: 1px solid var(--line); border-radius: 14px; padding: 22px;
  width: min(380px, calc(100vw - 32px)); box-shadow: 0 20px 50px rgba(15, 23, 42, .18);
  background: var(--card); color: var(--ink);
}
.pwd-dialog::backdrop { background: rgba(15, 23, 42, .35); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }
.edit-dialog { width: min(480px, calc(100vw - 32px)); }
.pill.warn { background: #fef3c7; color: #b45309; }

/* 客户管理主从视图 */
.customer-layout { display: grid; grid-template-columns: 268px minmax(0, 1fr); gap: 18px; align-items: start; }
.customer-list { display: flex; flex-direction: column; max-height: calc(100vh - 220px); overflow-y: auto; }
.customer-item {
  border: 0; border-bottom: 1px solid #f1f5f9; border-left: 3px solid transparent; background: transparent;
  width: 100%; text-align: left; padding: 13px 16px; cursor: pointer;
  display: flex; flex-direction: column; gap: 5px; transition: background .15s;
}
.customer-item:last-child { border-bottom: 0; }
.customer-item:hover { background: #f8fbff; }
.customer-item.active { background: var(--primary-soft); border-left-color: var(--primary); }
.customer-item-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.customer-item-name {
  font-size: 14px; font-weight: 700; color: var(--ink);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.customer-item-name.unassigned { color: #b45309; }
.customer-item-sub {
  font-size: 12px; color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.customer-detail-col, .customer-detail-body { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.customer-hero-head { flex-wrap: wrap; margin-bottom: 10px; }
.customer-meta-strip { display: flex; flex-wrap: wrap; gap: 10px 20px; font-size: 13px; color: var(--muted); }
.customer-detail-col .data-table th,
.customer-detail-col .data-table td { padding: 10px 10px; font-size: 13px; }
.customer-detail-col .data-table td .pill { white-space: normal; text-align: center; line-height: 1.3; }
.data-table tbody tr.row-selected td { background: var(--primary-soft); }

/* 移动端卡片列表 */
.mobile-cards { display: none; }
.m-card { border-bottom: 1px solid var(--line); padding: 14px; display: flex; flex-direction: column; gap: 6px; }
.m-card:last-child { border-bottom: 0; }
.m-card-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.m-card-title { font-weight: 700; font-size: 14.5px; }
.m-card-code { font-family: Consolas, ui-monospace, monospace; font-weight: 700; color: var(--primary); font-size: 15.5px; }
.m-card-sub { font-size: 12px; color: var(--muted); }
.m-card-actions { display: flex; gap: 8px; margin-top: 4px; }
.m-card-actions .btn { flex: 1; }

/* 平板与手机自适应 */
@media (max-width: 1360px) {
  .inline-create { grid-template-columns: 1fr 1fr; }
  .inline-create .actions { justify-content: flex-end; }
}

@media (max-width: 1120px) {
  .workbench-grid, .manage-layout, .customer-layout { grid-template-columns: 1fr; }
  .customer-list { max-height: 280px; }
  .workspace { padding: 18px 20px 30px; }
}

@media (max-width: 768px) {
  .app-shell { flex-direction: column; }
  .sidebar {
    position: fixed; bottom: 0; left: 0; right: 0; top: auto; width: 100%; height: auto;
    z-index: 50; border-right: 0; border-top: 1px solid var(--line);
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
  }
  .sidebar-brand, .sidebar-footer { display: none; }
  .side-nav { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; }
  .nav-btn {
    flex-direction: column; justify-content: center; gap: 3px; padding: 6px 2px; font-size: 11px;
  }
  .nav-btn svg { width: 19px; height: 19px; }

  .mobile-header {
    display: flex; justify-content: space-between; align-items: center; gap: 10px;
    position: sticky; top: 0; z-index: 40; background: var(--card); border-bottom: 1px solid var(--line);
    padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
  }
  .mobile-brand { display: flex; align-items: center; gap: 8px; }
  .mobile-logo { height: 24px; width: auto; }
  .mobile-brand strong { font-size: 15px; }
  .mobile-user { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--muted); }

  .workspace { padding: 14px 12px calc(76px + env(safe-area-inset-bottom)); }
  .kpi-strip { gap: 8px; margin-bottom: 12px; }
  .kpi-card { flex-direction: column; align-items: center; gap: 2px; padding: 10px 8px; }
  .kpi-card strong { font-size: 20px; }
  .card { padding: 15px; }
  .mode-tab-bar { padding: 0 4px; gap: 4px; }
  .seg-btn { font-size: 12.5px; padding: 8px 2px 7px; }
  .mode-tab-body { padding: 12px; }
  .inline-create { grid-template-columns: 1fr; }
  .field-grid-2, .preset-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .hero-code { font-size: 28px; }
  .toolbar-left input[type=search] { max-width: none; }
  .table-card .table-wrap { display: none; }
  .mobile-cards { display: block; }
}
