/* ========================================================
   SISTEMA DE PLANIFICACIÓN Y DISTRIBUCIÓN DE MALLA
   Tokens Base y Guía de Estilo Minimalista Industrial
   ======================================================== */

:root {
  --bg: #ffffff;
  --surface: #f6f7f9;
  --surface-hover: #edeff2;
  --surface-active: #e2e5e9;
  --text: #111827;
  --muted: #6b7280;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-light: #eff6ff;
  --success: #16a34a;
  --success-light: #f0fdf4;
  --success-border: #bbf7d0;
  --danger: #dc2626;
  --danger-light: #fef2f2;
  --danger-border: #fecaca;
  --warning: #d97706;
  --warning-light: #fffbeb;
  --warning-border: #fde68a;
  
  --radius: 8px;
  --radius-sm: 4px;
  --space: 8px;
  
  --font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-size: 14px;
}

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

body {
  font-family: var(--font-family);
  font-size: var(--font-size);
  color: var(--text);
  background-color: var(--surface);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* App Shell */
.app-container {
  display: flex;
  min-height: 100vh;
  width: 100%;
}

/* Sidebar Navigation */
.sidebar {
  width: 220px;
  background: var(--bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 40;
  user-select: none;
}

.sidebar-header {
  height: 64px;
  padding: 0 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--border);
}

.brand-badge {
  width: 32px;
  height: 32px;
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 16px;
}

.brand-title {
  font-weight: 700;
  font-size: 14px;
  color: var(--text);
  line-height: 1.2;
}

.brand-subtitle {
  font-size: 11px;
  color: var(--muted);
}

.sidebar-nav {
  padding: 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  min-height: 44px;
  border-radius: var(--radius-sm);
  color: var(--muted);
  text-decoration: none;
  font-weight: 500;
  font-size: 14px;
  border: 1px solid transparent;
  background: transparent;
  cursor: pointer;
  width: 100%;
  text-align: left;
  transition: background-color 150ms ease, color 150ms ease;
}

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

.nav-item.active {
  background-color: var(--accent-light);
  color: var(--accent);
  font-weight: 600;
  border-left: 3px solid var(--accent);
}

.nav-icon {
  width: 20px;
  height: 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

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

.status-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--success);
  display: inline-block;
  animation: pulse 2s infinite;
}

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

/* Main Content Area */
.main-wrapper {
  margin-left: 220px;
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  min-height: 100vh;
}

/* Topbar Header */
.topbar {
  height: 64px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 30;
}

.view-title-group {
  display: flex;
  align-items: baseline;
  gap: 12px;
}

.view-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.01em;
}

.view-subtitle {
  font-size: 13px;
  color: var(--muted);
}

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

/* Buttons */
.btn {
  min-height: 44px;
  padding: 0 16px;
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  transition: all 150ms ease;
  white-space: nowrap;
  user-select: none;
}

.btn-sm {
  min-height: 36px;
  padding: 0 12px;
  font-size: 13px;
}

.btn-primary {
  background: var(--accent);
  color: #ffffff;
  border: none;
}

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

.btn-primary:active {
  transform: translateY(1px);
}

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

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

.btn-danger {
  background: var(--danger-light);
  color: var(--danger);
  border: 1px solid var(--danger-border);
}

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

.btn-icon {
  width: 44px;
  height: 44px;
  padding: 0;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.btn-icon:hover {
  background: var(--surface);
}

/* KPI Metrics Bar */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.kpi-card {
  padding: 16px 24px;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.kpi-card:last-child {
  border-right: none;
}

.kpi-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.kpi-value-row {
  display: flex;
  align-items: baseline;
  gap: 6px;
  margin: 6px 0 2px 0;
}

.kpi-value {
  font-size: 26px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
}

.kpi-unit {
  font-size: 13px;
  color: var(--muted);
  font-weight: 500;
}

.kpi-subtext {
  font-size: 12px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 4px;
}

/* Page Body View */
.view-content {
  padding: 24px;
  flex: 1;
}

/* Grid & Calendar Matrix */
.matrix-container {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-x: auto;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.02);
}

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

.matrix-header-day {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  padding: 8px 12px;
  text-align: center;
  font-weight: 700;
  font-size: 13px;
  color: var(--text);
}

.matrix-header-shift {
  background: var(--bg);
  border-bottom: 2px solid var(--border);
  border-right: 1px solid var(--border);
  padding: 6px 8px;
  text-align: center;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
}

.matrix-line-header-row {
  background: #f1f3f6;
  font-weight: 700;
  font-size: 13px;
  color: var(--text);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

.matrix-line-header-cell {
  padding: 8px 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.matrix-machine-cell {
  padding: 8px 16px;
  background: var(--bg);
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  width: 190px;
  vertical-align: middle;
}

.matrix-machine-sub {
  font-size: 11px;
  font-weight: 400;
  color: var(--muted);
  margin-top: 2px;
}

.matrix-slot-cell {
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  padding: 4px;
  vertical-align: top;
  height: 64px;
  width: calc((100% - 190px) / 10);
  background: var(--bg);
  position: relative;
}

.matrix-slot-cell:hover {
  background: #fafbfc;
}

/* SKU Event Blocks */
.schedule-block {
  height: 100%;
  min-height: 54px;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  cursor: pointer;
  transition: transform 120ms ease, box-shadow 120ms ease;
  user-select: none;
  font-size: 11px;
  line-height: 1.25;
}

.schedule-block:hover {
  transform: translateY(-1px);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08);
}

/* Color Archetypes */
.block-rc {
  background-color: #fef3c7;
  border: 1px solid #fde68a;
  color: #92400e;
}

.block-dg {
  background-color: #dcfce7;
  border: 1px solid #bbf7d0;
  color: #166534;
}

.block-ld {
  background-color: #e0f2fe;
  border: 1px solid #bae6fd;
  color: #0369a1;
}

.block-vert {
  background-color: #f3e8ff;
  border: 1px solid #e9d5ff;
  color: #6b21a8;
}

.block-maintenance {
  background-color: #fee2e2;
  border: 1px solid #fca5a5;
  color: #991b1b;
  background-image: repeating-linear-gradient(45deg, rgba(239, 68, 68, 0.1) 0, rgba(239, 68, 68, 0.1) 4px, transparent 0, transparent 8px);
}

.block-empty {
  height: 100%;
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #9ca3af;
  font-size: 11px;
  cursor: pointer;
}

.block-empty:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-light);
}

.block-title {
  font-weight: 700;
  font-size: 11px;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.block-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 10px;
  font-weight: 600;
  margin-top: 4px;
}

.badge-hours {
  padding: 1px 4px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.6);
  font-family: monospace;
}

/* Master Data Tables */
.data-table-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.data-table-toolbar {
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}

.search-input {
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 14px;
  width: 280px;
  max-width: 100%;
}

.search-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-light);
}

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

.data-table th {
  padding: 12px 16px;
  background: var(--surface);
  color: var(--muted);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  border-bottom: 1px solid var(--border);
}

.data-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  vertical-align: middle;
}

.data-table tr:last-child td {
  border-bottom: none;
}

.data-table tr:hover td {
  background: #fbfcfd;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  font-size: 11px;
  font-weight: 600;
}

.badge-success { background: var(--success-light); color: var(--success); }
.badge-warning { background: var(--warning-light); color: var(--warning); }
.badge-danger { background: var(--danger-light); color: var(--danger); }
.badge-neutral { background: var(--surface); color: var(--muted); border: 1px solid var(--border); }
.badge-accent { background: var(--accent-light); color: var(--accent); }

/* Forms & Drawer */
.drawer-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 50;
  opacity: 0;
  pointer-events: none;
  transition: opacity 200ms ease;
}

.drawer-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 520px;
  max-width: 100%;
  background: var(--bg);
  box-shadow: -4px 0 24px rgba(0, 0, 0, 0.12);
  z-index: 51;
  transform: translateX(100%);
  transition: transform 200ms ease;
  display: flex;
  flex-direction: column;
}

.drawer.open {
  transform: translateX(0);
}

.drawer-header {
  height: 64px;
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
}

.drawer-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
}

.drawer-body {
  padding: 24px;
  flex: 1;
  overflow-y: auto;
}

.drawer-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  background: var(--surface);
}

.form-group {
  margin-bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

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

.form-help {
  font-size: 12px;
  color: var(--muted);
}

.form-control {
  height: 44px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  width: 100%;
}

.form-control:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-light);
}

/* Toast Alerts */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  background: #1f2937;
  color: #fff;
  padding: 12px 18px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  display: flex;
  align-items: center;
  gap: 8px;
  animation: slideUp 200ms ease;
  pointer-events: auto;
}

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

/* Filter Strip */
.filter-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 16px;
}

.filter-group {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* Legend */
.legend-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px;
  padding: 12px 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-top: 16px;
  font-size: 12px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.legend-chip {
  width: 14px;
  height: 14px;
  border-radius: 3px;
}

/* Helper Elements */
.mobile-user-nav {
  display: none !important;
}

.mobile-swipe-hint {
  display: none;
}

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

.week-btn-text {
  display: inline;
}

/* ==========================================
   NAVEGACIÓN SEMANAL Y CONTROL DE HISTÓRICO
   ========================================== */
.week-navigator {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 4px;
  border-radius: var(--radius);
}

.week-nav-btn {
  height: 36px;
  padding: 0 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  transition: all 120ms ease;
  user-select: none;
}

.week-nav-btn:hover {
  background: var(--surface-hover);
  border-color: var(--border-strong);
}

.week-nav-btn:active {
  transform: translateY(1px);
}

.week-select {
  height: 36px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
}

.week-select:focus {
  outline: none;
  border-color: var(--accent);
}

.week-alert-banner {
  padding: 12px 16px;
  background: var(--accent-light);
  border: 1px solid #bfdbfe;
  border-radius: var(--radius);
  margin-bottom: 16px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
  color: #1e40af;
}

.historical-badge-pill {
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

/* ==========================================
   PANTALLA DE LOGIN MINIMALISTA
   ========================================== */
.login-overlay {
  position: fixed;
  inset: 0;
  background-color: var(--surface);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px 24px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.06);
}

.login-header {
  text-align: center;
  margin-bottom: 24px;
}

.login-logo {
  width: 44px;
  height: 44px;
  background: var(--accent);
  color: #ffffff;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 20px;
  margin-bottom: 12px;
}

.login-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 4px;
}

.login-subtitle {
  font-size: 13px;
  color: var(--muted);
}

.login-error {
  background: var(--danger-light);
  border: 1px solid var(--danger-border);
  color: var(--danger);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  margin-bottom: 16px;
  display: none;
}

.user-profile-badge {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 12px;
  margin-top: 8px;
}

.user-email-text {
  font-weight: 600;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.btn-logout {
  background: transparent;
  border: none;
  color: var(--danger);
  cursor: pointer;
  padding: 4px;
  display: inline-flex;
  align-items: center;
  border-radius: var(--radius-sm);
}

.btn-logout:hover {
  background: var(--danger-light);
}

/* ========================================================
   DISEÑO RESPONSIVE PARA DISPOSITIVOS MÓVILES (<= 768px)
   Totalmente optimizado para pantallas de 360px a 768px.
   No modifica la experiencia ni visualización de PC.
   ======================================================== */
@media (max-width: 768px) {
  /* 1. Barra de Navegación Inferior Móvil (Bottom Navigation) */
  .sidebar {
    width: 100%;
    height: 60px;
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    flex-direction: row;
    border-right: none;
    border-top: 1px solid var(--border);
    padding: 0 4px;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: var(--bg);
    z-index: 50;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
  }

  .sidebar-header,
  .sidebar-footer {
    display: none !important;
  }

  .sidebar-nav {
    flex-direction: row;
    padding: 0 2px;
    align-items: center;
    justify-content: flex-start;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    gap: 2px;
    height: 100%;
    width: 100%;
  }

  .sidebar-nav::-webkit-scrollbar {
    display: none;
  }

  .nav-item {
    flex: 0 0 auto;
    min-width: 62px;
    max-width: 76px;
    min-height: 48px;
    height: 52px;
    padding: 4px 6px;
    font-size: 10px;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    border-left: none;
    border-bottom: 2px solid transparent;
    border-radius: var(--radius-sm);
    white-space: nowrap;
    text-align: center;
  }

  .nav-item .nav-icon {
    width: 18px;
    height: 18px;
  }

  .nav-item.active {
    border-left: none;
    border-bottom: 3px solid var(--accent);
    background-color: var(--accent-light);
    color: var(--accent);
    font-weight: 700;
  }

  /* 2. Área Principal de Contenido */
  .main-wrapper {
    margin-left: 0 !important;
    margin-bottom: 0 !important;
    min-width: 0;
    width: 100%;
  }

  .view-content {
    padding: 12px;
    padding-bottom: 84px; /* Espacio libre para la barra de navegación inferior */
  }

  /* 3. Encabezado Superior (Topbar) */
  .topbar {
    height: auto;
    min-height: 56px;
    padding: 8px 12px;
    gap: 8px;
    flex-wrap: wrap;
    position: sticky;
    top: 0;
    z-index: 40;
  }

  .view-title-group {
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
  }

  .view-title {
    font-size: 18px;
    line-height: 1.2;
  }

  .view-subtitle {
    font-size: 11px;
  }

  .topbar-actions-wrapper {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
  }

  .topbar-actions .btn {
    min-height: 38px;
    padding: 0 12px;
    font-size: 13px;
  }

  .mobile-user-nav {
    display: flex !important;
    align-items: center;
  }

  .btn-logout-mobile {
    width: 38px;
    height: 38px;
    background: var(--danger-light);
    color: var(--danger);
    border: 1px solid var(--danger-border);
    border-radius: var(--radius-sm);
  }

  /* 4. Métricas / KPIs */
  .kpi-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .kpi-card {
    padding: 10px 14px;
    border-right: 1px solid var(--border);
  }

  .kpi-card:nth-child(2),
  .kpi-card:nth-child(4) {
    border-right: none;
  }

  .kpi-card:nth-child(1),
  .kpi-card:nth-child(2) {
    border-bottom: 1px solid var(--border);
  }

  .kpi-label {
    font-size: 10px;
  }

  .kpi-value {
    font-size: 19px;
  }

  .kpi-unit {
    font-size: 11px;
  }

  .kpi-subtext {
    font-size: 10px;
  }

  /* 5. Barra de Filtros y Navegador de Semanas */
  .filter-strip {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    padding: 10px 12px;
  }

  .week-navigator {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 4px;
    padding: 4px;
  }

  .week-nav-btn {
    min-width: 36px;
    padding: 0 8px;
    justify-content: center;
  }

  .week-btn-text {
    display: none;
  }

  .week-select {
    flex: 1;
    min-width: 0;
    font-size: 12px;
    padding: 0 6px;
  }

  .filter-group {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    flex-wrap: wrap;
  }

  .filter-group .form-control {
    flex: 1;
    min-width: 120px;
  }

  .week-alert-banner {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .week-alert-banner > div:last-child {
    display: flex;
    gap: 8px;
    width: 100%;
  }

  .week-alert-banner > div:last-child .btn {
    flex: 1;
  }

  /* 6. Transformación de Tablas a Tarjetas en Móvil (Design Guideline 7) */
  .data-table:not(.matrix-table) thead {
    display: none;
  }

  .data-table:not(.matrix-table) tbody,
  .data-table:not(.matrix-table) tr,
  .data-table:not(.matrix-table) td {
    display: block;
    width: 100%;
  }

  .data-table:not(.matrix-table) tr {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 12px;
    padding: 12px 14px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.03);
  }

  .data-table:not(.matrix-table) td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 7px 0;
    border-bottom: 1px dashed var(--border);
    font-size: 13px;
    text-align: right;
  }

  .data-table:not(.matrix-table) td:last-child {
    border-bottom: none;
    padding-top: 10px;
    justify-content: flex-end;
  }

  .data-table:not(.matrix-table) td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--muted);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    margin-right: 12px;
    text-align: left;
    flex-shrink: 0;
  }

  .data-table-toolbar {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    padding: 12px 14px;
  }

  .search-input {
    width: 100%;
  }

  /* 7. Malla de Turnos (Matriz con Sticky First Column y Swipe Hint) */
  .mobile-swipe-hint {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 7px 12px;
    margin-bottom: 8px;
    background: var(--surface);
    border: 1px dashed var(--border-strong);
    border-radius: var(--radius-sm);
    font-size: 11px;
    color: var(--muted);
    font-weight: 500;
  }

  .matrix-container {
    -webkit-overflow-scrolling: touch;
    border-radius: var(--radius);
  }

  .matrix-table thead tr th:first-child,
  .matrix-table tbody tr .matrix-machine-cell {
    position: sticky;
    left: 0;
    z-index: 5;
    background: var(--bg);
    box-shadow: 2px 0 6px rgba(0, 0, 0, 0.06);
  }

  .matrix-line-header-row .matrix-line-header-cell {
    position: sticky;
    left: 0;
  }

  /* 8. Modal Lateral (Drawer) Convertido a Bottom-Sheet Móvil */
  .drawer {
    width: 100%;
    max-width: 100%;
    top: auto;
    bottom: 0;
    height: 88vh;
    border-radius: 16px 16px 0 0;
    transform: translateY(100%);
    box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.15);
  }

  .drawer.open {
    transform: translateY(0);
  }

  .drawer-header {
    height: 54px;
    padding: 0 16px;
  }

  .drawer-body {
    padding: 16px;
  }

  .drawer-footer {
    padding: 12px 16px;
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  }

  /* 9. Notificaciones Toast en Móvil */
  .toast-container {
    bottom: 70px;
    left: 12px;
    right: 12px;
    align-items: center;
  }

  .toast {
    width: 100%;
    max-width: 360px;
    justify-content: center;
    font-size: 12px;
    padding: 10px 14px;
  }
}

/* Pantallas Extra Pequeñas (<= 360px) */
@media (max-width: 360px) {
  .kpi-grid {
    grid-template-columns: 1fr;
  }
  .kpi-card {
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .kpi-card:last-child {
    border-bottom: none;
  }
  .nav-item {
    min-width: 54px;
    font-size: 9px;
  }
}


