/* Reset và Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    overflow-x: hidden;
}

/* Navbar Styles */
.navbar {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
    padding: 8px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 1000;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
}

.logo img {
    max-height: 45px;
    width: auto;
    transition: all 0.3s ease;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.1));
}

.nav-center {
    flex: 1;
    max-width: 400px;
    margin: 0 20px;
}

.search-container {
    position: relative;
}

#nav-search {
    width: 100%;
    padding: 12px 20px 12px 45px;
    border: none;
    border-radius: 25px;
    background: rgba(255, 255, 255, 0.9);
    box-shadow: inset 0 2px 10px rgba(0, 0, 0, 0.1);
    font-size: 14px;
    transition: all 0.3s ease;
    outline: none;
}

#nav-search:focus {
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.3);
    background: white;
}

#nav-search::placeholder {
    color: #999;
}

.search-container::before {
    content: "\f002";
    font-family: "Font Awesome 5 Free";
    font-weight: 900;
    position: absolute;
    left: 16px;
    top: 50%;
    transform: translateY(-50%);
    color: #999;
    z-index: 1;
}

.suggestions {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: white;
    border-radius: 15px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    max-height: 200px;
    overflow-y: auto;
    z-index: 1001;
    display: none;
}

.nav-right {
    display: flex;
    gap: 10px;
}

.nav-button {
    padding: 10px 20px;
    border: none;
    border-radius: 20px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 14px;
}

.nav-button.secondary {
    background: transparent;
    color: #667eea;
    border: 2px solid #667eea;
}

.nav-button.secondary:hover {
    background: #667eea;
    color: white;
    transform: translateY(-2px);
}

.nav-button.primary {
    background: linear-gradient(45deg, #667eea, #764ba2);
    color: white;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
}

.nav-button.primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.6);
}

/* Paint Container */
.paint-container {
    display: flex;
    height: calc(100vh - 80px);
    gap: 20px;
    padding: 20px;
}

/* Toolbar Styles */
.toolbar {
    width: 280px;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px);
    border-radius: 20px;
    padding: 25px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.1);
    overflow-y: auto;
    height: fit-content;
}

.toolbar h2 {
    color: #333;
    margin-bottom: 20px;
    font-size: 20px;
    font-weight: 700;
    text-align: center;
    background: linear-gradient(45deg, #667eea, #764ba2);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* Color Palette */
.color-palette {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin-bottom: 25px;
}

.color-btn {
    width: 40px;
    height: 40px;
    border: 3px solid white;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.2);
    position: relative;
}

.color-btn::before {
    content: '';
    position: absolute;
    top: -3px;
    left: -3px;
    right: -3px;
    bottom: -3px;
    border-radius: 50%;
    background: linear-gradient(45deg, transparent, transparent);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.color-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.3);
}

.color-btn.active {
    transform: scale(1.1);
    box-shadow: 0 0 0 4px rgba(102, 126, 234, 0.5);
}

/* Brush Controls */
.brush-controls h3 {
    color: #333;
    margin-bottom: 15px;
    font-size: 16px;
    font-weight: 600;
}

.brush-types {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 20px;
}

.brush-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    border: 2px solid #e0e0e0;
    border-radius: 15px;
    background: white;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 500;
}

.brush-btn:hover {
    border-color: #667eea;
    background: rgba(102, 126, 234, 0.05);
    transform: translateY(-2px);
}

.brush-btn.active {
    border-color: #667eea;
    background: linear-gradient(45deg, #667eea, #764ba2);
    color: white;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
}

.brush-size, .brush-opacity {
    margin-bottom: 20px;
}

.brush-size label, .brush-opacity label {
    display: block;
    color: #555;
    margin-bottom: 8px;
    font-weight: 500;
}

.brush-size input, .brush-opacity input {
    width: 100%;
    margin-bottom: 5px;
    accent-color: #667eea;
}

.brush-size span, .brush-opacity span {
    color: #667eea;
    font-weight: 600;
    font-size: 14px;
}

/* Tools */
.tools {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.tool-group {
    display: flex;
    gap: 8px;
    justify-content: center;
}

.tool-btn {
    width: 45px;
    height: 45px;
    border: none;
    border-radius: 12px;
    background: linear-gradient(45deg, #667eea, #764ba2);
    color: white;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
}

.tool-btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.5);
}

.tool-btn:active {
    transform: translateY(-1px);
}

.zoom-control {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 15px;
    background: rgba(255, 255, 255, 0.8);
    border-radius: 15px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.zoom-control i {
    color: #667eea;
}

.zoom-control input {
    flex: 1;
    accent-color: #667eea;
}

.zoom-control span {
    color: #667eea;
    font-weight: 600;
    font-size: 12px;
    min-width: 40px;
}

/* Canvas Container */
.canvas-container {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px);
    border-radius: 20px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.1);
    padding: 30px;
    position: relative;
    overflow: hidden;
    min-height: 500px;
    width: 100%;
}

.canvas-container::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: 
        radial-gradient(circle at 20% 50%, rgba(102, 126, 234, 0.05) 0%, transparent 50%),
        radial-gradient(circle at 80% 20%, rgba(118, 75, 162, 0.05) 0%, transparent 50%),
        radial-gradient(circle at 40% 80%, rgba(102, 126, 234, 0.05) 0%, transparent 50%);
    pointer-events: none;
}

#paint-canvas {
    background: white;
    border-radius: 15px;
    box-shadow: 0 5px 25px rgba(0, 0, 0, 0.1);
    cursor: crosshair;
    position: relative;
    z-index: 1;
    width: 100% !important;
    height: 100% !important;
    max-width: 100%;
    max-height: 100%;
    display: block;
    margin: 0 auto;
    object-fit: contain;
    
    /* Ultra anti-aliasing cho smooth lines */
    image-rendering: -webkit-optimize-contrast;
    image-rendering: -moz-crisp-edges;
    image-rendering: crisp-edges;
    image-rendering: pixelated;
    image-rendering: auto;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
    
    /* Subpixel rendering precision */
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    -webkit-perspective: 1000px;
    perspective: 1000px;
    -webkit-transform-style: preserve-3d;
    transform-style: preserve-3d;
    
    /* Hardware acceleration tối đa */
    transform: translateZ(0) scale(1);
    -webkit-transform: translateZ(0) scale(1);
    will-change: transform, contents;
    
    /* Touch và drawing optimizations */
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    
    /* Anti-aliasing */
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    body {
        background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        background-attachment: fixed;
    }
    
    .navbar {
        flex-direction: column;
        gap: 12px;
        padding: 12px 16px;
        background: rgba(255, 255, 255, 0.98);
        border-radius: 0 0 20px 20px;
        margin: 0;
    }
    
    .logo {
        text-align: center;
    }
    
    .logo img {
        max-height: 40px;
    }
    
    .nav-center {
        order: 2;
        max-width: none;
        margin: 0;
        width: 100%;
    }
    
    #nav-search {
        padding: 14px 20px 14px 45px;
        font-size: 16px; /* Prevents zoom on iOS */
        border-radius: 20px;
        background: rgba(255, 255, 255, 0.95);
        box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    }
    
    .nav-right {
        order: 3;
        justify-content: center;
        width: 100%;
        gap: 12px;
    }
    
    .nav-button {
        flex: 1;
        max-width: 140px;
        padding: 12px 16px;
        font-size: 13px;
        border-radius: 18px;
    }
    
    .paint-container {
        flex-direction: column;
        height: auto;
        min-height: calc(100vh - 120px);
        padding: 10px;
        gap: 12px;
        margin: 0;
        width: 100%;
    }
    
    .paint-container {
        flex-direction: column;
        height: auto;
        min-height: calc(100vh - 140px);
        padding: 16px;
        gap: 16px;
    }
    
    .toolbar {
        width: 100%;
        order: 2;
        padding: 20px;
        border-radius: 18px;
        background: rgba(255, 255, 255, 0.98);
        backdrop-filter: blur(25px);
        box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
    }
    
    .toolbar h2 {
        font-size: 18px;
        margin-bottom: 16px;
        text-align: center;
    }
    
    .color-palette {
        grid-template-columns: repeat(8, 1fr);
        gap: 8px;
        margin-bottom: 20px;
        padding: 8px;
        background: rgba(255, 255, 255, 0.5);
        border-radius: 12px;
    }
    
    .color-btn {
        width: 32px;
        height: 32px;
        border: 2px solid white;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    }
    
    .color-btn:hover, .color-btn:active {
        transform: scale(1.15);
        box-shadow: 0 4px 15px rgba(0, 0, 0, 0.25);
    }
    
    .brush-types {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        gap: 10px;
        margin-bottom: 20px;
    }
    
    .brush-btn {
        padding: 14px 12px;
        font-size: 13px;
        border-radius: 12px;
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 6px;
        min-height: 65px;
        border: 2px solid rgba(102, 126, 234, 0.2);
        background: rgba(255, 255, 255, 0.9);
        transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }
    
    .brush-btn:hover {
        background: rgba(102, 126, 234, 0.1);
        border-color: rgba(102, 126, 234, 0.4);
        transform: translateY(-2px);
    }
    
    .brush-btn.active {
        background: linear-gradient(135deg, #667eea, #764ba2);
        color: white;
        border-color: transparent;
        box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
        transform: translateY(-1px);
    }
    
    .brush-btn i {
        font-size: 18px;
    }
    
    .brush-size, .brush-opacity {
        margin-bottom: 18px;
        padding: 12px;
        background: rgba(255, 255, 255, 0.6);
        border-radius: 10px;
    }
    
    .brush-size label, .brush-opacity label {
        font-weight: 600;
        color: #444;
        margin-bottom: 10px;
        display: block;
    }
    
    .brush-size input, .brush-opacity input {
        width: 100%;
        height: 8px;
        background: linear-gradient(90deg, #667eea, #764ba2);
        border-radius: 4px;
        outline: none;
        margin-bottom: 8px;
    }
    
    .tool-group {
        justify-content: space-around;
        margin-bottom: 12px;
    }
    
    .tool-btn {
        width: 48px;
        height: 48px;
        font-size: 18px;
        border-radius: 14px;
        background: linear-gradient(135deg, #667eea, #764ba2);
        box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
        transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }
    
    .tool-btn:hover {
        transform: translateY(-3px) scale(1.05);
        box-shadow: 0 8px 25px rgba(102, 126, 234, 0.4);
    }
    
    .tool-btn:active {
        transform: translateY(-1px) scale(1.02);
    }
    
    .canvas-container {
        order: 1;
        min-height: 75vh;
        max-height: 80vh;
        padding: 8px;
        border-radius: 18px;
        background: rgba(255, 255, 255, 0.98);
        backdrop-filter: blur(25px);
        box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
        position: relative;
        overflow: hidden;
        width: 100%;
        margin: 0;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    #paint-canvas {
        width: 100% !important;
        height: 100% !important;
        max-width: calc(100% - 16px) !important;
        max-height: calc(100% - 16px) !important;
        object-fit: contain;
        border-radius: 12px;
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
        cursor: crosshair;
        display: block !important;
        margin: 0 auto;
        background: white;
        border: none;
        outline: none;
    }
    
    /* Add specific mobile canvas rules */
    @media (max-width: 768px) {
        .canvas-container {
            padding: 8px !important;
            min-height: 75vh !important;
            max-height: 80vh !important;
            width: 100% !important;
            margin: 0 !important;
        }
        
        #paint-canvas {
            width: 100% !important;
            height: 100% !important;
            max-width: none !important;
            max-height: none !important;
            min-width: calc(100vw - 36px) !important;
            min-height: calc(75vh - 16px) !important;
        }
    }
    
    /* Enhanced touch interactions */
    .brush-size input, .brush-opacity input {
        height: 44px; /* Larger touch target */
        -webkit-appearance: none;
        appearance: none;
        background: rgba(102, 126, 234, 0.2);
        border-radius: 22px;
    }
    
    .brush-size input::-webkit-slider-thumb, .brush-opacity input::-webkit-slider-thumb {
        -webkit-appearance: none;
        appearance: none;
        width: 24px;
        height: 24px;
        border-radius: 50%;
        background: linear-gradient(135deg, #667eea, #764ba2);
        box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
        cursor: pointer;
    }
    
    .zoom-control {
        padding: 16px;
        margin-top: 12px;
        background: rgba(255, 255, 255, 0.8);
        border-radius: 12px;
    }
    
    .zoom-control input {
        height: 44px;
        -webkit-appearance: none;
        appearance: none;
        background: rgba(102, 126, 234, 0.2);
        border-radius: 22px;
    }
    
    .zoom-control input::-webkit-slider-thumb {
        -webkit-appearance: none;
        appearance: none;
        width: 24px;
        height: 24px;
        border-radius: 50%;
        background: linear-gradient(135deg, #667eea, #764ba2);
        box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
    }
    
    /* Mobile-specific animations */
    .color-btn:active {
        transform: scale(0.9);
        transition: transform 0.1s ease;
    }
    
    .brush-btn:active {
        transform: scale(0.95);
        transition: transform 0.1s ease;
    }
    
    /* Improved accessibility for mobile */
    .suggestions {
        border-radius: 12px;
        box-shadow: 0 8px 30px rgba(0, 0, 0, 0.2);
        backdrop-filter: blur(10px);
        background: rgba(255, 255, 255, 0.95);
    }
    
    /* Add some breathing room */
    .brush-controls h3 {
        margin-top: 8px;
        margin-bottom: 12px;
        font-size: 15px;
        font-weight: 600;
        color: #333;
        text-align: center;
    }
}

/* Tablet responsive */
@media (max-width: 1024px) and (min-width: 769px) {
    .toolbar {
        width: 240px;
        padding: 20px;
    }
    
    .color-palette {
        grid-template-columns: repeat(3, 1fr);
        gap: 10px;
    }
    
    .color-btn {
        width: 45px;
        height: 45px;
    }
    
    .paint-container {
        padding: 15px;
        gap: 15px;
    }
}

/* Micro-animations */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

.toolbar {
    animation: fadeIn 0.5s ease-out;
}

.canvas-container {
    animation: fadeIn 0.5s ease-out 0.1s both;
}

/* Scrollbar styling */
.toolbar::-webkit-scrollbar {
    width: 6px;
}

.toolbar::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.1);
    border-radius: 3px;
}

.toolbar::-webkit-scrollbar-thumb {
    background: linear-gradient(45deg, #667eea, #764ba2);
    border-radius: 3px;
}

.toolbar::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(45deg, #5a6fd8, #6b4190);
}

/* Loading states */
.loading {
    position: relative;
    overflow: hidden;
}

.loading::after {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.6), transparent);
    animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
    0% { left: -100%; }
    100% { left: 100%; }
}

/* Focus states for accessibility */
.color-btn:focus,
.brush-btn:focus,
.tool-btn:focus,
.nav-button:focus,
#nav-search:focus {
    outline: 3px solid rgba(102, 126, 234, 0.5);
    outline-offset: 2px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .toolbar {
        background: white;
        border: 2px solid #000;
    }
    
    .color-btn {
        border: 2px solid #000;
    }
    
    .brush-btn {
        border: 2px solid #000;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
