/* ===== MOBILE CALENDAR CSS - TABLET AND PHONE ONLY ===== */
/* IMPORTANT: This file only affects screens 1024px and below */
/* Desktop (1025px+) uses original stylesheet.css layout untouched */

/* ===== DESKTOP APPOINTMENT ENHANCEMENT ===== */
@media (min-width: 1025px) {
  /* Enhance desktop appointments to show full info */
  .appointment {
    padding: 8px 10px !important;
    font-size: 12px !important;
    min-height: 20px !important;
  }
  
  .appointment div {
    font-size: 12px !important;
  }
}

/* ===== MOBILE VIEWPORT FIXES ===== */
@media (max-width: 1024px) {
  /* Uniform 7-day calendar grid on mobile/tablet */
  #calendarmonth {
    display: grid !important;
    grid-template-columns: repeat(7, 1fr) !important;
    gap: 1px !important;
    width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    box-sizing: border-box !important;
  }

  * {
    box-sizing: border-box;
  }
  
  html, body {
    overflow-x: hidden !important;
    width: 100% !important;
    max-width: 100vw !important;
    margin: 0 !important;
    padding: 0 !important;
  }
  
  #websitecontainer {
    width: 100% !important;
    max-width: 100vw !important;
    overflow-x: hidden !important;
    margin: 0 !important;
    padding: 0 !important;
  }
  
  /* Ensure all calendar elements stay within viewport */
  #mainconentcalendar,
  .modern-calendar-header,
  .modern-calendar-container,
  #calendarmonth {
    width: 100% !important;
    max-width: 100% !important;
    overflow-x: hidden !important;
    box-sizing: border-box !important;
  }
}

/* ===== TABLET (769px - 1024px) ===== */
@media (min-width: 769px) and (max-width: 1024px) {
  
  /* Navbar adjustments for tablet */
  #navbar {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    height: 80px !important;
    padding: 0 20px !important;
    z-index: 1000 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    gap: 16px !important;
  }
  
  #ClientSearch {
    flex: 1 1 200px;
    max-width: 300px;
    margin: 0 12px;
  }
  
  #navbarbttns {
    flex: 0 0 auto;
    display: flex;
    gap: 8px;
    align-items: center;
  }
  
  /* Sidebar becomes horizontal on tablet */
  #websitecontainer > div:first-child {
    position: static;
    width: 100%;
    margin-top: 80px;
    display: flex;
    flex-direction: column;
  }
  
  #sidebar {
    position: static;
    width: 100%;
    height: 60px;
    padding: 0;
    top: auto;
    display: flex;
    flex-direction: row;
    justify-content: space-evenly;
    align-items: stretch;
    overflow-x: auto;
    overflow-y: visible;
  }
  
  #sidebar > div {
    flex: 1 1 0;
    min-width: 120px;
    display: flex;
    height: 100%;
  }
  
  #sidebar > div > a {
    width: 100%;
    height: 100%;
    display: flex;
  }
  
  #sidebar > div > a > button {
    width: 100%;
    height: 100%;
    padding: 8px 12px;
    font-size: 13px;
    white-space: nowrap;
    text-align: center;
    border-radius: 0;
    margin: 0;
    border: none;
    border-right: 1px solid rgba(255,255,255,0.2);
  }
  
  #sidebar > div:last-child > a > button {
    border-right: none;
  }
  
  /* Filter panel with dropdown on tablet */
  #sidebar + div {
    margin: 16px 20px;
    padding: 0;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    overflow: hidden;
    order: 2;
  }
  
  #sidebar + div::before {
    content: var(--arrow, "Filters ▼");
    display: block;
    padding: 16px;
    background: linear-gradient(135deg, #f8fafc, #e2e8f0);
    font-weight: 600;
    color: #374151;
    cursor: pointer;
    text-align: center;
    border-bottom: 1px solid #e5e7eb;
    user-select: none;
    transition: all 0.3s ease;
  }
  
  #sidebar + div:hover::before {
    background: linear-gradient(135deg, #e2e8f0, #cbd5e1);
  }
  
  #sidebar + div > * {
    display: none;
  }
  
  #sidebar + div.expanded > * {
    display: block;
    padding: 16px;
    background: #ffffff;
    border: none;
  }
  
  /* Year view - 3 columns for tablet */
  .generated-year-grid {
    display: grid !important;
    grid-template-columns: repeat(3, 1fr) !important;
    gap: 12px !important;
    padding: 16px !important;
  }
  
  /* Main content adjustments */
  #rightsidepagecontainer {
    position: static;
    left: 0;
    top: 0;
    margin-top: 0;
    padding: 16px !important;
    height: auto;
    overflow: visible;
    width: 100% !important;
    box-sizing: border-box !important;
  }
  
  /* Modern calendar header - tablet responsive */
  .modern-calendar-header {
    padding: 20px 16px !important;
    margin: 0 !important;
  }
  
  /* Calendar flows naturally on tablet */
  #mainconentcalendar {
    height: auto !important;
    overflow: visible !important;
  }
  
  .modern-calendar-container {
    height: auto !important;
    max-height: none !important;
    overflow: visible !important;
  }
  
  /* TABLET CALENDAR GRID RESPONSIVENESS */
  #calendarmonth {
    display: grid !important;
    grid-template-columns: repeat(7, 1fr) !important;
    gap: 1px !important;
    width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    box-sizing: border-box !important;
  }
  
  /* Tablet date cells - compact but readable */
  .date {
    min-height: 100px !important;
    max-height: none !important; /* Remove max-height to allow unlimited appointments */
    padding: 8px 6px !important;
    border: 1px solid #f1f5f9 !important;
    font-size: 13px !important;
    box-sizing: border-box !important;
    overflow: visible !important; /* Allow appointments to show */
    display: flex !important;
    flex-direction: column !important;
  }
  
  /* Tablet day headers - FIXED height */
  .day {
    padding: 10px 8px !important;
    font-size: 12px !important;
    min-height: 36px !important;
    max-height: 36px !important;
    height: 36px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
  }
  
  /* TABLET WEEK VIEW RESPONSIVENESS */
  .generated-week-grid {
    display: grid !important;
    grid-template-columns: 70px repeat(7, 1fr) !important;
    gap: 1px !important;
    padding: 16px 12px !important;
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
    overflow-x: hidden !important;
  }
}

/* ===== MOBILE PHONES (max-width: 768px) ===== */
@media (max-width: 768px) {
  
  /* Compact navbar for mobile */
  #navbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 70px;
    padding: 0 12px;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    flex-wrap: nowrap;
  }
  
  #navbarimg {
    flex: 0 0 auto;
  }
  
  #navbarimg img {
    height: 32px;
  }
  
  #ClientSearch {
    flex: 1 1 120px;
    min-width: 100px;
    max-width: 180px;
    margin: 0 4px;
  }
  
  #ClientSearch input {
    padding: 8px 12px;
    font-size: 16px;
    border-radius: 20px;
  }
  
  #navbarbttns {
    flex: 0 0 auto;
    display: flex;
    gap: 6px;
    align-items: center;
  }
  
  #create-dropdown-container > button {
    width: 36px;
    height: 36px;
    font-size: 16px;
  }
  
  .account-btn span {
    display: none;
  }
  
  .account-btn {
    padding: 6px 8px !important;
  }
  
  .account-btn .account-avatar {
    width: 28px !important;
    height: 28px !important;
  }
  
  /* Sidebar becomes horizontal on mobile */
  #websitecontainer {
    display: block;
  }
  
  #websitecontainer > div:first-child {
    position: static;
    width: 100%;
    margin-top: 70px;
    display: flex;
    flex-direction: column;
  }
  
  #sidebar {
    position: static;
    width: 100%;
    height: 50px;
    padding: 0;
    top: auto;
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: stretch;
    overflow-x: hidden;
    overflow-y: visible;
    background: linear-gradient(90deg, var(--primary-green) 0%, var(--primary-green-dark) 100%) !important;
    gap: 1px;
  }
  
  #sidebar > div {
    flex: 1 1 0;
    min-width: 0;
    display: flex;
    height: 100%;
  }
  
  #sidebar > div > a {
    width: 100%;
    height: 100%;
    display: flex;
  }
  
  #sidebar > div > a > button {
    width: 100%;
    height: 100%;
    font-size: 12px;
    padding: 4px 2px;
    white-space: normal;
    word-wrap: break-word;
    text-align: center;
    line-height: 1.1;
    border-radius: 0;
    margin: 0;
    border: none;
    background: transparent;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
  }
  
  #sidebar > div > a > button:hover {
    background: rgba(255,255,255,0.15);
    transform: none;
  }
  
  /* Filter panel with dropdown on mobile */
  #sidebar + div {
    margin: 12px;
    padding: 0;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    overflow: hidden;
    order: 2;
  }
  
  #sidebar + div::before {
    content: var(--arrow, "Filters ▼");
    display: block;
    padding: 16px;
    background: linear-gradient(135deg, #f8fafc, #e2e8f0);
    font-weight: 600;
    color: #374151;
    cursor: pointer;
    text-align: center;
    border-bottom: 1px solid #e5e7eb;
    user-select: none;
    transition: all 0.3s ease;
  }
  
  #sidebar + div:hover::before {
    background: linear-gradient(135deg, #e2e8f0, #cbd5e1);
  }
  
  #sidebar + div > * {
    display: none;
  }
  
  #sidebar + div.expanded > * {
    display: block !important;
    padding: 16px !important;
    background: #ffffff !important;
    border: none !important;
  }
  
  /* Year view - 2 columns for mobile */
  .generated-year-grid {
    display: grid !important;
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 8px !important;
    padding: 12px !important;
  }
  
  /* Main content mobile */
  #rightsidepagecontainer {
    position: static;
    left: 0;
    top: 0;
    margin-top: 0;
    padding: 8px !important;
    height: auto;
    overflow: visible;
    width: 100% !important;
    box-sizing: border-box !important;
  }
  
  /* Modern calendar header - mobile responsive */
  .modern-calendar-header {
    padding: 16px 8px !important;
    margin: 0 !important;
  }
  
  .modern-header-top {
    flex-direction: column !important;
    gap: 12px !important;
    align-items: stretch !important;
  }
  
  .modern-calendar-title {
    font-size: 20px !important;
    text-align: center !important;
  }
  
  .modern-header-controls {
    flex-direction: column !important;
    gap: 12px !important;
  }
  
  /* Calendar flows naturally on mobile */
  #mainconentcalendar {
    height: auto !important;
    overflow: visible !important;
  }
  
  .modern-calendar-container {
    height: auto !important;
    max-height: none !important;
    overflow: visible !important;
  }
  
  /* MOBILE CALENDAR GRID RESPONSIVENESS */
  #calendarmonth {
    display: grid !important;
    grid-template-columns: repeat(7, 1fr) !important;
    gap: 1px !important;
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    box-sizing: border-box !important;
    overflow: hidden !important;
  }
  
  /* Mobile calendar container - ensure no overflow */
  .modern-calendar-container {
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    box-sizing: border-box !important;
    overflow: hidden !important;
  }
  
  /* Mobile day headers - FIXED - more compact */
  .day {
    padding: 8px 2px !important;
    font-size: 10px !important;
    text-align: center !important;
    font-weight: 700 !important;
    color: #64748b !important;
    background: linear-gradient(135deg, #f8fafc, #e2e8f0) !important;
    border-bottom: 2px solid #e2e8f0 !important;
    text-transform: uppercase !important;
    letter-spacing: 0.3px !important;
    border: none !important;
    box-sizing: border-box !important;
    overflow: hidden !important;
    min-height: 32px !important;
    max-height: 32px !important;
    height: 32px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
  }
  
  /* Mobile date cells - FIXED - proper sizing and no cutoff */
  .date {
    min-height: 80px !important;
    max-height: none !important; /* Remove max-height to allow unlimited appointments */
    padding: 6px 4px !important;
    border: 1px solid #f1f5f9 !important;
    position: relative !important;
    cursor: pointer !important;
    transition: all 0.3s ease !important;
    background: white !important;
    text-align: left !important;
    font-size: 11px !important;
    box-sizing: border-box !important;
    overflow: visible !important; /* Allow appointments to show */
    width: 100% !important;
    display: flex !important;
    flex-direction: column !important;
  }
  
  /* Mobile date numbers - FIXED */
  .date-container {
    font-weight: 700 !important;
    font-size: 12px !important;
    color: #1e293b !important;
    margin-bottom: 4px !important;
    display: flex !important;
    justify-content: space-between !important;
    align-items: center !important;
    flex: 0 0 auto !important;
    min-height: 16px !important;
  }
  
  /* Mobile appointments - FIXED - better scaling and no name cutoff */
  .appointment {
    background: linear-gradient(135deg, #6366f1, #4f46e5) !important;
    color: white !important;
    padding: 6px 5px !important;
    border-radius: 4px !important;
    margin-bottom: 2px !important;
    font-size: 10px !important;
    font-weight: 600 !important;
    cursor: pointer !important;
    transition: all 0.3s ease !important;
    box-shadow: 0 1px 3px rgba(99, 102, 241, 0.3) !important;
    position: relative !important;
    overflow: visible !important;
    border: none !important;
    line-height: 1.1 !important;
    min-height: 20px !important;
    display: flex !important;
    flex-direction: row !important;
    align-items: center !important;
    gap: 4px !important;
    word-wrap: break-word !important;
  }
  
  /* Mobile appointment text - FIXED - no more cutoff */
  .appointment .appt-name-mobile {
    flex: 1 !important;
    font-size: 10px !important;
    color: white !important;
    line-height: 1.1 !important;
    overflow: visible !important;
    text-overflow: visible !important;
    white-space: normal !important;
    font-weight: 700 !important;
    word-wrap: break-word !important;
    min-width: 0 !important;
  }
  
  .appointment .appt-time-mobile {
    flex: 0 0 auto !important;
    font-size: 8px !important;
    color: white !important;
    opacity: 0.9 !important;
    margin-bottom: 0 !important;
    white-space: nowrap !important;
  }
  
  .appointment .appt-name-only {
    flex: 1 !important;
    font-size: 10px !important;
    color: white !important;
    line-height: 1.1 !important;
    overflow: visible !important;
    text-overflow: visible !important;
    white-space: normal !important;
    font-weight: 700 !important;
    word-wrap: break-word !important;
  }
  
  .appointment .appt-title {
    display: none !important; /* Hide titles on mobile */
  }
  
  /* Mobile appointment container - better stacking */
  .appointment-container {
    margin-top: 4px !important;
    display: flex !important;
    flex-direction: column !important;
    gap: 2px !important;
    overflow: visible !important;
    flex: 1 !important;
  }
  
  /* Mobile add button - smaller */
  .add-event-btn {
    position: absolute !important;
    top: 4px !important;
    right: 4px !important;
    width: 18px !important;
    height: 18px !important;
    border: none !important;
    background: #e2e8f0 !important;
    border-radius: 50% !important;
    color: #64748b !important;
    cursor: pointer !important;
    font-size: 12px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    opacity: 0 !important;
    transition: all 0.2s ease !important;
    z-index: 10 !important;
  }
}

/* ===== SMALL PHONES (max-width: 480px) ===== */
@media (max-width: 480px) {
  
  #navbar {
    height: 60px;
    padding: 0 8px;
  }
  
  #navbarimg img {
    height: 28px;
  }
  
  #ClientSearch {
    max-width: 140px;
  }
  
  #create-dropdown-container > button {
    width: 32px;
    height: 32px;
    font-size: 14px;
  }
  
  #websitecontainer > div:first-child {
    margin-top: 60px;
  }
  
  #sidebar {
    height: 45px;
  }
  
  #sidebar > div > a > button {
    font-size: 12px;
    padding: 3px 1px;
    line-height: 1.0;
  }
  
  /* Year view - 2 columns with tighter spacing */
  .generated-year-grid {
    display: grid !important;
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 6px !important;
    padding: 8px !important;
  }
}

/* ===== LANDSCAPE ORIENTATION FIXES ===== */
@media screen and (orientation: landscape) and (max-height: 500px) {
  #navbar {
    height: 50px;
  }
  
  #sidebar {
    height: 40px;
  }
  
  #websitecontainer > div:first-child {
    margin-top: 50px;
  }
}

/* ===== iOS SAFE AREA SUPPORT ===== */
@supports (padding: max(0px)) {
  @media (max-width: 1024px) {
    #navbar {
      padding-left: max(12px, env(safe-area-inset-left));
      padding-right: max(12px, env(safe-area-inset-right));
    }
    
    #rightsidepagecontainer {
      padding-left: max(12px, env(safe-area-inset-left));
      padding-right: max(12px, env(safe-area-inset-right));
    }
  }
}

/* ===== PREVENT iOS INPUT ZOOM ===== */
@media screen and (-webkit-min-device-pixel-ratio: 0) {
  input[type="text"],
  input[type="search"] {
    font-size: 16px !important;
  }
}

/* ===== SMOOTH SCROLLING FOR MOBILE/TABLET ONLY ===== */
@media (max-width: 1024px) {
  html {
    scroll-behavior: smooth;
    overscroll-behavior: auto;
  }
  
  body {
    overscroll-behavior: auto;
  }
  
  /* Prevent scroll trapping in filter containers */
  #sidebar + div {
    overscroll-behavior: contain;
  }
  
  /* Smooth scrolling for filter lists */
  #sidebar + div .client-list,
  #sidebar + div .employee-list,
  #sidebar + div div[style*="overflow-y"] {
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }
  
  /* Week view smooth scrolling */
  .generated-week-grid {
    overscroll-behavior: auto;
    -webkit-overflow-scrolling: touch;
  }
  
  /* MOBILE WEEK VIEW RESPONSIVENESS */
  .generated-week-grid {
    display: grid !important;
    grid-template-columns: 60px repeat(7, 1fr) !important;
    gap: 1px !important;
    padding: 8px 4px !important;
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
    overflow-x: hidden !important;
  }
  
  /* Mobile week view time labels */
  .generated-week-grid > div:nth-child(8n+1) {
    font-size: 10px !important;
    padding: 2px !important;
    text-align: right !important;
    width: 60px !important;
    box-sizing: border-box !important;
  }
  
  /* Mobile week view day headers */
  .generated-week-grid > div:nth-child(-n+8):not(:first-child) {
    font-size: 11px !important;
    padding: 6px 2px !important;
    text-align: center !important;
    font-weight: bold !important;
    box-sizing: border-box !important;
  }
  
  /* Mobile week view time cells */
  .generated-week-grid > div:nth-child(n+9) {
    min-height: 40px !important;
    padding: 1px !important;
    border: 1px solid #e2e8f0 !important;
    box-sizing: border-box !important;
    overflow: hidden !important;
  }
  
  /* Prevent scroll trapping in modals */
  .modal-content-area {
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }
}
/* ── ACCOUNT DROPDOWN OVERRIDES FOR MOBILE CALENDAR PAGE ── */

/* 1) Let the container overflow and stack above the calendar */
.account-dropdown-container {
  position: relative !important;
  overflow: visible !important;
  z-index: 2000 !important;
}

/* 2) Base state: hidden off-screen */
.account-dropdown-container .dropdown-menu {
  position: absolute !important;
  top: calc(100% + 4px) !important;   /* just below the button */
  right: 0 !important;
  display: none !important;
  overflow: visible !important;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1) !important;
}

/* 3) When JS *removes* the .hidden class, force it visible */
.account-dropdown-container .dropdown-menu:not(.hidden) {
  display: block !important;
}

/* ─────────── MOBILE APPOINTMENT FIT & WRAP FIX ─────────── */
@media (max-width: 768px) {
  .appointment {
    padding: 4px 4px !important;
    font-size: 8px !important;
    flex-wrap: wrap !important;
    align-items: flex-start !important;
  }
  .appointment .appt-name-mobile {
    flex: 1 1 auto !important;
    min-width: 0 !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
  }
  .appointment .appt-time-mobile {
    flex: 0 0 auto !important;
    margin-left: 4px !important;
    white-space: nowrap !important;
  }
}


/* ─────────── UNIFORM 7-COLUMN GRID ON MOBILE ─────────── */
@media (max-width: 1024px) {
  #calendarmonth {
    display: grid !important;
    grid-template-columns: repeat(7, 1fr) !important;
    width: 100% !important;
    gap: 1px !important;
  }
}


/* Override mobile navbar offset */
@media (max-width: 768px) {
  #rightsidepagecontainer {
    position: static !important;
    margin-top: 70px !important;
    padding:    16px !important;
    width:      100%  !important;
    box-sizing: border-box !important;
  }
}
