@import url('https://fonts.googleapis.com/css2?family=Inter:wght@200;300;400;500;600;700;800;900&display=swap');

/* ============================================================
   VARIABLES Y RESET
   ============================================================ */
:root {
  --bg-primary: #ffffff;
  --bg-secondary: #fafafa;
  --bg-card: #ffffff;
  --bg-hover: #f5f5f5;
  --bg-active: #f0f0f0;
  --bg-input: #fafafa;
  --border: #e5e5e5;
  --border-light: #f0f0f0;
  --border-focus: #000000;
  --text-primary: #0a0a0a;
  --text-secondary: #525252;
  --text-muted: #a3a3a3;
  --text-thin: #737373;
  --accent: #0a0a0a;
  --accent-soft: #404040;
  --success: #16a34a;
  --danger: #dc2626;
  --warning: #d97706;
  --info: #2563eb;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.06);
  --shadow-lg: 0 12px 40px rgba(0,0,0,0.1);
  --transition: all 0.2s ease;
}

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-secondary);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  font-weight: 300;
}

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

::selection {
  background: var(--text-primary);
  color: var(--bg-primary);
}

/* ============================================================
   LOGIN
   ============================================================ */
.login-wrapper {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  background: var(--bg-primary);
}

.login-card {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 48px 44px;
  width: 100%;
  max-width: 400px;
  animation: fadeIn 0.5s ease;
}

.login-card .logo {
  margin-bottom: 40px;
}

.login-card .logo h1 {
  font-size: 2.4rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--text-primary);
}

.login-card .logo p {
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 300;
  margin-top: 4px;
  letter-spacing: 0.02em;
}

/* ============================================================
   FORM ELEMENTS
   ============================================================ */
.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 11px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-primary);
  font-size: 0.9rem;
  font-family: inherit;
  font-weight: 400;
  transition: var(--transition);
  outline: none;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  border-color: var(--border-focus);
  background: var(--bg-primary);
}

.form-group input::placeholder { color: var(--text-muted); font-weight: 300; }

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

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 20px;
  border: 1px solid transparent;
  border-radius: 6px;
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  gap: 6px;
  letter-spacing: 0.01em;
}

.btn-primary {
  background: var(--text-primary);
  color: var(--bg-primary);
  border-color: var(--text-primary);
}

.btn-primary:hover {
  background: var(--accent-soft);
  border-color: var(--accent-soft);
}

.btn-full { width: 100%; }

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

.btn-outline {
  background: transparent;
  color: var(--text-primary);
  border: 1px solid var(--border);
}

.btn-outline:hover { border-color: var(--text-primary); }

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

.btn-ghost:hover { color: var(--text-primary); }

.btn-danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid rgba(220, 38, 38, 0.3);
}

.btn-danger:hover { background: rgba(220, 38, 38, 0.05); }

.btn-success-fill {
  background: var(--success);
  color: #fff;
  border-color: var(--success);
}

.login-error {
  background: rgba(220, 38, 38, 0.05);
  border: 1px solid rgba(220, 38, 38, 0.2);
  color: var(--danger);
  padding: 10px 14px;
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 400;
  margin-bottom: 16px;
  display: none;
}

/* ============================================================
   LAYOUT
   ============================================================ */
.app-layout {
  display: flex;
  min-height: 100vh;
}

/* ============================================================
   SIDEBAR
   ============================================================ */
.sidebar {
  width: 240px;
  background: var(--bg-primary);
  border-right: 1px solid var(--border-light);
  padding: 28px 16px 20px;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
}

.sidebar .brand {
  font-size: 1.4rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--text-primary);
  padding: 0 12px 24px;
  border-bottom: 1px solid var(--border-light);
  margin-bottom: 24px;
}

.sidebar-section-label {
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  padding: 0 12px;
  margin: 20px 0 8px;
}

.sidebar-nav { flex: 1; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 6px;
  color: var(--text-thin);
  font-size: 0.85rem;
  font-weight: 400;
  cursor: pointer;
  transition: var(--transition);
  margin-bottom: 2px;
}

.nav-item:hover { background: var(--bg-hover); color: var(--text-primary); }

.nav-item.active {
  background: var(--bg-active);
  color: var(--text-primary);
  font-weight: 600;
}

.nav-item .nav-icon {
  font-size: 0.85rem;
  width: 20px;
  text-align: center;
  font-weight: 400;
  font-style: normal;
}

.sidebar-footer {
  padding-top: 16px;
  border-top: 1px solid var(--border-light);
}

.user-info {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--text-primary);
  color: var(--bg-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 0.75rem;
}

.user-name { font-size: 0.8rem; font-weight: 600; }
.user-role { font-size: 0.7rem; color: var(--text-muted); font-weight: 300; }

/* ============================================================
   MAIN CONTENT
   ============================================================ */
.main-content {
  flex: 1;
  margin-left: 240px;
  padding: 32px 40px;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-bottom: 32px;
}

.page-header h2 {
  font-size: 1.8rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.1;
}

.page-header .page-sub {
  font-size: 0.85rem;
  font-weight: 300;
  color: var(--text-muted);
  margin-top: 4px;
}

.page-header .header-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

/* ============================================================
   STATUS BADGES
   ============================================================ */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 0.7rem;
  font-weight: 500;
  letter-spacing: 0.02em;
}

.badge-online {
  background: rgba(22, 163, 74, 0.08);
  color: var(--success);
  border: 1px solid rgba(22, 163, 74, 0.2);
}

.badge-offline {
  background: rgba(163, 163, 163, 0.1);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.badge-active { background: rgba(22, 163, 74, 0.08); color: var(--success); }
.badge-inactive { background: rgba(163, 163, 163, 0.1); color: var(--text-muted); }

.pulse-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--success);
  animation: pulse 2s infinite;
}

/* ============================================================
   STAT CARDS
   ============================================================ */
.grid-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 32px;
}

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

.stat-card:hover {
  border-color: var(--border);
  box-shadow: var(--shadow-sm);
}

.stat-label {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  font-weight: 500;
  margin-bottom: 10px;
}

.stat-value {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1;
  color: var(--text-primary);
}

.stat-unit {
  font-size: 0.8rem;
  font-weight: 300;
  color: var(--text-muted);
  margin-left: 2px;
}

.stat-sub {
  font-size: 0.7rem;
  color: var(--text-muted);
  font-weight: 300;
  margin-top: 8px;
}

/* ============================================================
   PANELS
   ============================================================ */
.grid-panels {
  display: grid;
  grid-template-columns: 5fr 3fr;
  gap: 20px;
  margin-bottom: 32px;
}

.grid-panels.grid-3col {
  grid-template-columns: 4fr 3fr 3fr;
}

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

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

.panel-header h3 {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.panel-header .panel-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 300;
}

/* ============================================================
   DATA TABLES
   ============================================================ */
.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table thead th {
  padding: 10px 14px;
  text-align: left;
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  border-bottom: 1px solid var(--border);
}

.data-table tbody td {
  padding: 12px 14px;
  font-size: 0.85rem;
  font-weight: 400;
  border-bottom: 1px solid var(--border-light);
  color: var(--text-secondary);
}

.data-table tbody tr {
  transition: var(--transition);
}

.data-table tbody tr:hover {
  background: var(--bg-hover);
}

.data-table .cell-bold {
  font-weight: 600;
  color: var(--text-primary);
}

.data-table .cell-mono {
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 0.8rem;
  color: var(--text-thin);
}

.data-table .actions-cell {
  display: flex;
  gap: 4px;
  justify-content: flex-end;
}

/* ============================================================
   HELMET LIST (sidebar panel)
   ============================================================ */
.helmet-list { list-style: none; }

.helmet-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  border-radius: 6px;
  cursor: pointer;
  transition: var(--transition);
  margin-bottom: 2px;
}

.helmet-item:hover { background: var(--bg-hover); }
.helmet-item.selected { background: var(--bg-active); }

.helmet-info { display: flex; align-items: center; gap: 10px; }

.helmet-icon {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: var(--bg-active);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--text-secondary);
}

.helmet-name { font-weight: 500; font-size: 0.85rem; }
.helmet-tag { font-size: 0.7rem; color: var(--text-muted); font-weight: 300; }

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.status-dot.online { background: var(--success); box-shadow: 0 0 6px rgba(22, 163, 74, 0.4); }
.status-dot.offline { background: #ef4444; box-shadow: 0 0 6px rgba(239, 68, 68, 0.3); }

/* ============================================================
   CONTROLS
   ============================================================ */
.controls-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 16px;
}

.control-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 14px;
  border-radius: var(--radius);
  background: var(--bg-secondary);
  border: 1px solid var(--border-light);
  color: var(--text-muted);
  cursor: pointer;
  transition: var(--transition);
  gap: 6px;
}

.control-btn:hover { border-color: var(--border); }

.control-btn.active {
  background: var(--text-primary);
  color: var(--bg-primary);
  border-color: var(--text-primary);
}

.control-icon { font-size: 0.85rem; font-weight: 700; }
.control-label { font-size: 0.65rem; font-weight: 500; text-transform: uppercase; letter-spacing: 0.06em; }

/* ============================================================
   CHART
   ============================================================ */
.chart-container {
  position: relative;
  height: 260px;
}

/* ============================================================
   MODAL
   ============================================================ */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(4px);
  z-index: 1000;
  justify-content: center;
  align-items: flex-start;
  padding-top: 10vh;
  animation: fadeIn 0.2s ease;
}

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

.modal {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 500px;
  box-shadow: var(--shadow-lg);
  animation: slideUp 0.3s ease;
  max-height: 80vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 24px 28px 0;
}

.modal-header h3 {
  font-size: 1.1rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

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

.modal-close:hover { border-color: var(--text-primary); color: var(--text-primary); }

.modal-body { padding: 24px 28px; }

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 16px 28px 24px;
}

/* ============================================================
   PAGE SECTIONS
   ============================================================ */
.page-section { display: none; }
.page-section.active { display: block; }

/* ============================================================
   EMPTY STATE
   ============================================================ */
.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-muted);
}

.empty-state p { font-size: 0.85rem; font-weight: 300; }

/* ============================================================
   TOAST
   ============================================================ */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: var(--text-primary);
  color: var(--bg-primary);
  border-radius: 6px;
  padding: 12px 18px;
  font-size: 0.8rem;
  font-weight: 400;
  box-shadow: var(--shadow-lg);
  animation: slideInRight 0.3s ease;
  max-width: 340px;
}

/* ============================================================
   RESPONSIVE
   ============================================================ */

/* Boton hamburguesa (visible solo en mobile) */
.menu-toggle {
  display: none;
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 200;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 1.2rem;
  cursor: pointer;
  box-shadow: var(--shadow-md);
  align-items: center;
  justify-content: center;
}

@media (max-width: 1200px) {
  .grid-stats { grid-template-columns: repeat(3, 1fr); }
  .grid-panels { grid-template-columns: 1fr; }
  .grid-panels.grid-3col { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 768px) {
  .menu-toggle { display: flex; }

  .sidebar {
    position: fixed;
    left: -260px;
    top: 0;
    height: 100vh;
    z-index: 150;
    transition: left 0.3s ease;
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { left: 0; }

  /* Overlay oscuro cuando el sidebar esta abierto */
  .sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.3);
    z-index: 140;
  }
  .sidebar-overlay.open { display: block; }

  .main-content { margin-left: 0; padding: 60px 16px 20px; }
  .grid-stats { grid-template-columns: 1fr 1fr; }
  .grid-panels.grid-3col { grid-template-columns: 1fr; }
  .login-card { margin: 16px; padding: 36px 28px; }
  .form-row { grid-template-columns: 1fr; }

  /* Tablas con scroll horizontal */
  .panel { overflow-x: auto; }
  .data-table { min-width: 600px; }

  /* Modales mas compactos */
  .modal { margin: 16px; max-height: 85vh; overflow-y: auto; }
}

@media (max-width: 480px) {
  .grid-stats { grid-template-columns: 1fr; }
  .stat-value { font-size: 1.6rem; }
  .page-header { flex-direction: column; align-items: flex-start; gap: 8px; }
  .page-header h2 { font-size: 1.2rem; }
  .panel-header { flex-direction: column; align-items: flex-start; gap: 4px; }
}

/* ============================================================
   ANIMATIONS
   ============================================================ */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes slideInRight {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

