/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Helvetica', 'Arial', sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    color: #333;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* Shared utility */
.eyebrow {
    text-transform: uppercase;
    letter-spacing: 1.2px;
    font-weight: 700;
    font-size: 0.75rem;
    color: #8b5cf6;
    margin-bottom: 6px;
}

/* Header */
.header {
    background: white;
    padding: 20px 30px;
    border-radius: 12px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    margin-bottom: 20px;
    text-align: center;
}

.header h1 {
    color: #667eea;
    font-size: 2rem;
    margin-bottom: 5px;
}

.subtitle {
    color: #666;
    font-size: 0.95rem;
}

/* Main Content */
.main-content {
    display: grid;
    grid-template-columns: 320px 1fr;
    gap: 20px;
    flex: 1;
}

/* Sidebar */
.sidebar {
    background: white;
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
    gap: 20px;
    height: fit-content;
}

.sidebar h3 {
    color: #667eea;
    font-size: 1.1rem;
    margin-bottom: 15px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.form-group {
    margin-bottom: 15px;
}

.form-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: 500;
    color: #555;
    font-size: 0.9rem;
}

.form-group input {
    width: 100%;
    padding: 10px;
    border: 2px solid #e0e0e0;
    border-radius: 6px;
    font-size: 0.9rem;
    transition: border-color 0.3s;
}

.form-group input:focus {
    outline: none;
    border-color: #667eea;
}

/* Status Section */
.status-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid #f0f0f0;
}

.status-item:last-child {
    border-bottom: none;
}

.status-label {
    font-weight: 500;
    color: #666;
    font-size: 0.9rem;
}

.status-value {
    font-size: 0.9rem;
    color: #333;
    font-weight: 600;
}

.status-connected {
    color: #10b981;
}

.status-disconnected {
    color: #ef4444;
}

/* Progress Section */
.progress-bar {
    width: 100%;
    height: 24px;
    background: #f0f0f0;
    border-radius: 12px;
    overflow: hidden;
    margin-bottom: 8px;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
    transition: width 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 0.8rem;
    font-weight: 600;
}

.progress-text {
    text-align: center;
    font-size: 0.9rem;
    color: #666;
}

/* Actions Section */
.actions-section {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* Buttons */
.btn {
    padding: 12px 20px;
    border: none;
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

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

.btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.btn-primary:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.btn-warning {
    background: #f59e0b;
    color: white;
}

.btn-warning:hover:not(:disabled) {
    background: #d97706;
}

.btn-secondary {
    background: #6b7280;
    color: white;
}

.btn-secondary:hover {
    background: #4b5563;
}

/* Chat Area */
.chat-area {
    background: white;
    border-radius: 12px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chat-messages {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    max-height: calc(100vh - 300px);
    min-height: 400px;
}

/* Welcome Message */
.welcome-message {
    text-align: center;
    padding: 40px 20px;
    color: #666;
}

.welcome-message h2 {
    color: #667eea;
    margin-bottom: 10px;
}

.example-queries {
    margin-top: 30px;
    text-align: left;
    max-width: 500px;
    margin-left: auto;
    margin-right: auto;
}

.example-queries p {
    margin-bottom: 15px;
    font-weight: 600;
}

.example-btn {
    display: block;
    width: 100%;
    padding: 12px 20px;
    margin-bottom: 10px;
    background: #f3f4f6;
    border: 2px solid #e5e7eb;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s;
    text-align: left;
    font-size: 0.95rem;
}

.example-btn:hover {
    background: #667eea;
    color: white;
    border-color: #667eea;
    transform: translateX(5px);
}

/* Message Bubbles */
.message {
    margin-bottom: 20px;
    display: flex;
    animation: fadeIn 0.3s ease;
}

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

.message.user {
    justify-content: flex-end;
}

.message.assistant {
    justify-content: flex-start;
}

.message-bubble {
    max-width: 70%;
    padding: 15px 20px;
    border-radius: 18px;
    position: relative;
    word-wrap: break-word;
}

.message.user .message-bubble {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-bottom-right-radius: 4px;
}

.message.assistant .message-bubble {
    background: #f3f4f6;
    color: #333;
    border-bottom-left-radius: 4px;
}

.message-header {
    font-size: 0.8rem;
    font-weight: 600;
    margin-bottom: 5px;
    opacity: 0.8;
}

.message-content {
    line-height: 1.5;
    white-space: pre-wrap;
}

.message-time {
    font-size: 0.75rem;
    opacity: 0.6;
    margin-top: 5px;
}

/* System Messages */
.message.system .message-bubble {
    background: #fef3c7;
    color: #92400e;
    border-left: 4px solid #f59e0b;
    max-width: 100%;
}

/* Loading Indicator */
.loading {
    display: flex;
    gap: 5px;
    padding: 10px;
}

.loading-dot {
    width: 8px;
    height: 8px;
    background: #667eea;
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out both;
}

.loading-dot:nth-child(1) {
    animation-delay: -0.32s;
}

.loading-dot:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes bounce {
    0%, 80%, 100% {
        transform: scale(0);
    }
    40% {
        transform: scale(1);
    }
}

/* Chat Input */
.chat-input-area {
    padding: 20px;
    border-top: 2px solid #f0f0f0;
    background: #fafafa;
}

.input-wrapper {
    display: flex;
    gap: 10px;
}

#messageInput {
    flex: 1;
    padding: 15px 20px;
    border: 2px solid #e0e0e0;
    border-radius: 25px;
    font-size: 1rem;
    transition: border-color 0.3s;
}

#messageInput:focus {
    outline: none;
    border-color: #667eea;
}

#sendBtn {
    padding: 15px 30px;
    border-radius: 25px;
    white-space: nowrap;
}

/* Footer */
.footer {
    background: white;
    padding: 15px 30px;
    border-radius: 12px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    margin-top: 20px;
    text-align: center;
    font-size: 0.9rem;
    color: #666;
}

.footer a {
    color: #667eea;
    text-decoration: none;
    font-weight: 600;
}

.footer a:hover {
    text-decoration: underline;
}

/* Responsive Design */
@media (max-width: 1024px) {
    .main-content {
        grid-template-columns: 1fr;
    }
    
    .sidebar {
        order: 2;
    }
    
    .chat-area {
        order: 1;
    }
}

@media (max-width: 768px) {
    .container {
        padding: 10px;
    }
    
    .header h1 {
        font-size: 1.5rem;
    }
    
    .message-bubble {
        max-width: 85%;
    }
    
    .input-wrapper {
        flex-direction: column;
    }
    
    #sendBtn {
        width: 100%;
    }
}

/* Scrollbar Styling */
.chat-messages::-webkit-scrollbar {
    width: 8px;
}

.chat-messages::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 10px;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: #667eea;
    border-radius: 10px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: #764ba2;
}

/* =========================
   Admin page styles
   ========================= */
.admin-body {
    background: #0f172a;
    color: #0b1220;
}

.admin-container {
    max-width: 1200px;
}

.admin-header {
    background: radial-gradient(circle at 10% 20%, rgba(124, 58, 237, 0.15), transparent 25%),
                radial-gradient(circle at 90% 20%, rgba(59, 130, 246, 0.15), transparent 25%),
                #0f172a;
    color: #e5e7eb;
    border: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.admin-header h1 {
    color: #fff;
    margin-bottom: 6px;
}

.admin-header .subtitle {
    color: #cbd5e1;
}

.header-actions {
    display: flex;
    gap: 10px;
}

.btn.ghost {
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: inherit;
}

.admin-main {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-bottom: 20px;
}

.card {
    background: #0b1220;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 14px;
    padding: 20px;
    color: #e5e7eb;
}

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

.config-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 12px;
    align-items: end;
}

.config-actions {
    display: flex;
    gap: 10px;
    align-items: center;
}

.hint {
    color: #94a3b8;
    font-size: 0.85rem;
}

.status-pill {
    padding: 6px 12px;
    border-radius: 999px;
    font-weight: 700;
    font-size: 0.85rem;
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(255, 255, 255, 0.05);
}

.pill-ok {
    color: #22c55e;
    border-color: rgba(34, 197, 94, 0.3);
}

.pill-bad {
    color: #f97316;
    border-color: rgba(249, 115, 22, 0.3);
}

.table-card {
    overflow: hidden;
}

.list-actions {
    display: flex;
    gap: 10px;
    align-items: center;
}

.search-input {
    padding: 10px 12px;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(255, 255, 255, 0.04);
    color: #e5e7eb;
    min-width: 200px;
}

.search-input::placeholder {
    color: #94a3b8;
}

.table-wrapper {
    overflow-x: auto;
}

.playbook-table {
    width: 100%;
    border-collapse: collapse;
    color: #e5e7eb;
}

.playbook-table th,
.playbook-table td {
    text-align: left;
    padding: 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    vertical-align: top;
}

.playbook-table th {
    color: #cbd5e1;
    font-weight: 700;
    font-size: 0.95rem;
}

.empty-state {
    text-align: center;
    color: #94a3b8;
    padding: 18px;
}

.cell-title {
    font-weight: 700;
    color: #e5e7eb;
}

.cell-sub {
    color: #94a3b8;
    font-size: 0.9rem;
    margin-top: 4px;
}

.chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    border-radius: 999px;
    font-size: 0.85rem;
    margin: 2px;
}

.chip-filled {
    background: rgba(99, 102, 241, 0.18);
    color: #c7d2fe;
}

.chip-outline {
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: #e5e7eb;
}

.chip-ghost {
    background: rgba(255, 255, 255, 0.08);
    color: #e5e7eb;
}

.chip.removable {
    cursor: pointer;
}

.action-cell {
    display: flex;
    gap: 8px;
    align-items: center;
}

.icon-btn {
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 10px;
    color: #e5e7eb;
    padding: 8px 10px;
    cursor: pointer;
    transition: all 0.2s;
}

.icon-btn:hover {
    transform: translateY(-1px);
    border-color: rgba(99, 102, 241, 0.5);
}

.icon-btn.danger {
    border-color: rgba(239, 68, 68, 0.4);
    color: #f87171;
}

.drawer-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.35);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}

.drawer {
    position: fixed;
    top: 0;
    right: -520px;
    width: 520px;
    height: 100vh;
    background: #0b1220;
    border-left: 1px solid rgba(255, 255, 255, 0.06);
    box-shadow: -10px 0 30px rgba(0, 0, 0, 0.35);
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    transition: right 0.25s ease;
    color: #e5e7eb;
    z-index: 20;
}

.drawer.open {
    right: 0;
}

.drawer-backdrop.show {
    opacity: 1;
    pointer-events: auto;
    z-index: 10;
}

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

.drawer-body {
    display: flex;
    flex-direction: column;
    gap: 14px;
    flex: 1;
    overflow-y: auto;
    padding-right: 4px;
}

.drawer-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    padding-top: 12px;
}

.drawer-actions {
    display: flex;
    gap: 10px;
}

.form-group textarea,
.form-group input {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: #e5e7eb;
}

.form-group textarea:focus,
.form-group input:focus {
    border-color: rgba(99, 102, 241, 0.6);
}

.chips-input {
    border: 1px solid rgba(255, 255, 255, 0.08);
    padding: 8px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.02);
}

.chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 6px;
}

.chips-input input {
    width: 100%;
    background: transparent;
    border: none;
    color: #e5e7eb;
    outline: none;
    padding: 8px 4px;
}

.tool-form {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr)) 140px;
    gap: 8px;
    margin-bottom: 8px;
}

.tool-list {
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 10px;
    padding: 10px;
    background: rgba(255, 255, 255, 0.02);
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.tool-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.06);
}

.toast {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: #1f2937;
    color: #e5e7eb;
    padding: 12px 16px;
    border-radius: 10px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
    z-index: 30;
    border: 1px solid rgba(255, 255, 255, 0.06);
}

.toast.success { border-color: rgba(34, 197, 94, 0.5); }
.toast.error { border-color: rgba(239, 68, 68, 0.5); }
.toast.warning { border-color: rgba(234, 179, 8, 0.5); }

.toast.hidden {
    display: none;
}

@media (max-width: 960px) {
    .drawer {
        width: 100%;
    }

    .tool-form {
        grid-template-columns: 1fr;
    }
}
