:root{
  --bg: #f6f7fb;
  --card: #ffffff;
  --border: #e6e8f0;
  --text: #1f2937;
  --muted: #6b7280;
  --muted2: #ffffff;
  --primary: #3b82f6;
  --primary2: #2563eb;
  --shadow: 0 10px 25px rgba(0,0,0,.08);
  --radius: 14px;
}

*{ box-sizing: border-box; }
html,body{ height:100%; }
body{
  margin:0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, "Noto Sans", "Liberation Sans", sans-serif;
  color: var(--text);
  background: var(--bg);
}

.app{ height:100vh; display:flex; }
.app.is-sidebar-collapsed .sidebar{
  transform: translateX(-100%);
  width: 0;
  padding: 0;
  border-right: none;
  overflow: hidden;
  pointer-events: none;
}
.app.is-sidebar-collapsed .main{
  width: 100%;
}

/* Sidebar */
.sidebar{
  width: 480px; /* 320 × 1.5 */
  background: var(--card);
  border-right: 1px solid var(--border);
  padding: 20px;
  overflow:auto;
  transition: transform .25s ease, width .25s ease;
  will-change: transform;
}
.sidebar__header{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
  margin-bottom:16px;
}
.sidebar__actions{ display:flex; align-items:center; gap:8px; }
.sidebar h2{ font-size: 20px; margin:0; }

.addbox{
  background:#f3f4f6;
  border:1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 14px;
}
.addbox input, .addbox select{
  width:100%;
  padding:10px 12px;
  border-radius:10px;
  border:1px solid #d1d5db;
  outline:none;
  margin-bottom:10px;
  background:#fff;
}
.addbox input:focus, .addbox select:focus{
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59,130,246,.18);
}
.addbox__row{ display:flex; gap:10px; }
.addbox__row input{ margin-bottom:10px; }

.hidden{ display:none; }

.missions{ display:flex; flex-direction:column; gap:14px; }
.mission-group{ display:flex; flex-direction:column; gap:10px; }
.mission-group__title{
  font-size: 12px;
  font-weight: 900;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--muted);
}
.mission, .assigned{
  border-radius: 12px;
  padding: 8px 10px;
  border-left: 6px solid transparent;
  box-shadow: 0 2px 10px rgba(0,0,0,.06);
  cursor: pointer;
  user-select:none;
  transition: transform .08s ease, box-shadow .15s ease;
}
.mission:hover, .assigned:hover{ box-shadow: 0 8px 18px rgba(0,0,0,.10); transform: translateY(-1px); }
.mission[draggable="true"], .assigned[draggable="true"]{ cursor: grab; }
.mission__row{
  display:flex;
  align-items:center;
  gap:8px;
  min-width:0;
}
.mission__time{
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}
.mission__name{
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.mission__desc{
  margin-top: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.mission__hours{
  margin-left:auto;
  display:flex;
  align-items:center;
  gap:10px;
  white-space: nowrap;
  text-align:right;
  color: var(--text);
}
.mission__hours-total{
  font-weight: 800;
}
.mission__hours-done{
  font-weight: 700;
  color: var(--muted);
}

.missions-summary{
  position: sticky;
  bottom: 0;
  margin-top: 12px;
  padding-top: 12px;
  padding-bottom: 8px;
  border-top: 1px solid var(--border);
  background: var(--card);
}
.missions-summary__row{
  display:flex;
  align-items:center;
  justify-content:space-between;
  font-size: 13px;
  color: var(--muted);
  padding: 2px 0;
}
.missions-summary__row--strong{
  color: var(--text);
  font-weight: 800;
}

/* Main */
.main{
  flex:1;
  padding: 20px;
  overflow: hidden;
  display:flex;
  flex-direction: column;
  min-height: 0;
}
.main__header{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:16px;
  margin-bottom: 16px;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 5;
  padding-top: 8px;
  padding-bottom: 8px;
}
.main__title{ display:flex; align-items:center; gap:8px; }
.main__actions{ display:flex; align-items:center; gap:12px; }
.main h2{ margin:0; font-size: 22px; }

/* Buttons */
.btn{
  border:1px solid transparent;
  border-radius: 12px;
  padding: 10px 14px;
  font-weight: 850;
  cursor:pointer;
  transition: transform .08s ease, background .15s ease, border-color .15s ease;
  line-height: 1;
  white-space: nowrap;
}
.btn:active{ transform: scale(.98); }
.btn--primary{ background: var(--primary); color:#fff; }
.btn--cancel{ background: var(--bg); color:#000; }
.btn--primary:hover{ background: var(--primary2); }
.btn--outline{
  background:#fff;
  border-color: var(--border);
  color: var(--text);
}
.btn--outline:hover{ background:#f3f4f6; }
.btn--toggle{
  background:#fff;
  border-color: var(--border);
  color: var(--text);
  padding: 8px 12px;
  font-size: 13px;
}
.btn--toggle.is-active{
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.btn--ghost{
  background:#fff;
  border-color: var(--border);
  color: var(--text);
  font-size: 16px;
  width: 44px;
  height: 44px;
  display:grid;
  place-items:center;
}
.btn--ghost:hover{ background:#f3f4f6; }
.btn.btn--expand{ display:none; }
.app.is-sidebar-collapsed .btn.btn--expand{ display:inline-flex; }

/* Week nav */
.weeknav{ display:flex; align-items:center; gap:12px; }
.weeknav__label{ min-width: 220px; text-align:center; }
.weeknav__title{ font-size: 16px; font-weight: 900; }
.weeknav__range{ font-size: 13px; color: var(--muted); margin-top:2px; }
.view-toggle{ display:flex; gap:6px; }

@media (max-width: 920px){
  .main__header{
    flex-direction: column;
    align-items: flex-start;
  }
  .main__actions{
    width: 100%;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    grid-template-areas:
      "weeknav weeknav weeknav"
      "viewweek viewmonth logout";
    gap: 10px;
    align-items: center;
  }
  .weeknav{
    grid-area: weeknav;
    width: 100%;
    justify-content: space-between;
  }
  .view-toggle{ display: contents; }
  #btnViewWeek{ grid-area: viewweek; }
  #btnViewMonth{ grid-area: viewmonth; }
  .btn--outline{
    grid-area: logout;
    width: 100%;
  }
}

/* Card + table */
.card{
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow:hidden;
  flex: 1 1 auto;
  min-height: 0;
}
.tablewrap{
  overflow: auto;
  height: 100%;
}

/* Largeurs fixes (plus de variation au drop) */
.planning{
  width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
  min-width: 920px;
}
.planning thead th{
  position: sticky;
  top: 0;
  z-index: 2;
  background:#f3f4f6;
  border-bottom: 1px solid var(--border);
  padding: 14px 10px;
  text-align:center;
  font-weight: 900;
  color:#374151;
}
.planning thead th:first-child{
  text-align:left;
  width: 105px;
  left: 0;
  z-index: 4;
}
.planning tbody th{
  width: 105px;
  padding: 14px 10px;
  text-align:left;
  font-weight: 500;
  color:#374151;
  background:#fff;
  border-bottom:1px solid var(--border);
  position: sticky;
  left: 0;
  z-index: 3;
}
.operator-cell{ cursor: pointer; }
.op-name{ display:inline-block; line-height: 1.1; }
.op-name__last{ display:block; }

@media (max-width: 520px){
  .planning thead th:first-child,
  .planning tbody th{
    width: 80px;
  }
  .op-name__last{ display:block; }
}
.planning tbody td{
  width: calc((100% - 150px) / 7);
  border-bottom:1px solid var(--border);
  vertical-align: top;
}
.planning tbody tr:nth-child(even) th{ background:#fafafa; }
.planning tbody tr:nth-child(even) td{ background:#fafafa; }

.dayhead__date{
  display:block;
  font-weight: 600;
  color: var(--muted);
  font-size: 12px;
  margin-top:4px;
}

/* Cell */
.cell{
  padding: 8px;
  min-height: 96px;
  position: relative;
  overflow: hidden;
}
.cell-content{
  min-width: 0;
  height: 100%;
  display:flex;
  flex-direction:column;
  gap: 6px;
}
.dropzone{
  height: 64px;
  border: 2px dashed #d1d5db;
  border-radius: 12px;
  display:flex;
  align-items:center;
  justify-content:center;
  color:#9ca3af;
  font-size: 13px;
}

/* Assigned blocks */
.assigned{
  min-width: 0;
  padding: 6px 8px;
  font-size: 13px;
  position: relative;
  cursor: pointer; /* clic = edit planification */
  user-select:none;
  overflow:hidden;
}
.assigned .mission__row{ padding-right: 26px; }
.assigned.is-highlight{
  box-shadow: 0 0 0 2px #1d4ed8 inset;
}
.assigned__remove{
  position:absolute;
  top:6px;
  right:6px;
  width: 22px;
  height: 22px;
  border-radius: 999px;
  border: none;
  cursor:pointer;
  background: rgba(255,255,255,.92);
  color: #111827;
  font-weight: 900;
  opacity: 0;
  transition: opacity .15s ease;
}
.assigned:hover .assigned__remove{ opacity: 1; }

/* Overlay Move/Copy (stable) */
.overlay{
  position:absolute;
  inset: 6px;
  border-radius: 12px;
  overflow:hidden;
  z-index: 10;
  display:flex;
  pointer-events: none;
}
.overlay--month{
  inset: 0;
  border-radius: 12px;
  flex-direction: column;
}
.overlay__half{
  width:50%;
  display:flex;
  align-items:center;
  justify-content:center;
  font-weight: 600;
  font-size: 13px;
  pointer-events: auto;
}
.overlay__half + .overlay__half{ border-left: 3px solid rgba(255,255,255,.9); }
.overlay--month .overlay__half{
  width: 100%;
  height: 50%;
}
.overlay--month .overlay__half + .overlay__half{
  border-left: none;
  border-top: 3px solid rgba(255,255,255,.9);
}
.overlay__half--move{ background: rgba(59,130,246,.18); color: #1d4ed8; }
.overlay__half--copy{ background: rgba(16,185,129,.18); color: #047857; }
.overlay__half.is-active{ color:#fff; }
.overlay__half--move.is-active{ background: rgba(37,99,235,.95); }
.overlay__half--copy.is-active{ background: rgba(16,185,129,.95); }

/* Hint */
.hint{
  margin-top: 14px;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  color: #1e40af;
  padding: 12px 14px;
  border-radius: 12px;
  font-size: 13px;
  position: sticky;
  bottom: 0;
  z-index: 4;
}

/* Panel */
.panel-backdrop{
  position: fixed;
  inset: 0;
  background: rgba(17,24,39,.45);
  display:flex;
  align-items: stretch;
  justify-content:flex-end;
  padding: 0;
  z-index: 999;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease;
}
.panel-backdrop.is-open{
  opacity: 1;
  pointer-events: auto;
}
.panel{
  width: min(520px, 100%);
  height: 100%;
  background: #fff;
  box-shadow: -20px 0 60px rgba(0,0,0,.25);
  transform: translateX(100%);
  transition: transform .25s ease;
  display:flex;
  flex-direction: column;
}
.panel-backdrop.is-open .panel{ transform: translateX(0); }
.modal__header{
  display:flex;
  align-items:flex-start;
  justify-content:space-between;
  gap:12px;
  padding: 14px 14px 10px;
  background: #3b82f6;
  border-bottom: 1px solid var(--border);
  color: #fff;
}
.modal__title{ font-weight: 950; font-size: 16px; }
.modal__subtitle{ color: var(--muted2); font-size: 12px; margin-top:4px; }

.modal__body{ padding: 14px; display:flex; flex-direction:column; gap:12px; }
.mission-progress{
  margin-bottom: 6px;
}
.mission-progress__bar{
  height: 10px;
  background: #e5e7eb;
  border-radius: 999px;
  overflow: hidden;
  display:flex;
}
.mission-progress__segment{
  height: 100%;
}
.mission-progress__done{
  background: #1e3a8a;
}
.mission-progress__planned{
  background: repeating-linear-gradient(
    45deg,
    #3b82f6,
    #3b82f6 6px,
    #93c5fd 6px,
    #93c5fd 12px
  );
}
.mission-progress__remaining{
  background: #d1d5db;
}
.mission-assignments{
  background: #f9fafb;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
}
.mission-assignments__title{
  font-size: 12px;
  font-weight: 800;
  color: var(--muted);
  margin-bottom: 8px;
}
.mission-assignments__tablewrap{
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
}
.mission-assignments__table{
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.mission-assignments__table th,
.mission-assignments__table td{
  text-align: left;
  padding: 6px 4px;
  border-bottom: 1px solid #e5e7eb;
}
.mission-assignments__table th:first-child,
.mission-assignments__table td:first-child{
  width: 10px;
  padding: 0;
}
.mission-assignments__status{
  display:block;
  width: 6px;
  height: 100%;
  min-height: 24px;
}
.mission-assignments__status--done{
  background: #1e3a8a;
}
.mission-assignments__status--planned{
  background: repeating-linear-gradient(
    45deg,
    #3b82f6,
    #3b82f6 6px,
    #93c5fd 6px,
    #93c5fd 12px
  );
}
.mission-assignments__table thead th{
  position: sticky;
  top: 0;
  background: #f3f4f6;
  z-index: 1;
}
.mission-assignments__table tbody tr:last-child td{
  border-bottom: none;
}
.field{ display:flex; flex-direction:column; gap:6px; }
.field span{ font-size: 12px; color: var(--muted); font-weight: 850; }
.field input, .field select{
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid #d1d5db;
  outline:none;
}
.field input:focus, .field select:focus{
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59,130,246,.18);
}
.grid2{ display:grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.modal__footer{
  padding: 12px 14px 14px;
  border-top: 1px solid var(--border);
  display:flex;
  justify-content:flex-end;
  gap:10px;
}
.modal__extras{
  padding: 0 14px 14px;
  display:flex;
  flex-direction:column;
  gap:12px;
  flex: 1 1 auto;
  min-height: 0;
}

/* IMPORTANT: corrige la modale qui s'ouvrait au chargement */
.panel-backdrop.hidden{ display: none; }

/* Login */
.login-page{
  background: var(--bg);
  display:flex;
  align-items:center;
  justify-content:center;
  padding: 24px;
}
.planning.is-month thead th{
  padding: 10px 6px;
  font-size: 12px;
  min-width: 48px;
}
.planning.is-month tbody th{
  padding: 10px 8px;
}
.planning.is-month tbody td{
  width: 110px;
  min-width: 48px;
}
.planning.is-month .is-week-sep{
  border-left: 3px solid var(--border);
}
.planning.is-month .dropzone{
  display: none;
}
.planning .is-outside{
  opacity: .55;
}
.login-card{
  width: min(420px, 100%);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 24px;
}
.login-title{
  margin: 0 0 6px;
  font-size: 22px;
}
.login-subtitle{
  margin: 0 0 18px;
  color: var(--muted);
  font-size: 13px;
}
.login-form{
  display:flex;
  flex-direction:column;
  gap: 12px;
}
.login-submit{
  width: 100%;
}
.login-error{
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #991b1b;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 12px;
}
.mission[style*="#ef4444"],
.mission[data-color="#ef4444"],
.assigned[data-color="#ef4444"] {
  border-left-color: #ef4444 !important;
  background-color: rgba(239, 68, 68, 0.16) !important;
}

.mission[style*="#3b82f6"],
.mission[data-color="#3b82f6"],
.assigned[data-color="#3b82f6"] {
  border-left-color: #7c3aed !important;
  background-color: rgba(124, 58, 237, 0.16) !important;
}

.mission[style*="#10b981"],
.mission[data-color="#10b981"],
.assigned[data-color="#10b981"] {
  border-left-color: #22c55e !important;
  background-color: rgba(34, 197, 94, 0.16) !important;
}

.mission[style*="#f59e0b"],
.mission[data-color="#f59e0b"],
.assigned[data-color="#f59e0b"] {
  border-left-color: #111111 !important;
  background-color: rgba(17, 17, 17, 0.16) !important;
}


/* Operator week page */
.operator-week-page{
  background: var(--bg);
}
.operator-week{
  min-height: 100vh;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.operator-week__header{
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.operator-week__title h1{
  margin: 0;
  font-size: 24px;
}
.operator-week__subtitle{
  color: var(--muted);
  margin-top: 4px;
}
.operator-week__actions{
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.operator-week__range{
  font-weight: 800;
  color: var(--text);
  padding: 6px 10px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 999px;
}
.operator-week__card{
  padding: 12px;
}
.operator-week__days{
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 12px;
}
.operator-week__day{
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  min-height: 220px;
  display: flex;
  flex-direction: column;
}
.operator-week__day-header{
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.operator-week__day-name{
  font-weight: 800;
}
.operator-week__day-date{
  color: var(--muted);
  font-size: 12px;
}
.operator-week__list{
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.operator-week__assignment{
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  background: #f9fafb;
}
.operator-week__assignment-title{
  font-weight: 700;
  margin-bottom: 6px;
}
.operator-week__assignment-meta{
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 12px;
}
.operator-week__empty{
  color: var(--muted);
  font-size: 13px;
}
.operator-week__hint{
  color: var(--muted);
  font-size: 12px;
}

@media (max-width: 900px){
  .operator-week{
    padding: 16px;
  }
  .operator-week__days{
    display: flex;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    gap: 12px;
    padding-bottom: 4px;
  }
  .operator-week__days::-webkit-scrollbar{ display: none; }
  .operator-week__day{
    min-width: 100%;
    scroll-snap-align: start;
  }
}
