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

:root {
  --primary: #E53935;
  --primary-dark: #C62828;
  --primary-light: #EF5350;
  --bg: #09090b;
  --surface: #0f0f12;
  --surface-2: #18181b;
  --text: #fafafa;
  --text-muted: #a1a1aa;
  --border: #27272a;
  --success: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;
  --radius: 6px;
  --shadow: 0 4px 12px rgba(0,0,0,0.3);
}

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

#app-screen {
  display: flex;
  min-height: 100vh;
  width: 100%;
}

#auth-screen.hidden,
#app-screen.hidden {
  display: none !important;
}

.sidebar {
  width: 240px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
  transition: transform 0.3s;
}

.sidebar-header {
  padding: 20px;
  border-bottom: 1px solid var(--border);
}

.sidebar-header h2 {
  font-size: 18px;
  color: var(--primary-light);
  display: flex;
  align-items: center;
  gap: 10px;
}

.sidebar-brand-icon {
  width: 28px;
  height: 28px;
  background: var(--primary);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.sidebar-header span {
  font-size: 12px;
  color: var(--text-muted);
}

.sidebar-nav {
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: var(--radius);
  color: var(--text-muted);
  text-decoration: none;
  font-size: 14px;
  transition: all 0.2s;
  cursor: pointer;
  border-left: 3px solid transparent;
}

.nav-item svg {
  flex-shrink: 0;
  opacity: 0.65;
  transition: opacity 0.2s;
}

.nav-item:hover {
  background: var(--surface-2);
  color: var(--text);
}

.nav-item:hover svg {
  opacity: 1;
}

.nav-item.active {
  background: rgba(229, 57, 53, 0.12);
  color: var(--primary-light);
  border-left-color: var(--primary);
  font-weight: 500;
}

.nav-item.active svg {
  opacity: 1;
}

.nav-item-privacy {
  margin-top: 8px;
  border-top: 1px solid var(--border);
  padding-top: 12px;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.main-content {
  flex: 1;
  margin-left: 240px;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

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

.menu-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--text);
  font-size: 24px;
  cursor: pointer;
}

.topbar h1 {
  font-size: 18px;
  font-weight: 600;
  flex: 1;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.status-badge {
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 12px;
  background: var(--success);
  color: #fff;
}

.content {
  padding: 40px;
  flex: 1;
  width: 100%;
  max-width: 1000px;
  margin: 0;
}

.loading {
  text-align: center;
  padding: 60px;
  color: var(--text-muted);
}

.section {
  display: block;
}

.card {
  background: transparent;
  border: none;
  padding: 0;
  margin-bottom: 48px;
}

.card h3 {
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 24px;
  color: var(--text);
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

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

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

.form-group input,
.form-group textarea,
.form-group select {
  width: 100%;
  padding: 12px 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: all 0.2s;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 1px var(--primary);
}

.upload-group {
  display: flex;
  gap: 8px;
}

.upload-group input[type="text"] {
  flex: 1;
}

.btn-secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--border);
}

.d-none {
  display: none !important;
}

.form-group textarea {
  min-height: 80px;
  resize: vertical;
  font-family: monospace;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.btn {
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

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

.btn-primary:hover {
  background: var(--primary-dark);
}

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

.btn-danger:hover {
  opacity: 0.9;
}

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

.list-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.list-header h3 {
  font-size: 20px;
  font-weight: 600;
  color: var(--text);
  margin: 0;
}

.list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 12px;
  gap: 12px;
  transition: all 0.2s;
}

.list-item:hover {
  border-color: var(--primary);
}

.list-item-info {
  flex: 1;
}

.list-item-info .title {
  font-size: 14px;
  font-weight: 500;
}

.list-item-info .subtitle {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.list-item-actions {
  display: flex;
  gap: 8px;
}

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

.modal-overlay.open {
  display: flex;
}

.modal {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px;
  width: 90%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
}

.modal h3 {
  margin-bottom: 16px;
}

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

.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 12px 20px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 14px;
  z-index: 300;
  opacity: 0;
  transform: translateY(20px);
  transition: all 0.3s;
  box-shadow: var(--shadow);
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.toast.success { border-color: var(--success); }
.toast.error { border-color: var(--danger); }

.color-picker-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.color-picker-row input[type="color"] {
  width: 48px;
  height: 40px;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
  cursor: pointer;
}

.color-picker-row input[type="text"] {
  flex: 1;
}

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

#auth-screen {
  display: flex;
  width: 100%;
  min-height: 100vh;
}

.auth-container {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  width: 100%;
  padding: 24px;
}

.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px;
  width: 100%;
  max-width: 400px;
}

.auth-card h2 {
  font-size: 22px;
  color: var(--primary-light);
  margin-bottom: 4px;
}

.auth-card p {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 24px;
}

.auth-error {
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid var(--danger);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 13px;
  color: var(--danger);
  margin-bottom: 16px;
}

.btn-block {
  width: 100%;
  margin-top: 8px;
}

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-muted);
  margin-top: auto;
}

@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .main-content {
    margin-left: 0;
  }
  .menu-toggle {
    display: block;
  }
  .form-row {
    grid-template-columns: 1fr;
  }
}

.stats-hero {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 28px;
  flex-wrap: wrap;
  gap: 16px;
}

.stats-hero-text h2 {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  margin: 0 0 4px 0;
}

.stats-hero-text p {
  font-size: 13px;
  color: var(--text-muted);
  margin: 0;
}

.stats-hero-badge {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  padding: 6px 14px;
  border-radius: 20px;
  background: rgba(229, 57, 53, 0.12);
  color: var(--primary-light);
  border: 1px solid rgba(229, 57, 53, 0.25);
  white-space: nowrap;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  position: relative;
  overflow: hidden;
  transition: border-color 0.2s, transform 0.15s;
}

.kpi-card:hover {
  border-color: rgba(229, 57, 53, 0.3);
  transform: translateY(-1px);
}

.kpi-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 3px;
}

.kpi-card.accent-red::before { background: #E53935; }
.kpi-card.accent-green::before { background: #10b981; }
.kpi-card.accent-blue::before { background: #3b82f6; }
.kpi-card.accent-amber::before { background: #f59e0b; }

.kpi-icon {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 12px;
}

.kpi-card.accent-red .kpi-icon { background: rgba(229, 57, 53, 0.15); color: #EF5350; }
.kpi-card.accent-green .kpi-icon { background: rgba(16, 185, 129, 0.15); color: #10b981; }
.kpi-card.accent-blue .kpi-icon { background: rgba(59, 130, 246, 0.15); color: #60a5fa; }
.kpi-card.accent-amber .kpi-icon { background: rgba(245, 158, 11, 0.15); color: #fbbf24; }

.kpi-value {
  font-size: 30px;
  font-weight: 800;
  color: var(--text);
  line-height: 1.1;
  margin-bottom: 4px;
  letter-spacing: -0.5px;
}

.kpi-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  margin-bottom: 8px;
}

.kpi-sub {
  font-size: 11px;
  color: var(--text-muted);
  opacity: 0.7;
}

.charts-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}

.card-chart {
  min-height: 340px;
}

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

.card-header h3 {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  margin: 0;
}

.card-badge {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 3px 10px;
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.chart-wrap {
  position: relative;
  width: 100%;
  max-height: 280px;
}

.chart-wrap canvas {
  max-height: 280px;
}

.manufacturer-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
}

.mfg-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
}

.mfg-count {
  font-size: 22px;
  font-weight: 700;
  color: var(--primary-light);
  line-height: 1.1;
}

.mfg-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  margin: 4px 0 10px 0;
}

.mfg-bar {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 4px;
}

.mfg-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--primary-light));
  border-radius: 2px;
  transition: width 0.6s ease;
}

.mfg-pct {
  font-size: 11px;
  color: var(--text-muted);
  text-align: right;
}

.locations-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 10px;
}

.location-pin-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  transition: border-color 0.15s;
}

.location-pin-card:hover {
  border-color: rgba(229, 57, 53, 0.25);
}

.pin-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.pin-icon {
  font-size: 16px;
}

.pin-device {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.pin-coords {
  font-size: 12px;
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  color: var(--primary-light);
  margin-bottom: 4px;
}

.pin-time {
  font-size: 11px;
  color: var(--text-muted);
}

.empty-state-card {
  background: var(--surface-2);
  border: 1px dashed var(--border);
  border-radius: 8px;
  padding: 32px 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}

.activity-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.activity-dot.active { background: #10b981; box-shadow: 0 0 6px rgba(16, 185, 129, 0.4); }
.activity-dot.inactive { background: #52525b; }

.card-table .card-header {
  margin-bottom: 4px;
}

.stats-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 24px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-muted);
  flex-wrap: wrap;
  gap: 8px;
}

.stats-footer code {
  background: var(--surface-2);
  padding: 2px 6px;
  border-radius: 3px;
  font-size: 11px;
  color: var(--primary-light);
}

.area-stats .card {
  margin-bottom: 16px;
}

.error {
  color: var(--danger);
  font-size: 14px;
}

@media (max-width: 768px) {
  .charts-row {
    grid-template-columns: 1fr;
  }
  .kpi-grid {
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  }
  .manufacturer-grid {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  }
  .locations-grid {
    grid-template-columns: 1fr;
  }
}

.table-responsive {
  overflow-x: auto;
  margin-top: 12px;
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.table th {
  text-align: left;
  padding: 10px 8px;
  border-bottom: 2px solid var(--border);
  color: var(--text-muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.table td {
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}

.table tr:hover td {
  background: var(--surface-2);
}

code {
  background: var(--surface-2);
  padding: 2px 6px;
  border-radius: 3px;
  font-size: 12px;
  color: var(--primary-light);
}
