/* AI Conference Service - Mobile & Tablet Responsive Styles */
/* PWA Enhanced Version */

/* ========================================
   Mobile Sidebar (Hamburger Menu)
   ======================================== */
@media (max-width: 768px) {

    /* Hide sidebar by default on mobile */
    .sidebar {
        position: fixed !important;
        left: -100% !important;
        top: 0 !important;
        height: 100vh !important;
        width: 280px !important;
        z-index: 50 !important;
        transition: left 0.3s ease-in-out !important;
    }

    .sidebar.open {
        left: 0 !important;
    }

    /* Overlay when sidebar is open */
    .sidebar-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background-color: rgba(0, 0, 0, 0.5);
        z-index: 40;
    }

    .sidebar-overlay.open {
        display: block;
    }

    /* Header adjustments for mobile */
    header {
        padding-left: 0.75rem !important;
        padding-right: 0.75rem !important;
    }

    .mobile-header-title {
        font-size: 1.1rem !important;
        max-width: 150px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    /* Hide unnecessary header items on mobile */
    header .flex.items-center.space-x-4>span,
    header #adminLink,
    header #headerProfileBtn,
    header #headerLogoutBtn {
        display: none !important;
    }

    /* Ensure theme toggle is visible and properly spaced */
    #themeToggleBtn {
        margin-left: auto !important;
    }

    /* Hide desktop-only elements */
    .desktop-only {
        display: none !important;
    }

    /* Show hamburger menu button */
    .mobile-menu-btn {
        display: flex !important;
    }

    /* Adjust main content padding */
    main {
        padding: 1rem !important;
    }

    /* Make "New Note" button smaller on mobile */
    .mobile-new-note-btn {
        padding: 0.5rem 0.75rem !important;
        font-size: 0.75rem !important;
    }

    /* Note card grid - single column on mobile */
    #noteList {
        grid-template-columns: 1fr !important;
    }

    /* Search and filter section adjustments */
    .search-filter-section {
        flex-direction: column !important;
    }

    /* Date inputs smaller on mobile */
    input[type="date"] {
        font-size: 0.875rem !important;
        padding: 0.5rem !important;
    }

    /* Hide welcome message on very small screens */
    .welcome-message {
        display: none !important;
    }

    button,
    a[href] {
        min-height: 44px;
        min-width: 44px;
    }

    /* Larger touch targets for action buttons */
    .folder-item {
        padding: 0.75rem 1rem !important;
    }

    /* Note Detail Mobile Layout */
    #mainContentArea {
        flex-direction: column !important;
        overflow-y: auto !important;
        height: auto !important;
    }

    #scriptArea {
        width: 100% !important;
        border-right: none !important;
        border-bottom: 1px solid #e5e7eb !important;
        flex: none !important;
        overflow-y: visible !important;
        padding-bottom: 2rem !important;
    }

    #rightPanel {
        width: 100% !important;
        min-width: 0 !important;
        max-width: none !important;
        flex: none !important;
        overflow-y: visible !important;
    }

    #resizer {
        display: none !important;
    }

    /* Adjust sub-header for mobile */
    .sub-header {
        height: auto !important;
        padding: 0.75rem 1rem !important;
        flex-wrap: wrap !important;
    }

    /* Waveform height reduction on mobile */
    #waveform {
        height: 80px !important;
        margin-bottom: 1.5rem !important;
    }

    #waveform>wave {
        height: 80px !important;
    }

    /* Mobile-only sidebar menu */
    .mobile-only-menu {
        display: block !important;
        border-top: 1px solid #e5e7eb;
        margin-top: auto;
        padding-top: 1rem;
    }

    .dark .mobile-only-menu {
        border-top-color: #374151;
    }
}

.dark #scriptArea {
    border-bottom-color: #374151 !important;
}

/* Default hide mobile-only menu */
.mobile-only-menu {
    display: none;
}

/* ========================================
   Tablet Breakpoint
   ======================================== */
@media (min-width: 769px) and (max-width: 1024px) {

    /* Sidebar slightly narrower on tablets */
    aside {
        width: 220px !important;
    }

    /* Note grid - 2 columns */
    #noteList {
        grid-template-columns: repeat(2, 1fr) !important;
    }
}

/* ========================================
   Desktop - Hide mobile elements
   ======================================== */
@media (min-width: 769px) {
    .sidebar-overlay {
        display: none !important;
    }
}

/* ========================================
   Orientation Overlay
   ======================================== */
.orientation-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 9999;
    background-color: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 2rem;
}

.dark .orientation-overlay {
    background-color: rgba(17, 24, 39, 0.8);
}

.orientation-overlay.visible {
    display: flex;
}

.orientation-icon {
    width: 80px;
    height: 80px;
    margin-bottom: 2rem;
    color: #4f46e5;
    animation: rotate-device 2s infinite ease-in-out;
}

@keyframes rotate-device {
    0% {
        transform: rotate(0deg);
    }

    50% {
        transform: rotate(90deg);
    }

    100% {
        transform: rotate(0deg);
    }
}

.orientation-text {
    font-size: 1.5rem;
    font-weight: 700;
    color: #1f2937;
    line-height: 1.4;
}

.dark .orientation-text {
    color: #f3f4f6;
}

/* Smartphone Landscape Warning */
@media (max-width: 950px) and (orientation: landscape) {
    .orientation-overlay.smartphone-landscape {
        display: flex !important;
    }
}

/* Tablet Portrait - Remove warning for PWA */
/* @media (min-width: 769px) and (max-width: 1024px) and (orientation: portrait) {
    .orientation-overlay.tablet-portrait {
        display: flex !important;
    }
} */

/* ========================================
   Landscape Orientation Optimization
   ======================================== */
@media (max-height: 500px) and (orientation: landscape) {

    header {
        display: none !important;
    }

    .sub-header {
        height: 3rem !important;
        padding: 0 1rem !important;
        position: sticky;
        top: 0;
        z-index: 40;
        background-color: white;
        border-bottom: 1px solid #e5e7eb;
    }

    .dark .sub-header {
        background-color: #1f2937;
        border-bottom-color: #374151;
    }

    #mainContentArea {
        flex-direction: row !important;
        height: calc(100vh - 3rem) !important;
        overflow: hidden !important;
    }

    #scriptArea {
        width: 50% !important;
        height: 100% !important;
        overflow-y: auto !important;
        border-right: 1px solid #e5e7eb !important;
        border-bottom: none !important;
    }

    #rightPanel {
        width: 50% !important;
        height: 100% !important;
        overflow-y: auto !important;
    }

    #waveform,
    #waveform>wave {
        height: 40px !important;
    }

    .welcome-message,
    #headerUsername,
    #adminLink,
    #headerProfileBtn,
    #headerLogoutBtn {
        display: none !important;
    }
}

/* ========================================
   PWA - Bottom Navigation Bar
   ======================================== */
.mobile-bottom-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 64px;
    background: white;
    border-top: 1px solid #e5e7eb;
    justify-content: space-around;
    align-items: center;
    z-index: 1000;
    padding-bottom: env(safe-area-inset-bottom);
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.08);
}

.dark .mobile-bottom-nav {
    background: #1f2937;
    border-top-color: #374151;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.3);
}

.mobile-bottom-nav .nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 8px 16px;
    color: #6b7280;
    text-decoration: none;
    border: none;
    background: transparent;
    cursor: pointer;
    transition: all 0.2s ease;
    min-width: 64px;
}

.mobile-bottom-nav .nav-item:active {
    transform: scale(0.95);
}

.mobile-bottom-nav .nav-item.active {
    color: #4f46e5;
}

.dark .mobile-bottom-nav .nav-item {
    color: #9ca3af;
}

.dark .mobile-bottom-nav .nav-item.active {
    color: #818cf8;
}

.mobile-bottom-nav .nav-item svg {
    width: 24px;
    height: 24px;
    margin-bottom: 4px;
}

.mobile-bottom-nav .nav-item span {
    font-size: 10px;
    font-weight: 500;
}

/* Show bottom nav on mobile and tablet portrait */
@media (max-width: 1024px) {
    .mobile-bottom-nav {
        display: flex;
    }

    main {
        padding-bottom: 80px !important;
    }
}

/* Hide on tablet landscape and desktop */
@media (min-width: 1025px) {
    .mobile-bottom-nav {
        display: none !important;
    }
}

/* ========================================
   PWA - Tablet Portrait (768-1024px)
   ======================================== */
@media (min-width: 768px) and (max-width: 1024px) and (orientation: portrait) {

    /* Collapsible icon sidebar */
    .sidebar {
        width: 80px !important;
        overflow: hidden;
        transition: width 0.3s ease;
    }

    .sidebar:hover {
        width: 260px !important;
    }

    .sidebar .folder-item span,
    .sidebar h2,
    .sidebar .mobile-only-menu {
        opacity: 0;
        transition: opacity 0.2s ease;
    }

    .sidebar:hover .folder-item span,
    .sidebar:hover h2,
    .sidebar:hover .mobile-only-menu {
        opacity: 1;
    }

    /* 2-column note grid */
    #noteList {
        grid-template-columns: repeat(2, 1fr) !important;
    }
}

/* ========================================
   PWA - Tablet Landscape (1025-1366px)
   ======================================== */
@media (min-width: 1025px) and (max-width: 1366px) {
    .sidebar {
        width: 260px !important;
    }

    #noteList {
        grid-template-columns: repeat(2, 1fr) !important;
    }
}

/* ========================================
   PWA - Desktop (1367px+)
   ======================================== */
@media (min-width: 1367px) {
    .sidebar {
        width: 280px !important;
    }

    #noteList {
        grid-template-columns: repeat(3, 1fr) !important;
    }
}

/* ========================================
   PWA - Install Prompt Banner
   ======================================== */
.install-banner {
    position: fixed;
    bottom: 80px;
    left: 16px;
    right: 16px;
    background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
    color: white;
    padding: 16px 20px;
    border-radius: 16px;
    display: none;
    align-items: center;
    justify-content: space-between;
    z-index: 999;
    box-shadow: 0 10px 40px rgba(79, 70, 229, 0.3);
    animation: slideUp 0.4s ease;
}

@keyframes slideUp {
    from {
        transform: translateY(100px);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.install-banner.show {
    display: flex;
}

.install-banner-content {
    display: flex;
    align-items: center;
    gap: 12px;
}

.install-banner-icon {
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.install-banner-icon svg {
    width: 24px;
    height: 24px;
}

.install-banner-text h4 {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 2px;
}

.install-banner-text p {
    font-size: 12px;
    opacity: 0.9;
}

.install-banner-btn {
    background: white;
    color: #4f46e5;
    border: none;
    padding: 10px 20px;
    border-radius: 10px;
    font-weight: 600;
    font-size: 13px;
    cursor: pointer;
    transition: transform 0.2s;
}

.install-banner-btn:hover {
    transform: scale(1.05);
}

.install-banner-close {
    position: absolute;
    top: -8px;
    right: -8px;
    width: 24px;
    height: 24px;
    background: white;
    color: #4f46e5;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

/* ========================================
   PWA - Pull to Refresh Indicator
   ======================================== */
.pull-indicator {
    position: fixed;
    top: 0;
    left: 50%;
    transform: translateX(-50%) translateY(-100%);
    background: white;
    padding: 12px 24px;
    border-radius: 0 0 16px 16px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    display: flex;
    align-items: center;
    gap: 8px;
    z-index: 1001;
    transition: transform 0.3s ease;
}

.dark .pull-indicator {
    background: #374151;
    color: white;
}

.pull-indicator.visible {
    transform: translateX(-50%) translateY(0);
}

.pull-indicator svg {
    width: 20px;
    height: 20px;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}

/* ========================================
   PWA - Safe Area Support (iOS)
   ======================================== */
@supports (padding: max(0px)) {
    .mobile-bottom-nav {
        padding-bottom: max(8px, env(safe-area-inset-bottom));
        height: calc(64px + env(safe-area-inset-bottom));
    }

    @media (max-width: 1024px) {
        main {
            padding-bottom: calc(80px + env(safe-area-inset-bottom)) !important;
        }
    }
}