/**
 * Synexmedia Emoji Browser - Progressive Web App
 * © 2025 Synexmedia.com
 */

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

:root {
    --primary-color: #4A90E2;
    --primary-dark: #357ABD;
    --background: #ffffff;
    --surface: #f5f5f5;
    --border: #e0e0e0;
    --text-primary: #333333;
    --text-secondary: #666666;
    --text-tertiary: #999999;
    --success: #4CAF50;
    --shadow: rgba(0, 0, 0, 0.1);
    --shadow-strong: rgba(0, 0, 0, 0.15);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--background);
    color: var(--text-primary);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow: hidden;
}

/* App Container */
.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh; /* Dynamic viewport height for mobile */
    overflow: hidden;
}

/* Header */
.app-header {
    background: linear-gradient(135deg, #4A90E2 0%, #357ABD 100%);
    color: white;
    padding: 1rem;
    box-shadow: 0 2px 8px var(--shadow);
    z-index: 100;
}

.header-content {
    max-width: 1200px;
    margin: 0 auto;
    text-align: center;
}

.app-title {
    font-size: 1.5rem;
    font-weight: 700;
    margin: 0;
}

.app-subtitle {
    font-size: 0.875rem;
    opacity: 0.9;
    margin: 0.25rem 0 0;
}

/* Search Bar */
.search-container {
    padding: 1rem;
    background: var(--background);
    border-bottom: 1px solid var(--border);
    z-index: 90;
}

.mobile-categories-btn {
    display: none;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 0.9375rem;
    font-weight: 500;
    cursor: pointer;
    margin-bottom: 0.75rem;
    width: 100%;
    justify-content: center;
    transition: background 0.2s ease;
}

.mobile-categories-btn:hover {
    background: var(--primary-dark);
}

.search-box {
    max-width: 600px;
    margin: 0 auto;
    position: relative;
    display: flex;
    align-items: center;
}

.search-icon {
    position: absolute;
    left: 0.75rem;
    color: var(--text-tertiary);
    pointer-events: none;
}

.search-input {
    width: 100%;
    padding: 0.75rem 2.5rem 0.75rem 2.75rem;
    border: 2px solid var(--border);
    border-radius: 12px;
    font-size: 1rem;
    background: var(--surface);
    color: var(--text-primary);
    transition: all 0.2s ease;
}

.search-input:focus {
    outline: none;
    border-color: var(--primary-color);
    background: var(--background);
}

.clear-button {
    position: absolute;
    right: 0.5rem;
    background: none;
    border: none;
    color: var(--text-tertiary);
    cursor: pointer;
    padding: 0.25rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.2s ease;
}

.clear-button:hover {
    opacity: 0.7;
}

/* Main Content */
.main-content {
    display: flex;
    flex: 1;
    overflow: hidden;
    position: relative;
}

/* Categories Sidebar */
.categories-sidebar {
    width: 250px;
    background: var(--surface);
    border-right: 1px solid var(--border);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    flex-shrink: 0;
    transition: transform 0.3s ease;
}

.categories-header {
    padding: 1rem;
    border-bottom: 1px solid var(--border);
    background: var(--background);
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 10;
}

.categories-header h2 {
    font-size: 1.125rem;
    font-weight: 600;
}

.toggle-sidebar-btn {
    display: none;
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.25rem;
}

.categories-list {
    padding: 0.5rem 0;
}

.category-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    cursor: pointer;
    transition: background 0.2s ease;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
    font-size: 0.9375rem;
    color: var(--text-primary);
}

.category-item:hover {
    background: var(--background);
}

.category-item.active {
    background: rgba(74, 144, 226, 0.1);
    color: var(--primary-color);
    font-weight: 500;
}

.category-count {
    font-size: 0.75rem;
    color: var(--text-tertiary);
    background: var(--background);
    padding: 0.125rem 0.5rem;
    border-radius: 12px;
}

/* Emoji Container */
.emoji-container {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    background: var(--background);
}

.emoji-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(50px, 1fr));
    gap: 0.5rem;
    padding: 1rem;
    max-width: 1200px;
    margin: 0 auto;
}

.emoji-button {
    aspect-ratio: 1;
    background: var(--surface);
    border: 2px solid transparent;
    border-radius: 12px;
    font-size: 2rem;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.emoji-button:hover {
    background: var(--border);
    transform: scale(1.05);
}

.emoji-button:active {
    transform: scale(0.95);
}

.emoji-button.copied {
    background: rgba(76, 175, 80, 0.2);
    border-color: var(--success);
    animation: copyPulse 0.4s ease;
}

@keyframes copyPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

/* Footer */
.app-footer {
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding: 0.75rem 1rem;
    z-index: 90;
}

.status-message {
    text-align: center;
    margin-bottom: 0.5rem;
}

#statusText {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

#statusText.success {
    color: var(--success);
    font-weight: 500;
}

.copyright {
    text-align: center;
    font-size: 0.75rem;
    color: var(--text-tertiary);
}

/* Toast Notification */
.toast {
    position: fixed;
    bottom: 5rem;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: rgba(0, 0, 0, 0.85);
    color: white;
    padding: 0.75rem 1.5rem;
    border-radius: 24px;
    font-size: 0.875rem;
    font-weight: 500;
    box-shadow: 0 4px 12px var(--shadow-strong);
    opacity: 0;
    transition: all 0.3s ease;
    pointer-events: none;
    z-index: 1000;
    white-space: nowrap;
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* Install Prompt */
.install-prompt {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--background);
    border-top: 1px solid var(--border);
    padding: 1rem;
    box-shadow: 0 -2px 12px var(--shadow);
    z-index: 200;
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from {
        transform: translateY(100%);
    }
    to {
        transform: translateY(0);
    }
}

.install-content {
    max-width: 600px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.install-content span {
    font-size: 0.9375rem;
    color: var(--text-primary);
}

.install-buttons {
    display: flex;
    gap: 0.5rem;
}

.install-btn,
.dismiss-btn {
    padding: 0.5rem 1rem;
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    border: none;
}

.install-btn {
    background: var(--primary-color);
    color: white;
}

.install-btn:hover {
    background: var(--primary-dark);
}

.dismiss-btn {
    background: var(--surface);
    color: var(--text-secondary);
}

.dismiss-btn:hover {
    background: var(--border);
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .app-title {
        font-size: 1.25rem;
    }

    .app-subtitle {
        font-size: 0.8125rem;
    }

    .mobile-categories-btn {
        display: flex;
    }

    .categories-sidebar {
        position: absolute;
        top: 0;
        left: 0;
        bottom: 0;
        z-index: 150;
        transform: translateX(-100%);
        box-shadow: 2px 0 8px var(--shadow);
    }

    .categories-sidebar.open {
        transform: translateX(0);
    }

    .toggle-sidebar-btn {
        display: flex;
    }

    .emoji-grid {
        grid-template-columns: repeat(auto-fill, minmax(45px, 1fr));
        gap: 0.375rem;
        padding: 0.75rem;
    }

    .emoji-button {
        font-size: 1.75rem;
    }

    .install-content {
        flex-direction: column;
        align-items: stretch;
        text-align: center;
    }

    .install-buttons {
        justify-content: center;
    }
}

@media (max-width: 480px) {
    .search-container {
        padding: 0.75rem;
    }

    .emoji-grid {
        grid-template-columns: repeat(auto-fill, minmax(40px, 1fr));
    }

    .emoji-button {
        font-size: 1.5rem;
    }
}

/* Loading State */
.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 3rem;
    color: var(--text-tertiary);
}

.loading::after {
    content: '';
    width: 32px;
    height: 32px;
    border: 3px solid var(--border);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Empty State */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem 1rem;
    color: var(--text-tertiary);
    text-align: center;
}

.empty-state-icon {
    font-size: 4rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}

.empty-state-text {
    font-size: 1rem;
    margin-bottom: 0.5rem;
}

.empty-state-subtext {
    font-size: 0.875rem;
}

/* Scrollbar Styling */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--surface);
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-tertiary);
}

/* Dark Mode Support (auto) */
@media (prefers-color-scheme: dark) {
    :root {
        --background: #1a1a1a;
        --surface: #2d2d2d;
        --border: #3d3d3d;
        --text-primary: #e0e0e0;
        --text-secondary: #b0b0b0;
        --text-tertiary: #808080;
        --shadow: rgba(0, 0, 0, 0.3);
        --shadow-strong: rgba(0, 0, 0, 0.5);
    }

    .emoji-button {
        background: var(--surface);
    }

    .emoji-button:hover {
        background: #3a3a3a;
    }
}

/* Print Styles */
@media print {
    .app-header,
    .search-container,
    .categories-sidebar,
    .app-footer,
    .toast,
    .install-prompt {
        display: none;
    }

    .emoji-container {
        overflow: visible;
    }
}

/* Safe Area Insets for iOS */
@supports (padding: env(safe-area-inset-top)) {
    .app-header {
        padding-top: calc(1rem + env(safe-area-inset-top));
    }

    .app-footer {
        padding-bottom: calc(0.75rem + env(safe-area-inset-bottom));
    }

    .install-prompt {
        padding-bottom: calc(1rem + env(safe-area-inset-bottom));
    }
}

/* Utility Classes (CSP-compliant - no inline styles needed) */
.hidden {
    display: none !important;
}
