/* --- GLOBAL VARIABLES --- */
:root { 
    --glass-bg: rgba(255, 255, 255, 0.95); 
    --accent: #2563eb; 
    --text-dark: #0f172a; 
    --text-light: #64748b; 
    --danger: #ef4444;
    --success: #22c55e;
}

body { 
    margin: 0; height: 100vh; overflow: hidden; 
    font-family: 'Inter', sans-serif; 
    background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 100%); 
    display: flex; 
}

/* Helper Class */
.hidden { display: none !important; }

/* --- LOGIN SCREEN --- */
#login-container {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%; z-index: 1000;
    display: flex; justify-content: center; align-items: center;
    background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 100%);
}
.login-card { width: 320px; padding: 40px; text-align: center; display: flex; flex-direction: column; gap: 15px; }
.login-logo { font-size: 2.5rem; margin-bottom: 10px; }

/* --- GLASS UI --- */
.glass-panel { 
    background: var(--glass-bg); 
    backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); 
    border: 1px solid white; border-radius: 16px; 
    box-shadow: 0 4px 30px rgba(0,0,0,0.05); 
}

/* --- ADMIN DASHBOARD LAYOUT --- */
#dashboard-container, #system-dashboard {
    width: 100%; height: 100%; display: flex;
}

.dash-sidebar {
    width: 260px; background: white; border-right: 1px solid #e2e8f0;
    padding: 20px; display: flex; flex-direction: column; gap: 10px;
}

.dash-logo { font-weight: 700; font-size: 1.2rem; color: var(--text-dark); margin-bottom: 30px; display: flex; align-items: center; gap: 10px; }

.dash-nav-item {
    padding: 12px 15px; border-radius: 8px; cursor: pointer; text-decoration: none;
    color: var(--text-light); font-weight: 500; transition: 0.2s;
    display: flex; align-items: center; gap: 10px;
}
.dash-nav-item:hover { background: #f1f5f9; color: var(--accent); }
.dash-nav-item.active { background: #eff6ff; color: var(--accent); font-weight: 600; }

/* --- FIXED LAYOUT (V45.3 Update) --- */
.dash-content {
    flex: 1;
    padding: 30px; 
    height: 100vh;
    overflow-y: auto;
}

.dash-layout {
    display: flex;
    gap: 40px;
    max-width: 1400px;
    margin: 0 auto;
    align-items: flex-start; /* Prevents stretching */
}

/* LEFT COLUMN (Main) */
.dash-main {
    flex: 1; 
    min-width: 0; /* Prevents overflow issues */
}

/* RIGHT COLUMN (Sidebar) */
.dash-sidebar-right {
    width: 320px; /* Fixed width */
    flex-shrink: 0; /* Never shrink */
    display: flex;
    flex-direction: column;
    gap: 20px;
    position: sticky; /* Stays fixed while scrolling */
    top: 0;
}

/* WIDGET STYLING */
.widget-card { 
    background: white; border-radius: 12px; padding: 20px; 
    border: 1px solid #e2e8f0; 
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05); 
    max-height: calc(100vh - 60px); 
    overflow-y: auto; 
}
.widget-header { font-size: 1rem; font-weight: 600; color: #1e293b; margin-bottom: 15px; display: flex; justify-content: space-between; align-items: center; }
.booking-item { padding: 12px; border: 1px solid #f1f5f9; border-radius: 8px; margin-bottom: 10px; background: #f8fafc; transition: 0.2s; display: flex; justify-content: space-between; align-items: center; }
.booking-item:hover { border-color: #cbd5e1; background: white; transform: translateX(2px); }
.booking-date { font-weight: 600; color: #334155; font-size: 0.9rem; }
.booking-meta { font-size: 0.8rem; color: #64748b; margin-top: 2px; }

/* --- LOCATIONS GRID --- */
.locations-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 20px; }

.office-card {
    background: white; border: 1px solid #e2e8f0; border-radius: 12px;
    padding: 20px; transition: 0.2s;
}
.office-card:hover { transform: translateY(-2px); box-shadow: 0 10px 25px rgba(0,0,0,0.05); border-color: var(--accent); }

.office-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 15px; }
.office-title { font-weight: 600; color: var(--text-dark); font-size: 1.1rem; }
.floor-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.floor-item {
    display: flex; justify-content: space-between; align-items: center;
    padding: 10px; background: #f8fafc; border-radius: 8px; font-size: 0.9rem;
}
.btn-text { background: none; border: none; color: var(--accent); font-weight: 600; cursor: pointer; font-size: 0.85rem; }
.btn-text:hover { text-decoration: underline; }

/* --- USER TABLE --- */
.data-table { width: 100%; border-collapse: collapse; background: white; border-radius: 12px; overflow: hidden; border: 1px solid #e2e8f0; }
.data-table th { background: #f8fafc; text-align: left; padding: 15px; font-size: 0.85rem; color: var(--text-light); font-weight: 600; }
.data-table td { padding: 15px; border-top: 1px solid #e2e8f0; font-size: 0.9rem; color: var(--text-dark); }

/* --- FORM ELEMENTS --- */
.form-input { 
    width: 100%; padding: 12px; border: 1px solid #e2e8f0; border-radius: 10px; 
    font-family: 'Inter', sans-serif; outline: none; transition: 0.2s; 
    box-sizing: border-box; font-size: 0.95rem; margin-bottom: 10px;
}
.form-input:focus { border-color: var(--accent); }

.btn-primary { 
    background: var(--accent); color: white; border: none; padding: 14px; border-radius: 12px; 
    width: 100%; font-weight: 600; cursor: pointer; transition: 0.2s; 
}
.btn-primary:hover { filter: brightness(110%); }

/* --- MODALS --- */
.modal-overlay { position: fixed; top:0; left:0; width:100%; height:100%; background: rgba(0,0,0,0.4); z-index: 3000; display: none; justify-content: center; align-items: center; backdrop-filter: blur(2px); }
.modal-card { background: white; padding: 25px; border-radius: 12px; width: 320px; box-shadow: 0 20px 25px -5px rgba(0,0,0,0.1), 0 10px 10px -5px rgba(0,0,0,0.04); max-height: 80vh; overflow-y: auto; animation: modalPop 0.2s ease-out; }
@keyframes modalPop { from { opacity: 0; transform: scale(0.95); } to { opacity: 1; transform: scale(1); } }

/* --- TOASTS --- */
#toast-container { position: fixed; top: 20px; right: 20px; z-index: 4000; display: flex; flex-direction: column; gap: 10px; pointer-events: none; }
.toast { pointer-events: auto; background: white; padding: 15px 20px; border-radius: 10px; box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1); display: flex; align-items: center; gap: 12px; min-width: 250px; animation: slideIn 0.3s ease-out; border-left: 4px solid #3b82f6; }
.toast.success { border-left-color: #22c55e; } .toast.error { border-left-color: #ef4444; }
.toast-content { font-size: 0.9rem; color: #1e293b; font-weight: 500; }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* --- LIST VIEW --- */
.list-container { max-width: 800px; margin: 40px auto; background: white; border-radius: 12px; box-shadow: 0 4px 10px rgba(0,0,0,0.05); overflow: hidden; pointer-events: auto; }
.list-row { display: flex; align-items: center; justify-content: space-between; padding: 15px 20px; border-bottom: 1px solid #f1f5f9; transition: 0.1s; cursor: pointer; }
.list-row:hover { background: #f8fafc; }
.desk-dot { width: 8px; height: 8px; border-radius: 50%; margin-right: 10px; display: inline-block; }
.desk-dot.green { background: #22c55e; } .desk-dot.red { background: #ef4444; } .desk-dot.grey { background: #94a3b8; }
.list-amenity { font-size: 0.7rem; background: #f1f5f9; color: #64748b; padding: 2px 6px; border-radius: 4px; margin-left: 5px; }

/* --- MAP UI --- */
/* --- MAP UI (single source of truth) --- */
#map-view {
  position: absolute;
  inset: 0;
  z-index: 10;
  background-color: #f1f5f9;
  pointer-events: none; /* default: nothing inside can be clicked unless enabled */
}

/* Canvas area fills the page */
#canvas-wrapper {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  background-image: radial-gradient(#cbd5e1 1.5px, transparent 1.5px);
  background-size: 24px 24px;
  pointer-events: auto; /* allow canvas clicks */
}

#canvas-wrapper canvas {
  pointer-events: auto;
}

/* Ensure Fabric.js container fills the screen */
.canvas-container {
  width: 100% !important;
  height: 100% !important;
  background-color: #f1f5f9;
}

/* Things that must remain clickable */
#map-view nav,
#desk-list-view,
#zoom-controls {
  pointer-events: auto;
}

#map-view nav { z-index: 100; }

/* Booking panel stays clickable */
#booking-panel {
  position: absolute;
  top: 80px;
  right: 20px;
  width: 320px;
  padding: 24px;
  z-index: 50;
  pointer-events: auto;
}

/* -------------------------
   ADMIN EDITOR PANELS
   ------------------------- */
#admin-ui:not(.hidden) ~ #booking-panel {
  right: 300px;
}

#admin-ui {
  position: fixed;
  inset: 0;
  z-index: 60;
  pointer-events: none; /* don't block the canvas */
}
#admin-ui * {
  pointer-events: auto;
}

/* Left tools panel */
#admin-controls {
  position: fixed;
  top: 70px;
  left: 20px;
  width: 220px;
  max-height: calc(100vh - 110px);
  overflow: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 80;
}

/* Right plan overlay panel */
#plan-panel {
  position: fixed;
  top: 70px;
  right: 20px;
  width: 260px;
  max-height: calc(100vh - 110px);
  overflow: auto;
  padding: 14px;
  z-index: 80;
}

/* Slightly denser buttons inside editor */
#admin-controls .tool-btn {
  padding: 10px;
  font-size: 0.85rem;
}

/* Mobile tweaks */
@media (max-width: 768px) {
  #admin-controls {
    top: auto;
    bottom: 20px;
    left: 20px;
    right: 20px;
    width: auto;
    max-height: 40vh;
  }
  #plan-panel {
    top: 70px;
    left: 20px;
    right: 20px;
    width: auto;
    max-height: 45vh;
  }
}

/* =====================================================
   MOBILE: DASHBOARD + MAP BOOKING (USABLE ON PHONES)
   ===================================================== */

@media (max-width: 768px) {
  /* Allow the app to scroll on mobile */
  body { overflow-y: auto; }

  /* --- DASHBOARD LAYOUT --- */
  #dashboard-container, #system-dashboard {
    flex-direction: column;
    height: auto;
  }

  .dash-sidebar {
    width: 100%;
    height: auto;
    flex-direction: row;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-right: none;
    border-bottom: 1px solid #e2e8f0;
    position: sticky;
    top: 0;
    z-index: 200;
    overflow-x: auto;
    overflow-y: hidden;
    background: white;
  }

  .dash-logo {
    margin-bottom: 0;
    font-size: 1rem;
    flex-shrink: 0;
  }

  /* Hide the "Logged in as" block on small screens */
  #user-role-display { display: none !important; }

  .dash-nav-item {
    white-space: nowrap;
    padding: 10px 12px;
  }

  .dash-content {
    padding: 16px;
    height: auto;
    overflow: visible;
  }

  .dash-layout {
    flex-direction: column;
    gap: 16px;
  }

  .dash-sidebar-right {
    width: 100%;
    position: static;
  }

  .widget-card {
    max-height: none;
  }

  /* --- MAP: BOOKING PANEL AS BOTTOM SHEET --- */
  #map-view nav { position: fixed !important; top: 0; left: 0; }

  #booking-panel {
    position: fixed !important;
    left: 12px !important;
    right: 12px !important;
    top: auto !important;
    bottom: 12px !important;
    width: auto !important;
    max-height: 48vh;
    overflow: auto;
    padding: 16px !important;
    border-radius: 18px;
    box-shadow: 0 -10px 30px rgba(0,0,0,0.15);
  }

  /* Keep zoom controls reachable above the bottom sheet */
  #zoom-controls {
    bottom: calc(12px + 48vh);
    right: 12px;
  }

  /* List view should take the screen; hide booking UI while browsing the list */
  #desk-list-view {
    position: fixed !important;
    top: 64px !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    height: auto !important;
    padding: 0 !important;
    z-index: 120;
    background: #f8fafc;
  }

  #desk-list-view:not(.hidden) ~ #user-ui { display: none; }
  #desk-list-view:not(.hidden) ~ #zoom-controls { display: none; }
}
/* --- Power editor: properties panel --- */
#props-panel {
  position: fixed;
  right: 20px;
  top: 420px;
  width: 260px;
  max-height: calc(100vh - 440px);
  overflow: auto;
  padding: 14px;
  z-index: 80;
}

@media (max-width: 768px) {
  #props-panel {
    left: 20px;
    right: 20px;
    top: auto;
    bottom: 20px;
    width: auto;
    max-height: 40vh;
  }
}
