/* ==========================================================================
   MIROCONTROL SUITE - DESIGN SYSTEM BASE
   Tema: Industrial Moderno (SCADA/HMI UI)
   ========================================================================== */

:root {
  /* Paleta Industrial (Technical Blue & Slate) */
  --color-primary: #0284c7;       /* Azul técnico/SCADA */
  --color-primary-dark: #0369a1;  
  --color-primary-light: #38bdf8; 

  /* Cores de Status (Sinalização Industrial) */
  --color-success: #16a34a;       /* Operação Normal / OK */
  --color-warning: #ea580c;       /* Alerta / Atenção */
  --color-danger:  #dc2626;       /* Crítico / Falha */
  --color-info:    #2563eb;       /* Informativo */

  /* Cores de Fundo (Modo Claro) */
  --bg-primary:   #ffffff;
  --bg-secondary: #f8fafc;
  --bg-tertiary:  #f1f5f9;

  /* Cores de Texto */
  --text-primary:   #0f172a;
  --text-secondary: #475569;
  --text-tertiary:  #94a3b8;

  /* Bordas e Sombras */
  --border-color:  #e2e8f0;
  --border-radius: 8px;
  --border-radius-lg: 12px;
  --border-radius-full: 9999px;

  /* Layout Base */
  --sidebar-width: 240px;
  --sidebar-collapsed-width: 72px;
  --header-height: 64px;

  /* Sombras Modernas (SaaS) */
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.05), 0 2px 4px -2px rgb(0 0 0 / 0.05);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.05), 0 4px 6px -4px rgb(0 0 0 / 0.05);

  /* Transição Global para Tema */
  --theme-transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
}

/* ==========================================================================
   RESETS E TIPOGRAFIA
   ========================================================================== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background-color: var(--bg-secondary);
  color: var(--text-primary);
  transition: var(--theme-transition);
  overflow-x: hidden;
}

/* ==========================================================================
   LAYOUT PRINCIPAL
   ========================================================================== */
.app-container {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* SIDEBAR */
.sidebar {
  width: var(--sidebar-width);
  background-color: var(--bg-primary);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  transition: width 0.3s ease, transform 0.3s ease;
  z-index: 100;
}

.sidebar-header {
  height: var(--header-height);
  display: flex;
  align-items: center;
  padding: 0 1rem;
  border-bottom: 1px solid var(--border-color);
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--text-primary);
}

.sidebar-header span {
  font-weight: 400;
  margin-left: 4px;
}

.sidebar-nav {
  flex: 1;
  padding: 1rem 0;
  overflow-y: auto;
}

.sidebar-item {
  display: flex;
  align-items: center;
  padding: 0.75rem 1.25rem;
  color: var(--text-secondary);
  text-decoration: none;
  font-weight: 500;
  font-size: 0.95rem;
  transition: background-color 0.2s, color 0.2s;
  position: relative;
}

.sidebar-item:hover {
  background-color: var(--bg-tertiary);
  color: var(--text-primary);
}

.sidebar-item.active {
  background-color: var(--color-primary-light);
  color: var(--color-primary-dark);
  border-right: 3px solid var(--color-primary);
}

.sidebar-icon {
  margin-right: 12px;
  font-size: 1.2rem;
}

/* Badge na sidebar para alarmes */
.sidebar-badge {
  margin-left: auto;
  background-color: var(--color-danger);
  color: white;
  font-size: 0.7rem;
  padding: 2px 6px;
  border-radius: 10px;
  font-weight: 700;
}

/* MAIN CONTENT */
.main-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0; /* Impede overflow no flex filho */
}

/* HEADER */
.header {
  height: var(--header-height);
  background-color: var(--bg-primary);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  transition: var(--theme-transition);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.hamburger-btn {
  display: none;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 1.5rem;
  cursor: pointer;
}

.module-title {
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--text-primary);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 1.5rem;
}

.theme-toggle {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 1.2rem;
  cursor: pointer;
  transition: color 0.2s;
}

.theme-toggle:hover {
  color: var(--color-primary);
}

/* CONTEÚDO DA PÁGINA */
.content-area {
  flex: 1;
  padding: 1.5rem;
  overflow-y: auto;
}

/* ==========================================================================
   COMPONENTES GLOBAIS
   ========================================================================== */

/* CARDS DE KPI */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1.5rem;
  margin-bottom: 1.5rem;
}

.kpi-card {
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-lg);
  padding: 16px 20px;
  border-top: 3px solid var(--color-success);
  box-shadow: var(--shadow-sm);
  transition: var(--theme-transition);
}

.kpi-card.warning { border-top-color: var(--color-warning); }
.kpi-card.danger  { border-top-color: var(--color-danger); }
.kpi-card.info    { border-top-color: var(--color-info); }

.kpi-label { 
  font-size: 12px; 
  color: var(--text-secondary); 
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
}

.kpi-value-container {
  display: flex;
  align-items: baseline;
  margin-top: 8px;
  gap: 4px;
}

.kpi-value { 
  font-size: 28px; 
  font-weight: 700; 
  color: var(--text-primary); 
}

.kpi-unit { 
  font-size: 14px; 
  color: var(--text-secondary); 
  font-weight: 500;
}

.kpi-trend { 
  font-size: 12px; 
  margin-top: 8px;
  display: flex;
  align-items: center;
  gap: 4px;
}
.kpi-trend.up { color: var(--color-danger); } /* Em indústrias, subir temp/pressão pode ser ruim. Ajustável por contexto */
.kpi-trend.down { color: var(--color-success); }
.kpi-trend.neutral { color: var(--text-tertiary); }

/* BADGES DE STATUS */
.badge { 
  padding: 4px 10px; 
  border-radius: 20px; 
  font-size: 11px; 
  font-weight: 600; 
  display: inline-block;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.badge-critico   { background: #fee2e2; color: #991b1b; } /* Vermelho forte */
.badge-alerta    { background: #fef9c3; color: #854d0e; } /* Amarelo */
.badge-normal    { background: #dcfce7; color: #166534; } /* Verde */
.badge-info      { background: #dbeafe; color: #1e40af; } /* Azul */
.badge-aberto    { background: #fee2e2; color: #991b1b; border: 1px solid #f87171; } 
.badge-resolvido { background: #dcfce7; color: #166534; border: 1px solid #86efac; } 
.badge-justificado { background: #f3f4f6; color: #475569; border: 1px solid #cbd5e1; } 

/* BOTOES GLOBAIS */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: var(--border-radius);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  border: 1px solid transparent;
  text-decoration: none;
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background-color: var(--color-primary);
  color: white;
}

.btn-primary:hover {
  background-color: var(--color-primary-dark);
  box-shadow: var(--shadow-sm);
}

.btn-outline {
  background-color: transparent;
  border-color: var(--border-color);
  color: var(--text-primary);
}

.btn-outline:hover {
  background-color: var(--bg-tertiary);
}

.btn-icon {
  padding: 8px;
  border-radius: var(--border-radius);
  color: var(--text-secondary);
  background: transparent;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-icon:hover {
  background-color: var(--bg-tertiary);
  color: var(--text-primary);
}

/* SKELETON LOADING */
.skeleton {
  background: linear-gradient(90deg, var(--bg-tertiary) 25%, var(--border-color) 50%, var(--bg-tertiary) 75%);
  background-size: 200% 100%;
  animation: skeleton-loading 1.5s infinite;
  border-radius: 4px;
}

.skeleton-text { height: 16px; margin-bottom: 8px; width: 100%; }
.skeleton-text.short { width: 50%; }
.skeleton-circle { border-radius: 50%; width: 40px; height: 40px; }
.skeleton-chart { height: 250px; width: 100%; border-radius: var(--border-radius-lg); }

@keyframes skeleton-loading {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* GLOBAL NOTIFICATIONS / ALARMS (TOPBAR) */
.notification-dropdown {
  position: relative;
}

.notification-btn {
  position: relative;
}

.notification-badge {
  position: absolute;
  top: 0px;
  right: 0px;
  background-color: var(--color-danger);
  color: white;
  font-size: 10px;
  font-weight: bold;
  height: 16px;
  min-width: 16px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  border: 2px solid var(--bg-primary);
  animation: pulse-danger 2s infinite;
}

@keyframes pulse-danger {
  0% { box-shadow: 0 0 0 0 rgba(220, 38, 38, 0.7); }
  70% { box-shadow: 0 0 0 6px rgba(220, 38, 38, 0); }
  100% { box-shadow: 0 0 0 0 rgba(220, 38, 38, 0); }
}

.notification-panel {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  width: 320px;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-lg);
  box-shadow: var(--shadow-lg);
  display: none;
  flex-direction: column;
  z-index: 1000;
  overflow: hidden;
}

.notification-panel.show {
  display: flex;
  animation: slide-down 0.2s ease forwards;
}

@keyframes slide-down {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}

.notification-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background-color: var(--bg-secondary);
}

.notification-header h3 {
  font-size: 0.9rem;
  font-weight: 700;
  margin: 0;
}

.notification-body {
  max-height: 300px;
  overflow-y: auto;
}

.notification-item {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  gap: 12px;
  cursor: pointer;
  transition: background-color 0.2s;
}

.notification-item:hover {
  background-color: var(--bg-secondary);
}

.notification-item.unread {
  background-color: color-mix(in srgb, var(--color-danger) 5%, var(--bg-primary));
}

.notification-item-icon {
  color: var(--color-danger);
  font-size: 20px;
  margin-top: 2px;
}

.notification-item-content {
  flex: 1;
}

.notification-item-title {
  font-size: 0.85rem;
  font-weight: 600;
  margin: 0 0 4px 0;
  color: var(--text-primary);
}

.notification-item-desc {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin: 0 0 4px 0;
}

.notification-item-time {
  font-size: 0.7rem;
  color: var(--text-tertiary);
}

/* TABELA DE ALARMES / DADOS */
.table-container {
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-lg);
  box-shadow: var(--shadow-sm);
  overflow-x: auto;
  margin-bottom: 1.5rem;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
}

.data-table th, .data-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-color);
}

.data-table th {
  background-color: var(--bg-secondary);
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.data-table tbody tr {
  transition: background-color 0.15s;
}

.data-table tbody tr:hover {
  background-color: var(--bg-tertiary);
}

.data-table tbody tr:last-child td {
  border-bottom: none;
}

/* ==========================================================================
   RESPONSIVIDADE
   ========================================================================== */

/* Tablet: Sidebar colapsável */
@media (max-width: 1024px) {
  .sidebar {
    width: var(--sidebar-collapsed-width);
  }
  
  .sidebar-header .logo-text,
  .sidebar-item .item-text,
  .sidebar-badge {
    display: none;
  }
  
  .sidebar-item {
    justify-content: center;
    padding: 1rem 0;
  }
  
  .sidebar-icon {
    margin-right: 0;
    font-size: 1.4rem;
  }
}

/* Mobile: Drawer */
@media (max-width: 768px) {
  .hamburger-btn {
    display: block;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100%;
    width: var(--sidebar-width);
    transform: translateX(-100%);
    box-shadow: var(--shadow-md);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  /* Restaura os textos no modo mobile drawer */
  .sidebar-header .logo-text,
  .sidebar-item .item-text,
  .sidebar-badge {
    display: inline-block;
  }
  
  .sidebar-item {
    justify-content: flex-start;
    padding: 0.75rem 1.25rem;
  }
  
  .sidebar-icon {
    margin-right: 12px;
  }

  .header {
    padding: 0 1rem;
  }
  
  /* Esconde colunas menos importantes na tabela no mobile */
  .data-table th.hide-mobile, 
  .data-table td.hide-mobile {
    display: none;
  }
}
