/* ==========================================
   DRONE WEATHER DASHBOARD — app.css
   Bootstrap 5.3 + custom variables
   ========================================== */

/* ---- GridStack overrides ---- */
.grid-stack {
  min-height: 400px;
}
.grid-stack-item-content {
  overflow: visible !important;  /* let cards handle their own overflow */
  border-radius: var(--dwd-card-radius);
}
/* Leaflet requires overflow:hidden to clip tiles — override for map item only */
#item-map .grid-stack-item-content {
  overflow: hidden !important;
}
.grid-stack-item > .ui-resizable-se {
  bottom: 4px;
  right: 4px;
  width: 16px;
  height: 16px;
  opacity: 0.4;
}
.grid-stack-item:hover > .ui-resizable-se {
  opacity: 0.9;
}

/* Drag handle cursor */
.dwd-drag-handle {
  cursor: grab;
  user-select: none;
}
.dwd-drag-handle:active {
  cursor: grabbing;
}
.drag-hint {
  opacity: 0.35;
  font-size: 0.85rem;
}

/* ---- CSS Variables: Light Theme ---- */
:root {
  --dwd-score-good:    #198754;
  --dwd-score-ok:      #ffc107;
  --dwd-score-poor:    #fd7e14;
  --dwd-score-bad:     #dc3545;
  --dwd-card-radius:   0.5rem;
  --dwd-navbar-bg:     #f8f9fa;
  --dwd-arrow-color:   #0d6efd;
}

/* ---- Dark Theme (Bootstrap data-bs-theme=dark) ---- */
[data-bs-theme="dark"] {
  --dwd-navbar-bg:     #1a1d20;
  --dwd-arrow-color:   #66b2ff;
}

/* ---- Navbar ---- */
#main-navbar {
  background-color: var(--dwd-navbar-bg);
  border-bottom: 1px solid var(--bs-border-color);
  padding: 0.4rem 1rem;
}

/* ---- Cards ---- */
.card {
  border-radius: var(--dwd-card-radius);
}

/* ---- Flight Score Badge ---- */
.score-circle {
  width: 80px; height: 80px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.5rem; font-weight: 800;
  border: 4px solid currentColor;
}
.score-circle.success { color: var(--dwd-score-good); }
.score-circle.warning { color: var(--dwd-score-ok); }
.score-circle.orange  { color: var(--dwd-score-poor); }
.score-circle.danger  { color: var(--dwd-score-bad); }

/* ---- Wind Arrow ---- */
.wind-arrow {
  display: inline-block;
  color: var(--dwd-arrow-color);
  font-size: 1.2rem;
  transition: transform 0.5s ease;
}

/* ---- Hourly Timeline & Day-detail grid ---- */
/* Desktop/tablet: equal columns filling the width, no scroll */
#forecast-hourly,
#day-detail-grid {
  display: grid;
  grid-template-columns: repeat(24, minmax(0, 1fr));
  gap: 3px;
  padding-bottom: 0.5rem;
}
.hourly-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 0;         /* allow grid cells to shrink */
  padding: 0.35rem 0.1rem;
  border-radius: 0.4rem;
  border: 1px solid var(--bs-border-color);
  cursor: pointer;
  transition: background 0.15s;
  text-align: center;
  font-size: 0.7rem;
  overflow: hidden;
}
.hourly-card:hover { background: var(--bs-secondary-bg); }
.hourly-card.hour-active {
  background: rgba(13, 202, 240, 0.12);
  outline: 2px solid var(--bs-info);
  outline-offset: -1px;
}
.hourly-card.score-success { border-color: var(--dwd-score-good); }
.hourly-card.score-warning { border-color: var(--dwd-score-ok); }
.hourly-card.score-orange  { border-color: var(--dwd-score-poor); }
.hourly-card.score-danger  { border-color: var(--dwd-score-bad); }

.hourly-card .score-dot {
  width: 10px; height: 10px; border-radius: 50%;
  margin-bottom: 2px;
}
.score-success .score-dot { background: var(--dwd-score-good); }
.score-warning .score-dot { background: var(--dwd-score-ok); }
.score-orange  .score-dot { background: var(--dwd-score-poor); }
.score-danger  .score-dot { background: var(--dwd-score-bad); }

/* ---- Daily Cards ---- */
/* Desktop/tablet: 7 equal columns side by side */
#forecast-daily {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 3px;
}
.daily-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 0;
  padding: 0.35rem 0.1rem;
  border-radius: 0.4rem;
  border: 1px solid var(--bs-border-color);
  cursor: pointer;
  transition: background 0.15s;
  text-align: center;
  font-size: 0.72rem;
  overflow: hidden;
  gap: 2px;
}
.daily-card:hover { background: var(--bs-secondary-bg); }
.daily-card.score-success { border-color: var(--dwd-score-good); }
.daily-card.score-warning { border-color: var(--dwd-score-ok); }
.daily-card.score-orange  { border-color: var(--dwd-score-poor); }
.daily-card.score-danger  { border-color: var(--dwd-score-bad); }

/* ---- Wind altitude bars ---- */
.wind-bar-wrap { width: 100%; }
.wind-bar {
  height: 16px; border-radius: 4px;
  background: linear-gradient(90deg, #0d6efd, #0dcaf0);
  transition: width 0.4s ease;
  max-width: 100%;
}
.wind-bar.bg-danger {
  background: linear-gradient(90deg, #dc3545, #fd7e14);
}

/* ---- Planner ---- */
.mission-item {
  border-left: 3px solid;
  padding-left: 0.5rem;
  margin-bottom: 0.4rem;
  font-size: 0.82rem;
}
.mission-item.score-success { border-color: var(--dwd-score-good); }
.mission-item.score-warning { border-color: var(--dwd-score-ok); }
.mission-item.score-orange  { border-color: var(--dwd-score-poor); }
.mission-item.score-danger  { border-color: var(--dwd-score-bad); }

/* ============================================================
   MOBILE  ≤ 767px
   GridStack absolute layout → flex column stack
   ============================================================ */
@media (max-width: 767.98px) {

  /* ── Navbar ── */
  #main-navbar { padding: 0.2rem 0.5rem; }
  #main-navbar .navbar-brand span[data-i18n] { display: none; } /* icon only */

  /* ── Container ── */
  #app-container { padding: 0 !important; }

  /* ── GridStack reset ──
     Overrides ALL inline styles set by GridStack JS with !important  */
  #app-grid.grid-stack {
    display: flex !important;
    flex-direction: column !important;
    height: auto !important;
    min-height: 0 !important;
    gap: 6px;
    padding: 6px !important;
  }
  #app-grid > .grid-stack-item {
    position: static !important;
    width: 100% !important;
    height: auto !important;
    top: auto !important;
    left: auto !important;
    transform: none !important;
    margin: 0 !important;
  }
  #app-grid > .grid-stack-item > .grid-stack-item-content {
    position: relative !important;
    inset: auto !important;
    width: 100% !important;
    height: auto !important;   /* default: grow with content */
    overflow: hidden !important;
  }

  /* ── Card ordering ──
     1 Score  2 Prévisions  3 Vent  4 Carte  5 Lieu  6 Profil  7 Planif */
  #item-current  { order: 1; }
  #item-forecast { order: 2; }
  #item-wind     { order: 3; }
  #item-map      { order: 4; }
  #item-location { order: 5; }
  #item-profile  { order: 6; }
  #item-planner  { order: 7; }

  /* ── Cards with height: auto need Bootstrap h-100 neutralised ── */
  #item-current  .card,
  #item-wind     .card,
  #item-location .card,
  #item-profile  .card { height: auto !important; }

  /* ── Cards that require a fixed height for internal scrolling ──
     Must use both a higher-specificity selector AND !important to beat the
     generic "height: auto !important" rule above (which has specificity 0,1,2,0).
     Adding #app-grid gives specificity 0,2,1,0 → wins when both have !important. */
  #app-grid > #item-forecast > .grid-stack-item-content { height: 440px !important; }
  #app-grid > #item-map      > .grid-stack-item-content { height: 220px !important; }
  #app-grid > #item-planner  > .grid-stack-item-content { height: 340px !important; }

  /* ── Score (item-current) ── */
  #item-current .card-body {
    padding: 0.5rem !important;
    max-height: 75vh;
    overflow-y: auto;
  }
  .score-circle { width: 60px; height: 60px; font-size: 1rem; border-width: 3px; }

  /* ── Forecast tabs ── */
  .nav-link { padding: 0.45rem 0.55rem !important; font-size: 0.82rem; }
  .nav-link i { display: none; }

  /* Mobile hourly / day-detail: vertical list, each hour = one full-width row */
  #forecast-hourly,
  #day-detail-grid {
    display: flex;
    flex-direction: column;
    gap: 2px;
    overflow-y: auto;
    padding-bottom: 0.25rem;
  }
  .hourly-card {
    flex-direction: row;
    align-items: center;
    width: 100%;
    padding: 0.3rem 0.6rem;
    gap: 0.5rem;
    font-size: 0.8rem;
    text-align: left;
    overflow: visible;
  }
  /* score-dot: horizontal, no bottom margin */
  .hourly-card > .score-dot  { flex-shrink: 0; margin-bottom: 0; }
  /* time */
  .hourly-card > strong      { width: 2.8rem; flex-shrink: 0; }
  /* weather icon */
  .hourly-card > i           { width: 1.4rem; text-align: center; flex-shrink: 0; font-size: 1rem; }
  /* temp */
  .hourly-card > span:nth-child(4) { flex: 1; }
  /* wind */
  .hourly-card > span:nth-child(5) { flex: 1; text-align: right; }
  /* score number */
  .hourly-card > span:nth-child(6) { flex-shrink: 0; min-width: 1.8rem; text-align: right; font-weight: 700; }

  /* Mobile daily: vertical list, one day per row */
  #forecast-daily {
    display: flex;
    flex-direction: column;
    gap: 2px;
  }
  .daily-card {
    flex-direction: row;
    align-items: center;
    width: 100%;
    padding: 0.3rem 0.6rem;
    gap: 0.5rem;
    font-size: 0.8rem;
    text-align: left;
    overflow: visible;
  }
  .daily-card > .score-dot        { flex-shrink: 0; margin-bottom: 0; }
  .daily-card > strong            { width: 3.5rem; flex-shrink: 0; }
  .daily-card > i                 { width: 1.4rem; text-align: center; flex-shrink: 0; font-size: 1rem; }
  .daily-card > span:nth-child(4) { flex: 1.2; }                   /* temp min/max */
  .daily-card > span:nth-child(5) { flex: 1; }                     /* wind + arrow */
  .daily-card > span:nth-child(6) { flex: 0 0 2.2rem; text-align: right; } /* rain % */
  .daily-card > span:nth-child(7) { flex-shrink: 0; min-width: 1.8rem; text-align: right; font-weight: 700; } /* score */

  /* ── Charts ── */
  .chart-container        { height: 110px; }
  .chart-container canvas { max-height: 110px; }

  /* ── Wind altitude ── */
  #wind-altitude-body { padding: 0.4rem !important; }

  /* ── Map: Leaflet needs overflow:hidden ── */
  #item-map > .grid-stack-item-content { overflow: hidden !important; }
  #item-map .card,
  #item-map .card-body { height: 100%; }

  /* ── Touch targets: bigger card headers ── */
  .card-header { padding: 0.45rem 0.65rem !important; min-height: 40px; }

  /* ── Mobile reorder buttons ── */
  .mobile-order-btn {
    padding: 0 !important;
    width: 28px; height: 28px;
    display: flex; align-items: center; justify-content: center;
    font-size: 0.75rem;
    opacity: 0.7;
  }

  /* ── Hide drag UI ── */
  .drag-hint { display: none !important; }

  /* ── Bottom safe-area for phones with home bar ── */
  #app-grid { padding-bottom: max(6px, env(safe-area-inset-bottom)) !important; }
}

/* ---- Kp badge ---- */
.kp-badge {
  font-size: 0.9rem; font-weight: 700; padding: 0.3rem 0.6rem;
  border-radius: 50%; min-width: 2rem; text-align: center;
  display: inline-block;
}
.kp-low    { background: #198754; color: #fff; }
.kp-medium { background: #ffc107; color: #000; }
.kp-high   { background: #dc3545; color: #fff; }

/* ---- Loading spinner overlay ---- */
#loading-overlay {
  position: fixed; inset: 0; z-index: 9999;
  background: rgba(0,0,0,0.4);
  display: flex; align-items: center; justify-content: center;
}

/* ---- Animations ---- */
@keyframes spin { to { transform: rotate(360deg); } }
.spin { animation: spin 2s linear infinite; }

/* ---- Charts ---- */
.chart-container {
  position: relative;
  height: 140px;
}
.chart-container canvas {
  max-height: 140px;
  touch-action: none;  /* allow JS to handle touch on charts (crosshair drag) */
}

@keyframes fadeIn { from { opacity:0; transform:translateY(4px); } to { opacity:1; transform:none; } }
.fade-in { animation: fadeIn 0.25s ease forwards; }

/* ---- Charts grid wrapper ---- */
#charts-grid-wrapper {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.chart-cell { min-width: 0; }

/* 2×2 grid mode */
#charts-grid-wrapper.grid-2x2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}
/* Height variants — apply to BOTH stacked and 2×2 layouts.
   Controlled by grid-h1x / grid-h2x / grid-h3x on #charts-grid-wrapper.
   1x = 115 px, 2x = 230 px (défaut), 3x = 345 px */
#charts-grid-wrapper.grid-h1x .chart-container,
#charts-grid-wrapper.grid-h1x .chart-container canvas { height: 115px !important; max-height: 115px !important; }
#charts-grid-wrapper.grid-h2x .chart-container,
#charts-grid-wrapper.grid-h2x .chart-container canvas { height: 230px !important; max-height: 230px !important; }
#charts-grid-wrapper.grid-h3x .chart-container,
#charts-grid-wrapper.grid-h3x .chart-container canvas { height: 345px !important; max-height: 345px !important; }

/* ---- Hide-tile button (shown on hover) ---- */
.btn-hide-tile {
  opacity: 0;
  transition: opacity 0.15s;
  line-height: 1;
}
.card-header:hover .btn-hide-tile { opacity: 0.6; }
.btn-hide-tile:hover               { opacity: 1 !important; }

/* ---- Selected daily card ---- */
.daily-card.day-active {
  background: rgba(13, 202, 240, 0.12);
  outline: 2px solid var(--bs-info);
  outline-offset: -1px;
}

/* ---- Score color utility ---- */
.text-orange { color: var(--dwd-score-poor) !important; }
.bg-score-good   { background-color: var(--dwd-score-good) !important; }
.bg-score-ok     { background-color: var(--dwd-score-ok) !important; }
.bg-score-poor   { background-color: var(--dwd-score-poor) !important; }
.bg-score-bad    { background-color: var(--dwd-score-bad) !important; }
