/* ============================================
   Color Palette Generator — Styles
   ============================================ */

*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg: #0f172a;
    --surface: #1e293b;
    --surface-hover: #263548;
    --accent: #60a5fa;
    --accent-bold: #3b82f6;
    --accent-glow: rgba(59, 130, 246, 0.15);
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-dim: #64748b;
    --border: rgba(255, 255, 255, 0.08);
    --border-hover: rgba(255, 255, 255, 0.15);
    --danger: #ef4444;
    --success: #22c55e;
    --warning: #f59e0b;
    --radius: 10px;
    --radius-sm: 6px;
    --radius-lg: 14px;
    --font-ui: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-mono: 'SF Mono', 'Fira Code', 'Fira Mono', 'Roboto Mono', 'Consolas', monospace;
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.25);
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

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

/* ---- Scrollbar ---- */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: var(--text-dim);
    border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* ============================================
   Top Bar
   ============================================ */
.top-bar {
    position: sticky;
    top: 0;
    z-index: 100;
    height: 48px;
    background: linear-gradient(135deg, #1e3a5f 0%, #2563eb 50%, #7c3aed 100%);
    border-bottom: 1px solid var(--border);
    box-shadow: 0 2px 16px rgba(0, 0, 0, 0.3);
}

.top-bar-inner {
    max-width: 1280px;
    margin: 0 auto;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo-text {
    font-size: 15px;
    font-weight: 600;
    color: #fff;
    letter-spacing: -0.01em;
}

.mode-switcher {
    display: flex;
    gap: 4px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: var(--radius);
    padding: 3px;
}

.mode-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 14px;
    border: none;
    border-radius: 7px;
    background: transparent;
    color: rgba(255, 255, 255, 0.7);
    font-family: var(--font-ui);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.mode-btn:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.1);
}

.mode-btn.active {
    color: #fff;
    background: rgba(255, 255, 255, 0.2);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
}

/* ============================================
   Main Content
   ============================================ */
.main-content {
    max-width: 1280px;
    margin: 0 auto;
    padding: 24px 20px 60px;
}

/* ============================================
   Mode Panels
   ============================================ */
.mode-panel {
    display: none;
    animation: fadeIn 0.25s ease;
}

.mode-panel.active {
    display: block;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ---- Extract Mode ---- */
.extract-layout {
    display: flex;
    gap: 20px;
    align-items: flex-start;
}

.upload-area {
    flex: 1;
    min-height: 280px;
    background: var(--surface);
    border: 2px dashed var(--border-hover);
    border-radius: var(--radius-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
    overflow: hidden;
}

.upload-area:hover,
.upload-area.dragover {
    border-color: var(--accent);
    background: var(--accent-glow);
}

.upload-area.has-image {
    border-style: solid;
    border-color: var(--border);
    cursor: default;
}

.upload-placeholder {
    text-align: center;
    padding: 40px;
}

.upload-placeholder.hidden {
    display: none;
}

.upload-title {
    margin-top: 12px;
    font-size: 15px;
    font-weight: 500;
    color: var(--text-secondary);
}

.upload-subtitle {
    margin-top: 4px;
    font-size: 13px;
    color: var(--text-dim);
}

.preview-canvas {
    max-width: 100%;
    max-height: 400px;
    border-radius: var(--radius);
    display: block;
}

.preview-canvas.hidden {
    display: none;
}

.extract-controls {
    width: 220px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.control-label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.range-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 8px;
}

.range-input {
    flex: 1;
    -webkit-appearance: none;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    outline: none;
}

.range-input::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--accent-bold);
    cursor: pointer;
    box-shadow: 0 0 6px rgba(59, 130, 246, 0.4);
    transition: transform 0.15s ease;
}

.range-input::-webkit-slider-thumb:hover {
    transform: scale(1.15);
}

.range-value {
    font-size: 14px;
    font-weight: 600;
    color: var(--accent);
    min-width: 20px;
    text-align: center;
}

/* ---- Harmonies Mode ---- */
.harmonies-layout {
    display: flex;
    gap: 32px;
    align-items: flex-start;
}

.harmony-controls {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.color-input-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 8px;
}

.color-well {
    -webkit-appearance: none;
    width: 44px;
    height: 44px;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    background: none;
    cursor: pointer;
    padding: 2px;
}

.color-well::-webkit-color-swatch-wrapper {
    padding: 0;
}

.color-well::-webkit-color-swatch {
    border: none;
    border-radius: 6px;
}

.hex-input {
    width: 100px;
    padding: 8px 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s ease;
}

.hex-input:focus {
    border-color: var(--accent);
}

.harmony-btn-group {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
}

.harmony-type-btn {
    padding: 7px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text-secondary);
    font-family: var(--font-ui);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.harmony-type-btn:hover {
    border-color: var(--border-hover);
    color: var(--text-primary);
    background: var(--surface-hover);
}

.harmony-type-btn.active {
    border-color: var(--accent-bold);
    color: var(--accent);
    background: var(--accent-glow);
}

.harmony-wheel-container {
    flex-shrink: 0;
}

#harmony-wheel {
    border-radius: 50%;
    background: var(--surface);
    border: 1px solid var(--border);
}

/* ---- Manual Mode ---- */
.manual-controls {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

/* ============================================
   Buttons
   ============================================ */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 9px 18px;
    border: 1px solid transparent;
    border-radius: var(--radius);
    font-family: var(--font-ui);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

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

.btn-primary {
    background: var(--accent-bold);
    color: #fff;
    border-color: var(--accent-bold);
}

.btn-primary:hover:not(:disabled) {
    background: #2563eb;
    box-shadow: 0 0 12px rgba(59, 130, 246, 0.3);
}

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

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

.btn-danger {
    background: transparent;
    color: var(--danger);
    border-color: rgba(239, 68, 68, 0.3);
}

.btn-danger:hover {
    background: rgba(239, 68, 68, 0.1);
    border-color: var(--danger);
}

.btn-sm {
    padding: 5px 12px;
    font-size: 12px;
    border-radius: var(--radius-sm);
    background: var(--accent-bold);
    color: #fff;
    border: none;
    cursor: pointer;
    transition: all 0.15s ease;
}

.btn-sm:hover {
    background: #2563eb;
}

/* ============================================
   Palette Display
   ============================================ */
.palette-section {
    margin-top: 32px;
}

.palette-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 16px;
}

.palette-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
}

.palette-count {
    font-size: 13px;
    color: var(--text-dim);
    font-weight: 400;
}

.palette-swatches {
    display: flex;
    flex-direction: column;
    gap: 0;
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow);
}

.palette-swatches.grid-view {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 8px;
    border-radius: 0;
    overflow: visible;
    box-shadow: none;
}

.palette-swatches.grid-view .swatch {
    border-radius: var(--radius);
    height: 140px;
}

.swatch {
    height: 72px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    cursor: pointer;
    transition: all 0.15s ease;
    position: relative;
    user-select: none;
}

.swatch:hover {
    transform: scaleY(1.05);
    z-index: 2;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}

.swatch-label {
    font-family: var(--font-mono);
    font-size: 14px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

.swatch-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    opacity: 0;
    transition: opacity 0.15s ease;
}

.swatch:hover .swatch-actions {
    opacity: 1;
}

.swatch-action-btn {
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 6px;
    background: rgba(0, 0, 0, 0.3);
    color: inherit;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
    transition: background 0.15s ease;
}

.swatch-action-btn:hover {
    background: rgba(0, 0, 0, 0.5);
}

.swatch-copied {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(2px);
    font-size: 13px;
    font-weight: 600;
    color: #fff;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease;
}

.swatch-copied.show {
    opacity: 1;
}

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 48px 20px;
    text-align: center;
    color: var(--text-dim);
    font-size: 14px;
}

/* Drag handle for manual mode reordering */
.swatch-drag-handle {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: grab;
    opacity: 0;
    transition: opacity 0.15s ease;
    color: inherit;
}

.swatch:hover .swatch-drag-handle {
    opacity: 0.7;
}

.swatch.dragging {
    opacity: 0.5;
}

.swatch.drag-over {
    box-shadow: 0 -3px 0 var(--accent) inset;
}

/* ============================================
   Color Info Panel
   ============================================ */
.color-info-panel {
    position: fixed;
    right: 24px;
    top: 80px;
    width: 280px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    z-index: 200;
    overflow: hidden;
    animation: slideIn 0.2s ease;
}

.color-info-panel.hidden {
    display: none;
}

@keyframes slideIn {
    from { opacity: 0; transform: translateX(16px); }
    to   { opacity: 1; transform: translateX(0); }
}

.info-close {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 6px;
    background: rgba(0, 0, 0, 0.3);
    color: #fff;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1;
    transition: background 0.15s ease;
}

.info-close:hover {
    background: rgba(0, 0, 0, 0.5);
}

.info-preview {
    height: 100px;
    width: 100%;
}

.info-details {
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.info-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.info-label {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    flex-shrink: 0;
}

.info-value {
    font-family: var(--font-mono);
    font-size: 13px;
    color: var(--text-primary);
    background: rgba(0, 0, 0, 0.2);
    padding: 4px 8px;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.15s ease;
}

.info-value:hover {
    background: rgba(0, 0, 0, 0.4);
}

.info-divider {
    height: 1px;
    background: var(--border);
    margin: 4px 0;
}

.info-contrast {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
}

.contrast-ratio {
    font-family: var(--font-mono);
    font-size: 13px;
    color: var(--text-primary);
}

.contrast-badge {
    display: inline-block;
    padding: 1px 5px;
    border-radius: 3px;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.03em;
}

.contrast-badge.pass {
    background: rgba(34, 197, 94, 0.15);
    color: var(--success);
}

.contrast-badge.fail {
    background: rgba(239, 68, 68, 0.15);
    color: var(--danger);
}

/* ============================================
   Export Section
   ============================================ */
.export-section {
    margin-top: 32px;
    padding-top: 24px;
    border-top: 1px solid var(--border);
}

.section-title {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 16px;
    color: var(--text-primary);
}

.export-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.export-btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 9px 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-secondary);
    font-family: var(--font-ui);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.export-btn:hover {
    background: var(--surface-hover);
    color: var(--text-primary);
    border-color: var(--border-hover);
}

.export-btn:active {
    transform: scale(0.97);
}

.export-output {
    margin-top: 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.export-output.hidden {
    display: none;
}

.export-output-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    background: rgba(0, 0, 0, 0.15);
    border-bottom: 1px solid var(--border);
}

.export-output-title {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
}

.export-code {
    padding: 16px;
    font-family: var(--font-mono);
    font-size: 13px;
    line-height: 1.6;
    color: var(--text-primary);
    overflow-x: auto;
    max-height: 320px;
    white-space: pre;
    margin: 0;
}

/* ============================================
   Toast
   ============================================ */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(16px);
    padding: 10px 20px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 13px;
    font-weight: 500;
    box-shadow: var(--shadow);
    z-index: 1000;
    opacity: 0;
    transition: all 0.25s ease;
    pointer-events: none;
}

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

.toast.hidden {
    display: none;
}

/* ============================================
   Hidden Picker
   ============================================ */
.hidden-picker {
    position: fixed;
    top: -100px;
    left: -100px;
    opacity: 0;
    width: 0;
    height: 0;
    pointer-events: none;
}

/* ============================================
   Responsive
   ============================================ */
@media (max-width: 768px) {
    .top-bar-inner {
        flex-direction: column;
        height: auto;
        padding: 8px 16px;
        gap: 8px;
    }

    .top-bar {
        height: auto;
    }

    .mode-switcher {
        width: 100%;
        justify-content: center;
    }

    .mode-btn {
        flex: 1;
        justify-content: center;
        padding: 5px 8px;
        font-size: 12px;
    }

    .extract-layout {
        flex-direction: column;
    }

    .extract-controls {
        width: 100%;
        flex-direction: row;
        align-items: flex-end;
    }

    .harmonies-layout {
        flex-direction: column;
    }

    .harmony-wheel-container {
        align-self: center;
    }

    .color-info-panel {
        right: 8px;
        left: 8px;
        width: auto;
        top: auto;
        bottom: 8px;
    }

    .manual-controls {
        flex-direction: column;
    }

    .manual-controls .btn {
        width: 100%;
        justify-content: center;
    }
}
