:root {
  --canvas: #f5f7fa;
  --card: #ffffff;
  --sub: #eef2f7;
  --ink: #1e293b;
  --ink2: #334155;
  --muted: #64748b;
  --muted2: #94a3b8;
  --primary: #2563eb;
  --primary-deep: #1d4ed8;
  --blue-soft: #dbeafe;
  --green: #16a34a;
  --green-soft: #dcfce7;
  --amber: #d97706;
  --amber-soft: #fef3c7;
  --red: #dc2626;
  --red-soft: #fee2e2;
  --line: #e2e8f0;
  --side: #0f172a;
  --side-text: #cbd5e1;
  --side-active: #1e293b;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Inter, "Noto Sans SC", system-ui, "Microsoft YaHei", sans-serif;
  background: var(--canvas);
  color: var(--ink);
  display: flex;
  min-height: 100vh;
}
.sidebar {
  width: 220px;
  background: var(--side);
  color: var(--side-text);
  display: flex;
  flex-direction: column;
  padding: 20px 12px;
  flex-shrink: 0;
}
.brand { display: flex; gap: 12px; align-items: center; padding: 8px 10px 24px; }
.brand-mark {
  width: 36px; height: 36px; border-radius: 8px;
  background: var(--primary); color: #fff;
  display: grid; place-items: center; font-weight: 700;
}
.brand-title { color: #fff; font-weight: 700; font-size: 15px; }
.brand-sub { font-size: 12px; color: var(--muted2); }
.nav-item {
  display: block; width: 100%; text-align: left;
  background: transparent; border: 0; color: var(--side-text);
  padding: 12px 14px; border-radius: 8px; cursor: pointer;
  margin-bottom: 4px; font-size: 14px; position: relative;
}
.nav-item:hover { background: var(--side-active); }
.nav-item.active { background: var(--side-active); color: #fff; }
.nav-item.active::before {
  content: ""; position: absolute; left: 0; top: 8px; bottom: 8px;
  width: 3px; background: var(--primary); border-radius: 2px;
}
.sidebar-foot { margin-top: auto; padding: 12px 10px; }
.sidebar-foot select {
  width: 100%; margin-top: 6px; padding: 8px;
  border-radius: 8px; border: 1px solid #334155;
  background: #1e293b; color: #fff;
}
.muted { color: var(--muted2); font-size: 12px; }
.main { flex: 1; padding: 20px 28px; overflow: auto; }
.topbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; gap: 12px; }
.topbar h1 { margin: 0; font-size: 22px; font-family: "Noto Serif SC", Georgia, serif; }
.topbar-actions { display: flex; gap: 8px; align-items: center; }
.topbar-actions input {
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; min-width: 220px;
}
.btn {
  border: 0; border-radius: 8px; padding: 8px 14px; cursor: pointer;
  font-size: 13px; font-weight: 600;
}
.btn.primary { background: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-deep); }
.btn.ghost { background: #fff; border: 1px solid var(--line); color: var(--ink2); }
.btn.danger { background: var(--red); color: #fff; }
.btn.sm { padding: 6px 10px; font-size: 12px; }
.hidden { display: none !important; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.chip {
  border: 1px solid var(--line); background: #fff; border-radius: 999px;
  padding: 6px 12px; font-size: 12px; cursor: pointer; color: var(--ink2);
}
.chip.active { background: var(--blue-soft); border-color: var(--primary); color: var(--primary-deep); font-weight: 600; }
.table-wrap {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  overflow: auto; box-shadow: 0 1px 2px rgba(15,23,42,.04);
}
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; background: #fafbfc; }
tr:last-child td { border-bottom: 0; }
.tag {
  display: inline-block; padding: 2px 8px; border-radius: 6px; font-size: 12px; font-weight: 600;
}
.tag-pending_dispatch, .tag-assigned { background: var(--amber-soft); color: var(--amber); }
.tag-accepted, .tag-checked_in, .tag-working { background: var(--blue-soft); color: var(--primary-deep); }
.tag-quoted, .tag-work_submitted, .tag-approved, .tag-customer_accepted { background: #eef2ff; color: #4338ca; }
.tag-paid, .tag-settled { background: var(--green-soft); color: var(--green); }
.tag-rejected { background: var(--red-soft); color: var(--red); }
.kpi-grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px;
}
.kpi {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 16px;
  box-shadow: 0 1px 2px rgba(15,23,42,.04);
}
.kpi .label { color: var(--muted); font-size: 12px; }
.kpi .value { font-size: 24px; font-weight: 700; margin-top: 6px; }
.kpi .sub { color: var(--muted2); font-size: 12px; margin-top: 4px; }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 16px; margin-bottom: 16px; box-shadow: 0 1px 2px rgba(15,23,42,.04);
}
.card h2 { margin: 0 0 12px; font-size: 16px; }
.card-head { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; align-items: center; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.bars { display: flex; align-items: flex-end; gap: 4px; height: 120px; }
.bar {
  flex: 1; background: var(--blue-soft); border-radius: 4px 4px 0 0; min-height: 4px;
  position: relative;
}
.bar span {
  position: absolute; bottom: -18px; left: 50%; transform: translateX(-50%);
  font-size: 9px; color: var(--muted2); white-space: nowrap;
}
.fault-row, .site-row {
  display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--line);
  font-size: 13px;
}
.fault-row:last-child, .site-row:last-child { border-bottom: 0; }
.drawer {
  position: fixed; inset: 0; background: rgba(15,23,42,.35); display: flex; justify-content: flex-end; z-index: 50;
}
.drawer-panel {
  width: min(520px, 100%); background: #fff; height: 100%; overflow: auto;
  padding: 20px; border-left: 1px solid var(--line);
}
.drawer-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.timeline { border-left: 2px solid var(--line); margin-left: 8px; padding-left: 16px; }
.tl-item { margin-bottom: 14px; position: relative; }
.tl-item::before {
  content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--primary);
  position: absolute; left: -21px; top: 6px;
}
.tl-time { color: var(--muted2); font-size: 12px; }
.tl-act { font-weight: 600; margin-top: 2px; }
.tl-detail { color: var(--muted); font-size: 12px; margin-top: 2px; }
.meta-grid { display: grid; grid-template-columns: 90px 1fr; gap: 8px; font-size: 13px; margin-bottom: 16px; }
.meta-grid .k { color: var(--muted); }
.actions-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0 20px; }
select.inline {
  padding: 6px 8px; border-radius: 8px; border: 1px solid var(--line);
}
@media (max-width: 1100px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .grid-2 { grid-template-columns: 1fr; }
}
