* {
  box-sizing: border-box;
}

:root {
  --blue: #005493;
  --blue-dark: #003e70;
  --background: #eef3f7;
  --panel: #ffffff;
  --text: #1f2933;
  --muted: #5f6b76;
  --border: #d8e0e7;
  --soft: #f8fafc;
  --secondary: #667085;
  --danger: #b42318;
  --success: #176b39;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: Arial, Helvetica, sans-serif;
  background: var(--background);
  color: var(--text);
}

button,
input,
select,
textarea {
  font: inherit;
}

.app-header {
  min-height: 68px;
  padding: 10px 18px;
  background: var(--blue);
  color: white;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.app-header h1 {
  margin: 0;
  font-size: 22px;
}

.subtitle {
  margin-top: 3px;
  font-size: 12px;
  opacity: 0.85;
}

.header-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
}

.header-button {
  margin: 0;
  padding: 8px 10px;
  background: rgba(255, 255, 255, 0.14);
  border: 1px solid rgba(255, 255, 255, 0.35);
}

#status {
  font-size: 13px;
  white-space: nowrap;
}

.layout {
  display: grid;
  grid-template-columns: 380px minmax(0, 1fr) 370px;
  grid-template-rows: auto minmax(0, 1fr);
  grid-template-areas:
    "search map route"
    "results map route";
  height: calc(100vh - 68px);
}

.search-tools {
  grid-area: search;
  background: var(--panel);
  padding: 16px 16px 8px;
  border-right: 1px solid var(--border);
}

.results-panel {
  grid-area: results;
  background: var(--panel);
  padding: 4px 16px 16px;
  overflow-y: auto;
  border-right: 1px solid var(--border);
}

.map-panel {
  grid-area: map;
  position: relative;
  min-width: 0;
  min-height: 0;
}

#map {
  width: 100%;
  height: 100%;
  min-height: 340px;
}

.map-toolbar {
  position: absolute;
  z-index: 700;
  top: 10px;
  right: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-width: 250px;
}

.map-toolbar button {
  margin: 0;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18);
}

.map-toolbar .active {
  background: #b54708;
}

.route-panel {
  grid-area: route;
  background: var(--panel);
  padding: 16px;
  overflow-y: auto;
  border-left: 1px solid var(--border);
}

.route-panel h2 {
  margin-top: 0;
}

.route-panel h3 {
  margin: 22px 0 10px;
}

input,
select,
textarea {
  width: 100%;
  padding: 12px;
  border: 1px solid #cbd5df;
  border-radius: 10px;
  background: white;
  color: var(--text);
}

textarea {
  resize: vertical;
}

#search {
  margin-bottom: 10px;
  font-size: 16px;
}

.filters {
  display: grid;
  gap: 10px;
}

#counter {
  margin: 10px 0 14px;
  color: var(--muted);
  font-size: 14px;
}

.result {
  padding: 14px;
  margin-bottom: 10px;
  border: 1px solid #e2e8ee;
  border-radius: 12px;
  background: var(--soft);
}

.result:hover {
  background: #eef6fc;
}

.result-title {
  font-weight: 700;
  font-size: 16px;
}

.meta {
  margin: 7px 0 10px;
  color: var(--muted);
  font-size: 14px;
}

.badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 7px;
  border-radius: 999px;
  background: #e7eef5;
  color: #344054;
  font-size: 12px;
}

.badge.trusted {
  background: #e8f6ed;
  color: var(--success);
}

button,
.map-link {
  display: inline-block;
  margin: 4px 5px 4px 0;
  padding: 9px 11px;
  border: 0;
  border-radius: 8px;
  background: var(--blue);
  color: white;
  cursor: pointer;
  text-decoration: none;
  font-size: 13px;
}

button:hover,
.map-link:hover {
  background: var(--blue-dark);
}

button:disabled {
  background: #b8c1cb;
  cursor: not-allowed;
}

.secondary {
  background: var(--secondary);
}

.danger {
  background: var(--danger);
}

.empty {
  color: #777;
  font-style: italic;
}

.popup-title {
  margin-bottom: 5px;
  font-weight: 700;
}

.departure-options {
  margin: 0;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
}

.departure-options legend {
  padding: 0 6px;
  font-weight: 700;
}

.departure-options label {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 0;
  cursor: pointer;
}

.departure-options input[type="radio"] {
  width: auto;
  margin: 0;
}

.information-box {
  margin-top: 12px;
  padding: 11px;
  border-radius: 9px;
  background: #edf5fb;
  color: #31536d;
  font-size: 13px;
}

.start-stop-area {
  margin-top: 15px;
}

.start-stop-area > label {
  display: block;
  margin-bottom: 7px;
  font-weight: 700;
}

.hidden {
  display: none !important;
}

.start-result {
  padding: 9px;
  margin-top: 6px;
  border: 1px solid #dfe5eb;
  border-radius: 8px;
  background: var(--soft);
  cursor: pointer;
}

.start-result:hover {
  background: #eef6fc;
}

.selected-start {
  margin-top: 10px;
  padding: 11px;
  background: #eaf7ef;
  border: 1px solid #b9dfc7;
  border-radius: 9px;
}

.route-item {
  padding: 11px 0;
  border-bottom: 1px solid #e5e9ee;
}

.route-item-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 7px;
}

.route-item-buttons button {
  margin: 0;
}

.route-summary {
  margin-top: 12px;
  padding: 12px;
  background: #f3f8fc;
  border: 1px solid #d4e3ef;
  border-radius: 10px;
  font-size: 14px;
}

.route-actions {
  display: grid;
  gap: 8px;
  margin-top: 16px;
}

.route-actions button {
  width: 100%;
  margin: 0;
  padding: 11px;
  font-weight: 700;
}

.modal {
  width: min(720px, calc(100vw - 24px));
  max-height: calc(100vh - 24px);
  padding: 0;
  border: 0;
  border-radius: 14px;
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.3);
}

.modal::backdrop {
  background: rgba(15, 23, 42, 0.58);
}

.modal-card {
  padding: 18px;
  overflow-y: auto;
}

.modal-card.large {
  width: 100%;
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.modal-header h2 {
  margin: 0;
}

.icon-button {
  margin: 0;
  padding: 7px 10px;
  background: var(--secondary);
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.form-grid label,
.modal-card > label {
  display: grid;
  gap: 6px;
  font-weight: 700;
}

.full-width {
  grid-column: 1 / -1;
}

.modal-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
}

.modal-actions button {
  margin: 0;
}

.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 10px;
  margin-top: 14px;
}

.photo-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  background: var(--soft);
}

.photo-card img {
  display: block;
  width: 100%;
  height: 120px;
  object-fit: cover;
}

.library-item {
  padding: 14px;
  margin-bottom: 10px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--soft);
}

.library-item h3 {
  margin: 0 0 6px;
}

@media (max-width: 1000px) {
  .layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto 420px auto auto;
    grid-template-areas:
      "search"
      "map"
      "route"
      "results";
    height: auto;
  }

  .search-tools {
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .map-panel {
    height: 420px;
  }

  .route-panel {
    border-left: 0;
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    overflow: visible;
  }

  .results-panel {
    border-right: 0;
    overflow: visible;
  }
}

@media (max-width: 650px) {
  .app-header {
    align-items: flex-start;
    padding: 10px 12px;
  }

  .app-header h1 {
    font-size: 19px;
  }

  .header-actions {
    max-width: 58%;
  }

  .header-button {
    font-size: 11px;
    padding: 6px 7px;
  }

  #status {
    width: 100%;
    text-align: right;
    font-size: 11px;
  }

  .layout {
    grid-template-rows: auto 350px auto auto;
  }

  .map-panel {
    height: 350px;
  }

  .map-toolbar {
    left: 10px;
    right: 10px;
    top: 48px;
    max-width: none;
  }

  .map-toolbar button {
    font-size: 12px;
  }

  input,
  select,
  textarea {
    font-size: 16px;
  }

  button,
  .map-link {
    font-size: 14px;
    padding: 10px 12px;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .full-width {
    grid-column: auto;
  }
}


.admin-section {
  padding: 4px 0 14px;
}

.admin-section h3 {
  margin-top: 0;
}

.modal-actions.left {
  justify-content: flex-start;
}

.import-report {
  margin-top: 14px;
}

.import-summary {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--soft);
}

.import-summary strong {
  display: block;
  margin-bottom: 7px;
}

.import-progress {
  width: 100%;
  height: 12px;
  margin-top: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: #dfe7ee;
}

.import-progress > div {
  height: 100%;
  width: 0;
  background: var(--blue);
  transition: width 0.2s ease;
}

.route-stop-marker {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border: 3px solid white;
  border-radius: 50%;
  background: #005493;
  color: white;
  font-weight: 700;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}

.create-stop-cursor {
  cursor: crosshair !important;
}


.line-details {
  margin-top: 18px;
  min-height: 100px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--soft);
}

.line-title-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.line-color {
  width: 12px;
  height: 38px;
  border-radius: 999px;
  background: var(--blue);
}

.line-stop-list {
  max-height: 360px;
  overflow-y: auto;
  padding-left: 24px;
}

.line-stop-list li {
  margin: 7px 0;
}

.stop-lines-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 10px 0;
}

.stop-line-chip {
  padding: 5px 8px;
  border-radius: 999px;
  background: #eaf2f8;
  color: #154e75;
  font-size: 12px;
  cursor: pointer;
}

.gps-screen {
  position: fixed;
  z-index: 5000;
  inset: 0;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  background: #091522;
  color: white;
}

.gps-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: max(12px, env(safe-area-inset-top)) 14px 10px;
  background: #003e70;
}

.gps-route-name {
  font-size: 21px;
  font-weight: 800;
}

.gps-direction {
  margin-top: 3px;
  opacity: 0.85;
}

.gps-information {
  padding: 12px 16px;
  background: #0f2539;
  text-align: center;
}

.gps-next-label {
  font-size: 13px;
  text-transform: uppercase;
  opacity: 0.75;
}

.gps-next-stop {
  margin-top: 4px;
  font-size: 28px;
  font-weight: 800;
}

.gps-distance {
  margin-top: 3px;
  font-size: 22px;
}

.gps-following {
  margin-top: 5px;
  opacity: 0.8;
}

.gps-status {
  display: inline-block;
  margin-top: 9px;
  padding: 6px 10px;
  border-radius: 999px;
  background: #23445f;
  font-size: 13px;
}

.gps-status.off-route {
  background: #b42318;
}

.gps-status.on-route {
  background: #176b39;
}

.gps-map {
  min-height: 0;
}

.gps-footer {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 7px;
  padding: 9px 10px max(9px, env(safe-area-inset-bottom));
  background: #0f2539;
}

.gps-footer button {
  margin: 0;
}

@media (max-width: 650px) {
  .gps-footer {
    grid-template-columns: 1fr 1fr;
  }

  .gps-next-stop {
    font-size: 24px;
  }
}


.gps-map-rotator {
  position: absolute;
  inset: 0;
  transform-origin: 50% 50%;
  will-change: transform;
}

.gps-heading-marker {
  width: 34px;
  height: 34px;
  transform-origin: 50% 50%;
  transition: transform 0.25s linear;
}

.gps-heading-arrow {
  width: 0;
  height: 0;
  margin: 0 auto;
  border-left: 12px solid transparent;
  border-right: 12px solid transparent;
  border-bottom: 28px solid #1677ff;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.35));
}

.gps-follow-paused {
  background: #b54708 !important;
}

.gps-orientation-off {
  background: #667085 !important;
}


.sae-course-list {
  display: grid;
  gap: 12px;
  margin-top: 16px;
}

.sae-course-card {
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--soft);
  cursor: pointer;
}

.sae-course-card:hover {
  background: #eef6fc;
}

.sae-course-title {
  font-size: 17px;
  font-weight: 800;
}

.sae-course-meta {
  margin-top: 7px;
  color: var(--muted);
}

.sae-match-row {
  display: grid;
  grid-template-columns: 1fr 1.2fr;
  gap: 12px;
  padding: 13px 0;
  border-bottom: 1px solid var(--border);
}

.sae-match-source {
  font-weight: 700;
}

.sae-match-time {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.sae-screen {
  position: fixed;
  z-index: 6000;
  inset: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  background: #050706;
  color: white;
}

.sae-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 15px;
  min-height: 66px;
  padding: max(10px, env(safe-area-inset-top)) 18px 10px;
  background: #101311;
  border-bottom: 1px solid #2b302d;
}

.sae-course-name {
  font-size: 21px;
  font-weight: 900;
}

.sae-header-details {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
  font-size: 12px;
}

.sae-header-details span {
  padding: 3px 6px;
  border-radius: 5px;
  background: #222825;
}

.sae-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.sae-badge {
  padding: 7px 11px;
  border-radius: 999px;
  font-weight: 800;
  font-size: 12px;
}

.sae-badge-warning {
  background: #4c1515;
  color: #ff5b5b;
}

.sae-badge-success {
  background: #13391f;
  color: #65e488;
}

.sae-badge-passengers {
  background: #243b13;
  color: #8ce63f;
}

.sae-layout {
  display: grid;
  grid-template-columns: minmax(420px, 700px) minmax(0, 1fr);
  gap: 14px;
  min-height: 0;
  padding: 14px;
}

.sae-main-panel {
  min-width: 0;
  overflow-y: auto;
}

.sae-current-card,
.sae-next-card,
.sae-progress-card {
  margin-bottom: 14px;
  padding: 16px;
  border: 1px solid #343a36;
  border-radius: 14px;
  background: #111512;
}

.sae-current-card {
  border-color: #78d933;
  box-shadow: inset 0 0 0 1px rgba(120, 217, 51, 0.15);
}

.sae-section-label {
  color: #9fb0a5;
  font-size: 12px;
  font-weight: 800;
}

.sae-current-row,
.sae-next-card,
.sae-progress-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.sae-current-stop {
  margin-top: 7px;
  font-size: 29px;
  font-weight: 900;
}

.sae-time-row {
  margin-top: 5px;
  color: #adb8b1;
}

.sae-delay {
  min-width: 110px;
  padding: 12px;
  border-radius: 10px;
  text-align: center;
  font-size: 18px;
  font-weight: 900;
}

.sae-delay-early {
  background: #44200b;
  color: #ffa45d;
}

.sae-delay-late {
  background: #4e1111;
  color: #ff5e5e;
}

.sae-delay-ontime {
  background: #173d1d;
  color: #6de27e;
}

.sae-delay-neutral {
  background: #252a27;
  color: #d4dbd6;
}

.sae-count-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 18px;
}

.sae-count-box {
  padding: 11px;
  border: 1px solid #343a36;
  border-radius: 11px;
}

.sae-count-title {
  display: flex;
  justify-content: space-between;
  color: #aeb9b2;
  font-size: 12px;
}

.sae-count-title span {
  color: #79e338;
  font-size: 17px;
  font-weight: 900;
}

.sae-count-controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
  margin-top: 9px;
}

.sae-count-controls button {
  width: 100%;
  margin: 0;
  padding: 12px;
  font-size: 22px;
}

.sae-validate-button {
  width: 100%;
  margin-top: 14px;
  padding: 14px;
  background: #7fdf37;
  color: #081005;
  font-size: 17px;
  font-weight: 900;
}

.sae-next-stop-name {
  margin-top: 6px;
  font-size: 20px;
  font-weight: 800;
}

.sae-next-data {
  display: grid;
  gap: 6px;
  text-align: right;
}

.sae-next-data strong {
  color: #83e740;
  font-size: 22px;
}

.sae-progress-header {
  margin-bottom: 14px;
}

.sae-stop-progress {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 10px 4px 14px;
}

.sae-progress-stop {
  min-width: 120px;
  padding: 9px;
  border-top: 4px solid #434a46;
  color: #a9b3ad;
  font-size: 12px;
}

.sae-progress-stop.current {
  border-color: #7cdf38;
  color: #fff;
  font-weight: 800;
}

.sae-progress-stop.done {
  border-color: #226c35;
  color: #6f8f79;
}

.sae-map-panel {
  position: relative;
  min-width: 0;
  min-height: 0;
  border: 1px solid #343a36;
  border-radius: 14px;
  overflow: hidden;
}

#saeMap {
  width: 100%;
  height: 100%;
  min-height: 500px;
}

.sae-map-buttons {
  position: absolute;
  z-index: 700;
  top: 10px;
  right: 10px;
  display: grid;
  gap: 6px;
}

.sae-map-buttons button {
  margin: 0;
}

@media (max-width: 900px) {
  .sae-layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto 48vh;
    overflow-y: auto;
  }

  .sae-main-panel {
    overflow: visible;
  }

  .sae-map-panel {
    min-height: 48vh;
  }

  #saeMap {
    min-height: 48vh;
  }
}

@media (max-width: 600px) {
  .sae-header {
    align-items: flex-start;
    padding-left: 10px;
    padding-right: 10px;
  }

  .sae-course-name {
    font-size: 17px;
  }

  .sae-header-actions {
    flex-wrap: wrap;
    justify-content: flex-end;
  }

  .sae-count-grid {
    grid-template-columns: 1fr;
  }

  .sae-current-stop {
    font-size: 24px;
  }

  .sae-layout {
    padding: 8px;
  }
}


.stop-direction-badge {
  display: inline-block;
  margin-left: 5px;
  padding: 2px 6px;
  border-radius: 999px;
  background: #e8f1f8;
  color: #174d70;
  font-size: 11px;
  font-weight: 700;
}

.sae-map-buttons {
  max-height: calc(100% - 20px);
  overflow-y: auto;
}

.gps-heading-arrow {
  transform: rotate(0deg) !important;
}


/* V5.2 — SAE compact pour iPhone 16 */
.sae-layout-iphone {
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: auto minmax(340px, 52vh) auto;
  gap: 10px;
  overflow-y: auto;
  padding: 8px;
}

.sae-layout-iphone .sae-main-panel { overflow: visible; }

.sae-current-card-compact,
.sae-next-card-compact,
.sae-progress-card-compact {
  margin-bottom: 0;
  padding: 12px;
  border-radius: 12px;
}

.sae-current-topline {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}

.sae-current-card-compact .sae-current-stop {
  margin-top: 3px;
  font-size: 25px;
  line-height: 1.05;
}

.sae-current-card-compact .sae-delay {
  min-width: 104px;
  padding: 9px 10px;
  font-size: 15px;
  line-height: 1.15;
}

.sae-current-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 8px;
  color: #b8c1bb;
  font-size: 13px;
}

.sae-current-meta strong { color: #fff; }

.sae-count-inline {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 10px;
}

.sae-count-inline-group {
  display: grid;
  grid-template-columns: 28px 44px 34px 44px;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-width: 0;
  padding: 6px;
  border: 1px solid #343a36;
  border-radius: 10px;
  background: #0c100d;
}

.sae-count-inline-label {
  font-size: 19px;
  text-align: center;
}

.sae-count-inline-group strong {
  text-align: center;
  color: #80e63a;
  font-size: 18px;
}

.sae-count-inline-group button {
  width: 44px;
  min-width: 44px;
  height: 36px;
  margin: 0;
  padding: 0;
  border-radius: 8px;
  font-size: 20px;
  line-height: 1;
}

.sae-validate-button-compact {
  margin-top: 9px;
  padding: 10px;
  font-size: 15px;
}

.sae-next-card-compact {
  margin-top: 8px;
  min-height: 70px;
}

.sae-next-card-compact .sae-next-stop-name {
  margin-top: 4px;
  font-size: 18px;
}

.sae-next-card-compact .sae-next-data {
  font-size: 18px;
  font-weight: 800;
}

.sae-map-panel-iphone {
  min-height: 340px;
  height: 52vh;
  border-radius: 12px;
}

.sae-map-panel-iphone #saeMap {
  min-height: 340px;
  height: 100%;
}

.sae-map-buttons-compact {
  top: 8px;
  right: 8px;
  display: grid;
  grid-template-columns: repeat(5, 42px);
  gap: 5px;
}

.sae-map-buttons-compact button {
  width: 42px;
  min-width: 42px;
  height: 42px;
  margin: 0;
  padding: 0;
  font-size: 17px;
  border-radius: 9px;
}

.sae-progress-card-compact {
  margin-bottom: max(8px, env(safe-area-inset-bottom));
}

.sae-progress-card-compact .sae-progress-header {
  margin-bottom: 8px;
  font-size: 13px;
}

.sae-progress-card-compact .sae-stop-progress {
  padding-top: 6px;
  padding-bottom: 6px;
}

.sae-progress-card-compact .sae-progress-stop {
  min-width: 104px;
  padding: 7px;
  font-size: 11px;
}

@media (max-width: 650px) {
  .sae-screen { grid-template-rows: auto minmax(0, 1fr); }

  .sae-header {
    min-height: 58px;
    padding: max(7px, env(safe-area-inset-top)) 9px 7px;
  }

  .sae-course-name { font-size: 16px; }
  .sae-header-details { gap: 4px; font-size: 10px; }
  .sae-header-details span { padding: 2px 5px; }
  .sae-header-actions { gap: 5px; }
  .sae-badge { padding: 6px 8px; font-size: 10px; }
  .sae-header-actions .danger { padding: 8px 10px; font-size: 12px; }

  .sae-layout-iphone {
    grid-template-rows: auto minmax(320px, 49vh) auto;
    gap: 8px;
    padding: 7px;
  }

  .sae-map-panel-iphone {
    min-height: 320px;
    height: 49vh;
  }

  .sae-map-panel-iphone #saeMap { min-height: 320px; }

  .sae-current-card-compact .sae-current-stop { font-size: 23px; }

  .sae-count-inline-group {
    grid-template-columns: 24px 38px 28px 38px;
    gap: 4px;
  }

  .sae-count-inline-group button {
    width: 38px;
    min-width: 38px;
    height: 34px;
  }
}


/* ==========================================================
   V5.4 — interface SAE iPhone stable et sans débordement
   ========================================================== */

.sae-auto-summary {
  display: grid;
  gap: 7px;
  margin: 12px 0 16px;
  padding: 12px;
  border: 1px solid #9bcf72;
  border-radius: 11px;
  background: #eef9e8;
  color: #17320b;
}

.sae-auto-summary > div:first-child {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 6px;
}

.sae-auto-network {
  padding: 3px 7px;
  border-radius: 999px;
  background: #d8efc6;
  font-size: 12px;
}

.sae-auto-summary small {
  color: #42602f;
}

.sae-confidence {
  display: inline-block;
  margin-left: 6px;
  padding: 2px 6px;
  border-radius: 999px;
  font-weight: 800;
  font-size: 11px;
}

.sae-confidence.high {
  background: #dff4d4;
  color: #28650f;
}

.sae-confidence.medium {
  background: #fff0bf;
  color: #725700;
}

.sae-confidence.low {
  background: #ffe0dc;
  color: #9b2318;
}

@media (max-width: 650px) {
  html,
  body,
  .sae-screen {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
  }

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

  .sae-header {
    width: 100%;
    min-width: 0;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 6px;
    padding:
      max(8px, env(safe-area-inset-top))
      8px
      7px;
  }

  .sae-header > div:first-child {
    min-width: 0;
  }

  .sae-course-name {
    max-width: 100%;
    font-size: 17px;
    line-height: 1.1;
    overflow-wrap: anywhere;
  }

  .sae-header-details {
    gap: 4px;
    margin-top: 5px;
    font-size: 10px;
  }

  .sae-header-details span {
    padding: 2px 5px;
  }

  .sae-header-actions {
    display: grid;
    grid-template-columns: auto auto;
    gap: 5px;
    justify-items: stretch;
  }

  .sae-header-actions .danger {
    grid-column: 1 / 3;
    width: 100%;
    padding: 7px 9px;
  }

  .sae-badge {
    padding: 5px 7px;
    font-size: 10px;
  }

  /*
   * A single mobile column. The original desktop structure remains
   * untouched, which avoids the V5.3 JavaScript regression.
   */
  .sae-layout {
    width: 100%;
    min-width: 0;
    max-width: 100%;
    display: flex;
    flex-direction: column;
    gap: 8px;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 7px;
  }

  .sae-main-panel,
  .sae-map-panel {
    width: 100%;
    min-width: 0;
    max-width: 100%;
  }

  .sae-main-panel {
    display: contents;
  }

  .sae-current-card {
    order: 1;
    width: 100%;
    min-width: 0;
    margin: 0;
    padding: 10px;
  }

  .sae-next-card {
    order: 2;
    width: 100%;
    min-width: 0;
    min-height: 62px;
    margin: 0;
    padding: 10px;
  }

  .sae-map-panel {
    order: 3;
    min-height: 330px;
    height: 46vh;
    border-radius: 12px;
  }

  #saeMap {
    width: 100%;
    min-height: 330px;
    height: 100%;
  }

  .sae-progress-card {
    order: 4;
    width: 100%;
    min-width: 0;
    margin: 0 0 max(8px, env(safe-area-inset-bottom));
    padding: 10px;
  }

  .sae-current-row {
    align-items: center;
    gap: 7px;
  }

  .sae-current-row > div:first-child {
    min-width: 0;
    flex: 1;
  }

  .sae-current-stop {
    max-width: 100%;
    font-size: 23px;
    line-height: 1.05;
    overflow-wrap: anywhere;
  }

  .sae-delay {
    flex: 0 0 auto;
    min-width: 0;
    max-width: 43%;
    padding: 7px 8px;
    font-size: 13px;
    white-space: normal;
  }

  .sae-time-row {
    margin-top: 4px;
    font-size: 12px;
  }

  /*
   * Keep the original controls but flatten both passenger blocks onto
   * one compact row. No IDs are removed, so the stable event handlers
   * continue to work.
   */
  .sae-count-grid {
    width: 100%;
    min-width: 0;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 6px;
    margin-top: 9px;
  }

  .sae-count-box {
    min-width: 0;
    padding: 5px;
    border-radius: 9px;
  }

  .sae-count-title {
    align-items: center;
    font-size: 0;
  }

  .sae-count-box:first-child .sae-count-title::before {
    content: "⬆️";
    font-size: 17px;
  }

  .sae-count-box:last-child .sae-count-title::before {
    content: "⬇️";
    font-size: 17px;
  }

  .sae-count-title span {
    font-size: 16px;
  }

  .sae-count-controls {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 4px;
    margin-top: 4px;
  }

  .sae-count-controls button {
    width: 100%;
    min-width: 0;
    height: 31px;
    padding: 0;
    font-size: 18px;
  }

  .sae-validate-button {
    width: 100%;
    margin-top: 8px;
    padding: 9px;
    font-size: 15px;
  }

  .sae-next-card > div:first-child {
    min-width: 0;
    flex: 1;
  }

  .sae-next-stop-name {
    max-width: 100%;
    margin-top: 3px;
    font-size: 17px;
    overflow-wrap: anywhere;
  }

  .sae-next-data {
    flex: 0 0 auto;
    font-size: 15px;
    white-space: nowrap;
  }

  .sae-next-data strong {
    display: none;
  }

  .sae-map-buttons {
    top: 7px;
    right: 7px;
    max-width: calc(100% - 14px);
    grid-template-columns: repeat(5, 37px);
    grid-auto-flow: column;
    overflow: visible;
  }

  .sae-map-buttons button {
    width: 37px;
    min-width: 37px;
    height: 37px;
    padding: 0;
    font-size: 0;
  }

  #saeZoomIn::after {
    content: "+";
    font-size: 20px;
  }

  #saeZoomOut::after {
    content: "−";
    font-size: 20px;
  }

  #saeFollowToggle::after {
    content: "🎯";
    font-size: 16px;
  }

  #saeOrientationToggle::after {
    content: "🧭";
    font-size: 16px;
  }

  #saeNorthUp::after {
    content: "N";
    font-size: 16px;
  }

  .sae-progress-header {
    margin-bottom: 7px;
    font-size: 12px;
  }

  .sae-stop-progress {
    max-width: 100%;
    padding: 5px 2px;
  }

  .sae-progress-stop {
    min-width: 100px;
    padding: 6px;
    font-size: 11px;
  }
}


/* ==========================================================
   V5.5 — ordre définitif du SAE sur iPhone
   Arrêt actuel > Prochain arrêt > Carte > Progression
   ========================================================== */

@media (max-width: 650px) {
  /*
   * .sae-main-panel utilise display: contents sur mobile.
   * Les deux cartes qu'il contient deviennent donc des éléments directs
   * du conteneur flex .sae-layout.
   */
  .sae-current-card {
    order: 1 !important;
  }

  .sae-next-card {
    order: 2 !important;
  }

  .sae-map-panel {
    order: 3 !important;
  }

  /*
   * La progression est contenue dans .sae-progress-wrapper.
   * C'est ce parent qu'il faut ordonner, et non seulement la carte interne.
   */
  .sae-progress-wrapper {
    order: 4 !important;
    width: 100%;
    min-width: 0;
    max-width: 100%;
  }

  .sae-progress-card {
    width: 100%;
    min-width: 0;
    max-width: 100%;
    margin-top: 0;
    margin-bottom: max(10px, env(safe-area-inset-bottom));
  }

  /*
   * La carte reste la zone centrale du SAE.
   */
  .sae-map-panel {
    width: 100%;
    min-height: 350px;
    height: 48vh;
  }

  #saeMap {
    width: 100%;
    min-height: 350px;
    height: 100%;
  }
}


/* ==========================================================
   BreizhStops V6.0 — numéro de version
   ========================================================== */

.brand-title {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 7px;
}

.app-version {
  display: inline-block;
  padding: 2px 6px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 999px;
  color: rgba(255, 255, 255, 0.82);
  font-size: 10px;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: 0.04em;
  vertical-align: middle;
}

@media (max-width: 650px) {
  .brand-title {
    gap: 5px;
  }

  .app-version {
    padding: 1px 5px;
    font-size: 9px;
  }
}
