/**
 * CTV Portal - Responsive Styles
 * Modern Glassmorphism Design
 * 
 * Updated: January 2026
 */

/* Tablet / narrow desktop: keep the labeled desktop sidebar */
@media (max-width: 1024px) and (min-width: 641px) {

    .sidebar {
        width: var(--sidebar-width-expanded);
        padding: 20px 12px;
        align-items: stretch;
    }

    .main-wrapper {
        margin-left: var(--sidebar-width-expanded);
        padding: 90px 24px 24px 24px;
        width: calc(100% - var(--sidebar-width-expanded));
    }

    .floating-header {
        left: calc(var(--sidebar-width-expanded) + 16px);
        right: 16px;
    }

    .header-action-btn span {
        display: none;
    }

    .header-action-btn {
        padding: 10px 14px;
    }

    .header-user {
        display: none;
    }

    .nav-label {
        display: block;
    }

    .sidebar-icon span,
    .sidebar-icon .lang-current,
    .sidebar-logo span {
        display: inline-block;
    }

    .sidebar-icon {
        justify-content: flex-start;
        width: 100%;
        height: 50px;
        padding: 0 12px;
        margin-bottom: 0;
    }

    .sidebar-icon svg {
        width: 24px;
        height: 24px;
        margin: 0;
    }

    .sidebar-header {
        justify-content: center;
        padding-left: 0;
        margin-bottom: 24px;
    }

    .sidebar-logo {
        margin: 0;
    }

    .sidebar-logout {
        width: 56px;
        justify-content: center;
    }

    /* Grid Adjustments */
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 16px;
    }

    .ctv-clients-grid {
        grid-template-columns: 1fr;
    }

    .services-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .tree-stats {
        flex-direction: column;
        gap: 16px;
    }

    .tree-stat {
        flex: none;
        width: 100%;
    }

    /* Content adjustments */
    .content {
        padding: 0;
    }

    /* Language popup adjustments for iPad */
    .lang-popup {
        width: 200px !important;
        min-width: 200px !important;
        left: 70px !important;
        top: auto !important;
        bottom: 0 !important;
        transform: none !important;
        z-index: 2000 !important;
    }

    .lang-popup-title {
        font-size: 10px;
        padding: 6px 14px 4px;
    }

    .lang-option {
        padding: 8px 14px !important;
        font-size: 13px !important;
        min-width: 100% !important;
        width: 100% !important;
        margin: 0 !important;
    }

    .lang-option .lang-name {
        min-width: auto !important;
        width: auto !important;
        flex: 1 !important;
    }
}

/* Mobile Breakpoint */
@media (max-width: 640px) {

    /* Sidebar slides in/out - TG KOL Style */
    .sidebar {
        position: fixed !important;
        top: 0;
        left: 0;
        bottom: 0;
        width: 280px;
        z-index: 1100;
        transform: translateX(0);
        transition: transform 0.3s ease-in-out;
        display: flex !important;
        flex-direction: column;
        padding: 24px 16px;
    }

    /* Sidebar hidden state (collapsed) */
    .sidebar.collapsed {
        transform: translateX(-100%);
    }

    /* Sidebar backdrop for mobile */
    .sidebar-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        backdrop-filter: blur(4px);
        -webkit-backdrop-filter: blur(4px);
        z-index: 1099;
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.3s ease, visibility 0.3s ease;
    }

    .sidebar-backdrop.active {
        opacity: 1;
        visibility: visible;
    }

    /* Floating Header becomes the main navigation on mobile */
    .floating-header {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        border-radius: 0;
        border: none;
        border-bottom: 1px solid rgba(0, 0, 0, 0.06);
        z-index: 1001;
        background: rgba(255, 255, 255, 0.95);
    }

    .floating-header-inner {
        padding: 8px 12px;
        gap: 6px;
    }

    /* Show menu button on mobile */
    .header-menu-btn {
        display: flex !important;
        width: 36px;
        height: 36px;
    }

    .floating-header .header-logo {
        width: 32px;
        height: 32px;
    }

    /* Show brand name on mobile - compact */
    .header-brand {
        display: inline;
        font-size: 13px;
        font-weight: 700;
    }

    /* Show action buttons on mobile - icons only */
    .header-actions {
        display: flex;
        gap: 4px;
        flex: 0;
    }

    .header-action-btn {
        padding: 8px;
        border-radius: 10px;
    }

    .header-action-btn svg {
        width: 18px;
        height: 18px;
    }

    .header-action-btn span {
        display: none;
    }

    /* Hide booking button on mobile, keep only share link */
    .header-action-btn.action-booking {
        display: none;
    }

    /* Show user info in header on mobile - compact inline style */
    .header-user {
        display: flex !important;
        align-items: center;
        gap: 6px;
        padding: 4px 10px;
        background: rgba(0, 0, 0, 0.03);
        border-radius: 10px;
    }

    .floating-header .user-name {
        font-size: 12px;
        font-weight: 600;
        max-width: 70px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .floating-header .user-badge {
        font-size: 9px;
        padding: 2px 6px;
        border-radius: 6px;
        max-width: 90px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .header-lang-btn {
        padding: 6px 8px;
    }

    .header-lang-btn svg {
        width: 16px;
        height: 16px;
    }

    .header-lang-label {
        display: none;
    }

    /* Mobile Menu Popup - Glass Design */
    .mobile-menu-popup {
        display: block !important;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 2000;
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.3s ease, visibility 0.3s ease;
    }

    .mobile-menu-popup.active {
        opacity: 1;
        visibility: visible;
    }

    .mobile-menu-overlay {
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(15, 23, 42, 0.5);
        backdrop-filter: blur(4px);
        -webkit-backdrop-filter: blur(4px);
    }

    .mobile-menu-content {
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: auto;
        background: rgba(255, 255, 255, 0.98);
        backdrop-filter: blur(20px);
        -webkit-backdrop-filter: blur(20px);
        border-radius: 0 0 var(--radius-2xl) var(--radius-2xl);
        max-height: 85vh;
        overflow-y: auto;
        transform: translateY(-100%);
        transition: transform 0.3s ease;
        border: 1px solid var(--glass-border);
        border-top: none;
        box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
    }

    .mobile-menu-popup.active .mobile-menu-content {
        transform: translateY(0);
    }

    .mobile-menu-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 20px 24px;
        border-bottom: 1px solid rgba(0, 0, 0, 0.06);
        position: sticky;
        top: 0;
        background: rgba(255, 255, 255, 0.5);
        backdrop-filter: blur(10px);
        -webkit-backdrop-filter: blur(10px);
        z-index: 10;
    }

    .mobile-menu-header h3 {
        font-size: 18px;
        font-weight: 700;
        color: var(--text-primary);
        margin: 0;
    }

    .mobile-menu-close {
        width: 36px;
        height: 36px;
        background: rgba(0, 0, 0, 0.05);
        border: none;
        border-radius: var(--radius-sm);
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        transition: all 0.2s ease;
    }

    .mobile-menu-close:hover {
        background: rgba(0, 0, 0, 0.1);
    }

    .mobile-menu-close svg {
        width: 20px;
        height: 20px;
        stroke: var(--text-secondary);
        stroke-width: 2;
    }

    .mobile-menu-items {
        padding: 12px;
    }

    .mobile-menu-item {
        display: flex;
        align-items: center;
        gap: 16px;
        padding: 14px 16px;
        border-radius: var(--radius-md);
        cursor: pointer;
        transition: all 0.2s ease;
        color: var(--text-primary);
    }

    .mobile-menu-item:hover {
        background: rgba(79, 125, 243, 0.06);
    }

    .mobile-menu-item.active {
        background: linear-gradient(135deg, var(--primary-blue) 0%, var(--primary-purple) 100%);
        color: #ffffff;
        box-shadow: 0 4px 12px rgba(79, 125, 243, 0.3);
    }

    .mobile-menu-item.active svg {
        stroke: #ffffff;
    }

    .mobile-menu-item svg {
        width: 22px;
        height: 22px;
        stroke: var(--text-secondary);
        stroke-width: 2;
        stroke-linecap: round;
        stroke-linejoin: round;
        flex-shrink: 0;
    }

    .mobile-menu-item span {
        font-size: 15px;
        font-weight: 500;
        flex: 1;
    }

    /* Special styling for referral button in mobile menu */
    .mobile-menu-item.mobile-referral {
        background: linear-gradient(135deg, #ff8c42 0%, #ff6b35 100%);
        color: #ffffff;
        box-shadow: 0 4px 12px rgba(255, 107, 53, 0.3);
    }

    .mobile-menu-item.mobile-referral svg {
        stroke: #ffffff;
    }

    .mobile-menu-item.mobile-menu-logout {
        color: var(--danger);
    }

    .mobile-menu-item.mobile-menu-logout:hover {
        background: rgba(239, 68, 68, 0.1);
    }

    .mobile-menu-item.mobile-menu-logout svg {
        stroke: var(--danger);
    }

    .mobile-menu-divider {
        height: 1px;
        background: rgba(0, 0, 0, 0.06);
        margin: 8px 16px;
    }

    /* Mobile Language Toggle */
    .mobile-menu-lang {
        display: block !important;
    }

    .mobile-lang-current {
        font-size: 12px;
        font-weight: 700;
        color: var(--text-secondary);
        background: rgba(79, 125, 243, 0.08);
        padding: 4px 10px;
        border-radius: var(--radius-sm);
        margin-left: auto;
    }

    .mobile-menu-item.active .mobile-lang-current {
        background: rgba(255, 255, 255, 0.2);
        color: #ffffff;
    }

    .mobile-lang-popup {
        max-height: 0;
        overflow: hidden;
        transition: max-height 0.3s ease;
        padding: 0 16px;
    }

    .mobile-menu-lang.active .mobile-lang-popup {
        max-height: 200px;
        padding: 8px 16px;
    }

    .mobile-lang-popup .lang-option {
        margin-bottom: 4px;
    }

    /* Main wrapper adjustments - floating header needs top padding */
    .main-wrapper {
        margin-left: 0 !important;
        padding: 70px 0 20px 0 !important;
        /* Top padding for floating header */
        width: 100%;
        max-width: 100vw;
        overflow-x: hidden;
    }

    /* Legacy header hidden */
    .header {
        display: none !important;
    }

    /* Content padding */
    .content {
        padding: 16px;
        width: 100%;
        max-width: 100%;
    }

    /* Stats cards */
    .stats-grid {
        grid-template-columns: 1fr 1fr;
        gap: 12px;
    }

    .stat-card {
        padding: 14px 16px;
    }

    .stat-card .value {
        font-size: 18px;
    }

    .stat-card .label {
        font-size: 10px;
    }

    /* Cards */
    .card-header,
    .card-body {
        padding: 16px;
    }

    /* Phone check */
    .phone-check-row {
        flex-direction: column;
    }

    .phone-check-row input {
        width: 100%;
    }

    /* Booking phone input row */
    .phone-input-row {
        flex-direction: column;
        align-items: stretch;
    }

    .phone-input-row input {
        width: 100%;
    }

    .phone-input-row .btn-check-phone {
        width: 100%;
    }

    .phone-input-row .phone-check-result {
        width: 100%;
        text-align: center;
    }

    /* Date filters */
    .date-filter {
        flex-direction: column;
        gap: 12px;
    }

    .date-filter input,
    .date-filter select {
        width: 100%;
    }

    /* Client cards */
    .client-info-row {
        flex-direction: column;
        align-items: flex-start;
    }

    .client-status-badge {
        margin-left: 0;
        margin-top: 8px;
    }

    .services-grid {
        grid-template-columns: 1fr;
    }

    /* Tables */
    table {
        display: block;
        overflow-x: auto;
    }

    /* Tree */
    .tree-wrapper {
        padding: 12px;
    }

    .tree-node {
        padding: 6px 12px;
        font-size: 13px;
    }

    /* Commission tooltip */
    .commission-tooltip {
        left: 0;
        right: 0;
        transform: none;
        margin: 0 16px 8px;
    }

    .commission-tooltip::after {
        left: 20%;
    }
}

/* Larger mobile screens - show more user info */
@media (min-width: 480px) and (max-width: 640px) {
    .floating-header .user-name {
        max-width: 90px;
        font-size: 13px;
    }

    .floating-header .user-badge {
        max-width: 110px;
        font-size: 9px;
    }

    .header-lang-label {
        display: inline;
        font-size: 10px;
    }
}

/* Small Mobile */
@media (max-width: 480px) {

    /* Floating header adjustments for small mobile */
    .floating-header-inner {
        padding: 6px 8px;
        gap: 4px;
    }

    .header-menu-btn {
        width: 32px;
        height: 32px;
    }

    .header-menu-btn svg {
        width: 16px;
        height: 16px;
    }

    .floating-header .header-logo {
        width: 28px;
        height: 28px;
    }

    /* Hide brand text on very small screens */
    .header-brand {
        display: none;
    }

    /* Compact action buttons */
    .header-action-btn {
        padding: 6px;
    }

    .header-action-btn svg {
        width: 16px;
        height: 16px;
    }

    /* Compact user info on small mobile */
    .header-user {
        padding: 3px 6px;
        gap: 4px;
    }

    .floating-header .user-name {
        font-size: 11px;
        max-width: 50px;
    }

    .floating-header .user-badge {
        font-size: 8px;
        padding: 2px 4px;
        max-width: 70px;
    }

    .header-lang-btn {
        padding: 4px 6px;
    }

    .header-lang-btn svg {
        width: 14px;
        height: 14px;
    }

    .main-wrapper {
        padding-top: 55px !important;
    }

    .login-box {
        padding: 32px 24px;
    }

    .login-box h1 {
        font-size: 22px;
    }

    .login-logo {
        width: 60px;
        height: 60px;
    }

    .login-logo svg {
        width: 32px;
        height: 32px;
    }

    .header-title {
        font-size: 15px;
    }

    .header-page-title {
        font-size: 13px;
        margin-left: 8px;
    }

    .header-page-title::before {
        margin-right: 8px;
    }

    .user-name {
        font-size: 12px;
    }

    .stats-grid {
        grid-template-columns: 1fr;
    }

    .view-toggle {
        flex-direction: column;
    }

    .view-toggle-btn {
        width: 100%;
        justify-content: center;
    }

    .btn-filter-preset {
        padding: 6px 10px;
        font-size: 11px;
    }
}

/* Landscape Mobile */
@media (max-height: 500px) and (orientation: landscape) {
    .floating-header-inner {
        padding: 4px 10px;
    }

    .floating-header .header-logo {
        width: 28px;
        height: 28px;
    }

    .header-menu-btn {
        width: 32px;
        height: 32px;
    }

    .header-action-btn {
        padding: 6px 10px;
    }

    .main-wrapper {
        padding-top: 50px !important;
        padding-bottom: 20px !important;
    }
}
