@import url('./modal.css');

:root {
    /* Premium Dark Theme - Slate Palette */
    --background: #0f172a;       /* Slate 900 */
    --surface: #1e293b;          /* Slate 800 */
    --surface-hover: #334155;    /* Slate 700 */
    --surface-active: #475569;   /* Slate 600 */
    --border-color: #334155;     /* Slate 700 */

    /* Accents */
    --primary-color: #6366f1;    /* Indigo 500 */
    --primary-hover: #4f46e5;    /* Indigo 600 */
    --primary-light: rgba(99, 102, 241, 0.2);
    --accent-color: #38bdf8;     /* Sky 400 */

    /* Text */
    --text-primary: #f8fafc;     /* Slate 50 */
    --text-secondary: #cbd5e1;   /* Slate 300 */
    --text-muted: #94a3b8;       /* Slate 400 */

    /* Form Elements */
    --input-bg: #020617;         /* Slate 950 */
    --input-border: #334155;     /* Slate 700 */
    --input-focus: #6366f1;      /* Indigo 500 */

    /* Status */
    --success-color: #10b981;    /* Emerald 500 */
    --danger-color: #ef4444;     /* Red 500 */
    --warning-color: #f59e0b;    /* Amber 500 */

    /* UI */
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 10px 10px -5px rgb(0 0 0 / 0.04);

    --radius: 0.5rem;      /* 8px */
    --radius-md: 0.75rem;  /* 12px */
    --radius-lg: 1rem;     /* 16px */
    --radius-pill: 9999px;

    /* Checkerboard for Transparency */
    --canvas-check-1: #1e293b;
    --canvas-check-2: #334155;

    /* Transitions */
    --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background-color: var(--background);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    /* Transition Support */
    opacity: 0;
    transition: opacity 0.4s ease-in;
}

body.fade-in {
    opacity: 1;
}

/* Typography */
h1, h2, h3, h4, h5, h6 {
    color: var(--text-primary);
    font-weight: 600;
    letter-spacing: -0.025em;
    line-height: 1.25;
}

h1 { font-size: 2.25rem; font-weight: 800; }
h2 { font-size: 1.5rem; font-weight: 700; }
h3 { font-size: 1.125rem; font-weight: 600; }

p {
    color: var(--text-secondary);
    margin-bottom: 1rem;
}

a {
    text-decoration: none;
    color: var(--primary-color);
    transition: var(--transition);
    font-weight: 500;
}

a:hover {
    color: var(--primary-hover);
}

/* --- Form Elements --- */

/* Text Inputs & Selects */
input[type="text"],
input[type="number"],
input[type="email"],
textarea,
select {
    appearance: none;
    background-color: var(--input-bg);
    border: 1px solid var(--input-border);
    border-radius: var(--radius);
    padding: 0.625rem 0.875rem; /* More padding */
    font-family: inherit;
    font-size: 0.875rem;
    color: var(--text-primary);
    width: 100%;
    transition: var(--transition);
    outline: none;
    box-shadow: var(--shadow-sm);
}

input[type="text"]:focus,
input[type="number"]:focus,
textarea:focus,
select:focus {
    border-color: var(--input-focus);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15); /* Soft focus ring */
}

input[type="text"]:hover,
input[type="number"]:hover,
textarea:hover,
select:hover {
    border-color: var(--text-secondary); /* Hint on hover */
}

input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

/* Range Inputs - Custom Design */
input[type="range"] {
    -webkit-appearance: none;
    width: 100%;
    height: 4px; /* Thinner track */
    background: var(--surface-active);
    border-radius: 999px;
    outline: none;
    margin: 12px 0;
    cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--text-primary);
    border: 2px solid var(--primary-color);
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    cursor: grab;
    transition: transform 0.1s ease, box-shadow 0.1s ease;
    margin-top: -6px; /* Center relative to 4px track */
}

input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.1);
    box-shadow: 0 0 0 4px var(--primary-light);
}

input[type="range"]::-webkit-slider-thumb:active {
    cursor: grabbing;
    transform: scale(1.05);
    background: var(--primary-color);
    border-color: var(--primary-color);
    box-shadow: 0 0 0 6px var(--primary-light);
}

input[type="range"]::-moz-range-thumb {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--text-primary);
    border: 2px solid var(--primary-color);
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    cursor: grab;
    transition: transform 0.1s ease, box-shadow 0.1s ease;
}

input[type="range"]::-moz-range-thumb:hover {
    transform: scale(1.1);
    box-shadow: 0 0 0 4px var(--primary-light);
}

/* Color Picker */
.color-picker-wrapper {
    position: relative;
    width: 100%;
    height: 42px;
    border-radius: var(--radius);
    overflow: hidden;
    border: 1px solid var(--input-border);
    cursor: pointer;
    background: var(--input-bg);
    transition: var(--transition);
    display: flex;
}

.color-picker-wrapper:hover {
    border-color: var(--text-secondary);
    box-shadow: var(--shadow-sm);
}

input[type="color"] {
    -webkit-appearance: none;
    appearance: none;
    border: none;
    width: 100%;
    height: 100%;
    padding: 0;
    margin: 0;
    background: transparent;
    cursor: pointer;
    opacity: 0;
    position: absolute;
    top: 0;
    left: 0;
    z-index: 2;
}

/* Pickr Overrides */
.pickr {
    width: 100%;
    height: 42px;
}

.pickr .pcr-button {
    width: 100% !important;
    height: 100% !important;
    border-radius: var(--radius) !important;
    border: 1px solid var(--input-border) !important;
    box-shadow: var(--shadow-sm);
}

.pickr-container {
    width: 100%;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.625rem 1.25rem;
    font-size: 0.9rem;
    font-weight: 600;
    border-radius: var(--radius-md); /* Rounded Rect */
    cursor: pointer;
    transition: var(--transition);
    border: 1px solid transparent;
    user-select: none;
    position: relative;
    overflow: hidden;
}

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

/* Primary Button with Subtle Glow */
.btn.primary {
    background-color: var(--primary-color);
    color: white;
    box-shadow: 0 4px 6px -1px rgba(99, 102, 241, 0.3), 0 2px 4px -1px rgba(99, 102, 241, 0.1);
}

.btn.primary:hover:not(:disabled) {
    background-color: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 8px 12px -2px rgba(99, 102, 241, 0.4);
}

.btn.primary:active:not(:disabled) {
    transform: translateY(0);
    box-shadow: 0 2px 4px -1px rgba(99, 102, 241, 0.3);
}

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

.btn.secondary:hover:not(:disabled) {
    background-color: var(--surface-hover);
    border-color: var(--text-muted);
    transform: translateY(-1px);
    box-shadow: var(--shadow);
}

.btn.secondary:active:not(:disabled) {
    transform: translateY(0);
    box-shadow: none;
}

/* Active Icon Button (Favorites) */
.btn.icon-btn.active {
    color: #fbbf24; /* Amber 400 */
    border-color: rgba(251, 191, 36, 0.4);
    background: rgba(251, 191, 36, 0.1);
}

.btn.ghost {
    background: transparent;
    color: var(--text-secondary);
}

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

/* Toggle Switch */
.toggle-switch {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    cursor: pointer;
    padding: 0.5rem 0;
    user-select: none;
}

.toggle-switch input { display: none; }

.toggle-switch .slider {
    position: relative;
    width: 44px;
    height: 24px;
    background-color: var(--surface-active);
    border-radius: 99px;
    transition: var(--transition);
    flex-shrink: 0;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.1);
}

.toggle-switch .slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    border-radius: 50%;
    transition: var(--transition);
    box-shadow: 0 1px 2px rgba(0,0,0,0.2);
}

.toggle-switch input:checked + .slider {
    background-color: var(--primary-color);
}

.toggle-switch input:checked + .slider:before {
    transform: translateX(20px);
}

.label-text {
    color: var(--text-primary);
    font-size: 0.9rem;
    font-weight: 500;
}

/* File Upload */
.file-upload-wrapper {
    position: relative;
    width: 100%;
}

.file-upload-wrapper input[type="file"] {
    position: absolute;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
    z-index: 10;
}

.file-upload-label {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 1rem;
    background: rgba(99, 102, 241, 0.03);
    border: 2px dashed var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-weight: 500;
    transition: var(--transition);
}

.file-upload-wrapper:hover .file-upload-label {
    border-color: var(--primary-color);
    background: rgba(99, 102, 241, 0.08);
    transform: translateY(-1px);
}

/* Utilities */
.hidden { display: none !important; }
.flex { display: flex; }
.flex-col { display: flex; flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 0.5rem; }
.gap-4 { gap: 1rem; }
.mt-2 { margin-top: 0.5rem; }
.mt-4 { margin-top: 1rem; }
.mb-4 { margin-bottom: 1rem; }
.w-full { width: 100%; }

.col {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

/* Glass Effect */
.glass {
    background: rgba(30, 41, 59, 0.7);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.05);
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 0;
    height: 0;
    display: none;
}

html {
    scrollbar-width: none;
}

/* --- Modals (Shared: Help, Settings, Search) --- */
.help-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.help-btn:hover {
    background: var(--surface-active);
    color: var(--primary-color);
    transform: scale(1.1);
}

.help-btn svg {
    width: 20px;
    height: 20px;
    stroke-width: 2.5;
}

.help-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.help-modal-overlay.active {
    opacity: 1;
    pointer-events: all;
}

.help-modal-content {
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 700px;
    box-shadow: var(--shadow-xl);
    transform: translateY(20px) scale(0.95);
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    display: flex;
    flex-direction: column;
    max-height: 85vh;
    overflow: hidden;
    position: relative;
}

.help-modal-overlay.active .help-modal-content {
    transform: translateY(0) scale(1);
}

/* Close Button (Absolute) */
.help-close-btn {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: rgba(0, 0, 0, 0.3);
    border: none;
    color: white;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 50%;
    transition: var(--transition);
    display: flex;
    z-index: 10;
    backdrop-filter: blur(4px);
}

.help-close-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: rotate(90deg);
}

/* Hero Section */
.help-hero {
    position: relative;
    height: 220px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    flex-shrink: 0;
}

.help-hero-bg {
    position: absolute;
    inset: 0;
    background-size: cover;
    background-position: center;
    opacity: 0.4;
    transition: filter 0.3s ease;
}

/* Tool Specific Effects on Hero BG */
.help-hero-bg[data-tool="greyscale"] { filter: grayscale(1); }
.help-hero-bg[data-tool="blur"] { filter: blur(4px); }
.help-hero-bg[data-tool="pixelify"] { image-rendering: pixelated; filter: contrast(1.2); }
.help-hero-bg[data-tool="border"] { box-shadow: inset 0 0 0 10px rgba(255,255,255,0.2); }
.help-hero-bg[data-tool="round-corners"] { border-radius: 30px; transform: scale(0.9); }

/* Overlay gradient for legibility */
.help-hero::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(to bottom, transparent 0%, var(--surface) 100%);
}

.help-hero-content {
    position: relative;
    z-index: 5;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

.help-hero-icon {
    font-size: 4.5rem;
    margin-bottom: 0.5rem;
    filter: drop-shadow(0 4px 12px rgba(0,0,0,0.3));
    animation: floatIcon 3s ease-in-out infinite;
}

@keyframes floatIcon {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-12px); }
}

.help-hero-title {
    font-size: 2rem;
    font-weight: 800;
    color: white;
    text-shadow: 0 2px 4px rgba(0,0,0,0.5);
    margin: 0;
}

/* Body */
.help-modal-body {
    padding: 1.5rem 2rem 2rem;
    overflow-y: auto;
    color: var(--text-secondary);
}

.help-description {
    font-size: 1.05rem;
    line-height: 1.6;
    margin-bottom: 2rem;
    text-align: center;
    color: var(--text-primary);
    max-width: 80%;
    margin-left: auto;
    margin-right: auto;
}

.help-section-title {
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-muted);
    font-weight: 700;
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.help-section-title::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border-color);
    opacity: 0.5;
}

/* Steps Grid */
.help-steps-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.help-step-card {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border-color);
    padding: 1rem;
    border-radius: var(--radius);
    display: flex;
    gap: 0.75rem;
    align-items: flex-start;
    transition: var(--transition);
    opacity: 0;
    animation: slideUpFade 0.5s ease-out forwards;
}

.help-step-card:hover {
    background: var(--surface-active);
    transform: translateY(-2px);
    border-color: var(--primary-color);
}

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

.step-badge {
    background: var(--primary-color);
    color: white;
    font-weight: 700;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    flex-shrink: 0;
    margin-top: 2px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.step-text {
    font-size: 0.95rem;
    line-height: 1.5;
}

/* --- Tips Section --- */
.help-tips-container {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.help-tip-card {
    display: flex;
    gap: 0.75rem;
    align-items: flex-start;
    padding: 1rem;
    background: rgba(255, 193, 7, 0.1);
    border: 1px solid rgba(255, 193, 7, 0.2);
    border-radius: var(--radius);
    color: var(--text-primary);
    opacity: 0;
    animation: slideUpFade 0.5s ease-out forwards;
}

.help-tip-card:hover {
    background: rgba(255, 193, 7, 0.15);
    border-color: rgba(255, 193, 7, 0.4);
}

.tip-icon {
    font-size: 1.25rem;
    flex-shrink: 0;
    line-height: 1;
    margin-top: 2px;
}

.tip-text {
    font-size: 0.95rem;
    line-height: 1.5;
    color: var(--text-secondary);
}

.help-tip-card:hover .tip-text {
    color: var(--text-primary);
}

/* Mobile */
@media (max-width: 600px) {
    .help-steps-grid {
        grid-template-columns: 1fr;
    }

    .help-hero {
        height: 180px;
    }

    .help-hero-icon {
        font-size: 3.5rem;
    }

    .help-description {
        max-width: 100%;
        font-size: 1rem;
        text-align: left;
    }
}

/* --- Image Search Styles --- */
.search-results-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 0.75rem;
    padding: 1rem;
}

.search-result-item {
    position: relative;
    width: 100%;
    padding-bottom: 100%; /* Robust Square Aspect Ratio Hack */
    height: 0;
    border-radius: var(--radius);
    overflow: hidden;
    cursor: pointer;
    background: var(--surface);
    transition: var(--transition);
    border: 2px solid transparent;
}

.search-result-item:hover {
    transform: scale(1.02);
    border-color: var(--primary-color);
    box-shadow: var(--shadow-lg);
    z-index: 1;
}

.search-result-item img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover !important;
    display: block;
}

.search-buttons-row {
    margin-top: 0.5rem;
}

/* --- Tool Icons & Images (Shared for consistency) --- */
.select-icon-img {
    width: 20px;
    height: 20px;
    object-fit: contain;
    border-radius: 4px;
    vertical-align: middle;
}

.empty-state-img {
    width: 80px;
    height: 80px;
    object-fit: contain;
    border-radius: 12px;
    margin-bottom: 1.5rem;
    opacity: 0.8;
    filter: drop-shadow(0 4px 6px rgba(0,0,0,0.1));
    transition: transform 0.3s ease;
}

.empty-state:hover .empty-state-img {
    transform: scale(1.1) rotate(5deg);
    opacity: 1;
}

.tool-header-icon {
    width: 32px;
    height: 32px;
    object-fit: contain;
    border-radius: 6px;
    margin-right: 0.75rem;
    vertical-align: middle;
}

.help-hero-img {
    width: 80px;
    height: 80px;
    object-fit: contain;
    border-radius: 12px;
    filter: drop-shadow(0 4px 12px rgba(0,0,0,0.3));
    animation: floatIcon 3s ease-in-out infinite;
}
