:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --text-muted: #64748b;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-soft: #eff6ff;
  --success: #059669;
  --success-soft: #ecfdf5;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --warning: #d97706;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow: 0 4px 24px rgba(15, 23, 42, 0.08);
  --radius: 12px;
  --radius-lg: 16px;
  --sidebar-w: 240px;
  --font: "Plus Jakarta Sans", system-ui, sans-serif;
  --mono: ui-monospace, "JetBrains Mono", monospace;
}

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

html { scroll-behavior: smooth; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

.hidden { display: none !important; }

.mono { font-family: var(--mono); font-size: 0.8125rem; color: var(--text-muted); }

.muted { color: var(--text-muted); font-size: 0.875rem; }

.subtitle { color: var(--text-muted); font-size: 0.875rem; margin-top: 2px; }

code {
  font-family: var(--mono);
  font-size: 0.8125rem;
  background: var(--surface-2);
  padding: 2px 6px;
  border-radius: 4px;
  border: 1px solid var(--border);
}

/* Login */
.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: linear-gradient(145deg, #eff6ff 0%, #f8fafc 50%, #f1f5f9 100%);
}

.login-panel {
  width: min(100%, 400px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 36px 32px;
}

.login-brand { text-align: center; margin-bottom: 28px; }
.login-brand h1 { font-size: 1.5rem; font-weight: 700; margin: 12px 0 4px; }
.login-brand p { color: var(--text-muted); font-size: 0.9375rem; }

.logo-mark {
  width: 48px; height: 48px;
  margin: 0 auto;
  background: var(--primary);
  color: #fff;
  border-radius: 14px;
  display: grid; place-items: center;
  font-weight: 700; font-size: 1rem;
}
.logo-mark.sm { width: 36px; height: 36px; border-radius: 10px; font-size: 0.75rem; margin: 0; }

.login-form label { display: block; font-size: 0.8125rem; font-weight: 600; margin-bottom: 6px; color: var(--text-muted); }
.login-form input {
  width: 100%; padding: 12px 14px; margin-bottom: 16px;
  border: 1px solid var(--border); border-radius: var(--radius);
  font: inherit; background: var(--surface);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.login-form input:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.form-error { color: var(--danger); font-size: 0.875rem; text-align: center; }

/* Shell */
.shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 100;
  transition: transform 0.25s ease;
}

.sidebar-brand {
  display: flex; align-items: center; gap: 10px;
  padding: 20px 18px;
  font-weight: 700;
  border-bottom: 1px solid var(--border);
}

.sidebar-nav { flex: 1; padding: 12px 10px; display: flex; flex-direction: column; gap: 4px; }
.sidebar-foot { padding: 12px 10px 20px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 4px; }

.nav-item {
  display: block; width: 100%; text-align: left;
  padding: 10px 14px; border: none; border-radius: var(--radius);
  background: transparent; color: var(--text-muted);
  font: inherit; font-weight: 500; font-size: 0.9375rem;
  cursor: pointer; text-decoration: none;
  transition: background 0.15s, color 0.15s;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.nav-item.danger { color: var(--danger); }
.nav-item.link { color: var(--text-muted); }

.shell-main {
  flex: 1;
  margin-left: var(--sidebar-w);
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 16px 24px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  flex-wrap: wrap;
  position: sticky; top: 0; z-index: 50;
}

.topbar-left { display: flex; align-items: center; gap: 12px; }
.topbar-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.topbar h2 { font-size: 1.125rem; font-weight: 700; }

.mobile-menu { display: none; }

.content { padding: 24px; flex: 1; }

.view { display: none; }
.view.active { display: block; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 16px; border-radius: var(--radius);
  font: inherit; font-weight: 600; font-size: 0.875rem;
  border: 1px solid transparent; cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
  white-space: nowrap;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

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

.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-secondary:hover:not(:disabled) { background: var(--surface-2); border-color: var(--border-strong); }

.btn-danger { background: var(--danger-soft); color: var(--danger); border-color: #fecaca; }
.btn-danger:hover:not(:disabled) { background: #fee2e2; }

.btn-ghost { background: transparent; color: var(--text-muted); border: none; padding: 6px 10px; }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }

.btn-sm { padding: 6px 12px; font-size: 0.8125rem; }
.btn-lg { width: 100%; padding: 13px; font-size: 1rem; }

.icon-btn {
  width: 36px; height: 36px; border: 1px solid var(--border);
  border-radius: var(--radius); background: var(--surface);
  cursor: pointer; font-size: 1.125rem; color: var(--text-muted);
  display: grid; place-items: center;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

.field-select {
  padding: 9px 12px; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--surface);
  font: inherit; font-size: 0.875rem; min-width: 180px;
}

.badge {
  font-size: 0.75rem; font-weight: 600; padding: 4px 10px;
  border-radius: 999px; border: 1px solid var(--border);
}
.badge-muted { background: var(--surface-2); color: var(--text-muted); }
.badge-ok { background: var(--success-soft); color: var(--success); border-color: #a7f3d0; }

/* Panels */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.panel-head h4 { font-size: 0.9375rem; font-weight: 600; }

.view-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; margin-bottom: 16px; flex-wrap: wrap;
}

/* Dashboard */
.dash-hero {
  display: flex; align-items: center; justify-content: space-between;
  gap: 24px; padding: 24px; margin-bottom: 20px; flex-wrap: wrap;
}

.dash-hero h3 { font-size: 1.5rem; font-weight: 700; margin: 4px 0; }
.eyebrow { font-size: 0.75rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; color: var(--primary); }

.tag-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.tag {
  font-size: 0.75rem; font-weight: 500; padding: 4px 10px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px;
  color: var(--text-muted);
}

.fuel-ring-wrap { position: relative; width: 120px; height: 120px; flex-shrink: 0; }
.fuel-ring { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring-bg { fill: none; stroke: var(--border); stroke-width: 8; }
.ring-fill { fill: none; stroke: var(--primary); stroke-width: 8; stroke-linecap: round; stroke-dasharray: 327; stroke-dashoffset: 327; transition: stroke-dashoffset 0.6s ease; }
.fuel-label {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  font-weight: 700; font-size: 1.25rem;
}
.fuel-label small { font-size: 0.6875rem; font-weight: 500; color: var(--text-muted); }

.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px; margin-bottom: 20px;
}

.metric {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 16px 18px;
  box-shadow: var(--shadow-sm);
}
.metric-label { font-size: 0.75rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 6px; }
.metric-value { font-size: 1.375rem; font-weight: 700; letter-spacing: -0.02em; }
.metric-sub { font-size: 0.8125rem; color: var(--text-muted); margin-top: 2px; }

.split-grid {
  display: grid; grid-template-columns: 1.2fr 0.8fr;
  gap: 16px; margin-bottom: 16px;
}

.map-box { height: 280px; background: var(--surface-2); }
.map-box:empty::after { content: "No location available"; display: grid; place-items: center; height: 100%; color: var(--text-muted); font-size: 0.875rem; }

.cmd-panel { padding: 16px 20px 8px; }

.cmd-row {
  display: flex; gap: 10px; align-items: stretch;
}
.cmd-row .input { flex: 1; min-width: 0; }
.cmd-row .btn { flex-shrink: 0; white-space: nowrap; }

#commands-empty { padding: 8px 0 12px; font-size: 0.875rem; }

.alert {
  margin: 0 20px 16px; padding: 12px 14px; border-radius: var(--radius);
  font-size: 0.875rem; border: 1px solid;
}
.alert.success { background: var(--success-soft); border-color: #a7f3d0; color: var(--success); }
.alert.error { background: var(--danger-soft); border-color: #fecaca; color: var(--danger); }

.detail-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 1px; background: var(--border); padding: 0;
}
.detail-grid dl { background: var(--surface); padding: 14px 18px; }
.detail-grid dt { font-size: 0.6875rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted); margin-bottom: 4px; }
.detail-grid dd { font-size: 0.9375rem; font-weight: 500; }

/* Tables */
.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
.data-table th {
  text-align: left; padding: 12px 16px; font-weight: 600; font-size: 0.75rem;
  text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted);
  background: var(--surface-2); border-bottom: 1px solid var(--border);
}
.data-table td { padding: 14px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: #fafbfc; }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }

.empty-state {
  text-align: center; padding: 64px 24px;
  background: var(--surface); border: 1px dashed var(--border-strong);
  border-radius: var(--radius-lg);
}
.empty-state h3 { margin-bottom: 8px; }
.empty-state p { color: var(--text-muted); margin-bottom: 20px; max-width: 360px; margin-inline: auto; }

/* Modal */
.modal { position: fixed; inset: 0; z-index: 200; display: grid; place-items: center; padding: 20px; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(15, 23, 42, 0.4); backdrop-filter: blur(2px); }
.modal-card {
  position: relative; width: min(100%, 480px); max-height: 90vh; overflow: auto;
  background: var(--surface); border-radius: var(--radius-lg);
  box-shadow: var(--shadow); border: 1px solid var(--border);
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 20px; border-bottom: 1px solid var(--border);
}
.modal-head h3 { font-size: 1.0625rem; font-weight: 700; }
.modal-body { padding: 20px; }

.form-stack { display: flex; flex-direction: column; gap: 14px; }
.form-stack label { display: flex; flex-direction: column; gap: 6px; font-size: 0.8125rem; font-weight: 600; color: var(--text-muted); }
.form-stack input, .form-stack select {
  padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius);
  font: inherit; background: var(--surface);
}
.form-stack input:focus, .form-stack select:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}
.form-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 8px; padding-top: 16px; border-top: 1px solid var(--border); }

.discover-list { list-style: none; margin: 12px 0; max-height: 200px; overflow: auto; border: 1px solid var(--border); border-radius: var(--radius); }
.discover-list li { padding: 10px 12px; border-bottom: 1px solid var(--border); font-size: 0.875rem; cursor: pointer; }
.discover-list li:hover { background: var(--primary-soft); }
.discover-list li:last-child { border-bottom: none; }

.key-reveal {
  margin-top: 12px; padding: 12px; background: var(--warning-soft, #fffbeb);
  border: 1px solid #fde68a; border-radius: var(--radius);
  font-family: var(--mono); font-size: 0.75rem; word-break: break-all;
}

/* Toasts */
.toasts {
  position: fixed; bottom: 20px; right: 20px; z-index: 300;
  display: flex; flex-direction: column; gap: 8px; max-width: min(360px, calc(100vw - 40px));
}
.toast {
  padding: 12px 16px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--border);
  box-shadow: var(--shadow); font-size: 0.875rem; font-weight: 500;
  animation: slideIn 0.25s ease;
}
.toast.success { border-left: 3px solid var(--success); }
.toast.error { border-left: 3px solid var(--danger); }

@keyframes slideIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.inline-loader {
  position: fixed; top: 12px; right: 12px; z-index: 250;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 999px; padding: 8px 12px; box-shadow: var(--shadow);
  display: flex; align-items: center; gap: 8px; font-size: 0.8125rem; color: var(--text-muted);
}

.spinner {
  width: 16px; height: 16px; border: 2px solid var(--border);
  border-top-color: var(--primary); border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.leaflet-container { font-family: var(--font); z-index: 1; }

/* Responsive */
@media (max-width: 900px) {
  .split-grid { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
    box-shadow: var(--shadow);
  }
  .sidebar.open { transform: translateX(0); }
  .shell-main { margin-left: 0; }
  .mobile-menu { display: grid; }
  .content { padding: 16px; }
  .topbar { padding: 12px 16px; }
  .field-select { min-width: 140px; }
  .dash-hero { flex-direction: column; align-items: flex-start; }
}

@media (max-width: 480px) {
  .topbar-right { width: 100%; }
  .field-select { flex: 1; min-width: 0; }
  .row-actions { flex-direction: column; }
}
