/* ============================================================
 * style.css — 弱电工程进销存及费用系统 · 浅色商务主题
 * 白底黑字 + 科技蓝主色，零外部依赖
 * ============================================================ */
:root {
  --blue: #2563eb;
  --blue-d: #1d4ed8;
  --blue-l: #eff6ff;
  --ink: #1f2937;
  --ink-2: #4b5563;
  --ink-3: #9ca3af;
  --line: #e5e7eb;
  --bg: #f4f6fb;
  --card: #ffffff;
  --green: #16a34a;
  --green-l: #ecfdf5;
  --red: #dc2626;
  --red-l: #fef2f2;
  --amber: #d97706;
  --amber-l: #fffbeb;
  --purple: #7c3aed;
  --shadow: 0 1px 3px rgba(16,24,40,.08), 0 1px 2px rgba(16,24,40,.06);
  --shadow-lg: 0 10px 30px rgba(16,24,40,.12);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Microsoft YaHei", "PingFang SC", "Noto Sans SC", system-ui, -apple-system, sans-serif;
  background: var(--bg); color: var(--ink); font-size: 14px; line-height: 1.6;
}
a { color: var(--blue); text-decoration: none; }

/* ---- 布局 ---- */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 232px; background: #0f172a; color: #cbd5e1; flex-shrink: 0;
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.sidebar .brand {
  display: flex; align-items: center; gap: 10px; padding: 18px 20px;
  border-bottom: 1px solid rgba(255,255,255,.08); color: #fff;
}
.sidebar .brand .logo {
  width: 34px; height: 34px; border-radius: 9px; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--blue), #38bdf8); color: #fff; font-weight: 800; font-size: 15px;
}
.sidebar .brand b { font-size: 15px; }
.sidebar .brand small { display: block; font-size: 11px; color: #94a3b8; font-weight: 400; }
.nav { padding: 12px 10px; overflow-y: auto; flex: 1; }
.nav-group { font-size: 11px; color: #64748b; padding: 12px 14px 6px; letter-spacing: .05em; }
.nav-item {
  display: flex; align-items: center; gap: 11px; padding: 10px 14px; border-radius: 9px;
  color: #cbd5e1; cursor: pointer; font-size: 13.5px; margin-bottom: 2px; transition: .15s;
}
.nav-item:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-item.active { background: linear-gradient(135deg, var(--blue), var(--blue-d)); color: #fff; box-shadow: var(--shadow); }
.nav-item .ic { width: 18px; text-align: center; font-size: 15px; }
.sidebar .foot { padding: 12px 16px; border-top: 1px solid rgba(255,255,255,.08); font-size: 11px; color: #64748b; }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  height: 60px; background: var(--card); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between; padding: 0 24px; position: sticky; top: 0; z-index: 20;
}
.topbar h1 { font-size: 18px; margin: 0; font-weight: 700; }
.topbar .sub { font-size: 12px; color: var(--ink-3); }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.role-badge {
  background: var(--blue-l); color: var(--blue-d); border: 1px solid #bfdbfe;
  padding: 5px 12px; border-radius: 20px; font-size: 12px; cursor: pointer; display: flex; align-items: center; gap: 6px;
}
.btn-icon { width: 36px; height: 36px; border-radius: 9px; border: 1px solid var(--line); background: #fff; cursor: pointer; display: flex; align-items: center; justify-content: center; font-size: 16px; color: var(--ink-2); }
.btn-icon:hover { background: var(--bg); }
.content { padding: 24px; overflow-y: auto; }

/* ---- 卡片 ---- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 18px; box-shadow: var(--shadow); margin-bottom: 18px; }
.card h3 { margin: 0 0 14px; font-size: 15px; display: flex; align-items: center; gap: 8px; }
.card h3 .bar { width: 4px; height: 16px; background: var(--blue); border-radius: 3px; }
.card-title-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.muted { color: var(--ink-3); }
.small { font-size: 12px; }

/* ---- KPI ---- */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 16px; margin-bottom: 18px; }
.kpi {
  background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 18px; box-shadow: var(--shadow);
  position: relative; overflow: hidden;
}
.kpi .label { font-size: 12.5px; color: var(--ink-2); margin-bottom: 8px; }
.kpi .value { font-size: 26px; font-weight: 800; letter-spacing: -.5px; }
.kpi .delta { font-size: 12px; margin-top: 6px; }
.kpi .ic-bg { position: absolute; right: -8px; top: -8px; font-size: 64px; opacity: .06; }
.up { color: var(--green); } .down { color: var(--red); }

/* ---- 按钮 ---- */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 15px; border-radius: 9px; border: 1px solid var(--line); background: #fff; color: var(--ink); font-size: 13px; cursor: pointer; transition: .15s; font-family: inherit; }
.btn:hover { background: var(--bg); }
.btn.primary { background: var(--blue); color: #fff; border-color: var(--blue); }
.btn.primary:hover { background: var(--blue-d); }
.btn.danger { color: var(--red); border-color: #fecaca; }
.btn.danger:hover { background: var(--red-l); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.sm { padding: 5px 10px; font-size: 12px; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.btn[disabled]:hover { background: #fff; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---- 表格 ---- */
.table-wrap { overflow-x: auto; border-radius: 10px; border: 1px solid var(--line); }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th, table.data td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
/* 自适应表格：文本列允许换行收缩（任何宽度不出现横向滚动），编号/数字/操作列保持不换行 */
table.data.tbl-flex td { white-space: normal; word-break: break-word; min-width: 60px; }
table.data.tbl-flex td.mono, table.data.tbl-flex td.num, table.data.tbl-flex td.nowrap { white-space: nowrap; }
/* 材料字典（9列宽表）：窄屏隐藏「照片」列（列表里只显示📷N，价值最低），把宽度让给名称/规格列 */
@media (max-width: 900px) {
  table.data.mat-tbl th:nth-child(6), table.data.mat-tbl td:nth-child(6) { display: none; }
}
table.data th { background: #f8fafc; color: var(--ink-2); font-weight: 600; position: sticky; top: 0; font-size: 12.5px; }
/* 紧凑表格：列多的清单用，减小内边距避免横向滚动 */
table.data.compact th, table.data.compact td { padding: 6px 8px; font-size: 12.5px; }
table.data tbody tr:hover { background: var(--blue-l); }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data tbody tr:last-child td { border-bottom: none; }

/* ---- 表单 ---- */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
.field label { display: block; font-size: 12.5px; color: var(--ink-2); margin-bottom: 5px; font-weight: 500; }
.field input, .field select, .field textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 9px; font-size: 13px;
  font-family: inherit; background: #fff; color: var(--ink); transition: .15s;
}
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px rgba(37,99,235,.12); }
.field textarea { resize: vertical; min-height: 64px; }

/* ---- 徽章 ---- */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 20px; font-size: 11.5px; font-weight: 600; white-space: nowrap; }
.badge.blue { background: var(--blue-l); color: var(--blue-d); }
.badge.green { background: var(--green-l); color: var(--green); }
.badge.red { background: var(--red-l); color: var(--red); }
.badge.amber { background: var(--amber-l); color: var(--amber); }
.badge.gray { background: #f3f4f6; color: var(--ink-2); }
.badge.purple { background: #f5f3ff; color: var(--purple); }

/* ---- 模态框 ---- */
.modal-mask { position: fixed; inset: 0; background: rgba(15,23,42,.45); display: none; align-items: flex-start; justify-content: center; z-index: 100; padding: 40px 16px; overflow-y: auto; }
.modal-mask.open { display: flex; }
.modal { background: #fff; border-radius: 16px; width: 100%; max-width: 860px; box-shadow: var(--shadow-lg); animation: pop .18s ease; }
@keyframes pop { from { transform: translateY(10px) scale(.98); opacity: 0; } to { transform: none; opacity: 1; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px; border-bottom: 1px solid var(--line); }
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-body { padding: 22px; max-height: 70vh; overflow-y: auto; }
.modal-foot { padding: 16px 22px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 10px; }
.x-btn { background: none; border: none; font-size: 22px; cursor: pointer; color: var(--ink-3); line-height: 1; }

/* ---- Toast ---- */
#toast-wrap { position: fixed; top: 20px; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { background: #0f172a; color: #fff; padding: 10px 18px; border-radius: 10px; font-size: 13px; box-shadow: var(--shadow-lg); animation: slideIn .2s ease; }
.toast.ok { background: #16a34a; } .toast.err { background: #dc2626; }
@keyframes slideIn { from { transform: translateY(-12px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---- 只读访客模式 ---- */
.ro-banner {
  background: #fef3c7; border-bottom: 1px solid #f59e0b; color: #92400e;
  text-align: center; padding: 7px 12px; font-size: 12.5px; font-weight: 600;
}
body.readonly .btn, body.readonly .btn-icon { pointer-events: none; opacity: .5; }
body.readonly .modal-foot .btn.primary { pointer-events: none; opacity: .5; }

/* ---- 标签页 ---- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; flex-wrap: wrap; }
.tab { padding: 9px 16px; font-size: 13.5px; cursor: pointer; color: var(--ink-2); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tab.active { color: var(--blue-d); border-bottom-color: var(--blue); font-weight: 600; }
.tabpane { display: none; } .tabpane.active { display: block; }

/* ---- 仪表盘图表 ---- */
.chart-box { width: 100%; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; }
/* ---- 移动端适配（手机/平板：侧边栏变顶部横条导航） ---- */
@media (max-width: 900px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .layout { flex-direction: column; }
  .sidebar {
    width: 100%; height: auto; position: static;
    flex-direction: row; align-items: center;
    padding: 8px 10px; gap: 8px;
  }
  .sidebar .brand { border-bottom: none; padding: 0 8px; flex-shrink: 0; }
  .sidebar .brand small { display: none; }
  .nav {
    display: flex; flex-direction: row; overflow-x: auto;
    padding: 0; gap: 6px; flex: 1; -webkit-overflow-scrolling: touch;
  }
  .nav::-webkit-scrollbar { display: none; }
  .nav-group { display: none; }
  .nav-item { white-space: nowrap; padding: 8px 12px; margin-bottom: 0; font-size: 13px; }
  .sidebar .foot { display: none; }
  .topbar { padding: 0 14px; height: 54px; position: static; }
  .topbar .sub { display: none; }
  .topbar h1 { font-size: 16px; }
  .topbar-right { gap: 6px; }
  .user-chip { max-width: 90px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
  .role-badge { padding: 4px 9px; font-size: 11px; }
  .btn-icon { width: 32px; height: 32px; font-size: 14px; }
  .content { padding: 14px; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .kpi .value { font-size: 20px; }
  .kpi { padding: 14px; }
  .card { padding: 14px; }
  .form-grid { grid-template-columns: 1fr; }
  .modal { max-width: 100%; }
  .modal-mask { padding: 10px 8px; }
  .modal-head { padding: 14px 16px; }
  .modal-body { padding: 16px; max-height: 80vh; }
  .modal-foot { padding: 12px 16px; }
  .tabs { overflow-x: auto; flex-wrap: nowrap; -webkit-overflow-scrolling: touch; }
  .tab { white-space: nowrap; }
  .table-wrap { -webkit-overflow-scrolling: touch; }
}

.empty-state { text-align: center; padding: 50px 20px; color: var(--ink-3); }
.empty-state .big { font-size: 40px; margin-bottom: 10px; }

.flex { display: flex; } .between { justify-content: space-between; } .center { align-items: center; }
.gap8 { gap: 8px; } .gap12 { gap: 12px; } .wrap { flex-wrap: wrap; }
.mt8 { margin-top: 8px; } .mt16 { margin-top: 16px; } .mb8 { margin-bottom: 8px; }
.right { text-align: right; } .nowrap { white-space: nowrap; }
.pos { color: var(--green); font-weight: 600; } .neg { color: var(--red); font-weight: 600; }
.hr { height: 1px; background: var(--line); margin: 14px 0; border: 0; }
.mono { font-variant-numeric: tabular-nums; }
.backdrop-help { background: var(--blue-l); border: 1px solid #bfdbfe; border-radius: 12px; padding: 14px 16px; font-size: 12.5px; color: var(--ink-2); }

/* ---- 材料选择器（可搜索下拉）---- */
.matp { position: relative; }
.q-line input { min-width: 0; width: 100%; box-sizing: border-box; }
.q-line button { min-width: 0; }
.q-line .matp { min-width: 0; }
.matp-search { width: 100%; padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; font-size: 13px; outline: none; }
.matp-search:focus { border-color: var(--blue); }
.matp-panel {
  position: absolute; left: 0; right: 0; top: 100%; z-index: 60; margin-top: 3px;
  background: #fff; border: 1px solid var(--line); border-radius: 0 0 10px 10px;
  box-shadow: var(--shadow-lg); max-height: 260px; overflow: auto;
}
.matp-panel.matp-up { top: auto; bottom: 100%; margin-top: 0; margin-bottom: 3px; border-radius: 10px 10px 0 0; }
.matp-opt { display: flex; align-items: center; gap: 8px; padding: 7px 10px; cursor: pointer; border-bottom: 1px solid #f1f5f9; font-size: 13px; }
.matp-opt:hover { background: var(--blue-l); }
.matp-opt:last-child { border-bottom: none; }
.matp-name { flex: 1; min-width: 0; }
.matp-cat { color: var(--ink-3); font-size: 11px; background: #f1f5f9; padding: 1px 6px; border-radius: 6px; white-space: nowrap; }
.matp-empty { padding: 10px; color: var(--ink-3); font-size: 12px; text-align: center; }

/* ---- 基础数据：字典搜索 + 材料防重复提示 ---- */
.bd-search { width: 240px; padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; font-size: 13px; outline: none; }
.bd-search:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(37,99,235,.12); }
.bd-dup-hint { font-size: 12px; margin-top: 4px; min-height: 16px; color: #9ca3af; }
.bd-dup-hint.err { color: #dc2626; font-weight: 600; }
.bd-dup-hint.warn { color: #d97706; }

/* 基础数据表格：长文本单元格省略号截断 + 点击展开全文（备注/规格等超长文本） */
.bd-clamp-td { max-width: 200px; }
.bd-clamp {
  display: block; max-width: 200px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  cursor: pointer; color: var(--ink);
}
.bd-clamp:hover { color: var(--blue-d); text-decoration: underline; }

/* ---- 方案报价单文档 & 打印 ---- */
.qt-print-overlay { position: fixed; inset: 0; background: #f3f4f6; overflow: auto; z-index: 9999; padding: 20px; }
.qt-print-toolbar { position: sticky; top: 0; display: flex; gap: 10px; align-items: center; background: #fff; border: 1px solid #e5e7eb; border-radius: 10px; padding: 10px 16px; box-shadow: 0 1px 4px rgba(0,0,0,.08); margin-bottom: 16px; }
.qd { max-width: 820px; margin: 0 auto; background: #fff; padding: 32px 36px; box-shadow: 0 2px 12px rgba(0,0,0,.08); color: #1f2937; font-size: 13px; line-height: 1.6; }
.qd-head { display: flex; justify-content: space-between; align-items: flex-start; border-bottom: 3px solid #2563EB; padding-bottom: 12px; }
.qd-logo { font-size: 20px; font-weight: 800; color: #2563EB; }
.qd-tag { font-size: 11px; color: #6b7280; margin-top: 2px; }
.qd-title { font-size: 24px; font-weight: 800; color: #111827; letter-spacing: 4px; }
.qd-meta { font-size: 12px; color: #6b7280; text-align: right; }
.qd-info { display: flex; gap: 28px; margin: 14px 0; font-size: 13px; flex-wrap: wrap; }
.qd-info div { display: flex; gap: 6px; }
.qd-info span { color: #6b7280; }
.qd-tbl { width: 100%; border-collapse: collapse; margin-top: 6px; }
.qd-tbl th, .qd-tbl td { border: 1px solid #d1d5db; padding: 6px 8px; }
.qd-tbl th { background: #2563EB; color: #fff; font-weight: 600; }
.qd-tbl td.num, .qd-tbl th.num { text-align: right; }
.qd-tbl td.c, .qd-tbl th.c { text-align: center; width: 36px; }
.qd-tbl tfoot td { font-weight: 600; }
.qd-tbl tfoot .r { text-align: right; }
.qd-tbl tfoot .tot td { background: #eff6ff; color: #2563EB; font-size: 14px; }
.qd-remark { margin-top: 12px; font-size: 12px; color: #374151; }
.qd-sign { display: flex; justify-content: space-between; margin-top: 40px; font-size: 13px; }

/* ---- 移动端：单据明细行两行布局（材料/名称全宽 + 数字行），修复窄屏商品名被挤没 ---- */
@media (max-width: 640px) {
  .po-line { grid-template-columns: 64px 76px 1fr auto !important; }
  .po-line[data-did] { grid-template-columns: auto 64px 76px 1fr auto !important; }
  .po-line > .matp { grid-column: 1 / -1; }
  .po-in { grid-template-columns: 1fr 1fr 1fr !important; }
  .po-in > span:first-child { grid-column: 1 / -1; }
  .iss-line { grid-template-columns: 1fr 1fr 1fr !important; }
  .iss-line > .matp { grid-column: 1 / -1; }
  .st-line { grid-template-columns: 1fr 1fr 1fr !important; }
  .st-line > span:first-child { grid-column: 1 / -1; }
  .modal-body input, .modal-body select { font-size: 16px; } /* 防 iOS 聚焦自动放大 */
  .pr-line { grid-template-columns: 1fr 1fr 1fr !important; }
  .pr-line > div:first-child { grid-column: 1 / -1; }
  .card-title-row { flex-wrap: wrap; gap: 8px; }
  .bd-search { width: 100%; }
}

@media print {
  body * { visibility: hidden; }
  #print-area, #print-area * { visibility: visible; }
  #print-area { position: absolute; left: 0; top: 0; width: 100%; }
  .no-print { display: none !important; }
  .qt-print-overlay { position: static; background: #fff; padding: 0; overflow: visible; }
}
