/* Dealt - Mobile-First Styles */

/* ==================== MOBILE-FIRST BASE STYLES ==================== */

/* Hide desktop nav - now using unified navigation */
.desktop-nav {
    display: none;
}

/* Desktop footer hidden on mobile */
@media (max-width: 768px) {
    .desktop-footer {
        display: none;
    }
}

/* Keep bottom nav on mobile only */
@media (min-width: 769px) {
    .bottom-nav {
        display: none;
    }
}

/* ==================== MAIN HEADER ==================== */

.main-header {
    background: var(--nav-bg);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--card-border);
    position: sticky;
    top: 0;
    z-index: 100;
    padding: env(safe-area-inset-top) 0 0 0;
}

.main-header .container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    max-width: 1200px;
    margin: 0 auto;
}

.main-logo {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    text-decoration: none;
    font-family: 'Outfit', sans-serif;
}

.main-logo .suit {
    color: var(--accent);
    margin-right: 4px;
}

/* ==================== OFFLINE INDICATOR ==================== */

.offline-indicator {
    background: #ff6b35;
    color: white;
    padding: 8px 16px;
    text-align: center;
    font-size: 13px;
    font-weight: 500;
    border-bottom: 1px solid rgba(0,0,0,0.1);
    animation: slideInDown 0.3s ease;
    position: sticky;
    top: 0;
    z-index: 99;
}

@keyframes slideInDown {
    from {
        transform: translateY(-100%);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* Desktop offline indicator */
@media (min-width: 769px) {
    .offline-indicator {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        z-index: 1050;
    }
}

/* User Menu */
.user-menu {
    position: relative;
}

.user-menu-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 8px;
    padding: 8px 12px;
    color: var(--text-primary);
    cursor: pointer;
    min-height: 44px; /* iOS touch target */
    font-size: 14px;
}

.user-menu-btn:active {
    background: var(--input-bg);
    transform: scale(0.98);
}

.user-display {
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.dropdown-icon {
    transition: transform 0.2s ease;
}

.user-menu-btn.active .dropdown-icon {
    transform: rotate(180deg);
}

.user-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 8px;
    min-width: 140px;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px);
    transition: all 0.2s ease;
    z-index: 1000;
    margin-top: 4px;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.user-dropdown.open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.user-dropdown a {
    display: block;
    padding: 12px 16px;
    color: var(--text-primary);
    text-decoration: none;
    font-size: 14px;
    transition: background-color 0.2s ease;
}

.user-dropdown a:hover,
.user-dropdown a:active {
    background: var(--input-bg);
}

.user-dropdown a:first-child {
    border-radius: 7px 7px 0 0;
}

.user-dropdown a:last-child {
    border-radius: 0 0 7px 7px;
}

/* Auth Links */
.auth-links {
    display: flex;
    gap: 8px;
}

.auth-link {
    padding: 8px 16px;
    background: var(--accent);
    color: var(--bg-primary);
    text-decoration: none;
    border-radius: 6px;
    font-weight: 500;
    min-height: 44px;
    display: flex;
    align-items: center;
    font-size: 14px;
    transition: all 0.2s ease;
}

.auth-link:active {
    transform: scale(0.98);
    background: var(--accent-dark);
}

.auth-link:last-child {
    background: transparent;
    border: 1px solid var(--accent);
    color: var(--accent);
}

/* ==================== BOTTOM NAVIGATION ==================== */

/* Physical spacer to push content above fixed bottom nav — Safari-safe */
.bottom-nav-spacer {
    height: 80px;
    display: none;
}
@media (max-width: 768px) {
    .bottom-nav-spacer {
        display: block;
    }
}

.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--card-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 1px solid var(--card-border);
    display: flex;
    justify-content: space-around;
    align-items: center;
    padding: 8px 0 calc(8px + env(safe-area-inset-bottom));
    z-index: 100;
    box-shadow: 0 -2px 20px rgba(0, 0, 0, 0.1);
}

.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    color: var(--text-muted);
    padding: 8px 4px 4px;
    min-width: 64px;
    min-height: 60px;
    border-radius: 12px;
    transition: all 0.2s ease;
    position: relative;
}

.nav-item:active {
    transform: scale(0.95);
    background: var(--input-bg);
}

.nav-item.active {
    color: var(--accent);
    background: rgba(212, 175, 55, 0.1);
}

.nav-item.active::before {
    content: '';
    position: absolute;
    top: -1px;
    left: 50%;
    transform: translateX(-50%);
    width: 24px;
    height: 3px;
    background: var(--accent);
    border-radius: 0 0 3px 3px;
}

.nav-icon {
    width: 24px;
    height: 24px;
    margin-bottom: 2px;
    flex-shrink: 0;
}

.nav-label {
    font-size: 11px;
    font-weight: 500;
    line-height: 1;
    text-align: center;
}

/* ==================== MOBILE-OPTIMIZED CONTENT ==================== */

/* Add bottom padding to main content to account for bottom nav */
@media (max-width: 768px) {
    main {
        padding-bottom: 20px;
        padding-top: 16px;
    }
    
    .container {
        padding-left: 16px;
        padding-right: 16px;
    }
}

/* ==================== TOUCH-FRIENDLY BUTTONS ==================== */

/* Ensure all interactive elements meet iOS/Android touch target minimums */
@media (max-width: 768px) {
    button,
    .btn,
    input[type="submit"],
    input[type="button"],
    .touch-target {
        min-height: 44px;
        min-width: 44px;
        padding: 12px 20px;
        font-size: 16px; /* Prevents zoom on iOS */
        border-radius: 8px;
    }
    
    /* Make form inputs larger and more touch-friendly */
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="number"],
    select,
    textarea {
        min-height: 48px;
        padding: 12px 16px;
        font-size: 16px; /* Prevents zoom on iOS */
        border-radius: 8px;
        border: 2px solid var(--input-border);
        background: var(--input-bg);
        color: var(--text-primary);
    }
    
    input:focus,
    select:focus,
    textarea:focus {
        border-color: var(--accent);
        outline: none;
        box-shadow: 0 0 0 3px rgba(212, 175, 55, 0.2);
    }
    
    /* Larger checkboxes and radio buttons */
    input[type="checkbox"],
    input[type="radio"] {
        min-width: 20px;
        min-height: 20px;
        transform: scale(1.2);
    }
    
    /* Spacing between touch targets */
    .btn + .btn,
    .touch-target + .touch-target {
        margin-left: 12px;
    }
    
    .btn-group {
        display: flex;
        gap: 12px;
        flex-wrap: wrap;
    }
}

/* ==================== MOBILE SCORECARD IMPROVEMENTS ==================== */

@media (max-width: 768px) {
    /* Larger score input fields */
    .score-input {
        min-height: 60px;
        font-size: 24px;
        font-weight: 600;
        text-align: center;
        border-radius: 12px;
        border: 2px solid var(--input-border);
        background: var(--input-bg);
        color: var(--text-primary);
    }
    
    /* Quick score buttons */
    .quick-score-btn {
        min-height: 48px;
        min-width: 48px;
        background: var(--accent);
        color: var(--bg-primary);
        border: none;
        border-radius: 8px;
        font-weight: 600;
        font-size: 16px;
        margin: 4px;
        transition: all 0.2s ease;
    }
    
    .quick-score-btn:active {
        transform: scale(0.95);
        background: var(--accent-dark);
    }
    
    /* Player cards in scorecard */
    .player-card {
        background: var(--card-bg);
        border: 1px solid var(--card-border);
        border-radius: 12px;
        padding: 16px;
        margin: 8px 0;
        position: relative;
        backdrop-filter: blur(10px);
        -webkit-backdrop-filter: blur(10px);
    }
    
    .player-card.current {
        border-color: var(--accent);
        box-shadow: 0 0 20px rgba(212, 175, 55, 0.3);
    }
    
    .player-name {
        font-size: 18px;
        font-weight: 600;
        color: var(--text-primary);
        margin-bottom: 8px;
    }
    
    .player-score {
        font-size: 32px;
        font-weight: 700;
        color: var(--accent);
        text-align: center;
        margin: 12px 0;
    }
}

/* ==================== RESPONSIVE TABLES ==================== */

@media (max-width: 768px) {
    /* Stack table cells vertically on mobile */
    .responsive-table {
        display: block;
        overflow-x: auto;
        white-space: nowrap;
    }
    
    .responsive-table table {
        width: 100%;
        min-width: 600px; /* Allow horizontal scrolling */
    }
    
    .responsive-table th,
    .responsive-table td {
        padding: 12px 8px;
        min-width: 80px;
    }
    
    /* Card-based layout alternative */
    .card-list {
        display: flex;
        flex-direction: column;
        gap: 12px;
    }
    
    .list-card {
        background: var(--card-bg);
        border: 1px solid var(--card-border);
        border-radius: 12px;
        padding: 16px;
        backdrop-filter: blur(10px);
        -webkit-backdrop-filter: blur(10px);
    }
    
    .list-card h3 {
        margin: 0 0 8px 0;
        color: var(--text-primary);
        font-size: 18px;
        font-weight: 600;
    }
    
    .list-card p {
        margin: 4px 0;
        color: var(--text-secondary);
        font-size: 14px;
    }
    
    .list-card .actions {
        display: flex;
        gap: 8px;
        margin-top: 12px;
        flex-wrap: wrap;
    }
    
    .list-card .btn {
        flex: 1;
        min-width: 80px;
    }
}

/* ==================== IMPROVED EMPTY STATES ==================== */

.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-secondary);
}

.empty-state .icon {
    font-size: 64px;
    margin-bottom: 16px;
    opacity: 0.5;
}

.empty-state h2 {
    color: var(--text-primary);
    margin-bottom: 8px;
    font-size: 24px;
}

.empty-state p {
    margin-bottom: 24px;
    font-size: 16px;
    line-height: 1.5;
}

.empty-state .btn {
    background: var(--accent-gradient);
    color: var(--bg-primary);
    border: none;
    padding: 12px 24px;
    border-radius: 8px;
    font-weight: 600;
    text-decoration: none;
    display: inline-block;
    transition: all 0.2s ease;
}

.empty-state .btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 20px rgba(212, 175, 55, 0.3);
}

/* ==================== LOADING STATES ==================== */

.skeleton {
    background: linear-gradient(90deg, var(--card-bg) 25%, var(--input-bg) 50%, var(--card-bg) 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s infinite;
    border-radius: 4px;
}

@keyframes skeleton-loading {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.skeleton-text {
    height: 1em;
    margin: 0.5em 0;
}

.skeleton-button {
    height: 44px;
    width: 120px;
    border-radius: 8px;
}

.skeleton-card {
    height: 120px;
    margin: 12px 0;
    border-radius: 12px;
}

/* ==================== ANIMATIONS & MICRO-INTERACTIONS ==================== */

/* Smooth page transitions */
.page-transition {
    animation: fadeInUp 0.3s ease-out;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Button press animations */
.btn,
button {
    transition: all 0.2s ease;
    position: relative;
    overflow: hidden;
}

.btn:active,
button:active {
    transform: scale(0.98);
}

/* Success/error feedback */
.flash {
    border-radius: 8px;
    padding: 12px 16px;
    margin: 12px 0;
    animation: slideInFromTop 0.3s ease-out;
}

@keyframes slideInFromTop {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.flash-success {
    background: rgba(40, 167, 69, 0.2);
    border: 1px solid rgba(40, 167, 69, 0.5);
    color: #28a745;
}

.flash-error {
    background: rgba(220, 53, 69, 0.2);
    border: 1px solid rgba(220, 53, 69, 0.5);
    color: #dc3545;
}

.flash-info {
    background: rgba(23, 162, 184, 0.2);
    border: 1px solid rgba(23, 162, 184, 0.5);
    color: #17a2b8;
}

/* Haptic-style feedback for touch interactions */
@media (max-width: 768px) {
    .btn:active,
    button:active,
    .touch-target:active {
        transform: scale(0.95);
    }
}

/* Focus indicators for accessibility */
*:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: 4px;
}

/* ==================== NEW MOBILE NAVIGATION ==================== */

/* Hamburger Button */
.hamburger-btn {
    background: none;
    border: none;
    width: 44px;
    height: 44px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 4px;
    cursor: pointer;
    padding: 0;
}

.hamburger-btn span {
    width: 20px;
    height: 2px;
    background: var(--text-primary);
    transition: all 0.3s ease;
    border-radius: 1px;
}

.hamburger-btn:active span {
    background: var(--accent);
}

/* Main Navigation Drawer */
.main-nav-drawer {
    position: fixed;
    top: 0;
    left: -320px;
    width: 300px;
    height: 100vh;
    background: var(--card-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-right: 1px solid var(--card-border);
    z-index: 1000;
    transition: left 0.3s ease;
}

/* Desktop: wider drawer */
@media (min-width: 769px) {
    .main-nav-drawer {
        left: -380px;
        width: 360px;
    }
}

.main-nav-drawer.open {
    left: 0;
}

.nav-drawer-content {
    height: 100%;
    display: flex;
    flex-direction: column;
    padding-top: env(safe-area-inset-top);
}

.nav-drawer-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--card-border);
}

.drawer-logo {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    text-decoration: none;
    font-family: 'Outfit', sans-serif;
}

.drawer-logo .suit {
    color: var(--accent);
    margin-right: 4px;
}

.close-drawer-btn {
    background: none;
    border: none;
    width: 44px;
    height: 44px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    color: var(--text-secondary);
    border-radius: 8px;
}

.close-drawer-btn:active {
    background: var(--input-bg);
    color: var(--accent);
}

.nav-drawer-links {
    flex: 1;
    padding: 20px 0;
    overflow-y: auto;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px 20px;
    color: var(--text-primary);
    text-decoration: none;
    font-size: 16px;
    font-weight: 500;
    transition: all 0.2s ease;
}

.nav-link:active {
    background: var(--input-bg);
    color: var(--accent);
}

.nav-link .nav-icon {
    width: 24px;
    height: 24px;
    flex-shrink: 0;
}

.nav-divider {
    height: 1px;
    background: var(--card-border);
    margin: 12px 20px;
}

.theme-selector-drawer {
    padding: 16px 20px;
}

.theme-selector-drawer label {
    display: block;
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 8px;
    font-weight: 500;
}

.theme-selector-drawer select {
    width: 100%;
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    color: var(--text-primary);
    padding: 12px;
    border-radius: 8px;
    font-size: 16px;
    appearance: none;
}

/* Main Nav Overlay */
.main-nav-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.main-nav-overlay.open {
    opacity: 1;
    visibility: visible;
}

/* Prevent scrolling when nav is open */
body.nav-open {
    overflow: hidden;
}

/* ==================== CONTEXT-AWARE HEADERS ==================== */

.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
}

.game-header.hidden,
.normal-header.hidden {
    display: none;
}

.back-btn {
    background: none;
    border: none;
    width: 44px;
    height: 44px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    color: var(--text-primary);
    border-radius: 8px;
}

.back-btn:active {
    background: var(--input-bg);
    color: var(--accent);
    transform: scale(0.95);
}

.game-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
    text-align: center;
    margin: 0;
    max-width: 150px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.game-timer-mobile {
    font-size: 14px;
    color: var(--text-secondary);
    font-weight: 500;
    text-align: right;
    min-width: 60px;
}

/* ==================== PULL-TO-REFRESH ==================== */

.pull-to-refresh-container {
    position: absolute;
    top: -100px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    opacity: 0;
    transition: opacity 0.3s ease;
    z-index: 50;
}

.pull-to-refresh-arrow {
    font-size: 20px;
    color: var(--accent);
    transition: transform 0.3s ease;
}

.pull-to-refresh-text {
    font-size: 14px;
    color: var(--text-secondary);
    font-weight: 500;
}

/* ==================== GAME NAVIGATION ==================== */

.game-navigation-indicators {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 12px;
    margin-bottom: 16px;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.game-nav-btn {
    background: var(--accent);
    color: var(--bg-primary);
    border: none;
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.game-nav-btn:active {
    transform: scale(0.95);
    background: var(--accent-dark);
}

.game-nav-btn.prev {
    margin-right: auto;
}

.game-nav-btn.next {
    margin-left: auto;
}

.game-nav-dots {
    display: flex;
    gap: 8px;
    flex: 1;
    justify-content: center;
}

.nav-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-muted);
    transition: all 0.2s ease;
}

.nav-dot.active {
    background: var(--accent);
    transform: scale(1.2);
}

/* ==================== STICKY SCORE ENTRY FORM ==================== */

@media (max-width: 768px) {
    .score-entry-form {
        position: sticky;
        bottom: 0;
        background: var(--card-bg);
        backdrop-filter: blur(20px);
        -webkit-backdrop-filter: blur(20px);
        border-top: 1px solid var(--card-border);
        margin: 0 -16px -16px -16px;
        padding: 16px;
        box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.1);
        z-index: 90;
    }
    
    .scorecard-wrapper {
        margin-bottom: 120px; /* Space for sticky form */
        overflow-x: auto;
    }
    
    /* Hide mobile hint on desktop */
    .mobile-hint {
        display: block;
    }
    
    .desktop-only {
        display: none;
    }
}

@media (min-width: 769px) {
    .mobile-hint {
        display: none;
    }
    
    .desktop-only {
        display: block;
    }
}

/* ==================== TAP-TO-EDIT ==================== */

.editable-row {
    position: relative;
    cursor: pointer;
    transition: background 0.15s ease;
}

.editable-row:hover,
.editable-row:active {
    background: var(--table-row-hover);
}

.editing-row {
    background: rgba(212, 175, 55, 0.08);
}

/* ==================== RESPONSIVE ADJUSTMENTS ==================== */

@media (max-width: 768px) {
    /* Remove bottom padding from main container for sticky form */
    .container {
        padding-bottom: 0;
    }
    
    /* Hide bottom nav on game pages - minimalist approach */
    body.game-page .bottom-nav {
        display: none;
    }
    
    /* Game page specific adjustments */
    .game-actions {
        margin-bottom: 120px; /* Space for sticky form */
    }
    
    /* Better touch targets for mobile */
    .game-nav-btn {
        min-height: 44px;
        min-width: 44px;
    }
    
    /* Make hamburger menu more accessible */
    .hamburger-btn,
    .back-btn,
    .close-drawer-btn {
        min-height: 44px;
        min-width: 44px;
    }
}

/* Extra small screens (320px and below) */
@media (max-width: 320px) {
    .container {
        padding-left: 12px;
        padding-right: 12px;
    }
    
    .main-header .container {
        padding: 8px 12px;
    }
    
    .user-display {
        max-width: 80px;
    }
    
    .nav-label {
        font-size: 10px;
    }
    
    .player-cards {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.5rem;
    }
    
    .player-card {
        padding: 0.75rem;
    }
    
    .player-card .name {
        font-size: 0.8rem;
    }
    
    .scorecard-table th,
    .scorecard-table td {
        padding: 0.25rem;
        font-size: 0.8rem;
    }
    
    .score-entry-form .grid {
        grid-template-columns: 1fr;
        gap: 0.5rem;
    }
}