/* Admin Override Page Styles */

html,
body.override-body {
  height: 100%;
  margin: 0;
}

.admin-override-shell {
  display: grid;
  grid-template-columns: minmax(330px, 420px) 1fr;
  width: 100%;
  height: 100%;
}

/* The map needs an explicit height, otherwise the shell's `height: 100%`
   resolves against nothing and the map renders at zero height (blank page). */
.override-map-stage {
  position: relative;
  min-height: 100%;
  height: 100%;
}

#overrideMap {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

/* The `hidden` attribute must always win over display rules on the shell
   elements (e.g. `.auth-shell { display: flex }`), otherwise the login screen
   stays visible after a successful sign-in. */
.admin-override-shell[hidden],
.auth-shell[hidden],
.admin-shell[hidden],
.auth-card[hidden] {
  display: none !important;
}

/* Admin line-view style route editor overlay (route + stop-order editing).
   Mirrors the main app's line-view panel: a floating card over the map. */
.admin-line-editor-panel {
  position: absolute;
  top: 0;
  right: 0;
  height: 100%;
  width: min(430px, 46vw);
  min-width: 340px;
  z-index: 8;
  pointer-events: auto;
  padding: 10px;
}

.admin-line-editor-panel[hidden] {
  display: none;
}

.admin-line-editor-card {
  position: relative;
  height: 100%;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: rgba(254, 254, 252, 1);
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 12px;
  overflow: hidden;
}

body[data-theme="dark"] .admin-line-editor-card {
  background: rgba(16, 28, 40, 1);
}

.admin-line-editor-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 8px;
}

.admin-line-editor-title {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: start;
  gap: 10px;
  min-width: 0;
}

.admin-line-color-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #177ca2;
  margin-top: 4px;
  flex-shrink: 0;
}

.admin-line-editor-name {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  line-height: 1.2;
  overflow-wrap: break-word;
  word-break: break-word;
}

.admin-line-editor-meta {
  margin: 3px 0 0;
  font-size: 0.8rem;
  color: var(--muted);
  overflow-wrap: break-word;
  word-break: break-word;
}

.admin-line-editor-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: flex-end;
}

.admin-line-editor-close {
  width: auto;
  min-width: 44px;
}

.admin-line-editor-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-right: 2px;
}

.admin-line-editor-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
  border-bottom: 1px dashed var(--line, #e5e0d5);
  padding-bottom: 12px;
}

.admin-line-editor-section:last-child {
  border-bottom: none;
}

.admin-line-editor-section h3 {
  margin: 0;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.admin-line-editor-actions-row {
  flex-direction: row;
  align-items: center;
  border-bottom: none;
  padding-bottom: 0;
}

/* Overlap route-selector popup on the admin map. */
.admin-route-select-popup {
  min-width: 220px;
  max-height: min(60vh, calc(100dvh - 180px));
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.admin-route-select-popup h4 {
  margin: 0 0 4px;
  font-size: 14px;
}

.admin-route-select-hint {
  margin: 0 0 8px;
  font-size: 0.78rem;
  color: var(--muted);
}

.admin-route-select-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow-y: auto;
  max-height: min(52vh, calc(100dvh - 240px));
}

.admin-route-select-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  text-align: left;
  padding: 6px 8px;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  background: var(--button-bg);
  color: var(--ink);
  cursor: pointer;
}

.admin-route-select-btn:hover {
  background: var(--button-hover);
}

.admin-route-select-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.admin-route-select-name {
  font-weight: 500;
  min-width: 0;
  overflow-wrap: break-word;
  word-break: break-word;
}

.admin-route-select-meta {
  margin-left: auto;
  font-size: 0.72rem;
  color: var(--muted);
  font-family: "IBM Plex Mono", monospace;
  white-space: nowrap;
}

/* Mobile: the editor overlays full width. */
@media (max-width: 768px) {
  .admin-line-editor-panel {
    width: 100%;
    min-width: 0;
  }
}

.override-sidebar {
  position: relative;
  padding: 14px;
  overflow-y: auto;
  border-right: 1px solid var(--panel-border);
  background: var(--shell);
  backdrop-filter: blur(4px);
  /* Long route/stop identities and log lines must wrap inside the sidebar
     instead of overflowing the panel. */
  min-width: 0;
}

/* Theme toggle in the sidebar head (the shell is already flex space-between). */
.theme-toggle-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  flex-shrink: 0;
}

.theme-toggle-btn .header-icon {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.override-sidebar .panel,
.override-sidebar .override-edit-panel {
  min-width: 0;
  overflow-wrap: break-word;
}

.override-search-panel {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.override-search-panel input,
.override-search-panel select {
  width: 100%;
}

.override-search-panel .microcopy {
  margin: 0;
}

.override-controls-panel,
.override-edit-panel {
  margin-bottom: 14px;
}

.override-controls-panel h2,
.override-edit-panel h2 {
  margin: 0 0 12px;
  font-size: 14px;
  font-weight: 600;
}

.override-controls-panel h3,
.override-edit-panel h3 {
  margin: 12px 0 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}

.override-mode-selector select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  background: var(--input-bg);
  color: var(--ink);
  font: inherit;
  font-size: 13px;
}

.override-status {
  margin-top: 8px;
  padding: 8px;
  border-radius: 8px;
  background: rgba(23, 124, 162, 0.1);
  color: var(--accent);
  font-size: 12px;
  text-align: center;
}

.override-edit-panel label {
  display: block;
  margin-top: 10px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}

.override-edit-panel input,
.override-edit-panel select {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 8px 10px;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  background: var(--input-bg);
  color: var(--ink);
  font: inherit;
  font-size: 13px;
}

.override-stops-list {
  margin: 10px 0;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.3);
  max-height: 420px;
  overflow-y: auto;
}

.override-stops-toolbar {
  display: flex;
  gap: 8px;
  padding: 8px;
  border-bottom: 1px solid rgba(20, 53, 71, 0.1);
  position: sticky;
  top: 0;
  z-index: 1;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(4px);
}

.override-stop-fields {
  display: grid;
  grid-template-columns: minmax(0, 1.7fr) minmax(92px, 0.7fr) minmax(92px, 0.7fr) auto;
  gap: 8px;
  align-items: center;
  width: 100%;
}

.override-stop-name-input,
.override-stop-coordinate-input {
  min-width: 0;
  padding: 7px 8px;
  font-size: 12px;
}

.override-stop-order-controls {
  display: flex;
  gap: 6px;
}

.override-stop-order-btn {
  min-width: 44px;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 11px;
  background: rgba(23, 124, 162, 0.1);
  border: 1px solid rgba(23, 124, 162, 0.25);
  color: var(--accent);
}

.override-stop-order-btn:hover {
  background: rgba(23, 124, 162, 0.18);
}

.override-stop-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-bottom: 1px solid rgba(20, 53, 71, 0.1);
  font-size: 12px;
}

.override-stop-item:last-child {
  border-bottom: none;
}

.override-stop-item.is-dragging {
  opacity: 0.6;
  background: rgba(23, 124, 162, 0.1);
}

.override-stop-drag-handle {
  cursor: grab;
  color: var(--muted);
  font-size: 14px;
  user-select: none;
}

.override-stop-drag-handle:active {
  cursor: grabbing;
}

.override-stop-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 500;
}

.override-stop-delete-btn {
  width: auto;
  min-width: 60px;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 11px;
  background: rgba(182, 72, 44, 0.1);
  border: 1px solid rgba(182, 72, 44, 0.3);
  color: var(--warn);
  cursor: pointer;
}

.override-stop-delete-btn:hover {
  background: rgba(182, 72, 44, 0.2);
}

.override-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.override-actions .btn {
  flex: 1;
  font-size: 13px;
}

/* Review Settings */
.review-setting {
  margin-bottom: 10px;
}

.review-setting label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 13px;
}

.review-setting input[type="checkbox"] {
  cursor: pointer;
  width: 18px;
  height: 18px;
  border-radius: 4px;
}

.setting-note {
  margin: 4px 0 0 26px;
  font-size: 11px;
  color: var(--muted);
}

/* Operator Review List */
.operator-review-list {
  margin-bottom: 12px;
  padding: 8px;
  background: rgba(255, 255, 255, 0.04);
  border-radius: 8px;
  max-height: 180px;
  overflow-y: auto;
}

.operator-review-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 0;
  font-size: 12px;
}

.operator-review-item:not(:last-child) {
  border-bottom: 1px solid rgba(20, 53, 71, 0.1);
  padding-bottom: 6px;
  margin-bottom: 6px;
}

.operator-review-item .operator-name {
  flex: 1;
  font-weight: 500;
}

.operator-review-toggles {
  display: flex;
  gap: 6px;
}

.operator-toggle-btn {
  width: 24px;
  height: 24px;
  padding: 0;
  border: 1px solid var(--panel-border);
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--ink);
  cursor: pointer;
  font-size: 10px;
  font-weight: 600;
}

.operator-toggle-btn:hover {
  background: rgba(23, 124, 162, 0.1);
}

.operator-toggle-btn.allowed {
  background: rgba(31, 107, 47, 0.2);
  border-color: #1f6b2f;
  color: #1f6b2f;
}

.operator-toggle-btn.blocked {
  background: rgba(157, 34, 34, 0.2);
  border-color: #9d2222;
  color: #9d2222;
}

/* Mobile responsive */
@media (max-width: 768px) {
  .admin-override-shell {
    grid-template-columns: 1fr;
  }

  .override-sidebar {
    display: none;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10;
  }

  .override-sidebar.open {
    display: block;
  }

  .override-map-stage {
    width: 100%;
    height: 100%;
  }

  .override-stop-fields {
    grid-template-columns: 1fr;
  }

  .override-stops-toolbar {
    flex-direction: column;
  }
}

.auth-shell {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

.auth-shell .auth-card {
  width: 100%;
  max-width: 380px;
}

.auth-shell input {
  width: 100%;
  margin-bottom: 10px;
  padding: 8px 10px;
  border: 1px solid var(--line, #d8cfc0);
  border-radius: 8px;
}

.override-hint-panel p {
  margin: 0;
}

.override-edit-panel h2 {
  margin-top: 0;
}

.override-edit-panel label {
  display: block;
  margin-top: 10px;
  font-size: 0.8rem;
  color: var(--muted, #5a5a5a);
}

.override-edit-panel input,
.override-edit-panel select {
  width: 100%;
  padding: 7px 9px;
  border: 1px solid var(--line, #d8cfc0);
  border-radius: 8px;
  margin-top: 2px;
}

.override-edit-panel .review-setting {
  margin-top: 12px;
}

.override-actions {
  display: flex;
  gap: 8px;
  margin-top: 14px;
}

.btn-danger {
  color: #ffffff;
  background: #c0392b;
}

.operator-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid var(--line, #e5e0d5);
  font-size: 0.85rem;
}

.operator-row .btn {
  font-size: 0.75rem;
  padding: 4px 8px;
  white-space: nowrap;
}

.manual-edits-log {
  max-height: 280px;
  overflow: auto;
}

.manual-edit-row {
  padding: 6px 0;
  border-bottom: 1px dashed var(--line, #e5e0d5);
}

.manual-edit-row p {
  margin: 2px 0;
  font-size: 0.82rem;
  overflow-wrap: break-word;
  word-break: break-word;
}

.manual-edit-head {
  display: flex;
  justify-content: space-between;
  font-size: 0.72rem;
  color: var(--muted, #5a5a5a);
}

.manual-edit-kind {
  font-weight: 700;
  text-transform: uppercase;
}

.map-overlay-controls {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 10;
  display: flex;
  gap: 8px;
}

.route-stops-list {
  max-height: 220px;
  overflow: auto;
  margin-top: 6px;
}

.stop-order-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
  border-bottom: 1px solid var(--line, #e5e0d5);
  font-size: 0.82rem;
}

.stop-order-pos {
  font-family: "IBM Plex Mono", monospace;
  color: var(--muted, #5a5a5a);
  width: 22px;
}

.stop-order-name {
  flex: 1;
  min-width: 0;
  overflow-wrap: break-word;
  word-break: break-word;
}

.stop-order-row button {
  width: 26px;
  height: 24px;
  font-size: 0.8rem;
}

#batchStatus {
  margin-top: 8px;
}
