/* ==========================================================================
   CCalc - Mon Tableur Magique pour Enfants
   Ecole de l'Enfant-Jésus Morlanwelz
   ========================================================================== */

:root {
  --ccalc-primary: #16a34a;
  --ccalc-primary-dark: #15803d;
  --ccalc-primary-light: #dcfce7;
  --ccalc-accent: #f59e0b;
  --ccalc-border: #cbd5e1;
  --ccalc-toolbar-bg: #f8fafc;
  --ccalc-header-gray: #f1f5f9;
  --ccalc-text: #1e293b;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: #f1f5f9;
  font-family: 'Nunito', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  color: var(--ccalc-text);
  user-select: none;
}

*, *::before, *::after {
  box-sizing: border-box;
}

/* Application Wrapper */
.ccalc-wrapper {
  display: flex;
  flex-direction: column;
  width: 100vw;
  height: 100vh;
  margin: 0;
  padding: 0;
  overflow: hidden;
  background: white;
}

/* --------------------------------------------------------------------------
   Bouton Retour au site
   -------------------------------------------------------------------------- */
.btn-back-site {
  background: rgba(255, 255, 255, 0.95) !important;
  color: #15803d !important;
  font-weight: 800 !important;
  border: 1px solid white !important;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12);
  text-decoration: none !important;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 13px;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.btn-back-site:hover {
  background: white !important;
  color: #166534 !important;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

/* --------------------------------------------------------------------------
   Bannière supérieure (Top Bar - Vert Excel)
   -------------------------------------------------------------------------- */
.ccalc-top-bar {
  flex-shrink: 0;
  background: linear-gradient(135deg, #15803d 0%, #16a34a 50%, #10b981 100%);
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  color: white;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  z-index: 100;
}

.ccalc-title-group {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  min-width: 260px;
}

.ccalc-logo-badge {
  background: #facc15;
  color: #1e293b;
  font-weight: 900;
  font-size: 15px;
  padding: 4px 12px 4px 6px;
  border-radius: 20px;
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.15);
}

.ccalc-badge-icon {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  vertical-align: middle;
  object-fit: cover;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.ccalc-doc-name-input {
  background: rgba(255, 255, 255, 0.18);
  border: 1px solid rgba(255, 255, 255, 0.4);
  color: white;
  font-size: 16px;
  font-weight: 700;
  padding: 6px 12px;
  border-radius: 8px;
  outline: none;
  min-width: 220px;
  max-width: 380px;
  transition: all 0.2s;
}

.ccalc-doc-name-input:focus {
  background: white;
  color: #1e293b;
  border-color: #facc15;
  box-shadow: 0 0 0 3px rgba(250, 204, 21, 0.3);
}

.ccalc-top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.ccalc-pill-btn {
  background: rgba(255, 255, 255, 0.18);
  color: white;
  border: 1px solid rgba(255, 255, 255, 0.3);
  padding: 7px 12px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s;
  user-select: none;
}

.ccalc-pill-btn:hover {
  background: rgba(255, 255, 255, 0.3);
  transform: translateY(-1px);
}

.ccalc-pill-btn.btn-chart {
  background: linear-gradient(135deg, #0284c7, #0369a1);
  border-color: #38bdf8;
  color: white;
  font-size: 14px;
  padding: 7px 16px;
  box-shadow: 0 2px 8px rgba(2, 132, 199, 0.35);
}

.ccalc-pill-btn.btn-chart:hover {
  background: linear-gradient(135deg, #0369a1, #075985);
  box-shadow: 0 4px 12px rgba(2, 132, 199, 0.45);
}

.ccalc-pill-btn.btn-accent {
  background: #facc15;
  color: #1e293b;
  border-color: #facc15;
}

.ccalc-pill-btn.btn-accent:hover {
  background: #fde047;
}

.ccalc-pill-btn.btn-save {
  background: #f8fafc;
  color: #15803d;
  border-color: white;
}

.ccalc-pill-btn.btn-save:hover {
  background: white;
  color: #166534;
}

.ccalc-pill-btn.btn-primary {
  background: #16a34a;
  color: white;
  border-color: #15803d;
}

.ccalc-pill-btn.btn-primary:hover {
  background: #15803d;
}

.ccalc-pill-btn.btn-secondary {
  background: #f1f5f9;
  color: #334155;
  border-color: #cbd5e1;
}

.ccalc-pill-btn.btn-secondary:hover {
  background: #e2e8f0;
  color: #0f172a;
}

/* --------------------------------------------------------------------------
   Barre d'outils (Toolbar)
   -------------------------------------------------------------------------- */
.ccalc-toolbar {
  flex-shrink: 0;
  background: var(--ccalc-toolbar-bg);
  border-bottom: 1px solid var(--ccalc-border);
  padding: 8px 16px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  z-index: 90;
}

.ccalc-tool-group {
  display: flex;
  align-items: center;
  background: white;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  padding: 2px 4px;
  gap: 2px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
}

.ccalc-tool-separator {
  width: 1px;
  height: 28px;
  background: #cbd5e1;
  margin: 0 4px;
}

.ccalc-btn {
  background: transparent;
  border: 1px solid transparent;
  color: #1e293b;
  height: 32px;
  padding: 4px 8px;
  border-radius: 6px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 700;
  transition: all 0.12s ease;
}

.ccalc-btn:hover {
  background: #ecfdf5;
  border-color: #a7f3d0;
  color: #047857;
}

.ccalc-btn:active {
  background: #d1fae5;
  transform: translateY(1px);
}

.ccalc-btn.active {
  background: #d1fae5 !important;
  color: #047857 !important;
  border-color: #6ee7b7 !important;
}

.ccalc-btn.btn-danger-hover:hover {
  background: #fee2e2;
  border-color: #fca5a5;
  color: #dc2626;
}

.ccalc-select {
  height: 30px;
  padding: 2px 6px;
  border-radius: 6px;
  border: 1px solid #cbd5e1;
  background: white;
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  color: #1e293b;
  outline: none;
  cursor: pointer;
}

.ccalc-select:focus {
  border-color: var(--ccalc-primary);
  box-shadow: 0 0 0 2px rgba(22, 163, 74, 0.2);
}

.ccalc-size-control {
  display: flex;
  align-items: center;
  gap: 2px;
  background: #f1f5f9;
  border-radius: 6px;
  padding: 2px;
}

.ccalc-btn-mini {
  background: white;
  border: 1px solid #cbd5e1;
  border-radius: 4px;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 800;
  cursor: pointer;
}

.ccalc-btn-mini:hover {
  background: #e2e8f0;
}

.font-size-display {
  font-size: 12px;
  font-weight: 800;
  padding: 0 4px;
  min-width: 20px;
  text-align: center;
  color: #1e293b;
}

.ccalc-color-picker-wrapper {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 2px 6px;
  border-radius: 6px;
  cursor: pointer;
}

.ccalc-color-picker-wrapper:hover {
  background: #f1f5f9;
}

.color-icon {
  font-size: 13px;
}

.color-circle-input {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid white;
  box-shadow: 0 0 0 1px #94a3b8;
  cursor: pointer;
  padding: 0;
  background: transparent;
}

.color-circle-input::-webkit-color-swatch-wrapper {
  padding: 0;
}

.color-circle-input::-webkit-color-swatch {
  border: none;
  border-radius: 50%;
}

/* --------------------------------------------------------------------------
   Barre de Formule (fx)
   -------------------------------------------------------------------------- */
.ccalc-formula-bar {
  flex-shrink: 0;
  background: white;
  border-bottom: 1px solid #cbd5e1;
  padding: 6px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  z-index: 85;
}

.ccalc-cell-name-box {
  background: #f8fafc;
  border: 1.5px solid #cbd5e1;
  border-radius: 6px;
  padding: 4px 10px;
  font-weight: 900;
  font-size: 13px;
  color: #15803d;
  min-width: 55px;
  text-align: center;
  letter-spacing: 0.5px;
}

.ccalc-fx-symbol {
  font-family: 'Times New Roman', serif;
  font-style: italic;
  font-size: 18px;
  font-weight: 800;
  color: #64748b;
  user-select: none;
}

.ccalc-formula-input {
  flex: 1;
  height: 32px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 14px;
  font-weight: 600;
  color: #1e293b;
  outline: none;
  font-family: 'Nunito', sans-serif;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.ccalc-formula-input:focus {
  border-color: var(--ccalc-primary);
  box-shadow: 0 0 0 2px rgba(22, 163, 74, 0.2);
}

.formula-helpers {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.btn-formula-quick {
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  color: #1d4ed8;
  padding: 4px 10px;
  border-radius: 16px;
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-formula-quick:hover {
  background: #dbeafe;
  border-color: #93c5fd;
  transform: translateY(-1px);
}

/* --------------------------------------------------------------------------
   Menus Popovers (Export)
   -------------------------------------------------------------------------- */
.ccalc-dropdown-wrapper {
  position: relative;
  display: inline-block;
}

.ccalc-dropdown-popover {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  background: white;
  border: 1px solid #cbd5e1;
  border-radius: 12px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
  padding: 8px;
  z-index: 500;
  min-width: 250px;
}

.ccalc-dropdown-popover.active {
  display: block;
}

.export-option-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  cursor: pointer;
  text-align: left;
  transition: all 0.15s;
}

.export-option-btn:hover {
  background: #ecfdf5;
  border-color: #a7f3d0;
}

.export-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 800;
  padding: 4px 6px;
  border-radius: 6px;
  color: white;
  min-width: 48px;
}

.ods-badge { background: linear-gradient(135deg, #15803d, #10b981); }
.html-badge { background: linear-gradient(135deg, #0284c7, #38bdf8); }
.csv-badge { background: linear-gradient(135deg, #475569, #64748b); }
.ccalc-badge { background: linear-gradient(135deg, #16a34a, #22c55e); }
.print-badge { background: linear-gradient(135deg, #ea580c, #f97316); }

.export-text strong {
  display: block;
  font-size: 13px;
  color: #1e293b;
}

.export-text small {
  display: block;
  font-size: 11px;
  color: #64748b;
}

/* --------------------------------------------------------------------------
   Grille du tableur (Spreadsheet Table)
   -------------------------------------------------------------------------- */
.ccalc-grid-container {
  flex: 1;
  min-height: 0;
  overflow: auto;
  background: #ffffff;
  position: relative;
}

.ccalc-spreadsheet-wrapper {
  min-width: 100%;
  display: inline-block;
}

.ccalc-table {
  border-collapse: collapse;
  table-layout: fixed;
  background: white;
}

/* En-têtes fixes (Colonnes et Lignes) */
.col-header {
  position: sticky;
  top: 0;
  background: #f1f5f9;
  border: 1px solid #cbd5e1;
  font-weight: 800;
  font-size: 12px;
  color: #475569;
  text-align: center;
  height: 26px;
  min-width: 95px;
  padding: 4px;
  z-index: 20;
  user-select: none;
}

.row-header {
  position: sticky;
  left: 0;
  background: #f1f5f9;
  border: 1px solid #cbd5e1;
  font-weight: 800;
  font-size: 12px;
  color: #475569;
  text-align: center;
  width: 44px;
  min-width: 44px;
  padding: 4px;
  z-index: 20;
  user-select: none;
}

.corner-header {
  position: sticky;
  top: 0;
  left: 0;
  background: #e2e8f0;
  border: 1px solid #cbd5e1;
  z-index: 30;
  width: 44px;
  height: 26px;
}

.col-header.highlight, .row-header.highlight {
  background: #dcfce7;
  color: #15803d;
  font-weight: 900;
}

/* Cellules individuelles */
.ccalc-cell {
  border: 1px solid #e2e8f0;
  height: 30px;
  padding: 4px 8px;
  font-size: 14px;
  color: #1e293b;
  position: relative;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: cell;
  outline: none;
  background: white;
  transition: background-color 0.1s;
  user-select: none;
  -webkit-user-select: none;
}

.ccalc-cell.selected {
  outline: 2px solid #16a34a !important;
  outline-offset: -1px;
  z-index: 10;
  background-color: #f0fdf4;
}

.ccalc-cell.range-selected {
  background-color: rgba(22, 163, 74, 0.16) !important;
}

.col-header.range-highlight, .row-header.range-highlight {
  background: #bbf7d0 !important;
  color: #14532d !important;
  font-weight: 800;
}

.cell-inline-input {
  width: 100%;
  height: 100%;
  border: none;
  background: transparent;
  outline: none;
  font-family: inherit;
  font-size: inherit;
  font-weight: inherit;
  color: inherit;
  text-align: inherit;
  padding: 0;
  margin: 0;
}

/* --------------------------------------------------------------------------
   Barre d'état inférieure (Status Bar)
   -------------------------------------------------------------------------- */
.ccalc-status-bar {
  flex-shrink: 0;
  background: white;
  border-top: 1px solid var(--ccalc-border);
  padding: 8px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  font-size: 13px;
  color: #64748b;
  font-weight: 600;
  z-index: 80;
}

.status-stats {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

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

.status-school-brand {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: transparent;
  border: none;
  padding: 0;
  margin-left: 6px;
  font-size: 13px;
  font-weight: 700;
  color: #475569;
  user-select: none;
}

.status-school-logo {
  height: 20px;
  width: auto;
  max-width: 50px;
  object-fit: contain;
  vertical-align: middle;
}

.status-school-copy {
  letter-spacing: 0.2px;
  font-weight: 700;
  color: #475569;
}

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

.save-status-text {
  font-size: 12px;
  color: #16a34a;
  font-weight: 700;
}

.btn-recalc {
  background: #f1f5f9;
  color: #1e293b;
  border-color: #cbd5e1;
}

.btn-recalc:hover {
  background: #e2e8f0;
}

/* --------------------------------------------------------------------------
   Modales (Graphiques & Modèles)
   -------------------------------------------------------------------------- */
.ccalc-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(15, 23, 42, 0.7);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  padding: 20px;
}

.ccalc-modal-overlay.active {
  display: flex !important;
}

.ccalc-modal-card {
  background: white;
  border-radius: 16px;
  max-width: 740px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.25);
  transform: scale(0.94);
  transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  display: flex;
  flex-direction: column;
}

.ccalc-modal-overlay.active .ccalc-modal-card {
  transform: scale(1);
}

.ccalc-modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid #e2e8f0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #f8fafc;
  border-radius: 16px 16px 0 0;
}

.ccalc-modal-title {
  margin: 0;
  font-size: 18px;
  font-weight: 800;
  color: #0f172a;
}

.ccalc-modal-close {
  background: transparent;
  border: none;
  font-size: 24px;
  color: #94a3b8;
  cursor: pointer;
  border-radius: 50%;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}

.ccalc-modal-close:hover {
  background: #e2e8f0;
  color: #0f172a;
}

.ccalc-modal-body {
  padding: 20px;
}

.modal-intro-text {
  color: #64748b;
  margin-top: 0;
  margin-bottom: 16px;
  font-size: 14px;
}

/* Boutons de type de graphique */
.chart-type-buttons {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
}

.chart-type-btn {
  flex: 1;
  padding: 10px;
  border: 2px solid #cbd5e1;
  background: #f8fafc;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 800;
  color: #334155;
  cursor: pointer;
  transition: all 0.15s;
}

.chart-type-btn.active {
  border-color: #16a34a;
  background: #f0fdf4;
  color: #15803d;
}

.chart-selection-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: #dcfce7;
  color: #166534;
  font-size: 13px;
  font-weight: 800;
  padding: 6px 14px;
  border-radius: 20px;
  margin-bottom: 12px;
  border: 1px solid #bbf7d0;
}

.chart-modal-footer {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid #e2e8f0;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.btn-chart-tool {
  background: #f0fdf4 !important;
  color: #166534 !important;
  border-color: #86efac !important;
  font-weight: 800 !important;
}

.btn-chart-tool:hover {
  background: #dcfce7 !important;
  border-color: #22c55e !important;
  transform: translateY(-1px);
}

.btn-chart.has-selection {
  background: #fef08a !important;
  color: #854d0e !important;
  border-color: #facc15 !important;
  animation: pulse-selection 2s infinite;
}

@keyframes pulse-selection {
  0% { transform: scale(1); }
  50% { transform: scale(1.03); }
  100% { transform: scale(1); }
}

.chart-canvas-wrapper {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  min-height: 320px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

/* Modèles de tableaux */
.template-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 14px;
}

.template-card {
  background: #f8fafc;
  border: 1.5px solid #e2e8f0;
  border-radius: 12px;
  padding: 16px;
  cursor: pointer;
  transition: all 0.2s;
}

.template-card:hover {
  background: #ecfdf5;
  border-color: #10b981;
  transform: translateY(-2px);
  box-shadow: 0 8px 16px rgba(16, 185, 129, 0.12);
}

.template-card-title {
  font-weight: 800;
  font-size: 15px;
  color: #15803d;
  margin-bottom: 6px;
}

.template-card-desc {
  font-size: 13px;
  color: #64748b;
  margin: 0;
  line-height: 1.4;
}

/* Toast */
.ccalc-toast {
  position: fixed;
  bottom: 60px;
  right: 24px;
  background: #0f172a;
  color: white;
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 700;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.25);
  z-index: 10000;
  opacity: 0;
  transform: translateY(10px);
  transition: all 0.25s ease;
  pointer-events: none;
}

.ccalc-toast.show {
  opacity: 1;
  transform: translateY(0);
}

/* Impression / Export PDF */
@media print {
  @page {
    size: landscape;
    margin: 1cm;
  }

  body, html {
    background: white !important;
    overflow: visible !important;
  }

  .ccalc-top-bar, .ccalc-toolbar, .ccalc-formula-bar, .ccalc-status-bar, .ccalc-modal-overlay, .ccalc-toast {
    display: none !important;
  }

  .ccalc-wrapper, .ccalc-grid-container {
    display: block !important;
    width: 100% !important;
    height: auto !important;
    overflow: visible !important;
  }

  .ccalc-table {
    border: 1px solid #000;
  }

  .ccalc-cell, .col-header, .row-header {
    border: 1px solid #ccc;
  }
}
