/* ════════════════════════════════════════════════════════════════════════
   AquaWatch — Postes de Relevage
   Identité visuelle : bleu marin + turquoise (cohérent avec le logo)
   ════════════════════════════════════════════════════════════════════════ */

:root {
  /* Palette AquaWatch */
  --aw-deep:    #0C1A2E;   /* bleu marin foncé (logo) */
  --aw-navy:    #0A1628;   /* bleu marin (logo) */
  --aw-blue:    #0066CC;   /* bleu vif (logo) */
  --aw-teal:    #06D6B0;   /* turquoise (logo) */
  --aw-cyan:    #00B4D8;   /* cyan secondaire */

  /* Surfaces */
  --bg:         #f0f4f8;
  --panel:      #ffffff;
  --panel-2:    #e6edf3;
  --line:       #c9d3df;

  /* Texte */
  --text:       #1a2332;
  --muted:      #5d6b7d;

  /* États */
  --warn:       #ffb547;
  --bad:        #e74c3c;
  --good:       #06D6B0;

  /* Effets */
  --shadow:     0 2px 8px rgba(12, 26, 46, 0.08);
  --shadow-hi:  0 4px 16px rgba(12, 26, 46, 0.18);
  --radius:     8px;
  --topbar-h:   60px;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.4;
  overscroll-behavior: none;
}
button { font-family: inherit; cursor: pointer; }

/* ════════════════════════════════════════════════════════════════════════
   TOPBAR — bleu marin avec dégradé + logo
   ════════════════════════════════════════════════════════════════════════ */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: linear-gradient(135deg, var(--aw-deep) 0%, var(--aw-navy) 50%, var(--aw-blue) 100%);
  color: #fff;
  box-shadow: var(--shadow);
  padding-top: env(safe-area-inset-top);
}
.topbar-row {
  display: flex;
  align-items: center;
  gap: 10px;
  height: var(--topbar-h);
  padding: 0 14px;
  max-width: 1600px;
  margin: 0 auto;
}

/* Brand : logo + nom */
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: #fff;
  flex-shrink: 0;
  padding: 4px 8px;
  border-radius: 6px;
  transition: background .15s;
}
.brand:hover { background: rgba(255,255,255,.08); }
.brand-logo {
  width: 38px;
  height: 38px;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,.3));
}
.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
}
.brand-name {
  font-weight: 700;
  font-size: 17px;
  letter-spacing: .02em;
  background: linear-gradient(90deg, #fff 0%, var(--aw-teal) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
.brand-tag {
  font-size: 11px;
  color: rgba(255,255,255,.7);
  font-weight: 500;
  letter-spacing: .04em;
  text-transform: uppercase;
}

.topbar select {
  flex: 1;
  background: rgba(255,255,255,.95);
  color: var(--text);
  border: none;
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 14px;
  font-weight: 500;
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'><path d='M2 4l4 4 4-4' stroke='%231a2332' stroke-width='2' fill='none' stroke-linecap='round'/></svg>");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 30px;
  min-width: 0;
}
.icon-btn {
  background: rgba(255,255,255,.12);
  color: #fff;
  border: none;
  width: 40px; height: 40px;
  border-radius: 6px;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  text-decoration: none;
  transition: background .15s;
}
.icon-btn:hover, .icon-btn:active { background: rgba(255,255,255,.25); }

/* Bannière dernière tournée */
.banner {
  background: rgba(6, 214, 176, 0.18);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  padding: 6px 12px;
  white-space: nowrap;
  overflow: hidden;
  border-top: 1px solid rgba(255,255,255,.08);
}
.banner-text {
  display: inline-block;
  padding-left: 100%;
  animation: scroll-left 30s linear infinite;
}
@keyframes scroll-left {
  from { transform: translateX(0); }
  to   { transform: translateX(-100%); }
}

/* ════════════════════════════════════════════════════════════════════════
   ACCUEIL
   ════════════════════════════════════════════════════════════════════════ */
.view { padding: 20px 16px; max-width: 1600px; margin: 0 auto; }
.home-header {
  text-align: center;
  margin-bottom: 28px;
  padding: 8px 0;
}
.home-header h1 {
  margin: 0 0 6px;
  font-size: 28px;
  color: var(--aw-deep);
  font-weight: 700;
}
.home-header .subtitle {
  margin: 0;
  color: var(--muted);
  font-size: 15px;
}

.commune-list {
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.commune-block {
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  border-left: 4px solid var(--aw-teal);
}
.commune-block h2 {
  margin: 0 0 14px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--aw-deep);
  border-bottom: 1px solid var(--line);
  padding-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.commune-count {
  font-weight: 400;
  color: var(--muted);
  font-size: 12px;
  margin-left: auto;
}
.poste-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 10px;
}
.poste-card {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  background: linear-gradient(135deg, var(--panel-2) 0%, #f0f5fb 100%);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px 14px;
  text-decoration: none;
  color: var(--text);
  transition: all .15s;
  cursor: pointer;
  position: relative;
}
.poste-card:hover {
  background: linear-gradient(135deg, var(--aw-navy) 0%, var(--aw-blue) 100%);
  color: #fff;
  border-color: var(--aw-blue);
  transform: translateY(-2px);
  box-shadow: var(--shadow-hi);
}
.poste-card-name { font-weight: 600; font-size: 14px; }
.poste-card[data-no-plan] { opacity: 0.7; }
.poste-card[data-no-plan]::after {
  content: "Sans plan";
  font-size: 10px;
  background: var(--warn);
  color: var(--aw-deep);
  padding: 1px 6px;
  border-radius: 3px;
  align-self: flex-start;
  margin-top: 6px;
  font-weight: 700;
}
.loading, .error-block {
  text-align: center;
  color: var(--muted);
  padding: 40px;
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.error-block h3 { color: var(--bad); margin: 0 0 12px; }
.error-block code {
  background: var(--panel-2);
  padding: 2px 6px;
  border-radius: 3px;
  font-size: 13px;
}

/* ════════════════════════════════════════════════════════════════════════
   VUE POSTE
   ════════════════════════════════════════════════════════════════════════ */
.poste-layout {
  display: grid;
  grid-template-columns: 220px 1fr 260px;
  gap: 12px;
  align-items: start;
}
.sidebar {
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  position: sticky;
  top: calc(var(--topbar-h) + 12px);
  max-height: calc(100vh - var(--topbar-h) - 24px);
  overflow-y: auto;
}
.sidebar-title {
  margin: 0 0 12px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--aw-deep);
  border-bottom: 2px solid var(--aw-teal);
  padding-bottom: 8px;
}

.chip-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 10px;
}
.chip {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  transition: all .12s;
  text-align: left;
  width: 100%;
}
.chip:hover { background: #d8e2ed; }
.chip[data-active="true"] {
  background: var(--aw-blue);
  color: #fff;
  border-color: var(--aw-blue);
}
.chip-dot {
  width: 12px; height: 12px;
  border-radius: 50%;
  border: 2px solid #fff;
  flex-shrink: 0;
  box-shadow: 0 0 0 1px rgba(0,0,0,.2);
}
.filter-actions {
  display: flex;
  justify-content: space-between;
  gap: 4px;
}
.link-btn {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 12px;
  text-decoration: underline;
  padding: 4px;
}
.link-btn:hover { color: var(--aw-blue); }

/* Tournées sidebar */
.link-list { display: flex; flex-direction: column; gap: 8px; }
.tournee-item {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-left: 3px solid var(--aw-teal);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 12px;
  cursor: pointer;
  transition: all .12s;
}
.tournee-item:hover {
  background: #d8e2ed;
  border-left-color: var(--aw-blue);
}
.tournee-item .t-date {
  font-weight: 700;
  color: var(--aw-deep);
}
.tournee-item .t-agent {
  color: var(--muted);
  margin-top: 2px;
}
.urg {
  display: inline-block;
  padding: 2px 6px;
  border-radius: 3px;
  font-size: 10px;
  text-transform: uppercase;
  font-weight: 700;
  margin-top: 4px;
}
.urg-urgente { background: var(--bad); color: #fff; }
.urg-normale { background: var(--good); color: var(--aw-deep); }

/* Plan */
.plan-zone { position: relative; min-width: 0; }
.plan-empty {
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 80px 20px;
  text-align: center;
  color: var(--muted);
}
.plan-empty .empty-icon {
  font-size: 56px;
  margin-bottom: 16px;
  opacity: 0.5;
}
.plan-empty p { margin: 6px 0; }
.plan-empty .muted { color: var(--muted); font-size: 13px; }
.plan-wrap {
  position: relative;
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  width: 100%;
  border: 1px solid var(--line);
}
.plan-wrap img {
  display: block;
  width: 100%;
  height: auto;
  user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;
}
.points-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.points-layer > * { pointer-events: auto; }

.pt {
  position: absolute;
  transform: translate(-50%, -50%);
}
.pt-dot {
  width: 14px; height: 14px;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px rgba(0,0,0,.4), 0 1px 4px rgba(0,0,0,.3);
  cursor: pointer;
  transition: transform .12s;
}
.pt-dot:hover, .pt-dot:active {
  transform: translate(-50%, -50%) scale(1.4);
}
.pt-special {
  width: 18px; height: 18px;
  background: var(--bad);
  border-radius: 50%;
  border: 3px solid #fff;
  box-shadow: 0 0 0 1px rgba(0,0,0,.4), 0 0 10px rgba(231,76,60,.6);
  cursor: pointer;
  animation: pulse 2s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 1px rgba(0,0,0,.4), 0 0 0 0 rgba(231,76,60,.6); }
  50%      { box-shadow: 0 0 0 1px rgba(0,0,0,.4), 0 0 0 6px rgba(231,76,60,0); }
}
.pt-panneau {
  background: var(--warn);
  color: var(--aw-deep);
  border: 2px solid #b38700;
  border-radius: 6px;
  padding: 6px 10px;
  font-weight: 700;
  font-size: 13px;
  text-align: center;
  line-height: 1.2;
  white-space: nowrap;
  box-shadow: 0 2px 6px rgba(0,0,0,.3);
  cursor: pointer;
}
.pt-image {
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  cursor: pointer;
}
.pt[hidden] { display: none !important; }

/* Tooltip */
.tooltip {
  position: fixed;
  background: rgba(12, 26, 46, 0.95);
  color: #fff;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-hi);
  pointer-events: none;
  z-index: 1000;
  max-width: 200px;
  text-align: center;
  border: 1px solid var(--aw-teal);
}
.tooltip img {
  display: block;
  margin: 6px auto 0;
  max-width: 160px;
  max-height: 100px;
  border-radius: 4px;
}

/* ════════════════════════════════════════════════════════════════════════
   MODALE — fond clair, identité AquaWatch
   ════════════════════════════════════════════════════════════════════════ */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(12, 26, 46, .65);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  animation: fade-in .2s;
}
.modal[hidden] { display: none !important; }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.modal-card {
  background: linear-gradient(180deg, #f0f9ff 0%, #ffffff 30%);
  border-radius: 12px;
  box-shadow: var(--shadow-hi);
  border-top: 4px solid var(--aw-teal);
  max-width: 600px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  padding: 24px 28px;
  position: relative;
  animation: slide-up .25s;
}
@keyframes slide-up {
  from { transform: translateY(20px); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}
.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  background: var(--bad);
  color: #fff;
  border: none;
  width: 32px; height: 32px;
  border-radius: 50%;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 6px rgba(0,0,0,.2);
}
.modal-card h2 {
  margin: 0 0 16px;
  font-size: 18px;
  color: var(--aw-deep);
  padding-right: 40px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 12px;
}
.modal-card h3 {
  margin: 22px 0 10px;
  font-size: 14px;
  color: var(--aw-blue);
  font-weight: 700;
}
.modal-card p { margin: 8px 0; line-height: 1.5; }
.modal-card .equip-field {
  font-size: 14px;
  margin: 6px 0;
}
.modal-card .equip-field strong {
  color: var(--aw-deep);
}
.modal-card .equip-photo-wrap {
  text-align: center;
  margin: 16px 0;
}
.modal-card img.equip-photo {
  max-width: 90%;
  max-height: 220px;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: var(--shadow);
}
.modal-card .muted { color: var(--muted); font-size: 13px; }

.history-table-wrap {
  margin-top: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
  background: #fff;
}
.history-table-scroll { max-height: 280px; overflow-y: auto; }
.history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.history-table th, .history-table td {
  padding: 8px 10px;
  text-align: left;
  border-bottom: 1px solid var(--panel-2);
  vertical-align: top;
}
.history-table th {
  background: var(--aw-deep);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  position: sticky;
  top: 0;
}
.history-table tbody tr:hover { background: #f0f9ff; }

/* Footer */
.footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 16px;
  font-size: 12px;
  color: var(--muted);
  border-top: 1px solid var(--line);
  background: var(--panel);
}
.signature {
  font-weight: 700;
  opacity: .6;
  background: linear-gradient(90deg, var(--aw-deep) 0%, var(--aw-blue) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

/* ════════════════════════════════════════════════════════════════════════
   RESPONSIVE
   ════════════════════════════════════════════════════════════════════════ */
@media (max-width: 1100px) {
  .poste-layout { grid-template-columns: 200px 1fr 220px; }
}

@media (max-width: 768px) {
  .topbar-row { gap: 6px; padding: 0 8px; }
  .brand-text { display: none; }
  .brand-logo { width: 32px; height: 32px; }

  .poste-layout { grid-template-columns: 1fr; gap: 10px; }
  .sidebar {
    position: static;
    max-height: none;
    padding: 12px;
  }
  #sidebar-filters .chip-list {
    flex-direction: row;
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: 6px;
    margin-bottom: 6px;
    gap: 6px;
    -webkit-overflow-scrolling: touch;
  }
  #sidebar-filters .chip {
    flex-shrink: 0;
    white-space: nowrap;
    width: auto;
  }
  #sidebar-docs .link-list {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 6px;
  }
  #sidebar-docs .tournee-item {
    flex: 1;
    min-width: 130px;
  }
  .tooltip { display: none !important; }
  .pt-dot { width: 16px; height: 16px; }
  .pt-dot:hover { transform: translate(-50%, -50%); }
  .pt-panneau { font-size: 12px; padding: 5px 8px; }
  .modal-card { padding: 18px; }
  .home-header h1 { font-size: 22px; }
  .poste-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

:focus-visible { outline: 2px solid var(--aw-teal); outline-offset: 2px; }

/* ════════════════════════════════════════════════════════════════════════
   FORMULAIRE D'INTERVENTION (modale)
   ════════════════════════════════════════════════════════════════════════ */
.equip-actions {
  display: flex;
  justify-content: center;
  margin: 18px 0;
}
.btn-intervention {
  background: linear-gradient(135deg, var(--aw-blue) 0%, var(--aw-teal) 100%);
  color: #fff;
  border: none;
  padding: 12px 24px;
  border-radius: 6px;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(6, 214, 176, 0.3);
  transition: transform .12s, box-shadow .12s;
  width: 100%;
  max-width: 300px;
}
.btn-intervention:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(6, 214, 176, 0.4);
}
.btn-intervention:active {
  transform: translateY(0);
}

.intervention-form .form-row {
  margin-bottom: 14px;
}
.intervention-form .form-row label {
  display: block;
  font-size: 12px;
  font-weight: 700;
  color: var(--aw-deep);
  margin-bottom: 4px;
  letter-spacing: .03em;
  text-transform: uppercase;
}
.intervention-form input[type="datetime-local"],
.intervention-form input[type="text"],
.intervention-form select,
.intervention-form textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
  color: var(--text);
}
.intervention-form input:focus,
.intervention-form select:focus,
.intervention-form textarea:focus {
  outline: none;
  border-color: var(--aw-blue);
  box-shadow: 0 0 0 3px rgba(0, 102, 204, 0.15);
}
.intervention-form textarea { resize: vertical; min-height: 60px; }
.intervention-form .form-row-2cols {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.intervention-form .form-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
  justify-content: flex-end;
}
.intervention-form .btn-cancel,
.intervention-form .btn-submit {
  padding: 10px 20px;
  border-radius: 6px;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  border: none;
}
.intervention-form .btn-cancel {
  background: var(--panel-2);
  color: var(--muted);
  border: 1px solid var(--line);
}
.intervention-form .btn-cancel:hover { background: var(--line); }
.intervention-form .btn-submit {
  background: var(--aw-blue);
  color: #fff;
}
.intervention-form .btn-submit:hover { background: var(--aw-deep); }
.intervention-form .btn-submit:disabled { opacity: 0.6; cursor: wait; }

/* Toast de notification */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--aw-deep);
  color: #fff;
  padding: 12px 24px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  box-shadow: var(--shadow-hi);
  border-left: 3px solid var(--aw-teal);
  opacity: 0;
  pointer-events: none;
  transition: all .25s;
  z-index: 2000;
  max-width: 90vw;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
