/* ========================================
   Design System & Variables
   ======================================== */
:root {
    /* Colors - Dark Theme */
    --bg-primary: #0a0a0f;
    --bg-secondary: #12121a;
    --bg-tertiary: #1a1a26;
    --bg-card: #14141e;
    --bg-card-hover: #1a1a28;
    --bg-input: #0d0d14;
    
    --border-subtle: rgba(255, 255, 255, 0.06);
    --border-default: rgba(255, 255, 255, 0.1);
    --border-focus: rgba(99, 102, 241, 0.5);
    
    --text-primary: #f0f0f5;
    --text-secondary: #8888a0;
    --text-tertiary: #5a5a72;
    --text-code: #c8c8e0;
    
    --accent-primary: #6366f1;
    --accent-primary-hover: #818cf8;
    --accent-primary-glow: rgba(99, 102, 241, 0.15);
    
    --cockpit-accent: #06b6d4;
    --cockpit-glow: rgba(6, 182, 212, 0.12);
    --cli-accent: #f59e0b;
    --cli-glow: rgba(245, 158, 11, 0.12);
    
    --success: #10b981;
    --success-glow: rgba(16, 185, 129, 0.15);
    --error: #ef4444;
    --error-glow: rgba(239, 68, 68, 0.12);
    
    /* Spacing */
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 12px;
    --space-lg: 16px;
    --space-xl: 24px;
    --space-2xl: 32px;
    --space-3xl: 48px;
    
    /* Typography */
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
    --font-mono: 'JetBrains Mono', 'Cascadia Code', 'Fira Code', monospace;
    
    --text-xs: 11px;
    --text-sm: 13px;
    --text-base: 14px;
    --text-lg: 16px;
    --text-xl: 20px;
    --text-2xl: 24px;
    
    /* Radius */
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --radius-xl: 18px;
    
    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.5);
    --shadow-glow: 0 0 20px rgba(99, 102, 241, 0.08);
    
    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-base: 250ms ease;
    --transition-slow: 400ms ease;
}

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

html {
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-sans);
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    overflow-x: hidden;
}

/* Background ambience */
body::before {
    content: '';
    position: fixed;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: 
        radial-gradient(ellipse at 20% 20%, rgba(99, 102, 241, 0.04) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 80%, rgba(6, 182, 212, 0.03) 0%, transparent 50%),
        radial-gradient(ellipse at 50% 50%, rgba(245, 158, 11, 0.02) 0%, transparent 60%);
    pointer-events: none;
    z-index: 0;
    animation: ambience 20s ease-in-out infinite alternate;
}

@keyframes ambience {
    0% { transform: translate(0, 0) scale(1); }
    100% { transform: translate(-2%, -1%) scale(1.02); }
}

/* ========================================
   App Container
   ======================================== */
.app-container {
    position: relative;
    z-index: 1;
    max-width: 1200px;
    margin: 0 auto;
    padding: var(--space-xl) var(--space-lg);
    padding-bottom: var(--space-3xl);
}

/* ========================================
   Header
   ======================================== */
.app-header {
    position: relative;
    margin-bottom: var(--space-2xl);
    padding: var(--space-xl) var(--space-xl);
    background: linear-gradient(135deg, var(--bg-card) 0%, rgba(20, 20, 30, 0.8) 100%);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-xl);
    overflow: hidden;
}

.header-glow {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--accent-primary), var(--cockpit-accent), transparent);
    opacity: 0.6;
}

.header-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-lg);
}

.logo-group {
    display: flex;
    align-items: center;
    gap: var(--space-md);
}

.logo-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border-radius: var(--radius-md);
    background: linear-gradient(135deg, var(--accent-primary), #818cf8);
    color: white;
    box-shadow: 0 0 16px rgba(99, 102, 241, 0.25);
}

.logo-group h1 {
    font-size: var(--text-xl);
    font-weight: 700;
    letter-spacing: -0.02em;
    background: linear-gradient(135deg, var(--text-primary), var(--text-secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.subtitle {
    font-size: var(--text-xs);
    color: var(--text-tertiary);
    font-weight: 500;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.header-stats {
    display: flex;
    gap: var(--space-sm);
}

.stat-badge {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
    padding: var(--space-xs) var(--space-md);
    background: var(--success-glow);
    border: 1px solid rgba(16, 185, 129, 0.2);
    border-radius: 100px;
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--success);
    animation: fadeSlideIn 0.3s ease;
}

.stat-badge.stat-error {
    background: var(--error-glow);
    border-color: rgba(239, 68, 68, 0.2);
    color: var(--error);
}

.stat-icon {
    font-size: var(--text-xs);
}

/* ========================================
   Section Headers
   ======================================== */
.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-md);
    flex-wrap: wrap;
    gap: var(--space-sm);
}

.section-title-group {
    display: flex;
    align-items: baseline;
    gap: var(--space-md);
}

.section-title {
    font-size: var(--text-lg);
    font-weight: 600;
    color: var(--text-primary);
}

.format-hint {
    font-size: var(--text-xs);
    color: var(--text-tertiary);
    font-family: var(--font-mono);
    background: var(--bg-tertiary);
    padding: 2px var(--space-sm);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-subtle);
}

.input-actions {
    display: flex;
    gap: var(--space-sm);
}

/* ========================================
   Buttons
   ======================================== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: var(--space-xs);
    padding: var(--space-sm) var(--space-lg);
    font-family: var(--font-sans);
    font-size: var(--text-sm);
    font-weight: 500;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
    user-select: none;
}

.btn:active {
    transform: scale(0.97);
}

.btn-primary {
    background: linear-gradient(135deg, var(--accent-primary), #818cf8);
    color: white;
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.3);
}

.btn-primary:hover {
    box-shadow: 0 4px 16px rgba(99, 102, 241, 0.4);
    filter: brightness(1.1);
}

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

.btn-ghost:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border-color: var(--border-default);
}

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

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

.btn-accent {
    background: linear-gradient(135deg, #f59e0b, #f97316);
    color: #000;
    font-weight: 600;
    box-shadow: 0 2px 8px rgba(245, 158, 11, 0.3);
}

.btn-accent:hover {
    box-shadow: 0 4px 16px rgba(245, 158, 11, 0.4);
    filter: brightness(1.1);
}

.btn-accent:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    animation: pulse 1.5s ease-in-out infinite;
}

.btn-sm {
    padding: var(--space-xs) var(--space-md);
    font-size: var(--text-xs);
}

/* ========================================
   Input Section
   ======================================== */
.input-section {
    margin-bottom: var(--space-2xl);
}

.textarea-wrapper {
    position: relative;
}

#inputArea {
    width: 100%;
    min-height: 280px;
    max-height: 600px;
    padding: var(--space-lg);
    padding-bottom: var(--space-2xl);
    background: var(--bg-input);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-lg);
    color: var(--text-code);
    font-family: var(--font-mono);
    font-size: var(--text-sm);
    line-height: 1.7;
    resize: vertical;
    outline: none;
    word-break: break-all;
    overflow-wrap: break-word;
    white-space: pre-wrap;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

#inputArea::placeholder {
    color: var(--text-tertiary);
    opacity: 0.6;
}

#inputArea:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px var(--accent-primary-glow), var(--shadow-glow);
}

.textarea-counter {
    position: absolute;
    bottom: var(--space-sm);
    right: var(--space-md);
    font-size: var(--text-xs);
    color: var(--text-tertiary);
    font-family: var(--font-mono);
    pointer-events: none;
}

/* ========================================
   Output Section
   ======================================== */
.output-section {
    display: flex;
    flex-direction: column;
    gap: var(--space-xl);
    animation: fadeSlideIn 0.4s ease;
}

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

/* ========================================
   Output Cards
   ======================================== */
.output-card {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    overflow: hidden;
    transition: border-color var(--transition-base), box-shadow var(--transition-base);
}

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

#cockpitCard {
    border-top: 2px solid var(--cockpit-accent);
}

#cockpitCard:hover {
    box-shadow: var(--shadow-md), 0 -2px 12px var(--cockpit-glow);
}

#cliCard {
    border-top: 2px solid var(--cli-accent);
}

#cliCard:hover {
    box-shadow: var(--shadow-md), 0 -2px 12px var(--cli-glow);
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-lg) var(--space-xl);
    background: linear-gradient(180deg, var(--bg-tertiary) 0%, transparent 100%);
    border-bottom: 1px solid var(--border-subtle);
    flex-wrap: wrap;
    gap: var(--space-sm);
}

.card-title-group {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.card-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
}

.cockpit-icon {
    background: var(--cockpit-glow);
    color: var(--cockpit-accent);
    border: 1px solid rgba(6, 182, 212, 0.2);
}

.cli-icon {
    background: var(--cli-glow);
    color: var(--cli-accent);
    border: 1px solid rgba(245, 158, 11, 0.2);
}

.card-title-group h3 {
    font-size: var(--text-base);
    font-weight: 600;
}

.card-count {
    font-size: var(--text-xs);
    color: var(--text-tertiary);
    background: var(--bg-primary);
    padding: 2px var(--space-sm);
    border-radius: 100px;
    font-family: var(--font-mono);
    border: 1px solid var(--border-subtle);
}

.card-actions {
    display: flex;
    gap: var(--space-xs);
    flex-wrap: wrap;
}

/* ========================================
   Completion Progress
   ======================================== */
.completion-progress {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: var(--space-sm) var(--space-xl);
    background: rgba(245, 158, 11, 0.05);
    border-bottom: 1px solid var(--border-subtle);
}

.completion-bar-track {
    flex: 1;
    height: 4px;
    background: var(--bg-tertiary);
    border-radius: 2px;
    overflow: hidden;
}

.completion-bar-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #f59e0b, #f97316);
    border-radius: 2px;
    transition: width 0.3s ease;
}

.completion-status {
    font-size: var(--text-xs);
    font-family: var(--font-mono);
    color: var(--text-secondary);
    white-space: nowrap;
}

/* ========================================
   Filter Section
   ======================================== */
.cli-filter-section {
    padding: var(--space-md) var(--space-xl);
    border-bottom: 1px solid var(--border-subtle);
    background: rgba(255, 255, 255, 0.015);
    animation: fadeSlideIn 0.3s ease;
}

.filter-tabs {
    display: flex;
    gap: var(--space-xs);
    margin-bottom: var(--space-md);
}

.filter-tab {
    display: inline-flex;
    align-items: center;
    gap: var(--space-xs);
    padding: var(--space-xs) var(--space-md);
    font-family: var(--font-sans);
    font-size: var(--text-xs);
    font-weight: 500;
    color: var(--text-tertiary);
    background: transparent;
    border: 1px solid var(--border-subtle);
    border-radius: 100px;
    cursor: pointer;
    transition: all var(--transition-fast);
    user-select: none;
}

.filter-tab:hover {
    color: var(--text-primary);
    border-color: var(--border-default);
    background: var(--bg-tertiary);
}

.filter-tab.active {
    color: var(--text-primary);
    background: var(--bg-tertiary);
    border-color: var(--accent-primary);
    box-shadow: 0 0 8px var(--accent-primary-glow);
}

.filter-tab.filter-success.active {
    border-color: var(--success);
    box-shadow: 0 0 8px var(--success-glow);
    color: var(--success);
}

.filter-tab.filter-fail.active {
    border-color: var(--error);
    box-shadow: 0 0 8px var(--error-glow);
    color: var(--error);
}

.filter-count {
    font-family: var(--font-mono);
    font-size: 10px;
    padding: 1px 5px;
    background: rgba(255, 255, 255, 0.06);
    border-radius: 100px;
    min-width: 18px;
    text-align: center;
}

.filter-actions {
    display: flex;
    gap: var(--space-xs);
    margin-bottom: var(--space-md);
}

/* Email Result List */
.result-email-list {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-xs);
    max-height: 200px;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--bg-tertiary) transparent;
}

.result-email-list::-webkit-scrollbar {
    width: 4px;
}

.result-email-list::-webkit-scrollbar-thumb {
    background: var(--bg-tertiary);
    border-radius: 2px;
}

.email-item {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    border-radius: 100px;
    font-size: 11px;
    font-family: var(--font-mono);
    white-space: nowrap;
    transition: all var(--transition-fast);
}

.email-item.email-success {
    background: rgba(16, 185, 129, 0.08);
    border: 1px solid rgba(16, 185, 129, 0.15);
    color: var(--success);
}

.email-item.email-fail {
    background: rgba(239, 68, 68, 0.08);
    border: 1px solid rgba(239, 68, 68, 0.15);
    color: var(--error);
}

.email-icon {
    font-size: 10px;
    font-weight: 700;
}

.email-addr {
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.email-error-tip {
    font-size: 10px;
    color: rgba(239, 68, 68, 0.6);
    margin-left: 4px;
    max-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ========================================
   Code Block
   ======================================== */
.code-block {
    max-height: 400px;
    overflow: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--bg-tertiary) transparent;
}

.code-block::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

.code-block::-webkit-scrollbar-track {
    background: transparent;
}

.code-block::-webkit-scrollbar-thumb {
    background: var(--bg-tertiary);
    border-radius: 3px;
}

.code-block::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.15);
}

.code-block pre {
    margin: 0;
    padding: var(--space-lg) var(--space-xl);
}

.code-block code {
    font-family: var(--font-mono);
    font-size: var(--text-sm);
    line-height: 1.7;
    color: var(--text-code);
    white-space: pre;
    word-break: break-all;
}

/* JSON Syntax Highlighting */
.json-key {
    color: #93c5fd;
}

.json-string {
    color: #86efac;
}

.json-number {
    color: #fca5a5;
}

.json-boolean {
    color: #c4b5fd;
}

.json-null {
    color: #94a3b8;
}

.json-bracket {
    color: #9ca3af;
}

/* ========================================
   Error Section
   ======================================== */
.error-section {
    margin-top: var(--space-xl);
    padding: var(--space-lg);
    background: var(--error-glow);
    border: 1px solid rgba(239, 68, 68, 0.2);
    border-radius: var(--radius-lg);
    animation: fadeSlideIn 0.4s ease;
}

.error-header {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    color: var(--error);
    font-weight: 600;
    font-size: var(--text-sm);
    margin-bottom: var(--space-md);
}

.error-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
}

.error-item {
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    color: rgba(239, 68, 68, 0.8);
    padding: var(--space-xs) var(--space-sm);
    background: rgba(239, 68, 68, 0.06);
    border-radius: var(--radius-sm);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.error-item .line-num {
    color: var(--text-tertiary);
    margin-right: var(--space-sm);
}

/* ========================================
   Toast
   ======================================== */
.toast {
    position: fixed;
    bottom: var(--space-2xl);
    left: 50%;
    transform: translateX(-50%) translateY(120%);
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-md) var(--space-xl);
    background: var(--bg-card);
    color: var(--success);
    border: 1px solid rgba(16, 185, 129, 0.3);
    border-radius: 100px;
    font-size: var(--text-sm);
    font-weight: 500;
    box-shadow: var(--shadow-lg), 0 0 20px var(--success-glow);
    z-index: 1000;
    opacity: 0;
    transition: all var(--transition-base);
    pointer-events: none;
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ========================================
   Responsive
   ======================================== */
@media (max-width: 640px) {
    .app-container {
        padding: var(--space-md);
    }
    
    .header-content {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .section-header {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .section-title-group {
        flex-direction: column;
        gap: var(--space-xs);
    }
    
    .card-header {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .card-actions {
        width: 100%;
    }
    
    .card-actions .btn {
        flex: 1;
        justify-content: center;
    }
}

/* ========================================
   Animations
   ======================================== */
@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

.btn-primary:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    animation: pulse 1.5s ease-in-out infinite;
}
