/* CSS Reset & Variables */
:root {
    --bg-color: #0d1117;
    --card-bg: rgba(22, 27, 34, 0.7);
    --card-border: rgba(240, 246, 252, 0.1);
    --primary: #f02e65;
    /* n8n primary like color or custom */
    --primary-glow: rgba(240, 46, 101, 0.3);
    --secondary: #5865F2;
    --text-main: #f0f6fc;
    --text-muted: #8b949e;
    --focus-color: #58a6ff;
    --success: #2ea043;

    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --font-mono: 'JetBrains Mono', monospace;

    --transition-speed: 0.2s;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background-color: var(--bg-color);
    color: var(--text-main);
    font-family: var(--font-sans);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow-x: hidden;
    position: relative;
}

/* Background Effects */
.background-grid {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: linear-gradient(var(--card-border) 1px, transparent 1px),
        linear-gradient(90deg, var(--card-border) 1px, transparent 1px);
    background-size: 50px 50px;
    opacity: 0.05;
    z-index: -1;
    pointer-events: none;
}

/* Sidebar History */
.history-sidebar {
    position: fixed;
    left: 2rem;
    top: 50%;
    transform: translateY(-50%);
    width: 260px;
    max-height: 80vh;
    background: rgba(22, 27, 34, 0.6);
    backdrop-filter: blur(10px);
    border: 1px solid var(--card-border);
    border-radius: 16px;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    z-index: 10;
    opacity: 0;
    animation: fadeIn 0.8s ease-out 0.5s forwards;
    overflow-y: auto;
}

.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--card-border);
}

.history-header h3 {
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
}

.icon-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 1rem;
    padding: 2px;
    opacity: 0.6;
    transition: 0.2s;
}

.icon-btn:hover {
    opacity: 1;
    transform: scale(1.1);
}

.history-list {
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
}

.history-item {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--card-border);
    border-radius: 8px;
    padding: 0.8rem;
    cursor: pointer;
    transition: all 0.2s;
}

.history-item:hover {
    background: rgba(255, 255, 255, 0.08);
    transform: translateX(4px);
    border-color: var(--primary-glow);
}

.history-time {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-bottom: 0.2rem;
    display: block;
}

.history-prompt {
    font-size: 0.85rem;
    color: var(--text-main);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    line-height: 1.4;
}

.history-placeholder {
    font-size: 0.8rem;
    color: var(--text-muted);
    text-align: center;
    padding: 1rem 0;
    font-style: italic;
}

/* Background Effects */
.background-glob {
    position: fixed;
    top: -20%;
    left: -10%;
    width: 60vw;
    height: 60vw;
    background: radial-gradient(circle, var(--primary-glow) 0%, transparent 60%);
    opacity: 0.4;
    filter: blur(80px);
    z-index: -2;
    animation: pulse 10s ease-in-out infinite alternate;
}

@keyframes pulse {
    0% {
        transform: scale(1);
        opacity: 0.3;
    }

    100% {
        transform: scale(1.1);
        opacity: 0.5;
    }
}

/* Container */
.container {
    width: 90%;
    max-width: 800px;
    padding: 3rem;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 24px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    margin: 2rem 0;
    opacity: 0;
    transform: translateY(20px);
    animation: fadeIn 0.6s ease-out forwards;
}

@keyframes fadeIn {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Header */
.header {
    text-align: center;
    margin-bottom: 2.5rem;
}

.logo-wrapper {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 64px;
    height: 64px;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0.05));
    border-radius: 16px;
    border: 1px solid var(--card-border);
    margin-bottom: 1rem;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.logo-icon {
    font-size: 32px;
}

h1 {
    font-weight: 700;
    font-size: 2.5rem;
    background: linear-gradient(135deg, #fff 0%, #aaa 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 0.5rem;
    letter-spacing: -0.02em;
}

.subtitle {
    color: var(--text-muted);
    font-size: 1.1rem;
}

/* Inputs */
.input-group {
    margin-bottom: 2rem;
    position: relative;
}

.textarea-wrapper {
    position: relative;
    border-radius: 12px;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--card-border);
    transition: all var(--transition-speed);
}

.textarea-wrapper:focus-within {
    border-color: var(--focus-color);
    box-shadow: 0 0 0 3px rgba(88, 166, 255, 0.15);
}

textarea {
    width: 100%;
    height: 140px;
    background: transparent;
    border: none;
    color: var(--text-main);
    padding: 1.5rem;
    font-family: var(--font-sans);
    font-size: 1rem;
    resize: vertical;
    outline: none;
}

textarea::placeholder {
    color: rgba(139, 148, 158, 0.5);
}

/* Example Chips */
.examples {
    margin-top: 1rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
}

.example-label {
    font-size: 0.85rem;
    color: var(--text-muted);
    font-weight: 500;
}

.example-chip {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--card-border);
    color: var(--text-muted);
    padding: 0.3rem 0.8rem;
    border-radius: 20px;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: none;
}

.example-chip:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-main);
    border-color: rgba(255, 255, 255, 0.2);
    transform: translateY(-1px);
    box-shadow: none;
}

/* Actions */
.actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
}

.toggle-switch {
    display: flex;
    align-items: center;
    cursor: pointer;
    user-select: none;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: relative;
    display: inline-block;
    width: 48px;
    height: 26px;
    background-color: rgba(255, 255, 255, 0.1);
    border-radius: 34px;
    transition: .3s;
    margin-right: 12px;
    border: 1px solid var(--card-border);
}

.slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    border-radius: 50%;
    transition: .3s;
}

input:checked+.slider {
    background-color: var(--success);
    border-color: var(--success);
}

input:checked+.slider:before {
    transform: translateX(22px);
}

.label-text {
    color: var(--text-main);
    font-weight: 500;
}

/* Access Code Input styling - Premium Dark Mode */
.access-code-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    height: 48px;
    /* Match button height */
}

.lock-icon {
    position: absolute;
    left: 14px;
    width: 18px;
    height: 18px;
    color: rgba(255, 255, 255, 0.4);
    pointer-events: none;
    transition: color 0.3s ease;
    z-index: 2;
}

.access-input {
    height: 100%;
    background: rgba(15, 15, 20, 0.6);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: #fff;
    padding: 0 1rem 0 3rem;
    /* Left padding for icon */
    border-radius: 12px;
    font-size: 0.95rem;
    font-family: 'Inter', sans-serif;
    outline: none;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    width: 220px;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.2);
}

.access-input::placeholder {
    color: rgba(255, 255, 255, 0.25);
    font-weight: 400;
}

.access-input:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.2);
}

.access-input:focus {
    background: rgba(20, 20, 25, 0.9);
    border-color: var(--focus-color);
    box-shadow: 0 0 0 1px var(--focus-color), 0 0 15px rgba(88, 166, 255, 0.2);
    color: #fff;
}

.access-input:focus+.lock-icon,
.access-code-wrapper:focus-within .lock-icon {
    color: var(--focus-color);
}

/* Ensure Button matches height */
button {
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    padding: 0 2rem;
    background: linear-gradient(135deg, var(--primary) 0%, #ff4b82 100%);
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    overflow: hidden;
    transition: transform 0.1s, box-shadow 0.2s;
    box-shadow: 0 4px 12px var(--primary-glow);
}

button:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px var(--primary-glow);
}

button:active {
    transform: translateY(0);
}

.btn-shine {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(to right, transparent, rgba(255, 255, 255, 0.2), transparent);
    transform: translateX(-100%);
    transition: transform 0.5s;
}

button:hover .btn-shine {
    transform: translateX(100%);
    transition: 0.5s ease-in-out;
}

/* Result Section */
.result-section {
    margin-top: 2.5rem;
    border-top: 1px solid var(--card-border);
    padding-top: 2rem;
    animation: slideUp 0.4s ease-out;
}

.result-section.hidden {
    display: none;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.result-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.result-header h2 {
    font-size: 1.25rem;
    font-weight: 600;
}

.result-actions {
    display: flex;
    gap: 0.5rem;
}

.action-btn {
    background: transparent;
    border: 1px solid var(--card-border);
    padding: 0.4rem;
    border-radius: 8px;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    box-shadow: none;
}

.action-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-main);
    transform: translateY(-1px);
    box-shadow: none;
}

.code-block-wrapper {
    background: #000;
    border-radius: 12px;
    padding: 1.5rem;
    overflow-x: auto;
    border: 1px solid var(--card-border);
    max-height: 400px;
    overflow-y: auto;
    margin-bottom: 2rem;
}

/* Prism Overrides */
pre[class*="language-"] {
    background: transparent !important;
    text-shadow: none !important;
    padding: 0 !important;
    margin: 0 !important;
}

code[class*="language-"],
pre[class*="language-"] {
    font-family: var(--font-mono) !important;
    font-size: 0.85rem !important;
    line-height: 1.5 !important;
}

/* Workflow Summary */
.workflow-summary {
    margin-bottom: 2rem;
}

.workflow-summary.hidden {
    display: none;
}

.workflow-summary h3,
.setup-guide h3 {
    font-size: 1rem;
    color: var(--text-muted);
    margin-bottom: 1rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    font-weight: 600;
}

.node-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.8rem;
    align-items: center;
    padding: 1rem;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 12px;
    border: 1px dashed var(--card-border);
}

.node-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: rgba(255, 255, 255, 0.08);
    padding: 0.5rem 0.8rem;
    border-radius: 8px;
    font-size: 0.9rem;
    border: 1px solid var(--card-border);
}

.node-arrow {
    color: var(--text-muted);
    font-size: 1.2rem;
}

/* Setup Guide */
.setup-guide {
    background: rgba(88, 166, 255, 0.05);
    /* Blue tint */
    border: 1px solid rgba(88, 166, 255, 0.1);
    border-radius: 12px;
    padding: 1.5rem;
}

.setup-guide ol {
    padding-left: 1.5rem;
    color: var(--text-main);
}

.setup-guide li {
    margin-bottom: 0.5rem;
}

.setup-guide a {
    color: var(--focus-color);
    text-decoration: none;
}

.setup-guide a:hover {
    text-decoration: underline;
}

/* Loader */
.loader {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(13, 17, 23, 0.8);
    backdrop-filter: blur(5px);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 100;
}

.loader.hidden {
    display: none;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(255, 255, 255, 0.1);
    border-radius: 50%;
    border-top-color: var(--primary);
    animation: spin 1s ease-in-out infinite;
    margin-bottom: 1rem;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.loader p {
    color: var(--text-main);
    font-weight: 500;
}

/* Toast */
.toast {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%);
    background: var(--success);
    color: white;
    padding: 0.8rem 1.5rem;
    border-radius: 50px;
    font-weight: 500;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    z-index: 200;
    transition: opacity 0.3s, transform 0.3s;
}

.toast.hidden {
    opacity: 0;
    transform: translate(-50%, 20px);
    font-weight: 500;
}

/* Footer */
.footer {
    position: absolute;
    bottom: 0.5rem;
    width: 100%;
    text-align: center;
    color: var(--card-border);
    font-size: 0.75rem;
    padding: 1rem;
    pointer-events: none;
}

.footer p {
    pointer-events: auto;
    display: inline-block;
}

.footer a {
    color: var(--text-muted);
    text-decoration: none;
    transition: color 0.2s;
}

.footer a:hover {
    color: var(--primary);
}

/* Responsive */
@media (max-width: 1300px) {
    .history-sidebar {
        display: none;
        /* Hide history on smaller screens for simplicity now */
    }
}

@media (max-width: 600px) {
    .container {
        padding: 1.5rem;
        width: 95%;
    }

    h1 {
        font-size: 2rem;
    }

    .actions {
        flex-direction: column;
        align-items: stretch;
    }

    .toggle-switch {
        justify-content: center;
        margin-bottom: 1rem;
    }

    button {
        width: 100%;
    }

    .access-code-wrapper {
        width: 100%;
        margin-bottom: 1rem;
    }

    .access-input {
        width: 100%;
    }
}