/* MapMap — Map Viewer Styles */

:root, [data-theme="dark"] {
  --bg: #0f1117; --surface: #1a1d27; --surface2: #232736;
  --border: #2e3345; --text: #e4e6f0; --text-dim: #8b8fa3;
  --text-muted: #5c6078; --accent: #f97316;
  --accent-dim: rgba(249,115,22,0.15);
  --radius: 8px; --shadow: 0 4px 24px rgba(0,0,0,0.4);
}
[data-theme="light"] {
  --bg: #f5f5f7; --surface: #ffffff; --surface2: #ecedf0;
  --border: #d5d7de; --text: #1a1d27; --text-dim: #555a6e;
  --text-muted: #8b8fa3; --accent: #e86305;
  --accent-dim: rgba(232,99,5,0.10);
  --shadow: 0 4px 24px rgba(0,0,0,0.10);
}
[data-theme="light"] .marker-icon         { border-color: rgba(0,0,0,.55); box-shadow: 0 2px 8px rgba(0,0,0,.2); }
[data-theme="light"] .marker-icon.outdated { border-color: #dc2626; }
[data-theme="light"] .legend-dot          { border-color: rgba(0,0,0,.3); }
[data-theme="light"] .modal-overlay       { background: rgba(0,0,0,.35); }
[data-theme="light"] .edit-overlay        { background: rgba(0,0,0,.30); }
[data-theme="light"] .register-overlay    { background: rgba(0,0,0,.30); }

* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: 'DM Sans', sans-serif; background: var(--bg); color: var(--text); height: 100vh; overflow: hidden; }

/* Loading screen */
#loading-screen { position: fixed; inset: 0; z-index: 9999; background: var(--bg); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; transition: opacity .4s; }
#loading-screen.hidden { opacity: 0; pointer-events: none; }
.spinner { width: 36px; height: 36px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin  { to { transform: rotate(360deg); } }
@keyframes pulse { 0%, 100% { opacity: .6; } 50% { opacity: 1; } }
#loading-screen p { color: var(--text-dim); font-size: 14px; }

/* Header */
header { height: 52px; background: var(--surface); border-bottom: 1px solid var(--border); display: flex; align-items: center; padding: 0 20px; gap: 16px; z-index: 1000; position: relative; }
.logo { font-weight: 700; font-size: 18px; letter-spacing: -.5px; display: flex; align-items: center; gap: 8px; }
.logo-icon { width: 28px; height: 28px; background: var(--accent); border-radius: 6px; display: flex; align-items: center; justify-content: center; font-size: 14px; }
.header-stats { font-size: 13px; color: var(--text-dim); font-weight: 300; }
.header-stats span { color: var(--accent); font-family: 'JetBrains Mono', monospace; font-weight: 600; font-size: 12px; }

/* Layout */
.app-layout { display: flex; height: calc(100vh - 52px); }

/* Sidebar */
.sidebar { width: 340px; min-width: 340px; background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; overflow: hidden; }
.search-box { padding: 12px 16px; border-bottom: 1px solid var(--border); position: relative; }
.search-box input { width: 100%; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 9px 12px 9px 36px; color: var(--text); font-family: inherit; font-size: 13px; outline: none; transition: border-color .2s; }
.search-box input:focus { border-color: var(--accent); }
.search-icon { position: absolute; left: 28px; top: 50%; transform: translateY(-50%); color: var(--text-muted); font-size: 14px; pointer-events: none; }

/* Filters */
.filters { padding: 12px 16px; border-bottom: 1px solid var(--border); display: flex; flex-direction: column; gap: 10px; }
.filter-group label { display: block; font-size: 10px; text-transform: uppercase; letter-spacing: 1px; color: var(--text-muted); margin-bottom: 6px; font-weight: 500; }
.filter-chips { display: flex; flex-wrap: wrap; gap: 5px; }
.chip { font-size: 11px; padding: 4px 10px; border-radius: 20px; border: 1px solid var(--border); background: transparent; color: var(--text-dim); cursor: pointer; transition: all .15s; font-family: inherit; font-weight: 500; white-space: nowrap; }
.chip:hover { border-color: var(--text-dim); color: var(--text); }
.chip.active { border-color: var(--accent); background: var(--accent-dim); color: var(--accent); }
.chip .dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 4px; vertical-align: middle; }

/* Map list */
.map-list { flex: 1; overflow-y: auto; padding: 8px; }
.map-list::-webkit-scrollbar       { width: 6px; }
.map-list::-webkit-scrollbar-track { background: transparent; }
.map-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
.list-item { padding: 10px 12px; border-radius: var(--radius); cursor: pointer; transition: background .15s; border: 1px solid transparent; margin-bottom: 2px; }
.list-item:hover    { background: var(--surface2); }
.list-item.selected { background: var(--surface2); border-color: var(--border); }
.list-item-name { font-size: 13px; font-weight: 500; margin-bottom: 3px; display: flex; align-items: center; gap: 6px; }
.list-item-meta { font-size: 11px; color: var(--text-dim); display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }

/* Badges */
.badge        { font-size: 10px; padding: 1px 6px; border-radius: 3px; font-weight: 600; font-family: 'JetBrains Mono', monospace; color: #fff; }
.multi-badge  { font-size: 10px; background: var(--accent-dim); color: var(--accent); padding: 1px 6px; border-radius: 3px; font-weight: 600; font-family: 'JetBrains Mono', monospace; }
.status-badge { font-size: 9px; padding: 1px 5px; border-radius: 3px; font-weight: 600; font-family: 'JetBrains Mono', monospace; text-transform: uppercase; letter-spacing: .3px; }
.status-complete { background: rgba(16,185,129,.15);  color: #34d399; }
.status-draft    { background: rgba(251,191,36,.15);  color: #fbbf24; }
.status-assigned { background: rgba(96,165,250,.15);  color: #60a5fa; }
.status-needed   { background: rgba(107,114,128,.15); color: #9ca3af; }
.status-outdated { background: rgba(248,113,113,.15); color: #f87171; }
.list-count { padding: 8px 16px; font-size: 11px; color: var(--text-muted); border-bottom: 1px solid var(--border); font-family: 'JetBrains Mono', monospace; }

/* Map container */
.map-container { flex: 1; position: relative; }
#map { width: 100%; height: 100%; background: var(--bg); }

/* Leaflet overrides */
.leaflet-popup-content-wrapper { background: var(--surface) !important; color: var(--text) !important; border-radius: var(--radius) !important; box-shadow: var(--shadow) !important; border: 1px solid var(--border) !important; }
.leaflet-popup-tip             { background: var(--surface) !important; border: 1px solid var(--border) !important; border-top: none !important; border-left: none !important; }
.leaflet-popup-content         { margin: 14px 16px !important; font-family: 'DM Sans', sans-serif !important; font-size: 13px !important; line-height: 1.5 !important; }
.leaflet-popup-close-button    { color: var(--text-dim) !important; font-size: 20px !important; }
.leaflet-control-zoom a        { background: var(--surface) !important; color: var(--text) !important; border-color: var(--border) !important; }
.leaflet-control-zoom a:hover  { background: var(--surface2) !important; }

/* Popup content */
.popup-header      { font-size: 15px; font-weight: 700; margin-bottom: 2px; }
.popup-location    { font-size: 12px; color: var(--text-dim); margin-bottom: 10px; }
.popup-maps        { display: flex; flex-direction: column; gap: 10px; }
.popup-map-entry   { background: var(--bg); border-radius: 6px; padding: 10px; border: 1px solid var(--border); }
.popup-map-title   { font-weight: 500; font-size: 13px; margin-bottom: 6px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.popup-map-details { font-size: 11px; color: var(--text-dim); display: flex; flex-direction: column; gap: 3px; }
.popup-map-details .detail-row   { display: flex; gap: 6px; }
.popup-map-details .detail-label { color: var(--text-muted); min-width: 70px; }
.popup-links { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.popup-link      { font-size: 11px; padding: 4px 10px; border-radius: 4px; text-decoration: none; font-weight: 500; transition: opacity .15s; }
.popup-link:hover { opacity: .8; }
.popup-link.view-map    { background: var(--accent); color: #fff; }
.popup-link.view-folder { background: var(--surface2); color: var(--text-dim); border: 1px solid var(--border); }

/* Map markers */
.marker-icon       { display: flex; align-items: center; justify-content: center; border-radius: 50%; border: 2px solid rgba(255,255,255,.9); box-shadow: 0 2px 8px rgba(0,0,0,.4); font-size: 9px; font-weight: 700; color: #fff; font-family: 'JetBrains Mono', monospace; transition: transform .15s; }
.marker-icon:hover { transform: scale(1.3); z-index: 9999 !important; }
.marker-icon.multi    { border-width: 3px; border-style: double; }
.marker-icon.needed   { border-style: dashed; opacity: .6; }
.marker-icon.assigned { animation: pulse 2s ease-in-out infinite; }
.marker-icon.draft    { opacity: .8; }
.marker-icon.outdated { border-color: #f87171; }

/* Map legend */
.map-legend   { position: absolute; bottom: 24px; right: 12px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; z-index: 800; font-size: 11px; box-shadow: var(--shadow); }
.legend-title { font-weight: 700; font-size: 10px; text-transform: uppercase; letter-spacing: .8px; color: var(--text-muted); margin-bottom: 8px; }
.legend-item  { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; color: var(--text-dim); }
.legend-dot   { width: 10px; height: 10px; border-radius: 50%; border: 1.5px solid rgba(255,255,255,.5); flex-shrink: 0; }
.legend-sep   { margin: 6px 0; padding-top: 6px; border-top: 1px solid var(--border); }

/* Misc */
.no-results      { padding: 24px 16px; text-align: center; color: var(--text-muted); font-size: 13px; }
.no-coords-badge { font-size: 11px; opacity: .7; flex-shrink: 0; }
.list-item.no-coords  { opacity: .75; border-style: dashed; }
.restricted-notice    { font-size: 0.8rem; color: #f59e0b; margin-top: 6px; font-style: italic; }

/* Buttons */
.add-map-btn { background: var(--accent); color: #fff; border: none; padding: 6px 14px; border-radius: var(--radius); font-family: inherit; font-size: 13px; font-weight: 500; cursor: pointer; transition: opacity .15s; margin-left: 12px; }
.add-map-btn:hover { opacity: .85; }

/* Modal (iframe) */
.modal-overlay { position: fixed; inset: 0; z-index: 9000; background: rgba(0,0,0,.6); display: none; align-items: center; justify-content: center; }
.modal-overlay.open { display: flex; }
.modal-box { width: min(900px, 95vw); height: 90vh; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; position: relative; overflow: hidden; box-shadow: 0 16px 64px rgba(0,0,0,.5); }
.modal-close { position: absolute; top: 10px; right: 14px; z-index: 10; background: var(--surface2); border: 1px solid var(--border); color: var(--text-dim); width: 30px; height: 30px; border-radius: 50%; font-size: 18px; cursor: pointer; display: flex; align-items: center; justify-content: center; transition: all .15s; }
.modal-close:hover { color: var(--text); border-color: var(--text-dim); }
.modal-box iframe { width: 100%; height: 100%; border: none; }

/* ── Hamburger button (desktop: hidden) ──────────────────────────────────── */
.hamburger-btn {
  display: none;
  background: var(--surface2); border: 1px solid var(--border); color: var(--text-dim);
  width: 32px; height: 32px; border-radius: 50%; font-size: 18px; cursor: pointer;
  align-items: center; justify-content: center; transition: all .15s; flex-shrink: 0;
}
.hamburger-btn:hover { border-color: var(--text-dim); color: var(--text); }

/* ── Mobile nav dropdown ─────────────────────────────────────────────────── */
.mobile-nav-backdrop {
  display: none; position: fixed; inset: 0; z-index: 940;
}
.mobile-nav-backdrop.open { display: block; }

.mobile-nav-dropdown {
  display: none; position: fixed; top: 52px; left: 0; right: 0;
  background: var(--surface); border-bottom: 1px solid var(--border);
  z-index: 950; padding: 6px 0;
  box-shadow: 0 8px 24px rgba(0,0,0,.3);
  animation: slideDown .18s ease;
}
.mobile-nav-dropdown.open { display: block; }
@keyframes slideDown {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.mobile-nav-item {
  display: flex; align-items: center; width: 100%; padding: 14px 20px;
  font-family: inherit; font-size: 15px; font-weight: 500;
  color: var(--text); background: none; border: none; cursor: pointer;
  text-decoration: none; transition: background .15s;
}
.mobile-nav-item:hover { background: var(--surface2); }
.mobile-nav-divider { height: 1px; background: var(--border); margin: 4px 0; }

/* ── Mobile tab bar (desktop: hidden) ────────────────────────────────────── */
.mobile-tab-bar { display: none; }

/* ── Mobile breakpoint ───────────────────────────────────────────────────── */
@media (max-width: 768px) {

  /* Header: show hamburger, hide stats and all individual nav buttons */
  .hamburger-btn { display: flex; }
  .header-stats  { display: none; }
  #btn-add-map, #btn-course, #btn-programs, #btn-issues,
  #btn-admin, #btn-register { display: none !important; }

  /* Layout: shrink to leave room for the fixed tab bar */
  .app-layout { height: calc(100vh - 52px - 56px); }

  /* Sidebar: fixed full-screen overlay (hidden until List tab is tapped) */
  .sidebar {
    display: none; position: fixed;
    top: 52px; left: 0; right: 0; bottom: 56px;
    width: 100%; min-width: 0; z-index: 800; border-right: none;
  }
  .sidebar.mobile-visible { display: flex; }

  /* Filter chips: horizontal scroll instead of wrapping */
  .filter-chips { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 4px; -ms-overflow-style: none; scrollbar-width: none; }
  .filter-chips::-webkit-scrollbar { display: none; }

  /* Hide the map legend on small screens */
  .map-legend { display: none; }

  /* Bottom tab bar */
  .mobile-tab-bar {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0;
    height: 56px; background: var(--surface); border-top: 1px solid var(--border); z-index: 900;
  }
  .mobile-tab {
    flex: 1; display: flex; flex-direction: column; align-items: center;
    justify-content: center; gap: 3px; background: none; border: none;
    font-family: inherit; font-size: 11px; font-weight: 500;
    color: var(--text-dim); cursor: pointer; transition: color .15s;
  }
  .mobile-tab .tab-icon { font-size: 20px; line-height: 1; }
  .mobile-tab.active { color: var(--accent); }
}

/* Auth UI */
.auth-area  { display: flex; align-items: center; gap: 10px; margin-left: auto; }
.user-info  { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-dim); }
.user-avatar { width: 24px; height: 24px; border-radius: 50%; }
.role-badge  { font-size: 9px; padding: 1px 6px; border-radius: 3px; font-weight: 600; font-family: 'JetBrains Mono', monospace; text-transform: uppercase; letter-spacing: .3px; }
.role-badge.viewer  { background: rgba(96,165,250,.15);  color: #60a5fa; }
.role-badge.staff   { background: rgba(52,211,153,.15);  color: #34d399; }
.role-badge.manager { background: rgba(249,115,22,.15);  color: var(--accent); }
.sign-out-btn { background: var(--surface2); border: 1px solid var(--border); color: var(--text-dim); padding: 4px 10px; border-radius: var(--radius); font-family: inherit; font-size: 11px; cursor: pointer; transition: all .15s; }
.sign-out-btn:hover { border-color: var(--text-dim); color: var(--text); }
.nav-btn      { background: var(--surface2); border: 1px solid var(--border); color: var(--text-dim); padding: 6px 14px; border-radius: var(--radius); font-family: inherit; font-size: 13px; font-weight: 500; cursor: pointer; transition: all .15s; text-decoration: none; }
.nav-btn:hover { border-color: var(--text-dim); color: var(--text); }

/* Registration modal */
.register-overlay { position: fixed; inset: 0; z-index: 9500; background: rgba(0,0,0,.6); display: none; align-items: center; justify-content: center; }
.register-overlay.open { display: flex; }
.register-box { width: min(420px, 90vw); background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 28px; box-shadow: 0 16px 64px rgba(0,0,0,.5); }
.register-box h2 { font-size: 18px; font-weight: 700; margin-bottom: 4px; }
.register-box p  { font-size: 13px; color: var(--text-dim); margin-bottom: 20px; }
.register-box label { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .8px; color: var(--text-muted); margin-bottom: 4px; margin-top: 14px; font-weight: 500; }
.register-box input,
.register-box select { width: 100%; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 9px 12px; color: var(--text); font-family: inherit; font-size: 13px; outline: none; }
.register-box input:focus,
.register-box select:focus { border-color: var(--accent); }
.register-box select { appearance: none; -webkit-appearance: none; }
.register-actions { display: flex; gap: 10px; margin-top: 20px; }
.register-actions button { flex: 1; padding: 9px; border-radius: var(--radius); font-family: inherit; font-size: 13px; font-weight: 500; cursor: pointer; border: none; }
.register-submit { background: var(--accent); color: #fff; }
.register-cancel { background: var(--surface2); color: var(--text-dim); border: 1px solid var(--border) !important; }

/* Edit map modal */
.edit-overlay { position: fixed; inset: 0; z-index: 9800; background: rgba(0,0,0,.65); display: none; align-items: center; justify-content: center; }
.edit-overlay.open { display: flex; }
.edit-box { width: min(580px, 94vw); max-height: 90vh; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 24px 26px; box-shadow: 0 16px 64px rgba(0,0,0,.5); overflow-y: auto; position: relative; }
.edit-box h2  { font-size: 17px; font-weight: 700; margin-bottom: 2px; }
.edit-meta    { font-size: 12px; color: var(--text-dim); margin-bottom: 18px; }
.edit-section { font-size: 10px; text-transform: uppercase; letter-spacing: .9px; color: var(--text-muted); font-weight: 500; margin-top: 18px; margin-bottom: 8px; padding-bottom: 5px; border-bottom: 1px solid var(--border); }
.edit-row      { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 10px; }
.edit-row.full { grid-template-columns: 1fr; }
.edit-field label { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .7px; color: var(--text-muted); margin-bottom: 4px; font-weight: 500; }
.edit-field input,
.edit-field select,
.edit-field textarea { width: 100%; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 8px 10px; color: var(--text); font-family: inherit; font-size: 13px; outline: none; transition: border-color .15s; }
.edit-field input:focus,
.edit-field select:focus,
.edit-field textarea:focus { border-color: var(--accent); }
.edit-field select  { appearance: none; -webkit-appearance: none; }
.edit-field textarea { resize: vertical; min-height: 64px; }
.edit-tristate-row { display: flex; gap: 20px; margin-bottom: 10px; }
.edit-tristate { display: flex; flex-direction: column; gap: 4px; }
.edit-tristate label  { font-size: 11px; text-transform: uppercase; letter-spacing: .7px; color: var(--text-muted); font-weight: 500; }
.edit-tristate select { background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 8px 10px; color: var(--text); font-family: inherit; font-size: 13px; outline: none; transition: border-color .15s; appearance: none; -webkit-appearance: none; min-width: 140px; }
.edit-tristate select:focus { border-color: var(--accent); }
.edit-actions  { display: flex; gap: 10px; margin-top: 22px; justify-content: flex-end; }
.edit-save     { background: var(--accent); color: #fff; border: 1px solid transparent; padding: 8px 20px; border-radius: var(--radius); font-family: inherit; font-size: 13px; font-weight: 500; cursor: pointer; transition: opacity .15s, background .2s, color .2s, border-color .2s; }
.edit-save:hover    { opacity: .85; }
.edit-save:disabled { opacity: .5; cursor: default; }
.edit-save.idle     { background: var(--surface2); color: var(--text-dim); border-color: var(--border); opacity: 1; cursor: default; }
.edit-save.idle:hover { opacity: 1; }
.edit-cancel  { background: var(--surface2); color: var(--text-dim); border: 1px solid var(--border); padding: 8px 16px; border-radius: var(--radius); font-family: inherit; font-size: 13px; cursor: pointer; }
.edit-delete  { background: transparent; color: #f87171; border: 1px solid #f87171; padding: 8px 16px; border-radius: var(--radius); font-family: inherit; font-size: 13px; cursor: pointer; margin-right: auto; transition: background .15s, color .15s; }
.edit-delete:hover    { background: #f87171; color: #fff; }
.edit-delete:disabled { opacity: .5; cursor: default; }
.edit-error   { font-size: 12px; color: #f87171; margin-top: 8px; display: none; }
.edit-btn-small { background: var(--surface2); color: var(--text-dim); border: 1px solid var(--border); padding: 5px 12px; border-radius: var(--radius); font-family: inherit; font-size: 12px; cursor: pointer; white-space: nowrap; transition: border-color .15s, color .15s, background .15s; }
.edit-btn-small:hover    { border-color: var(--accent); color: var(--text); }
.edit-btn-small:disabled { opacity: .5; cursor: default; }
.edit-btn-small.file-ready       { background: var(--accent); color: #fff; border-color: var(--accent); }
.edit-btn-small.file-ready:hover { opacity: .85; color: #fff; border-color: var(--accent); }
.edit-upload-ok  { color: #34d399; }
.edit-upload-err { color: #f87171; }

/* Theme toggle */
.theme-toggle       { background: var(--surface2); border: 1px solid var(--border); color: var(--text-dim); width: 32px; height: 32px; border-radius: 50%; font-size: 16px; cursor: pointer; display: flex; align-items: center; justify-content: center; transition: all .15s; flex-shrink: 0; }
.theme-toggle:hover { border-color: var(--text-dim); color: var(--text); }
