/* ============================================
   Bulk Image Downloader + YouTube Thumbnails
   Dark Mode Support with Light Mode Default
   Forest Green Theme (#2d8659)
   Complement: Warm Gold (#c49a3c)
   Overrides custom_styles.css
   ============================================ */

/* ============================================
   OVERRIDE CUSTOM_STYLES.CSS VARIABLES
   ============================================ */
:root {
    --transition-speed: 0.25s;

    /* Primary Colors - Forest Green */
    --primary: #2d8659;
    --primary-light: #e6f4ed;
    --primary-dark: #24704a;
    --accent: #38a06e;

    /* Complement - Warm Gold */
    --gold: #c49a3c;
    --gold-light: #fdf6e3;
    --gold-dark: #a6812f;

    /* Override custom_styles.css globals */
    --accent-color: #2d8659;
    --accent-hover: #24704a;
    --link-color: #2d8659;
    --link-hover: #c49a3c;
    --input-focus-border: #2d8659;

    /* Status Colors */
    --success: #10b981;
    --success-color: #10b981;
    --success-light: #d1fae5;
    --success-bg: #e7f7ed;
    --warning: #c49a3c;
    --warning-light: #fdf6e3;
    --danger: #ef4444;
    --danger-light: #fee2e2;
    --error-color: #ef4444;
    --info-color: #2d8659;
    --info-bg: #e6f4ed;

    /* Background Colors */
    --bg: #f2f9f5;
    --bg-elevated: #ffffff;
    --bg-secondary: #eaf5ef;
    --bg-tertiary: #d4eddf;
    --body-bg: #f2f9f5;

    /* Text Colors */
    --text: #1a3a2a;
    --text-secondary: #2d5040;
    --text-muted: #5f7268;
    --text-primary: #1a3a2a;

    /* Border Colors */
    --border: #c3dece;
    --border-light: #dceee4;
    --border-color: #c3dece;

    /* Shadows */
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.08);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.08);
    --shadow-xl: 0 20px 25px -5px rgba(0,0,0,0.1);
    --shadow-primary: 0 4px 14px rgba(45, 134, 89, 0.2);
    --shadow-primary-hover: 0 6px 20px rgba(45, 134, 89, 0.3);

    /* Radius */
    --radius-sm: 6px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    --radius-full: 9999px;

    /* Checkerboard */
    --checker-light: #f3f4f6;
    --checker-dark: #e5e7eb;

    /* Input */
    --input-bg: #ffffff;
    --input-border: #c3dece;

    /* Tab Colors */
    --tab-bg: #eaf5ef;
    --tab-text: #5f7268;
    --tab-hover-bg: #d4eddf;
    --tab-hover-text: #1a3a2a;
    --tab-active-bg: #ffffff;
    --tab-active-text: #2d8659;

    /* Button overrides for custom_styles.css */
    --button-primary-bg: #2d8659;
    --button-primary-text: #ffffff;
    --button-primary-hover: #24704a;
}

/* ============================================
   DARK MODE
   ============================================ */
[data-theme="dark"] {
    --primary: #4aba80;
    --primary-light: rgba(74, 186, 128, 0.12);
    --primary-dark: #2d8659;
    --accent: #6ee7a8;
    --gold: #d4aa4c;
    --gold-light: rgba(212, 170, 76, 0.12);

    --accent-color: #4aba80;
    --accent-hover: #2d8659;
    --link-color: #4aba80;
    --link-hover: #d4aa4c;
    --input-focus-border: #4aba80;

    --success: #34d399;
    --success-color: #34d399;
    --success-light: rgba(52, 211, 153, 0.15);
    --warning: #d4aa4c;
    --warning-light: rgba(212, 170, 76, 0.15);
    --danger: #f87171;
    --danger-light: rgba(248, 113, 113, 0.15);
    --info-color: #4aba80;
    --info-bg: rgba(74, 186, 128, 0.12);

    --bg: #0d1a13;
    --bg-elevated: #162a1f;
    --bg-secondary: #1c3628;
    --bg-tertiary: #264a34;
    --body-bg: #0d1a13;

    --text: #e6f4ed;
    --text-secondary: #c3dece;
    --text-muted: #8faa98;
    --text-primary: #e6f4ed;

    --border: #264a34;
    --border-light: #1c3628;
    --border-color: #264a34;

    --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.4);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.35);
    --shadow-xl: 0 20px 25px -5px rgba(0,0,0,0.5);
    --shadow-primary: 0 4px 14px rgba(74, 186, 128, 0.15);
    --shadow-primary-hover: 0 6px 20px rgba(74, 186, 128, 0.25);

    --checker-light: #1c3628;
    --checker-dark: #264a34;

    --input-bg: #1c3628;
    --input-border: #264a34;

    --tab-bg: #162a1f;
    --tab-text: #8faa98;
    --tab-hover-bg: #264a34;
    --tab-hover-text: #e6f4ed;
    --tab-active-bg: #264a34;
    --tab-active-text: #6ee7a8;

    --button-primary-bg: #4aba80;
    --button-primary-text: #ffffff;
    --button-primary-hover: #6ee7a8;

    --card-bg: #162a1f;
    --card-secondary: #1c3628;
    --card-tertiary: #264a34;
    --bg-elevated: #162a1f;
}

/* ============================================
   BASE STYLES
   ============================================ */
* {
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    margin: 0;
    padding: 0;
    transition: background-color var(--transition-speed), color var(--transition-speed);
}

/* ============================================
   TOOL LAYOUT
   ============================================ */
.tool-container {
    max-width: 1000px;
    margin: 0 auto;
    padding: 2rem;
}

/* Header */
.tool-header {
    text-align: center;
    margin-bottom: 2rem;
}

.tool-title-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    margin-bottom: 1rem;
}

.tool-icon-wrapper {
    width: 64px;
    height: 64px;
    background: var(--primary);
    border-radius: var(--radius-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    box-shadow: var(--shadow-primary);
}

.tool-icon-wrapper svg {
    width: 32px;
    height: 32px;
}

.tool-title {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--primary);
    margin: 0;
}

.tool-description {
    font-size: 1.1rem;
    color: var(--text-muted);
    max-width: 800px;
    margin: 0 auto;
    line-height: 1.7;
}

.tool-description a {
    color: var(--primary);
    text-decoration: none;
}

.tool-description a:hover {
    text-decoration: underline;
}

/* ============================================
   MAIN CARD
   ============================================ */
.tool-main {
    background: var(--bg-elevated);
    border-radius: var(--radius-xl);
    padding: 2rem;
    box-shadow: var(--shadow-lg);
    margin-bottom: 2rem;
}

/* ============================================
   MODE TABS (pill style)
   ============================================ */
.mode-tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    background: var(--tab-bg);
    padding: 0.375rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
}

.mode-tab {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.875rem 1.5rem;
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--tab-text);
    cursor: pointer;
    transition: all var(--transition-speed);
}

.mode-tab:hover {
    color: var(--tab-hover-text);
    background: var(--tab-hover-bg);
}

.mode-tab.active {
    background: var(--tab-active-bg);
    color: var(--tab-active-text);
    box-shadow: var(--shadow-sm);
    font-weight: 600;
}

.mode-tab svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

/* ============================================
   INPUT SECTIONS
   ============================================ */
.tab-content {
    width: 100%;
}

.input-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.input-icon {
    width: 24px;
    height: 24px;
    color: var(--primary);
}

.input-header h2 {
    font-size: 1.25rem;
    font-weight: 600;
    margin: 0;
    color: var(--text);
}

.input-group {
    margin-bottom: 1rem;
}

.input-group label {
    display: block;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 0.5rem;
}

.url-input-wrapper {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.url-input {
    flex: 1;
    padding: 1rem 1.25rem;
    font-size: 1rem;
    border: 1px solid var(--input-border);
    border-radius: var(--radius-md);
    background: var(--input-bg);
    color: var(--text);
    transition: border-color var(--transition-speed), box-shadow var(--transition-speed);
}

.url-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.url-input::placeholder {
    color: var(--text-muted);
}

textarea.url-input {
    min-height: 120px;
    resize: vertical;
    width: 100%;
}

/* URL type detection badges */
.url-type-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.375rem 0.75rem;
    border-radius: var(--radius-full);
    font-size: 0.8rem;
    font-weight: 600;
    margin-top: 0.75rem;
}

.url-type-badge svg {
    width: 14px;
    height: 14px;
}

.badge-youtube {
    background: #fee2e2;
    color: #dc2626;
}

[data-theme="dark"] .badge-youtube {
    background: rgba(220, 38, 38, 0.15);
    color: #f87171;
}

.badge-webpage {
    background: var(--primary-light);
    color: var(--primary);
}

.badge-image {
    background: var(--gold-light);
    color: var(--gold);
}

/* ============================================
   BUTTONS
   ============================================ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.875rem 1.75rem;
    font-size: 1rem;
    font-weight: 600;
    border-radius: var(--radius-md);
    border: none;
    cursor: pointer;
    transition: all var(--transition-speed);
    white-space: nowrap;
}

.btn svg {
    width: 18px;
    height: 18px;
}

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

.btn-primary:hover:not(:disabled) {
    background: var(--primary-dark);
    box-shadow: var(--shadow-primary-hover);
    transform: translateY(-1px);
}

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

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

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

.btn-outline {
    background: transparent;
    color: var(--text);
    border: 1px solid var(--border);
}

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

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

.btn-success:hover:not(:disabled) {
    filter: brightness(1.1);
}

.btn-fetch {
    width: 100%;
    padding: 1rem;
}

.btn-text {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.5rem 0.75rem;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-speed);
    border-radius: var(--radius-sm);
}

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

.btn-sm {
    padding: 0.5rem 0.75rem;
    font-size: 0.85rem;
}

.btn-sm svg {
    width: 16px;
    height: 16px;
}

/* ============================================
   LOADING SECTION
   ============================================ */
.loading-section {
    text-align: center;
    padding: 3rem;
}

.loading-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.loading-spinner {
    width: 64px;
    height: 64px;
    margin: 0 auto 1.5rem;
    border: 4px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.loading-text {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 0.5rem;
}

.loading-subtext {
    font-size: 0.95rem;
    color: var(--text-muted);
}

/* ============================================
   RESULTS SECTION
   ============================================ */
.results-section {
    display: none;
    padding: 1.5rem 0;
}

.results-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.results-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text);
}

.results-title svg {
    color: var(--primary);
}

.results-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 24px;
    padding: 0.125rem 0.5rem;
    background: var(--primary);
    color: white;
    border-radius: var(--radius-full);
    font-size: 0.75rem;
    font-weight: 600;
    margin-left: 0.5rem;
}

.results-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

/* Image grid */
.image-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 1rem;
    max-height: 500px;
    overflow-y: auto;
    padding: 0.5rem;
    margin-bottom: 1.5rem;
}

.image-card {
    position: relative;
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    overflow: hidden;
    border: 2px solid transparent;
    transition: all var(--transition-speed);
    cursor: pointer;
}

.image-card:hover {
    border-color: var(--primary);
    box-shadow: var(--shadow-md);
}

.image-card.selected {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px var(--primary);
}

.image-card-check {
    position: absolute;
    top: 0.5rem;
    left: 0.5rem;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: rgba(255,255,255,0.9);
    border: 2px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2;
    transition: all 0.2s;
}

.image-card.selected .image-card-check {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

.image-card-check svg {
    width: 14px;
    height: 14px;
    opacity: 0;
}

.image-card.selected .image-card-check svg {
    opacity: 1;
}

.image-card-preview {
    width: 100%;
    aspect-ratio: 16 / 10;
    background: repeating-conic-gradient(var(--checker-light) 0% 25%, var(--checker-dark) 0% 50%) 50% / 16px 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.image-card-preview img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.image-card-info {
    padding: 0.625rem;
}

.image-card-name {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 0.25rem;
}

.image-card-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.75rem;
    color: var(--text-muted);
}

.image-card-size {
    font-weight: 500;
}

.image-card-dims {
    color: var(--primary);
    font-weight: 500;
}

/* YouTube thumbnail quality labels */
.yt-quality-label {
    display: inline-block;
    padding: 0.2rem 0.5rem;
    border-radius: var(--radius-sm);
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    z-index: 2;
}

.yt-quality-hd {
    background: #dc2626;
    color: #fff;
}

.yt-quality-sd {
    background: var(--gold);
    color: #fff;
}

.yt-quality-low {
    background: #6b7280;
    color: #fff;
}

/* Scrollbar */
.image-grid::-webkit-scrollbar {
    width: 8px;
}

.image-grid::-webkit-scrollbar-track {
    background: var(--bg-secondary);
    border-radius: 4px;
}

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

.image-grid::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* ============================================
   SUCCESS SECTION
   ============================================ */
.success-section {
    text-align: center;
    padding: 3rem;
    display: none;
}

.success-content {
    max-width: 500px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* Override custom_styles.css success icon */
.success-section .success-icon,
#successSection .success-icon {
    width: 80px !important;
    height: 80px !important;
    margin: 0 auto 1.5rem auto !important;
    background: var(--primary-light) !important;
    border-radius: 50% !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    color: var(--primary) !important;
    font-size: inherit !important;
}

.success-section .success-icon svg,
#successSection .success-icon svg {
    width: 40px !important;
    height: 40px !important;
}

[data-theme="dark"] .success-section .success-icon,
[data-theme="dark"] #successSection .success-icon {
    background: rgba(74, 186, 128, 0.15) !important;
    color: #4aba80 !important;
}

.success-section h2 {
    font-size: 1.5rem;
    font-weight: 700;
    margin: 0 0 0.5rem 0;
    color: var(--primary);
}

#successMessage {
    font-size: 1rem;
    color: var(--text-muted);
    margin-bottom: 1.5rem;
}

.next-actions {
    padding: 1.25rem;
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    margin-bottom: 1.5rem;
    width: 100%;
}

.next-label {
    display: block;
    font-size: 0.875rem;
    color: var(--text-muted);
    margin-bottom: 0.75rem;
}

.next-links {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    justify-content: center;
}

.next-link {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.5rem 0.875rem;
    background: var(--bg-tertiary);
    border-radius: var(--radius-full);
    color: var(--text);
    text-decoration: none;
    font-size: 0.875rem;
    transition: all var(--transition-speed);
}

.next-link:hover {
    background: var(--primary-light);
    color: var(--primary);
}

.next-link svg {
    width: 16px;
    height: 16px;
}

/* ============================================
   ERROR / INFO MESSAGES
   ============================================ */
.message-box {
    display: none;
    padding: 1rem 1.25rem;
    border-radius: var(--radius-md);
    margin: 1rem 0;
    font-size: 0.95rem;
    line-height: 1.5;
}

.message-box svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.message-error {
    background: var(--danger-light);
    color: var(--danger);
}

.message-success {
    background: var(--success-light);
    color: var(--success);
}

.message-info {
    background: var(--primary-light);
    color: var(--primary);
}

/* ============================================
   SPIN ANIMATION
   ============================================ */
.spin {
    animation: spin 1s linear infinite;
}

/* ============================================
   INFO CARDS
   ============================================ */
.info-sections {
    margin-top: 3rem;
}

.info-card {
    background: var(--bg-elevated);
    border-radius: var(--radius-xl);
    padding: 2rem;
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow-md);
}

.info-card h2 {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 1.5rem;
    font-weight: 700;
    margin: 0 0 1.5rem 0;
    color: var(--primary);
}

.info-card h2 svg {
    color: var(--primary);
}

.info-card p {
    color: var(--text-muted);
    line-height: 1.7;
    margin-bottom: 0.75rem;
    font-size: 0.95rem;
}

.info-card p:last-child {
    margin-bottom: 0;
}

.info-card a {
    color: var(--primary);
    text-decoration: none;
}

.info-card a:hover {
    text-decoration: underline;
    color: var(--gold);
}

.info-card code {
    background: var(--bg-secondary);
    padding: 0.15rem 0.4rem;
    border-radius: 4px;
    font-size: 0.9em;
    color: var(--text);
}

/* Features Grid */
.features-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1.5rem;
}

.feature-item {
    padding: 1.25rem;
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    transition: box-shadow var(--transition-speed);
}

.feature-item:hover {
    box-shadow: var(--shadow-sm);
}

.feature-item svg {
    color: var(--primary);
    margin-bottom: 0.75rem;
}

.feature-item h4 {
    font-size: 1rem;
    font-weight: 600;
    margin: 0 0 0.5rem 0;
    color: var(--text);
}

.feature-item p {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin: 0;
    line-height: 1.5;
}

/* Related tools */
.related-tools {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 1rem;
}

.related-link {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.5rem 0.875rem;
    background: var(--bg-secondary);
    border-radius: var(--radius-full);
    color: var(--text);
    text-decoration: none;
    font-size: 0.875rem;
    transition: all var(--transition-speed);
}

.related-link:hover {
    background: var(--primary-light);
    color: var(--primary);
}

.related-link svg {
    width: 16px;
    height: 16px;
}

/* FAQ override - ensure green accent inside info-card context */
.info-card .faq-item:hover {
    border-color: var(--primary);
}

.info-card .faq-question svg {
    color: var(--primary);
}

.info-card .faq-answer a {
    color: var(--primary);
}

.info-card .faq-answer a:hover {
    color: var(--gold);
    text-decoration: underline;
}

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 768px) {
    .tool-container {
        padding: 1rem;
    }

    .tool-title {
        font-size: 1.75rem;
    }

    .tool-icon-wrapper {
        width: 48px;
        height: 48px;
    }

    .tool-icon-wrapper svg {
        width: 24px;
        height: 24px;
    }

    .tool-main {
        padding: 1.25rem;
    }

    .mode-tabs {
        flex-direction: column;
    }

    .url-input-wrapper {
        flex-direction: column;
    }

    .image-grid {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
        gap: 0.75rem;
    }

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

    .results-actions {
        width: 100%;
    }

    .results-actions .btn {
        flex: 1;
    }

    .info-card {
        padding: 1.5rem;
    }

    .features-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 480px) {
    .image-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.5rem;
    }

    .image-card-info {
        padding: 0.5rem;
    }
}
