:root {
  --bg-dark: #090d16;
  --bg-card: #131d2e;
  --bg-card-hover: #1e293b;
  --border-color: rgba(255, 255, 255, 0.12);
  --primary: #38bdf8;
  --primary-hover: #0284c7;
  --accent-green: #10b981;
  --accent-yellow: #f59e0b;
  --accent-red: #ef4444;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  --bottom-nav-height: 64px;
  --topbar-height: 56px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: var(--font-family);
  -webkit-tap-highlight-color: transparent;
}

html, body {
  background-color: var(--bg-dark);
  color: var(--text-main);
  height: 100%;
  width: 100%;
  overflow: hidden;
  position: fixed;
}

.app-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  width: 100vw;
  overflow: hidden;
}

/* ============================================================
   1. TOPBAR
   ============================================================ */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 16px;
  height: var(--topbar-height);
  background: rgba(15, 23, 42, 0.95);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-color);
  z-index: 1100;
  flex-shrink: 0;
}

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

.brand h1 {
  font-size: 1.05rem;
  font-weight: 800;
  letter-spacing: 0.5px;
  background: linear-gradient(135deg, #38bdf8, #818cf8);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.subtitle {
  font-size: 0.7rem;
  color: var(--text-muted);
  display: block;
}

.pulse-icon {
  font-size: 1.35rem;
  color: var(--primary);
  animation: pulse-ring 2s infinite;
}

@keyframes pulse-ring {
  0% { transform: scale(0.95); opacity: 0.8; }
  50% { transform: scale(1.1); opacity: 1; }
  100% { transform: scale(0.95); opacity: 0.8; }
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-icon-top {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-icon-top:active {
  transform: scale(0.92);
}

.badge {
  padding: 5px 10px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.badge-connected {
  background: rgba(16, 185, 129, 0.15);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.badge-disconnected {
  background: rgba(239, 68, 68, 0.15);
  color: #f87171;
  border: 1px solid rgba(239, 68, 68, 0.3);
}

/* ============================================================
   2. MAIN LAYOUT (DESKTOP DEFAULT)
   ============================================================ */
.main-content {
  display: grid;
  grid-template-columns: 320px 1fr 340px;
  flex: 1;
  overflow: hidden;
  position: relative;
}

/* Left Sidebar on Desktop */
.sidebar {
  background-color: var(--bg-card);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  padding: 16px;
  overflow-y: auto;
  gap: 16px;
  z-index: 1000;
}

.drawer-body {
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow-y: auto;
  flex: 1;
}

.tab-header {
  display: flex;
  background: var(--bg-dark);
  border-radius: 10px;
  padding: 4px;
  gap: 2px;
}

.tab-btn {
  flex: 1;
  padding: 8px 6px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 700;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  white-space: nowrap;
}

.tab-btn.active {
  background: var(--primary);
  color: #0f172a;
}

.tab-pane {
  display: none;
}

.tab-pane.active {
  display: block;
  animation: fadeIn 0.2s ease;
}

/* Panel Card */
.panel-card {
  background: rgba(15, 23, 42, 0.7);
  border: 1px solid var(--border-color);
  border-radius: 14px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.panel-card h3 {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.hint {
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.45;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
}

.highlight-val {
  color: var(--primary);
  font-weight: 700;
  margin-left: auto;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

/* Inputs & Form Controls */
input, select {
  background: #090d16;
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 12px 14px;
  border-radius: 10px;
  font-size: 16px; /* Prevents iOS auto-zoom */
  outline: none;
  transition: border-color 0.2s;
  width: 100%;
}

input:focus, select:focus {
  border-color: var(--primary);
}

.input-with-label {
  position: relative;
  display: flex;
  align-items: center;
}

.input-with-label input {
  padding-right: 44px;
}

.input-with-label .unit {
  position: absolute;
  right: 14px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
}

/* Buttons */
.btn {
  padding: 12px 16px;
  border-radius: 10px;
  font-weight: 700;
  font-size: 0.9rem;
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all 0.2s;
  touch-action: manipulation;
}

.btn-lg {
  padding: 14px 20px;
  font-size: 0.95rem;
}

.btn:active {
  transform: scale(0.98);
}

.btn-block {
  width: 100%;
}

.btn-primary {
  background: linear-gradient(135deg, #0284c7, #38bdf8);
  color: #0f172a;
  box-shadow: 0 4px 14px rgba(56, 189, 248, 0.25);
}

.btn-success {
  background: linear-gradient(135deg, #059669, #10b981);
  color: #ffffff;
}

.btn-danger {
  background: linear-gradient(135deg, #dc2626, #ef4444);
  color: #ffffff;
}

.btn-secondary {
  background: var(--bg-card-hover);
  color: var(--text-main);
  border: 1px solid var(--border-color);
}

.stats-panel {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: auto;
}

.stat-item {
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 10px;
  text-align: center;
}

.stat-num {
  display: block;
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--primary);
}

.stat-label {
  font-size: 0.7rem;
  color: var(--text-muted);
}

.classes-scroll-box {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 280px;
  overflow-y: auto;
}

/* ============================================================
   3. CENTER MAP & FLOATING ACTION BUTTONS (FAB)
   ============================================================ */
.map-container {
  position: relative;
  height: 100%;
  width: 100%;
  overflow: hidden;
}

#map {
  height: 100%;
  width: 100%;
  background-color: #131d2e;
}

/* Mode Banner Floating on Top */
.mode-indicator {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(15, 23, 42, 0.95);
  border: 2px solid var(--primary);
  color: var(--primary);
  padding: 8px 16px;
  border-radius: 30px;
  font-size: 0.85rem;
  font-weight: 700;
  z-index: 1050;
  box-shadow: 0 6px 24px rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 90%;
  text-align: center;
}

.mode-indicator.hidden {
  display: none !important;
}

.btn-cancel-indicator {
  background: rgba(239, 68, 68, 0.2);
  border: 1px solid #ef4444;
  color: #ef4444;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  margin-left: 4px;
}

/* Map FAB Buttons (Floating on Map) */
.map-fab-container {
  position: absolute;
  bottom: 24px;
  right: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 1000;
}

.fab-btn {
  border: none;
  border-radius: 50px;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  touch-action: manipulation;
}

.fab-btn:active {
  transform: scale(0.92);
}

.fab-primary {
  background: linear-gradient(135deg, #0284c7, #38bdf8);
  color: #0f172a;
  padding: 12px 18px;
  font-weight: 800;
  font-size: 0.88rem;
  gap: 8px;
}

.fab-secondary {
  background: rgba(30, 41, 59, 0.95);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  width: 44px;
  height: 44px;
  font-size: 1.1rem;
  align-self: flex-end;
}

/* ============================================================
   4. RIGHT PANEL: LOGS (DESKTOP)
   ============================================================ */
.right-panel {
  background-color: var(--bg-card);
  border-left: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 1000;
}

.panel-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.panel-header h3 {
  font-size: 0.9rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-icon {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px 8px;
  border-radius: 6px;
}

.btn-icon:hover {
  color: var(--accent-red);
}

.logs-container {
  flex: 1;
  padding: 12px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.log-entry {
  background: rgba(15, 23, 42, 0.85);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 0.82rem;
  animation: fadeIn 0.25s ease;
}

.log-entry.info { border-left: 4px solid var(--primary); }
.log-entry.success { border-left: 4px solid var(--accent-green); background: rgba(16, 185, 129, 0.08); }
.log-entry.warning { border-left: 4px solid var(--accent-yellow); }
.log-entry.error { border-left: 4px solid var(--accent-red); }

.log-entry .time {
  font-size: 0.68rem;
  color: var(--text-muted);
  display: block;
  margin-bottom: 4px;
}

.log-entry .match-score-card {
  margin-top: 8px;
  padding: 8px 10px;
  background: rgba(30, 41, 59, 0.9);
  border-radius: 8px;
  font-size: 0.78rem;
}

/* Custom Marker Styles */
.custom-marker {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 14px rgba(0,0,0,0.6);
  position: relative;
  font-size: 18px;
}

.teacher-marker.status-available {
  background: #10b981;
  border: 2.5px solid #ffffff;
}

.teacher-marker.status-pending {
  background: #f59e0b;
  border: 2.5px solid #ffffff;
  animation: pulse-ring 1s infinite;
}

.teacher-marker.status-busy {
  background: #64748b;
  border: 2.5px solid #94a3b8;
}

.student-marker {
  background: #38bdf8;
  border: 2.5px solid #ffffff;
}

.marker-badge {
  position: absolute;
  bottom: -6px;
  right: -6px;
  background: #0f172a;
  color: #fbbf24;
  font-size: 9px;
  font-weight: 800;
  padding: 2px 4px;
  border-radius: 6px;
  border: 1px solid var(--border-color);
}

/* ============================================================
   5. MODAL (2-WAY HANDSHAKE)
   ============================================================ */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}

.modal.hidden {
  display: none !important;
}

.modal-backdrop {
  position: absolute;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(8px);
}

.modal-content {
  position: relative;
  background: #131d2e;
  border: 2px solid var(--primary);
  border-radius: 20px;
  width: 90%;
  max-width: 440px;
  padding: 24px;
  box-shadow: 0 16px 50px rgba(0, 0, 0, 0.8);
  display: flex;
  flex-direction: column;
  gap: 16px;
  animation: scaleUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  max-height: 90vh;
  overflow-y: auto;
}

@keyframes scaleUp {
  from { transform: scale(0.92); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-badge {
  background: var(--primary);
  color: #0f172a;
  font-size: 0.8rem;
  font-weight: 800;
  padding: 5px 12px;
  border-radius: 20px;
}

.countdown {
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--accent-yellow);
}

.modal-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

/* ============================================================
   6. MOBILE-SPECIFIC RESPONSIVE STYLES (UNDER 1024px)
   ============================================================ */
.desktop-hidden {
  display: none !important;
}

@media (max-width: 1024px) {
  .desktop-only {
    display: none !important;
  }

  .desktop-hidden {
    display: flex !important;
  }

  /* Full Viewport Map on Mobile */
  .main-content {
    display: flex;
    flex-direction: column;
    height: calc(100dvh - var(--topbar-height) - var(--bottom-nav-height));
    position: relative;
  }

  .map-container {
    height: 100%;
    width: 100%;
  }

  /* Slide-Up Bottom Drawer Sheet on Mobile */
  .sidebar {
    position: fixed;
    bottom: var(--bottom-nav-height);
    left: 0;
    width: 100%;
    max-height: 80dvh;
    border-radius: 24px 24px 0 0;
    border-top: 1px solid var(--border-color);
    border-right: none;
    background: rgba(19, 29, 46, 0.98);
    backdrop-filter: blur(20px);
    box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.7);
    padding: 12px 16px 20px 16px;
    z-index: 1200;
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  }

  .sidebar.drawer-closed {
    transform: translateY(120%);
    pointer-events: none;
  }

  .sidebar:not(.drawer-closed) {
    transform: translateY(0);
    pointer-events: auto;
  }

  .drawer-handle {
    width: 100%;
    display: flex;
    justify-content: center;
    padding: 6px 0 10px 0;
    cursor: pointer;
  }

  .handle-bar {
    width: 44px;
    height: 5px;
    background: rgba(255, 255, 255, 0.25);
    border-radius: 10px;
  }

  .drawer-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 12px;
  }

  .drawer-title {
    font-size: 1rem;
    font-weight: 800;
    color: var(--primary);
  }

  .btn-close-drawer {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: var(--text-main);
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
  }

  /* Fixed Mobile Bottom Navigation Bar */
  .mobile-bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: var(--bottom-nav-height);
    background: rgba(15, 23, 42, 0.98);
    backdrop-filter: blur(16px);
    border-top: 1px solid var(--border-color);
    display: grid !important;
    grid-template-columns: repeat(6, 1fr);
    z-index: 1300;
    padding-bottom: env(safe-area-inset-bottom, 0);
  }

  .nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 0.65rem;
    font-weight: 600;
    gap: 4px;
    cursor: pointer;
    transition: color 0.2s;
    touch-action: manipulation;
  }

  .nav-item i {
    font-size: 1.15rem;
    transition: transform 0.2s;
  }

  .nav-item.active {
    color: var(--primary);
  }

  .nav-item.active i {
    transform: scale(1.15);
  }

  /* FAB Position adjustment on Mobile */
  .map-fab-container {
    bottom: calc(var(--bottom-nav-height) + 16px);
  }

  /* Modal on Mobile becomes a sleek bottom sheet */
  .modal {
    align-items: flex-end;
  }

  .modal-content {
    width: 100%;
    max-width: 100%;
    border-radius: 24px 24px 0 0;
    margin-bottom: 0;
    padding: 20px 16px calc(20px + env(safe-area-inset-bottom, 0)) 16px;
    border-bottom: none;
  }
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}
