:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --danger: #dc2626;
  --ok: #16a34a;
  --bg: #f1f5f9;
  --card: #ffffff;
  --line: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --sidebar-w: 220px;
  --radius: 10px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: "Microsoft YaHei", "PingFang SC", "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.muted { color: var(--muted); }

/* ---------- 按钮 ---------- */
.btn {
  display: inline-block;
  padding: 8px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
  transition: all .15s;
  white-space: nowrap;
}
.btn:hover { border-color: var(--primary); color: var(--primary); text-decoration: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); color: #fff; }
.btn-danger { background: #fff; border-color: #fecaca; color: var(--danger); }
.btn-danger:hover { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { color: var(--danger); border-color: transparent; }
.btn-block { display: block; width: 100%; text-align: center; }
.btn-sm { padding: 4px 10px; font-size: 13px; border-radius: 6px; }

/* ---------- 输入 ---------- */
.input, select.input, textarea.input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 14px;
  background: #fff;
  color: var(--text);
  outline: none;
}
.input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, .12); }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }

/* ---------- 登录页 ---------- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1e3a8a 0%, #2563eb 60%, #3b82f6 100%);
  padding: 20px;
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: #fff;
  border-radius: 14px;
  padding: 36px 32px;
  box-shadow: 0 20px 50px rgba(0,0,0,.25);
}
.login-card h1 { font-size: 22px; text-align: center; color: var(--text); }
.login-sub { text-align: center; color: var(--muted); margin: 6px 0 24px; }
.login-card label { margin-top: 14px; }
.login-card .btn { margin-top: 22px; }
.login-tip { margin-top: 16px; font-size: 12px; color: var(--muted); text-align: center; }
.setup-warning {
  background: #fef2f2;
  color: #991b1b;
  border-bottom: 1px solid #fecaca;
  padding: 12px 20px;
  text-align: center;
}

/* ---------- 前台顶栏 ---------- */
.topbar {
  background: #0f172a;
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 20px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.brand { font-size: 18px; font-weight: 700; }
.topbar-user { display: flex; align-items: center; gap: 10px; }
.topbar-user .uname { color: #cbd5e1; }
.topbar-user .btn { color: #e2e8f0; border-color: #334155; background: transparent; }
.topbar-user .btn:hover { border-color: #60a5fa; color: #fff; }

.container { max-width: 1280px; margin: 20px auto 60px; padding: 0 20px; }

/* ---------- 工具栏 ---------- */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.toolbar-left { display: flex; gap: 10px; flex-wrap: wrap; }
.toolbar-right { font-size: 13px; }

/* ---------- 报价表 ---------- */
.table-card {
  background: var(--card);
  border-radius: var(--radius);
  border: 1px solid var(--line);
  overflow-x: auto;
  box-shadow: 0 1px 3px rgba(15, 23, 42, .06);
}
.price-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 860px;
}
.price-table th {
  background: #f8fafc;
  border-bottom: 2px solid var(--line);
  padding: 10px 12px;
  text-align: left;
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
}
.price-table td {
  padding: 8px 12px;
  border-bottom: 1px solid #f1f5f9;
  vertical-align: middle;
}
.price-table tbody tr:hover { background: #f8fafc; }
.price-table.compact th, .price-table.compact td { padding: 6px 8px; font-size: 13px; }

.col-no { width: 52px; text-align: center; }
.col-cat { width: 120px; }
.col-model { min-width: 260px; }
.col-spec { width: 180px; }
.col-price { width: 130px; }
.col-note { min-width: 140px; }
.col-op { width: 80px; text-align: center; }

.row-wrap { display: flex; gap: 6px; align-items: center; }
.model-cell { position: relative; flex: 1; }
.model-cell .model-input { width: 100%; }
.spec-cell-input, .price-input, .note-input {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 14px;
  background: #fff;
  color: var(--text);
  outline: none;
}
.spec-cell-input:focus, .price-input:focus, .note-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
}
.price-input { text-align: right; font-weight: 600; }

/* 联想下拉 */
.suggest {
  position: absolute;
  top: calc(100% + 2px);
  left: 0;
  right: 0;
  z-index: 100;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 10px 30px rgba(15, 23, 42, .18);
  max-height: 320px;
  overflow-y: auto;
  display: none;
}
.suggest.open { display: block; }
.suggest-item {
  padding: 8px 12px;
  cursor: pointer;
  border-bottom: 1px solid #f1f5f9;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
}
.suggest-item:last-child { border-bottom: none; }
.suggest-item:hover, .suggest-item.active { background: #eff6ff; }
.suggest-item .s-name { font-weight: 600; }
.suggest-item .s-name small { color: var(--muted); font-weight: 400; margin-left: 6px; }
.suggest-item .s-spec { color: var(--muted); font-size: 12px; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.suggest-item .s-price { color: var(--danger); font-weight: 700; white-space: nowrap; }
.suggest-empty { padding: 12px; color: var(--muted); text-align: center; }

.total-row td {
  background: #eff6ff;
  border-top: 2px solid var(--primary);
  font-weight: 700;
  padding: 12px;
}
.total-row .total-label { text-align: right; }
.total-row .total-price { color: var(--danger); font-size: 20px; }

/* ---------- 后台 ---------- */
.admin-layout { display: flex; min-height: 100vh; }
.admin-sidebar {
  width: var(--sidebar-w);
  background: #0f172a;
  color: #cbd5e1;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  flex-shrink: 0;
}
.admin-brand {
  padding: 20px;
  font-size: 17px;
  font-weight: 700;
  color: #fff;
  border-bottom: 1px solid #1e293b;
  line-height: 1.3;
}
.admin-brand span { display: block; font-size: 12px; color: #64748b; font-weight: 400; }
.admin-nav { flex: 1; padding: 12px 0; }
.admin-nav .nav-item {
  display: block;
  padding: 11px 20px;
  color: #cbd5e1;
  border-left: 3px solid transparent;
}
.admin-nav .nav-item:hover { background: #1e293b; color: #fff; text-decoration: none; }
.admin-nav .nav-item.active { background: #1e293b; color: #fff; border-left-color: var(--primary); }
.admin-side-foot { padding: 14px; border-top: 1px solid #1e293b; display: flex; flex-direction: column; gap: 8px; }

.admin-main { flex: 1; padding: 24px 28px 60px; min-width: 0; }
.admin-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}
.admin-head h1 { font-size: 20px; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: 0 1px 3px rgba(15, 23, 42, .06);
}
.card h3 { margin-bottom: 12px; font-size: 15px; }
.mt-16 { margin-top: 16px; }

.form-row { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.form-row label { min-width: 180px; flex: 1; }
.form-row .input, .form-row select.input { min-width: 140px; }
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
}
.form-actions { display: flex; align-items: flex-end; }
.form-actions .btn { margin-bottom: 1px; }

.result-box {
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: 8px;
  display: none;
  white-space: pre-wrap;
  word-break: break-all;
}
.result-box.ok { display: block; background: #f0fdf4; border: 1px solid #bbf7d0; color: #166534; }
.result-box.err { display: block; background: #fef2f2; border: 1px solid #fecaca; color: #991b1b; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}
.stat-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
}
.stat-card .num { font-size: 26px; font-weight: 800; color: var(--primary); }
.stat-card .lbl { color: var(--muted); font-size: 13px; }

.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; padding: 10px 12px; flex-wrap: wrap; }
.pager .pg-btn {
  min-width: 32px;
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
  font-size: 13px;
}
.pager .pg-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.pager .pg-btn:disabled { opacity: .4; cursor: not-allowed; }
.pager .pg-info { color: var(--muted); font-size: 13px; }

.inline-edit {
  border: 1px solid transparent;
  background: transparent;
  padding: 3px 5px;
  border-radius: 5px;
  width: 100%;
  font-size: 13px;
  color: var(--text);
}
.inline-edit:hover { border-color: var(--line); background: #fff; }
.inline-edit:focus { border-color: var(--primary); background: #fff; outline: none; }
.inline-price { width: 90px; text-align: right; font-weight: 600; }

.row-actions { display: flex; gap: 6px; align-items: center; justify-content: center; }

code {
  background: #f1f5f9;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 12px;
}

/* ---------- 打印 ---------- */
@media print {
  .topbar, .toolbar, .btn, .admin-sidebar, .suggest, .col-op { display: none !important; }
  body { background: #fff; }
  .table-card { border: none; box-shadow: none; }
  .price-table th { background: #f1f5f9; }
  .model-cell .suggest { display: none !important; }
}

/* ---------- 小屏适配 ---------- */
@media (max-width: 900px) {
  .admin-layout { flex-direction: column; }
  .admin-sidebar { width: 100%; height: auto; position: static; }
  .admin-nav { display: flex; overflow-x: auto; padding: 6px; }
  .admin-nav .nav-item { border-left: none; border-bottom: 2px solid transparent; padding: 9px 14px; white-space: nowrap; }
  .admin-nav .nav-item.active { border-bottom-color: var(--primary); }
  .admin-side-foot { flex-direction: row; }
}
