* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
}

body {
  font-family:
    "Segoe UI",
    system-ui,
    -apple-system,
    sans-serif;
  background: #0f1115;
  color: #e8eaed;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

.topbar {
  display: flex;
  padding: 12px 16px;
  background: #151922;
  border-bottom: 1px solid #222836;
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar-main {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: nowrap;
  margin-left: auto;
}

.favorites-menu {
  position: relative;
  flex: 0 0 auto;
}

.top-menu {
  position: relative;
  flex: 0 0 auto;
}

.map-switch-menu {
  position: relative;
  flex: 0 0 auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-link {
  color: inherit;
  text-decoration: none;
}

.app-logo-img {
  width: 28px;
  height: 28px;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.3));
}

.topbar h1 {
  font-size: 18px;
  margin: 0;
  font-weight: 600;
}

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

.icon-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 42px;
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid #2f3748;
  background: #1b2130;
  color: #f7f8fb;
  text-decoration: none;
  font-size: 12px;
  font-weight: 700;
}

.icon-link i {
  font-size: 14px;
  line-height: 1;
}

.icon-link:hover {
  border-color: #4a89dc;
}

.icon-link--favorites {
  cursor: pointer;
}

.icon-link--alerts {
  position: relative;
}

.icon-badge--favorites {
  background: #ffcc33;
  color: #1a1a1a;
  box-shadow: 0 6px 12px rgba(255, 204, 51, 0.28);
}

.favorites-popover {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  width: min(360px, calc(100vw - 24px));
  max-height: min(60vh, 420px);
  overflow: auto;
  padding: 12px;
  border-radius: 18px;
  border: 1px solid #2a3242;
  background: rgba(21, 25, 34, 0.98);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.34);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  z-index: 40;
}

.top-popover {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  width: min(320px, calc(100vw - 24px));
  max-height: min(60vh, 420px);
  overflow: auto;
  padding: 12px;
  border-radius: 18px;
  border: 1px solid #2a3242;
  background: rgba(21, 25, 34, 0.98);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.34);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  z-index: 40;
}

.map-switch-popover {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  width: min(172px, calc(100vw - 24px));
  padding: 8px;
  border-radius: 14px;
  border: 1px solid #2a3242;
  background: rgba(21, 25, 34, 0.98);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.34);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  z-index: 40;
}

.map-switch-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.map-switch-link {
  display: block;
  border-radius: 10px;
  border: 1px solid #2f3748;
  background: #1b2130;
  color: #f7f8fb;
  text-decoration: none;
  padding: 9px 10px;
  font-size: 13px;
  font-weight: 600;
}

.map-switch-link:hover {
  border-color: #4a89dc;
}

.map-switch-link.is-active {
  border-color: #4a89dc;
  background: #2f6ec5;
  pointer-events: none;
}

.favorites-popover-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  color: #f4f7fb;
}

.favorites-popover-header--sub {
  margin-top: 14px;
}

.favorites-list {
  display: grid;
  gap: 10px;
}

.favorites-auth {
  display: grid;
  gap: 8px;
  margin-bottom: 10px;
}

.favorites-auth-info {
  font-size: 12px;
  line-height: 1.4;
  color: #a6afbd;
}

.favorite-auth-button {
  border: 1px solid #2f3748;
  background: #1b2130;
  color: #f7f8fb;
  border-radius: 999px;
  padding: 7px 10px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.favorite-auth-button:hover {
  border-color: #4a89dc;
}

.favorite-auth-button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.favorites-global-top {
  display: grid;
  gap: 8px;
}

.favorites-empty {
  padding: 12px;
  border: 1px dashed #34415a;
  border-radius: 14px;
  color: #9da8ba;
  font-size: 13px;
  line-height: 1.4;
}

.favorite-train-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  padding: 10px;
  border-radius: 14px;
  background: #1a2030;
  border: 1px solid #293145;
}

.favorite-train-jump,
.favorite-train-remove {
  border: 0;
  font: inherit;
}

.favorite-train-jump {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  min-width: 0;
  padding: 0;
  background: transparent;
  color: #f6f8fb;
  text-align: left;
  cursor: pointer;
}

.favorite-train-jump:disabled {
  cursor: not-allowed;
  opacity: 0.62;
}

.favorite-train-title {
  font-size: 14px;
  font-weight: 700;
}

.favorite-train-meta,
.favorite-train-subtitle {
  color: #a6afbd;
  font-size: 12px;
  line-height: 1.4;
}

.favorite-train-subtitle {
  grid-column: 1 / -1;
}

.favorite-train-remove {
  width: 30px;
  height: 30px;
  border-radius: 999px;
  background: #262f43;
  color: #f6f8fb;
  cursor: pointer;
}

.favorite-train-remove:hover,
.favorite-train-jump:not(:disabled):hover .favorite-train-title {
  color: #ffd95c;
}

.favorite-limit-notice {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  z-index: 1200;
  max-width: min(92vw, 360px);
  padding: 10px 14px;
  border-radius: 999px;
  border: 1px solid #3b4761;
  background: rgba(21, 25, 34, 0.94);
  color: #f6f8fb;
  font-size: 12px;
  font-weight: 600;
  text-align: center;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.28);
  opacity: 0;
  transition: opacity 0.18s ease;
  pointer-events: none;
}

.favorite-limit-notice.is-visible {
  opacity: 1;
}

.global-follow-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 12px;
  border: 1px solid #293145;
  background: #1a2030;
}

.global-follow-title {
  color: #f6f8fb;
  font-size: 13px;
  font-weight: 700;
}

.global-follow-count {
  color: #ffd95c;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.icon-badge {
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: #ff5252;
  color: #fff;
  font-size: 11px;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 6px 12px rgba(255, 82, 82, 0.28);
}

.icon-link .icon-badge {
  margin-left: 4px;
}

.feed-filters {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.feed-filters-map {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 500;
  pointer-events: none;
}

.feed-filters-map .feed-filters {
  pointer-events: auto;
  padding: 6px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(21, 25, 34, 0.88);
  box-shadow: 0 12px 26px rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  flex-wrap: nowrap;
}

.feed-chip {
  border: 1px solid #2f3748;
  background: #1b2130;
  color: #d6dbe5;
  border-radius: 999px;
  padding: 7px 12px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.16s ease;
}

.feed-chip:hover {
  border-color: #4a89dc;
  color: #ffffff;
}

.feed-chip.is-active {
  border-color: #4a89dc;
  background: #2f6ec5;
  color: #ffffff;
}

main {
  display: block;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

#map {
  width: 100%;
  height: 100%;
}

.dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 999px;
  margin-right: 6px;
}

.leaflet-container {
  background: #0b0e14;
  touch-action: pan-x pan-y;
}

.leaflet-top.leaflet-right .leaflet-control-attribution,
.leaflet-bottom.leaflet-right .leaflet-control-attribution,
.leaflet-top.leaflet-left .leaflet-control-attribution,
.leaflet-bottom.leaflet-left .leaflet-control-attribution {
  position: fixed;
  bottom: 12px;
  left: 12px;
  top: auto;
  right: auto;
  margin: 0;
  z-index: 1100;
  background: rgba(17, 21, 33, 0.86);
  color: #cfd6e4;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.leaflet-control-attribution a {
  color: #f4ddff;
}

@media (max-width: 900px) {
  .leaflet-top.leaflet-right .leaflet-control-attribution,
  .leaflet-bottom.leaflet-right .leaflet-control-attribution,
  .leaflet-top.leaflet-left .leaflet-control-attribution,
  .leaflet-bottom.leaflet-left .leaflet-control-attribution {
    bottom: 10px;
    left: 10px;
    max-width: calc(100vw - 20px);
  }

  .leaflet-top.leaflet-left .leaflet-control-zoom {
    margin-top: 64px;
    margin-left: 10px;
  }
}

@media (max-width: 900px) {
  .topbar {
    padding: 10px 12px;
  }

  .topbar-main {
    gap: 8px;
  }

  .brand {
    min-width: 0;
  }

  .topbar h1 {
    white-space: nowrap;
  }

  .topbar-actions {
    flex-wrap: nowrap;
    margin-left: 0;
    gap: 8px;
  }

  .status {
    display: none;
  }

  .icon-link {
    min-width: 40px;
    padding: 8px 10px;
    gap: 0;
  }

  .icon-link-text {
    display: none;
  }

  .icon-badge {
    display: none !important;
  }

  .favorites-popover {
    right: 0;
    left: auto;
    width: min(420px, calc(100vw - 24px));
  }

  .top-popover {
    position: fixed;
    top: 58px;
    right: 12px;
    left: 12px;
    width: auto;
    max-height: calc(100dvh - 74px);
  }

  .map-switch-popover {
    right: 0;
    left: auto;
    width: min(172px, calc(100vw - 24px));
  }

  .feed-filters-map {
    top: 12px;
    left: 12px;
    right: 12px;
    transform: none;
  }

  .feed-filters-map .feed-filters {
    width: fit-content;
    max-width: 100%;
  }

  main {
    height: auto;
    flex: 1 1 auto;
    min-height: 0;
    position: relative;
    overflow: hidden;
  }

  #map {
    height: 100%;
    z-index: 1;
  }

}

.main-content-area {
  flex-grow: 1;
  position: relative;
  height: 100%;
  overflow: hidden;
  isolation: isolate;
}

.view-content {
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
  z-index: 1;
}

.alerts-page {
  overflow: auto;
}

.popup-quick-actions {
  margin-top: 10px;
  display: flex;
  gap: 6px;
}

.popup-favorite-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 10px;
  border: 1px solid #d6b33f;
  background: #fff6cf;
  color: #5d4700;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}

.popup-favorite-button.is-active {
  border-color: #c48b00;
  background: #ffe28a;
  color: #513b00;
}

.popup-favorite-button i,
.popup-report-button i {
  font-size: 16px;
  line-height: 1;
}

.popup-report-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 10px;
  border: 1px solid #6f9ae6;
  background: #dfeaff;
  color: #1e3e75;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}

.popup-report-button:hover {
  border-color: #4a89dc;
  background: #d3e2ff;
}

.alerts-layout {
  display: grid;
  grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
  gap: 18px;
  padding: 18px;
  overflow: auto;
}

.alerts-panel,
.alert-card {
  background: #151922;
  border: 1px solid #222836;
  border-radius: 18px;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.24);
}

.alerts-panel {
  padding: 18px;
  height: fit-content;
  position: sticky;
  top: 18px;
}

.alerts-panel-header h2 {
  margin: 0 0 6px;
  font-size: 24px;
}

.alerts-panel-header p {
  margin: 0 0 16px;
  color: #a9b1bd;
  line-height: 1.45;
}

.form-hint {
  margin: -2px 0 4px;
  color: #93a0b7;
  font-size: 13px;
  line-height: 1.45;
}

.card-form,
.comment-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.card-form input,
.card-form select,
.card-form textarea,
.comment-form input,
.comment-form textarea {
  width: 100%;
  border: 1px solid #2b3344;
  background: #0f131c;
  color: #edf2fb;
  border-radius: 12px;
  padding: 11px 13px;
  font: inherit;
}

.card-form textarea,
.comment-form textarea {
  resize: vertical;
}

.primary-button,
.secondary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 0;
  border-radius: 12px;
  padding: 11px 14px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.primary-button {
  background: linear-gradient(135deg, #ff7b4d, #ff5252);
  color: #fff;
}

.secondary-button {
  background: #243047;
  color: #f7f9fd;
}

.alerts-feed {
  min-width: 0;
}

.alerts-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.alert-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.alert-category {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.alert-category--info {
  background: rgba(74, 137, 220, 0.16);
  color: #9bc4ff;
  border: 1px solid rgba(74, 137, 220, 0.35);
}

.alert-category--retraso {
  background: rgba(255, 183, 77, 0.16);
  color: #ffd37e;
  border: 1px solid rgba(255, 183, 77, 0.38);
}

.alert-category--averia {
  background: rgba(255, 82, 82, 0.16);
  color: #ff9d9d;
  border: 1px solid rgba(255, 82, 82, 0.4);
}

.alert-card {
  padding: 18px;
}

.alert-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.alert-toggle-button {
  border: 1px solid #32425f;
  background: #1a2438;
  color: #dce8ff;
  border-radius: 999px;
  padding: 8px 12px;
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}

.alert-toggle-button:hover {
  border-color: #4a89dc;
  background: #223252;
}

.alert-toggle-button[aria-expanded="true"] {
  border-color: #4a89dc;
  background: #2a3f67;
}

.alert-line {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 11px;
  font-weight: 800;
  color: #dce7f8;
  background: rgba(220, 231, 248, 0.08);
  border: 1px solid rgba(220, 231, 248, 0.16);
}

.alert-card-head h3 {
  margin: 0;
  font-size: 20px;
}

.alert-meta,
.comment-meta {
  color: #9da8bc;
  font-size: 12px;
}

.alert-body {
  margin: 14px 0 16px;
  line-height: 1.55;
  color: #eef2f9;
}

.alert-image-link {
  display: block;
  margin: 0 0 14px;
}

.alert-image {
  display: block;
  width: 100%;
  max-height: min(420px, 56vh);
  object-fit: cover;
  border-radius: 14px;
  border: 1px solid #2a3142;
  background: #0f131c;
}

.alert-source-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 16px;
  padding: 9px 12px;
  border-radius: 10px;
  color: #9bc4ff;
  text-decoration: none;
  background: rgba(74, 137, 220, 0.12);
  border: 1px solid rgba(74, 137, 220, 0.24);
}

.alert-source-link:hover {
  background: rgba(74, 137, 220, 0.18);
}

.alert-actions {
  margin: 0 0 14px;
}

.alert-like-button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid #32425f;
  background: #1a2438;
  color: #dce8ff;
  border-radius: 999px;
  padding: 8px 12px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.alert-like-button:hover:not(:disabled) {
  border-color: #4a89dc;
  background: #223252;
}

.alert-like-button:disabled {
  opacity: 0.65;
  cursor: not-allowed;
}

.alert-like-count {
  padding: 1px 7px;
  border-radius: 999px;
  background: rgba(74, 137, 220, 0.2);
  font-size: 12px;
}

.comment-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 14px;
}

.comment-item {
  background: #0f131c;
  border: 1px solid #232c3d;
  border-radius: 12px;
  padding: 10px 12px;
}

.empty-state {
  border: 1px dashed #384258;
  border-radius: 16px;
  padding: 24px;
  text-align: center;
  color: #a9b1bd;
}
.chart-card {
  background: rgba(21, 25, 34, 0.4);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 12px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  min-height: 320px; /* Force larger size */
}

.chart-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.chart-header h3 {
  margin: 0;
  font-size: 15px;
  color: #ffffff;
  font-weight: 600;
}

.expand-btn {
  background: rgba(255, 255, 255, 0.05);
  border: none;
  color: #a9b1bd;
  cursor: pointer;
  font-size: 14px;
  padding: 6px 10px;
  border-radius: 6px;
  transition: all 0.2s;
}

.expand-btn:hover {
  background: #1e88e5;
  color: #ffffff;
}

.chart-wrapper {
  flex-grow: 1;
  width: 100%;
  min-height: 240px;
}

.chart-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 180px;
  color: #5f6368;
  font-style: italic;
  font-size: 12px;
  border: 1px dashed #2a3140;
  border-radius: 8px;
}

/* Modal */
.modal {
  display: none;
  position: fixed;
  z-index: 2000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(5px);
}

.modal-content {
  position: relative;
  background-color: #111521;
  margin: 4vh auto;
  padding: 40px;
  border: 1px solid #222836;
  width: 90%;
  max-width: 1000px;
  border-radius: 16px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
}

.close-modal {
  position: absolute;
  top: 15px;
  right: 25px;
  color: #a9b1bd;
  font-size: 35px;
  font-weight: bold;
  cursor: pointer;
}

.close-modal:hover {
  color: #ffffff;
}

.modal-chart-container {
  height: 70vh;
}

@media (max-width: 900px) {
  .topbar {
    gap: 6px;
    padding: 8px 10px;
  }

  .topbar-main {
    width: 100%;
    min-width: 0;
    gap: 8px;
  }

  .brand {
    min-width: 0;
    flex: 1 1 auto;
  }

  .topbar-actions {
    flex: 0 0 auto;
  }
  
  .topbar h1 {
    font-size: 16px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .status {
    display: none;
  }

  .topbar-actions .status {
    display: none;
  }

  .feed-filters {
    gap: 6px;
  }

  .feed-chip {
    font-size: 11px;
    padding: 6px 10px;
  }

  .icon-link {
    min-width: auto;
    padding: 7px 10px;
    font-size: 11px;
    white-space: nowrap;
  }

  .icon-badge {
    min-width: 18px;
    height: 18px;
    font-size: 10px;
    padding: 0 5px;
  }

  .icon-link .icon-badge {
    margin-left: 6px;
  }

  .chart-card {
    padding: 12px;
    min-height: 280px;
  }

  .chart-header h3 {
    font-size: 13px;
  }

  .chart-wrapper {
    min-height: 200px;
  }

  .modal-content {
    width: 96%;
    margin: 2vh auto;
    padding: 16px;
  }
  
  .modal-chart-container {
    height: 50vh;
  }

  .alerts-layout {
    grid-template-columns: 1fr;
    padding: 12px;
  }

  .alerts-panel {
    position: static;
  }

  .alert-card-head {
    flex-direction: column;
    gap: 10px;
  }

  .alert-toggle-button {
    width: fit-content;
  }
}

