/* QuestFleet Dashboard — Dark Theme */
:root {
  --bg: #0f1117;
  --bg-card: #1a1d27;
  --bg-input: #252836;
  --border: #2e3248;
  --text: #e2e8f0;
  --text-muted: #8892a4;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --warning: #f59e0b;
  --success: #22c55e;
  --online: #22c55e;
  --offline: #6b7280;
  --radius: 8px;
  --shadow: 0 4px 16px rgba(0,0,0,0.4);
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
}

a {
  color: var(--primary);
  text-decoration: none;
}
a:hover { text-decoration: underline; }

/* ─── Nav ─────────────────────────────────────────────────────────────── */
.navbar {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  display: flex;
  align-items: center;
  height: 52px;
  gap: 24px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.navbar-brand {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.3px;
}
.navbar-brand span { color: var(--primary); }

.navbar-links {
  display: flex;
  gap: 4px;
  flex: 1;
}

.navbar-links a {
  color: var(--text-muted);
  padding: 6px 12px;
  border-radius: var(--radius);
  font-size: 14px;
  transition: background 0.15s, color 0.15s;
}
.navbar-links a:hover, .navbar-links a.active {
  background: var(--bg-input);
  color: var(--text);
  text-decoration: none;
}

.navbar-end {
  display: flex;
  align-items: center;
  gap: 12px;
}

.ws-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
}
.ws-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--offline);
}
.ws-dot.connected { background: var(--online); }

/* ─── Page Layout ─────────────────────────────────────────────────────── */
.page {
  max-width: 1280px;
  margin: 0 auto;
  padding: 24px;
}

.page-header {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 24px;
}

.page-title {
  font-size: 22px;
  font-weight: 600;
}

/* ─── Buttons ─────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius);
  border: none;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: background 0.15s, opacity 0.15s;
  white-space: nowrap;
}
.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-secondary { background: var(--bg-input); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover:not(:disabled) { background: var(--border); }

.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover:not(:disabled) { background: var(--bg-input); color: var(--text); }

.btn-sm { padding: 4px 10px; font-size: 12px; }

/* ─── Login Page ──────────────────────────────────────────────────────── */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--bg);
}

.login-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 40px;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow);
}

.login-logo {
  text-align: center;
  margin-bottom: 28px;
}
.login-logo h1 {
  font-size: 26px;
  font-weight: 700;
}
.login-logo h1 span { color: var(--primary); }
.login-logo p { color: var(--text-muted); font-size: 13px; margin-top: 4px; }

.form-group {
  margin-bottom: 16px;
}
.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.form-group input, .form-group select, .form-group textarea {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 9px 12px;
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
  border-color: var(--primary);
}
.form-group input::placeholder { color: var(--text-muted); }

.login-error {
  color: var(--danger);
  font-size: 13px;
  margin-bottom: 12px;
  display: none;
}

.btn-login {
  width: 100%;
  justify-content: center;
  padding: 10px;
  font-size: 15px;
}

/* ─── Batch Actions Bar ───────────────────────────────────────────────── */
.batch-bar {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.batch-bar-label {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 500;
  margin-right: 4px;
}

/* ─── Device Grid ─────────────────────────────────────────────────────── */
.device-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}

.device-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  text-decoration: none;
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
  display: block;
  position: relative;
}
.device-card:hover {
  border-color: var(--primary);
  box-shadow: 0 0 0 1px var(--primary)22;
  text-decoration: none;
}
.device-card.offline { opacity: 0.7; }

.device-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 12px;
}

.device-name {
  font-size: 15px;
  font-weight: 600;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-top: 4px;
  margin-left: 8px;
}
.status-dot.online  { background: var(--online);  box-shadow: 0 0 6px var(--online)80; }
.status-dot.offline { background: var(--offline); }

.device-serial {
  font-size: 11px;
  color: var(--text-muted);
  font-family: monospace;
  margin-bottom: 10px;
}

.device-meta {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.device-meta-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-muted);
}
.device-meta-row .label { width: 60px; flex-shrink: 0; }
.device-meta-row .value { color: var(--text); }

/* Battery bar */
.battery-bar-wrap {
  flex: 1;
  background: var(--bg-input);
  border-radius: 3px;
  height: 6px;
  overflow: hidden;
}
.battery-bar {
  height: 100%;
  border-radius: 3px;
  transition: width 0.3s;
}
.battery-bar.high   { background: var(--success); }
.battery-bar.medium { background: var(--warning); }
.battery-bar.low    { background: var(--danger); }

.battery-pct { font-size: 11px; color: var(--text-muted); min-width: 30px; text-align: right; }

/* WiFi signal */
.wifi-bars {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 14px;
}
.wifi-bars span {
  width: 3px;
  background: var(--bg-input);
  border-radius: 1px;
}
.wifi-bars span:nth-child(1) { height: 4px; }
.wifi-bars span:nth-child(2) { height: 7px; }
.wifi-bars span:nth-child(3) { height: 10px; }
.wifi-bars span:nth-child(4) { height: 14px; }
.wifi-bars span.active { background: var(--primary); }

/* ─── Device Detail Page ──────────────────────────────────────────────── */
.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

@media (max-width: 860px) {
  .detail-grid { grid-template-columns: 1fr; }
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.card-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 16px;
}

.stat-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.stat-row {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
}
.stat-row .key { color: var(--text-muted); width: 110px; flex-shrink: 0; }
.stat-row .val { color: var(--text); font-weight: 500; }
.stat-row .val.mono { font-family: monospace; }

/* Action buttons grid */
.action-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 8px;
}

/* ─── Command Log ─────────────────────────────────────────────────────── */
.log-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  font-family: monospace;
}
.log-table th {
  text-align: left;
  padding: 8px 10px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  font-weight: 500;
}
.log-table td {
  padding: 7px 10px;
  border-bottom: 1px solid var(--border)80;
  vertical-align: top;
}
.log-table tr:last-child td { border-bottom: none; }

.log-status {
  padding: 2px 7px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 500;
}
.log-status.pending  { background: #f59e0b22; color: var(--warning); }
.log-status.ok       { background: #22c55e22; color: var(--success); }
.log-status.error    { background: #ef444422; color: var(--danger); }
.log-status.timeout  { background: #6b728022; color: var(--text-muted); }

/* ─── Installed Apps ──────────────────────────────────────────────────── */
.app-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 240px;
  overflow-y: auto;
}
.app-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 8px;
  border-radius: var(--radius);
  background: var(--bg-input);
  font-size: 12px;
  font-family: monospace;
}
.app-item-name { color: var(--text); flex: 1; }
.app-item-actions { display: flex; gap: 4px; }

/* ─── Schedule Page ───────────────────────────────────────────────────── */
.schedule-layout {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 20px;
  align-items: start;
}

@media (max-width: 860px) {
  .schedule-layout { grid-template-columns: 1fr; }
}

.schedule-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.schedule-table th {
  text-align: left;
  padding: 10px 12px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  font-weight: 500;
}
.schedule-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border)80;
  vertical-align: middle;
}
.schedule-table tr:last-child td { border-bottom: none; }
.schedule-table .action-col { font-weight: 600; }
.schedule-table .targets-col { font-size: 11px; color: var(--text-muted); font-family: monospace; }

/* ─── Toast Notifications ─────────────────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 9999;
  pointer-events: none;
}

.toast {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  min-width: 260px;
  max-width: 360px;
  box-shadow: var(--shadow);
  pointer-events: auto;
  animation: toast-in 0.2s ease;
  font-size: 13px;
  display: flex;
  align-items: flex-start;
  gap: 8px;
}
.toast.success { border-left: 3px solid var(--success); }
.toast.error   { border-left: 3px solid var(--danger); }
.toast.info    { border-left: 3px solid var(--primary); }

.toast-msg { flex: 1; }
.toast-close {
  cursor: pointer;
  color: var(--text-muted);
  font-size: 16px;
  line-height: 1;
  flex-shrink: 0;
}
.toast-close:hover { color: var(--text); }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ─── Empty State ─────────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
}
.empty-state p { font-size: 15px; }
.empty-state small { font-size: 12px; }

/* ─── Misc ────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
}
.badge-online  { background: #22c55e22; color: var(--success); }
.badge-offline { background: #6b728022; color: var(--text-muted); }

.divider { height: 1px; background: var(--border); margin: 16px 0; }

.text-muted { color: var(--text-muted); }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.mono { font-family: monospace; }

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ─── Responsive ──────────────────────────────────────────────────────── */
@media (max-width: 600px) {
  .page { padding: 16px; }
  .navbar { padding: 0 16px; }
  .device-grid { grid-template-columns: 1fr; }
  .batch-bar { flex-direction: column; align-items: flex-start; }
  .action-grid { grid-template-columns: 1fr 1fr; }
}

/* Target/checkbox list in schedule form */
.target-list {
  max-height: 160px;
  overflow-y: auto;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px;
}
.target-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
  font-size: 13px;
}
.target-item input[type=checkbox] { accent-color: var(--primary); }

.section-full { grid-column: 1 / -1; }
