/* Shared responsive layout for the main Dhannyllo+ platform. */

html {
    width: 100%;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body,
#app,
.main-layout,
.main-content,
.player-page-content {
    min-width: 0;
    max-width: 100%;
}

:where(button, input, select, textarea, iframe, video, audio, canvas) {
    max-width: 100%;
}

:where(input, select, textarea) {
    min-width: 0;
}

:where(img, video, iframe, canvas) {
    max-width: 100%;
}

:where(p, a, label, td, th, h1, h2, h3, h4, h5, h6) {
    overflow-wrap: anywhere;
}

.main-content,
.player-layout > .player-page-content {
    width: calc(100% - 260px);
    min-width: 0;
    padding: clamp(1rem, 2vw, 2rem);
}

.main-content > *,
.player-page-content > *,
.section-content-wrapper > * {
    min-width: 0;
    max-width: 100%;
}

.content-grid,
.plans-grid,
.games-grid,
.creators-grid,
.lives-grid,
.features-grid,
.metrics-grid,
.admin-panel,
.ia-projects-grid {
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 17rem), 1fr));
}

.page-header,
.home-header,
.section-header,
.creator-header,
.creator-actions,
.modal-actions,
.form-actions {
    min-width: 0;
    flex-wrap: wrap;
}

.page-header > :where(h1, h2),
.home-header > :where(h1, h2),
.section-header > :where(h1, h2) {
    min-width: 0;
    flex: 1 1 12rem;
}

.admin-form-grid,
.form-grid,
.profile-grid,
.dashboard-grid,
.player-columns {
    min-width: 0;
}

table {
    display: block;
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
}

.modal-backdrop {
    padding: max(0.75rem, env(safe-area-inset-top))
        max(0.75rem, env(safe-area-inset-right))
        max(0.75rem, env(safe-area-inset-bottom))
        max(0.75rem, env(safe-area-inset-left));
}

.modal,
.modal-content,
.modal-body {
    min-width: 0;
    max-width: 100%;
    max-height: min(90vh, 90dvh);
    overflow: auto;
    overscroll-behavior: contain;
}

.player-container {
    min-width: 0;
}

.sidebar {
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

.sidebar-logo,
.sidebar-footer {
    flex: 0 0 auto;
}

.sidebar-nav {
    flex: 1 1 auto;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior-y: contain;
}

.sidebar-footer {
    max-height: min(28dvh, 11rem);
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
    touch-action: pan-y;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.45) transparent;
    padding-bottom: max(var(--spacing-md), env(safe-area-inset-bottom));
}

.sidebar-footer::-webkit-scrollbar {
    width: 8px;
}

.sidebar-footer::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar-footer::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.38);
    border: 2px solid transparent;
    border-radius: 999px;
    background-clip: padding-box;
}

.sidebar-footer::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.62);
    background-clip: padding-box;
}

.sidebar-bottom-nav {
    min-height: 0;
}

.sidebar-bottom-nav ul {
    margin: 0;
    padding: 0;
    list-style: none;
}

.sidebar-bottom-nav li {
    margin-bottom: 0.25rem;
}

.sidebar-bottom-nav li:last-child {
    margin-bottom: 0;
}

.sidebar-bottom-nav a {
    min-height: 44px;
}

.sidebar-bottom-nav ul li a {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-height: 44px;
    padding: 0.75rem 1rem;
    border-radius: var(--radius-lg);
    color: rgba(255, 255, 255, 0.92);
    font-weight: 600;
    text-decoration: none;
}

.sidebar-bottom-nav ul li a:hover,
.sidebar-bottom-nav ul li a.active {
    background: rgba(255, 255, 255, 0.14);
    color: #fff;
}

.sidebar-bottom-nav ul li a.active {
    border-left: 4px solid rgba(255, 255, 255, 0.85);
    padding-left: calc(1rem - 4px);
}

.sidebar-bottom-icon {
    display: block;
    flex: 0 0 24px;
    width: 24px;
    height: 24px;
    max-width: 24px;
    object-fit: contain;
}

.sidebar-bottom-nav ul li a > span {
    display: block;
    flex: 1 1 auto;
    min-width: 0;
    color: inherit;
    opacity: 1;
    visibility: visible;
    overflow-wrap: anywhere;
}

@media (min-width: 1600px) {
    .main-content,
    .player-layout > .player-page-content {
        padding-inline: clamp(2rem, 3vw, 4rem);
    }
}

@media (min-width: 901px) {
    .hamburger-menu {
        display: none;
    }
}

@media (max-width: 1100px) {
    .content-grid {
        grid-template-columns: repeat(auto-fit, minmax(min(100%, 15rem), 1fr));
        gap: clamp(0.75rem, 2vw, 1.5rem);
    }

    .admin-form-grid,
    .form-grid,
    .profile-grid {
        grid-template-columns: repeat(auto-fit, minmax(min(100%, 18rem), 1fr));
    }
}

@media (max-width: 900px) {
    .sidebar {
        inset: 0 auto 0 0;
        width: min(86vw, 320px);
        min-width: 0;
        max-width: 320px;
        height: 100vh;
        height: 100dvh;
        transform: translateX(-105%);
        z-index: 700;
    }

    .sidebar.active,
    .sidebar.open {
        transform: translateX(0);
    }

    .main-content,
    .player-layout > .player-page-content {
        width: 100%;
        margin-left: 0;
        padding: clamp(1rem, 3vw, 1.5rem);
    }

    .hamburger-menu {
        display: inline-flex;
        flex: 0 0 44px;
        align-items: center;
        justify-content: center;
        min-width: 44px;
        min-height: 44px;
    }

    .section-hero {
        min-height: clamp(12rem, 35vw, 18rem);
        padding: clamp(1rem, 4vw, 2rem);
    }

    .section-hero .page-header {
        padding: clamp(1rem, 3vw, 1.5rem);
    }

    .player-columns {
        grid-template-columns: minmax(0, 1fr);
    }

    .playlist-container {
        position: static;
        max-height: min(45vh, 28rem);
        order: 1;
    }
}

@media (max-width: 640px) {
    .main-content,
    .player-layout > .player-page-content {
        padding: 1rem max(0.75rem, env(safe-area-inset-right)) 1.25rem
            max(0.75rem, env(safe-area-inset-left));
        border-radius: 0;
    }

    .page-header,
    .section-header {
        align-items: center;
        gap: 0.75rem;
        padding: 0.875rem;
    }

    .page-header > :where(h1, h2),
    .section-header > :where(h1, h2) {
        flex-basis: calc(100% - 3.5rem);
        font-size: clamp(1.2rem, 5vw, 1.65rem);
    }

    .home-header {
        align-items: flex-start;
        gap: 0.75rem;
        padding: 1rem 0.75rem;
    }

    .home-nav {
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .hero,
    .section-hero {
        border-radius: var(--radius-lg);
    }

    .hero {
        padding: clamp(1.25rem, 6vw, 2rem) 1rem;
    }

    .hero h1,
    .hero h2 {
        font-size: clamp(1.5rem, 7vw, 2rem);
    }

    .hero p {
        font-size: 1rem;
    }

    .section-hero h1 {
        font-size: clamp(1.65rem, 8vw, 2.4rem);
    }

    .content-grid,
    .plans-grid,
    .games-grid,
    .creators-grid,
    .lives-grid,
    .features-grid,
    .metrics-grid,
    .admin-panel,
    .ia-projects-grid {
        grid-template-columns: minmax(0, 1fr);
        gap: 1rem;
    }

    .admin-form-grid,
    .form-grid,
    .profile-grid,
    .dashboard-grid {
        grid-template-columns: minmax(0, 1fr);
    }

    .site-footer,
    .login-form-container,
    .admin-section,
    .section-content-wrapper,
    .creator-dashboard,
    .settings-section {
        padding: 1rem;
    }

    :where(button, .btn, .button-primary, .button-secondary, .button-tertiary) {
        min-height: 44px;
    }

    .btn,
    .button-primary {
        max-width: 100%;
        white-space: normal;
    }

    :where(input, select, textarea) {
        font-size: 16px;
    }

    .creator-actions,
    .modal-actions {
        align-items: stretch;
    }

    .creator-actions > *,
    .modal-actions > * {
        flex: 1 1 9rem;
        min-width: 0;
    }

    .modal-content {
        padding: 1.25rem;
    }

    .modal {
        width: 100%;
        max-height: min(88vh, 88dvh);
    }

    .chat-input-area,
    .live-detail-chat-form {
        gap: 0.5rem;
    }

    #send-btn {
        min-width: 0;
    }

    .player-controls {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        flex-wrap: wrap;
    }

    .player-container {
        border-radius: var(--radius-md);
    }

    #toast-container {
        inset: auto max(0.75rem, env(safe-area-inset-right))
            max(0.75rem, env(safe-area-inset-bottom))
            max(0.75rem, env(safe-area-inset-left));
        width: auto;
    }

    .toast {
        width: 100%;
        min-width: 0;
        overflow-wrap: anywhere;
    }

    .accessibility-controls {
        left: max(0.75rem, env(safe-area-inset-left));
        bottom: max(0.75rem, env(safe-area-inset-bottom));
    }

    .a11y-panel {
        left: max(0.75rem, env(safe-area-inset-left));
        bottom: calc(max(0.75rem, env(safe-area-inset-bottom)) + 64px);
        width: min(360px, calc(100vw - 1.5rem));
    }
}

@media (max-width: 360px) {
    .main-content,
    .player-layout > .player-page-content {
        padding-inline: 0.625rem;
    }

    .page-header,
    .section-header {
        padding: 0.75rem;
    }

    .creator-header {
        align-items: flex-start;
    }

    .creator-avatar {
        width: 56px;
        height: 56px;
    }

    .player-controls {
        grid-template-columns: minmax(0, 1fr);
    }
}

@media (max-height: 500px) and (orientation: landscape) {
    .sidebar {
        height: 100vh;
        height: 100dvh;
    }

    .modal,
    .modal-content,
    .modal-body {
        max-height: 85vh;
        max-height: 85dvh;
    }

    .hero {
        padding-block: 1.25rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    html {
        scroll-behavior: auto;
    }
}
