/* =========================================
   CORS Configuration Tester — Styles
   Primary: #6366F1, Accent: #FCD34D
   Background: #0F0F24, Radius: 12px
   ========================================= */

*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary: #6366F1;
    --primary-light: #818CF8;
    --primary-dark: #4F46E5;
    --primary-glow: rgba(99, 102, 241, 0.15);
    --secondary: #818CF8;
    --accent: #FCD34D;
    --accent-glow: rgba(252, 211, 77, 0.15);

    --bg-base: #0F0F24;
    --bg-surface: #1A1A3E;
    --bg-elevated: #23234A;
    --bg-hover: #2D2D5A;
    --bg-input: #0D0D1F;

    --text-primary: #F1F5F9;
    --text-secondary: #A5B4FC;
    --text-muted: #6B7280;

    --border: #2D2D5A;
    --border-focus: #6366F1;

    --success: #10B981;
    --success-bg: rgba(16, 185, 129, 0.12);
    --error: #EF4444;
    --error-bg: rgba(239, 68, 68, 0.12);
    --warning: #F59E0B;
    --warning-bg: rgba(245, 158, 11, 0.12);
    --info: #60A5FA;
    --info-bg: rgba(96, 165, 250, 0.12);

    --radius: 12px;
    --radius-sm: 8px;
    --font: 'Inter', system-ui, sans-serif;
    --font-mono: 'JetBrains Mono', monospace;
    --transition: 200ms ease;
    --shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}

html {
    font-size: 16px;
}

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

.app-container {
    max-width: 800px;
    margin: 0 auto;
    padding: 0 20px 60px;
    position: relative;
}

/* Header */
.app-header {
    padding: 20px 0 16px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo {
    width: 42px;
    height: 42px;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    border-radius: var(--radius-sm);
    display: grid;
    place-items: center;
    color: #fff;
    box-shadow: 0 0 20px var(--primary-glow);
}

h1 {
    font-size: 1.3rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    background: linear-gradient(135deg, var(--text-primary), var(--primary-light));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.tagline {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 500;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-family: var(--font);
    font-size: 0.85rem;
    font-weight: 500;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    padding: 8px 12px;
}

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

.btn-sm {
    font-size: 0.8rem;
    padding: 6px 10px;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: #fff;
    padding: 12px 24px;
    font-weight: 600;
    border-radius: var(--radius);
    box-shadow: 0 0 20px var(--primary-glow);
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 0 30px rgba(99, 102, 241, 0.3);
}

.btn-secondary {
    background: var(--bg-surface);
    color: var(--primary-light);
    padding: 12px 24px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

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

.btn-accent {
    background: var(--accent);
    color: var(--bg-base);
    padding: 6px 14px;
    font-weight: 600;
}

.btn-danger {
    color: var(--error);
}

.btn-danger:hover {
    background: var(--error-bg);
}

/* Forms */
.config-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    margin-bottom: 24px;
}

.config-card h2 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 16px;
}

.form-row {
    display: flex;
    gap: 12px;
    margin-bottom: 14px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-group.grow {
    flex: 1;
}

.form-group label {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.input {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 0.85rem;
    padding: 10px 14px;
    transition: border-color var(--transition);
}

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

.select {
    font-family: var(--font);
    cursor: pointer;
}

.headers-container {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.header-row {
    display: flex;
    gap: 8px;
    align-items: center;
}

.header-key,
.header-value {
    flex: 1;
}

.actions-row {
    margin-top: 20px;
    gap: 12px;
}

/* Flow Diagram */
.flow-section {
    margin-bottom: 24px;
    animation: fadeIn 300ms ease;
}

.flow-section h2 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 12px;
}

.flow-diagram {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.flow-step {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    animation: slideRight 300ms ease backwards;
}

.flow-step:nth-child(1) {
    animation-delay: 0ms;
}

.flow-step:nth-child(2) {
    animation-delay: 100ms;
}

.flow-step:nth-child(3) {
    animation-delay: 200ms;
}

.flow-step:nth-child(4) {
    animation-delay: 300ms;
}

.flow-step.request {
    background: var(--info-bg);
    border-left: 3px solid var(--info);
}

.flow-step.response {
    background: var(--success-bg);
    border-left: 3px solid var(--success);
}

.flow-step.error-step {
    background: var(--error-bg);
    border-left: 3px solid var(--error);
}

.flow-step.preflight {
    background: var(--warning-bg);
    border-left: 3px solid var(--warning);
}

.flow-arrow {
    color: var(--text-muted);
    font-size: 0.8rem;
    text-align: center;
}

.flow-label {
    font-weight: 600;
    min-width: 80px;
    flex-shrink: 0;
}

.flow-detail {
    color: var(--text-secondary);
    font-family: var(--font-mono);
    font-size: 0.8rem;
    word-break: break-all;
}

/* Results */
.results-section {
    margin-bottom: 24px;
    animation: fadeIn 300ms ease;
}

.results-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

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

.result-badge {
    font-size: 0.75rem;
    font-weight: 600;
    padding: 4px 12px;
    border-radius: 100px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.result-badge.pass {
    background: var(--success-bg);
    color: var(--success);
    border: 1px solid rgba(16, 185, 129, 0.25);
}

.result-badge.fail {
    background: var(--error-bg);
    color: var(--error);
    border: 1px solid rgba(239, 68, 68, 0.25);
}

.result-badge.warn {
    background: var(--warning-bg);
    color: var(--warning);
    border: 1px solid rgba(245, 158, 11, 0.25);
}

.cors-headers {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 16px;
    font-family: var(--font-mono);
    font-size: 0.82rem;
    line-height: 1.8;
}

.header-item {
    display: flex;
    gap: 10px;
    align-items: baseline;
}

.header-name {
    color: var(--primary-light);
    min-width: 200px;
    flex-shrink: 0;
    font-weight: 600;
}

.header-val {
    color: var(--text-primary);
    word-break: break-word;
}

.header-val.missing {
    color: var(--error);
    font-style: italic;
}

.diagnosis {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 16px;
}

.diag-item {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
}

.diag-item.error {
    background: var(--error-bg);
    border-left: 3px solid var(--error);
}

.diag-item.warning {
    background: var(--warning-bg);
    border-left: 3px solid var(--warning);
}

.diag-item.success {
    background: var(--success-bg);
    border-left: 3px solid var(--success);
}

.diag-item.info {
    background: var(--info-bg);
    border-left: 3px solid var(--info);
}

.diag-icon {
    flex-shrink: 0;
    font-size: 1rem;
}

.diag-text {
    flex: 1;
}

.diag-fix {
    display: block;
    margin-top: 4px;
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-style: italic;
}

/* Server Config */
.server-config {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 16px;
}

.config-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
    flex-wrap: wrap;
    gap: 8px;
}

.config-header h3 {
    font-size: 0.9rem;
    font-weight: 600;
}

.config-tabs {
    display: flex;
    gap: 4px;
}

.config-tab {
    padding: 4px 12px;
    font-size: 0.78rem;
    font-family: var(--font);
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition);
}

.config-tab.active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

.config-code {
    background: var(--bg-input);
    border-radius: var(--radius-sm);
    padding: 16px;
    font-family: var(--font-mono);
    font-size: 0.82rem;
    color: var(--accent);
    line-height: 1.6;
    overflow-x: auto;
    white-space: pre-wrap;
    margin-bottom: 10px;
}

/* Examples */
.examples-section {
    margin-bottom: 24px;
}

.examples-section h2 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 12px;
}

.examples-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
    gap: 10px;
}

.example-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    cursor: pointer;
    transition: all var(--transition);
    text-align: left;
    font-family: var(--font);
    color: var(--text-primary);
}

.example-card:hover {
    border-color: var(--primary);
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

.example-icon {
    font-size: 1.4rem;
    margin-bottom: 2px;
}

.example-title {
    font-size: 0.85rem;
    font-weight: 600;
}

.example-desc {
    font-size: 0.72rem;
    color: var(--text-muted);
}

/* History Panel */
.history-panel {
    position: fixed;
    top: 0;
    right: 0;
    width: 320px;
    max-width: 90vw;
    height: 100vh;
    background: var(--bg-surface);
    border-left: 1px solid var(--border);
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    z-index: 100;
    box-shadow: -8px 0 30px rgba(0, 0, 0, 0.5);
    animation: slideInRight 250ms ease;
    overflow-y: auto;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.panel-header h2 {
    font-size: 1.1rem;
    font-weight: 700;
}

.history-list {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.history-item {
    padding: 10px 12px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: border-color var(--transition);
}

.history-item:hover {
    border-color: var(--primary);
}

.history-item-url {
    font-family: var(--font-mono);
    font-size: 0.78rem;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.history-item-meta {
    display: flex;
    gap: 8px;
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 4px;
}

.history-status.pass {
    color: var(--success);
    font-weight: 600;
}

.history-status.fail {
    color: var(--error);
    font-weight: 600;
}

.empty-state {
    color: var(--text-muted);
    text-align: center;
    padding: 24px 0;
    font-size: 0.85rem;
}

/* Loading */
.loading {
    position: fixed;
    inset: 0;
    background: rgba(15, 15, 36, 0.8);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    z-index: 200;
    color: var(--text-primary);
    font-size: 0.9rem;
}

.spinner {
    width: 36px;
    height: 36px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 800ms linear infinite;
}

/* Toast */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 20px;
    font-size: 0.85rem;
    color: var(--text-primary);
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
    z-index: 300;
    opacity: 0;
    transition: transform 250ms ease, opacity 250ms ease;
    pointer-events: none;
}

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

.hidden {
    display: none !important;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes slideRight {
    from {
        opacity: 0;
        transform: translateX(-20px);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes slideInRight {
    from {
        transform: translateX(100%);
    }

    to {
        transform: translateX(0);
    }
}

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

@media (max-width: 640px) {
    .form-row {
        flex-direction: column;
    }

    .header-name {
        min-width: 120px;
    }

    .examples-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .history-panel {
        width: 100%;
    }
}

:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}