/* 
 * Mobile-First Responsive CSS for Laghaim Dragon Realms
 * Editor: Claude Code | Created: 2025-01-25 14:45:00 +07 Bangkok
 * Purpose: ปรับปรุงการแสดงผลบนมือถือและ tablet ด้วยหลัก Mobile-first
 */

/* ===== Base Mobile Styles (360px and up) ===== */
:root {
    --primary-color: #667eea;
    --secondary-color: #764ba2;
    --success-color: #10b981;
    --danger-color: #ef4444;
    --warning-color: #f59e0b;
    --touch-target-min: 44px;
    --spacing-mobile: 1rem;
    --spacing-tablet: 1.5rem;
    --spacing-desktop: 2rem;
}

/* Reset และ Base Styles */
* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent; /* ลบ highlight เมื่อ tap บนมือถือ */
}

html {
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%; /* ป้องกัน text resize บน iOS */
}

body {
    min-width: 360px;
    overflow-x: hidden;
    touch-action: manipulation; /* ปรับปรุง touch response */
}

/* Container Responsive */
.container, .container-fluid {
    padding-left: var(--spacing-mobile);
    padding-right: var(--spacing-mobile);
    width: 100%;
}

/* Typography Responsive */
h1, h2, h3, h4, h5, h6 {
    word-wrap: break-word;
    line-height: 1.3;
}

h1 { font-size: clamp(1.75rem, 5vw, 2.5rem); }
h2 { font-size: clamp(1.5rem, 4vw, 2rem); }
h3 { font-size: clamp(1.25rem, 3.5vw, 1.75rem); }
h4 { font-size: clamp(1.125rem, 3vw, 1.5rem); }
h5 { font-size: clamp(1rem, 2.5vw, 1.25rem); }
h6 { font-size: clamp(0.875rem, 2vw, 1rem); }

p, .text-body {
    font-size: clamp(0.875rem, 2vw, 1rem);
    line-height: 1.6;
}

/* Touch-Friendly Buttons */
.btn, button, [type="button"], [type="submit"], [type="reset"] {
    min-height: var(--touch-target-min);
    min-width: var(--touch-target-min);
    padding: 0.75rem 1rem;
    touch-action: manipulation;
    font-size: 1rem;
    border-radius: 0.5rem;
    transition: all 0.2s ease;
}

/* Mobile Navigation */
.navbar {
    padding: 0.5rem var(--spacing-mobile);
}

.navbar-toggler {
    min-width: var(--touch-target-min);
    min-height: var(--touch-target-min);
    border: none;
    padding: 0.5rem;
}

.nav-link {
    padding: 0.75rem 1rem;
    min-height: var(--touch-target-min);
    display: flex;
    align-items: center;
}

/* Mobile-Optimized Forms */
.form-control, .form-select, select, input[type="text"], 
input[type="email"], input[type="password"], input[type="tel"], 
input[type="number"], textarea {
    font-size: 16px; /* ป้องกัน zoom บน iOS */
    padding: 0.75rem;
    min-height: var(--touch-target-min);
    border-radius: 0.5rem;
    width: 100%;
}

.form-group {
    margin-bottom: 1.25rem;
}

label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
}

/* Character Cards for Mobile */
.character-info {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    border-radius: 0.75rem;
    padding: 1rem;
    margin-bottom: 0.75rem;
    color: white;
}

@media (max-width: 767px) {
    .character-info {
        display: flex;
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .character-info > span {
        display: flex;
        justify-content: space-between;
        padding: 0.5rem 0;
        border-bottom: 1px solid rgba(255, 255, 255, 0.2);
    }
    
    .character-info > span:last-child {
        border-bottom: none;
    }
}

/* Tables Responsive */
.table-responsive {
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
    margin: 0 -1rem;
    padding: 0 1rem;
}

@media (max-width: 767px) {
    table {
        font-size: 0.875rem;
    }
    
    .table td, .table th {
        padding: 0.5rem;
    }
}

/* Cards & Modals */
.card {
    border-radius: 1rem;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    margin-bottom: 1rem;
}

.modal-dialog {
    margin: 1rem;
    max-width: calc(100% - 2rem);
}

@media (max-width: 575px) {
    .modal-dialog {
        margin: 0.5rem;
        max-width: calc(100% - 1rem);
    }
    
    .modal-content {
        border-radius: 1rem;
    }
}

/* Popup/Overlay Responsive */
.exchange-popup, .password-popup {
    width: calc(100% - 2rem);
    max-width: 600px;
    max-height: 85vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

@media (max-width: 575px) {
    .exchange-popup, .password-popup {
        width: calc(100% - 1rem);
        max-height: 90vh;
        padding: 1.5rem;
    }
}

/* Stats Grid Mobile */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 0.75rem;
}

@media (max-width: 575px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }
    
    .stat-item {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 0.75rem;
        background: rgba(255, 255, 255, 0.1);
        border-radius: 0.5rem;
    }
}

/* QR Code Display */
.qr-container img {
    max-width: 250px;
    width: 100%;
    height: auto;
}

@media (max-width: 575px) {
    .qr-container img {
        max-width: 200px;
    }
}

/* Button Groups Mobile */
@media (max-width: 767px) {
    .btn-group-mobile {
        display: flex;
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .btn-group-mobile .btn {
        width: 100%;
    }
}

/* ===== Breakpoint: Small Phones (390px+) ===== */
@media (min-width: 390px) {
    .container, .container-fluid {
        padding-left: 1.25rem;
        padding-right: 1.25rem;
    }
}

/* ===== Breakpoint: Tablets (768px+) ===== */
@media (min-width: 768px) {
    .container, .container-fluid {
        padding-left: var(--spacing-tablet);
        padding-right: var(--spacing-tablet);
    }
    
    .character-info {
        flex-direction: row;
        align-items: center;
    }
    
    .character-info > span {
        flex: 1;
        text-align: center;
        border-bottom: none;
    }
    
    .btn-group-mobile {
        flex-direction: row;
    }
    
    .btn-group-mobile .btn {
        width: auto;
    }
    
    .stats-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* ===== Breakpoint: Desktop (1024px+) ===== */
@media (min-width: 1024px) {
    .container {
        max-width: 960px;
    }
    
    .container, .container-fluid {
        padding-left: var(--spacing-desktop);
        padding-right: var(--spacing-desktop);
    }
    
    .modal-dialog {
        max-width: 600px;
        margin: 1.75rem auto;
    }
}

/* ===== Breakpoint: Large Desktop (1280px+) ===== */
@media (min-width: 1280px) {
    .container {
        max-width: 1200px;
    }
}

/* ===== Accessibility Improvements ===== */

/* Focus Styles */
*:focus {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

/* Skip Navigation Link */
.skip-nav {
    position: absolute;
    top: -40px;
    left: 0;
    background: var(--primary-color);
    color: white;
    padding: 0.5rem 1rem;
    text-decoration: none;
    border-radius: 0 0 0.5rem 0;
    z-index: 100;
}

.skip-nav:focus {
    top: 0;
}

/* High Contrast Mode Support */
@media (prefers-contrast: high) {
    .btn, .card {
        border: 2px solid currentColor;
    }
}

/* Reduced Motion Support */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* Dark Mode Support (Optional) */
@media (prefers-color-scheme: dark) {
    :root {
        --bg-color: #1a1a1a;
        --text-color: #e5e5e5;
    }
    
    body {
        background-color: var(--bg-color);
        color: var(--text-color);
    }
    
    .card, .modal-content {
        background-color: #2a2a2a;
        color: var(--text-color);
    }
}

/* ===== Utility Classes ===== */

/* Spacing Utilities */
.mt-mobile { margin-top: var(--spacing-mobile); }
.mb-mobile { margin-bottom: var(--spacing-mobile); }
.pt-mobile { padding-top: var(--spacing-mobile); }
.pb-mobile { padding-bottom: var(--spacing-mobile); }

/* Text Utilities */
.text-wrap { word-wrap: break-word; overflow-wrap: break-word; }
.text-truncate-mobile { 
    white-space: nowrap; 
    overflow: hidden; 
    text-overflow: ellipsis; 
    max-width: 100%;
}

/* Display Utilities */
.hide-mobile { display: none !important; }
.show-mobile { display: block !important; }

@media (min-width: 768px) {
    .hide-mobile { display: block !important; }
    .show-mobile { display: none !important; }
}

/* Safe Area Insets (for notched devices) */
.safe-area-inset {
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
}

.safe-area-inset-top {
    padding-top: env(safe-area-inset-top);
}

.safe-area-inset-bottom {
    padding-bottom: env(safe-area-inset-bottom);
}

/* Loading States */
.skeleton {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: loading 1.5s infinite;
}

@keyframes loading {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* Print Styles */
@media print {
    .no-print, .navbar, .btn, button {
        display: none !important;
    }
    
    body {
        font-size: 12pt;
    }
}