:root {
    --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, sans-serif;
    --font-mono: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.12);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.15);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.2);
    --transition: 0.2s ease;
}

[data-theme="light"] {
    --bg-primary: #ffffff;
    --bg-secondary: #f5f5f7;
    --bg-tertiary: #e8e8ed;
    --bg-hover: #f0f0f2;
    --text-primary: #1d1d1f;
    --text-secondary: #6e6e73;
    --text-muted: #aeaeb2;
    --border: #d2d2d7;
    --border-light: #e5e5ea;
    --accent: #0071e3;
    --accent-hover: #0077ed;
    --danger: #ff3b30;
    --danger-hover: #ff453a;
    --success: #30d158;
    --surface: #ffffff;
    --surface-raised: #f9f9fb;
    --overlay: rgba(0,0,0,0.4);
    --swatch-border: #d2d2d7;
}

[data-theme="dark"] {
    --bg-primary: #1c1c1e;
    --bg-secondary: #2c2c2e;
    --bg-tertiary: #3a3a3c;
    --bg-hover: #38383a;
    --text-primary: #f5f5f7;
    --text-secondary: #a1a1a6;
    --text-muted: #636366;
    --border: #48484a;
    --border-light: #3a3a3c;
    --accent: #0a84ff;
    --accent-hover: #409cff;
    --danger: #ff453a;
    --danger-hover: #ff6961;
    --success: #30d158;
    --surface: #2c2c2e;
    --surface-raised: #3a3a3c;
    --overlay: rgba(0,0,0,0.6);
    --swatch-border: #58585a;
}

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

body {
    font-family: var(--font-sans);
    background: var(--bg-primary);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* Header */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    min-height: 48px;
    z-index: 100;
}

.app-title {
    font-size: 16px;
    font-weight: 700;
    letter-spacing: -0.3px;
}

.header-right {
    display: flex;
    gap: 4px;
}

.header-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border: none;
    border-radius: var(--radius-md);
    background: transparent;
    color: var(--text-primary);
    font-size: 13px;
    cursor: pointer;
    transition: background var(--transition);
}

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

.icon {
    width: 18px;
    height: 18px;
    fill: currentColor;
    flex-shrink: 0;
}

[data-theme="dark"] .icon-theme-dark,
[data-theme="light"] .icon-theme-light {
    display: block;
}

[data-theme="dark"] .icon-theme-light,
[data-theme="light"] .icon-theme-dark {
    display: none;
}

/* Mobile Tabs */
.mobile-tabs {
    display: none;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
}

.tab-btn {
    flex: 1;
    padding: 10px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all var(--transition);
}

.tab-btn.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

/* Main Layout */
.app-main {
    display: flex;
    flex: 1;
    overflow: hidden;
}

.panel {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.panel-image {
    flex: 6;
    min-width: 300px;
}

.panel-toolbox {
    flex: 4;
    min-width: 280px;
    border-left: 1px solid var(--border);
    background: var(--bg-secondary);
}

/* Divider */
.divider {
    width: 5px;
    cursor: col-resize;
    background: var(--border);
    transition: background var(--transition);
    flex-shrink: 0;
}

.divider:hover,
.divider.active {
    background: var(--accent);
}

/* Panel Toolbar */
.panel-toolbar {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border-light);
    background: var(--bg-secondary);
}

.toolbar-btn {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text-primary);
    font-size: 12px;
    cursor: pointer;
    transition: all var(--transition);
}

.toolbar-btn:hover {
    background: var(--bg-hover);
    border-color: var(--accent);
}

.toolbar-btn.btn-danger {
    color: var(--danger);
    border-color: var(--danger);
}

.toolbar-btn.btn-danger:hover {
    background: var(--danger);
    color: white;
}

.toolbar-spacer {
    flex: 1;
}

/* Image Viewport */
.image-viewport {
    flex: 1;
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-primary);
}

#image-canvas {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    display: none;
}

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    color: var(--text-muted);
}

.empty-icon {
    width: 64px;
    height: 64px;
    fill: var(--text-muted);
    opacity: 0.5;
}

.empty-state p {
    font-size: 14px;
}

/* Eyedropper Overlay */
.eyedropper-overlay {
    position: absolute;
    inset: 0;
    cursor: crosshair;
    z-index: 50;
}

.eyedropper-box {
    position: absolute;
    border: 2px solid rgba(255,255,255,0.9);
    box-shadow: 0 0 0 1px rgba(0,0,0,0.5), inset 0 0 0 1px rgba(0,0,0,0.3);
    pointer-events: none;
    transition: none;
}

.eyedropper-preview {
    position: absolute;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    pointer-events: none;
    white-space: nowrap;
    font-size: 12px;
    font-family: var(--font-mono);
}

.preview-swatch {
    width: 20px;
    height: 20px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--swatch-border);
    background: #000;
}

/* Image Navigation */
.image-nav {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 8px;
    border-top: 1px solid var(--border-light);
    background: var(--bg-secondary);
}

.nav-btn {
    width: 32px;
    height: 32px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text-primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
    flex-shrink: 0;
}

.nav-btn:hover:not(:disabled) {
    background: var(--bg-hover);
    border-color: var(--accent);
}

.nav-btn:disabled {
    opacity: 0.3;
    cursor: default;
}

.thumbnail-strip {
    display: flex;
    gap: 4px;
    overflow-x: auto;
    flex: 1;
    padding: 2px;
    scrollbar-width: thin;
}

.thumbnail-strip::-webkit-scrollbar {
    height: 4px;
}

.thumbnail-strip::-webkit-scrollbar-thumb {
    background: var(--text-muted);
    border-radius: 2px;
}

.thumbnail-item {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-sm);
    border: 2px solid transparent;
    overflow: hidden;
    cursor: pointer;
    flex-shrink: 0;
    transition: border-color var(--transition);
}

.thumbnail-item.active {
    border-color: var(--accent);
}

.thumbnail-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Toolbox */
.toolbox-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-light);
}

.toolbox-header h2 {
    font-size: 15px;
    font-weight: 600;
}

.completion-badge {
    font-size: 11px;
    padding: 3px 8px;
    border-radius: 10px;
    background: var(--bg-tertiary);
    color: var(--text-secondary);
}

.completion-badge.complete {
    background: var(--success);
    color: white;
}

.toolbox-controls {
    padding: 10px 16px;
    border-bottom: 1px solid var(--border-light);
}

.control-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 13px;
}

.control-row input[type="number"] {
    width: 60px;
    padding: 4px 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text-primary);
    font-size: 13px;
    text-align: center;
}

/* Palette List */
.palette-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.palette-list::-webkit-scrollbar {
    width: 6px;
}

.palette-list::-webkit-scrollbar-thumb {
    background: var(--text-muted);
    border-radius: 3px;
}

.base-color-card {
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    margin-bottom: 8px;
    background: var(--surface);
    overflow: hidden;
}

.base-color-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    cursor: pointer;
    user-select: none;
    transition: background var(--transition);
}

.base-color-header:hover {
    background: var(--bg-hover);
}

.collapse-icon {
    width: 16px;
    height: 16px;
    fill: var(--text-secondary);
    transition: transform var(--transition);
    flex-shrink: 0;
}

.base-color-card.collapsed .collapse-icon {
    transform: rotate(-90deg);
}

.base-color-swatch {
    width: 24px;
    height: 24px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--swatch-border);
    flex-shrink: 0;
}

.base-color-name {
    flex: 1;
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.base-color-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}

.toggle-active {
    position: relative;
    width: 32px;
    height: 18px;
    border-radius: 9px;
    background: var(--bg-tertiary);
    border: none;
    cursor: pointer;
    transition: background var(--transition);
}

.toggle-active.active {
    background: var(--success);
}

.toggle-active::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: white;
    transition: transform var(--transition);
}

.toggle-active.active::after {
    transform: translateX(14px);
}

.btn-remove-color {
    width: 24px;
    height: 24px;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
}

.btn-remove-color:hover {
    background: var(--danger);
    color: white;
}

/* Base color edit row */
.base-color-edit {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-top: 1px solid var(--border-light);
}

.base-color-edit input[type="text"] {
    flex: 1;
    padding: 4px 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text-primary);
    font-size: 12px;
    min-width: 0;
}

.base-color-edit .hex-input {
    width: 80px;
    font-family: var(--font-mono);
    font-size: 12px;
}

.base-color-edit input[type="color"] {
    width: 28px;
    height: 28px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 2px;
    cursor: pointer;
    background: var(--surface);
}

/* Layers */
.layers-container {
    border-top: 1px solid var(--border-light);
    padding: 8px 12px;
}

.base-color-card.collapsed .base-color-edit,
.base-color-card.collapsed .layers-container {
    display: none;
}

.layer-row {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 0;
}

.layer-number {
    font-size: 11px;
    color: var(--text-muted);
    width: 18px;
    text-align: right;
    flex-shrink: 0;
}

.layer-swatch {
    width: 22px;
    height: 22px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--swatch-border);
    flex-shrink: 0;
    background: var(--bg-tertiary);
}

.layer-swatch.filled {
    border-color: var(--border);
}

.layer-hex {
    flex: 1;
    padding: 3px 6px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 11px;
    min-width: 0;
}

.layer-hex::placeholder {
    color: var(--text-muted);
}

.btn-eyedropper {
    width: 26px;
    height: 26px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
    flex-shrink: 0;
}

.btn-eyedropper:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.btn-eyedropper.active {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}

/* Toolbox Actions */
.toolbox-actions {
    display: flex;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid var(--border-light);
}

.action-btn {
    flex: 1;
    padding: 10px 16px;
    border: none;
    border-radius: var(--radius-md);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: all var(--transition);
}

.btn-add {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.btn-add:hover {
    background: var(--accent);
    color: white;
}

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

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

.btn-export:disabled {
    opacity: 0.4;
    cursor: default;
}

/* Modals */
.modal {
    border: none;
    border-radius: var(--radius-lg);
    background: var(--surface);
    color: var(--text-primary);
    box-shadow: var(--shadow-lg);
    padding: 0;
    max-width: 560px;
    width: 90%;
}

.modal::backdrop {
    background: var(--overlay);
}

.modal-content {
    padding: 20px;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.modal-header h3 {
    font-size: 16px;
    font-weight: 600;
}

.modal-close {
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 50%;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--transition);
}

.modal-close:hover {
    background: var(--danger);
    color: white;
}

.modal-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.select-all-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    cursor: pointer;
}

/* Image Grid (manage modal) */
.image-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 8px;
    max-height: 400px;
    overflow-y: auto;
}

.image-grid-item {
    position: relative;
    aspect-ratio: 1;
    border-radius: var(--radius-md);
    overflow: hidden;
    border: 2px solid transparent;
    cursor: pointer;
    transition: border-color var(--transition);
}

.image-grid-item.selected {
    border-color: var(--accent);
}

.image-grid-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.image-grid-item .check-overlay {
    position: absolute;
    top: 4px;
    left: 4px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--bg-primary);
    border: 2px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
}

.image-grid-item.selected .check-overlay {
    background: var(--accent);
    border-color: var(--accent);
}

.image-grid-item.selected .check-overlay::after {
    content: '✓';
    color: white;
    font-size: 12px;
    font-weight: bold;
}

/* Settings */
.settings-body {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.setting-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 13px;
}

.setting-row select {
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text-primary);
    font-size: 13px;
}

.settings-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-top: 16px;
    border-top: 1px solid var(--border-light);
    margin-top: 8px;
}

.settings-link {
    font-size: 12px;
    color: var(--accent);
    text-decoration: none;
}

.settings-link:hover {
    text-decoration: underline;
}

.version-label {
    font-size: 11px;
    color: var(--text-muted);
}

/* Import modal */
.import-body p {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 16px;
}

.import-actions {
    display: flex;
    gap: 8px;
}

/* URL modal */
.url-body {
    display: flex;
    gap: 8px;
}

.url-field {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text-primary);
    font-size: 13px;
}

/* Toast notifications */
.toast-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    padding: 10px 16px;
    border-radius: var(--radius-md);
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-md);
    font-size: 13px;
    animation: toast-in 0.3s ease;
}

.toast.error {
    border-color: var(--danger);
    color: var(--danger);
}

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

@keyframes toast-in {
    from { transform: translateY(10px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}
