/* ========================================
   ADERM SST-SM4G Dashboard Styles
   Charte : énergie solaire, rural, Tchad
   ======================================== */

:root {
  --primary: #2e7d32;
  --primary-dark: #1b5e20;
  --primary-light: #66bb6a;
  --accent: #f4b942;
  --accent-dark: #e69c00;
  --danger: #d32f2f;
  --danger-light: #ffcdd2;
  --warning: #f57c00;
  --warning-light: #ffe0b2;
  --success: #388e3c;
  --success-light: #c8e6c9;
  --info: #1976d2;
  --info-light: #bbdefb;
  --bg: #f5f7f5;
  --card-bg: #ffffff;
  --text: #263238;
  --text-muted: #607d8b;
  --border: #e0e0e0;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  --radius: 12px;
  --header-height: 72px;
  --nav-height: 56px;
}

* {
  box-sizing: border-box;
}

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

/* Header */
.app-header {
  height: var(--header-height);
  background: linear-gradient(90deg, var(--primary-dark) 0%, var(--primary) 100%);
  color: white;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 1000;
  box-shadow: var(--shadow);
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand h1 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
}

.brand p {
  margin: 2px 0 0;
  font-size: 0.85rem;
  opacity: 0.9;
}

.header-meta {
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 0.9rem;
}

.subscriber-counter {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.15);
  border: 2px solid var(--accent);
  border-radius: 10px;
  padding: 6px 16px;
  min-width: 80px;
}

.counter-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  opacity: 0.9;
}

.counter-value {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--accent);
  line-height: 1.1;
}

.status {
  padding: 6px 12px;
  border-radius: 20px;
  font-weight: 600;
  font-size: 0.8rem;
  background: rgba(255, 255, 255, 0.2);
}

.status.online {
  background: var(--success-light);
  color: var(--success);
}

.status.offline {
  background: var(--danger-light);
  color: var(--danger);
}

/* Navigation */
.app-nav {
  height: var(--nav-height);
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 16px;
  overflow-x: auto;
  position: sticky;
  top: var(--header-height);
  z-index: 999;
}

.nav-item {
  background: transparent;
  border: none;
  padding: 10px 16px;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: 8px;
  white-space: nowrap;
  transition: all 0.2s ease;
}

.nav-item:hover {
  background: #f1f8e9;
  color: var(--primary);
}

.nav-item.active {
  background: var(--primary);
  color: white;
}

/* Main content */
.app-main {
  padding: 24px;
  max-width: 1400px;
  margin: 0 auto;
}

.section {
  display: none;
  animation: fadeIn 0.3s ease;
}

.section.active {
  display: block;
}

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

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

.section-header h2 {
  margin: 0;
  font-size: 1.4rem;
  color: var(--primary-dark);
}

.meter-id {
  font-family: 'Courier New', monospace;
  background: #e8f5e9;
  color: var(--primary-dark);
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 600;
}

.live-badge {
  color: var(--danger);
  font-weight: 700;
  font-size: 0.85rem;
  animation: pulse 1.5s infinite;
}

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

.badge {
  background: var(--accent);
  color: #3e2723;
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 700;
}

/* Cards */
.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 20px;
}

.card h3 {
  margin: 0 0 16px;
  font-size: 1.05rem;
  color: var(--text);
  border-bottom: 2px solid #e8f5e9;
  padding-bottom: 10px;
}

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

.kpi-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  display: flex;
  align-items: center;
  gap: 14px;
  transition: transform 0.2s ease;
}

.kpi-card:hover {
  transform: translateY(-2px);
}

.kpi-icon {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
  flex-shrink: 0;
}

.kpi-icon.energy { background: #fff3e0; }
.kpi-icon.credit { background: #e8f5e9; }
.kpi-icon.power { background: #e3f2fd; }
.kpi-icon.relay { background: #f3e5f5; }

.kpi-content {
  display: flex;
  flex-direction: column;
}

.kpi-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.kpi-value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text);
}

.kpi-unit {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Dashboard grid */
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
  gap: 20px;
}

.chart-container {
  position: relative;
  height: 280px;
}

/* Metrics grid */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
}

.metric {
  background: #fafafa;
  border-radius: 10px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  border-left: 4px solid var(--primary-light);
}

.metric-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.metric-value {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text);
}

.metric-unit {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.metric.alert {
  border-left-color: var(--danger);
  background: var(--danger-light);
}

.metric.warning {
  border-left-color: var(--warning);
  background: var(--warning-light);
}

/* Alerts */
.alerts-card {
  margin-top: 20px;
}

.alerts-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.alert {
  padding: 12px 14px;
  border-radius: 8px;
  margin-bottom: 8px;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 10px;
}

.alert::before {
  content: '•';
  font-size: 1.5rem;
  line-height: 0;
}

.alert.info { background: var(--info-light); color: var(--info); }
.alert.warning { background: var(--warning-light); color: var(--warning); }
.alert.danger { background: var(--danger-light); color: var(--danger); }
.alert.success { background: var(--success-light); color: var(--success); }

/* Prepaid */
.prepaid-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 20px;
}

.balance-card {
  text-align: center;
}

.balance-display {
  font-size: 3rem;
  font-weight: 800;
  color: var(--primary-dark);
  line-height: 1;
}

.balance-unit {
  font-size: 1rem;
  color: var(--text-muted);
  font-weight: 500;
}

.balance-bar {
  width: 100%;
  height: 12px;
  background: #e0e0e0;
  border-radius: 6px;
  margin: 16px 0;
  overflow: hidden;
}

.balance-fill {
  height: 100%;
  width: 0%;
  background: var(--primary);
  border-radius: 6px;
  transition: width 0.4s ease, background 0.3s ease;
}

.balance-message {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: 16px;
}

.recharge-card form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.recharge-card label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
}

.recharge-card input {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  transition: border-color 0.2s;
}

.recharge-card input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(46, 125, 50, 0.1);
}

/* Buttons */
.btn {
  padding: 12px 18px;
  border: none;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn:hover {
  opacity: 0.9;
  transform: translateY(-1px);
}

.btn-primary { background: var(--primary); color: white; }
.btn-success { background: var(--success); color: white; }
.btn-danger { background: var(--danger); color: white; }
.btn-warning { background: var(--warning); color: white; }

.relay-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

/* Tables */
.table-responsive {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.data-table th,
.data-table td {
  text-align: left;
  padding: 12px;
  border-bottom: 1px solid var(--border);
}

.data-table th {
  background: #f1f8e9;
  color: var(--primary-dark);
  font-weight: 700;
  position: sticky;
  top: 0;
}

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

/* Events filter */
.filter-group {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.filter-btn {
  background: #f5f5f5;
  border: 1px solid var(--border);
  padding: 8px 14px;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  color: var(--text-muted);
  transition: all 0.2s;
}

.filter-btn:hover,
.filter-btn.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

/* Shortcodes */
.shortcodes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 10px;
}

.shortcode-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #f5f5f5;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 0.85rem;
}

.shortcode-code {
  font-weight: 700;
  color: var(--primary-dark);
  background: #e8f5e9;
  padding: 4px 8px;
  border-radius: 4px;
}

/* Map */
.map-card {
  padding: 0;
  overflow: hidden;
}

#meter-map {
  height: 400px;
  width: 100%;
  border-radius: var(--radius);
}

/* Footer */
.app-footer {
  text-align: center;
  padding: 20px;
  color: var(--text-muted);
  font-size: 0.8rem;
  border-top: 1px solid var(--border);
  margin-top: 20px;
}

/* ========================================
   Styles complémentaires multi-abonnés
   ======================================== */

.filter-bar {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.filter-bar input,
.filter-bar select {
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.9rem;
}

.filter-bar input {
  flex: 1;
  min-width: 220px;
}

.history-filter-bar input[type="date"] {
  flex: 0 1 160px;
  min-width: 140px;
}

.filter-label {
  align-self: center;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.subscriber-selector-card h3 {
  margin-bottom: 12px;
}

.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 16px;
  margin-top: 16px;
}

.btn-sm {
  padding: 8px 12px;
  font-size: 0.8rem;
}

.subscribers-table tbody tr {
  cursor: pointer;
}

.subscribers-table tbody tr:hover {
  background: #f1f8e9;
}

.credit-pill,
.relay-pill {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 0.8rem;
  font-weight: 700;
}

.credit-pill {
  background: #e8f5e9;
  color: var(--primary-dark);
}

.credit-pill.low {
  background: var(--danger-light);
  color: var(--danger);
}

.relay-pill.on {
  background: var(--success-light);
  color: var(--success);
}

.relay-pill.off {
  background: var(--danger-light);
  color: var(--danger);
}

.status-inactive {
  color: var(--text-muted);
}

.status-warning {
  color: var(--warning);
}

.text-muted {
  color: var(--text-muted);
}

.fraud-pill {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 0.8rem;
  font-weight: 700;
  background: #ffebee;
  color: #c62828;
}

.fraud-detail-card {
  background: #fff8e1;
  border-left: 5px solid #f57c00;
}

.fraud-schema {
  background: #263238;
  color: #aed581;
  padding: 16px;
  border-radius: 8px;
  font-family: 'Courier New', monospace;
  white-space: pre-wrap;
  overflow-x: auto;
}

.badge-danger {
  background: #d32f2f;
  color: #fff;
}

.login-overlay {
  position: fixed;
  inset: 0;
  background: linear-gradient(135deg, #1b5e20 0%, #2e7d32 50%, #f4b942 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20000;
}

.login-overlay.hidden {
  display: none;
}

.login-card {
  background: #fff;
  padding: 32px;
  border-radius: 16px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.25);
  width: 100%;
  max-width: 420px;
}

.login-card h2 {
  text-align: center;
  margin-bottom: 8px;
  color: var(--primary-dark);
}

.login-subtitle {
  text-align: center;
  color: var(--text-muted);
  margin-bottom: 24px;
}

.login-card form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.login-card label {
  font-weight: 600;
  font-size: 0.9rem;
}

.login-card input {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
}

.btn-block {
  width: 100%;
  justify-content: center;
}

.login-error {
  color: #d32f2f;
  text-align: center;
  margin-top: 12px;
  min-height: 1.2em;
}

.login-roles {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  font-size: 0.85rem;
  color: var(--text-muted);
}

.login-roles ul {
  margin: 8px 0 0 18px;
  line-height: 1.6;
}

.user-menu {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: 16px;
  padding-left: 16px;
  border-left: 1px solid rgba(255,255,255,0.3);
}

.user-menu .btn {
  background: rgba(255,255,255,0.15);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.3);
}

.role-badge {
  background: #f4b942;
  color: #1b1b1b;
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
}

.role-badge.super-admin {
  background: #d32f2f;
  color: #fff;
}

.role-badge.supervisor,
.role-badge.reseau {
  background: #1976d2;
  color: #fff;
}

/* Responsive */
@media (max-width: 768px) {
  .app-header {
    flex-direction: column;
    height: auto;
    padding: 12px 16px;
    gap: 8px;
  }

  .brand h1 {
    font-size: 1.1rem;
  }

  .brand p {
    font-size: 0.75rem;
  }

  .app-main {
    padding: 16px;
  }

  .dashboard-grid {
    grid-template-columns: 1fr;
  }

  .metrics-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .kpi-value {
    font-size: 1.2rem;
  }

  .balance-display {
    font-size: 2.2rem;
  }

  #meter-map {
    height: 300px;
  }
}

@media (max-width: 480px) {
  .metrics-grid {
    grid-template-columns: 1fr;
  }

  .relay-actions {
    flex-direction: column;
  }

  .relay-actions .btn {
    width: 100%;
  }
}
