/* ============================================
   Converter Tool - Shared Styling
   Dark mode support, light default
   ============================================ */

:root {
    --transition-speed: 0.25s;
    --primary: #3399cc;
    --primary-light: #E0F4FF;
    --primary-dark: #2980b9;
    --accent: #38BDF8;
    --success: #339966;
    --success-light: #D1FAE5;
    --warning: #F59E0B;
    --warning-light: #FEF3C7;
    --danger: #e64e4e;
    --danger-light: #FEE2E2;
    --bg: #F8FAFC;
    --bg-elevated: #FFFFFF;
    --bg-secondary: #F1F5F9;
    --bg-tertiary: #E2E8F0;
    --text: #1E293B;
    --text-secondary: #475569;
    --text-muted: #64748B;
    --border: #E2E8F0;
    --border-light: #F1F5F9;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1);
    --shadow-xl: 0 20px 25px -5px rgba(0,0,0,0.1);
    --shadow-primary: 0 4px 14px rgba(51,153,204,0.25);
    --shadow-primary-hover: 0 6px 20px rgba(51,153,204,0.35);
    --radius-sm: 6px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    --radius-full: 9999px;
    --checker-light: #f0f0f0;
    --checker-dark: #e0e0e0;
    --input-bg: #FFFFFF;
    --input-border: #E2E8F0;
}

[data-theme="dark"] {
    --primary: #38BDF8;
    --primary-light: rgba(56,189,248,0.15);
    --primary-dark: #0EA5E9;
    --accent: #7DD3FC;
    --success: #4ADE80;
    --success-light: rgba(74,222,128,0.15);
    --warning: #FBBF24;
    --warning-light: rgba(251,191,36,0.15);
    --danger: #F87171;
    --danger-light: rgba(248,113,113,0.15);
    --bg: #0F172A;
    --bg-elevated: #1E293B;
    --bg-secondary: #334155;
    --bg-tertiary: #475569;
    --text: #F1F5F9;
    --text-secondary: #CBD5E1;
    --text-muted: #94A3B8;
    --border: #334155;
    --border-light: #475569;
    --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.4);
    --shadow-xl: 0 20px 25px -5px rgba(0,0,0,0.5);
    --shadow-primary: 0 4px 14px rgba(56,189,248,0.2);
    --shadow-primary-hover: 0 6px 20px rgba(56,189,248,0.3);
    --checker-light: #334155;
    --checker-dark: #475569;
    --input-bg: #334155;
    --input-border: #475569;
}

* { 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-container { max-width: 1000px; margin: 0 auto; padding: 2rem; }
.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);
    flex-shrink: 0;
}

.tool-icon-wrapper svg, .tool-icon-wrapper i { width: 28px; height: 28px; }

.tool-title {
    font-size: clamp(1.75rem, 4vw, 2.5rem);
    font-weight: 700; margin: 0;
    color: var(--primary);
    letter-spacing: -0.02em;
}

.tool-description {
    font-size: 1.1rem; color: var(--text-secondary);
    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; }

.tool-main {
    background: var(--bg-elevated);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl);
    overflow: hidden;
    border: 1px solid var(--border);
    margin-bottom: 2rem;
    position: relative;
    transition: background-color var(--transition-speed), border-color var(--transition-speed);
}

/* Upload */
.upload-section { padding: 3rem; }

.upload-area {
    border: 2px dashed var(--border);
    border-radius: var(--radius-lg);
    padding: 4rem 2rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    background: var(--bg-secondary);
    position: relative; overflow: hidden;
}

.upload-area::before {
    content: ''; position: absolute; inset: 0;
    background: var(--primary-light);
    opacity: 0; transition: opacity 0.3s ease;
}

.upload-area:hover, .upload-area.drag-over {
    border-color: var(--primary); background: var(--bg);
    transform: translateY(-2px); box-shadow: var(--shadow-md);
}

.upload-area:hover::before, .upload-area.drag-over::before { opacity: 0.5; }
.upload-content { position: relative; z-index: 1; }
.upload-icon { color: var(--primary); margin-bottom: 1.5rem; transition: transform 0.3s ease; }
.upload-area:hover .upload-icon { transform: translateY(-5px); }

.upload-title { font-size: 1.5rem; font-weight: 600; color: var(--text); margin: 0 0 0.5rem; }
.upload-subtitle { color: var(--text-secondary); margin: 0 0 1rem; font-size: 1rem; }

.file-types { display: flex; gap: 0.4rem; justify-content: center; flex-wrap: wrap; margin-bottom: 1rem; }

.file-type-badge {
    background: var(--primary-light); color: var(--primary);
    padding: 0.3rem 0.7rem; border-radius: var(--radius-full);
    font-size: 0.75rem; font-weight: 600;
}

.upload-hint {
    display: inline-flex; align-items: center; gap: 0.5rem;
    color: var(--success); font-size: 0.875rem; font-weight: 500;
}

/* Editor */
.editor-section { padding: 2rem; animation: fadeIn 0.4s ease; }

.preview-area {
    background: var(--bg-secondary);
    border: 2px solid var(--border);
    border-radius: var(--radius-md);
    padding: 1rem;
    margin-bottom: 1.5rem;
    text-align: center;
    min-height: 200px;
    display: flex; align-items: center; justify-content: center;
    background-image:
        linear-gradient(45deg, var(--checker-dark) 25%, transparent 25%),
        linear-gradient(-45deg, var(--checker-dark) 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, var(--checker-dark) 75%),
        linear-gradient(-45deg, transparent 75%, var(--checker-dark) 75%);
    background-size: 16px 16px;
    background-position: 0 0, 0 8px, 8px -8px, -8px 0;
}

.preview-area img {
    max-width: 100%; max-height: 500px; object-fit: contain;
    border-radius: var(--radius-sm);
}

.file-info {
    display: flex; flex-wrap: wrap; gap: 1.5rem;
    justify-content: center; padding: 0.75rem 0; margin-bottom: 1rem;
}

.file-info-item {
    display: flex; align-items: center; gap: 0.4rem;
    color: var(--text-secondary); font-size: 0.9rem; font-weight: 500;
}

.file-info-item svg, .file-info-item i { color: var(--primary); }

/* Settings */
.settings-panel {
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    border: 1px solid var(--border);
}

.settings-title {
    display: flex; align-items: center; gap: 0.5rem;
    font-size: 1rem; font-weight: 600;
    color: var(--text); margin: 0 0 1.25rem;
}

.settings-title svg, .settings-title i { color: var(--primary); }

.settings-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1.25rem;
}

.setting-group label {
    display: block; font-size: 0.85rem;
    font-weight: 600; color: var(--text-secondary);
    margin-bottom: 0.4rem;
}

.setting-group select,
.setting-group input[type="text"],
.setting-group input[type="number"] {
    width: 100%; padding: 0.6rem 0.75rem;
    border: 1px solid var(--input-border);
    border-radius: var(--radius-sm);
    background: var(--input-bg); color: var(--text);
    font-size: 0.9rem; transition: border-color 0.2s;
}

.setting-group select:focus,
.setting-group input:focus {
    outline: none; border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(51,153,204,0.15);
}

.setting-group input[type="range"] { width: 100%; accent-color: var(--primary); }
.range-row { display: flex; align-items: center; gap: 0.75rem; }

.range-value {
    font-weight: 600; color: var(--primary);
    font-size: 0.9rem; min-width: 40px; text-align: center;
}

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

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

.color-row input[type="text"] { flex: 1; }

/* Buttons */
.action-bar {
    display: flex; gap: 0.75rem;
    justify-content: center; flex-wrap: wrap;
    padding: 0.5rem 0;
}

.tool-btn {
    display: inline-flex; align-items: center; justify-content: center;
    gap: 0.5rem; padding: 0.875rem 1.75rem;
    border-radius: var(--radius-full);
    font-size: 1rem; font-weight: 600;
    cursor: pointer; transition: all 0.2s ease;
    text-decoration: none; border: none;
}

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

.tool-btn-primary:hover {
    background: var(--primary-dark);
    transform: translateY(-2px);
    box-shadow: var(--shadow-primary-hover);
}

.tool-btn-primary:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

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

.tool-btn-secondary:hover { background: var(--bg-tertiary); transform: translateY(-2px); }

.tool-btn-success {
    background: var(--success); color: white;
    box-shadow: 0 4px 14px rgba(51,153,102,0.25);
}

.tool-btn-success:hover { filter: brightness(1.1); transform: translateY(-2px); }

/* Results */
.results-section { padding: 2rem; animation: fadeIn 0.4s ease; }

.result-card {
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    padding: 1.5rem;
    margin-bottom: 1rem;
    border: 1px solid var(--border);
    text-align: center;
}

.result-preview {
    margin-bottom: 1rem;
    background-image:
        linear-gradient(45deg, var(--checker-dark) 25%, transparent 25%),
        linear-gradient(-45deg, var(--checker-dark) 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, var(--checker-dark) 75%),
        linear-gradient(-45deg, transparent 75%, var(--checker-dark) 75%);
    background-size: 16px 16px;
    background-position: 0 0, 0 8px, 8px -8px, -8px 0;
    border-radius: var(--radius-sm);
    padding: 1rem; display: inline-block;
}

.result-preview img {
    max-width: 100%; max-height: 400px;
    object-fit: contain; border-radius: var(--radius-sm);
}

.result-stats {
    display: flex; flex-wrap: wrap; gap: 1.5rem;
    justify-content: center; margin-bottom: 1rem;
}

.result-stat {
    display: flex; align-items: center; gap: 0.4rem;
    font-size: 0.9rem; color: var(--text-secondary); font-weight: 500;
}

.result-stat svg, .result-stat i { color: var(--primary); }
.result-stat .success { color: var(--success); }

/* Output area (Base64 tools) */
.output-area {
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    border: 1px solid var(--border);
}

.output-tabs { display: flex; gap: 0.5rem; margin-bottom: 1rem; flex-wrap: wrap; }

.output-tab {
    padding: 0.5rem 1rem;
    border-radius: var(--radius-full);
    font-size: 0.85rem; font-weight: 600;
    cursor: pointer; border: 1px solid var(--border);
    background: var(--bg-elevated); color: var(--text-secondary);
    transition: all 0.2s ease;
}

.output-tab.active { background: var(--primary); color: white; border-color: var(--primary); }
.output-tab:hover:not(.active) { background: var(--bg-tertiary); }

.output-textarea {
    width: 100%; min-height: 180px; max-height: 400px;
    padding: 1rem; border: 1px solid var(--input-border);
    border-radius: var(--radius-sm);
    background: var(--input-bg); color: var(--text);
    font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
    font-size: 0.8rem; resize: vertical;
    line-height: 1.5; word-break: break-all;
}

.output-textarea:focus {
    outline: none; border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(51,153,204,0.15);
}

.output-actions { display: flex; gap: 0.5rem; margin-top: 0.75rem; flex-wrap: wrap; }

.copy-btn {
    display: inline-flex; align-items: center; gap: 0.4rem;
    padding: 0.5rem 1rem; border-radius: var(--radius-full);
    font-size: 0.85rem; font-weight: 600;
    cursor: pointer; border: 1px solid var(--border);
    background: var(--bg-elevated); color: var(--text-secondary);
    transition: all 0.2s ease;
}

.copy-btn:hover { background: var(--primary); color: white; border-color: var(--primary); }
.copy-btn.copied { background: var(--success); color: white; border-color: var(--success); }

/* Paste area (Base64 to Image) */
.paste-area {
    width: 100%; min-height: 200px;
    padding: 1rem; border: 2px dashed var(--border);
    border-radius: var(--radius-md);
    background: var(--bg-secondary); color: var(--text);
    font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
    font-size: 0.8rem; resize: vertical;
    line-height: 1.5; word-break: break-all;
    transition: border-color 0.2s;
}

.paste-area:focus { outline: none; border-color: var(--primary); }
.paste-area::placeholder { color: var(--text-muted); font-family: inherit; }

/* Processing */
.processing-overlay {
    position: absolute; inset: 0;
    background: rgba(255,255,255,0.9);
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    gap: 1rem; z-index: 10;
    border-radius: var(--radius-xl);
}

[data-theme="dark"] .processing-overlay { background: rgba(15,23,42,0.9); }

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

@keyframes spin { to { transform: rotate(360deg); } }
.loading-text { font-size: 1rem; color: var(--text-muted); margin: 0; }

/* Error */
.error-message {
    background: var(--danger-light);
    border: 1px solid var(--danger);
    color: var(--danger);
    padding: 1rem 1.25rem;
    border-radius: var(--radius-md);
    margin: 1.25rem;
    font-weight: 500;
}

/* Notification */
.notification {
    position: fixed; top: 1.5rem; right: 1.5rem;
    padding: 0.875rem 1.5rem;
    border-radius: var(--radius-md);
    font-weight: 600; font-size: 0.9rem;
    z-index: 1000; transform: translateX(120%);
    transition: transform 0.3s ease;
    box-shadow: var(--shadow-lg);
}

.notification.show { transform: translateX(0); }
.notification.success { background: var(--success); color: white; }
.notification.error { background: var(--danger); color: white; }

/* Related Tools */
.related-tools {
    display: flex; align-items: center; flex-wrap: wrap;
    gap: 1rem; padding: 1.25rem 1.5rem;
    background: var(--bg-elevated);
    border-radius: var(--radius-lg);
    margin-bottom: 2rem;
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}

.related-label {
    display: flex; align-items: center; gap: 0.5rem;
    font-weight: 600; color: var(--text); font-size: 0.9rem;
}

.related-label svg, .related-label i { color: var(--primary); }
.related-links { display: flex; flex-wrap: wrap; gap: 0.5rem; }

.related-link {
    display: inline-flex; align-items: center; gap: 0.4rem;
    padding: 0.5rem 1rem;
    background: var(--bg-secondary);
    border-radius: var(--radius-full);
    color: var(--text-secondary);
    text-decoration: none; font-size: 0.875rem; font-weight: 500;
    transition: all 0.2s ease;
    border: 1px solid var(--border);
}

.related-link:hover {
    background: var(--primary); color: white;
    border-color: var(--primary); transform: translateY(-2px);
}

/* Info Sections */
.info-sections { display: flex; flex-direction: column; gap: 1.5rem; }

.info-card {
    background: var(--bg-elevated);
    border-radius: var(--radius-xl);
    padding: 2rem;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border);
}

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

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

.steps-list { counter-reset: step; list-style: none; padding: 0; margin: 0; }

.steps-list li {
    position: relative; padding-left: 3.25rem;
    margin-bottom: 1rem; counter-increment: step;
    color: var(--text-secondary); line-height: 1.6;
}

.steps-list li:not(:last-child)::after {
    content: ''; position: absolute;
    left: calc(1rem - 1px); top: 2rem; bottom: 0;
    width: 2px; background: var(--primary-light);
}

.steps-list li::before {
    content: counter(step);
    position: absolute; left: 0; top: 0;
    width: 2rem; height: 2rem;
    background: var(--primary); color: white;
    border-radius: var(--radius-full);
    display: flex; align-items: center; justify-content: center;
    font-weight: 600; font-size: 0.875rem; z-index: 1;
}

.steps-list li:last-child { margin-bottom: 0; }
.steps-list a, .info-card a { color: var(--primary); text-decoration: none; }
.steps-list a:hover, .info-card a:hover { text-decoration: underline; }

/* Responsive */
@media (max-width: 768px) {
    .tool-container { padding: 1rem; }
    .tool-icon-wrapper { width: 50px; height: 50px; }
    .upload-section { padding: 2rem 1.5rem; }
    .upload-area { padding: 2.5rem 1.5rem; }
    .editor-section, .results-section { padding: 1.25rem; }
    .settings-grid { grid-template-columns: 1fr; }
    .action-bar { flex-direction: column; }
    .tool-btn { width: 100%; }
    .related-tools { flex-direction: column; align-items: flex-start; }
    .info-card { padding: 1.5rem; }
}

@media (max-width: 480px) {
    .tool-title-row { flex-direction: column; gap: 0.75rem; }
    .file-info { gap: 0.75rem; }
}

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg); border-radius: 4px; }
::-webkit-scrollbar-thumb { background: var(--text-muted); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-secondary); }

::selection { background: rgba(51,153,204,0.2); color: var(--text); }
[data-theme="dark"] ::selection { background: rgba(56,189,248,0.3); }

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

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}
