/* CSS Variables */
:root {
    /* Dark theme (default) */
    --bg-primary: #0a0a0b;
    --bg-secondary: #111113;
    --bg-tertiary: #18181b;
    --bg-elevated: #1f1f23;
    --bg-hover: #27272a;
    
    --text-primary: #fafafa;
    --text-secondary: #a1a1aa;
    --text-tertiary: #71717a;
    
    --border-primary: #27272a;
    --border-secondary: #3f3f46;
    
    --accent-primary: #6366f1;
    --accent-secondary: #8b5cf6;
    --accent-gradient: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    
    --status-pass: #22c55e;
    --status-fail: #ef4444;
    --status-warn: #eab308;
    --status-info: #3b82f6;
    
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.4);
    --shadow-glow: 0 0 40px rgba(99, 102, 241, 0.15);
    
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    
    --transition-fast: 150ms ease;
    --transition-normal: 250ms ease;
    --transition-slow: 400ms ease;
}

/* Light theme */
[data-theme="light"] {
    --bg-primary: #ffffff;
    --bg-secondary: #fafafa;
    --bg-tertiary: #f4f4f5;
    --bg-elevated: #ffffff;
    --bg-hover: #e4e4e7;
    
    --text-primary: #18181b;
    --text-secondary: #52525b;
    --text-tertiary: #a1a1aa;
    
    --border-primary: #e4e4e7;
    --border-secondary: #d4d4d8;
    
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.07);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.1);
    --shadow-glow: 0 0 40px rgba(99, 102, 241, 0.1);
}

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

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    transition: background-color var(--transition-normal), color var(--transition-normal);
}

/* App Container */
.app {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* Header */
.header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border-primary);
    backdrop-filter: blur(12px);
    background: rgba(10, 10, 11, 0.8);
}

[data-theme="light"] .header {
    background: rgba(255, 255, 255, 0.8);
}

.header-content {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

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

.logo-icon {
    width: 36px;
    height: 36px;
}

.logo-text {
    font-size: 1.25rem;
    font-weight: 700;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.telegram-link {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.875rem;
    font-weight: 500;
    transition: all var(--transition-fast);
}

.telegram-link:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    border-color: var(--border-secondary);
}

.telegram-icon {
    width: 18px;
    height: 18px;
    color: #229ED9;
}

.theme-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.theme-toggle:hover {
    background: var(--bg-hover);
    border-color: var(--border-secondary);
}

.theme-toggle svg {
    width: 18px;
    height: 18px;
    color: var(--text-secondary);
}

.sun-icon { display: none; }
.moon-icon { display: block; }

[data-theme="light"] .sun-icon { display: block; }
[data-theme="light"] .moon-icon { display: none; }

/* Main Content */
.main {
    flex: 1;
    max-width: 900px;
    margin: 0 auto;
    padding: 3rem 1.5rem;
    width: 100%;
}

/* Hero Section */
.hero {
    text-align: center;
    margin-bottom: 3rem;
}

.hero-title {
    font-size: clamp(2rem, 5vw, 3rem);
    font-weight: 800;
    letter-spacing: -0.02em;
    margin-bottom: 1rem;
    line-height: 1.2;
}

.hero-subtitle {
    font-size: 1.125rem;
    color: var(--text-secondary);
    max-width: 600px;
    margin: 0 auto;
    line-height: 1.7;
}

/* Input Section */
.input-section {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.textarea-wrapper {
    position: relative;
}

.headers-textarea {
    width: 100%;
    height: 300px;
    padding: 1.25rem;
    padding-right: 3rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-lg);
    color: var(--text-primary);
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
    font-size: 0.875rem;
    line-height: 1.7;
    resize: vertical;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.headers-textarea::placeholder {
    color: var(--text-tertiary);
}

.headers-textarea:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

.clear-btn {
    position: absolute;
    top: 1rem;
    right: 1rem;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-sm);
    cursor: pointer;
    opacity: 0;
    transition: all var(--transition-fast);
}

.textarea-wrapper:hover .clear-btn,
.headers-textarea:focus ~ .clear-btn {
    opacity: 1;
}

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

.clear-btn svg {
    width: 14px;
    height: 14px;
    color: var(--text-tertiary);
}

/* Mode Toggle */
.mode-toggle-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    padding: 1rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-md);
}

.mode-label {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
    transition: color var(--transition-fast);
}

.mode-label:first-of-type {
    color: var(--accent-primary);
}

.toggle {
    position: relative;
    width: 52px;
    height: 28px;
}

.toggle input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-secondary);
    border-radius: 28px;
    transition: all var(--transition-normal);
}

.toggle-slider::before {
    position: absolute;
    content: "";
    height: 20px;
    width: 20px;
    left: 3px;
    bottom: 3px;
    background: var(--text-primary);
    border-radius: 50%;
    transition: transform var(--transition-normal);
}

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

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

/* Analyze Button */
.analyze-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    width: 100%;
    padding: 1rem 2rem;
    background: var(--accent-gradient);
    border: none;
    border-radius: var(--radius-md);
    color: white;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-fast);
    position: relative;
    overflow: hidden;
}

.analyze-btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: var(--shadow-glow);
}

.analyze-btn:active:not(:disabled) {
    transform: translateY(0);
}

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

.analyze-btn .btn-text,
.analyze-btn .btn-icon {
    position: relative;
    z-index: 1;
}

.analyze-btn .btn-icon {
    width: 20px;
    height: 20px;
    transition: transform var(--transition-fast);
}

.analyze-btn:hover:not(:disabled) .btn-icon {
    transform: translateX(4px);
}

.analyze-btn.loading .btn-text,
.analyze-btn.loading .btn-icon {
    opacity: 0;
}

.analyze-btn .btn-loader {
    position: absolute;
    width: 24px;
    height: 24px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    opacity: 0;
    animation: spin 0.8s linear infinite;
}

.analyze-btn.loading .btn-loader {
    opacity: 1;
}

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

/* Results Section */
.results-section {
    background: var(--bg-secondary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-lg);
    overflow: hidden;
    opacity: 0;
    transform: translateY(20px);
    transition: all var(--transition-slow);
}

.results-section.visible {
    opacity: 1;
    transform: translateY(0);
}

.results-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.25rem 1.5rem;
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-primary);
}

.results-title {
    font-size: 1rem;
    font-weight: 600;
}

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

.copy-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: var(--bg-elevated);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
}

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

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

.copy-btn.copied {
    color: var(--status-pass);
    border-color: var(--status-pass);
}

.results-content {
    padding: 1.5rem;
}

/* Collapsible Sections */
.result-section {
    margin-bottom: 1rem;
}

.result-section:last-child {
    margin-bottom: 0;
}

.result-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.result-header:hover {
    background: var(--bg-hover);
}

.result-header.open {
    border-radius: var(--radius-md) var(--radius-md) 0 0;
    border-bottom-color: transparent;
}

.result-header-left {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.result-icon {
    width: 20px;
    height: 20px;
    color: var(--text-tertiary);
}

.result-title {
    font-size: 0.9375rem;
    font-weight: 600;
}

.result-body {
    display: none;
    padding: 1.25rem;
    background: var(--bg-elevated);
    border: 1px solid var(--border-primary);
    border-top: none;
    border-radius: 0 0 var(--radius-md) var(--radius-md);
}

.result-header.open + .result-body {
    display: block;
    animation: slideDown var(--transition-normal);
}

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

.chevron-icon {
    width: 16px;
    height: 16px;
    color: var(--text-tertiary);
    transition: transform var(--transition-fast);
}

.result-header.open .chevron-icon {
    transform: rotate(180deg);
}

/* Status Badges */
.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.25rem 0.625rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.025em;
}

.status-badge.pass {
    background: rgba(34, 197, 94, 0.15);
    color: var(--status-pass);
}

.status-badge.fail {
    background: rgba(239, 68, 68, 0.15);
    color: var(--status-fail);
}

.status-badge.warn {
    background: rgba(234, 179, 8, 0.15);
    color: var(--status-warn);
}

.status-badge.info {
    background: rgba(59, 130, 246, 0.15);
    color: var(--status-info);
}

.status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
}

/* Authentication Results */
.auth-results {
    display: grid;
    gap: 1rem;
}

.auth-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem;
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
}

.auth-item-left {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.auth-icon {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    font-weight: 700;
}

.auth-icon.spf {
    background: rgba(59, 130, 246, 0.15);
    color: var(--status-info);
}

.auth-icon.dkim {
    background: rgba(168, 85, 247, 0.15);
    color: #a855f7;
}

.auth-icon.dmarc {
    background: rgba(236, 72, 153, 0.15);
    color: #ec4899;
}

.auth-name {
    font-weight: 600;
    margin-bottom: 0.125rem;
}

.auth-desc {
    font-size: 0.8125rem;
    color: var(--text-secondary);
}

/* Mail Flow */
.mail-flow {
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
    font-size: 0.8125rem;
}

.hop {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    padding: 1rem 0;
    position: relative;
}

.hop:not(:last-child)::before {
    content: "";
    position: absolute;
    left: 15px;
    top: 50px;
    bottom: 0;
    width: 2px;
    background: var(--border-primary);
}

.hop-marker {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--accent-primary);
    border-radius: 50%;
    color: white;
    font-weight: 600;
    font-size: 0.75rem;
    z-index: 1;
}

.hop-content {
    flex: 1;
    min-width: 0;
}

.hop-server {
    font-weight: 600;
    word-break: break-all;
}

.hop-details {
    color: var(--text-secondary);
    margin-top: 0.25rem;
}

.hop-delay {
    display: inline-block;
    padding: 0.125rem 0.5rem;
    background: var(--bg-tertiary);
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    color: var(--text-tertiary);
    margin-top: 0.5rem;
}

.hop-delay.fast {
    color: var(--status-pass);
}

.hop-delay.slow {
    color: var(--status-warn);
}

.hop-delay.very-slow {
    color: var(--status-fail);
}

/* Spam Indicators */
.spam-indicators {
    display: grid;
    gap: 0.75rem;
}

.spam-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.875rem 1rem;
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
}

.spam-item.low {
    border-left: 3px solid var(--status-pass);
}

.spam-item.medium {
    border-left: 3px solid var(--status-warn);
}

.spam-item.high {
    border-left: 3px solid var(--status-fail);
}

.spam-icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

.spam-item.low .spam-icon { color: var(--status-pass); }
.spam-item.medium .spam-icon { color: var(--status-warn); }
.spam-item.high .spam-icon { color: var(--status-fail); }

.spam-text {
    flex: 1;
}

.spam-name {
    font-weight: 500;
    font-size: 0.9375rem;
}

.spam-desc {
    font-size: 0.8125rem;
    color: var(--text-secondary);
    margin-top: 0.125rem;
}

/* Raw Headers */
.raw-headers {
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
    font-size: 0.8125rem;
    line-height: 1.8;
    white-space: pre-wrap;
    word-break: break-all;
    max-height: 400px;
    overflow-y: auto;
    padding: 1rem;
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
    color: var(--text-secondary);
}

.raw-headers::-webkit-scrollbar {
    width: 8px;
}

.raw-headers::-webkit-scrollbar-track {
    background: var(--bg-tertiary);
    border-radius: 4px;
}

.raw-headers::-webkit-scrollbar-thumb {
    background: var(--border-secondary);
    border-radius: 4px;
}

.raw-headers::-webkit-scrollbar-thumb:hover {
    background: var(--text-tertiary);
}

/* Telegram CTA */
.telegram-cta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1.5rem;
    margin-top: 1.5rem;
    padding: 1.25rem 1.5rem;
    background: linear-gradient(135deg, rgba(34, 211, 238, 0.1) 0%, rgba(0, 136, 204, 0.1) 100%);
    border: 1px solid rgba(34, 211, 238, 0.2);
    border-radius: var(--radius-lg);
}

[data-theme="light"] .telegram-cta {
    background: linear-gradient(135deg, rgba(34, 211, 238, 0.08) 0%, rgba(0, 136, 204, 0.08) 100%);
    border-color: rgba(34, 211, 238, 0.3);
}

.cta-content {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
}

.cta-icon {
    width: 32px;
    height: 32px;
    color: #229ED9;
    flex-shrink: 0;
}

.cta-text {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.cta-text strong {
    font-size: 0.9375rem;
}

.cta-text span {
    font-size: 0.8125rem;
    color: var(--text-secondary);
}

.cta-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1.25rem;
    background: #229ED9;
    border-radius: var(--radius-md);
    color: white;
    text-decoration: none;
    font-size: 0.875rem;
    font-weight: 600;
    white-space: nowrap;
    transition: all var(--transition-fast);
}

.cta-btn:hover {
    background: #1a8cc7;
    transform: translateY(-1px);
}

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

/* Footer */
.footer {
    border-top: 1px solid var(--border-primary);
    padding: 2rem 1.5rem;
    margin-top: auto;
}

.footer-content {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.footer-text {
    font-size: 0.875rem;
    color: var(--text-tertiary);
    margin: 0;
}

.footer-build-info {
    font-size: 0.75rem;
    color: var(--text-tertiary);
    margin: 0.25rem 0 0 0;
}

.footer-links {
    display: flex;
    gap: 1.5rem;
}

.footer-link {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.875rem;
    transition: color var(--transition-fast);
}

.footer-link:hover {
    color: var(--text-primary);
}

.footer-link svg {
    width: 18px;
    height: 18px;
}

/* Error State */
.error-message {
    padding: 1.5rem;
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.2);
    border-radius: var(--radius-md);
    color: var(--status-fail);
    text-align: center;
}

.error-message strong {
    display: block;
    margin-bottom: 0.5rem;
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 3rem 1.5rem;
    color: var(--text-tertiary);
}

.empty-state-icon {
    width: 48px;
    height: 48px;
    margin: 0 auto 1rem;
    opacity: 0.5;
}

/* Responsive */
@media (max-width: 768px) {
    .header-content {
        padding: 0.875rem 1rem;
    }
    
    .telegram-link span {
        display: none;
    }
    
    .main {
        padding: 2rem 1rem;
    }
    
    .hero-title {
        font-size: 1.75rem;
    }
    
    .hero-subtitle {
        font-size: 1rem;
    }
    
    .mode-toggle-wrapper {
        flex-wrap: wrap;
        gap: 0.75rem;
    }
    
    .mode-label {
        font-size: 0.8125rem;
    }
    
    .telegram-cta {
        flex-direction: column;
        text-align: center;
    }
    
    .cta-content {
        flex-direction: column;
        align-items: center;
    }
    
    .footer-content {
        flex-direction: column;
        text-align: center;
    }
    
    .auth-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
    }
}

@media (max-width: 480px) {
    .result-header {
        padding: 0.875rem 1rem;
    }
    
    .result-body {
        padding: 1rem;
    }
    
    .copy-btn span {
        display: none;
    }
}

/* Security Headers Section */
.security-headers-grid {
    display: grid;
    gap: 0.75rem;
}

.security-header-item {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    padding: 1rem;
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
    border-left: 3px solid var(--border-primary);
}

.security-header-item .status-badge.pass ~ .security-header-right {
    border-left-color: var(--status-pass);
}

.security-header-item .status-badge.fail ~ .security-header-right {
    border-left-color: var(--status-fail);
}

.security-header-item .status-badge.warn ~ .security-header-right {
    border-left-color: var(--status-warn);
}

.security-header-left {
    flex: 1;
    min-width: 0;
}

.security-header-name {
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--text-primary);
    margin-bottom: 0.25rem;
}

.security-header-desc {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.security-header-right {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.5rem;
    min-width: 200px;
}

.security-header-value {
    font-size: 0.6875rem;
    color: var(--text-tertiary);
    font-family: 'SF Mono', 'Fira Code', monospace;
    max-width: 300px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

@media (max-width: 768px) {
    .security-header-item {
        flex-direction: column;
    }
    
    .security-header-right {
        align-items: flex-start;
        width: 100%;
    }
}
