/* ================================
   CSS Variables / Theme
   ================================ */
:root {
    --bg-primary: #1e1e1e;
    --bg-secondary: #252526;
    --bg-tertiary: #2d2d30;
    --bg-hover: #3c3c3c;
    --border-color: #3c3c3c;
    --text-primary: #cccccc;
    --text-secondary: #808080;
    --text-highlight: #ffffff;
    --accent-blue: #007acc;
    --accent-blue-hover: #1a8ad4;
    --accent-green: #4ec9b0;
    --accent-purple: #c586c0;
    --accent-yellow: #dcdcaa;
    --success: #4caf50;
    --error: #f44336;
}

/* ================================
   Reset & Base
   ================================ */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    
    /* Disable text selection */
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

html {
    scroll-behavior: smooth;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    font-size: 13px;
    line-height: 1.4;
    overflow-x: hidden;
}

/* Allow text selection where needed */
.command-block,
input[type="text"],
input[type="search"],
textarea {
    -webkit-user-select: text;
    -moz-user-select: text;
    -ms-user-select: text;
    user-select: text;
}

/* Disable image drag */
img {
    -webkit-user-drag: none;
    pointer-events: none;
    -webkit-touch-callout: none;
}

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

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

::-webkit-scrollbar-thumb {
    background: #444;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* Firefox scrollbar */
* {
    scrollbar-width: thin;
    scrollbar-color: #444 var(--bg-primary);
}

/* ================================
   Header
   ================================ */
.header {
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    padding: 0.625rem 1.25rem;
    position: sticky;
    top: 0;
    z-index: 100;
}

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

.logo {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: default;
}

.logo i {
    font-size: 1.25rem;
    color: var(--accent-blue);
}

.logo h1 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-highlight);
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.search-box {
    position: relative;
}

.search-box i {
    position: absolute;
    left: 0.625rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-secondary);
    font-size: 0.75rem;
    pointer-events: none;
}

.search-box input {
    padding: 0.375rem 0.625rem 0.375rem 1.75rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    color: var(--text-primary);
    font-size: 0.8125rem;
    width: 180px;
    outline: none;
    transition: border-color 0.15s;
}

.search-box input:focus {
    border-color: var(--accent-blue);
}

.search-box input::placeholder {
    color: var(--text-secondary);
}

.header-stats {
    color: var(--text-secondary);
    font-size: 0.8125rem;
    cursor: default;
}

.header-stats #selectedCount {
    color: var(--accent-blue);
    font-weight: 600;
    display: inline-block;
    min-width: 3ch;
    text-align: right;
}

.header-buttons {
    display: flex;
    gap: 0.375rem;
}

/* ================================
   Buttons
   ================================ */
.btn {
    padding: 0.375rem 0.75rem;
    border: none;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 500;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    transition: all 0.15s;
    outline: none;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn:active:not(:disabled) {
    transform: scale(0.97);
}

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--bg-hover);
    border-color: #555;
}

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

.btn-primary:hover:not(:disabled) {
    background: var(--accent-blue-hover);
}

/* ================================
   Main Layout
   ================================ */
.main-container {
    max-width: 1800px;
    margin: 0 auto;
    display: grid;
    grid-template-columns: 1fr 340px;
    min-height: calc(100vh - 52px);
}

@media (max-width: 1024px) {
    .main-container {
        grid-template-columns: 1fr;
    }
}

/* ================================
   Apps Section
   ================================ */
.apps-section {
    padding: 1rem 1.25rem;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1.25rem;
    align-content: start;
}

.loading-state {
    grid-column: 1 / -1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 200px;
    color: var(--text-secondary);
}

.loading-state i {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
    color: var(--accent-blue);
}

/* ================================
   Category Block
   ================================ */
.category {
    background: var(--bg-secondary);
    border-radius: 6px;
    border: 1px solid var(--border-color);
    overflow: hidden;
    transition: border-color 0.15s;
}

.category:hover {
    border-color: #4a4a4a;
}

.category-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-color);
    cursor: default;
}

.category-icon {
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    font-size: 0.625rem;
    color: white;
    flex-shrink: 0;
}

.category-name {
    font-weight: 600;
    font-size: 0.8125rem;
    color: var(--text-highlight);
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.category-actions {
    margin-left: auto;
    flex-shrink: 0;
}

.category-select-btn {
    font-size: 0.625rem;
    padding: 0.15rem 0.4rem;
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    border-radius: 3px;
    cursor: pointer;
    transition: all 0.15s;
    outline: none;
}

.category-select-btn:hover {
    background: var(--accent-blue);
    border-color: var(--accent-blue);
    color: white;
}

.category-select-btn:active {
    transform: scale(0.95);
}

/* ================================
   Apps List
   ================================ */
.apps-list {
    padding: 0.375rem;
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
}

.app-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.3rem 0.5rem;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.1s;
}

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

.app-item.selected {
    background: rgba(0, 122, 204, 0.2);
}

.app-item:active {
    background: rgba(0, 122, 204, 0.3);
}

.app-item.hidden {
    display: none;
}

/* Checkbox */
.app-checkbox {
    width: 14px;
    height: 14px;
    border: 1.5px solid var(--border-color);
    border-radius: 3px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.1s;
}

.app-item:hover .app-checkbox {
    border-color: #555;
}

.app-item.selected .app-checkbox {
    background: var(--accent-blue);
    border-color: var(--accent-blue);
}

.app-checkbox i {
    font-size: 0.5rem;
    color: white;
    opacity: 0;
    transition: opacity 0.1s;
}

.app-item.selected .app-checkbox i {
    opacity: 1;
}

/* App Icon */
.app-icon {
    width: 20px;
    height: 20px;
    border-radius: 3px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    background: var(--bg-tertiary);
    overflow: hidden;
}

.app-icon img {
    width: 16px;
    height: 16px;
    object-fit: contain;
}

.app-icon .fallback-icon {
    font-size: 0.75rem;
}

/* App Name */
.app-name {
    font-size: 0.8125rem;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

.app-item:hover .app-name {
    color: var(--text-highlight);
}

.app-item.selected .app-name {
    color: var(--text-highlight);
    font-weight: 500;
}

/* ================================
   Output Section
   ================================ */
.output-section {
    background: var(--bg-secondary);
    border-left: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 52px;
    height: calc(100vh - 52px);
}

@media (max-width: 1024px) {
    .output-section {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: auto;
        max-height: 50vh;
        border-left: none;
        border-top: 1px solid var(--border-color);
        z-index: 50;
    }

    .apps-section {
        padding-bottom: 200px;
    }
}

.output-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.625rem 0.875rem;
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-color);
    cursor: default;
}

.output-title {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--text-highlight);
}

.output-title i {
    color: var(--accent-blue);
}

/* ================================
   Output Options
   ================================ */
.output-options {
    padding: 0.5rem 0.875rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-primary);
}

.option-checkbox {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    cursor: pointer;
    font-size: 0.75rem;
    color: var(--text-secondary);
    transition: color 0.1s;
}

.option-checkbox:hover {
    color: var(--text-primary);
}

.option-checkbox input {
    width: 12px;
    height: 12px;
    accent-color: var(--accent-blue);
    cursor: pointer;
}

/* ================================
   Output Content
   ================================ */
.output-content {
    flex: 1;
    overflow-y: auto;
    padding: 0.75rem;
}

.command-block {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 0.75rem;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 0.75rem;
    line-height: 1.6;
    color: var(--text-primary);
    white-space: pre-wrap;
    word-break: break-all;
    max-height: 100%;
    overflow-y: auto;
    cursor: text;
}

/* Syntax Highlighting */
.command-block .keyword {
    color: var(--accent-purple);
}

.command-block .command {
    color: var(--accent-yellow);
}

.command-block .flag {
    color: var(--accent-blue);
}

.command-block .package {
    color: var(--accent-green);
}

/* ================================
   Empty State
   ================================ */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 150px;
    color: var(--text-secondary);
    text-align: center;
    cursor: default;
}

.empty-state i {
    font-size: 2rem;
    margin-bottom: 0.5rem;
    opacity: 0.4;
}

.empty-state p {
    font-size: 0.8125rem;
}

/* ================================
   How to Use
   ================================ */
.how-to-use {
    padding: 0.625rem 0.875rem;
    background: var(--bg-tertiary);
    border-top: 1px solid var(--border-color);
    font-size: 0.6875rem;
    color: var(--text-secondary);
    cursor: default;
}

.how-to-use strong {
    color: var(--text-primary);
}

/* ================================
   Toast Notification
   ================================ */
.toast {
    position: fixed;
    bottom: 1.5rem;
    left: 50%;
    transform: translateX(-50%) translateY(80px);
    background: var(--bg-tertiary);
    border: 1px solid var(--success);
    padding: 0.5rem 1rem;
    border-radius: 6px;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
    opacity: 0;
    transition: all 0.25s ease;
    z-index: 200;
    font-size: 0.8125rem;
    pointer-events: none;
}

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

.toast i {
    color: var(--success);
}

/* ================================
   Category Colors
   ================================ */
.cat-browsers { background: linear-gradient(135deg, #4285f4, #34a853); }
.cat-messaging { background: linear-gradient(135deg, #7289da, #5865f2); }
.cat-media { background: linear-gradient(135deg, #ff6b6b, #ee5a5a); }
.cat-dotnet { background: linear-gradient(135deg, #512bd4, #68217a); }
.cat-java { background: linear-gradient(135deg, #f89820, #ed8b00); }
.cat-imaging { background: linear-gradient(135deg, #ff7eb3, #ff758c); }
.cat-documents { background: linear-gradient(135deg, #00b4d8, #0077b6); }
.cat-security { background: linear-gradient(135deg, #ef476f, #d62828); }
.cat-filesharing { background: linear-gradient(135deg, #06ffa5, #00c9a7); }
.cat-storage { background: linear-gradient(135deg, #0061ff, #60efff); }
.cat-other { background: linear-gradient(135deg, #a855f7, #6366f1); }
.cat-utilities { background: linear-gradient(135deg, #f59e0b, #d97706); }
.cat-compression { background: linear-gradient(135deg, #10b981, #059669); }
.cat-vcredist { background: linear-gradient(135deg, #6b7280, #4b5563); }
.cat-devtools { background: linear-gradient(135deg, #3b82f6, #2563eb); }

/* ================================
   Focus Styles (Accessibility)
   ================================ */
.btn:focus-visible,
.category-select-btn:focus-visible,
.option-checkbox input:focus-visible {
    outline: 2px solid var(--accent-blue);
    outline-offset: 2px;
}

.search-box input:focus-visible {
    outline: none;
    border-color: var(--accent-blue);
    box-shadow: 0 0 0 2px rgba(0, 122, 204, 0.25);
}

/* ================================
   Responsive Design
   ================================ */
@media (max-width: 768px) {
    .header {
        padding: 0.5rem 0.75rem;
    }

    .header-content {
        flex-direction: column;
        align-items: stretch;
        gap: 0.5rem;
    }

    .header-actions {
        justify-content: space-between;
    }

    .search-box {
        flex: 1;
    }

    .search-box input {
        width: 100%;
    }

    .apps-section {
        grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
        padding: 0.75rem;
        gap: 0.75rem;
    }

    .output-section {
        max-height: 40vh;
    }
}

@media (min-width: 1400px) {
    .apps-section {
        grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    }
}

@media (min-width: 1600px) {
    .apps-section {
        grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    }
}

@media (min-width: 1900px) {
    .apps-section {
        grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    }
}

/* ================================
   Print Styles
   ================================ */
@media print {
    .header,
    .apps-section,
    .output-header,
    .output-options,
    .how-to-use,
    .toast {
        display: none !important;
    }

    .output-section {
        position: static;
        height: auto;
        border: none;
    }

    .command-block {
        border: 1px solid #ccc;
        color: #000;
        background: #fff;
    }
}

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

/* ================================
   High Contrast Mode
   ================================ */
@media (prefers-contrast: high) {
    :root {
        --border-color: #666;
        --text-secondary: #aaa;
    }

    .app-checkbox {
        border-width: 2px;
    }

    .category {
        border-width: 2px;
    }
}