.line-view-panel {
  position: absolute;
  top: 0;
  right: 0;
  height: 100%;
  width: min(420px, 40vw);
  min-width: 330px;
  z-index: 7;
  pointer-events: auto;
  padding: 10px;
  background: rgba(254, 254, 252, 1);
  border-left: 1px solid var(--panel-border);
}

body[data-theme="dark"] .line-view-panel {
  background: rgba(16, 28, 40, 1);
}

.line-view-panel[hidden] {
  display: none;
}

.line-view-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"] .line-view-card {
  background: rgba(16, 28, 40, 1);
}

.line-view-header {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 8px;
  min-height: 40px;
  padding-right: 72px;
}

.line-view-actions {
  position: absolute;
  top: 0;
  right: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: flex-end;
}

.line-view-actions .line-view-nav {
  width: auto;
  min-width: 44px;
}

.line-view-title {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: start;
  gap: 10px;
  min-width: 0;
  flex: 1;
}

.line-view-title .line-color-dot {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

.line-view-name {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.2;
  min-width: 0;
  overflow: visible;
  white-space: normal;
  overflow-wrap: break-word;
  word-wrap: break-word;
  max-width: 100%;
}

.line-view-meta {
  margin: 2px 0 0;
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.line-view-nav {
  width: 32px;
  height: 32px;
  min-width: 32px;
  padding: 0;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  border-radius: 8px;
}

.line-view-nav:hover {
  background: rgba(23, 124, 162, 0.1);
}

.line-view-status {
  border-top: none;
  padding-top: 0;
}

.line-view-status-text {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
}

.line-view-progress {
  margin-top: 8px;
}

.line-view-progress-text {
  margin: 0 0 4px;
  font-size: 11px;
  color: var(--muted);
}

.line-view-diagnostics {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px dashed rgba(20, 53, 71, 0.2);
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 11px;
}

.line-view-diagnostics .diagnostic-label {
  color: var(--ink);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.line-view-ordering-row {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: nowrap;
  width: 100%;
}

.diagnostic-label {
  color: var(--muted);
  white-space: nowrap;
  font-weight: 500;
}

.line-view-ordering-group {
  display: flex;
  flex: 1 1 auto;
  min-width: 0;
  flex-wrap: nowrap;
  gap: 4px;
}

.line-view-ordering-btn,
.line-view-reverse-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 1 1 0;
  min-width: 0;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 4px 10px;
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  background: var(--shell);
  color: var(--ink);
  font-size: 11px;
  cursor: pointer;
  transition: border-color 140ms ease, background-color 140ms ease, color 140ms ease, transform 140ms ease;
}

.line-view-ordering-btn:hover,
.line-view-reverse-btn:hover {
  border-color: var(--accent);
}

.line-view-reverse-btn {
  flex: 0 0 100%;
  width: 100%;
  margin-top: 0;
}

.line-view-ordering-btn:focus,
.line-view-reverse-btn:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(23, 124, 162, 0.12);
}

.line-view-ordering-btn.is-active,
.line-view-reverse-btn.is-active {
  background: var(--accent);
  border-color: transparent;
  color: #ffffff;
}

.line-view-reverse-btn.is-active {
  background: rgba(23, 124, 162, 0.12);
  border-color: var(--accent);
  color: var(--accent);
}

.line-view-ordering-btn.is-active:hover,
.line-view-reverse-btn.is-active:hover {
  transform: translateY(-1px);
}

.diagnostic-resolved {
  width: 100%;
  margin: 0;
  font-style: italic;
  font-weight: 400;
  font-size: 10px;
  line-height: 1.15;
  color: var(--muted);
}

.line-view-stop-list {
  flex: 1;
  overflow-y: auto;
  padding-right: 6px;
  display: flex;
  flex-direction: column;
  gap: 0;
  --line-color: var(--accent);
  position: relative;
}

#lineViewConnectorSvg {
  position: absolute !important;
  top: 0 !important;
  left: 0 !important;
  width: 100% !important;
  pointer-events: none;
  z-index: 0;
}

.line-view-stop-row:first-child::before,
.line-view-stop-row:last-child::after {
  content: "";
  position: absolute;
  left: 0;
  width: 24px;
  height: 12px;
  background: var(--panel);
  pointer-events: none;
  z-index: 0;
}

.line-view-stop-row:first-child::before {
  top: 0;
}

.line-view-stop-row:last-child::after {
  bottom: 0;
}

.line-view-stop-row {
  display: grid;
  grid-template-columns: 18px 1fr;
  gap: 10px;
  align-items: start;
  padding: 8px 4px;
  border: none;
  background: transparent;
  text-align: left;
  color: var(--ink);
  cursor: pointer;
  position: relative;
  z-index: 1;
}

.line-view-stop-row:disabled {
  cursor: default;
  opacity: 1;
}

.line-view-stop-row:hover:not(:disabled) {
  background: rgba(23, 124, 162, 0.08);
}

.line-view-stop-marker {
  position: relative;
  width: 18px;
  display: flex;
  justify-content: center;
}

.line-view-stop-dot {
  width: 12px;
  height: 12px;
  border-radius: 999px;
  border: 2px solid var(--line-color);
  background: #d9563a;
  margin-top: 2px;
  z-index: 1;
  flex-shrink: 0;
  opacity: 1;
  box-shadow: 0 1px 3px rgba(17, 42, 61, 0.18), inset 0 0.5px 1px rgba(255, 255, 255, 0.0);
  transition: box-shadow 0.2s, transform 0.2s;
}

.line-view-stop-row.is-visited .line-view-stop-dot {
  background: #1a9b66;
  border: 2px solid var(--line-color);
  box-shadow: 0 1px 4px rgba(34, 139, 88, 0.3), inset 0 0.5px 1px rgba(255, 255, 255, 0.0);
}

.line-view-stop-row:hover:not(:disabled) .line-view-stop-dot {
  box-shadow: 0 2px 6px rgba(23, 124, 162, 0.25), inset 0 0.5px 1px rgba(255, 255, 255, 0.8);
  transform: scale(1.1);
}

.line-view-stop-name {
  margin: 0;
  font-size: 12px;
  font-weight: 600;
}

.line-view-stop-status {
  margin: 3px 0 0;
  font-size: 11px;
  color: var(--muted);
}

@media (max-width: 740px) {
  .line-view-card {
    padding: 10px;
    gap: 8px;
  }

  .line-view-header {
    grid-template-columns: minmax(0, 1fr) auto;
    padding-right: 0;
    min-height: 0;
  }

  .line-view-actions {
    position: static;
    flex-direction: column;
    justify-content: flex-start;
    align-items: flex-end;
    gap: 6px;
    margin-top: 2px;
    justify-self: end;
  }

  .line-view-actions .line-view-nav {
    min-width: 40px;
  }

  .line-view-status,
  .line-view-diagnostics {
    padding-top: 5px;
  }

  .line-view-diagnostics {
    flex-direction: column;
    align-items: stretch;
  }

  .diagnostic-label {
    white-space: normal;
  }

  .diagnostic-select {
    width: 100%;
  }
}

@media (max-width: 900px) {
  .line-view-panel {
    width: min(420px, 46vw);
    min-width: 300px;
  }

  .line-view-auto-toggle-btn {
    display: none !important;
  }
}

@media (max-width: 900px) and (orientation: portrait) {
  .line-view-panel {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100dvh;
    padding: calc(10px + env(safe-area-inset-top)) 10px calc(10px + env(safe-area-inset-bottom));
    z-index: 20;
    background: rgba(16, 28, 40, 1);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  body[data-theme="light"] .line-view-panel {
    background: rgba(254, 254, 252, 1);
  }

  .line-view-card {
    border-radius: 18px;
    height: 100%;
    width: 100%;
    background: rgba(16, 28, 40, 1);
  }

  body[data-theme="light"] .line-view-card {
    background: rgba(254, 254, 252, 1);
  }
}

@media (max-width: 640px) {
  .line-view-auto-toggle-btn {
    display: none !important;
  }
}
