/* ===========================
   Connector - Code Agent
   Complete Stylesheet
   =========================== */

:root {
    --bg-primary: #0f0f14;
    --bg-secondary: #1a1a24;
    --bg-tertiary: #24243a;
    --bg-hover: #2a2a42;
    --bg-input: #16161e;
    --text-primary: #e8e8f0;
    --text-secondary: #9898b0;
    --text-muted: #606078;
    --accent: #6c5ce7;
    --accent-hover: #7d6ff0;
    --accent-light: rgba(108, 92, 231, 0.15);
    --danger: #e74c3c;
    --danger-hover: #c0392b;
    --success: #2ecc71;
    --warning: #f39c12;
    --border: #2a2a3e;
    --border-light: #3a3a58;
    --radius: 8px;
    --radius-lg: 12px;
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    --transition: 0.2s ease;
    --sidebar-width: 280px;
    --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
    --font-mono: 'Cascadia Code', 'Fira Code', 'Consolas', monospace;
}

*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: var(--font);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 14px;
    line-height: 1.6;
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ===========================
   Buttons
   =========================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 16px;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    font-family: var(--font);
    font-size: 13px;
    font-weight: 500;
    transition: all var(--transition);
    text-decoration: none;
    white-space: nowrap;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--accent);
    color: #fff;
}
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }

.btn-outline {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border);
}
.btn-outline:hover:not(:disabled) {
    background: var(--bg-hover);
    color: var(--text-primary);
    border-color: var(--border-light);
}

.btn-danger {
    background: var(--danger);
    color: #fff;
}
.btn-danger:hover:not(:disabled) { background: var(--danger-hover); }

.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-block { width: 100%; }

/* ===========================
   Forms
   =========================== */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 10px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-family: var(--font);
    font-size: 14px;
    transition: border-color var(--transition);
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--accent);
}

.form-group small {
    display: block;
    margin-top: 4px;
    font-size: 11px;
    color: var(--text-muted);
}

.checkbox-label {
    display: flex !important;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}

.checkbox-label input[type="checkbox"] {
    width: auto;
}

/* ===========================
   Alerts
   =========================== */
.alert {
    padding: 10px 14px;
    border-radius: var(--radius);
    font-size: 13px;
    margin-bottom: 16px;
}

.alert-error {
    background: rgba(231, 76, 60, 0.15);
    color: #e74c3c;
    border: 1px solid rgba(231, 76, 60, 0.3);
}

.alert-success {
    background: rgba(46, 204, 113, 0.15);
    color: #2ecc71;
    border: 1px solid rgba(46, 204, 113, 0.3);
}

/* ===========================
   Badge
   =========================== */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 20px;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.badge-admin {
    background: var(--accent-light);
    color: var(--accent);
}

.badge-active {
    background: rgba(46, 204, 113, 0.15);
    color: var(--success);
}

.badge-inactive {
    background: rgba(231, 76, 60, 0.15);
    color: var(--danger);
}

/* ===========================
   Auth Pages
   =========================== */
.auth-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    overflow: auto;
    background: linear-gradient(135deg, var(--bg-primary) 0%, #1a1040 100%);
}

.auth-container {
    width: 100%;
    max-width: 420px;
    padding: 20px;
}

.auth-card {
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    padding: 32px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}

.auth-header {
    text-align: center;
    margin-bottom: 24px;
}

.auth-logo {
    font-size: 48px;
    margin-bottom: 8px;
}

.auth-header h1 {
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 4px;
}

.auth-header p {
    color: var(--text-secondary);
    font-size: 13px;
}

.auth-tabs {
    display: flex;
    gap: 0;
    margin-bottom: 20px;
    background: var(--bg-tertiary);
    border-radius: var(--radius);
    padding: 3px;
}

.auth-tab {
    flex: 1;
    padding: 8px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-family: var(--font);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    border-radius: 6px;
    transition: all var(--transition);
}

.auth-tab.active {
    background: var(--accent);
    color: #fff;
}

/* ===========================
   App Layout (Chat)
   =========================== */
.app-container {
    display: flex;
    height: 100vh;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar-header {
    padding: 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border);
}

.logo {
    font-size: 16px;
    font-weight: 700;
}

.sidebar-conversations {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.conv-item {
    padding: 10px 12px;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 13px;
    color: var(--text-secondary);
    transition: all var(--transition);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 2px;
}

.conv-item:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.conv-item.active {
    background: var(--accent-light);
    color: var(--accent);
}

.sidebar-footer {
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 8px;
}

.user-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
}

.user-name {
    font-size: 13px;
    font-weight: 500;
}

.user-actions {
    display: flex;
    gap: 6px;
}

.sidebar-toggle {
    display: none;
    position: fixed;
    top: 12px;
    left: 12px;
    z-index: 100;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    color: var(--text-primary);
    font-size: 20px;
    padding: 6px 10px;
    border-radius: var(--radius);
    cursor: pointer;
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chat-header {
    padding: 12px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 52px;
}

.chat-header h2 {
    font-size: 15px;
    font-weight: 600;
}

.chat-actions {
    display: flex;
    gap: 6px;
}

/* Chat Messages */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.welcome-message {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    text-align: center;
    padding: 40px 20px;
    color: var(--text-secondary);
}

.welcome-icon {
    font-size: 56px;
    margin-bottom: 16px;
}

.welcome-message h2 {
    font-size: 22px;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.welcome-message p {
    font-size: 14px;
    max-width: 400px;
    margin-bottom: 24px;
}

.welcome-suggestions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    max-width: 500px;
}

.suggestion-btn {
    padding: 12px 16px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-secondary);
    font-family: var(--font);
    font-size: 12px;
    cursor: pointer;
    text-align: left;
    transition: all var(--transition);
}

.suggestion-btn:hover {
    border-color: var(--accent);
    color: var(--text-primary);
    background: var(--accent-light);
}

/* Message Bubbles */
.message {
    display: flex;
    gap: 12px;
    max-width: 900px;
    width: 100%;
    margin: 0 auto;
}

.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    flex-shrink: 0;
    margin-top: 2px;
}

.message.user .message-avatar {
    background: var(--accent);
    color: #fff;
}

.message.assistant .message-avatar {
    background: var(--bg-tertiary);
    color: var(--accent);
}

.message-content {
    flex: 1;
    min-width: 0;
}

.message-role {
    font-size: 12px;
    font-weight: 600;
    margin-bottom: 4px;
    color: var(--text-secondary);
}

.message-body {
    font-size: 14px;
    line-height: 1.7;
    color: var(--text-primary);
}

.message-body p {
    margin-bottom: 12px;
}

.message-body p:last-child {
    margin-bottom: 0;
}

.message-body ul, .message-body ol {
    margin: 8px 0;
    padding-left: 24px;
}

.message-body li {
    margin-bottom: 4px;
}

.message-body strong {
    color: #fff;
}

.message-body code {
    font-family: var(--font-mono);
    font-size: 13px;
    background: var(--bg-tertiary);
    padding: 2px 6px;
    border-radius: 4px;
    color: #f0c674;
}

.message-body pre {
    margin: 12px 0;
    border-radius: var(--radius);
    overflow: hidden;
    position: relative;
}

.message-body pre code {
    display: block;
    padding: 16px;
    background: var(--bg-input);
    overflow-x: auto;
    font-size: 13px;
    line-height: 1.5;
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.code-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-bottom: none;
    border-radius: var(--radius) var(--radius) 0 0;
    font-size: 11px;
    color: var(--text-muted);
}

.code-header + code {
    border-radius: 0 0 var(--radius) var(--radius) !important;
}

.code-header-actions {
    display: flex;
    gap: 4px;
    align-items: center;
}

.copy-btn, .save-to-page-btn {
    padding: 2px 8px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 11px;
    font-family: var(--font);
    transition: all var(--transition);
    white-space: nowrap;
}

.copy-btn:hover, .save-to-page-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.save-to-page-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
}

/* Typing indicator */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 4px 0;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    background: var(--text-muted);
    border-radius: 50%;
    animation: typing 1.4s infinite;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing {
    0%, 60%, 100% { opacity: 0.3; transform: scale(0.8); }
    30% { opacity: 1; transform: scale(1); }
}

/* Chat Input */
.chat-input-container {
    padding: 16px 20px;
    border-top: 1px solid var(--border);
    background: var(--bg-primary);
}

.chat-form {
    max-width: 900px;
    margin: 0 auto;
}

.input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 8px 12px;
    transition: border-color var(--transition);
}

.input-wrapper:focus-within {
    border-color: var(--accent);
}

.input-wrapper textarea {
    flex: 1;
    border: none;
    background: transparent;
    color: var(--text-primary);
    font-family: var(--font);
    font-size: 14px;
    resize: none;
    outline: none;
    max-height: 150px;
    line-height: 1.5;
    padding: 4px 0;
}

.send-btn {
    width: 36px;
    height: 36px;
    border: none;
    background: var(--accent);
    color: #fff;
    border-radius: var(--radius);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background var(--transition);
}

.send-btn:hover:not(:disabled) { background: var(--accent-hover); }
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.input-hint {
    text-align: center;
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 8px;
}

/* ===========================
   Pages/Files Panel
   =========================== */
.pages-toggle-bar {
    margin-bottom: 8px;
}

.pages-toggle-btn {
    font-size: 12px;
}

.pages-panel {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    margin-bottom: 10px;
    overflow: hidden;
}

.pages-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-tertiary, var(--bg-hover));
}

.pages-header h3 {
    margin: 0;
    font-size: 13px;
    color: var(--text-primary);
}

.pages-count {
    color: var(--text-muted);
    font-weight: normal;
}

.pages-actions {
    display: flex;
    gap: 6px;
}

.pages-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    padding: 8px 10px;
    max-height: 80px;
    overflow-y: auto;
}

.pages-empty {
    color: var(--text-muted);
    font-size: 12px;
    padding: 4px;
}

.page-tab {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 10px;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 12px;
    transition: all var(--transition);
}

.page-tab:hover {
    border-color: var(--accent);
    background: var(--bg-hover);
}

.page-tab.active {
    border-color: var(--accent);
    background: rgba(59, 130, 246, 0.1);
}

.page-tab-name {
    color: var(--text-primary);
    font-weight: 500;
}

.page-tab-lang {
    color: var(--text-muted);
    font-size: 10px;
}

.pages-editor {
    padding: 10px 14px;
    border-top: 1px solid var(--border);
}

.page-editor-header {
    display: flex;
    gap: 8px;
    margin-bottom: 8px;
}

.page-filename-input {
    flex: 1;
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-family: var(--font-mono, monospace);
    font-size: 13px;
    outline: none;
}

.page-filename-input:focus {
    border-color: var(--accent);
}

.page-language-select {
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 12px;
    outline: none;
    min-width: 110px;
}

.page-content-textarea {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-family: var(--font-mono, 'Courier New', monospace);
    font-size: 13px;
    line-height: 1.5;
    resize: vertical;
    outline: none;
    tab-size: 4;
    box-sizing: border-box;
}

.page-content-textarea:focus {
    border-color: var(--accent);
}

.page-editor-actions {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}

/* ===========================
   Admin Layout
   =========================== */
.admin-container {
    display: flex;
    height: 100vh;
}

.admin-sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
}

.admin-nav {
    flex: 1;
    padding: 8px;
}

.admin-nav-item {
    display: block;
    padding: 10px 14px;
    border-radius: var(--radius);
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 13px;
    transition: all var(--transition);
    margin-bottom: 2px;
}

.admin-nav-item:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.admin-nav-item.active {
    background: var(--accent-light);
    color: var(--accent);
}

.admin-main {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
}

.admin-section h2 {
    font-size: 20px;
    margin-bottom: 20px;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    text-align: center;
}

.stat-value {
    font-size: 32px;
    font-weight: 700;
    color: var(--accent);
    margin-bottom: 4px;
}

.stat-label {
    font-size: 13px;
    color: var(--text-secondary);
}

/* Data Table */
.table-container {
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    overflow: hidden;
    border: 1px solid var(--border);
}

.data-table th,
.data-table td {
    padding: 10px 14px;
    text-align: left;
    font-size: 13px;
    border-bottom: 1px solid var(--border);
}

.data-table th {
    background: var(--bg-tertiary);
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.data-table tr:hover {
    background: var(--bg-hover);
}

.data-table .actions {
    display: flex;
    gap: 4px;
}

/* Modal */
.modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
}

.modal-content {
    position: relative;
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    padding: 24px;
    width: 90%;
    max-width: 480px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}

.modal-sm { max-width: 360px; }

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.modal-header h3 {
    font-size: 16px;
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 24px;
    cursor: pointer;
    padding: 0;
    line-height: 1;
}

.modal-close:hover { color: var(--text-primary); }

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 20px;
}

/* ===========================
   Setup Wizard
   =========================== */
.setup-steps {
    display: flex;
    gap: 0;
    margin-bottom: 24px;
    background: var(--bg-tertiary);
    border-radius: var(--radius);
    padding: 3px;
}

.setup-step {
    flex: 1;
    padding: 8px;
    text-align: center;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-muted);
    border-radius: 6px;
    transition: all var(--transition);
}

.setup-step.active {
    background: var(--accent);
    color: #fff;
}

.setup-step.done {
    color: var(--success);
}

.setup-step span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--bg-hover);
    font-size: 11px;
    margin-right: 4px;
}

.setup-step.active span {
    background: rgba(255,255,255,0.2);
}

.setup-step.done span {
    background: rgba(46, 204, 113, 0.2);
}

.setup-panel h3 {
    font-size: 15px;
    margin-bottom: 16px;
    color: var(--text-primary);
}

.setup-nav {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    margin-top: 8px;
}

/* ===========================
   Settings Panel (Admin)
   =========================== */
.settings-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
    gap: 20px;
    margin-bottom: 20px;
}

.settings-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 24px;
}

.settings-card h3 {
    font-size: 15px;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border);
}

.settings-actions {
    display: flex;
    align-items: center;
    gap: 16px;
}

.settings-hint {
    font-size: 12px;
    color: var(--text-muted);
}

.input-with-badge {
    position: relative;
    display: flex;
    align-items: center;
}

.input-with-badge input {
    flex: 1;
    padding-right: 110px;
}

.field-badge {
    position: absolute;
    right: 8px;
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 4px;
    white-space: nowrap;
    pointer-events: none;
}

.field-badge.badge-active {
    background: rgba(46, 204, 113, 0.12);
    color: var(--success);
}

.field-badge.badge-inactive {
    background: rgba(243, 156, 18, 0.12);
    color: var(--warning);
}

/* ===========================
   Responsive
   =========================== */
@media (max-width: 768px) {
    .sidebar, .admin-sidebar {
        position: fixed;
        left: -100%;
        top: 0;
        bottom: 0;
        z-index: 99;
        transition: left var(--transition);
    }

    .sidebar.open, .admin-sidebar.open {
        left: 0;
    }

    .sidebar-toggle {
        display: block;
    }

    .welcome-suggestions {
        grid-template-columns: 1fr;
    }

    .stats-grid {
        grid-template-columns: 1fr 1fr;
    }

    .settings-grid {
        grid-template-columns: 1fr;
    }

    .settings-actions {
        flex-direction: column;
        align-items: flex-start;
    }
}
