/* Responsive stylesheet for ELESKA Mail */

@media (max-width: 992px) {
  :root {
    --sidebar-width: 220px;
  }
}

@media (max-width: 768px) {
  :root {
    --sidebar-width: 0px;
    /* Hide sidebar off-screen by default */
  }

  /* Hamburger toggle navigation menu */
  .sidebar {
    position: absolute;
    top: 0;
    left: -300px;
    width: 300px;
    height: 100%;
    z-index: 1000;
    transition: left var(--transition-normal);
    box-shadow: 4px 0 20px rgba(0, 0, 0, 0.1);
  }

  .sidebar.mobile-open {
    left: 0;
  }

  /* Overlay behind sidebar on mobile */
  .sidebar-backdrop {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(0, 0, 0, 0.4);
    z-index: 999;
  }

  .sidebar-backdrop.active {
    display: block;
  }

  /* Top Header adjust */
  .top-header {
    height: var(--header-height) !important;
    padding: 0 1rem;
    gap: 0.5rem;
  }

  .hamburger-btn {
    display: flex !important;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: var(--text-muted);
    width: 38px;
    height: 38px;
    border-radius: 50%;
    cursor: pointer;
  }

  .hamburger-btn:hover {
    background-color: var(--hover-bg);
    color: var(--text-main);
  }

  /* Search Container take full space */
  .search-container {
    margin-right: 0.5rem;
    margin-top: 2px;
    margin-bottom: 2px;
  }

  #theme-toggle-btn,
  #header-settings-btn,
  .header-actions-right .btn-icon-header:not(#notification-dropdown-trigger) {
    display: none !important;
  }

  .mail-avatar-wrap {
    width: 30px;
    height: 30px;
  }

  /* Mail list cell adjustments */
  .mail-cell-star {
    display: none !important;
  }

  .mail-badges {
    display: none !important;
  }

  .mail-row {
    display: grid !important;
    grid-template-columns: auto 1fr auto;
    grid-template-rows: auto auto;
    grid-template-areas: 
      "avatar sender date"
      "avatar summary summary";
    height: auto !important;
    min-height: 80px !important;
    padding: 0.65rem 1rem !important;
    align-items: center !important;
    row-gap: 3px !important;
  }

  .mail-avatar-wrap {
    grid-area: avatar;
    margin-right: 0.75rem !important;
    margin-left: 0 !important;
    align-self: center !important;
  }

  .mail-sender {
    grid-area: sender;
    width: auto !important;
    min-width: 0 !important;
    max-width: none !important;
    margin-left: 0 !important;
    font-size: 0.92rem !important;
    font-weight: 600 !important;
    line-height: 1.2 !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
  }

  .mail-date {
    grid-area: date;
    width: auto !important;
    min-width: 0 !important;
    text-align: right !important;
    font-size: 0.78rem !important;
    color: var(--text-muted) !important;
    align-self: center !important;
  }

  .mail-content-summary {
    grid-area: summary;
    display: flex !important;
    flex-direction: column !important;
    align-items: flex-start !important;
    min-width: 0 !important;
    padding-right: 0 !important;
    gap: 1px !important;
  }

  .mail-subject {
    font-size: 0.85rem !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    display: block !important;
    max-width: 100% !important;
    color: var(--text-main) !important;
  }

  .mail-snippet {
    display: block !important;
    font-size: 0.82rem !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    max-width: 100% !important;
    color: var(--text-muted) !important;
  }

  .snippet-sep {
    display: none !important;
  }

  /* Floating Compose Modal */
  .compose-modal {
    right: 0;
    bottom: 0;
    width: 100% !important;
    height: 100% !important;
    border-radius: 0;
    max-width: 100vw;
    max-height: 100vh;
    top: 0 !important;
    left: 0 !important;
  }

  /* Detailed email page padding */
  .detail-content-scroll {
    padding: 1.25rem 1rem;
  }

  .detail-subject {
    font-size: 1.2rem;
  }

  .meta-recipients {
    display: none;
  }

  .detail-meta-row {
    margin-bottom: 1.25rem;
  }

  .mail-selection-bar {
    padding: 0.5rem 1rem !important;
    height: 48px !important;
    border-bottom: 1px solid var(--border-color) !important;
    background-color: var(--bg-surface) !important;
  }

  /* Keep toolbar at top on mobile */
  .mail-viewport {
    flex-direction: column;
  }

  #mail-list-viewport-container {
    order: 2;
    flex-grow: 1;
  }

  .mail-viewport .mail-list-container {
    order: 2 !important;
  }

  .mail-toolbar {
    order: 1;
    border-bottom: 1px solid var(--border-color) !important;
    border-top: none !important;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.03);
    height: auto !important;
    padding-top: 0.65rem !important;
    padding-bottom: 0.65rem !important;
    padding-left: 1rem !important;
    padding-right: 1rem !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    flex-wrap: nowrap !important;
    justify-content: flex-start !important;
    gap: 0.75rem !important;
    -webkit-overflow-scrolling: touch;
  }

  .mail-toolbar::-webkit-scrollbar {
    display: none !important;
    width: 0 !important;
    height: 0 !important;
  }

  .mail-toolbar .btn-toolbar,
  .detail-header .btn-toolbar {
    width: 44px !important;
    height: 44px !important;
    border-radius: 12px !important;
    background-color: var(--hover-bg) !important;
    color: var(--text-main) !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    flex-shrink: 0 !important;
  }

  .mail-toolbar .btn-toolbar svg,
  .detail-header .btn-toolbar svg {
    width: 20px !important;
    height: 20px !important;
  }

  .mail-toolbar .btn-toolbar-action {
    display: none !important;
  }

  .mail-toolbar .btn-toolbar-action.toolbar-action-visible {
    display: flex !important;
  }

  #btn-toolbar-refresh {
    display: none !important;
  }

  #btn-compose-minimize,
  #btn-compose-maximize {
    display: none !important;
  }


  .email-detail-page {
    flex-direction: column;
  }

  .detail-header {
    order: 1;
    height: auto !important;
    min-height: 56px;
    padding: 0.5rem 0.75rem !important;
    border-bottom: 1px solid var(--border-color) !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    flex-shrink: 0 !important;
  }

  .detail-header-scroll-area {
    gap: 0.35rem !important;
  }

  .detail-header .btn-toolbar {
    width: 40px !important;
    height: 40px !important;
    flex-shrink: 0 !important;
  }

  .detail-content-scroll {
    order: 2;
    flex-grow: 1;
  }

  .toolbar-group-left {
    flex-shrink: 0 !important;
    gap: 0.5rem !important;
  }

  /* Override base gray background to match clean white surface on mobile */
  body,
  .eleska-app,
  .main-content,
  .mail-viewport,
  .mail-list-viewport-container {
    background-color: var(--bg-surface) !important;
  }

  .mail-row {
    background-color: var(--bg-surface) !important;
  }

  .mail-row.unread {
    background-color: #f2f6fc !important;
  }

  html[data-theme="dark"] .mail-row.unread {
    background-color: #1e293b !important;
  }



  /* Premium iOS-Style Bottom Sheet Drawer */
  .mobile-bottom-sheet {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100dvh;
    z-index: 2500;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
  }

  .sheet-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.4);
    opacity: 0;
    transition: opacity 0.3s ease;
  }

  .sheet-content {
    position: relative;
    background-color: var(--bg-surface);
    border-radius: 24px 24px 0 0;
    padding: 1.5rem;
    width: 100%;
    max-height: 70%;
    overflow-y: auto;
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.15);
    z-index: 2;
  }

  .mobile-bottom-sheet.active .sheet-backdrop {
    opacity: 1;
  }

  .mobile-bottom-sheet.active .sheet-content {
    transform: translateY(0);
  }

  .sheet-drag-handle {
    width: 40px;
    height: 5px;
    background-color: var(--border-color);
    border-radius: 3px;
    margin: 0 auto 1.25rem auto;
  }

  .sheet-title {
    font-size: 1.1rem;
    font-weight: 700;
    margin-bottom: 1.25rem;
    text-align: center;
    color: var(--text-main);
  }

  .sheet-body-list {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
  }

  .sheet-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-main);
    border-radius: 12px;
    cursor: pointer;
    transition: background-color var(--transition-fast);
  }

  .sheet-item:hover {
    background-color: var(--hover-bg);
  }

  .sheet-item svg,
  .sheet-item i {
    color: var(--primary-color) !important;
  }

  /* Disable bootstrap dropdowns on mobile to avoid duplicate showing with bottom-sheet */
  .mail-toolbar .dropdown-menu {
    display: none !important;
  }

  #notification-dropdown-menu {
    width: 300px !important;
    max-width: 90vw !important;
  }

  /* Mobile Tab Bar Styles (iOS-Like) */
  .mobile-tab-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 64px;
    background-color: var(--bg-surface);
    border-top: 1px solid var(--border-color);
    box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.05);
    display: flex;
    justify-content: space-around;
    align-items: center;
    z-index: 998;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    height: calc(64px + env(safe-area-inset-bottom, 0px));
  }

  .mobile-tab-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    text-decoration: none !important;
    font-size: 0.65rem;
    font-weight: 600;
    gap: 4px;
    flex: 1;
    height: 100%;
    transition: color 0.15s ease, transform 0.1s ease;
  }

  .mobile-tab-item i,
  .mobile-tab-item svg {
    width: 20px;
    height: 20px;
    transition: transform 0.15s ease;
  }

  .mobile-tab-item.active {
    color: var(--primary-color) !important;
  }

  .mobile-tab-item.active i,
  .mobile-tab-item.active svg {
    transform: scale(1.1);
  }

  .mobile-tab-item:active {
    transform: scale(0.95);
  }

  /* Padding offset so scroll content does not get hidden behind bottom tabbar */
  #mail-list-viewport-container,
  .contacts-view-viewport {
    padding-bottom: calc(72px + env(safe-area-inset-bottom, 0px)) !important;
  }
  .detail-content-scroll {
    padding-bottom: calc(72px + env(safe-area-inset-bottom, 0px) + 60px) !important;
  }

  .detail-float-actions {
    bottom: calc(72px + env(safe-area-inset-bottom, 0px) + 1.25rem) !important;
  }
}



/* Extra small screens */
@media (max-width: 480px) {
  .mail-sender {
    width: 80px;
    min-width: 80px;
    max-width: 80px;
  }

  .top-header {
    height: 60px;
  }

  .search-input-wrapper {
    padding: 0.2rem 0.75rem;
  }

  .mail-date {
    font-size: 0.75rem;
    width: 60px;
    min-width: 60px;
  }
}