/* Enhanced Mobile Responsiveness Styles */

/* General responsive styles for all screen sizes */
@media screen and (max-width: 1200px) {
  /* Improve table responsiveness across all tabs */
  .forms-table {
    overflow-x: auto;
    display: block;
    width: 100%;
  }
  
  /* Fix for client documents tab search filter */
  #client-repository .tab-content .search-filter {
    position: sticky;
    left: 0;
    z-index: 10;
    background-color: #fff;
    width: 100%;
  }
  
  /* Ensure filter dropdown stays with search filter */
  #client-repository .filter-dropdown-container {
    position: sticky;
    left: 0;
    z-index: 9;
    background-color: #fff;
    margin-bottom: 15px;
  }
  
  /* Ensure buttons have proper spacing */
  .btn.btn-primary {
    margin-bottom: 10px;
  }
}

/* Tablet and small desktop responsive styles */
@media screen and (max-width: 992px) {
  /* Top navigation tabs */
  .mui-tabs-wrapper {
    flex-direction: column;
  }
  
  .mui-tabs-container {
    width: 100%;
    overflow-x: auto;
    white-space: nowrap;
    padding: 10px 0;
  }
  
  .mui-tab {
    padding: 8px 15px;
    font-size: 14px;
  }
  
  /* Tables responsiveness */
  table {
    min-width: 600px;
  }
  
  /* Requested files section */
  #client-requested-files .search-filter {
    flex: 1 1 100%;
    margin-bottom: 10px;
  }
  
  #client-requested-files .btn.btn-primary {
    width: 100%;
    margin-left: 0 !important;
  }
  
  /* Todo Lists tab responsiveness */
  #todo-lists .search-filter,
  #client-todo-lists .search-filter {
    flex: 1 1 100%;
    margin-bottom: 10px;
  }
  
  /* Cases tab responsiveness */
  #cases .search-filter {
    flex: 1 1 100%;
    margin-bottom: 10px;
  }
  
  /* Invoices tab responsiveness */
  #invoices .search-filter,
  #client-invoices .search-filter {
    flex: 1 1 100%;
    margin-bottom: 10px;
  }
  
  /* Forms tab responsiveness */
  #client-forms .search-filter {
    flex: 1 1 100%;
    margin-bottom: 10px;
  }
}

/* Chat responsive styles for mobile */
@media screen and (max-width: 768px) {
  .chat-container {
    flex-direction: column;
    position: relative;
    height: 100%;
  }
  
  /* Client list takes full width initially */
  .client-list {
    width: 100% !important;
    margin-bottom: 0;
    border-right: none !important;
    display: block;
  }
  
  /* Chat window initially hidden on mobile */
  .chat-window {
    width: 100%;
    display: none;
    padding: 10px !important;
    height: calc(100% - 50px);
  }
  
  /* Show chat window when active */
  .chat-window.mobile-active {
    display: block;
  }
  
  /* Hide client list when chat is active */
  .client-list.mobile-hidden {
    display: none;
  }
  
  /* Back button for mobile chat */
  .mobile-chat-back-button {
    display: none;
    align-items: center;
    background-color: #f5f5f5;
    padding: 10px;
    margin-bottom: 10px;
    border-radius: 4px;
    cursor: pointer;
    font-weight: bold;
  }
  
  .mobile-chat-back-button svg {
    margin-right: 8px;
    width: 20px;
    height: 20px;
  }
  
  /* Show back button when chat is active */
  .mobile-chat-back-button.mobile-active {
    display: flex;
  }
  
  /* Reduce padding in chat messages */
  .chat-messages {
    padding: 10px !important;
  }
  
  .message {
    margin-bottom: 10px !important;
  }
  
  .message-content {
    padding: 10px !important;
    max-width: 85% !important;
  }
}

/* Keep admin horizontal bar visible when client dashboard is active */
body.client-dashboard-active .mui-tabs-wrapper {
  display: flex !important;
  flex-direction: row !important;
  justify-content: space-between !important;
  z-index: 1001 !important; /* Ensure it's above other elements */
}

/* Position client detail section directly below admin bar */
#client-detail-section {
  margin-top: 0 !important; /* Remove space between navbar and client dashboard */
  position: relative !important;
  z-index: 10 !important;
  height: auto !important;
  overflow: visible !important;
}

/* Mobile specific enhancements */
@media screen and (max-width: 768px) {
  /* Reorganize tabs, logo and logout buttons for better mobile view */
  .mui-tabs-wrapper {
    display: flex !important;
    flex-direction: row !important;
    justify-content: center !important;
    align-items: center !important;
    padding: 5px 0 !important;
    width: 100% !important;
    overflow: hidden !important;
    background-color: white !important;
  }
  
  /* Hide the logo and logout buttons from their original positions */
  .menu-item[data-section="logout"] {
    display: none !important;
  }
  
  /* Make the tabs container take full width */
  .mui-tabs-container {
    width: 100% !important;
    overflow-x: auto !important;
    white-space: nowrap !important;
    -webkit-overflow-scrolling: touch !important;
    scrollbar-width: none !important; /* Firefox */
    -ms-overflow-style: none !important; /* IE and Edge */
    padding: 0 !important;
    display: flex !important;
    flex-wrap: nowrap !important;
    align-items: center !important; /* Ensure vertical centering of all items */
  }
  
  /* Add the logo and logout buttons to the tabs container */
  .mui-tabs-container::before {
    content: "" !important;
    display: inline-block !important;
    width: 120px !important;
    height: 28px !important;
    background-image: url('../images/logo.png') !important;
    background-size: contain !important;
    background-repeat: no-repeat !important;
    background-position: center !important;
    flex-shrink: 0 !important;
    margin-right: 10px !important;
    margin-left: 10px !important;
    align-self: center !important;
    vertical-align: middle !important;
  }
  
  .mui-tabs-container::after {
    content: "" !important;
    display: inline-block !important;
    width: 28px !important;
    height: 28px !important;
    background-image: url('../images/icons/log_out.svg') !important;
    background-size: contain !important;
    background-repeat: no-repeat !important;
    background-position: center !important;
    flex-shrink: 0 !important;
    margin-left: 10px !important;
    margin-right: 10px !important;
    align-self: center !important;
    vertical-align: middle !important;
  }
  
  .mui-tabs-container::-webkit-scrollbar {
    display: none; /* Chrome, Safari, Opera */
  }
  
  .mui-tab {
    display: inline-block !important;
    padding: 10px 15px !important;
    font-size: 14px !important;
    flex: 1 !important;
    text-align: center !important;
    white-space: nowrap !important;
    min-width: auto !important;
  }
  
  /* Ensure all tabs have consistent padding */
  .mui-tab[data-admin-section="clients"],
  .mui-tab[data-admin-section="calendar"],
  .mui-tab[data-admin-section="messages"],
  .mui-tab[data-admin-section="todo-lists"],
  .mui-tab[data-admin-section="invoices"],
  .mui-tab[data-admin-section="cases"] {
    padding: 10px 15px !important;
    margin: 0 !important;
  }
  
  /* Fix calendar navigation and filter layout */
  #calendar > div:nth-child(2) > div,
  #client-calendar > div:nth-child(2) > div {
    flex-direction: column;
    align-items: flex-start;
  }
  
  /* Fix event filter button */
  #calendar .custom-select-wrapper[style*="margin-left"],
  #client-calendar .custom-select-wrapper[style*="margin-left"] {
    margin-left: 0 !important;
    margin-top: 15px;
    width: 100%;
  }
  
  /* Improve overall layout on mobile */
  .main-card {
    padding: 15px;
  }
  
  /* Adjust search and filter elements */
  .search-filter {
    width: 100%;
  }
  
  .search-filter input {
    width: 100%;
  }
  
  /* Adjust buttons on mobile */
  .main-card > div:first-child .btn.btn-primary {
    min-width: auto !important;
    padding: 8px 12px;
    font-size: 14px;
    width: auto;
  }
  
  /* Make other buttons full width on mobile */
  .tab-content .btn.btn-primary,
  .forms-actions .btn.btn-primary,
  .filter-dropdown-container .btn.btn-primary {
    width: 100%;
    margin-left: 0 !important;
    margin-right: 0 !important;
  }
  
  /* Client dashboard responsive styles */
  .client-container {
    flex-direction: column;
    position: relative;
  }
  
  /* Client mobile header */
  .client-mobile-header {
    display: flex !important;
    height: auto !important;
    justify-content: space-between !important;
    align-items: center !important;
    color: white !important;
    padding: 10px 15px !important;
    border-radius: 8px 8px 0 0 !important;
    margin-bottom: 0 !important; /* No margin so sidebar connects directly */
    width: 100% !important;
    box-sizing: border-box !important;
    position: relative !important; /* Changed to relative for proper scrolling */
    z-index: 100 !important;
    background-color: #1a3a5f !important;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1) !important;
    color: white !important;
    min-height: 50px !important; /* Minimum height for consistent spacing */
  }
  
  /* Add padding to the top of the client container to allow proper flow with sidebar */
  .client-container {
    padding-top: 0px !important; /* Space for admin bar */
    width: 100% !important;
    margin: 0 auto !important;
    position: relative !important;
    z-index: 10 !important;
    display: flex !important;
    flex-direction: column !important; /* Stack elements vertically */
    overflow-x: hidden !important; /* Prevent horizontal scrolling */
    overflow-y: visible !important; /* Allow vertical scrolling */
    height: auto !important; /* Allow container to expand */
  }
  
  /* Ensure client content flows properly below the sidebar and is scrollable */
  .client-content {
    position: relative !important;
    z-index: 10 !important;
    width: 100% !important;
    padding-top: 0 !important;
    box-sizing: border-box !important;
    padding-bottom: 20px !important; /* Add padding at bottom for better scrolling */
    overflow-y: visible !important; /* Allow vertical scrolling */
    height: auto !important; /* Allow content to expand */
    min-height: 500px !important; /* Ensure there's enough content to scroll */
  }
  
  /* Mobile menu overlay */
  .mobile-menu-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 98; /* Lower than sidebar but higher than other content */
  }
  
  .mobile-menu-overlay.active {
    display: block;
  }
  
  /* Allow body scrolling even when menu is open */
  body.menu-open {
    overflow-y: auto !important;
    height: auto !important;
  }
  
  .client-mobile-header .mobile-client-name {
    display: flex;
    align-items: center;
    padding-left: 5px;
  }
  
  .client-mobile-header .mobile-client-name span {
    color: white;
    font-size: 18px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 250px;
  }
  
  /* Mobile menu button for client sidebar */
  .mobile-menu-toggle-client {
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    z-index: 100;
    background-color: transparent;
    color: white;
    border: none;
    cursor: pointer;
    padding: 10px !important;
  }
  
  .mobile-menu-toggle-client svg {
    width: 24px;
    height: 24px;
    stroke-width: 2px;
  }
  
  /* Sidebar styles for mobile - part of normal document flow */
  .client-sidebar {
    display: none; /* Hidden by default on mobile */
    width: 100% !important;
    min-height: auto;
    position: static !important; /* Static position to be part of normal flow */
    margin: 0 !important;
    box-sizing: border-box !important;
    background-color: #1a3a5f;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding: 0 !important;
    margin-bottom: 0 !important;
    max-height: none !important; /* Remove height restriction */
    border-radius: 0px !important;
  }
  
  /* Make sidebar visible when active */
  .client-sidebar.mobile-active {
    display: block !important;
    pointer-events: auto !important;
  }
  
  /* Ensure sidebar items are clickable */
  .client-sidebar-item {
    pointer-events: auto !important;
    cursor: pointer !important;
    touch-action: auto !important;
    position: relative;
    z-index: 10000 !important;
  }
  
  /* Enhance sidebar items for mobile */
  .client-sidebar .client-sidebar-item {
    padding: 15px 20px !important; /* Larger touch targets */
    border-bottom: 1px solid rgba(255, 255, 255, 0.1) !important;
    margin: 0 !important;
  }
  
  .client-sidebar .client-sidebar-item:last-child {
    border-bottom: none !important;
  }
  
  .client-sidebar-item:hover {
    background-color: rgba(255, 255, 255, 0.1);
  }
  
  /* Hide client name in sidebar on mobile */
  @media (max-width: 768px) {
    .client-sidebar .client-name-item {
      display: none !important;
    }
  }
  
  /* Adjust content to take full width */
  .client-content {
    width: 100%;
    border-radius: 8px;
    padding-top: 10px; /* Space for the menu button */
  }
  
  /* Client repository tabs */
  #client-repository .tabs {
    flex-wrap: wrap;
  }
  
  #client-repository .tab {
    flex: 1 1 auto;
    min-width: 120px;
    text-align: center;
    padding: 10px 5px;
  }
  
  /* Fix document list overflow */
  #client-repository .files-table {
    width: 100%;
    overflow-x: auto;
    display: block;
    max-width: 100%;
    border: none;
  }
  
  /* Make the table container scrollable */
  #client-view-files {
    overflow-x: auto;
    max-width: 100%;
    padding: 0;
  }
  
  /* Ensure table content stays within container */
  #client-repository table {
    width: 100%;
    table-layout: fixed;
    border-collapse: collapse;
  }
  
  /* Ensure the table cells don't break out of container */
  #client-repository table th,
  #client-repository table td {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  
  /* Fix calendar button alignment */
  #client-calendar .calendar-navigation,
  #calendar .calendar-navigation,
  #client-calendar .month-navigation {
    flex-direction: row;
    align-items: center;
    width: 100%;
    justify-content: space-between;
  }
  
  #client-calendar .calendar-selectors,
  #calendar .calendar-selectors,
  #client-calendar .month-year-selectors {
    display: flex;
    flex: 1;
    margin: 0 5px;
    justify-content: center;
    align-items: center;
  }
  
  #client-calendar .nav-btn,
  #calendar .nav-btn {
    width: 36px;
    height: 36px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  
  #client-calendar .custom-select-wrapper,
  #calendar .custom-select-wrapper {
    margin: 0 5px;
    flex: 1;
    max-width: 120px;
  }
  
  /* Remove client calendar specific styles that are no longer needed */
  /* Client calendar now uses the same structure as root calendar */
  
  /* Forms section responsive */
  .forms-header {
    flex-direction: column;
    align-items: flex-start;
  }
  
  .forms-header .search-filter {
    width: 100%;
    margin-bottom: 10px;
  }
  
  .forms-actions {
    width: 100%;
    flex-direction: column;
  }
  
  .forms-actions button {
    width: 100%;
    margin-top: 10px;
  }
  
  /* Calendar responsive improvements */
  .calendar-navigation {
    flex-direction: row;
    align-items: center;
    width: 100%;
    justify-content: space-between;
    margin-bottom: 15px;
  }
  
  .calendar-selectors {
    margin: 0 10px;
    display: flex;
    flex: 1;
  }
  
  .calendar-selectors .custom-select-wrapper {
    flex: 1;
    margin: 0 5px;
  }
  
  .nav-btn {
    width: 36px;
    height: 36px;
    font-size: 16px;
  }
  
  .events-container {
    min-width: auto;
    width: 100%;
    margin-top: 20px;
  }
  
  /* Fix calendar days grid */
  .calendar-container {
    flex-direction: column;
    gap: 10px;
  }
  
  .calendar-grid {
    width: 100%;
    min-width: 0 !important; /* Override the desktop min-width */
    overflow-x: hidden;
  }
  
  .calendar-days {
    min-width: 100%;
    grid-template-columns: repeat(7, 1fr);
    grid-auto-rows: minmax(60px, auto); /* Smaller height on mobile */
  }
  
  .calendar-day {
    min-height: 60px;
    padding: 5px;
    font-size: 13px;
  }
}

/* Small mobile devices */
@media screen and (max-width: 480px) {
  /* Adjust spacing for all cards */
  .card-title {
    font-size: 18px;
    margin-bottom: 15px;
  }
  
  /* Improve table display on very small screens */
  table th, table td {
    padding: 8px 5px;
    font-size: 13px;
  }
  
  /* Adjust filter buttons */
  .filter-toggle-btn {
    padding: 8px;
  }
  
  /* Client list in messages tab */
  .client-list {
    width: 100% !important;
    height: auto !important;
    max-height: 300px;
    overflow-y: auto;
    border-right: none !important;
    border-bottom: 1px solid #eee;
  }
  
  /* Chat window adjustments */
  .chat-window {
    width: 100%;
    height: calc(80vh - 300px);
  }
  
  /* Chat input adjustments */
  .chat-input {
    display: flex;
    align-items: center;
    padding: 8px;
  }
  
  .chat-input textarea {
    height: 36px;
    padding: 8px;
    font-size: 14px;
    min-height: 36px;
  }
  
  .chat-input button {
    height: 36px;
    padding: 0 12px;
    font-size: 14px;
    min-width: 60px;
  }
  
  /* Todo list responsive */
  .todo-item {
    flex-direction: column;
    align-items: flex-start;
  }
  
  .todo-actions {
    margin-top: 10px;
    width: 100%;
    justify-content: flex-end;
  }
  
  /* Invoices responsive */
  .invoice-item {
    flex-direction: column;
  }
  
  .invoice-details {
    width: 100%;
  }
  
  .invoice-actions {
    width: 100%;
    justify-content: flex-end;
    margin-top: 10px;
  }
  
  /* Custom select responsiveness */
  .custom-select-wrapper {
    width: 100%;
    margin-bottom: 10px;
  }
  
  /* Requested files section */
  .btn.btn-primary {
    margin-bottom: 10px;
  }
  
  /* Improve responsive layout for all tabs */
  .tab-content {
    padding: 10px;
  }
  
  /* Calendar day improvements for small screens */
  .calendar-day {
    padding: 2px;
    min-height: 50px;
  }
  
  .calendar-day .day-events {
    font-size: 10px;
  }
  
  /* Adjust status badges for better mobile display */
  .status-badge {
    padding: 3px 6px;
    font-size: 11px;
  }
  
  /* Improve forms display on mobile */
  .form-group {
    margin-bottom: 15px;
  }
  
  .form-group label {
    margin-bottom: 5px;
    display: block;
  }
  
  /* Fix file upload section */
  .upload-preview-item {
    flex-direction: column;
    align-items: flex-start;
  }
  
  .upload-preview-item .remove-file {
    margin-top: 5px;
  }
  
  /* Adjust client sidebar items */
  .client-sidebar-item {
    padding: 10px 15px;
  }
  
  /* Fix case status display */
  .case-status-item {
    padding: 10px;
  }
  
  .case-status-date {
    font-size: 12px;
  }
}
