/* ============================================
   MOBILE HEADER OPTIMIZATIONS
   ============================================ */
/* ============================================
   LEADERBOARD MOBILE OPTIMIZATIONS
   ============================================ */

@media (max-width: 768px) {
    /* Compact header */
    .leaderboard-container .header-section {
        padding: 15px;
        margin-bottom: 15px;
        border-radius: 12px;
    }
    
    .leaderboard-container .zinlab-logo {
        height: 70px !important;
        margin-bottom: 8px !important;
    }
    
    .leaderboard-container .header-section h1 {
        font-size: 1.2rem !important;
        margin-bottom: 8px !important;
    }
    
    .leaderboard-container .header-section p {
        font-size: 0.85rem;
        display: none; /* Hide subtitle on mobile */
    }
    
    /* Compact stats bar */
    .leaderboard-container .stats-bar {
        gap: 15px;
        margin-top: 15px;
    }
    
    .leaderboard-container .stat-item {
        min-width: 70px;
    }
    
    .leaderboard-container .stat-value {
        font-size: 1.5rem;
    }
    
    .leaderboard-container .stat-label {
        font-size: 0.65rem;
    }
    
    /* Filter section - stack vertically */
    .filter-section {
        padding: 12px;
        margin: 0 0 15px 0;
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }
    
    .filter-section > div {
        width: 100%;
    }
    
    .filter-section strong {
        display: block;
        margin-bottom: 8px;
        font-size: 0.85rem;
    }
    
    .filter-buttons {
        display: flex;
        gap: 6px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 5px;
    }
    
    .filter-btn {
        padding: 8px 15px;
        font-size: 0.8rem;
        white-space: nowrap;
        flex-shrink: 0;
        border-radius: 16px;
    }
    
    .form-select {
        width: 100%;
        padding: 10px;
        font-size: 0.9rem;
        border-radius: 8px;
    }
    
    /* Compact leaderboard items */
    .leaderboard-item {
        padding: 12px;
        margin-bottom: 10px;
        border-radius: 12px;
    }
    
    .rank-badge {
        width: 40px;
        height: 40px;
        font-size: 1.2rem;
        top: -5px;
        left: -5px;
    }
    
    .rank-badge.rank-1 {
        font-size: 1.5rem;
    }
    
    .blend-header {
        margin-left: 35px;
        margin-bottom: 12px;
        flex-direction: column;
        gap: 8px;
    }
    
    .blend-name {
        font-size: 1.1rem;
        line-height: 1.2;
    }
    
    .blend-creator {
        font-size: 0.85rem;
    }
    
    .blend-stats {
        text-align: left;
        margin-top: 0;
    }
    
    .twin-count {
        font-size: 1.5rem;
    }
    
    .twin-label {
        font-size: 0.75rem;
    }
    
    .blend-gradient {
        height: 40px;
        margin: 12px 0;
        border-radius: 8px;
    }
    
    .blend-formula {
        gap: 6px;
        margin-top: 10px;
    }
    
    .varietal-pill {
        padding: 5px 10px;
        font-size: 0.75rem;
        border-radius: 16px;
        border-left-width: 3px;
    }
    
    .varietal-pill .varietal-name {
        font-size: 0.75rem;
    }
    
    .varietal-pill .varietal-percentage {
        font-size: 0.85rem;
    }
    
    .blend-date {
        font-size: 0.7rem;
        margin-top: 8px;
    }
    
    .crown-icon {
        font-size: 2rem;
        top: 10px;
        right: 10px;
    }
    
    .view-blend-btn {
        padding: 8px 20px;
        font-size: 0.8rem;
        border-radius: 16px;
        margin-top: 10px;
    }
    
    /* Back button */
    .back-btn {
        padding: 10px 20px;
        font-size: 0.85rem;
        margin-bottom: 12px;
        border-radius: 8px;
    }
    
    /* Empty state */
    .empty-state {
        padding: 40px 15px;
    }
    
    .empty-state-icon {
        font-size: 3rem;
        margin-bottom: 15px;
    }
    
    .empty-state h3 {
        font-size: 1.2rem !important;
    }
    
    .empty-state p {
        font-size: 0.9rem;
    }
}

@media (max-width: 768px) {
    /* Compact header for mobile */
    .app-header {
        background: #78264C;
        padding: 10px;
        margin-bottom: 12px; /* Space for sticky nav */
        box-shadow: none;
        border-radius: unset;
    }
    
    .zinlab-logo {
        height: 70px !important;
        margin-bottom: 8px !important;
    }
    
    .app-header h1 {
        font-size: 0.9rem !important;
        margin: 0 !important;
        letter-spacing: 0.5px;
        display: none;
    }
    
    .session-info {
        font-size: 0.75rem;
        margin-bottom: 0;
        display: none;
    }
    
    /* Hide user badge container on mobile - info in sticky nav instead */
    .user-badge-container {
        display: none;
    }
}

/* ============================================
   STICKY NAVIGATION BAR
   ============================================ */

.zinlab-sticky-nav {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background:#78264C;
    color: white;
    padding: 8px 12px;
    box-shadow: none;
    z-index: 1000;
    display: none; /* Hidden by default, shown on mobile */
}

@media (max-width: 768px) {
    .zinlab-sticky-nav {
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: 8px;
    }
}

.sticky-nav-left {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    min-width: 0;
}

.sticky-nav-user {
    font-size: 0.8rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sticky-nav-blend-count {
    background: rgba(255,255,255,0.2);
    padding: 3px 8px;
    border-radius: 12px;
    font-size: 0.7rem;
    white-space: nowrap;
    font-weight: 600;
}

.sticky-nav-actions {
    display: flex;
    gap: 6px;
}

.sticky-nav-btn {
    background: rgba(255,255,255,0.2);
    border: none;
    color: white;
    padding: 5px 10px;
    border-radius: 16px;
    font-size: 0.7rem;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    gap: 4px;
}

.sticky-nav-btn:hover,
.sticky-nav-btn:active {
    background: rgba(255,255,255,0.3);
}

.sticky-nav-btn i {
    font-size: 0.8rem;
}

/* ============================================
   MOBILE CONTENT LAYOUT
   ============================================ */

@media (max-width: 768px) {
    .app-container {
        padding: 42px 0px 20px 0px; /* Top padding for sticky nav */
    }
    
    .content-grid {
        grid-template-columns: 1fr;
        gap: 15px;
    }
    
    /* Make sidebar sections stack on mobile */
    .sidebar-section {
        order: 1; /* Move below main content on mobile */
    }
    
    .main-content-section {
        order: 0;
    }
}

/* ============================================
   BLEND COMPOSITION - MOBILE OPTIMIZED
   ============================================ */

@media (max-width: 768px) {
    /* Compact blend composition header */
    .sliders-section {
        padding: 15px;
        border-radius: 12px;
    }
    
    .sliders-section > h2 {
        font-size: 1rem !important;
        margin: 0 0 12px 0 !important;
        padding-bottom: 8px;
        border-bottom: 2px solid #e0e0e0;
    }
    
    /* Varietal sliders - optimized spacing */
    .varietal-slider,
    .slider-group {
        margin-bottom: 12px;
    }
    
    .varietal-header,
    .slider-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-bottom: 6px;
    }
    
    .varietal-name,
    .slider-header .varietal-name {
        font-size: 0.85rem;
        font-weight: 600;
    }
    
    .slider-header small {
        font-size: 0.7rem;
        margin-left: 6px;
    }
    
    .varietal-percentage {
        font-size: 1rem;
        font-weight: 700;
        color: #78264C;
        min-width: 45px;
        text-align: right;
    }
    
    .ml-display {
        font-size: 0.8rem;
        padding: 3px 10px !important;
    }
    
    /* Slider styling */
    input[type="range"] {
        width: 100%;
        height: 6px;
        -webkit-appearance: none;
        appearance: none;
        background: #e0e0e0;
        border-radius: 4px;
        outline: none;
        touch-action: none;
    }
    
    input[type="range"]::-webkit-slider-thumb {
        -webkit-appearance: none;
        appearance: none;
        width: 28px;
        height: 28px;
        background: #78264C;
        border-radius: 50%;
        cursor: pointer;
        box-shadow: 0 2px 4px rgba(0,0,0,0.2);
        touch-action: none;
    }

    input[type="range"]::-moz-range-thumb {
        width: 28px;
        height: 28px;
        background: #78264C;
        border-radius: 50%;
        cursor: pointer;
        border: none;
        box-shadow: 0 2px 4px rgba(0,0,0,0.2);
        touch-action: none;
    }
    
    .percentage-input {
        width: 60px;
        padding: 6px;
        font-size: 1rem;
    }
    
    /* Total percentage indicator */
    .total-percentage,
    .total-display {
        background: #f8f9fa;
        padding: 10px 12px;
        border-radius: 8px;
        margin-top: 12px;
        display: flex;
        justify-content: space-between;
        align-items: center;
        font-weight: 600;
    }
    
    .total-display {
        flex-direction: column;
        text-align: center;
    }
    
    .total-display .total-value {
        font-size: 2rem;
    }
    
    .total-display .total-label {
        font-size: 0.75rem;
    }
    
    .total-percentage .label {
        font-size: 0.85rem;
    }
    
    .total-percentage .value {
        font-size: 1.2rem;
        color: #78264C;
    }
    
    .total-percentage.valid {
        background: #d4edda;
        border: 2px solid #28a745;
    }
    
    .total-percentage.invalid {
        background: #f8d7da;
        border: 2px solid #dc3545;
        color: #dc3545;
    }
}

/* ============================================
   WINEMAKER HINT - COMPACT FOR MOBILE
   ============================================ */

@media (max-width: 768px) {
    .winemaker-hint-toggle {
        background: #f8f9fa;
        padding: 10px 12px;
        border-radius: 8px;
        margin-bottom: 15px;
        border: 1px solid #e0e0e0;
        cursor: pointer;
        transition: all 0.3s;
        display: flex;
        justify-content: space-between;
        align-items: center;
    }
    
    .winemaker-hint-toggle:hover,
    .winemaker-hint-toggle:active {
        background: #e9ecef;
        border-color: #78264C;
    }
    
    .winemaker-hint-toggle h3 {
        font-size: 0.8rem !important;
        margin: 0 !important;
        color: #495057;
        display: flex;
        align-items: center;
        gap: 6px;
        font-weight: 600 !important;
        text-transform: none !important;
        letter-spacing: 0 !important;
    }
    
    .winemaker-hint-toggle h3 i {
        font-size: 0.9rem;
    }
    
    .winemaker-hint-toggle .toggle-icon {
        font-size: 0.9rem;
        color: #78264C;
        transition: transform 0.3s;
    }
    
    .winemaker-hint-toggle.open .toggle-icon {
        transform: rotate(180deg);
    }
    
    .winemaker-hint-content {
        max-height: 0;
        overflow: hidden;
        transition: max-height 0.4s ease-out;
        background: white;
        border: 1px solid #e0e0e0;
        border-top: none;
        border-radius: 0 0 8px 8px;
        margin-top: -8px;
        margin-bottom: 15px;
    }
    
    .winemaker-hint-content.open {
        max-height: 500px;
        padding: 12px;
        border-top: 1px solid #e0e0e0;
    }
    
    .winemaker-hint-content p {
        margin: 0 0 10px 0;
        color: #495057;
        font-size: 0.8rem;
    }
    
    .suggestion-blend-formula {
        display: flex;
        flex-wrap: wrap;
        gap: 6px;
        margin: 10px 0;
        padding: 10px;
        background: #f8f9fa;
        border-radius: 6px;
    }
    
    .suggestion-varietal {
        display: flex;
        align-items: center;
        gap: 6px;
        padding: 5px 10px;
        background: white;
        border-radius: 16px;
        border-left: 3px solid;
        font-size: 0.75rem;
    }
    
    .suggestion-varietal .varietal-name {
        font-weight: 600;
        color: #333;
    }
    
    .suggestion-varietal .varietal-pct {
        font-weight: 700;
        color: #78264C;
    }
    
    .winemaker-hint-content .btn-apply {
        margin-top: 10px;
        background: #78264C;
        color: white;
        border: none;
        padding: 8px 16px;
        border-radius: 16px;
        font-weight: 600;
        cursor: pointer;
        transition: all 0.3s;
        font-size: 0.8rem;
        width: 100%;
    }
    
    .winemaker-hint-content .btn-apply:hover,
    .winemaker-hint-content .btn-apply:active {
        background: #5a1d38;
    }
}

/* ============================================
   BLEND TABS - MOBILE OPTIMIZED
   ============================================ */

@media (max-width: 768px) {
    .blend-tabs {
        display: flex;
        gap: 6px;
        margin: 0 12px 15px 12px;
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 5px;
    }
    
    .tab-btn {
        background: white;
        border: 2px solid #e0e0e0;
        padding: 8px 16px;
        border-radius: 8px;
        font-weight: 600;
        cursor: pointer;
        transition: all 0.3s;
        position: relative;
        white-space: nowrap;
        font-size: 0.8rem;
        flex-shrink: 0;
    }
    
    .tab-btn.active {
        background: #78264C;
        color: white;
        border-color: #78264C;
    }
    
    .tab-btn.finalized {
        background: #46b450;
        color: white;
        border-color: #46b450;
    }
    
    .tab-btn.finalized::after {
        content: '✓';
        position: absolute;
        top: -6px;
        right: -6px;
        background: #2e7d32;
        color: white;
        width: 18px;
        height: 18px;
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 11px;
    }
    
    .add-blend-btn {
        background: #f8f9fa;
        border: 2px dashed #78264C;
        padding: 8px 16px;
        border-radius: 8px;
        font-weight: 600;
        cursor: pointer;
        color: #78264C;
        transition: all 0.3s;
        font-size: 0.8rem;
        flex-shrink: 0;
        display: flex;
        align-items: center;
        gap: 4px;
    }
    
    .add-blend-btn i {
        font-size: 0.8rem;
    }
    
    .add-blend-btn:hover,
    .add-blend-btn:active {
        background: #78264C;
        color: white;
    }
}

/* ============================================
   BLENDING NOTES - MORE PROMINENT
   ============================================ */

@media (max-width: 768px) {
    .notes-section {
        background: linear-gradient(135deg, #fffbf0 0%, #fff8e1 100%);
        border: 2px solid #78264C;
        border-radius: 10px;
        padding: 15px;
        margin-top: 15px;
        box-shadow: 0 4px 15px rgba(120, 38, 76, 0.15);
    }
    
    .notes-section h4 {
        color: #78264C;
        font-size: 0.95rem;
        font-weight: 700;
        margin-bottom: 10px;
        display: flex;
        align-items: center;
        gap: 6px;
    }
    
    .notes-section h4 i {
        font-size: 1rem;
    }
    
    .notes-section textarea {
        width: 100%;
        min-height: 100px;
        padding: 12px;
        border: 2px solid #e0e0e0;
        border-radius: 8px;
        font-size: 0.85rem;
        resize: vertical;
        transition: all 0.3s;
        background: white;
    }
    
    .notes-section textarea:focus {
        border-color: #78264C;
        outline: none;
        box-shadow: 0 0 0 3px rgba(120, 38, 76, 0.1);
    }
    
    .notes-section .notes-helper {
        font-size: 0.75rem;
        color: #666;
        margin-top: 6px;
        font-style: italic;
    }
    
    .notes-section .character-count {
        text-align: right;
        font-size: 0.7rem;
        color: #999;
        margin-top: 4px;
    }
}

/* ============================================
   FLAVOR CHART - MOBILE OPTIMIZED
   ============================================ */

@media (max-width: 768px) {
    .chart-container {
        position: relative;
        height: 250px;
        width: 100%;
        margin: 15px auto;
    }
    
    #flavorChart {
        max-width: 100% !important;
        height: 250px !important;
    }
    
    /* Make flavor profile section more compact */
    .flavor-profile-section {
        margin: 12px 0;
    }
    
    .flavor-profile-section h4 {
        font-size: 0.95rem;
        margin-bottom: 8px;
    }
    
    #customize-flavor-btn {
        font-size: 1.25rem;
        padding: 6px 12px;
        background: #78264C;
        border-radius: 8px;
        color: white;
        border: none;
    }
    
    #flavor-sliders {
        padding: 12px;
        margin-top: 12px;
    }
    
    #flavor-sliders p {
        font-size: 0.8rem;
        margin-bottom: 10px;
    }
    
    #flavor-sliders > div {
        margin-bottom: 12px;
    }
    
    #flavor-sliders label {
        font-size: 0.75rem;
        margin-bottom: 4px;
    }
    
    .flavor-range {
        height: 6px;
    }
    
    .flavor-range::-webkit-slider-thumb {
        width: 18px;
        height: 18px;
    }
    
    .flavor-range::-moz-range-thumb {
        width: 18px;
        height: 18px;
    }
}

/* ============================================
   ACTION BUTTONS - MOBILE OPTIMIZED
   ============================================ */

@media (max-width: 768px) {
    .action-buttons {
        display: flex;
        flex-direction: column;
        gap: 8px;
        margin-top: 15px;
        position: sticky;
        bottom: 0;
        background: white;
        padding: 12px;
        margin-left: -15px;
        margin-right: -15px;
        box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
        z-index: 100;
    }
    
    .action-btn,
    .btn-commit,
    .btn-finalize {
        width: 100%;
        padding: 12px;
        font-size: 0.9rem;
        font-weight: 600;
        border-radius: 8px;
        border: none;
        cursor: pointer;
        transition: all 0.3s;
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 6px;
    }
    
    .btn-primary-action,
    .btn-commit {
        background: #78264C;
        color: white;
    }
    
    .btn-primary-action:hover,
    .btn-primary-action:active,
    .btn-commit:hover,
    .btn-commit:active {
        background: #5a1d38;
    }
    
    .btn-secondary-action {
        background: #f8f9fa;
        color: #333;
        border: 2px solid #dee2e6;
    }
    
    .btn-secondary-action:hover,
    .btn-secondary-action:active {
        background: #e9ecef;
    }
    
    .btn-success-action,
    .btn-finalize {
        background: #28a745;
        color: white;
    }
    
    .btn-success-action:disabled,
    .btn-finalize:disabled {
        background: #c0c0c0;
        cursor: not-allowed;
    }
}

/* ============================================
   BLEND CARDS - MOBILE OPTIMIZED
   ============================================ */

@media (max-width: 768px) {
    .blend-card {
        margin-bottom: 15px;
        border-radius: 12px;
        overflow: hidden;
    }
    
    .blend-card .card-header-custom {
        padding: 15px;
    }
    
    .blend-card .card-header-custom input {
        font-size: 1.2rem;
    }
    
    .blend-card .card-body-custom {
        padding: 15px;
    }
    
    .blend-card-header {
        padding: 12px;
        cursor: pointer;
        display: flex;
        justify-content: space-between;
        align-items: center;
        background: #f8f9fa;
    }
    
    .blend-card-title {
        font-size: 0.9rem;
        font-weight: 600;
        margin: 0;
        flex: 1;
    }
    
    .blend-card-meta {
        font-size: 0.75rem;
        color: #666;
        margin-top: 2px;
    }
    
    .blend-card-actions {
        display: flex;
        gap: 6px;
    }
    
    .blend-card-icon-btn {
        background: white;
        border: 1px solid #dee2e6;
        border-radius: 6px;
        padding: 6px 8px;
        font-size: 0.8rem;
        color: #666;
        cursor: pointer;
    }
    
    .blend-card-body {
        padding: 12px;
        background: white;
        display: none;
    }
    
    .blend-card.expanded .blend-card-body {
        display: block;
    }
    
    .twin-count-box {
        padding: 12px;
        margin: 12px 0;
    }
    
    .twin-count-box h4 {
        font-size: 0.8rem !important;
        margin-bottom: 8px !important;
    }
    
    .twin-count-box .count {
        font-size: 2rem;
    }
}

/* ============================================
   MODAL OPTIMIZATIONS
   ============================================ */

@media (max-width: 768px) {
    .modal-dialog {
        margin: 8px;
        max-width: calc(100% - 16px);
    }
    
    .modal-content {
        border-radius: 12px;
    }
    
    .modal-header {
        padding: 15px;
    }
    
    .modal-header h3 {
        font-size: 1.2rem !important;
    }
    
    .modal-body {
        padding: 15px;
    }
    
    .modal-footer {
        padding: 12px;
        flex-direction: column;
        gap: 8px;
    }
    
    .modal-footer .btn {
        width: 100%;
        margin: 0;
        padding: 10px;
        font-size: 0.9rem;
    }
}

/* ============================================
   FORM OPTIMIZATIONS
   ============================================ */

@media (max-width: 768px) {
    .form-group {
        margin-bottom: 12px;
    }
    
    .form-label {
        font-size: 0.85rem;
        font-weight: 600;
        margin-bottom: 4px;
        display: block;
    }
    
    .form-control {
        font-size: 0.9rem;
        padding: 10px;
        border-radius: 8px;
    }
    
    .form-control:focus {
        border-color: #78264C;
        box-shadow: 0 0 0 3px rgba(120, 38, 76, 0.1);
    }
}

/* ============================================
   UTILITY CLASSES
   ============================================ */

@media (max-width: 768px) {
    .mobile-hidden {
        display: none !important;
    }
    
    .mobile-visible {
        display: block !important;
    }
    
    .mobile-full-width {
        width: 100% !important;
    }
    
    .mobile-text-center {
        text-align: center !important;
    }
    
    .mobile-mt-0 {
        margin-top: 0 !important;
    }
    
    .mobile-mb-0 {
        margin-bottom: 0 !important;
    }
    
    .mobile-p-10 {
        padding: 10px !important;
    }
}

/* ============================================
   ANIMATION FOR SMOOTH INTERACTIONS
   ============================================ */

@media (max-width: 768px) {
    * {
        -webkit-tap-highlight-color: transparent;
    }
    
    button, a, input, textarea {
        touch-action: manipulation;
    }
    
    .zinlab-sticky-nav,
    .action-buttons,
    .blend-card-body {
        transition: all 0.3s ease;
    }
}