/* ==================== HELPMUSIC RESPONSIVE CSS ==================== */
/* Mobile-first approach for tablets and smartphones */

/* ==================== DESKTOP (hide mobile elements) ==================== */
.mobile-header {
    display: none;
}

.sidebar-overlay {
    display: none;
}

/* ==================== TABLET (768px - 1024px) ==================== */
@media (max-width: 1024px) {
    :root {
        --sidebar-width: 60px;
    }

    /* Sidebar colapsada */
    .sidebar {
        width: 60px;
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        z-index: 1000;
    }

    .sidebar .logo-text,
    .sidebar .nav-item span,
    .sidebar .nav-section-title,
    .sidebar .user-details,
    .sidebar .badge,
    .sidebar .setlist-name {
        display: none;
    }

    .sidebar .nav-item {
        justify-content: center;
        padding: 14px;
    }

    .sidebar .nav-item i {
        margin-right: 0;
        font-size: 18px;
    }

    .sidebar-header {
        justify-content: center;
        padding: 16px 8px;
    }

    .sidebar .logo {
        display: none;
    }

    .sidebar .user-info {
        flex-direction: column;
        gap: 8px;
    }

    .sidebar .user-avatar {
        margin-right: 0;
    }

    .sidebar .user-menu-btn {
        display: none;
    }

    /* Main content ajustado */
    .main-content {
        margin-left: 60px;
        width: calc(100% - 60px);
    }

    /* Header da página */
    .page-header {
        flex-wrap: wrap;
        gap: 16px;
        padding: 16px 20px;
    }

    .page-header h1 {
        font-size: 20px;
        width: 100%;
    }

    .header-actions {
        width: 100%;
        justify-content: space-between;
    }

    .search-box {
        flex: 1;
        max-width: 300px;
    }

    /* Tabela de tracks */
    .tracks-table {
        padding: 0 16px;
    }

    .table-header,
    .track-row {
        grid-template-columns: 1fr 120px 60px 70px 40px;
        gap: 8px;
        padding: 12px;
    }

    .col-duration {
        display: none;
    }

    /* Editor */
    .editor-sidebar {
        left: 60px;
        width: 280px;
    }

    .editor-main {
        margin-left: 280px;
    }

    .editor-header {
        padding: 16px 20px;
    }

    /* Stems grid */
    .stems-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
        padding: 16px;
    }

    .stem-card.wide {
        grid-column: span 1;
    }

    /* Player footer */
    .player-footer {
        padding: 12px 16px;
    }

    .player-controls {
        gap: 12px;
    }

    /* Modais */
    .modal-content {
        width: 90%;
        max-width: 500px;
        margin: 20px;
    }

    /* YouTube miniplayer */
    .youtube-miniplayer {
        width: 280px;
        right: 10px;
        bottom: 100px;
    }
}

/* ==================== MOBILE (< 768px) ==================== */
@media (max-width: 768px) {
    /* Sidebar como menu lateral deslizante */
    .sidebar {
        width: 280px;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        z-index: 2000;
    }

    .sidebar.mobile-open {
        transform: translateX(0);
    }

    .sidebar .logo-text,
    .sidebar .nav-item span,
    .sidebar .nav-section-title,
    .sidebar .user-details,
    .sidebar .setlist-name {
        display: block;
    }

    .sidebar .nav-item {
        justify-content: flex-start;
        padding: 12px 16px;
    }

    .sidebar .nav-item i {
        margin-right: 12px;
    }

    .sidebar-header {
        justify-content: space-between;
        padding: 16px;
    }

    .sidebar .logo {
        display: flex;
    }

    /* Overlay quando sidebar aberta */
    .sidebar-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.6);
        z-index: 1999;
    }

    .sidebar-overlay.visible {
        display: block;
    }

    /* Main content full width */
    .main-content {
        margin-left: 0;
        width: 100%;
    }

    /* Mobile header com menu hamburger */
    .mobile-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 12px 16px;
        background: var(--bg-secondary);
        border-bottom: 1px solid var(--border-color);
        position: sticky;
        top: 0;
        z-index: 100;
    }

    .mobile-menu-btn {
        width: 40px;
        height: 40px;
        background: none;
        border: none;
        color: var(--text-primary);
        font-size: 20px;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        border-radius: var(--radius-md);
    }

    .mobile-menu-btn:active {
        background: var(--bg-hover);
    }

    .mobile-logo {
        display: flex;
        align-items: center;
        gap: 8px;
    }

    .mobile-logo svg {
        width: 24px;
        height: 24px;
    }

    .mobile-logo span {
        font-size: 16px;
        font-weight: 600;
    }

    /* Page header mobile */
    .page-header {
        flex-direction: column;
        align-items: flex-start;
        padding: 16px;
        gap: 12px;
    }

    .page-header h1 {
        font-size: 18px;
        display: flex;
        align-items: center;
        gap: 8px;
    }

    .track-count {
        font-size: 12px;
    }

    .header-actions {
        width: 100%;
        flex-wrap: wrap;
        gap: 8px;
    }

    .search-box {
        flex: 1;
        min-width: 150px;
        order: 1;
    }

    .search-box input {
        font-size: 14px;
    }

    #sortBtn {
        order: 2;
    }

    #addTrackBtn {
        order: 3;
        flex: 1;
        justify-content: center;
    }

    /* Tabela de tracks - layout card */
    .tracks-table {
        padding: 0 12px;
    }

    .table-header {
        display: none;
    }

    .table-body {
        display: flex;
        flex-direction: column;
        gap: 8px;
        padding: 8px 0;
    }

    .track-row {
        display: flex;
        flex-direction: column;
        padding: 12px;
        background: var(--bg-secondary);
        border-radius: var(--radius-md);
        border: 1px solid var(--border-color);
        gap: 8px;
    }

    .track-row:active {
        background: var(--bg-hover);
    }

    .col-title {
        display: flex;
        align-items: center;
        gap: 12px;
        width: 100%;
    }

    .track-cover {
        width: 48px;
        height: 48px;
        flex-shrink: 0;
    }

    .track-info {
        flex: 1;
        min-width: 0;
    }

    .track-name {
        font-size: 15px;
        font-weight: 500;
    }

    .col-artist {
        display: none;
    }

    .track-artist {
        display: block;
        font-size: 13px;
        color: var(--text-secondary);
        margin-top: 2px;
    }

    .track-meta {
        display: flex;
        align-items: center;
        gap: 16px;
        padding-left: 60px;
    }

    .col-bpm,
    .col-key {
        display: flex;
        align-items: center;
        gap: 4px;
        font-size: 12px;
        color: var(--text-secondary);
    }

    .col-bpm::before {
        content: 'BPM:';
        color: var(--text-muted);
    }

    .col-key::before {
        content: 'Tom:';
        color: var(--text-muted);
    }

    .col-duration,
    .col-genre {
        display: none;
    }

    .col-actions {
        position: absolute;
        top: 12px;
        right: 12px;
    }

    .track-row {
        position: relative;
    }

    /* Editor mobile */
    .page-editor {
        flex-direction: column;
    }

    .editor-sidebar {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        top: auto;
        width: 100%;
        height: auto;
        max-height: 50vh;
        border-radius: var(--radius-xl) var(--radius-xl) 0 0;
        transform: translateY(100%);
        transition: transform 0.3s ease;
        z-index: 1500;
    }

    .editor-sidebar.mobile-open {
        transform: translateY(0);
    }

    .editor-main {
        margin-left: 0;
        padding-bottom: 80px;
    }

    .editor-header {
        padding: 12px 16px;
        flex-wrap: wrap;
        gap: 12px;
    }

    .editor-track-info {
        width: 100%;
    }

    .editor-actions {
        width: 100%;
        justify-content: space-between;
    }

    /* Stems grid mobile */
    .stems-grid {
        grid-template-columns: 1fr;
        gap: 8px;
        padding: 12px;
    }

    .stem-card {
        padding: 12px;
    }

    .stem-card.wide {
        grid-column: span 1;
    }

    .stem-header {
        margin-bottom: 8px;
    }

    .stem-name {
        font-size: 14px;
    }

    .stem-waveform {
        height: 40px;
    }

    .stem-controls {
        margin-top: 8px;
    }

    /* Player footer mobile */
    .player-footer {
        padding: 8px 12px;
        flex-wrap: wrap;
        gap: 8px;
    }

    .player-track-info {
        width: 100%;
        order: 1;
    }

    .player-controls {
        width: 100%;
        justify-content: center;
        order: 2;
        gap: 16px;
    }

    .player-progress {
        width: 100%;
        order: 3;
    }

    .player-volume {
        display: none;
    }

    .btn-play {
        width: 56px;
        height: 56px;
        font-size: 20px;
    }

    /* Modais mobile */
    .modal-content {
        width: 100%;
        max-width: none;
        margin: 0;
        border-radius: var(--radius-xl) var(--radius-xl) 0 0;
        max-height: 90vh;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
    }

    .modal-header {
        padding: 16px;
        position: sticky;
        top: 0;
        background: var(--bg-secondary);
        z-index: 10;
    }

    .modal-body {
        padding: 16px;
        overflow-y: auto;
        max-height: calc(90vh - 120px);
    }

    .modal-footer {
        padding: 16px;
        position: sticky;
        bottom: 0;
        background: var(--bg-secondary);
    }

    .form-row {
        flex-direction: column;
        gap: 12px;
    }

    .form-group {
        width: 100%;
    }

    /* Upload modal */
    .upload-area {
        padding: 24px 16px;
    }

    .upload-area i {
        font-size: 36px;
    }

    .upload-area h3 {
        font-size: 16px;
    }

    /* YouTube miniplayer mobile */
    .youtube-miniplayer {
        width: calc(100% - 24px);
        left: 12px;
        right: 12px;
        bottom: 12px;
    }

    .youtube-miniplayer-title {
        max-width: 180px;
    }

    /* Pagination mobile */
    .pagination {
        flex-wrap: wrap;
        justify-content: center;
        gap: 8px;
        padding: 16px;
    }

    .pagination-btn {
        min-width: 40px;
        height: 40px;
    }

    /* Toast mobile */
    .toast-container {
        left: 12px;
        right: 12px;
        bottom: 80px;
    }

    .toast {
        width: 100%;
    }

    /* Context menu mobile */
    .context-menu {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        top: auto;
        border-radius: var(--radius-xl) var(--radius-xl) 0 0;
        max-height: 60vh;
        overflow-y: auto;
    }

    .context-menu-item {
        padding: 16px 20px;
        font-size: 15px;
    }

    /* Dropdown mobile */
    .dropdown-menu {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        top: auto;
        border-radius: var(--radius-xl) var(--radius-xl) 0 0;
        max-height: 60vh;
    }

    /* Loading overlay mobile */
    .loading-content-bars {
        width: 100%;
        margin: 16px;
        padding: 24px;
    }

    .loading-bars {
        gap: 8px;
    }

    .loading-bar {
        width: 8px;
    }
}

/* ==================== SMALL MOBILE (< 480px) ==================== */
@media (max-width: 480px) {
    .page-header h1 {
        font-size: 16px;
    }

    .btn-primary {
        padding: 10px 16px;
        font-size: 13px;
    }

    .track-cover {
        width: 40px;
        height: 40px;
    }

    .track-name {
        font-size: 14px;
    }

    .track-meta {
        padding-left: 52px;
    }

    .stem-card {
        padding: 10px;
    }

    .player-controls button {
        width: 36px;
        height: 36px;
    }

    .btn-play {
        width: 48px;
        height: 48px;
    }

    .modal-header h3 {
        font-size: 16px;
    }

    .form-group label {
        font-size: 12px;
    }

    .form-group input,
    .form-group select,
    .form-group textarea {
        font-size: 14px;
        padding: 10px 12px;
    }
}

/* ==================== LANDSCAPE MOBILE ==================== */
@media (max-width: 768px) and (orientation: landscape) {
    .modal-content {
        max-height: 100vh;
        border-radius: 0;
    }

    .editor-sidebar {
        max-height: 100vh;
        width: 50%;
        left: auto;
        right: 0;
        top: 0;
        bottom: 0;
        border-radius: 0;
        transform: translateX(100%);
    }

    .editor-sidebar.mobile-open {
        transform: translateX(0);
    }

    .player-footer {
        flex-wrap: nowrap;
    }

    .player-track-info {
        width: auto;
        flex: 1;
    }

    .player-controls {
        width: auto;
    }

    .player-progress {
        width: auto;
        flex: 2;
    }
}

/* ==================== TOUCH OPTIMIZATIONS ==================== */
@media (hover: none) and (pointer: coarse) {
    /* Aumentar áreas de toque */
    .nav-item {
        min-height: 48px;
    }

    .btn-icon {
        min-width: 44px;
        min-height: 44px;
    }

    .track-row {
        min-height: 64px;
    }

    .stem-controls button {
        min-width: 44px;
        min-height: 44px;
    }

    .slider-thumb {
        width: 24px;
        height: 24px;
    }

    /* Remover hover effects em touch */
    .track-row:hover {
        background: transparent;
    }

    .nav-item:hover {
        background: transparent;
    }

    /* Adicionar active states */
    .track-row:active {
        background: var(--bg-hover);
    }

    .nav-item:active {
        background: var(--bg-hover);
    }

    .btn-primary:active {
        transform: scale(0.98);
    }

    .btn-icon:active {
        transform: scale(0.95);
    }

    /* Scroll suave */
    .table-body,
    .modal-body,
    .sidebar-nav {
        -webkit-overflow-scrolling: touch;
        scroll-behavior: smooth;
    }

    /* Prevenir zoom em inputs */
    input, select, textarea {
        font-size: 16px !important;
    }
}

/* ==================== SAFE AREA (iPhone X+) ==================== */
@supports (padding: max(0px)) {
    .sidebar {
        padding-bottom: max(16px, env(safe-area-inset-bottom));
    }

    .player-footer {
        padding-bottom: max(12px, env(safe-area-inset-bottom));
    }

    .modal-content {
        padding-bottom: max(16px, env(safe-area-inset-bottom));
    }

    .context-menu {
        padding-bottom: max(16px, env(safe-area-inset-bottom));
    }

    .mobile-header {
        padding-top: max(12px, env(safe-area-inset-top));
    }
}

/* ==================== DARK MODE ADJUSTMENTS ==================== */
@media (prefers-color-scheme: dark) {
    /* Já é dark por padrão, mas garantir contraste */
    .track-row {
        border-color: var(--border-color);
    }
}

/* ==================== REDUCED MOTION ==================== */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ==================== HIGH CONTRAST ==================== */
@media (prefers-contrast: high) {
    :root {
        --border-color: #666666;
        --text-secondary: #cccccc;
    }

    .track-row {
        border-width: 2px;
    }

    .btn-primary {
        border: 2px solid var(--accent-primary);
    }
}
