@font-face {
  font-family: "LTAIdentity";
  src: url("../assets/fonts/LTAIdentity.ttf") format("truetype");
  font-weight: normal;
  font-style: normal;
}

#system-map-svg text,
.legend-grid,
.legend-item span {
  font-family: "LTAIdentity", "Inter", sans-serif !important;
}

/* Cursor fallbacks and fixes to ensure visibility everywhere */
#system-map-svg {
  cursor: none !important;
  user-select: none !important;
  -webkit-user-select: none !important;
  -moz-user-select: none !important;
  -ms-user-select: none !important;
}
#system-map-svg * {
  cursor: none !important;
}
/* Custom floating cursor element inside canvas */
.custom-map-cursor {
  position: fixed;
  pointer-events: none;
  z-index: 9999;
  display: none;
  width: 36px;
  height: 36px;
  background-color: var(--surface);
  border: 2.5px solid var(--ink);
  border-radius: 50%;
  color: var(--ink);
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 10px rgba(15, 23, 42, 0.2);
  transform: translate(-50%, -50%);
  transition:
    transform 0.12s cubic-bezier(0.175, 0.885, 0.32, 1.275),
    background-color 0.15s ease,
    color 0.15s ease,
    border-color 0.15s ease;
}
.custom-map-cursor.grabbing {
  transform: translate(-50%, -50%) scale(0.85);
  background-color: var(--brand);
  color: white;
  border-color: white;
}
.custom-map-cursor.hovering-station {
  color: var(--brand);
  border-color: var(--brand);
  transform: translate(-50%, -50%) scale(1.1);
}

.form-input {
  cursor: text !important;
  caret-color: var(--ink) !important;
}
select.form-input {
  cursor: pointer !important;
}
input[type="checkbox"].form-input,
input[type="color"].form-input {
  cursor: pointer !important;
}
.portal-btn,
.editor-tab-btn,
.menu-item,
.sortable-item button {
  cursor: pointer !important;
}

.station-corner-handle {
  cursor: -webkit-grab !important;
  cursor: grab !important;
  transition: fill-opacity 0.2s;
}
.station-corner-handle:hover {
  fill-opacity: 1;
  r: 6.5;
}
.station-capsule:hover rect.capsule-bg-rect {
  stroke: var(--brand) !important;
  stroke-width: 2.5px !important;
}

/* Clean portal overrides using design variables */
body.portal-body {
  background-color: var(--bg-offset);
  margin: 0;
  padding: 0;
  height: 100vh;
  display: flex;
  font-family: "Inter", sans-serif;
}

/* Login Card Styles */
.login-container {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100vw;
  height: 100vh;
  background-color: var(--bg-offset);
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  width: 100%;
  max-width: 400px;
  padding: var(--space-lg);
  box-shadow: var(--shadow-md);
}

.login-header {
  text-align: center;
  margin-bottom: var(--space-md);
}

.login-header img {
  border-radius: 8px;
  margin-bottom: var(--space-xs);
  border: 1px solid var(--border);
}

.login-header h2 {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--ink);
}

.portal-btn-outline {
  background-color: transparent;
  color: var(--brand);
  border-color: var(--brand);
}

.portal-btn-danger {
  background-color: #ef4444;
  border-color: #ef4444;
}

.portal-btn-sm {
  padding: 0.4rem 0.8rem;
  font-size: 0.8rem;
  width: auto;
}

/* Dashboard Layout */
.dashboard-wrapper {
  display: none; /* Shown after auth */
  width: 100vw;
  height: 100vh;
  grid-template-columns: 240px 1fr;
}

.dashboard-sidebar {
  background-color: var(--ink);
  color: #ffffff;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: var(--space-md) var(--space-sm);
  height: 100%;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: #ffffff;
  font-weight: 800;
  font-size: 1.15rem;
  padding-bottom: var(--space-md);
  border-bottom: 1px solid #334155;
  margin-bottom: var(--space-md);
  text-decoration: none;
}

.sidebar-brand img {
  border-radius: 4px;
}

.sidebar-menu {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  flex-grow: 1;
}

.menu-item {
  color: #94a3b8;
  padding: 0.75rem 1rem;
  text-decoration: none;
  font-weight: 600;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  cursor: pointer;
}

.menu-item.active {
  color: #ffffff;
  background-color: rgba(255, 255, 255, 0.08);
  border-left: 3px solid var(--brand);
}

.sidebar-footer {
  border-top: 1px solid #334155;
  padding-top: var(--space-sm);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.user-badge-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.user-badge-row {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  min-width: 0;
}

.user-avatar-wrapper {
  position: relative;
  flex-shrink: 0;
  width: 38px;
  height: 38px;
}

.user-avatar-img {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--brand);
  display: block;
}

.user-avatar-fallback {
  display: none;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  border: 2px solid #334155;
  align-items: center;
  justify-content: center;
  color: #94a3b8;
  font-size: 1rem;
}

/* User directory table avatar */
.user-dir-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--brand);
  display: block;
}

.user-dir-avatar-fallback {
  display: inline-flex;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.07);
  border: 2px solid #334155;
  align-items: center;
  justify-content: center;
  color: #94a3b8;
  font-size: 0.85rem;
}

.user-badge-email {
  font-size: 0.8rem;
  color: #94a3b8;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-badge-role {
  font-size: 0.7rem;
  text-transform: uppercase;
  font-weight: 800;
  letter-spacing: 0.05em;
  color: var(--brand);
}

.btn-logout {
  color: #ef4444;
  background: transparent;
  border: 1px solid rgba(239, 68, 68, 0.4);
  padding: 0.5rem;
  font-family: inherit;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

/* Main Content Area */
.dashboard-main {
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  height: 100%;
  background-color: var(--bg-offset);
}

.portal-header {
  background-color: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: var(--space-sm) var(--space-lg);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.portal-header h1 {
  margin: 0;
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--ink);
}

.portal-content-body {
  padding: var(--space-lg);
  flex-grow: 1;
}

/* Module Tabs */
.module-tab {
  display: none;
}

.module-tab.active {
  display: block;
}

/* User Management Panel */
.admin-controls-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-md);
}

/* Tables Style */
.portal-table-container {
  background: var(--surface);
  border: 1px solid var(--border);
  width: 100%;
  overflow-x: auto;
}

.portal-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.9rem;
}

.portal-table th,
.portal-table td {
  padding: 0.85rem var(--space-md);
  border-bottom: 1px solid var(--border);
}

.portal-table th {
  background-color: var(--bg-alt);
  color: var(--ink-medium);
  font-weight: 700;
}

.portal-table tr:last-child td {
  border-bottom: none;
}

.badge-role {
  padding: 0.2rem 0.5rem;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  border-radius: 2px;
}

.badge-role.admin {
  background-color: var(--brand-light);
  color: var(--brand-hover);
}

.badge-role.stationmaster {
  background-color: #f3e8ff;
  color: #7e22ce;
}

.badge-role.user {
  background-color: var(--bg-alt);
  color: var(--ink-medium);
}

/* Modal Popups */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(15, 23, 42, 0.4);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}

.modal-backdrop.active {
  display: flex;
}

.modal-card {
  background-color: var(--surface);
  border: 1px solid var(--border);
  width: 100%;
  max-width: 450px;
  padding: var(--space-lg);
  position: relative;
  box-shadow: var(--shadow-lg);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-md);
}

.modal-header h3 {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 800;
}

.btn-close-modal {
  background: transparent;
  border: none;
  font-size: 1.25rem;
  color: var(--ink-muted);
  cursor: pointer;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-xs);
  margin-top: var(--space-md);
}

/* Loader Spinner */
.portal-loader {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  padding: var(--space-xl) 0;
  color: var(--ink-muted);
  font-weight: 500;
}

.spinner {
  width: 2.5rem;
  height: 2.5rem;
  border: 4px solid var(--border);
  border-top: 4px solid var(--brand);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

/* System Map Maker Layout */
.maps-container {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-md);
  width: 100%;
  text-align: left;
}

.maps-container.has-editor {
  grid-template-columns: 1fr 340px;
}

.map-viewer-card,
.map-editor-card {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: var(--space-md);
}

.viewer-header {
  margin-bottom: var(--space-sm);
}

.canvas-wrapper {
  border: 1px solid var(--border);
  background-color: #fafbfc;
  position: relative;
  overflow: hidden;
}

.legend-panel {
  margin-top: var(--space-sm);
  border-top: 1px solid var(--border);
  padding-top: var(--space-sm);
}

.legend-panel h4 {
  margin: 0 0 0.5rem;
  font-size: 1rem;
  font-weight: 700;
}

.legend-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 0.5rem;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
}

.editor-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  margin-bottom: var(--space-sm);
}

.editor-tab-btn {
  flex: 1;
  padding: 0.6rem;
  border: none;
  background: transparent;
  cursor: pointer;
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--ink-muted);
  text-align: center;
}

.editor-tab-btn.active {
  color: var(--brand);
  border-bottom: 2px solid var(--brand);
}

.editor-subtab {
  display: none;
}

.editor-subtab.active {
  display: block;
}

.sortable-list {
  list-style: none;
  padding: 0;
  margin: 0;
  max-height: 200px;
  overflow-y: auto;
  border: 1px solid var(--border);
}

.sortable-item {
  padding: 0.6rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg);
  font-size: 0.85rem;
  font-weight: 500;
}

.sortable-item:last-child {
  border-bottom: none;
}

.station-dot {
  transition:
    stroke 0.2s,
    stroke-width 0.2s,
    r 0.2s;
  cursor: pointer;
}

.station-dot.highlighted {
  stroke: var(--brand) !important;
  stroke-width: 4px !important;
  animation: pulse-marker 1.2s infinite alternate;
}

@keyframes pulse-marker {
  0% {
    r: 8px;
  }
  100% {
    r: 12px;
  }
}

@media (max-width: 1024px) {
  .maps-container.has-editor {
    grid-template-columns: 1fr;
  }
}

/* Mobile Drawer and Responsiveness optimizations */
@media (max-width: 768px) {
  .dashboard-wrapper {
    grid-template-columns: 1fr !important;
  }

  .dashboard-sidebar {
    position: fixed !important;
    left: -260px !important;
    top: 0 !important;
    bottom: 0 !important;
    width: 260px !important;
    z-index: 2000 !important;
    transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
    box-shadow: var(--shadow-lg) !important;
  }

  .dashboard-sidebar.active {
    left: 0 !important;
  }

  .sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(15, 23, 42, 0.4);
    z-index: 1999;
    display: none;
    opacity: 0;
    transition: opacity 0.2s ease;
  }

  .sidebar-overlay.active {
    display: block;
    opacity: 1;
  }

  .maps-container.has-editor {
    grid-template-columns: 1fr !important;
    position: relative;
  }

  #map-editor-panel {
    position: fixed !important;
    left: 0 !important;
    right: 0 !important;
    bottom: -100% !important; /* Slide down off screen */
    height: 70vh !important;
    background: var(--surface) !important;
    border-top: 2px solid var(--border) !important;
    border-radius: 16px 16px 0 0 !important;
    box-shadow: 0 -8px 24px rgba(15, 23, 42, 0.15) !important;
    z-index: 1001 !important;
    transition: bottom 0.35s cubic-bezier(0.4, 0, 0.2, 1) !important;
    overflow-y: auto !important;
    padding: var(--space-md) !important;
    display: none; /* Controlled by JS and css states */
  }

  #map-editor-panel.drawer-open {
    display: flex !important;
    bottom: 0 !important;
  }

  .drawer-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(15, 23, 42, 0.4);
    z-index: 1000;
    display: none;
    opacity: 0;
    transition: opacity 0.2s ease;
  }

  .drawer-backdrop.active {
    display: block;
    opacity: 1;
  }

  #btn-toggle-editor-drawer {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background-color: var(--brand);
    color: white;
    border: none;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.4);
    z-index: 1002;
    display: none; /* Toggled by switchTab JS */
    align-items: center;
    justify-content: center;
    font-size: 1.35rem;
    cursor: pointer;
    transition:
      transform 0.2s,
      background-color 0.2s;
  }
  #btn-toggle-editor-drawer:active {
    transform: scale(0.9);
  }
}

/* Map gallery styles */
.map-gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.5rem;
  width: 100%;
  max-width: 1000px;
  margin: 0 auto;
  padding: 1rem 0;
}

.map-gallery-card {
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.5rem;
  text-align: left;
  cursor: pointer;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  position: relative;
  overflow: hidden;
  min-height: 140px;
}

.map-gallery-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-md);
  border-color: var(--brand);
}

.map-gallery-title {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--ink);
  margin: 0 0 0.5rem 0;
}

.map-gallery-meta {
  font-size: 0.85rem;
  color: var(--ink-muted);
  display: flex;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.map-gallery-meta span {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.map-gallery-action {
  color: var(--brand);
  font-weight: 600;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 0.25rem;
  margin-top: auto;
}

/* Sidebar Toggle Button (Desktop & Mobile) */
.sidebar-toggle-btn {
  display: flex !important;
  background: none;
  border: none;
  color: var(--ink);
  font-size: 1.25rem;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  align-items: center;
  justify-content: center;
  transition: background-color 0.2s ease;
}

.sidebar-toggle-btn:hover {
  background-color: var(--bg-alt);
}

/* Desktop Collapsed Sidebar Layout & Animations */
@media (min-width: 769px) {
  /* Smooth transition for grid sidebar width change */
  .dashboard-wrapper {
    transition: grid-template-columns 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  }

  /* Shrink sidebar grid column when collapsed */
  .dashboard-wrapper.collapsed {
    grid-template-columns: 64px 1fr;
  }

  /* Compact padding for collapsed sidebar */
  .dashboard-wrapper.collapsed .dashboard-sidebar {
    padding: var(--space-md) 0.5rem;
    align-items: center;
  }

  /* Full width layout components when collapsed */
  .dashboard-wrapper.collapsed .dashboard-sidebar > div,
  .dashboard-wrapper.collapsed .sidebar-menu,
  .dashboard-wrapper.collapsed .sidebar-footer {
    width: 100%;
    align-items: center;
  }

  /* Hide sidebar brand text span */
  .dashboard-wrapper.collapsed .sidebar-brand span {
    display: none;
  }

  /* Adjust brand logo container */
  .dashboard-wrapper.collapsed .sidebar-brand {
    justify-content: center;
    width: 100%;
    padding-bottom: var(--space-sm);
    margin-bottom: var(--space-sm);
  }

  /* Center menu items and hide their labels */
  .dashboard-wrapper.collapsed .menu-item {
    justify-content: center;
    padding: 0.75rem 0;
    gap: 0;
    border-radius: 8px;
  }

  .dashboard-wrapper.collapsed .menu-item span {
    display: none;
  }

  /* Hide the profile email and role badges */
  .dashboard-wrapper.collapsed .user-badge-row {
    justify-content: center;
  }

  .dashboard-wrapper.collapsed .user-badge-info {
    display: none;
  }

  /* Slightly smaller avatar in collapsed mode */
  .dashboard-wrapper.collapsed .user-avatar-wrapper,
  .dashboard-wrapper.collapsed .user-avatar-img,
  .dashboard-wrapper.collapsed .user-avatar-fallback {
    width: 32px;
    height: 32px;
  }

  /* Scale and center the logout button */
  .dashboard-wrapper.collapsed .btn-logout {
    padding: 0.75rem 0;
    width: 100%;
    justify-content: center;
    gap: 0;
    border-radius: 6px;
  }

  .dashboard-wrapper.collapsed .btn-logout span {
    display: none;
  }
}
