/* ============================================
   TribIsle MMORPG - Mobile Optimizations
   ============================================
   Target: Devices <= 768px width
   Strategy: CSS-only, preserves desktop experience
   ============================================ */

/* ============================================
   1. GLOBAL MOBILE FIXES
   ============================================ */
@media (max-width: 768px) {
    /* Prevent horizontal scroll */
    body {
        overflow-x: hidden;
    }

    /* Responsive images */
    img {
        max-width: 100%;
        height: auto;
    }

    /* Better button spacing */
    .btn + .btn {
        margin-top: 0.5rem;
    }

    /* Readable text */
    body {
        font-size: 16px;
        line-height: 1.5;
    }

    /* Stack Bootstrap columns */
    .row > [class*='col-'] {
        margin-bottom: 1rem;
    }

    /* Reduce container padding */
    .container-fluid {
        padding-left: 0.5rem;
        padding-right: 0.5rem;
    }

    /* Content padding adjustment */
    .content {
        padding-left: 0.5rem !important;
        padding-right: 0.5rem !important;
    }
}

/* ============================================
   2. GAME PAGE OPTIMIZATIONS
   ============================================ */
@media (max-width: 768px) {
    /* Stack game columns vertically */
    .game-container .row > .col-lg-8,
    .game-container .row > .col-lg-4 {
        width: 100%;
        margin-bottom: 1rem;
    }

    /* Compact player stats */
    .game-container .card-body .row > .col-md-6 {
        width: 100%;
        margin-bottom: 0.75rem;
    }

    /* Make progress bars more prominent */
    .progress {
        height: 30px !important;
        font-size: 0.9rem;
        font-weight: 600;
    }

    /* Touch-friendly buttons */
    .game-container .btn {
        min-height: 44px;
        font-size: 1rem;
        padding: 0.5rem 1rem;
        width: 100%;
        margin-bottom: 0.5rem;
    }

    /* Reduce card padding */
    .game-container .card-body {
        padding: 0.75rem;
    }

    .game-container .card-header {
        padding: 0.75rem;
    }

    /* Location images - mobile optimized */
    .location-image-small {
        max-width: 50px;
        height: auto;
    }

    /* Combat log - scrollable with max height */
    .combat-log {
        max-height: 200px;
        overflow-y: auto;
        font-size: 0.85rem;
        padding: 0.5rem;
    }

    /* Inventory grid - 2 columns instead of 4 */
    .inventory-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 0.5rem;
    }

    /* Compact stat displays */
    .game-container .badge {
        font-size: 0.85rem;
        padding: 0.35em 0.65em;
    }

    /* Action buttons grid */
    .action-buttons {
        display: grid;
        grid-template-columns: 1fr;
        gap: 0.5rem;
    }
}

/* ============================================
   3. CHARACTER SELECT OPTIMIZATIONS
   ============================================ */
@media (max-width: 768px) {
    /* Full-width character cards on mobile */
    .character-select .col-md-6,
    .character-select .col-lg-4 {
        width: 100%;
    }

    .character-card {
        margin-bottom: 1rem;
    }

    /* Larger touch targets */
    .character-card-footer .btn {
        min-height: 50px;
        font-size: 1.1rem;
    }

    /* Stack character stats vertically */
    .character-stats {
        flex-direction: column;
        gap: 0.5rem;
    }

    /* Larger avatars for easier selection */
    .character-avatar {
        width: 100px;
        height: 100px;
    }

    /* Create new character card */
    .create-new .create-icon {
        font-size: 3rem;
    }

    /* Character select container */
    .character-select {
        padding: 1rem 0.5rem;
    }
}

/* ============================================
   4. ADMIN TABLES - MOBILE FRIENDLY
   ============================================ */
@media (max-width: 768px) {
    /* Make admin tables scrollable by default */
    .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        display: block;
        width: 100%;
    }

    /* Card-style table rows for mobile */
    .table-mobile {
        display: block;
        border: none;
    }

    .table-mobile thead {
        display: none;
    }

    .table-mobile tbody {
        display: block;
    }

    .table-mobile tr {
        display: block;
        margin-bottom: 1rem;
        border: 1px solid #dee2e6;
        border-radius: 0.5rem;
        padding: 0.75rem;
        background: white;
        box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    }

    .table-mobile td {
        display: block;
        width: 100%;
        text-align: left !important;
        padding: 0.5rem 0;
        border: none;
    }

    .table-mobile td:before {
        content: attr(data-label);
        font-weight: bold;
        display: block;
        margin-bottom: 0.25rem;
        color: #6c757d;
        font-size: 0.85rem;
        text-transform: uppercase;
    }

    /* Action buttons full-width */
    .table-mobile .btn {
        width: 100%;
        margin-bottom: 0.5rem;
    }

    .table-mobile .btn-group {
        display: flex;
        flex-direction: column;
        width: 100%;
    }

    .table-mobile .btn-group .btn {
        border-radius: 0.25rem !important;
        margin-bottom: 0.5rem;
    }

    /* Image thumbnails smaller */
    .table-mobile img {
        max-width: 100%;
        height: auto;
        margin-bottom: 0.5rem;
    }

    /* Badges stack */
    .table-mobile .badge {
        display: inline-block;
        margin: 0.25rem 0.25rem 0.25rem 0;
    }
}

/* ============================================
   5. NAVIGATION IMPROVEMENTS
   ============================================ */
@media (max-width: 640px) {
    /* Larger touch targets */
    .nav-item ::deep .nav-link {
        height: 3.5rem;
        font-size: 1rem;
        padding: 0 1rem;
    }

    /* Sticky header on mobile */
    .top-row {
        position: sticky;
        top: 0;
        z-index: 1000;
        background-color: rgba(5, 39, 103, 0.95);
        backdrop-filter: blur(10px);
    }

    /* Scrollable menu */
    .nav-scrollable {
        max-height: calc(100vh - 3.5rem);
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Better section spacing */
    .nav-item.px-3 {
        padding-left: 1rem !important;
        padding-right: 1rem !important;
    }

    /* Admin section styling */
    .nav-item .text-warning {
        font-size: 0.9rem;
    }
}

/* ============================================
   6. FORMS & INPUTS
   ============================================ */
@media (max-width: 768px) {
    /* Larger form inputs for touch */
    .form-control,
    .form-select,
    textarea.form-control {
        min-height: 44px;
        font-size: 16px; /* Prevents zoom on iOS */
        padding: 0.75rem;
    }

    textarea.form-control {
        min-height: 100px;
    }

    /* Labels more prominent */
    label {
        font-weight: 600;
        margin-bottom: 0.5rem;
        display: block;
    }

    /* Full-width buttons in forms */
    .form-group .btn,
    form .btn {
        width: 100%;
        margin-bottom: 0.5rem;
        min-height: 44px;
    }

    /* Stack form rows */
    .row > .col-md-6,
    .row > .col-md-4,
    .row > .col-md-3 {
        width: 100%;
        margin-bottom: 1rem;
    }

    /* Modal adjustments */
    .modal-dialog {
        margin: 0.5rem;
        max-width: calc(100% - 1rem);
    }

    .modal-body {
        padding: 1rem;
    }

    .modal-header {
        padding: 1rem;
    }

    .modal-footer {
        padding: 0.75rem;
        flex-direction: column;
    }

    .modal-footer .btn {
        width: 100%;
        margin: 0.25rem 0;
    }

    /* File upload larger */
    input[type="file"] {
        min-height: 50px;
        padding: 0.75rem;
        font-size: 16px;
    }

    /* Checkboxes and radios */
    .form-check-input {
        width: 1.5rem;
        height: 1.5rem;
        margin-top: 0.25rem;
    }

    .form-check-label {
        padding-left: 0.5rem;
        font-size: 1rem;
    }
}

/* ============================================
   7. CARDS & PANELS
   ============================================ */
@media (max-width: 768px) {
    .card {
        margin-bottom: 1rem;
    }

    .card-body {
        padding: 1rem;
    }

    .card-header {
        padding: 0.75rem 1rem;
    }

    .card-footer {
        padding: 0.75rem 1rem;
    }

    /* Alert boxes */
    .alert {
        padding: 0.75rem 1rem;
        font-size: 0.9rem;
    }

    /* Badge sizing */
    .badge {
        font-size: 0.85rem;
        padding: 0.35em 0.65em;
    }
}

/* ============================================
   8. UTILITY CLASSES
   ============================================ */
.mobile-only {
    display: none;
}

.desktop-only {
    display: block;
}

@media (max-width: 768px) {
    .mobile-only {
        display: block !important;
    }

    .desktop-only {
        display: none !important;
    }

    /* Mobile-friendly spacing */
    .mobile-stack > * {
        margin-bottom: 1rem;
    }

    /* Touch-friendly spacing */
    .mobile-touch-spacing {
        padding: 1rem 0.5rem;
    }

    /* Scrollable horizontal containers */
    .mobile-scroll-x {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        white-space: nowrap;
    }

    /* Full-width utility */
    .mobile-full-width {
        width: 100% !important;
    }

    /* Hide on mobile */
    .mobile-hidden {
        display: none !important;
    }

    /* Text alignment */
    .mobile-text-center {
        text-align: center !important;
    }

    /* Spacing utilities */
    .mobile-mb-2 {
        margin-bottom: 0.5rem !important;
    }

    .mobile-mb-3 {
        margin-bottom: 1rem !important;
    }

    .mobile-p-2 {
        padding: 0.5rem !important;
    }

    .mobile-p-3 {
        padding: 1rem !important;
    }
}

/* ============================================
   9. PLAYER HUB / HOME
   ============================================ */
@media (max-width: 768px) {
    /* Stack stat cards */
    .player-hub .row > div {
        width: 100%;
        margin-bottom: 1rem;
    }

    /* Stat cards compact */
    .stat-card {
        padding: 1rem;
        margin-bottom: 1rem;
    }

    .stat-card h3 {
        font-size: 1.25rem;
    }

    /* Player info compact */
    .player-info-card {
        padding: 1rem;
    }
}

/* ============================================
   10. AUTH PAGES (Login/Register)
   ============================================ */
@media (max-width: 768px) {
    /* Full-width auth cards */
    .auth-card,
    .login-card,
    .register-card {
        margin: 1rem;
        max-width: 100%;
    }

    /* Auth buttons */
    .auth-buttons .btn {
        width: 100%;
        margin-bottom: 0.5rem;
    }

    /* Social login buttons */
    .social-login .btn {
        width: 100%;
        margin-bottom: 0.5rem;
    }
}

/* ============================================
   11. IMAGE GALLERY / LOCATION IMAGES
   ============================================ */
@media (max-width: 768px) {
    /* Location image previews */
    .location-image-preview {
        max-width: 100%;
        height: auto;
        margin-bottom: 1rem;
    }

    /* Image upload preview */
    .image-upload-preview img {
        max-width: 100%;
        height: auto;
    }

    /* Gallery grid */
    .image-gallery {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 0.5rem;
    }
}

/* ============================================
   12. SPINNER / LOADING STATES
   ============================================ */
@media (max-width: 768px) {
    .spinner-border {
        width: 2rem;
        height: 2rem;
    }

    .spinner-border-sm {
        width: 1rem;
        height: 1rem;
    }

    /* Loading overlay */
    .loading-overlay {
        font-size: 1rem;
    }
}

/* ============================================
   13. TOAST / NOTIFICATIONS
   ============================================ */
@media (max-width: 768px) {
    .toast {
        width: calc(100% - 1rem);
        margin: 0.5rem;
    }

    .toast-container {
        right: 0.5rem;
        left: 0.5rem;
    }
}

/* ============================================
   14. QUEST DISPLAY
   ============================================ */
@media (max-width: 768px) {
    /* Quest cards full width */
    .quest-card {
        width: 100%;
        margin-bottom: 1rem;
    }

    /* Quest details */
    .quest-details {
        padding: 1rem;
    }

    /* Quest objectives */
    .quest-objectives {
        font-size: 0.9rem;
    }

    /* Reward badges */
    .quest-rewards .badge {
        display: block;
        margin-bottom: 0.5rem;
        width: 100%;
    }
}

/* ============================================
   15. NPC / ENEMY DISPLAY
   ============================================ */
@media (max-width: 768px) {
    /* Enemy cards */
    .enemy-card {
        margin-bottom: 1rem;
        padding: 1rem;
    }

    /* Enemy stats */
    .enemy-stats {
        font-size: 0.9rem;
    }

    /* NPC dialogue */
    .npc-dialogue {
        padding: 1rem;
        font-size: 0.95rem;
    }
}

/* ============================================
   16. PERFORMANCE OPTIMIZATIONS
   ============================================ */
@media (max-width: 768px) {
    /* Reduce animations on mobile */
    * {
        transition-duration: 0.15s !important;
    }

    /* Disable hover effects on touch devices */
    @media (hover: none) {
        .btn:hover,
        .nav-link:hover,
        .card:hover {
            transform: none;
        }
    }
}

/* ============================================
   17. ACCESSIBILITY
   ============================================ */
@media (max-width: 768px) {
    /* Focus states more visible on mobile */
    *:focus {
        outline: 2px solid #1b6ec2;
        outline-offset: 2px;
    }

    /* Skip link for mobile */
    .skip-link {
        position: absolute;
        top: -40px;
        left: 0;
        background: #000;
        color: white;
        padding: 8px;
        z-index: 100;
    }

    .skip-link:focus {
        top: 0;
    }
}

/* ============================================
   18. PRINT STYLES (Mobile)
   ============================================ */
@media print {
    .sidebar,
    .nav-menu,
    .btn,
    .navbar-toggler {
        display: none !important;
    }

    main {
        width: 100%;
    }
}

/* ============================================
   MOBILE GAME OPTIMIZATIONS  
   ============================================ */

/* Mobile Quest Menu (Offcanvas) */
.mobile-quest-toggle {
    position: fixed;
    top: 70px;
    right: 1rem;
    z-index: 1050;
    box-shadow: 0 4px 12px rgba(255, 193, 7, 0.5);
}

.offcanvas {
    position: fixed !important;
    top: 0 !important;
    right: -100%;
    width: 80%;
    max-width: 320px;
    height: 100%;
    background: white;
    box-shadow: -4px 0 12px rgba(0, 0, 0, 0.3);
    z-index: 1055;
    transition: right 0.3s ease;
}

.offcanvas.show {
    right: 0;
}

.offcanvas-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1054;
}

.offcanvas-header {
    padding: 1rem;
    border-bottom: 1px solid #dee2e6;
}

.offcanvas-body {
    padding: 1rem;
    overflow-y: auto;
}

/* Mobile Player Stats - Compact */
.mobile-player-stats .card {
    background: rgba(255, 255, 255, 0.95);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.mobile-player-stats .card-body {
    padding: 0.75rem;
}

/* Mobile Enemy Display */
.mobile-enemy-display .card {
    background: rgba(255, 245, 245, 0.95);
    animation: enemyPulse 1s ease-in-out;
}

@keyframes enemyPulse {
    0% {
        transform: scale(0.95);
        opacity: 0.8;
    }
    50% {
        transform: scale(1.02);
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

.mobile-enemy-image {
    width: 50px;
    height: 50px;
    object-fit: cover;
    border-radius: 8px;
    border: 2px solid #dc3545;
}

/* Mobile Actions Body */
@media (max-width: 991.98px) {
    .mobile-actions-body {
        padding: 0.75rem;
    }
    
    .mobile-roll-button {
        padding: 1rem;
        font-size: 1.5rem;
        font-weight: bold;
        box-shadow: 0 6px 16px rgba(40, 167, 69, 0.5);
    }
    
    .mobile-roll-button:active {
        transform: scale(0.95);
    }
    
    /* Compact D-Pad for Mobile */
    .mobile-dpad-container {
        padding: 0.5rem 0;
    }
    
    .mobile-dpad-grid {
        grid-template-columns: repeat(3, 50px);
        grid-template-rows: repeat(3, 50px);
        gap: 2px;
    }
    
    .mobile-dpad-grid .dpad-button {
        width: 50px;
        height: 50px;
        font-size: 1.25rem;
    }
    
    .mobile-dpad-grid .dpad-center {
        width: 50px;
        height: 50px;
    }
    
    .mobile-dpad-grid .dpad-empty {
        width: 50px;
        height: 50px;
    }
    
    /* Hide full game log on mobile */
    .desktop-game-log {
        display: none !important;
    }
    
    /* Mobile game container padding */
    .game-container {
        padding: 0.5rem !important;
    }
    
    /* Sticky actions at top on mobile */
    .sticky-top {
        position: sticky;
        top: 60px;
        z-index: 1020;
    }
}

/* Mobile Quest Tracker Items */
.quest-tracker-item {
    background: white;
    border-radius: 8px;
    transition: all 0.2s ease;
}

.quest-tracker-item:hover {
    transform: translateX(5px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

/* Mobile-specific button sizing */
@media (max-width: 991.98px) {
    .btn-sm {
        padding: 0.5rem;
        font-size: 0.875rem;
    }
    
    /* Ensure text doesn't wrap in compact buttons */
    .mobile-actions-body .btn {
        white-space: nowrap;
    }
}

/* Mobile game notifications positioning */
@media (max-width: 991.98px) {
    .item-notification {
        top: 70px;
        right: 10px;
        max-width: calc(100% - 20px);
    }
    
    .quest-notification {
        top: 70px;
        left: 10px;
        max-width: calc(100% - 20px);
    }
}

/* ============================================
   MOBILE GAME OPTIMIZATIONS (Game.razor)
   Target: Actual mobile devices only
   Hide on: width < 1680px (mobile + tablets)
   ============================================ */

/* Hide Quest Log on mobile/tablet - show only on large desktop */
@media (max-width: 1679px) {
    /* Hide desktop quest panel */
    .card .card-header:has(h6:contains("Active Quests")) {
        display: none !important;
    }
    
    /* Alternative: Target by class if added */
    .desktop-quest-panel {
        display: none !important;
    }
    
    /* Hide game log on mobile */
    .game-log-container {
        display: none !important;
    }
}

/* Mobile Game Layout Optimizations */
@media (max-width: 768px) {
    /* Reduce game container padding */
    .game-container {
        padding: 0.5rem !important;
    }
    
    /* Make ROLL button more prominent on mobile */
    .roll-button {
        font-size: 1.75rem !important;
        padding: 1.25rem !important;
        margin-bottom: 1rem !important;
        box-shadow: 0 6px 20px rgba(40, 167, 69, 0.6) !important;
    }
    
    /* Compact player stats card */
    .card.mb-3 .card-header {
        padding: 0.5rem 1rem;
        font-size: 0.9rem;
    }
    
    .card.mb-3 .card-body {
        padding: 0.75rem;
    }
    
    /* Compact enemy display */
    .card.border-danger .card-body {
        padding: 0.75rem;
    }
    
    /* Center D-Pad on mobile */
    .dpad-container {
        display: flex;
        justify-content: center;
        align-items: center;
        padding: 0.5rem 0;
    }
    
    /* Compact D-Pad on mobile */
    .dpad-grid {
        grid-template-columns: repeat(3, 50px) !important;
        grid-template-rows: repeat(3, 50px) !important;
        gap: 3px !important;
    }
    
    .dpad-button {
        width: 50px !important;
        height: 50px !important;
        font-size: 1.25rem !important;
    }
    
    .dpad-center {
        width: 50px !important;
        height: 50px !important;
    }
    
    .dpad-empty {
        width: 50px !important;
        height: 50px !important;
    }
    
    /* Reduce movement section padding */
    .movement-section {
        padding: 0.5rem;
        margin-bottom: 0.75rem !important;
    }
    
    /* Compact action buttons */
    .card-body .d-grid.gap-2 {
        gap: 0.5rem !important;
    }
    
    /* Enemy image optimization */
    .enemy-image-large {
        max-height: 150px !important;
    }
    
    .enemy-image-container {
        padding: 0.5rem !important;
        margin-bottom: 0.75rem !important;
    }
    
    /* Reduce card margins */
    .card.mb-3 {
        margin-bottom: 0.75rem !important;
    }
    
    /* Sticky positioning for actions panel */
    .sticky-top {
        position: sticky;
        top: 60px;
        z-index: 1020;
    }
    
    /* Mobile action buttons spacing */
    .mobile-actions-body .row.g-2 {
        row-gap: 0.5rem !important;
    }
    
    /* Mobile action buttons font size */
    .mobile-actions-body .btn-sm {
        font-size: 0.8rem;
        padding: 0.5rem 0.25rem;
    }
}

/* Ensure quest and game logs show on desktop */
@media (min-width: 1680px) {
    .desktop-quest-panel {
        display: block !important;
    }
    
    .game-log-container {
        display: block !important;
    }
}
