:root {
  --gray-bg: #222222;
  --gray-face: #333333;
  --gray-highlight: #444444;
  --gray-shadow: #111111;
  --gray-dark-shadow: #000000;
  --win-blue: #000080;
  --win-text: #ffffff;
  --win-text-dim: #bbbbbb;
  --win-accent: #008080;
  --border-outset: 1px solid var(--gray-highlight), 1px solid var(--gray-shadow);
  --border-inset: 1px solid var(--gray-shadow), 1px solid var(--gray-highlight);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

/* Custom Scrollbars */
::-webkit-scrollbar {
  width: 14px;
  height: 14px;
}

::-webkit-scrollbar-track {
  background: #111;
  border-left: 1px solid #444;
}

::-webkit-scrollbar-thumb {
  background: var(--gray-face);
  border: 1px outset #fff;
}

::-webkit-scrollbar-thumb:hover {
  background: #444;
}

::-webkit-scrollbar-corner {
  background: #111;
}

html {
  scrollbar-color: var(--gray-face) #111;
  scrollbar-width: thin;
}

body {
  font-family: "Verdana", "Tahoma", sans-serif;
  background-color: #000000;
  color: var(--win-text);
  padding: 10px;
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.container {
  max-width: 1600px;
  margin: 0 auto;
  width: 100%;
}

/* Classic Win98 3D Border Mixins */
.win-outset {
  background-color: var(--gray-face);
  border-top: 2px solid #555;
  border-left: 2px solid #555;
  border-bottom: 2px solid #111;
  border-right: 2px solid #111;
}

.win-inset {
  background-color: #1a1a1a;
  border-top: 2px solid #000;
  border-left: 2px solid #000;
  border-bottom: 2px solid #444;
  border-right: 2px solid #444;
}

/* Header & Nav */
header {
  margin-bottom: 20px;
}

nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 10px;
}

.logo {
  font-weight: bold;
  font-size: 1.2rem;
  display: flex;
  align-items: center;
  gap: 8px;
}

.nav-links a {
  color: var(--win-text);
  text-decoration: none;
  padding: 4px 12px;
  font-size: 0.9rem;
}

.nav-links a:hover {
  background: var(--win-blue);
}

.accent {
  color: #00ffff;
}

/* Search Bar */
.search-bar {
  max-width: 500px;
  margin: 0 auto 30px;
}

.search-bar input {
  width: 100%;
  background: #000;
  color: #00ff00;
  border: 2px solid #444;
  padding: 8px 12px;
  font-family: "Courier New", monospace;
  font-size: 1rem;
}

/* Main scrolling area for landing page */
body:not(.detail-page) main {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
}

/* Feed Grid & Cards */
.feed-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 20px;
  padding-bottom: 20px;
}

.feed-card {
  padding: 15px;
}

.feed-card h3 {
  background: var(--win-blue);
  color: white;
  padding: 4px 8px;
  margin-bottom: 12px;
  font-size: 1rem;
}

.feed-info {
  font-size: 0.85rem;
  color: var(--win-text-dim);
  margin-bottom: 15px;
}

.card-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.explore-btn,
.download-btn,
.cache-btn,
.default-btn {
  flex: 1 1 140px;
  min-width: 140px;
  padding: 6px;
  text-align: center;
  text-decoration: none;
  color: var(--win-text);
  font-size: 0.85rem;
  font-weight: bold;
}

.explore-btn {
  color: #ffff00;
}
.download-btn {
  color: #00ffff;
}
.cache-btn {
  color: #ff80df;
}

/* Detail Page Layout */
.detail-page .container {
  display: grid;
  grid-template-columns: 350px 1fr;
  gap: 15px;
  height: calc(100vh - 20px);
  max-width: 98%;
  position: relative;
}

.sidebar {
  padding: 10px;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

#map {
  height: 100%;
  position: relative;
  border: 2px solid #444;
}

.leaflet-tile-pane {
  filter: invert(1) hue-rotate(180deg) brightness(5) contrast(0.5) saturate(1);
}

.leaflet-popup-content-wrapper,
.leaflet-popup-tip {
  background: #575043aa !important;
  color: var(--win-text);
}

.win-outset:is(a, button, .tab-btn, .win-titlebar-btn, .data-item) {
  cursor: pointer;
  user-select: none;
}

.win-outset:is(a, button, .tab-btn, .win-titlebar-btn, .data-item):active {
  border-top: 2px solid #111 !important;
  border-left: 2px solid #111 !important;
  border-bottom: 2px solid #555 !important;
  border-right: 2px solid #555 !important;
  transform: translate(1px, 1px);
}

/* Timetable Windows Overlay */
.win-overlay {
  position: absolute;
  top: 20px;
  right: 20px;
  width: 350px;
  max-height: 500px;
  z-index: 2000;
  display: none;
  flex-direction: column;
  pointer-events: auto;
  background-color: rgba(33, 33, 33, 0.4) !important;
}

#stopTimetableWindow {
  top: 20px;
  right: 20px;
  max-height: 500px;
}

.win-titlebar {
  background: var(--win-blue);
  color: white;
  padding: 0 10px;
  height: 32px;
  font-weight: bold;
  font-size: 0.85rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  overflow: hidden;
  flex-shrink: 0;
}

.win-titlebar span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.win-titlebar div {
  display: flex;
  gap: 4px;
  align-items: center;
  flex-shrink: 0;
}

.win-titlebar-btn {
  background: var(--gray-face);
  border: 1px outset #fff;
  padding: 2px 8px;
  font-size: 0.8rem;
  font-weight: bold;
  cursor: pointer;
  min-width: fit-content !important;
}

.win-titlebar-btn:active {
  border: 1px inset #fff !important;
  transform: translate(1px, 1px) !important;
}
.win-content {
  background-color: rgba(0, 0, 0, 0.5) !important;
  padding: 10px;
  overflow-y: auto;
  font-size: 0.8rem;
  color: #00ff00;
  font-family: "Courier New", monospace;
  border: 2px solid #333;
}

/* Tabs */
.tabs {
  display: flex;
  margin-bottom: 10px;
}

.tab-btn {
  padding: 4px 10px;
  background: var(--gray-face);
  color: var(--win-text);
  border: 2px solid #555;
  cursor: pointer;
  font-size: 0.8rem;
}

.tab-btn.active {
  background: #1a1a1a;
  border-bottom: none;
}

.data-list {
  flex: 1;
  overflow-y: auto;
}

.data-item {
  padding: 6px;
  margin-bottom: 4px;
  cursor: pointer;
  font-size: 0.8rem;
  border: 1px solid transparent;
}

.data-item:hover {
  border: 1px solid var(--win-blue);
}
.data-item.active {
  background: var(--win-blue);
}

.route-orb {
  width: 12px;
  height: 12px;
  display: inline-block;
  vertical-align: middle;
  margin-right: 8px;
}

.tab-content {
  display: none;
}
.tab-content.active {
  display: block;
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
  .detail-page .container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    padding: 0 !important;
    gap: 0;
  }

  .sidebar {
    width: 100%;
    max-height: 40vh;
    z-index: 1000;
    transition: max-height 0.3s ease;
  }

  .sidebar.collapsed {
    max-height: 40px;
    overflow: hidden;
  }

  #map {
    flex: 1;
    border: none;
    border-top: 2px solid #444;
  }

  /* Overlay Timetable Window adjustments for Mobile */
  .win-overlay {
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    max-height: 50vh;
    border-left: none;
    border-right: none;
    border-bottom: none;
    transition: transform 0.3s ease;
  }

  .win-overlay.collapsed {
    transform: translateY(calc(100% - 32px));
  }

  /* Mobile Toggle Buttons */
  .mobile-toggle {
    display: block !important;
    background: var(--win-blue);
    color: white;
    border: 1px outset #fff;
    cursor: pointer;
    padding: 2px 8px;
    font-size: 0.8rem;
    font-weight: bold;
    float: right;
  }

  #stopTimetableWindow {
    bottom: 0 !important;
    left: 0 !important;
    width: 100% !important;
    max-height: 50vh !important;
    top: auto !important;
    z-index: 2001;
  }

  #stopTimetableWindow.collapsed {
    transform: translateY(calc(100% - 32px));
  }
}

.mobile-toggle {
  display: none;
}

.cache-footer {
  text-align: center;
  padding: 1rem;
  font-size: 0.75rem;
  color: #888;
  border-top: 1px solid #222;
  margin-top: 1rem;
}

.cache-footer-label {
  margin-bottom: 0.5rem;
  color: #555;
}

.cache-footer-btns {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
}

.cache-clear-btn {
  font-family: inherit;
  font-size: 0.75rem;
  color: #aaa;
  padding: 4px 10px;
  cursor: pointer;
}

/* Map Controls Styling */
.leaflet-control-zoom {
  border: none !important;
}

.leaflet-control-zoom-in,
.leaflet-control-zoom-out,
.map-control-btn {
  background-color: var(--gray-face) !important;
  color: #00ff00 !important;
  border: 2px solid #555 !important;
  border-bottom-color: #111 !important;
  border-right-color: #111 !important;
  border-radius: 2px !important;
  font-family: "Verdana", sans-serif !important;
  font-weight: bold !important;
  width: 32px !important;
  height: 32px !important;
  line-height: 28px !important;
  display: flex !important;
  align-items: center;
  justify-content: center;
  text-decoration: none !important;
  margin-bottom: 2px !important;
}

.leaflet-control-zoom-in:active,
.leaflet-control-zoom-out:active,
.map-control-btn:active {
  border-top-color: #111 !important;
  border-left-color: #111 !important;
  border-bottom-color: #555 !important;
  border-right-color: #555 !important;
  transform: translate(1px, 1px);
}

@keyframes pulse-scan {
  0% {
    box-shadow: 0 0 0 0 rgba(255, 255, 0, 0.7);
  }
  70% {
    box-shadow: 0 0 0 10px rgba(255, 255, 0, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(255, 255, 0, 0);
  }
}

.map-control-btn.scanning {
  animation: pulse-scan 2s infinite;
  border-color: #ffff00 !important;
}

.live-toggle-btn {
  width: auto !important;
  padding: 0 8px !important;
  min-width: 40px;
}

.hidden {
  display: none !important;
}

.leaflet-control-attribution {
  background: rgba(0, 0, 0, 0.7) !important;
  color: #888 !important;
  font-family: "Courier New", monospace !important;
  font-size: 0.7rem !important;
  padding: 2px 5px !important;
  border: 1px solid #333;
}

.leaflet-control-attribution a {
  color: #008080 !important;
  text-decoration: none;
}
