/* ============ CSS Variables ============ */
:root {
  --primary: #1a6dff;
  --primary-dark: #1255cc;
  --primary-light: #e8f0ff;
  --success: #18b566;
  --warning: #f59e0b;
  --danger: #ef4444;
  --info: #06b6d4;
  --text-primary: #1e2130;
  --text-secondary: #6b7280;
  --text-muted: #9ca3af;
  --bg-main: #f0f2f7;
  --bg-card: #ffffff;
  --border: #e5e7eb;
  --sidebar-bg: #141b2d;
  --sidebar-text: #a0aec0;
  --sidebar-active: #1a6dff;
  --sidebar-hover: #1e2a42;
  --topbar-h: 56px;
  --sidebar-w: 220px;
  --sidebar-collapsed: 56px;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow: 0 2px 8px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.12);
  --transition: 0.22s ease;
}

/* ============ Reset & Base ============ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; font-family: 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif; font-size: 14px; color: var(--text-primary); background: var(--bg-main); }
a { text-decoration: none; color: inherit; }
ul { list-style: none; }
input, select, textarea, button { font-family: inherit; font-size: 14px; outline: none; }
button { cursor: pointer; border: none; background: none; }
table { border-collapse: collapse; width: 100%; }

/* ============ Scrollbar ============ */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #c1c9d8; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #9ca3af; }

/* ============ Topbar ============ */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; height: var(--topbar-h);
  background: #fff; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px; z-index: 1000;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}
.topbar-left { display: flex; align-items: center; gap: 12px; }
.sidebar-toggle {
  width: 32px; height: 32px; border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-secondary); transition: var(--transition);
}
.sidebar-toggle:hover { background: var(--bg-main); color: var(--primary); }
.brand { display: flex; align-items: center; gap: 8px; }
.brand i { color: var(--primary); font-size: 20px; }
.brand-name { font-size: 16px; font-weight: 700; color: var(--text-primary); }
.topbar-right { display: flex; align-items: center; gap: 16px; }
.top-info { display: flex; align-items: center; gap: 8px; color: var(--text-muted); font-size: 13px; }
.weather-badge { background: var(--primary-light); color: var(--primary); padding: 2px 8px; border-radius: 12px; font-size: 12px; }
.alerts-btn {
  position: relative; width: 36px; height: 36px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-secondary); cursor: pointer; transition: var(--transition);
}
.alerts-btn:hover { background: var(--bg-main); color: var(--warning); }
.alerts-btn .badge {
  position: absolute; top: 4px; right: 4px; min-width: 16px; height: 16px;
  background: var(--danger); color: #fff; font-size: 10px; font-weight: 700;
  border-radius: 8px; display: flex; align-items: center; justify-content: center;
  padding: 0 3px;
}
.user-menu {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 10px; border-radius: 8px; cursor: pointer;
  transition: var(--transition); position: relative;
}
.user-menu:hover { background: var(--bg-main); }
.avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), #6366f1);
  color: #fff; font-size: 12px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.user-menu > span { font-size: 13px; font-weight: 500; }
.user-menu i.fa-chevron-down { font-size: 11px; color: var(--text-muted); }
.user-dropdown {
  display: none; position: absolute; top: calc(100% + 8px); right: 0;
  background: #fff; border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-md); min-width: 160px; z-index: 2000;
  overflow: hidden;
}
.user-dropdown a {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 14px; color: var(--text-primary);
  transition: var(--transition); font-size: 13px;
}
.user-dropdown a:hover { background: var(--bg-main); }
.user-dropdown a.logout { color: var(--danger); }
.user-dropdown hr { border: none; border-top: 1px solid var(--border); margin: 4px 0; }
.user-menu.open .user-dropdown { display: block; }

/* ============ Alerts Panel ============ */
.alerts-panel {
  display: none; position: fixed; top: calc(var(--topbar-h) + 8px); right: 16px;
  background: #fff; border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md); width: 320px; z-index: 1500;
}
.alerts-panel.open { display: block; }
.alerts-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; border-bottom: 1px solid var(--border);
  font-weight: 600; color: var(--text-primary);
}
.alerts-header button { color: var(--text-muted); padding: 4px; border-radius: 4px; }
.alerts-header button:hover { background: var(--bg-main); color: var(--text-primary); }
.alerts-list { padding: 8px; }
.alert-item {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 10px; border-radius: var(--radius); margin-bottom: 6px;
}
.alert-item:last-child { margin-bottom: 0; }
.alert-warn { background: #fffbeb; }
.alert-info { background: #f0f9ff; }
.alert-warn > i { color: var(--warning); margin-top: 2px; }
.alert-info > i { color: var(--info); margin-top: 2px; }
.alert-title { font-weight: 500; font-size: 13px; color: var(--text-primary); }
.alert-desc { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.overlay { display: none; position: fixed; inset: 0; z-index: 1400; }
.overlay.show { display: block; }

/* ============ Layout ============ */
.main-layout {
  display: flex; margin-top: var(--topbar-h);
  min-height: calc(100vh - var(--topbar-h));
}

/* ============ Sidebar ============ */
.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  position: fixed; top: var(--topbar-h); bottom: 0; left: 0;
  overflow-y: auto; overflow-x: hidden;
  transition: width var(--transition);
  z-index: 900;
}
.sidebar.collapsed { width: var(--sidebar-collapsed); }
.nav-menu { padding: 10px 0; }
.nav-group { margin-bottom: 4px; }
.nav-group-title {
  padding: 14px 16px 6px;
  font-size: 10px; font-weight: 700; letter-spacing: 0.08em;
  color: #4a5568; text-transform: uppercase;
  white-space: nowrap; overflow: hidden;
  transition: var(--transition);
}
.sidebar.collapsed .nav-group-title { opacity: 0; height: 0; padding: 0; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 16px; cursor: pointer;
  color: var(--sidebar-text); transition: var(--transition);
  border-left: 3px solid transparent;
  white-space: nowrap;
}
.nav-item i { font-size: 15px; min-width: 20px; text-align: center; }
.nav-item span { font-size: 13px; overflow: hidden; text-overflow: ellipsis; }
.nav-item:hover { background: var(--sidebar-hover); color: #fff; }
.nav-item.active { background: rgba(26,109,255,0.15); color: var(--primary); border-left-color: var(--primary); }
.sidebar.collapsed .nav-item span,
.sidebar.collapsed .nav-group-title { display: none; }
.sidebar.collapsed .nav-item { padding: 11px 0; justify-content: center; }

/* ============ Content Area ============ */
.content-area {
  margin-left: var(--sidebar-w);
  min-height: calc(100vh - var(--topbar-h));
  padding: 20px;
  transition: margin-left var(--transition);
  flex: 1;
}
.sidebar.collapsed ~ .content-area,
body.sidebar-collapsed .content-area { margin-left: var(--sidebar-collapsed); }

/* ============ Page Header ============ */
.page-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 20px;
}
.page-title { font-size: 18px; font-weight: 700; color: var(--text-primary); }
.page-subtitle { font-size: 13px; color: var(--text-muted); margin-top: 2px; }
.page-actions { display: flex; gap: 8px; }

/* ============ Cards ============ */
.card {
  background: var(--bg-card); border-radius: var(--radius-lg);
  box-shadow: var(--shadow); padding: 20px; margin-bottom: 16px;
  transition: transform 0.2s, box-shadow 0.2s;
}
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  padding-bottom: 14px; margin-bottom: 14px;
  border-bottom: 1px solid var(--border);
}
.card-title { font-size: 15px; font-weight: 600; color: var(--text-primary); }
.card-title i { color: var(--primary); margin-right: 6px; }

/* ============ Stats Cards ============ */
.stats-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px; margin-bottom: 20px;
}
.stat-card {
  background: var(--bg-card); border-radius: var(--radius-lg);
  padding: 18px; box-shadow: var(--shadow);
  display: flex; align-items: center; gap: 14px;
  transition: var(--transition);
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
/* 可点击卡片悬停效果 */
.card[style*="cursor:pointer"]:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.vehicle-card[style*="cursor:pointer"]:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.stat-icon {
  width: 50px; height: 50px; border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; flex-shrink: 0;
}
.stat-icon.blue { background: #dbeafe; color: #2563eb; }
.stat-icon.green { background: #dcfce7; color: #16a34a; }
.stat-icon.orange { background: #fef3c7; color: #d97706; }
.stat-icon.red { background: #fee2e2; color: #dc2626; }
.stat-icon.purple { background: #ede9fe; color: #7c3aed; }
.stat-icon.teal { background: #ccfbf1; color: #0d9488; }
.stat-value { font-size: 24px; font-weight: 700; color: var(--text-primary); line-height: 1; }
.stat-label { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.stat-trend { font-size: 11px; margin-top: 2px; }
.stat-trend.up { color: var(--success); }
.stat-trend.down { color: var(--danger); }

/* ============ Buttons ============ */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 14px; border-radius: 6px;
  font-size: 13px; font-weight: 500; cursor: pointer;
  transition: var(--transition); border: 1px solid transparent;
}
.btn i { font-size: 12px; }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); color: #fff; border-color: var(--success); }
.btn-success:hover { background: #149c58; }
.btn-warning { background: var(--warning); color: #fff; border-color: var(--warning); }
.btn-warning:hover { background: #d97706; }
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-danger:hover { background: #dc2626; }
.btn-default { background: #fff; color: var(--text-primary); border-color: var(--border); }
.btn-default:hover { background: var(--bg-main); }
.btn-info { background: var(--info); color: #fff; border-color: var(--info); }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-xs { padding: 2px 8px; font-size: 11px; border-radius: 4px; }
.btn-icon { width: 30px; height: 30px; padding: 0; justify-content: center; border-radius: 6px; }

/* ============ Forms ============ */
.form-group { margin-bottom: 14px; }
.form-label { display: block; font-size: 13px; font-weight: 500; color: var(--text-secondary); margin-bottom: 5px; }
.form-label .required { color: var(--danger); margin-left: 2px; }
.form-control {
  width: 100%; padding: 7px 10px;
  border: 1px solid var(--border); border-radius: 6px;
  background: #fff; color: var(--text-primary);
  transition: var(--transition);
}
.form-control:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(26,109,255,0.1); }
.form-control:disabled { background: var(--bg-main); cursor: not-allowed; }
select.form-control { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M6 8L0 0h12z' fill='%236b7280'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 28px; }
textarea.form-control { resize: vertical; min-height: 80px; }
.form-control-plain {
  display: flex; align-items: center;
  width: 100%; padding: 7px 10px;
  font-size: 13px; color: var(--text-primary);
  background: var(--bg-main); border: 1px solid transparent;
  border-radius: 6px; min-height: 33px; line-height: 1.4;
}
.report-section { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); }
.report-section-title { font-weight: 600; color: var(--text-primary); border-bottom: 1px solid var(--border); }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
.form-row-2 { grid-template-columns: 7fr 3fr; }
.form-row-3 { grid-template-columns: 1fr 1fr 1fr; }
.form-row-4 { grid-template-columns: 1fr 1fr 1fr 1fr; }

/* ============ Tables ============ */
.table-wrapper { overflow-x: auto; border-radius: var(--radius); }
.data-table { width: 100%; }
.data-table thead th {
  background: #f8fafc; padding: 10px 12px;
  font-size: 12px; font-weight: 600;
  color: var(--text-secondary); text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.data-table tbody td {
  padding: 10px 12px; border-bottom: 1px solid #f1f5f9;
  font-size: 13px; color: var(--text-primary);
}
.data-table tbody tr:hover { background: #f8fafc; }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table .actions { display: flex; gap: 4px; }

/* ============ Badges / Tags ============ */
.badge-tag {
  display: inline-flex; align-items: center;
  padding: 2px 8px; border-radius: 12px;
  font-size: 11px; font-weight: 500;
}
.badge-success { background: #dcfce7; color: #166534; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-danger { background: #fee2e2; color: #991b1b; }
.badge-info { background: #e0f2fe; color: #0369a1; }
.badge-secondary { background: #f1f5f9; color: #475569; }
.badge-primary { background: var(--primary-light); color: var(--primary-dark); }

/* ============ Search/Filter Bar ============ */
.filter-bar {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 16px; flex-wrap: wrap;
}
.search-box {
  display: flex; align-items: center;
  border: 1px solid var(--border); border-radius: 6px;
  background: #fff; overflow: hidden;
  flex: 1; min-width: 200px; max-width: 320px;
}
.search-box input { border: none; padding: 7px 10px; flex: 1; }
.search-box button { padding: 7px 12px; color: var(--text-muted); }
.search-box button:hover { color: var(--primary); }
.filter-select { padding: 7px 28px 7px 10px; border: 1px solid var(--border); border-radius: 6px; background: #fff; appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M6 8L0 0h12z' fill='%236b7280'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 8px center; min-width: 100px; }

/* ============ Pagination ============ */
.pagination {
  display: flex; align-items: center; gap: 4px;
  margin-top: 16px; justify-content: flex-end;
}
.pagination .page-btn {
  min-width: 30px; height: 30px; border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; cursor: pointer; border: 1px solid var(--border);
  background: #fff; color: var(--text-secondary); transition: var(--transition);
}
.pagination .page-btn:hover { border-color: var(--primary); color: var(--primary); }
.pagination .page-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.pagination .page-btn.disabled { opacity: 0.5; cursor: not-allowed; }
.pagination .total-info { color: var(--text-muted); font-size: 12px; margin-right: 8px; }

/* ============ Modal ============ */
.modal-backdrop {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,0.45); z-index: 2000;
}
.modal-backdrop.show { display: block; }
.modal {
  display: none; position: fixed; top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  background: #fff; border-radius: var(--radius-lg);
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
  z-index: 2001; min-width: 400px; max-width: 90vw;
  max-height: 90vh; display: none; flex-direction: column;
}
.modal.show { display: flex; }
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
  font-size: 15px; font-weight: 600;
}
.modal-header button { color: var(--text-muted); padding: 4px; border-radius: 4px; }
.modal-header button:hover { background: var(--bg-main); color: var(--text-primary); }
.modal-body { padding: 20px; overflow-y: auto; flex: 1; }
.modal-footer {
  display: flex; justify-content: flex-end; gap: 8px;
  padding: 12px 20px; border-top: 1px solid var(--border);
}

/* ============ Toast ============ */
.toast-container {
  position: fixed; top: calc(var(--topbar-h) + 16px); right: 16px;
  display: flex; flex-direction: column; gap: 8px; z-index: 9999;
}
.toast {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px; border-radius: var(--radius);
  background: #fff; box-shadow: var(--shadow-md);
  min-width: 260px; max-width: 380px;
  animation: slideIn 0.25s ease;
  border-left: 4px solid var(--primary);
}
.toast.success { border-left-color: var(--success); }
.toast.warning { border-left-color: var(--warning); }
.toast.error { border-left-color: var(--danger); }
.toast i { font-size: 16px; }
.toast.success i { color: var(--success); }
.toast.warning i { color: var(--warning); }
.toast.error i { color: var(--danger); }
.toast.info i { color: var(--primary); }
.toast span { flex: 1; font-size: 13px; }
.toast .close-toast { color: var(--text-muted); padding: 2px; }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes slideOut { from { transform: translateX(0); opacity: 1; } to { transform: translateX(100%); opacity: 0; } }

/* ============ Tabs ============ */
.tab-nav {
  display: flex; border-bottom: 1px solid var(--border);
  margin-bottom: 16px; gap: 0; overflow-x: auto;
}
.tab-btn {
  padding: 10px 18px; font-size: 13px; font-weight: 500;
  color: var(--text-muted); cursor: pointer; white-space: nowrap;
  border-bottom: 2px solid transparent; transition: var(--transition);
}
.tab-btn:hover { color: var(--text-primary); }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-pane { display: none; }
.tab-pane.active { display: block; }

/* ============ Status Colors ============ */
.status-standby { background: #dcfce7; color: #166534; }
.status-out { background: #fef3c7; color: #92400e; }
.status-repair { background: #fee2e2; color: #991b1b; }
.status-done { background: #dcfce7; color: #166534; }
.status-undone { background: #fef3c7; color: #92400e; }
.status-cancel { background: #f1f5f9; color: #475569; }

/* ============ Grid Layout ============ */
.grid-2 { display: grid; grid-template-columns: 7fr 3fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }

/* ============ Utility ============ */
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-primary { color: var(--primary) !important; }
.text-success { color: var(--success) !important; }
.text-warning { color: var(--warning) !important; }
.text-danger { color: var(--danger) !important; }
.text-muted { color: var(--text-muted) !important; }
.font-bold { font-weight: 700; }
.font-medium { font-weight: 500; }
.mb-0 { margin-bottom: 0; }
.mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.mt-16 { margin-top: 16px; }
.flex { display: flex; }
.flex-center { display: flex; align-items: center; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.d-none { display: none !important; }

/* ============ Empty State ============ */
.empty-state {
  padding: 48px 20px; text-align: center; color: var(--text-muted);
}
.empty-state i { font-size: 48px; margin-bottom: 12px; opacity: 0.3; }
.empty-state p { font-size: 14px; }

/* ============ Responsive ============ */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.mobile-open { transform: translateX(0); }
  .content-area { margin-left: 0 !important; padding: 12px; }
  .stats-grid { grid-template-columns: 7fr 3fr; }
  .form-row-3, .form-row-4 { grid-template-columns: 7fr 3fr; }
  .brand-name { display: none; }
  .top-info { display: none; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
}
@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
  .form-row-2, .form-row-3, .form-row-4 { grid-template-columns: 1fr; }
  .modal { min-width: 90vw; }
}
