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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #f5f7fa;
  color: #1a202c;
  min-height: 100vh;
}

/* === LOADING === */
#loading-screen {
  position: fixed;
  inset: 0;
  background: linear-gradient(135deg, #0f4c81, #1a73a8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  color: white;
}
.loading-content { text-align: center; }
.loading-content img {
  width: 100px; height: 100px;
  border-radius: 20px;
  background: white;
  padding: 8px;
  margin-bottom: 20px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.3);
}
.loading-content h2 { font-size: 24px; margin-bottom: 8px; }
.loading-content p { opacity: 0.9; margin-bottom: 20px; }
.spinner {
  width: 40px; height: 40px;
  border: 4px solid rgba(255,255,255,0.3);
  border-top-color: white;
  border-radius: 50%;
  margin: 0 auto;
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* === TOPBAR === */
.topbar {
  background: linear-gradient(135deg, #0f4c81 0%, #1a73a8 100%);
  color: white;
  padding: 14px 24px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
}
.topbar-brand { display: flex; align-items: center; gap: 12px; }
.topbar-logo {
  width: 44px; height: 44px;
  border-radius: 8px;
  background: white;
  padding: 4px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}
.topbar-text h1 { font-size: 18px; font-weight: 700; line-height: 1.2; }
.topbar-text small { opacity: 0.85; font-weight: 400; font-size: 12px; }
.user-info { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.user-info select {
  padding: 6px 10px; border-radius: 6px; border: none;
  background: rgba(255,255,255,0.15); color: white; cursor: pointer;
}
.user-info select option { color: #1a202c; }
.conn-status {
  background: rgba(56,161,105,0.3);
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
}
.conn-status.offline {
  background: rgba(229,62,62,0.3);
}

/* === TABS === */
.tabs {
  background: white;
  display: flex;
  border-bottom: 1px solid #e2e8f0;
  overflow-x: auto;
  padding: 0 16px;
  position: sticky; top: 0; z-index: 50;
}
.tab {
  padding: 14px 20px;
  cursor: pointer;
  border: none;
  background: none;
  font-size: 14px;
  color: #4a5568;
  font-weight: 500;
  border-bottom: 3px solid transparent;
  transition: all 0.2s;
  white-space: nowrap;
}
.tab:hover { color: #0f4c81; }
.tab.active { color: #0f4c81; border-bottom-color: #0f4c81; }

.container { padding: 24px; max-width: 1400px; margin: 0 auto; }
.view { display: none; }
.view.active { display: block; }

/* === STAT CARDS === */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  background: white;
  padding: 20px;
  border-radius: 10px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
  border-left: 4px solid #0f4c81;
}
.stat-card.warn { border-left-color: #e53e3e; }
.stat-card.ok { border-left-color: #38a169; }
.stat-card.info { border-left-color: #d69e2e; }
.stat-label { font-size: 12px; color: #718096; text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 8px; }
.stat-value { font-size: 28px; font-weight: 700; color: #1a202c; }
.stat-sub { font-size: 12px; color: #718096; margin-top: 4px; }

.panel {
  background: white;
  border-radius: 10px;
  padding: 20px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
  margin-bottom: 20px;
}
.panel h2 {
  font-size: 16px;
  margin-bottom: 16px;
  color: #2d3748;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

/* === TABLES === */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; padding: 10px 12px; background: #edf2f7; color: #4a5568; font-weight: 600; font-size: 12px; text-transform: uppercase; }
td { padding: 12px; border-bottom: 1px solid #edf2f7; }
tr:hover td { background: #f7fafc; }
.table-wrap { overflow-x: auto; }

.badge { display: inline-block; padding: 3px 10px; border-radius: 12px; font-size: 11px; font-weight: 600; }
.badge.ok { background: #c6f6d5; color: #22543d; }
.badge.low { background: #fed7d7; color: #742a2a; }
.badge.warn { background: #feebc8; color: #7c2d12; }
.badge.in { background: #bee3f8; color: #2a4365; }
.badge.out { background: #fbd5d5; color: #742a2a; }

/* === BUTTONS === */
.btn {
  padding: 9px 16px;
  border: none;
  border-radius: 6px;
  background: #0f4c81;
  color: white;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: background 0.2s;
}
.btn:hover { background: #0a3a66; }
.btn.secondary { background: #718096; }
.btn.secondary:hover { background: #4a5568; }
.btn.danger { background: #e53e3e; }
.btn.danger:hover { background: #c53030; }
.btn.small { padding: 5px 10px; font-size: 12px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* === FORMS === */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}
label { display: block; font-size: 12px; color: #4a5568; margin-bottom: 6px; font-weight: 500; }
input, select, textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid #cbd5e0;
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: #0f4c81;
  box-shadow: 0 0 0 3px rgba(15,76,129,0.1);
}

/* === MODAL === */
.modal-bg {
  display: none;
  position: fixed; top:0; left:0; right:0; bottom:0;
  background: rgba(0,0,0,0.5); z-index: 100;
  align-items: center; justify-content: center;
  padding: 20px;
}
.modal-bg.show { display: flex; }
.modal {
  background: white; border-radius: 10px;
  padding: 24px; max-width: 600px; width: 100%;
  max-height: 90vh; overflow-y: auto;
}
.modal h3 { margin-bottom: 16px; color: #2d3748; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; }

/* === ALERTS === */
.alert {
  padding: 12px 16px;
  border-radius: 6px;
  margin-bottom: 16px;
  font-size: 14px;
}
.alert.danger { background: #fff5f5; border-left: 4px solid #e53e3e; color: #742a2a; }
.alert.info { background: #ebf8ff; border-left: 4px solid #3182ce; color: #2a4365; }
.alert.success { background: #f0fff4; border-left: 4px solid #38a169; color: #22543d; }

/* === BACKUP REMINDER === */
.backup-reminder {
  background: white;
  border-radius: 10px;
  padding: 16px 20px;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
  border-left: 4px solid #38a169;
}
.backup-reminder.warn { border-left-color: #d69e2e; background: #fef5e7; }
.backup-reminder.danger { border-left-color: #e53e3e; background: #fff5f5; }
.backup-reminder strong { color: #2d3748; }

.filter-bar {
  display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap;
}
.filter-bar input, .filter-bar select { flex: 1; min-width: 150px; }
.empty { text-align: center; padding: 40px 20px; color: #a0aec0; }
.calc-result {
  background: #f0fff4;
  padding: 12px 16px;
  border-radius: 6px;
  margin-top: 12px;
  border-left: 3px solid #38a169;
  font-size: 13px;
  color: #22543d;
  line-height: 1.8;
}
.splash {
  text-align: center;
  padding: 40px 20px;
  background: white;
  border-radius: 12px;
  margin-bottom: 24px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.splash img {
  width: 120px; height: 120px;
  border-radius: 20px;
  margin-bottom: 16px;
  box-shadow: 0 8px 24px rgba(15,76,129,0.25);
}
.splash h2 { font-size: 22px; color: #0f4c81; margin-bottom: 8px; }
.splash p { color: #4a5568; max-width: 500px; margin: 0 auto; font-size: 14px; line-height: 1.6; }

@media (max-width: 640px) {
  .topbar-text h1 { font-size: 14px; }
  .topbar-text small { font-size: 11px; }
  .topbar-logo { width: 38px; height: 38px; }
  .container { padding: 16px; }
  .stat-value { font-size: 22px; }
  .splash img { width: 90px; height: 90px; }
  .splash h2 { font-size: 18px; }
  /* Em mobile o grid de 5 colunas dos prioritários quebra pra caber */
  #panorama-dashboard-zona > div:first-child,
  #panorama-relatorio-zona > div:first-child {
    grid-template-columns: repeat(2, 1fr) !important;
  }
}
@media (min-width: 641px) and (max-width: 900px) {
  #panorama-dashboard-zona > div:first-child,
  #panorama-relatorio-zona > div:first-child {
    grid-template-columns: repeat(3, 1fr) !important;
  }
}
