/* ===== CSS Variables ===== */
:root {
    /* Dark Theme (Default) */
    --bg-primary: #0f0f14;
    --bg-secondary: #16161d;
    --bg-tertiary: #1e1e28;
    --bg-card: rgba(30, 30, 40, 0.8);
    --bg-hover: rgba(255, 255, 255, 0.05);

    --text-primary: #ffffff;
    --text-secondary: #a0a0b0;
    --text-muted: #666680;

    --accent-orange: #ff6b35;
    --accent-purple: #a855f7;
    --accent-blue: #3b82f6;
    --accent-green: #22c55e;
    --accent-red: #ef4444;

    --gradient-primary: linear-gradient(135deg, #ff6b35 0%, #a855f7 100%);
    --gradient-hover: linear-gradient(135deg, #ff8555 0%, #b875f7 100%);

    --border-color: rgba(255, 255, 255, 0.1);
    --border-radius: 12px;
    --border-radius-sm: 8px;

    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.4);

    --transition-fast: 0.15s ease;
    --transition-normal: 0.25s ease;

    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* Light Theme */
[data-theme="light"] {
    --bg-primary: #f5f5f7;
    --bg-secondary: #ffffff;
    --bg-tertiary: #f0f0f2;
    --bg-card: rgba(255, 255, 255, 0.9);
    --bg-hover: rgba(0, 0, 0, 0.05);

    --text-primary: #1a1a2e;
    --text-secondary: #4a4a5a;
    --text-muted: #8a8a9a;

    --accent-orange: #e85d2b;
    --accent-purple: #9333ea;
    --accent-blue: #2563eb;
    --accent-green: #16a34a;
    --accent-red: #dc2626;

    --gradient-primary: linear-gradient(135deg, #ff6b35 0%, #a855f7 100%);
    --gradient-hover: linear-gradient(135deg, #ff8555 0%, #b875f7 100%);

    --border-color: rgba(0, 0, 0, 0.1);

    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.08);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.12);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.16);
}

/* Theme Toggle Button */
.theme-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    border-radius: var(--border-radius-sm);
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    cursor: pointer;
    font-size: 20px;
    transition: all var(--transition-fast);
}

.theme-toggle:hover {
    background: var(--bg-hover);
    transform: scale(1.05);
}

/* ===== Reset & Base ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-family);
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
}

/* ===== App Layout ===== */
.app {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* ===== Header ===== */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 24px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: blur(10px);
}

.logo {
    font-size: 1.5rem;
    font-weight: 700;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.header-right {
    display: flex;
    gap: 12px;
}

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    border: none;
    border-radius: var(--border-radius-sm);
    font-family: inherit;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.btn-primary {
    background: var(--gradient-primary);
    color: white;
}

.btn-primary:hover {
    background: var(--gradient-hover);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: var(--bg-hover);
    border-color: rgba(255, 255, 255, 0.2);
}

.btn-danger {
    background: var(--accent-red);
    color: white;
}

.btn-danger:hover {
    background: #dc2626;
}

.btn-sm {
    padding: 8px 16px;
    font-size: 13px;
}

.btn-icon {
    padding: 8px;
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}

.btn-icon:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.btn-close {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 24px;
    cursor: pointer;
    padding: 4px 8px;
    line-height: 1;
}

.btn-close:hover {
    color: var(--text-primary);
}

.icon {
    font-size: 16px;
}

/* ===== Main Content ===== */
.main-content {
    display: flex;
    flex: 1;
}

/* ===== Sidebar ===== */
.sidebar {
    width: 240px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    padding: 20px 0;
}

.nav-list {
    list-style: none;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 24px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition-fast);
    border-left: 3px solid transparent;
}

.nav-item:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.nav-item.active {
    background: rgba(168, 85, 247, 0.1);
    color: var(--accent-purple);
    border-left-color: var(--accent-purple);
}

.nav-icon {
    font-size: 20px;
}

.nav-text {
    font-weight: 500;
}

/* ===== Content Area ===== */
.content {
    flex: 1;
    padding: 24px;
    overflow-y: auto;
}

.section {
    animation: fadeIn 0.3s ease;
}

.section.hidden {
    display: none;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}

.section-header h2 {
    font-size: 1.5rem;
    font-weight: 600;
}

/* ===== Cards ===== */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 24px;
    backdrop-filter: blur(10px);
}

.provider-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    margin-bottom: 16px;
    overflow: hidden;
    transition: all var(--transition-normal);
}

.provider-card:hover {
    border-color: rgba(255, 255, 255, 0.2);
    box-shadow: var(--shadow-md);
}

.provider-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    background: rgba(255, 255, 255, 0.02);
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
}

.provider-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.provider-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: var(--gradient-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
}

.provider-name {
    font-weight: 600;
    font-size: 1.1rem;
}

.provider-url {
    font-size: 13px;
    color: var(--text-muted);
}

.provider-actions {
    display: flex;
    gap: 8px;
}

.provider-body {
    padding: 20px;
}

.provider-body.collapsed {
    display: none;
}

/* ===== Model List ===== */
.model-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.model-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: var(--bg-tertiary);
    border-radius: var(--border-radius-sm);
    border: 1px solid var(--border-color);
}

.model-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.model-id {
    font-weight: 500;
    font-family: 'Monaco', 'Consolas', monospace;
    font-size: 14px;
}

.model-meta {
    display: flex;
    gap: 12px;
    font-size: 12px;
    color: var(--text-muted);
}

.model-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    background: rgba(168, 85, 247, 0.2);
    color: var(--accent-purple);
    border-radius: 4px;
    font-size: 11px;
}

.model-actions {
    display: flex;
    gap: 8px;
}

.add-model-btn {
    width: 100%;
    margin-top: 16px;
    padding: 12px;
    background: var(--bg-tertiary);
    border: 2px dashed var(--border-color);
    border-radius: var(--border-radius-sm);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.add-model-btn:hover {
    border-color: var(--accent-purple);
    color: var(--accent-purple);
    background: rgba(168, 85, 247, 0.1);
}

/* ===== Form Elements ===== */
.form-group {
    margin-bottom: 20px;
}

.form-group:last-child {
    margin-bottom: 0;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    color: var(--text-secondary);
}

.input,
.select {
    width: 100%;
    padding: 12px 16px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 14px;
    transition: all var(--transition-fast);
}

.input:focus,
.select:focus {
    outline: none;
    border-color: var(--accent-purple);
    box-shadow: 0 0 0 3px rgba(168, 85, 247, 0.2);
}

.input::placeholder {
    color: var(--text-muted);
}

.input-group {
    display: flex;
    gap: 8px;
}

.input-group .input {
    flex: 1;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
}

.checkbox-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--accent-purple);
}

/* ===== Fallback Models ===== */
.fallback-models {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 12px;
}

.fallback-item {
    display: flex;
    align-items: center;
    gap: 8px;
}

.fallback-item .select {
    flex: 1;
}

.fallback-item .btn-icon {
    flex-shrink: 0;
}

/* ===== Channels ===== */
.channel-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 20px;
    margin-bottom: 16px;
}

.channel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.channel-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.channel-icon {
    font-size: 28px;
}

.channel-name {
    font-weight: 600;
    font-size: 1.1rem;
}

.channel-status {
    font-size: 12px;
    padding: 4px 12px;
    border-radius: 20px;
}

.channel-status.enabled {
    background: rgba(34, 197, 94, 0.2);
    color: var(--accent-green);
}

.channel-status.disabled {
    background: rgba(239, 68, 68, 0.2);
    color: var(--accent-red);
}

/* ===== Code Editor ===== */
.code-editor {
    width: 100%;
    min-height: 500px;
    padding: 16px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    color: var(--text-primary);
    font-family: 'Monaco', 'Consolas', 'Courier New', monospace;
    font-size: 13px;
    line-height: 1.6;
    resize: vertical;
}

.code-editor:focus {
    outline: none;
    border-color: var(--accent-purple);
}

/* ===== Modal ===== */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(4px);
    animation: fadeIn 0.2s ease;
}

.modal-overlay.hidden {
    display: none;
}

.modal {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h3 {
    font-size: 1.25rem;
    font-weight: 600;
}

.modal-body {
    padding: 24px;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    padding: 20px 24px;
    border-top: 1px solid var(--border-color);
}

/* ===== Toast ===== */
.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 24px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    box-shadow: var(--shadow-lg);
    animation: slideIn 0.3s ease;
    z-index: 2000;
}

.toast.hidden {
    display: none;
}

.toast.success {
    border-left: 4px solid var(--accent-green);
}

.toast.error {
    border-left: 4px solid var(--accent-red);
}

.toast.warning {
    border-left: 4px solid var(--accent-orange);
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(20px);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* ===== Empty State ===== */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}

.empty-state-icon {
    font-size: 48px;
    margin-bottom: 16px;
}

.empty-state-text {
    font-size: 16px;
    margin-bottom: 20px;
}

/* ===== Section Actions ===== */
.section-actions {
    display: flex;
    gap: 8px;
}

/* ===== Cache Status ===== */
.cache-status {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 16px;
    padding: 8px 12px;
    background: var(--bg-tertiary);
    border-radius: var(--border-radius-sm);
    font-size: 13px;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent-orange);
}

.cache-status.saved .status-dot {
    background: var(--accent-green);
}

.cache-status.modified .status-dot {
    background: var(--accent-orange);
    animation: pulse 1.5s infinite;
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.5;
    }
}

/* ===== Commands Section ===== */
.commands-list {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-top: 20px;
}

.command-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    overflow: hidden;
}

.command-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: rgba(255, 255, 255, 0.02);
    border-bottom: 1px solid var(--border-color);
}

.command-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
}

.command-title .icon {
    font-size: 18px;
}

.command-body {
    padding: 16px;
}

.command-code {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    padding: 12px 16px;
    font-family: 'Monaco', 'Consolas', monospace;
    font-size: 13px;
    line-height: 1.5;
    overflow-x: auto;
    white-space: pre-wrap;
    word-break: break-all;
    color: var(--accent-green);
    position: relative;
}

.command-code::before {
    content: '$ ';
    color: var(--text-muted);
}

.command-description {
    margin-top: 12px;
    font-size: 13px;
    color: var(--text-muted);
}

.copy-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    color: var(--text-secondary);
    font-size: 12px;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.copy-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.copy-btn.copied {
    background: rgba(34, 197, 94, 0.2);
    color: var(--accent-green);
    border-color: var(--accent-green);
}

/* ===== Server Connection ===== */
.server-info-banner {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px;
    background: rgba(168, 85, 247, 0.1);
    border: 1px solid rgba(168, 85, 247, 0.3);
    border-radius: var(--border-radius-sm);
    margin-bottom: 20px;
    color: var(--accent-purple);
}

.server-info-banner .icon {
    font-size: 24px;
}

.server-commands {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-top: 20px;
}

/* ===== Instructions Card ===== */
.instructions-card {
    margin-top: 32px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    overflow: hidden;
}

.instructions-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 20px;
    background: rgba(168, 85, 247, 0.1);
    border-bottom: 1px solid var(--border-color);
}

.instructions-header .icon {
    font-size: 24px;
}

.instructions-header h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    color: var(--accent-purple);
}

.instructions-content {
    padding: 20px;
}

.instruction-section {
    margin-bottom: 24px;
}

.instruction-section:last-child {
    margin-bottom: 0;
}

.instruction-section h4 {
    margin: 0 0 12px 0;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
}

.instruction-section ol,
.instruction-section ul {
    margin: 0;
    padding-left: 20px;
    color: var(--text-secondary);
}

.instruction-section li {
    margin-bottom: 8px;
    line-height: 1.6;
}

.instruction-section li:last-child {
    margin-bottom: 0;
}

.instruction-section code {
    background: var(--bg-tertiary);
    padding: 2px 8px;
    border-radius: 4px;
    font-family: 'Monaco', 'Consolas', monospace;
    font-size: 13px;
    color: var(--accent-cyan);
}

.instruction-section strong {
    color: var(--text-primary);
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .header {
        flex-direction: column;
        gap: 16px;
        padding: 16px;
    }

    .main-content {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
        padding: 10px 0;
    }

    .nav-list {
        display: flex;
        overflow-x: auto;
        padding: 0 16px;
    }

    .nav-item {
        padding: 12px 16px;
        border-left: none;
        border-bottom: 3px solid transparent;
        white-space: nowrap;
    }

    .nav-item.active {
        border-left-color: transparent;
        border-bottom-color: var(--accent-purple);
    }

    .content {
        padding: 16px;
    }

    .modal {
        margin: 16px;
        max-height: calc(100vh - 32px);
    }
}