/* Energy Manager - Styles pour hébergement web */
:root {
  --primary: #0ea5e9;
  --primary-dark: #0284c7;
  --success: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;
  
  --bg-primary: #f8fafc;
  --bg-card: #ffffff;
  --bg-hover: #f1f5f9;
  
  --text-primary: #1e293b;
  --text-secondary: #64748b;
  --text-muted: #94a3b8;
  
  --border: #e2e8f0;
  --border-hover: #cbd5e1;
  
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1);
  
  --radius: 8px;
  --radius-lg: 12px;
}

/* Reset et base */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  line-height: 1.6;
  color: var(--text-primary);
  background: var(--bg-primary);
  min-height: 100vh;
}

.app-container {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header */
.header {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: white;
  padding: 2rem 1rem;
  box-shadow: var(--shadow-md);
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  max-width: 1200px;
  margin: 0 auto;
}

.header-title {
  text-align: left;
}

.header-title h1 {
  font-size: 2.5rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
}

.header-title p {
  font-size: 1.1rem;
  opacity: 0.9;
}

.header-actions {
  display: flex;
  gap: 1rem;
}

/* Bouton de rapport PDF */
.btn-report {
  background: rgba(255, 255, 255, 0.2);
  color: white;
  border: 2px solid rgba(255, 255, 255, 0.3);
  padding: 0.75rem 1.5rem;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  backdrop-filter: blur(10px);
}

.btn-report:hover {
  background: rgba(255, 255, 255, 0.3);
  border-color: rgba(255, 255, 255, 0.5);
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.2);
}

.btn-report:active {
  transform: translateY(0);
}

/* Responsive header */
@media (max-width: 768px) {
  .header-content {
    flex-direction: column;
    gap: 1rem;
  }
  
  .header-title {
    text-align: center;
  }
  
  .header-title h1 {
    font-size: 2rem;
  }
}

/* Main Content */
.main-content {
  flex: 1;
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem 1rem;
  width: 100%;
  display: grid;
  gap: 2rem;
}

/* Cards */
.card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 2rem;
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border);
}

.card h2 {
  color: var(--text-primary);
  margin-bottom: 1.5rem;
  font-size: 1.5rem;
  font-weight: 600;
}

/* Forms */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 1.5rem;
  align-items: end;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.form-group label {
  font-weight: 500;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.form-group input,
.form-group select {
  padding: 0.75rem 1rem;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  font-size: 1rem;
  transition: all 0.2s ease;
  background: white;
}

.form-group input:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.1);
}

.form-actions {
  display: flex;
  align-items: end;
}

.btn-primary {
  background: var(--primary);
  color: white;
  border: none;
  padding: 0.75rem 2rem;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-primary:hover {
  background: var(--primary-dark);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

/* Messages */
.message {
  margin-top: 1rem;
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  font-weight: 500;
  min-height: 1rem;
}

.message.success {
  background: rgba(16, 185, 129, 0.1);
  color: var(--success);
  border: 1px solid rgba(16, 185, 129, 0.2);
}

.message.error {
  background: rgba(239, 68, 68, 0.1);
  color: var(--danger);
  border: 1px solid rgba(239, 68, 68, 0.2);
}

.message.info {
  background: rgba(14, 165, 233, 0.1);
  color: var(--primary);
  border: 1px solid rgba(14, 165, 233, 0.2);
}

/* Tabs */
.tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 2rem;
  border-bottom: 1px solid var(--border);
}

.tab {
  padding: 0.75rem 1.5rem;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  font-weight: 500;
  border-bottom: 2px solid transparent;
  transition: all 0.2s ease;
}

.tab:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
}

.tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

/* Charts */
.charts-container {
  display: grid;
  gap: 2rem;
  margin-bottom: 2rem;
}

.chart-wrapper.full-width {
  grid-column: 1 / -1;
}

.chart-wrapper {
  background: var(--bg-primary);
  border-radius: var(--radius);
  padding: 1.5rem;
  position: relative;
}

.chart-wrapper h3 {
  color: var(--text-secondary);
  margin-bottom: 1rem;
  font-size: 1rem;
  font-weight: 600;
}

.chart-wrapper canvas {
  max-height: 300px !important;
  width: 100% !important;
  height: 300px !important;
}

/* Tables */
.table-container h3 {
  color: var(--text-secondary);
  margin-bottom: 1rem;
  font-size: 1rem;
  font-weight: 600;
}

.year-tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.year-tab {
  padding: 0.5rem 1rem;
  border: none;
  background: var(--bg-hover);
  color: var(--text-secondary);
  cursor: pointer;
  font-weight: 500;
  border-radius: var(--radius);
  font-size: 0.9rem;
  transition: all 0.2s ease;
}

.year-tab:hover {
  color: var(--text-primary);
  background: var(--border-hover);
}

.year-tab.active {
  color: var(--primary);
  background: rgba(14, 165, 233, 0.1);
  border: 1px solid rgba(14, 165, 233, 0.2);
}

.table-wrapper {
  overflow-x: auto;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

table {
  width: 100%;
  border-collapse: collapse;
  background: white;
}

thead th {
  background: var(--bg-primary);
  color: var(--text-secondary);
  font-weight: 600;
  padding: 1rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

tbody td {
  padding: 1rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

tbody tr:hover {
  background: var(--bg-hover);
}

/* Évolution des consommations */
.evolution-increase {
  color: var(--danger);
  font-weight: 700;
  font-size: 1.1rem;
}

.evolution-decrease {
  color: var(--success);
  font-weight: 700;
  font-size: 1.1rem;
}

.evolution-stable {
  color: var(--text-muted);
  font-weight: 500;
  font-size: 1rem;
}

/* Boutons d'actions dans le tableau */
.btn-delete {
  background: var(--danger);
  color: white;
  border: none;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.2s ease;
  font-weight: 500;
  margin-left: 4px;
}

.btn-delete:hover {
  background: #dc2626;
  transform: scale(1.05);
}

.btn-edit {
  background: var(--warning);
  color: white;
  border: none;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.2s ease;
  font-weight: 500;
}

.btn-edit:hover {
  background: #d97706;
  transform: scale(1.05);
}

.actions-cell {
  text-align: center;
  width: 120px;
}

/* Modal d'édition */
.edit-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 2000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.edit-modal.show {
  opacity: 1;
  pointer-events: all;
}

.edit-modal-content {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 2rem;
  max-width: 500px;
  width: 90%;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
  transform: translateY(-20px);
  transition: transform 0.3s ease;
}

.edit-modal.show .edit-modal-content {
  transform: translateY(0);
}

.edit-modal h3 {
  margin: 0 0 1.5rem;
  color: var(--text-primary);
}

.edit-form {
  display: grid;
  gap: 1rem;
}

.edit-form-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.edit-form-group label {
  font-weight: 500;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.edit-form-group input {
  padding: 0.75rem 1rem;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  font-size: 1rem;
  transition: all 0.2s ease;
  background: white;
}

.edit-form-group input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.1);
}

.edit-form-actions {
  display: flex;
  gap: 1rem;
  justify-content: flex-end;
  margin-top: 1rem;
}

.btn-save {
  background: var(--primary);
  color: white;
  border: none;
  padding: 0.75rem 1.5rem;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-save:hover {
  background: var(--primary-dark);
}

.btn-cancel {
  background: var(--text-muted);
  color: white;
  border: none;
  padding: 0.75rem 1.5rem;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-cancel:hover {
  background: #64748b;
}

.edit-form-group textarea {
  padding: 0.75rem 1rem;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  font-size: 1rem;
  transition: all 0.2s ease;
  background: white;
  font-family: inherit;
  resize: vertical;
}

.edit-form-group textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.1);
}

/* Indicateur d'événement sur le graphique */
.chart-event-indicator {
  position: absolute;
  background: #ff6b35;
  color: white;
  padding: 2px 6px;
  border-radius: 3px;
  font-size: 12px;
  font-weight: bold;
  cursor: pointer;
  z-index: 100;
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
  pointer-events: auto;
}

/* Champs électricité */
.electricity-inputs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-top: 0.5rem;
}

.electricity-input {
  display: flex;
  flex-direction: column;
}

.electricity-input label {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 0.25rem;
}

.electricity-input input {
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.875rem;
  transition: border-color 0.2s ease;
}

.electricity-input input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary)20;
}

@media (max-width: 768px) {
  .electricity-inputs {
    grid-template-columns: 1fr;
  }
}

.chart-event-indicator:hover {
  background: #e55a2b;
  transform: scale(1.1);
}

/* Résumé des évolutions */
.evolution-summary {
  background: linear-gradient(135deg, rgba(14, 165, 233, 0.1), rgba(52, 211, 153, 0.1));
  border: 1px solid rgba(14, 165, 233, 0.2);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
}

.evolution-summary.hidden {
  display: none;
}

.summary-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
}

.summary-label {
  font-size: 0.9rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.summary-value {
  font-size: 1.4rem;
  font-weight: 700;
}

.summary-value.positive {
  color: var(--danger);
}

.summary-value.negative {
  color: var(--success);
}

.summary-value.neutral {
  color: var(--text-muted);
}

.evolution-cell {
  position: relative;
  cursor: help;
}

/* Tooltip pour les évolutions */
.evolution-tooltip {
  position: fixed;
  background: rgba(15, 23, 42, 0.95);
  color: white;
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 0.9rem;
  line-height: 1.4;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.3);
  z-index: 1000;
  min-width: 200px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(8px);
  opacity: 0;
  transform: translateY(-5px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
}

.evolution-tooltip.show {
  opacity: 1;
  transform: translateY(0);
}

.evolution-tooltip::before {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: rgba(15, 23, 42, 0.95);
}

.evolution-tooltip .calc-line {
  margin: 4px 0;
  font-family: monospace;
}

.evolution-tooltip .calc-result {
  font-weight: 600;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid rgba(255, 255, 255, 0.2);
}

/* Footer */
.footer {
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  padding: 1.5rem;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* Responsive */
@media (min-width: 768px) {
  .charts-container {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 768px) {
  .header h1 {
    font-size: 2rem;
  }
  
  .main-content {
    padding: 1rem;
  }
  
  .card {
    padding: 1.5rem;
  }
  
  .form-grid {
    grid-template-columns: 1fr;
  }
  
  .tabs {
    flex-wrap: wrap;
  }
}

/* Animations fluides */
* {
  transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

/* Stabilisation des graphiques */
.chart-wrapper {
  contain: layout style paint;
}

.chart-wrapper canvas {
  display: block;
  position: relative;
}
