/* ============================================
   车队管理平台 - 全局样式
   ============================================ */

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

:root {
  --primary: #1677FF;
  --primary-hover: #4096FF;
  --danger: #FF4D4F;
  --danger-hover: #FF7875;
  --success: #52C41A;
  --warning: #FAAD14;
  --bg: #F5F5F5;
  --bg-white: #FFFFFF;
  --text: #333333;
  --text-secondary: #666666;
  --text-muted: #999999;
  --border: #E8E8E8;
  --shadow: 0 2px 8px rgba(0,0,0,0.08);
  --radius: 8px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
}

/* ==================== 登录面板 ==================== */

#login-panel {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.login-card {
  background: var(--bg-white);
  padding: 40px;
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.2);
  width: 400px;
  max-width: 90vw;
}

.login-card h1 {
  text-align: center;
  margin-bottom: 8px;
  font-size: 24px;
  color: var(--primary);
}

.login-card .subtitle {
  text-align: center;
  color: var(--text-muted);
  margin-bottom: 32px;
  font-size: 14px;
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  margin-bottom: 6px;
  font-size: 14px;
  color: var(--text-secondary);
  font-weight: 500;
}

.form-group input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  transition: border-color 0.2s;
  outline: none;
}

.form-group input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(22,119,255,0.1);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
  font-weight: 500;
  gap: 6px;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: var(--danger-hover); }

.btn-outline {
  background: #fff;
  color: var(--primary);
  border: 1px solid var(--primary);
}
.btn-outline:hover:not(:disabled) { background: #F0F5FF; }

.btn-sm { padding: 5px 12px; font-size: 12px; }
.btn-lg { padding: 12px 28px; font-size: 16px; }
.btn-block { display: block; width: 100%; }

/* ==================== 主界面 ==================== */

#main-panel {
  display: none;
  flex-direction: column;
  height: 100vh;
}

/* 顶部导航 */
.navbar {
  display: flex;
  align-items: center;
  background: var(--bg-white);
  border-bottom: 1px solid var(--border);
  padding: 0 20px;
  height: 56px;
  box-shadow: var(--shadow);
  z-index: 100;
  flex-shrink: 0;
}

.navbar .logo {
  font-size: 18px;
  font-weight: 700;
  color: var(--primary);
  margin-right: 32px;
  white-space: nowrap;
}

.nav-tabs {
  display: flex;
  gap: 4px;
  flex: 1;
}

.nav-tab {
  padding: 8px 20px;
  border: none;
  background: transparent;
  font-size: 14px;
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: var(--radius);
  transition: all 0.2s;
  font-weight: 500;
}

.nav-tab:hover { background: #F0F5FF; color: var(--primary); }
.nav-tab.active { background: #E6F4FF; color: var(--primary); }

.navbar .logout-btn {
  padding: 6px 16px;
  border: 1px solid var(--border);
  background: #fff;
  border-radius: var(--radius);
  font-size: 13px;
  cursor: pointer;
  color: var(--text-secondary);
  transition: all 0.2s;
}
.navbar .logout-btn:hover { color: var(--danger); border-color: var(--danger); }

/* 标签页面板 */
.tab-content {
  flex: 1;
  overflow: hidden;
  position: relative;
}

.tab-panel {
  display: none;
  height: 100%;
  overflow: auto;
}

.tab-panel.active { display: flex; flex-direction: column; }

/* ==================== 轨迹回放 ==================== */

#tab-playback {
  flex-direction: column;
}

/* 查询工具栏 */
.toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--bg-white);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  flex-shrink: 0;
}

.toolbar label {
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 500;
  white-space: nowrap;
}

.toolbar select,
.toolbar input[type="datetime-local"] {
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  outline: none;
}

.toolbar select:focus,
.toolbar input:focus {
  border-color: var(--primary);
}

/* 地图容器 */
.map-wrapper {
  flex: 1;
  position: relative;
  min-height: 0;
}

#map-container {
  width: 100%;
  height: 100%;
}

/* 信息栏 */
.info-bar {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 10px 16px;
  background: var(--bg-white);
  border-top: 1px solid var(--border);
  font-size: 13px;
  flex-shrink: 0;
  flex-wrap: wrap;
}

.info-item {
  display: flex;
  align-items: center;
  gap: 4px;
}

.info-item .label {
  color: var(--text-muted);
}

.info-item .value {
  font-weight: 600;
  color: var(--text);
}

.info-item .value.highlight {
  color: var(--primary);
  font-size: 15px;
}

/* 播放控件 */
.playback-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--bg-white);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  flex-wrap: wrap;
}

.playback-bar input[type="range"] {
  flex: 1;
  min-width: 100px;
  height: 6px;
  -webkit-appearance: none;
  appearance: none;
  background: #E8E8E8;
  border-radius: 3px;
  outline: none;
  cursor: pointer;
}

.playback-bar input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--primary);
  cursor: pointer;
}

/* 跟随复选框 */
.follow-label {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  white-space: nowrap;
}

/* ==================== 用户/设备管理 ==================== */

#tab-users, #tab-devices {
  padding: 16px;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.panel-header h2 {
  font-size: 18px;
  font-weight: 600;
}

/* 表格 */
.table-wrapper {
  background: var(--bg-white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th, td {
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

th {
  background: #FAFAFA;
  font-weight: 600;
  color: var(--text-secondary);
  position: sticky;
  top: 0;
}

tr:hover td { background: #FAFAFA; }

.action-cell {
  display: flex;
  gap: 8px;
}

/* 徽章 */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 500;
}

.badge-admin { background: #FFF1F0; color: var(--danger); }
.badge-user { background: #F6FFED; color: var(--success); }
.badge-active { background: #F6FFED; color: var(--success); }
.badge-disabled { background: #FFF7E6; color: var(--warning); }

/* ==================== 模态对话框 ==================== */

.modal {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.45);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}

.modal.show { display: flex; }

.modal-content {
  background: var(--bg-white);
  border-radius: 12px;
  padding: 24px;
  width: 480px;
  max-width: 90vw;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 8px 32px rgba(0,0,0,0.15);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.modal-header h3 {
  font-size: 16px;
  font-weight: 600;
}

.modal-close {
  width: 28px;
  height: 28px;
  border: none;
  background: transparent;
  font-size: 18px;
  cursor: pointer;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
}

.modal-close:hover { background: #F5F5F5; }

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
}

/* 表单checkbox行 */
.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.checkbox-row label {
  font-size: 14px;
  cursor: pointer;
}

/* ==================== Toast ==================== */

#toast {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.8);
  color: #fff;
  padding: 12px 24px;
  border-radius: 8px;
  font-size: 14px;
  z-index: 2000;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s;
}

#toast.show { opacity: 1; }

/* ==================== 加载遮罩 ==================== */

#loading-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(255,255,255,0.7);
  z-index: 1500;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 12px;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

#loading-text {
  font-size: 14px;
  color: var(--text-secondary);
}

/* ==================== 实时监控 ==================== */

.realtime-layout {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.realtime-sidebar {
  width: 240px;
  min-width: 240px;
  background: var(--bg-white);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.realtime-sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.realtime-sidebar-header h3 {
  font-size: 15px;
  font-weight: 600;
}

.realtime-count {
  font-size: 12px;
  color: var(--text-muted);
  background: #F5F5F5;
  padding: 2px 10px;
  border-radius: 10px;
}

.realtime-device-list {
  flex: 1;
  overflow-y: auto;
}

.realtime-device-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid #F5F5F5;
  cursor: pointer;
  transition: background 0.15s;
}

.realtime-device-item:hover { background: #FAFAFA; }
.realtime-device-item.active { background: #E6F4FF; border-left: 3px solid var(--primary); }

.realtime-device-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.realtime-device-dot.online { background: var(--success); box-shadow: 0 0 4px var(--success); }
.realtime-device-dot.offline { background: #CCC; }

.realtime-device-info { flex: 1; min-width: 0; }
.realtime-device-name { font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.realtime-device-time { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

.realtime-device-status {
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 8px;
}
.realtime-device-status.online { background: #F6FFED; color: var(--success); }
.realtime-device-status.offline { background: #F5F5F5; color: #CCC; }

.realtime-map-wrapper {
  flex: 1;
  position: relative;
  min-width: 0;
}

#realtime-map-container {
  width: 100%;
  height: 100%;
}

.realtime-info-panel {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 10px 20px;
  background: var(--bg-white);
  border-top: 1px solid var(--border);
  font-size: 13px;
  flex-shrink: 0;
  min-height: 44px;
}

.realtime-info-empty { color: var(--text-muted); }

.realtime-info-panel .info-label { color: var(--text-muted); font-size: 12px; }
.realtime-info-panel .info-value { font-weight: 600; color: var(--text); margin: 0 16px 0 4px; }

/* ==================== 报表 ==================== */

.panel-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
}

#tab-reports, #tab-settings {
  flex-direction: column;
}
#tab-reports.active, #tab-settings.active {
  display: flex;
  flex-direction: column;
}

.report-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  flex-wrap: wrap;
}

.report-toolbar label {
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 500;
  white-space: nowrap;
}

.report-toolbar input[type="date"] {
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  outline: none;
}
.report-toolbar input[type="date"]:focus { border-color: var(--primary); }

.report-device-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tag {
  padding: 4px 14px;
  border-radius: 14px;
  font-size: 12px;
  cursor: pointer;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text-secondary);
  transition: all 0.15s;
  user-select: none;
}
.tag:hover { border-color: var(--primary); color: var(--primary); }
.tag-selected { background: var(--primary); color: #fff; border-color: var(--primary); }
.tag-selected:hover { background: var(--primary-hover); color: #fff; }

.report-section {
  margin-top: 20px;
}

.report-section h3 {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--text);
}

.empty-cell {
  text-align: center;
  padding: 40px;
  color: var(--text-muted);
}

/* ==================== 设置 ==================== */

.settings-form {
  max-width: 700px;
}

.settings-group {
  background: var(--bg-white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 24px;
  margin-bottom: 16px;
}

.settings-group h3 {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 16px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

.form-row {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
}

.form-row .form-group {
  flex: 1;
  min-width: 180px;
}

.settings-form .form-group label {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 500;
}

.settings-form .form-group input,
.settings-form .form-group select {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  outline: none;
}
.settings-form .form-group input:focus,
.settings-form .form-group select:focus {
  border-color: var(--primary);
}

/* ==================== 下拉多选组件 ==================== */

.dropdown {
  position: relative;
  min-width: 200px;
}

.dropdown-trigger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  text-align: left;
}
.dropdown-trigger:hover { border-color: var(--primary); }

.dropdown-arrow {
  font-size: 10px;
  color: var(--text-muted);
  transition: transform 0.2s;
}

.dropdown.open .dropdown-arrow { transform: rotate(180deg); }
.dropdown.open .dropdown-trigger { border-color: var(--primary); }

.dropdown-panel {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin-top: 4px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.12);
  z-index: 200;
  min-width: 280px;
  max-height: 360px;
  display: none;
  flex-direction: column;
}
.dropdown.open .dropdown-panel { display: flex; }

.dropdown-search {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}
.dropdown-search input {
  width: 100%;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  outline: none;
}
.dropdown-search input:focus { border-color: var(--primary); }

.dropdown-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  font-size: 12px;
  border-bottom: 1px solid #F5F5F5;
}
.dropdown-actions a {
  color: var(--primary);
  text-decoration: none;
  cursor: pointer;
}
.dropdown-actions a:hover { text-decoration: underline; }

.dropdown-list {
  flex: 1;
  overflow-y: auto;
  max-height: 240px;
}

.dropdown-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.1s;
}
.dropdown-item:hover { background: #F5F5F5; }

.dropdown-item input[type="checkbox"] {
  width: 15px;
  height: 15px;
  cursor: pointer;
  accent-color: var(--primary);
}

.dropdown-item.hidden { display: none; }

/* ==================== 报表（覆盖旧标签样式） ==================== */

.report-device-tags { display: none; }

/* ==================== 实时监控筛选 ==================== */

.realtime-filter-tabs {
  display: flex;
  padding: 8px 12px;
  gap: 6px;
  border-bottom: 1px solid #F5F5F5;
  flex-shrink: 0;
}

.realtime-filter-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: #fff;
  font-size: 12px;
  cursor: pointer;
  color: var(--text-secondary);
  transition: all 0.15s;
}
.realtime-filter-btn:hover { border-color: var(--primary); color: var(--primary); }
.realtime-filter-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }

.realtime-filter-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  display: inline-block;
}
.realtime-filter-dot.online { background: var(--success); }
.realtime-filter-btn.active .realtime-filter-dot.online { background: #fff; }
.realtime-filter-dot.offline { background: #CCC; }
.realtime-filter-btn.active .realtime-filter-dot.offline { background: #fff; }

/* ==================== 分页组件 ==================== */

.pagination {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  padding: 12px 16px;
  background: #FAFAFA;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
}

.pagination-info {
  margin-right: 12px;
  font-size: 12px;
  color: var(--text-muted);
}

.pagination-btn {
  min-width: 32px;
  height: 32px;
  padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  user-select: none;
}
.pagination-btn:hover:not(:disabled):not(.active) {
  border-color: var(--primary);
  color: var(--primary);
}
.pagination-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.pagination-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.pagination-ellipsis {
  min-width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  color: var(--text-muted);
  user-select: none;
}

/* ==================== 地图（全屏设备总览） ==================== */

.map-view-layout {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.map-view-sidebar {
  width: 240px;
  min-width: 240px;
  background: var(--bg-white);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.map-view-sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.map-view-sidebar-header h3 {
  font-size: 15px;
  font-weight: 600;
}

.map-view-device-list {
  flex: 1;
  overflow-y: auto;
}

.map-view-device-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid #F5F5F5;
  cursor: pointer;
  transition: background 0.15s;
}
.map-view-device-item:hover { background: #FAFAFA; }
.map-view-device-item.active { background: #E6F4FF; border-left: 3px solid var(--primary); }

.map-view-device-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.map-view-device-info { flex: 1; min-width: 0; }
.map-view-device-name { font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.map-view-device-detail { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

.map-view-map-wrapper {
  flex: 1;
  position: relative;
  min-width: 0;
}

#map-view-container {
  width: 100%;
  height: 100%;
}

/* ==================== 响应式 ==================== */

@media (max-width: 768px) {
  .toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .playback-bar {
    flex-wrap: wrap;
  }

  .info-bar {
    gap: 10px;
    font-size: 12px;
  }

  .navbar .nav-tab {
    padding: 6px 12px;
    font-size: 13px;
  }
}
