/* ============================================
   Design System & Variables
   ============================================ */
:root {
    --color-bg: #0f0f1a;
    --color-surface: #1a1a2e;
    --color-surface-2: #222240;
    --color-border: rgba(99, 102, 241, 0.15);
    --color-border-hover: rgba(99, 102, 241, 0.4);
    --color-text: #e2e8f0;
    --color-text-muted: #94a3b8;
    --color-primary: #6366f1;
    --color-primary-hover: #818cf8;
    --color-accent: #8b5cf6;
    --color-success: #10b981;
    --color-error: #ef4444;
    --color-warning: #f59e0b;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
    --shadow-glow: 0 0 20px rgba(99, 102, 241, 0.15);
    --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

/* ============================================
   Reset & Base
   ============================================ */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font);
    background: var(--color-bg);
    color: var(--color-text);
    min-height: 100vh;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Background gradient effect */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: 
        radial-gradient(ellipse at 20% 20%, rgba(99, 102, 241, 0.08) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 80%, rgba(139, 92, 246, 0.06) 0%, transparent 50%);
    pointer-events: none;
    z-index: 0;
}

/* ============================================
   Layout - Split View
   ============================================ */
.split-layout {
    position: relative;
    z-index: 1;
    display: grid;
    grid-template-columns: 55% 45%;
    height: calc(100vh - 41px);
    overflow: hidden;
}

.panel-left {
    padding: 1.5rem;
    overflow-y: auto;
    border-right: 1px solid var(--color-border);
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.panel-right {
    padding: 1.5rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.panel-right .preview-section {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.panel-right .tab-content {
    flex: 1;
}

.panel-right .tab-content.active {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex: 1;
}

.panel-right .phone-frame {
    flex: 1;
    max-height: calc(100vh - 180px);
}

.panel-right .phone-frame iframe {
    height: 100%;
}

.panel-right .desktop-frame {
    flex: 1;
    max-height: calc(100vh - 180px);
}

.panel-right .desktop-frame iframe {
    height: 100%;
}

.panel-right .code-block {
    max-height: calc(100vh - 180px);
    overflow: auto;
}

/* Responsive: stack on small screens */
@media (max-width: 900px) {
    .split-layout {
        grid-template-columns: 1fr;
        height: auto;
        overflow: auto;
    }
    .panel-left {
        border-right: none;
        border-bottom: 1px solid var(--color-border);
        max-height: none;
    }
    .panel-right {
        min-height: 600px;
    }
}

/* ============================================
   Header
   ============================================ */
.header {
    text-align: left;
    margin-bottom: 0.5rem;
    animation: fadeInDown 0.6s ease-out;
}

.logo {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 0.75rem;
    margin-bottom: 0.5rem;
}

.logo h1 {
    font-size: 1.4rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--color-primary), var(--color-accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.subtitle {
    color: var(--color-text-muted);
    font-size: 0.8rem;
    font-weight: 400;
    letter-spacing: 0.5px;
}

/* ============================================
   Input Section
   ============================================ */
.input-section {
    margin-bottom: 0.5rem;
    animation: fadeInUp 0.6s ease-out 0.1s both;
}

.input-wrapper {
    display: flex;
    align-items: center;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 0.4rem 0.4rem 0.4rem 1rem;
    transition: border-color var(--transition), box-shadow var(--transition);
    gap: 0.75rem;
}

.input-wrapper:focus-within {
    border-color: var(--color-border-hover);
    box-shadow: var(--shadow-glow);
}

.input-icon {
    color: var(--color-text-muted);
    flex-shrink: 0;
    display: flex;
}

#url-input {
    flex: 1;
    background: none;
    border: none;
    outline: none;
    color: var(--color-text);
    font-size: 0.95rem;
    font-family: var(--font);
    padding: 0.75rem 0;
}

#url-input::placeholder {
    color: var(--color-text-muted);
    opacity: 0.7;
}

.fetch-btn {
    flex-shrink: 0;
    background: linear-gradient(135deg, var(--color-primary), var(--color-accent));
    color: white;
    border: none;
    border-radius: var(--radius-md);
    padding: 0.75rem 1.75rem;
    font-size: 0.9rem;
    font-weight: 600;
    font-family: var(--font);
    cursor: pointer;
    transition: transform var(--transition), box-shadow var(--transition), opacity var(--transition);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.fetch-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 16px rgba(99, 102, 241, 0.4);
}

.fetch-btn:active {
    transform: translateY(0);
}

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

.spinner {
    animation: spin 1s linear infinite;
}

/* Options bar */
.options-bar {
    display: flex;
    gap: 1.25rem;
    margin-top: 1rem;
    padding: 0 0.5rem;
    flex-wrap: wrap;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--color-text-muted);
    font-size: 0.85rem;
    cursor: pointer;
    transition: color var(--transition);
    user-select: none;
}

.checkbox-label:hover {
    color: var(--color-text);
}

.checkbox-label input[type="checkbox"] {
    display: none;
}

.checkmark {
    width: 18px;
    height: 18px;
    border: 2px solid var(--color-border-hover);
    border-radius: 4px;
    position: relative;
    transition: background var(--transition), border-color var(--transition);
}

.checkbox-label input[type="checkbox"]:checked + .checkmark {
    background: var(--color-primary);
    border-color: var(--color-primary);
}

.checkbox-label input[type="checkbox"]:checked + .checkmark::after {
    content: '';
    position: absolute;
    left: 5px;
    top: 2px;
    width: 5px;
    height: 9px;
    border: solid white;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

/* ============================================
   Status Bar
   ============================================ */
.status-bar {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.85rem 1.25rem;
    border-radius: var(--radius-md);
    margin-bottom: 1.5rem;
    font-size: 0.875rem;
    animation: fadeIn 0.3s ease-out;
}

.status-bar.loading {
    background: rgba(99, 102, 241, 0.1);
    border: 1px solid rgba(99, 102, 241, 0.2);
    color: var(--color-primary-hover);
}

.status-bar.success {
    background: rgba(16, 185, 129, 0.1);
    border: 1px solid rgba(16, 185, 129, 0.2);
    color: var(--color-success);
}

.status-bar.error {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.2);
    color: var(--color-error);
}

.status-icon {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.status-bar.loading .status-icon {
    background: var(--color-primary);
    animation: pulse 1.5s infinite;
}

.status-bar.success .status-icon {
    background: var(--color-success);
}

.status-bar.error .status-icon {
    background: var(--color-error);
}

/* ============================================
   Preview Section
   ============================================ */
.preview-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    animation: fadeInUp 0.5s ease-out;
}

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

.preview-tabs {
    display: flex;
    gap: 0.25rem;
    background: var(--color-surface);
    border-radius: var(--radius-md);
    padding: 0.25rem;
    border: 1px solid var(--color-border);
}

.tab-btn {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.6rem 1rem;
    border: none;
    background: none;
    color: var(--color-text-muted);
    font-size: 0.8rem;
    font-weight: 500;
    font-family: var(--font);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition);
}

.tab-btn:hover {
    color: var(--color-text);
}

.tab-btn.active {
    background: var(--color-primary);
    color: white;
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.3);
}

.preview-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.action-input {
    padding: 0.55rem 0.8rem;
    border: 1px solid var(--color-border);
    background: var(--color-surface);
    color: var(--color-text);
    font-size: 0.8rem;
    font-family: var(--font);
    border-radius: var(--radius-sm);
    outline: none;
    transition: all var(--transition);
    width: 160px;
}

.action-input:focus {
    border-color: var(--color-accent);
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.15);
}

.action-input::placeholder {
    color: var(--color-text-muted);
    font-size: 0.75rem;
}

.action-btn {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.55rem 1rem;
    border: 1px solid var(--color-border);
    background: var(--color-surface);
    color: var(--color-text-muted);
    font-size: 0.8rem;
    font-weight: 500;
    font-family: var(--font);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition);
}

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

/* Tab Content */
.tab-content {
    display: none;
    flex: 1;
}

.tab-content.active {
    display: flex;
    justify-content: center;
    align-items: flex-start;
}

/* ============================================
   Phone Frame
   ============================================ */
.phone-frame {
    width: 320px;
    height: 580px;
    background: #000;
    border-radius: 36px;
    padding: 10px;
    box-shadow: 
        var(--shadow-lg),
        inset 0 0 0 2px rgba(255, 255, 255, 0.1);
    position: relative;
    display: flex;
    flex-direction: column;
}

.phone-notch {
    width: 120px;
    height: 24px;
    background: #000;
    border-radius: 0 0 16px 16px;
    position: absolute;
    top: 12px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10;
}

#mobile-preview {
    flex: 1;
    width: 100%;
    border: none;
    border-radius: 28px;
    background: white;
}

.phone-home-bar {
    width: 120px;
    height: 4px;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 2px;
    margin: 8px auto 4px;
}

/* ============================================
   Desktop Frame
   ============================================ */
.desktop-frame {
    width: 100%;
    max-width: 900px;
    height: 560px;
    background: var(--color-surface);
    border-radius: var(--radius-md);
    border: 1px solid var(--color-border);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
}

.desktop-toolbar {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    background: var(--color-surface-2);
    border-bottom: 1px solid var(--color-border);
}

.dots {
    display: flex;
    gap: 6px;
}

.dots span {
    width: 12px;
    height: 12px;
    border-radius: 50%;
}

.dots span:nth-child(1) { background: #ef4444; }
.dots span:nth-child(2) { background: #f59e0b; }
.dots span:nth-child(3) { background: #10b981; }

.address-bar {
    flex: 1;
    background: var(--color-bg);
    border-radius: 6px;
    padding: 0.4rem 0.75rem;
    font-size: 0.75rem;
    color: var(--color-text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#desktop-preview {
    flex: 1;
    width: 100%;
    border: none;
    background: white;
}

/* ============================================
   Code Block
   ============================================ */
.code-block {
    width: 100%;
    max-width: 900px;
    max-height: 600px;
    overflow: auto;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 1.5rem;
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 0.8rem;
    line-height: 1.7;
    color: var(--color-text-muted);
    white-space: pre-wrap;
    word-break: break-all;
}

/* ============================================
   Footer
   ============================================ */
.footer {
    margin-top: 2rem;
    text-align: center;
    padding: 1.5rem 0;
    border-top: 1px solid var(--color-border);
}

.footer p {
    color: var(--color-text-muted);
    font-size: 0.8rem;
}

/* ============================================
   Animations
   ============================================ */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

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

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

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

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

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

    .logo h1 {
        font-size: 1.4rem;
    }

    .input-wrapper {
        flex-direction: column;
        padding: 0.75rem;
        gap: 0.5rem;
    }

    .input-icon {
        display: none;
    }

    #url-input {
        width: 100%;
        padding: 0.5rem;
    }

    .fetch-btn {
        width: 100%;
        justify-content: center;
        padding: 0.85rem;
    }

    .options-bar {
        gap: 0.75rem;
    }

    .preview-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .phone-frame {
        width: 100%;
        max-width: 340px;
        height: 620px;
    }

    .preview-tabs {
        width: 100%;
    }

    .tab-btn {
        flex: 1;
        justify-content: center;
        font-size: 0.75rem;
        padding: 0.5rem 0.5rem;
    }

    .desktop-frame {
        height: 400px;
    }
}

@media (max-width: 480px) {
    .options-bar {
        flex-direction: column;
        gap: 0.5rem;
    }

    .phone-frame {
        border-radius: 30px;
        height: 550px;
    }
}
/* ============================================
   Template Selector
   ============================================ */
.template-selector {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 14px;
    padding-top: 14px;
    border-top: 1px solid var(--color-border);
}

.template-label {
    font-size: 0.78rem;
    color: var(--color-text-muted);
    white-space: nowrap;
    font-weight: 500;
}

.template-options {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    flex-wrap: nowrap;
    padding-bottom: 4px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}

.template-options::-webkit-scrollbar {
    display: none;
}

.tpl-pill {
    padding: 6px 14px;
    border: 1px solid var(--color-border);
    border-radius: 999px;
    background: var(--color-surface);
    color: var(--color-text-muted);
    font-size: 0.75rem;
    font-weight: 500;
    font-family: var(--font);
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
    flex-shrink: 0;
}

.tpl-pill:hover {
    border-color: var(--color-primary);
    color: var(--color-text);
    background: var(--color-surface-2);
}

.tpl-pill.active {
    border-color: var(--color-primary);
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.2), rgba(139, 92, 246, 0.2));
    color: #a5b4fc;
    font-weight: 600;
    box-shadow: 0 0 8px rgba(99, 102, 241, 0.15);
}

/* AI Generate button - special gradient style */
.tpl-pill-ai {
    background: linear-gradient(135deg, rgba(236, 72, 153, 0.15), rgba(168, 85, 247, 0.15));
    border-color: rgba(236, 72, 153, 0.4);
    color: #f0abfc;
    position: relative;
    overflow: hidden;
}

.tpl-pill-ai::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: linear-gradient(45deg, transparent, rgba(236, 72, 153, 0.1), transparent);
    animation: ai-shimmer 3s ease-in-out infinite;
}

@keyframes ai-shimmer {
    0% { transform: translateX(-100%) rotate(45deg); }
    100% { transform: translateX(100%) rotate(45deg); }
}

.tpl-pill-ai:hover {
    border-color: rgba(236, 72, 153, 0.7);
    color: #f9a8d4;
    background: linear-gradient(135deg, rgba(236, 72, 153, 0.25), rgba(168, 85, 247, 0.25));
    box-shadow: 0 0 12px rgba(236, 72, 153, 0.2);
}

.tpl-pill-ai.active {
    border-color: rgba(236, 72, 153, 0.7);
    background: linear-gradient(135deg, rgba(236, 72, 153, 0.3), rgba(168, 85, 247, 0.3));
    color: #fbbef9;
    box-shadow: 0 0 16px rgba(236, 72, 153, 0.25);
}

/* AI Prompt Panel */
.ai-prompt-panel {
    margin-top: 12px;
    padding: 14px 16px;
    background: rgba(236, 72, 153, 0.05);
    border: 1px solid rgba(236, 72, 153, 0.2);
    border-radius: var(--radius-md);
    animation: fadeSlideDown 0.3s ease-out;
}

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

.ai-prompt-options {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 10px;
}

.ai-prompt-pill {
    padding: 6px 12px;
    border: 1px solid rgba(168, 85, 247, 0.25);
    border-radius: 999px;
    background: rgba(168, 85, 247, 0.08);
    color: #c4b5fd;
    font-size: 0.72rem;
    font-weight: 500;
    font-family: var(--font);
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
}

.ai-prompt-pill:hover {
    border-color: rgba(168, 85, 247, 0.5);
    background: rgba(168, 85, 247, 0.15);
    color: #e9d5ff;
}

.ai-prompt-pill.active {
    border-color: rgba(236, 72, 153, 0.6);
    background: linear-gradient(135deg, rgba(236, 72, 153, 0.2), rgba(168, 85, 247, 0.2));
    color: #f0abfc;
    font-weight: 600;
    box-shadow: 0 0 8px rgba(168, 85, 247, 0.15);
}

.ai-custom-prompt {
    margin-top: 10px;
    animation: fadeSlideDown 0.2s ease-out;
}

.ai-custom-prompt input {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid rgba(168, 85, 247, 0.3);
    border-radius: var(--radius-sm);
    background: rgba(168, 85, 247, 0.06);
    color: var(--color-text);
    font-size: 0.8rem;
    font-family: var(--font);
    outline: none;
    transition: border-color var(--transition);
}

.ai-custom-prompt input:focus {
    border-color: rgba(236, 72, 153, 0.6);
    box-shadow: 0 0 12px rgba(236, 72, 153, 0.1);
}

.ai-custom-prompt input::placeholder {
    color: var(--color-text-muted);
    opacity: 0.6;
}
