/* CSS Variables for theming */
:root {
    --primary-color: #6366f1;
    --primary-hover: #4f46e5;
    --secondary-color: #64748b;
    --background-color: #0f172a;
    --surface-color: #1e293b;
    --surface-light: #334155;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --border-color: #475569;
    --success-color: #22c55e;
    --warning-color: #f59e0b;
    --error-color: #ef4444;
    --red-channel: #ef4444;
    --green-channel: #22c55e;
    --blue-channel: #3b82f6;
    --alpha-channel: #a855f7;
    --font-mono: 'SF Mono', 'Fira Code', 'Consolas', monospace;
    --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    --border-radius: 12px;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3), 0 2px 4px -2px rgba(0, 0, 0, 0.2);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.4), 0 4px 6px -4px rgba(0, 0, 0, 0.3);
}

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

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-sans);
    background-color: var(--background-color);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
}

/* App Container */
.app-container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* Header */
.header {
    text-align: center;
    padding: 2rem 1rem;
    background: linear-gradient(135deg, var(--surface-color) 0%, var(--background-color) 100%);
    border-bottom: 1px solid var(--border-color);
}

.logo-container {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    margin-bottom: 0.5rem;
}

.logo {
    width: 48px;
    height: 48px;
    object-fit: contain;
}

.header h1 {
    font-size: 2rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary-color) 0%, #a855f7 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.tagline {
    color: var(--text-secondary);
    font-size: 1rem;
}

/* Main Content */
.main-content {
    flex: 1;
    padding: 1.5rem;
    max-width: 1400px;
    margin: 0 auto;
    width: 100%;
}

/* Upload Section */
.upload-section {
    margin-bottom: 2rem;
}

.drop-zone {
    border: 2px dashed var(--border-color);
    border-radius: var(--border-radius);
    padding: 3rem 2rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    background: var(--surface-color);
}

.drop-zone:hover,
.drop-zone.dragover {
    border-color: var(--primary-color);
    background: rgba(99, 102, 241, 0.1);
}

.drop-zone-content {
    pointer-events: none;
}

.upload-icon {
    width: 64px;
    height: 64px;
    margin-bottom: 1rem;
    color: var(--primary-color);
}

.drop-text {
    font-size: 1.125rem;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.supported-formats {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

/* Preview Section */
.preview-section {
    margin-bottom: 2rem;
    background: var(--surface-color);
    border-radius: var(--border-radius);
    padding: 1.5rem;
    box-shadow: var(--shadow);
}

.preview-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.preview-header h2 {
    font-size: 1.25rem;
    font-weight: 600;
}

.preview-container {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

#imageCanvas {
    max-width: 100%;
    max-height: 400px;
    border-radius: 8px;
    background: repeating-conic-gradient(var(--surface-light) 0% 25%, var(--surface-color) 0% 50%) 50% / 20px 20px;
    cursor: crosshair;
}

.pixel-info {
    display: flex;
    gap: 2rem;
    padding: 0.75rem 1.5rem;
    background: var(--surface-light);
    border-radius: 8px;
    font-family: var(--font-mono);
    font-size: 0.875rem;
}

.pixel-coords,
.pixel-color {
    color: var(--text-secondary);
}

/* Buttons */
.btn {
    padding: 0.625rem 1.25rem;
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    border: none;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

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

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

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

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

/* Tabs */
.tabs-section {
    background: var(--surface-color);
    border-radius: var(--border-radius);
    overflow: hidden;
    box-shadow: var(--shadow);
}

.tabs-nav {
    display: flex;
    overflow-x: auto;
    border-bottom: 1px solid var(--border-color);
    background: var(--surface-light);
    -webkit-overflow-scrolling: touch;
}

.tab-btn {
    padding: 1rem 1.5rem;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
    position: relative;
}

.tab-btn:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.05);
}

.tab-btn.active {
    color: var(--primary-color);
    background: var(--surface-color);
}

.tab-btn.active::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--primary-color);
}

.tab-content {
    display: none;
    padding: 1.5rem;
}

.tab-content.active {
    display: block;
}

/* Hex Display */
.hex-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    margin-bottom: 1rem;
    align-items: flex-end;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
}

.control-group label {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.control-group input,
.control-group select {
    padding: 0.5rem 0.75rem;
    background: var(--surface-light);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 0.875rem;
    min-width: 120px;
}

.control-group input:focus,
.control-group select:focus {
    outline: none;
    border-color: var(--primary-color);
}

.hex-display-container {
    overflow-x: auto;
    background: var(--background-color);
    border-radius: 8px;
    padding: 1rem;
    margin-bottom: 1rem;
}

.hex-display {
    font-family: var(--font-mono);
    font-size: 0.8rem;
    line-height: 1.8;
    white-space: pre;
    color: var(--text-primary);
}

.hex-row {
    display: flex;
    gap: 0.5rem;
}

.hex-offset {
    color: var(--primary-color);
    min-width: 80px;
}

.hex-bytes {
    color: var(--text-primary);
    letter-spacing: 0.5px;
}

.hex-byte {
    display: inline-block;
    width: 24px;
    text-align: center;
}

.hex-byte.zero {
    color: var(--text-secondary);
    opacity: 0.5;
}

.hex-byte.high {
    color: var(--warning-color);
}

.hex-ascii {
    color: var(--green-channel);
    min-width: 170px;
    margin-left: 1rem;
    border-left: 1px solid var(--border-color);
    padding-left: 1rem;
}

.hex-stats {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

/* Analysis Tab */
.analysis-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1.5rem;
}

.analysis-card {
    background: var(--surface-light);
    border-radius: 8px;
    padding: 1.25rem;
}

.analysis-card h3 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 1rem;
    color: var(--text-primary);
}

.histogram-card {
    grid-column: 1 / -1;
}

.histogram-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    margin-bottom: 1rem;
}

.histogram-controls label {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    font-size: 0.875rem;
    color: var(--text-secondary);
    cursor: pointer;
}

.histogram-controls input[type="checkbox"] {
    accent-color: var(--primary-color);
}

#histogramCanvas {
    width: 100%;
    height: 200px;
    background: var(--background-color);
    border-radius: 6px;
}

.info-list {
    display: flex;
    flex-direction: column;
    gap: 0.625rem;
}

.info-item {
    display: flex;
    justify-content: space-between;
    font-size: 0.875rem;
    padding: 0.375rem 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.info-item:last-child {
    border-bottom: none;
}

.info-label {
    color: var(--text-secondary);
}

.info-value {
    color: var(--text-primary);
    font-family: var(--font-mono);
}

.distribution-info {
    font-size: 0.875rem;
}

.distribution-bar {
    margin-top: 0.75rem;
}

.distribution-bar-label {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.25rem;
    color: var(--text-secondary);
}

.distribution-bar-track {
    height: 8px;
    background: var(--background-color);
    border-radius: 4px;
    overflow: hidden;
}

.distribution-bar-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.3s ease;
}

/* Channel Separation */
.channels-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1.5rem;
}

.channel-card {
    background: var(--surface-light);
    border-radius: 8px;
    padding: 1rem;
    text-align: center;
}

.channel-card h3 {
    font-size: 0.9rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
}

.channel-card canvas {
    max-width: 100%;
    max-height: 200px;
    border-radius: 6px;
    background: var(--background-color);
}

.channel-stats {
    margin-top: 0.75rem;
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-family: var(--font-mono);
}

/* Metadata Tab */
.metadata-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1.5rem;
}

.metadata-card {
    background: var(--surface-light);
    border-radius: 8px;
    padding: 1.25rem;
}

.metadata-card h3 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 1rem;
}

.metadata-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.metadata-item {
    display: flex;
    flex-direction: column;
    padding: 0.5rem 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.metadata-item:last-child {
    border-bottom: none;
}

.metadata-key {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 0.25rem;
}

.metadata-value {
    font-size: 0.875rem;
    color: var(--text-primary);
    font-family: var(--font-mono);
    word-break: break-all;
}

.raw-header {
    background: var(--background-color);
    border-radius: 6px;
    padding: 1rem;
    font-family: var(--font-mono);
    font-size: 0.75rem;
    line-height: 1.6;
    max-height: 300px;
    overflow-y: auto;
    white-space: pre-wrap;
    word-break: break-all;
    color: var(--text-secondary);
}

/* Footer */
.footer {
    text-align: center;
    padding: 1.5rem;
    background: var(--surface-color);
    border-top: 1px solid var(--border-color);
}

.footer p {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.footer a {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 500;
    transition: color 0.2s ease;
}

.footer a:hover {
    color: var(--primary-hover);
    text-decoration: underline;
}

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

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

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

::-webkit-scrollbar-thumb:hover {
    background: var(--secondary-color);
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .header {
        padding: 1.5rem 1rem;
    }

    .header h1 {
        font-size: 1.5rem;
    }

    .logo-container {
        flex-direction: column;
        gap: 0.5rem;
    }

    .main-content {
        padding: 1rem;
    }

    .drop-zone {
        padding: 2rem 1rem;
    }

    .upload-icon {
        width: 48px;
        height: 48px;
    }

    .drop-text {
        font-size: 1rem;
    }

    .tabs-nav {
        justify-content: flex-start;
    }

    .tab-btn {
        padding: 0.75rem 1rem;
        font-size: 0.8rem;
    }

    .tab-content {
        padding: 1rem;
    }

    .hex-controls {
        flex-direction: column;
        align-items: stretch;
    }

    .control-group input,
    .control-group select {
        width: 100%;
    }

    .hex-display {
        font-size: 0.7rem;
    }

    .hex-ascii {
        display: none;
    }

    .pixel-info {
        flex-direction: column;
        gap: 0.5rem;
        text-align: center;
    }

    .analysis-grid,
    .channels-grid,
    .metadata-container {
        grid-template-columns: 1fr;
    }

    .preview-header {
        flex-direction: column;
        gap: 1rem;
        align-items: flex-start;
    }
}

@media (max-width: 480px) {
    .header h1 {
        font-size: 1.25rem;
    }

    .tagline {
        font-size: 0.875rem;
    }

    .tab-btn {
        padding: 0.625rem 0.75rem;
        font-size: 0.75rem;
    }

    .hex-byte {
        width: 20px;
    }

    .analysis-card,
    .channel-card,
    .metadata-card {
        padding: 1rem;
    }
}

/* Utility Classes */
.text-red { color: var(--red-channel); }
.text-green { color: var(--green-channel); }
.text-blue { color: var(--blue-channel); }
.text-purple { color: var(--alpha-channel); }

/* Loading State */
.loading {
    opacity: 0.6;
    pointer-events: none;
}

/* Color Swatch */
.color-swatch {
    display: inline-block;
    width: 16px;
    height: 16px;
    border-radius: 3px;
    vertical-align: middle;
    margin-right: 0.5rem;
    border: 1px solid var(--border-color);
}
