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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  display: flex;
  height: 100vh;
  background: #f5f6fa;
  color: #2c3e50;
}

/* ── Sidebar ──────────────────────────────────────────────────────── */
.sidebar {
  width: 300px;
  background: #fff;
  border-right: 1px solid #e1e5eb;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  flex-shrink: 0;
}

.sidebar-header {
  padding: 16px 20px;
  border-bottom: 1px solid #e1e5eb;
  background: #2c3e50;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.sidebar-header h2 {
  font-size: 17px;
  font-weight: 600;
}

/* "+" button in header */
.btn-add-device {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 1.5px solid rgba(255,255,255,0.45);
  background: rgba(255,255,255,0.12);
  color: #fff;
  font-size: 20px;
  font-weight: 300;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  transition: background 0.15s;
  flex-shrink: 0;
}
.btn-add-device:hover { background: rgba(255,255,255,0.28); }

/* ── Stats Grid ───────────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 12px;
  flex-shrink: 0;
}

.stat-card {
  background: #f8f9fb;
  border-radius: 8px;
  padding: 10px 12px;
  text-align: center;
  border: 1px solid #e1e5eb;
}

.stat-card.online  { border-left: 3px solid #27ae60; }
.stat-card.offline { border-left: 3px solid #e74c3c; }

.stat-value {
  display: block;
  font-size: 22px;
  font-weight: 700;
  color: #2c3e50;
}

.stat-label {
  font-size: 10px;
  color: #7f8c8d;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* ── Filter Section ───────────────────────────────────────────────── */
.filter-section {
  padding: 12px 14px;
  border-top: 1px solid #e1e5eb;
  flex-shrink: 0;
}

.filter-section h3,
.device-list-section h3 {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: #7f8c8d;
  margin-bottom: 10px;
}

.filter-section label {
  display: block;
  font-size: 11px;
  font-weight: 500;
  color: #555;
  margin-bottom: 3px;
  margin-top: 8px;
}

.filter-section select,
.filter-section input {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid #dcdfe6;
  border-radius: 6px;
  font-size: 13px;
  background: #fff;
  outline: none;
  color: #2c3e50;
}

.filter-section select:focus,
.filter-section input:focus {
  border-color: #3498db;
  box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.15);
}

.filter-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

/* ── Buttons ──────────────────────────────────────────────────────── */
.btn {
  padding: 8px 14px;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-primary  { background: #3498db; color: #fff; flex: 1; }
.btn-primary:hover  { background: #2980b9; }
.btn-secondary { background: #ecf0f1; color: #555; flex: 1; }
.btn-secondary:hover { background: #dcdfe6; }

/* ── Download Section ─────────────────────────────────────────────── */
.download-section {
  margin: 0 12px 4px;
  padding: 12px 14px;
  border: 1px solid #d5e8d4;
  border-radius: 8px;
  background: linear-gradient(135deg, #f0faf0 0%, #e8f5e9 100%);
  flex-shrink: 0;
}

.download-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.download-title {
  font-size: 13px;
  font-weight: 600;
  color: #1e8449;
}

.download-hint {
  font-size: 11px;
  color: #52be80;
  margin-top: 2px;
}

.btn-download {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 8px 14px;
  border: none;
  border-radius: 6px;
  background: #27ae60;
  color: #fff;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s;
  flex-shrink: 0;
}
.btn-download:hover { background: #219a52; }

.download-icon {
  font-size: 15px;
  font-weight: 700;
}

/* ── Device List ──────────────────────────────────────────────────── */
.device-list-section {
  padding: 12px 14px;
  border-top: 1px solid #e1e5eb;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.device-list {
  flex: 1;
  overflow-y: auto;
}
.device-list::-webkit-scrollbar { width: 4px; }
.device-list::-webkit-scrollbar-thumb { background: #dcdfe6; border-radius: 2px; }

.device-item {
  display: flex;
  align-items: center;
  padding: 9px 10px;
  border-radius: 6px;
  margin-bottom: 3px;
  cursor: pointer;
  transition: background 0.15s;
}

.device-item:hover { background: #f0f3f7; }

.device-status {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 10px;
  flex-shrink: 0;
}

.device-status.online  { background: #27ae60; }
.device-status.offline { background: #e74c3c; }

.device-info { flex: 1; min-width: 0; }

.device-reg {
  font-size: 13px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.device-imei {
  font-size: 11px;
  color: #95a5a6;
  font-family: monospace;
}

.device-speed {
  font-size: 12px;
  font-weight: 500;
  color: #3498db;
  flex-shrink: 0;
}

/* ── Main Content ─────────────────────────────────────────────────── */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Tab Navigation ───────────────────────────────────────────────── */
.tab-nav {
  display: flex;
  background: #fff;
  border-bottom: 1px solid #e1e5eb;
  padding: 0 15px;
  flex-shrink: 0;
}

.tab-btn {
  padding: 12px 20px;
  border: none;
  background: none;
  font-size: 14px;
  font-weight: 500;
  color: #7f8c8d;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.2s;
}

.tab-btn.active  { color: #3498db; border-bottom-color: #3498db; }
.tab-btn:hover   { color: #2c3e50; }

/* ── Tab Content ──────────────────────────────────────────────────── */
.tab-content { display: none; flex: 1; overflow: hidden; }
.tab-content.active { display: flex; flex-direction: column; }

/* ── Map ──────────────────────────────────────────────────────────── */
#map { flex: 1; z-index: 1; }

/* ── Tables ───────────────────────────────────────────────────────── */
.table-container {
  flex: 1;
  overflow-y: auto;
  padding: 15px;
}

table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

thead { background: #f8f9fb; }

th {
  padding: 10px 12px;
  text-align: left;
  font-size: 11px;
  font-weight: 700;
  color: #7f8c8d;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid #e1e5eb;
}

td {
  padding: 10px 12px;
  font-size: 13px;
  border-bottom: 1px solid #f0f3f7;
}

tr:hover { background: #f8f9fb; }

/* ── Event type badges ────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 500;
}

.badge-emergency { background: #fde8e8; color: #e74c3c; }
.badge-ignition  { background: #e8f5e9; color: #27ae60; }
.badge-alert     { background: #fff3cd; color: #f39c12; }
.badge-normal    { background: #e3f2fd; color: #3498db; }

/* ── Pagination ───────────────────────────────────────────────────── */
.pagination {
  display: flex;
  justify-content: center;
  gap: 5px;
  padding: 15px;
}

.pagination button {
  padding: 6px 12px;
  border: 1px solid #dcdfe6;
  border-radius: 4px;
  background: #fff;
  cursor: pointer;
  font-size: 13px;
}

.pagination button.active {
  background: #3498db;
  color: #fff;
  border-color: #3498db;
}

/* ── Modal ────────────────────────────────────────────────────────── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 200;
  align-items: center;
  justify-content: center;
}
.modal-overlay.open { display: flex; }

.modal-box {
  background: #fff;
  border-radius: 10px;
  width: 500px;
  max-width: 96vw;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 8px 32px rgba(0,0,0,0.16);
}

.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid #e1e5eb;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  background: #fff;
  z-index: 1;
}

.modal-header h3 {
  font-size: 16px;
  font-weight: 600;
  color: #2c3e50;
}

.modal-close {
  width: 28px;
  height: 28px;
  border: none;
  background: #f0f3f7;
  border-radius: 50%;
  cursor: pointer;
  font-size: 13px;
  color: #555;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}
.modal-close:hover { background: #e74c3c; color: #fff; }

.modal-body {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.modal-section-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  color: #95a5a6;
  padding-bottom: 6px;
  border-bottom: 1px solid #f0f3f7;
  margin-top: 4px;
}

.modal-row {
  display: flex;
  gap: 12px;
}

.modal-field {
  flex: 1;
  min-width: 0;
}

.modal-field label {
  display: block;
  font-size: 11px;
  font-weight: 500;
  color: #7f8c8d;
  margin-bottom: 4px;
}

.modal-field input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid #dcdfe6;
  border-radius: 6px;
  font-size: 13px;
  background: #fff;
  color: #2c3e50;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.modal-field input:focus {
  border-color: #3498db;
  box-shadow: 0 0 0 2px rgba(52,152,219,0.15);
}

.add-device-msg {
  font-size: 12px;
  min-height: 16px;
  padding: 2px 0;
}
.add-device-msg.success { color: #27ae60; }
.add-device-msg.error   { color: #e74c3c; }

.btn-modal-submit {
  width: 100%;
  padding: 10px;
  margin-top: 4px;
  font-size: 14px;
  flex: none;
}

/* ── Responsive ───────────────────────────────────────────────────── */
@media (max-width: 768px) {
  body { flex-direction: column; }
  .sidebar { width: 100%; max-height: 40vh; }
  .stats-grid { grid-template-columns: repeat(4, 1fr); }
}

/* ── Login page ───────────────────────────────────────────────────── */
.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #1a2a3a 0%, #2c3e50 60%, #3498db22 100%);
}

.login-card {
  background: #fff;
  border-radius: 16px;
  padding: 48px 40px 40px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.25);
  text-align: center;
}

.login-logo {
  margin-bottom: 16px;
}

.login-title {
  font-size: 1.6rem;
  font-weight: 700;
  color: #2c3e50;
  margin-bottom: 4px;
}

.login-subtitle {
  font-size: 0.875rem;
  color: #7f8c8d;
  margin-bottom: 28px;
}

.login-form {
  text-align: left;
}

.login-field {
  margin-bottom: 16px;
}

.login-field label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: #5a6a7a;
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.login-field input {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid #dce1e7;
  border-radius: 8px;
  font-size: 0.95rem;
  color: #2c3e50;
  transition: border-color 0.2s;
  outline: none;
}

.login-field input:focus {
  border-color: #3498db;
}

.login-error {
  background: #fdecea;
  color: #c0392b;
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 0.85rem;
  margin-bottom: 14px;
}

.login-btn {
  width: 100%;
  padding: 11px;
  font-size: 1rem;
  font-weight: 600;
  border-radius: 8px;
  margin-top: 4px;
}
