/* CSS Variables */
:root {
    --n8n-primary: #2563eb;
    --n8n-bg: #ffffff;
    --n8n-text: #1f2937;
    --n8n-gray: #f3f4f6;
    --n8n-border: #e5e7eb;
    --n8n-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}

/* --- Admin Panel Styling --- */
.n8n-admin-wrapper {
    margin-top: 20px;
    max-width: 800px;
}

.n8n-admin-header {
    display: flex;
    align-items: center;
    gap: 10px;
}

.version-badge {
    background: #e5e7eb;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 11px;
    color: #374151;
}

.n8n-form-card {
    background: #fff;
    padding: 2rem;
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    margin-bottom: 20px;
    border: 1px solid #e5e7eb;
}

.status-card {
    border-left: 5px solid var(--n8n-primary);
}

.n8n-admin-form label {
    display: block;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: #374151;
}

.n8n-admin-form input[type="text"],
.n8n-admin-form input[type="url"],
.n8n-admin-form input[type="email"] {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    margin-bottom: 1rem;
    transition: border-color 0.2s;
}

.n8n-admin-form input:focus {
    border-color: var(--n8n-primary);
    outline: none;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.n8n-grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
}

.n8n-save-btn {
    background: #111827 !important;
    border: none !important;
    padding: 12px 30px !important;
    font-size: 16px !important;
    border-radius: 8px !important;
}

/* Toggle Switch */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 24px;
    margin-right: 10px;
    vertical-align: middle;
    cursor: pointer;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
    margin: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #ccc;
    transition: .4s;
    border-radius: 24px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 16px;
    width: 16px;
    left: 4px;
    bottom: 4px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}

input:checked+.slider {
    background-color: var(--n8n-primary);
}

input:checked+.slider:before {
    transform: translateX(26px);
}

/* --- Frontend Chat Widget Styling --- */
#n8n-chat-toggle {
    position: fixed;
    bottom: 20px;
    right: 20px;
    /* MASAÜSTÜNDE SAĞDA */
    width: 60px;
    height: 60px;
    background-color: var(--n8n-primary);
    color: white;
    border: none;
    border-radius: 50%;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
    cursor: pointer;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

#n8n-chat-toggle:hover {
    transform: scale(1.05);
}

#n8n-chat-toggle svg {
    width: 30px;
    height: 30px;
}

.hidden {
    display: none !important;
}

/* Main Container (Desktop) */
#n8n-chat-container {
    position: fixed;
    bottom: 90px;
    right: 20px;
    width: 700px;
    height: 600px;
    background: var(--n8n-bg);
    border-radius: 16px;
    box-shadow: var(--n8n-shadow);
    display: flex;
    flex-direction: column;
    z-index: 9998;
    overflow: hidden;
    opacity: 0;
    transform: translateY(20px);
    transition: all 0.3s ease;
    pointer-events: none;
    font-family: 'Segoe UI', system-ui, sans-serif;
    border: 1px solid #e5e7eb;
}

#n8n-chat-widget.open #n8n-chat-container {
    opacity: 1;
    transform: translateY(0);
    pointer-events: all;
}

/* Header */
.n8n-chat-header {
    background: var(--n8n-primary);
    color: white;
    padding: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.header-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.header-actions {
    display: flex;
    align-items: center;
}

/* Avatars */
.bot-avatar {
    background: rgba(255, 255, 255, 0.2);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
}

.bot-avatar-img {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    background: white;
}

.n8n-chat-header h4 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    color: #fff;
}

.status-indicator {
    display: inline-block;
    width: 8px;
    height: 8px;
    background: #4ade80;
    border-radius: 50%;
}

/* Buttons in Header */
#n8n-chat-close-btn,
#n8n-chat-end-btn {
    background: transparent;
    border: none;
    color: white;
    font-size: 24px;
    cursor: pointer;
    padding: 0 5px;
    opacity: 0.8;
    transition: opacity 0.2s;
    display: flex;
    align-items: center;
}

#n8n-chat-close-btn:hover,
#n8n-chat-end-btn:hover {
    opacity: 1;
}

/* Login Screen */
#n8n-chat-login-screen {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 2rem;
    background: #fff;
    overflow-y: auto;
}

.n8n-login-content h3 {
    margin: 0 0 10px 0;
    font-size: 20px;
    color: #111827;
}

.n8n-login-content p {
    color: #6b7280;
    font-size: 14px;
    margin-bottom: 20px;
}

.n8n-input-group {
    margin-bottom: 15px;
}

.n8n-input-group label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    margin-bottom: 5px;
    color: #374151;
}

/* iPhone Zoom Fix */
.n8n-input-group input {
    width: 100%;
    padding: 12px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    font-size: 16px;
    box-sizing: border-box;
    background: #fff;
    -webkit-appearance: none;
}

.n8n-input-group input:focus {
    border-color: var(--n8n-primary);
    outline: none;
}

.n8n-start-btn {
    width: 100%;
    padding: 14px;
    background: var(--n8n-primary);
    color: white;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    margin-top: 10px;
    transition: background 0.2s;
    font-size: 16px;
}

.n8n-start-btn:hover {
    filter: brightness(90%);
}

/* Chat Interface */
#n8n-chat-interface {
    display: flex;
    flex-direction: column;
    height: 100%;
    flex: 1;
    overflow: hidden;
    position: relative;
}

#n8n-chat-messages {
    flex: 1;
    padding: 1.5rem;
    overflow-y: auto;
    background: #f9fafb;
    display: flex;
    flex-direction: column;
    gap: 15px;
    -webkit-overflow-scrolling: touch;
}

/* Message Bubbles */
.message {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 15px;
    line-height: 1.6;
    word-wrap: break-word;
    animation: fadeIn 0.3s ease;
}

.message.bot {
    background: white;
    color: #374151;
    border-bottom-left-radius: 2px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
    align-self: flex-start;
}

.message.user {
    background: var(--n8n-primary);
    color: white;
    border-bottom-right-radius: 2px;
    align-self: flex-end;
}

/* Markdown Styles */
.message.bot strong {
    font-weight: 700;
    color: #111827;
}

.message.bot a {
    color: var(--n8n-primary);
    text-decoration: underline;
    font-weight: 500;
}

.message.bot ul,
.message.bot ol {
    margin: 8px 0 8px 20px;
    padding: 0;
    list-style-position: outside;
}

.message.bot ul {
    list-style-type: disc;
}

.message.bot ol {
    list-style-type: decimal;
}

.message.bot li {
    margin-bottom: 4px;
}

.message.bot p {
    margin: 0 0 8px 0;
}

.message.bot p:last-child {
    margin-bottom: 0;
}

/* Input Area */
.n8n-chat-input-area {
    padding: 1rem;
    background: white;
    border-top: 1px solid var(--n8n-border);
    flex-shrink: 0;
}

#n8n-chat-form {
    display: flex;
    gap: 10px;
    align-items: center;
}

#n8n-chat-input {
    flex: 1;
    padding: 12px;
    border: 1px solid var(--n8n-border);
    border-radius: 8px;
    outline: none;
    font-size: 16px;
    -webkit-appearance: none;
}

#n8n-chat-input:focus {
    border-color: var(--n8n-primary);
}

#n8n-chat-form button {
    background: var(--n8n-primary);
    color: white;
    border: none;
    width: 48px;
    height: 48px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    -webkit-appearance: none;
    padding: 0;
}

#n8n-chat-form button svg {
    width: 24px;
    height: 24px;
    stroke: currentColor;
    fill: none;
    display: block;
}

/* Çıkış Onay Overlay */
#n8n-end-confirm-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.95);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10000;
    animation: fadeIn 0.2s;
}

.n8n-confirm-box {
    background: white;
    padding: 2rem;
    border-radius: 12px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
    border: 1px solid #e5e7eb;
    text-align: center;
    width: 80%;
    max-width: 300px;
}

.n8n-confirm-box h4 {
    margin: 0 0 10px 0;
    font-size: 18px;
    color: #111827;
}

.n8n-confirm-box p {
    margin: 0 0 20px 0;
    color: #6b7280;
    font-size: 14px;
}

.n8n-action-btn {
    display: block;
    width: 100%;
    padding: 12px;
    margin-bottom: 10px;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    font-size: 15px;
    font-weight: 500;
    transition: filter 0.2s;
}

.n8n-action-btn.primary {
    background: var(--n8n-primary);
    color: white;
}

.n8n-action-btn.secondary {
    background: #f3f4f6;
    color: #374151;
}

.n8n-action-btn.text {
    background: transparent;
    color: #6b7280;
    margin-bottom: 0;
    text-decoration: underline;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(5px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* --- MOBILE RESPONSIVE --- */
@media (max-width: 768px) {

    /* 1. Butonu MOBİLDE Sola Al */
    #n8n-chat-toggle {
        right: auto !important;
        /* Sağdaki pozisyonu iptal et */
        left: 20px !important;
        /* Sola sabitle */
    }

    /* 2. Chat Penceresi Tam Ekran */
    #n8n-chat-container {
        width: 100% !important;
        height: 100% !important;
        max-width: none !important;
        max-height: none !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        border-radius: 0 !important;
        border: none !important;
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
    }

    #n8n-chat-widget.open #n8n-chat-container {
        transform: none !important;
    }

    /* 3. Giriş Ekranı Scroll */
    #n8n-chat-login-screen {
        justify-content: flex-start;
        padding-top: 15vh;
    }

    .n8n-login-content {
        flex: 0 1 auto;
    }

    #n8n-chat-close-btn {
        font-size: 28px;
        padding: 10px;
    }
}