/* MCP Factory - Minimalist CMS UI */

:root {
    --bg-primary: #ffffff;
    --bg-secondary: #f9fafb;
    --bg-tertiary: #f3f4f6;
    --text-primary: #111827;
    --text-secondary: #6b7280;
    --text-muted: #9ca3af;
    --border-color: #e5e7eb;
    --accent: #2563eb;
    --accent-hover: #1d4ed8;
    --danger: #dc2626;
    --danger-light: #fef2f2;
    --success: #16a34a;
    --success-light: #dcfce7;
    --header-height: 56px;
    --slide-over-width: 400px;
}

/* Reset */
*, *::before, *::after {
    box-sizing: border-box;
}

body {
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg-secondary);
    color: var(--text-primary);
    line-height: 1.5;
    min-height: 100vh;
}

/* App Header */
.app-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-height);
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    z-index: 100;
}

.app-header .logo {
    font-weight: 600;
    font-size: 1.1rem;
    color: var(--text-primary);
    text-decoration: none;
}

.app-header .logo:hover {
    color: var(--accent);
}

.app-header nav {
    display: flex;
    gap: 1.5rem;
    align-items: center;
}

.app-header nav a {
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.875rem;
}

.app-header nav a:hover {
    color: var(--text-primary);
}

/* Main Content */
.main-content {
    margin-top: var(--header-height);
    padding: 2rem;
    max-width: 1000px;
    margin-left: auto;
    margin-right: auto;
}

/* Back Link */
.back-link {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.875rem;
    margin-bottom: 1rem;
}

.back-link:hover {
    color: var(--text-primary);
}

/* Section Header */
.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
}

.section-header h2 {
    font-size: 1rem;
    font-weight: 600;
    margin: 0;
    color: var(--text-primary);
}

/* Page Header */
.page-header {
    margin-bottom: 2rem;
}

.page-header h1 {
    font-size: 1.5rem;
    font-weight: 600;
    margin: 0 0 0.25rem 0;
}

.page-header p {
    color: var(--text-secondary);
    margin: 0;
    font-size: 0.9rem;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    font-weight: 500;
    border-radius: 6px;
    border: 1px solid var(--border-color);
    background: var(--bg-primary);
    color: var(--text-primary);
    cursor: pointer;
    text-decoration: none;
    transition: all 0.15s ease;
    line-height: 1.4;
}

.btn:hover {
    background: var(--bg-secondary);
    border-color: var(--text-muted);
}

.btn-primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.btn-primary:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
}

.btn-danger {
    background: var(--bg-primary);
    border-color: var(--danger);
    color: var(--danger);
}

.btn-danger:hover {
    background: var(--danger-light);
}

.btn-sm {
    padding: 0.35rem 0.75rem;
    font-size: 0.8rem;
}

.btn-ghost {
    border: none;
    background: transparent;
}

.btn-ghost:hover {
    background: var(--bg-secondary);
}

/* Card */
.card {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

/* Table - Clickable Rows */
.table-wrapper {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    overflow: hidden;
}

table {
    width: 100%;
    border-collapse: collapse;
    margin: 0;
}

th {
    text-align: left;
    padding: 0.75rem 1rem;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
}

td {
    padding: 0.75rem 1rem;
    font-size: 0.875rem;
    border-bottom: 1px solid var(--border-color);
    vertical-align: middle;
}

tr:last-child td {
    border-bottom: none;
}

.table-clickable tbody tr {
    cursor: pointer;
    transition: background 0.1s ease;
}

.table-clickable tbody tr:hover {
    background: var(--bg-secondary);
}

.table-clickable tbody tr:active {
    background: var(--bg-tertiary);
}

/* Text Utilities */
.text-muted {
    color: var(--text-muted);
}

.text-secondary {
    color: var(--text-secondary);
}

.text-danger {
    color: var(--danger);
}

.text-sm {
    font-size: 0.875rem;
}

.text-xs {
    font-size: 0.75rem;
}

/* Slide Over Panel */
.slide-over-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.3);
    z-index: 200;
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s ease;
}

.slide-over-backdrop.active {
    opacity: 1;
    visibility: visible;
}

.slide-over {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: var(--slide-over-width);
    max-width: 100%;
    background: var(--bg-primary);
    box-shadow: -4px 0 20px rgba(0, 0, 0, 0.1);
    z-index: 201;
    transform: translateX(100%);
    transition: transform 0.2s ease;
    display: flex;
    flex-direction: column;
}

.slide-over.active {
    transform: translateX(0);
}

.slide-over-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.slide-over-header h3 {
    font-size: 1rem;
    font-weight: 600;
    margin: 0;
}

.slide-over-close {
    background: none;
    border: none;
    padding: 0.5rem;
    cursor: pointer;
    color: var(--text-secondary);
    border-radius: 4px;
}

.slide-over-close:hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.slide-over-content {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
}

.slide-over-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: 0.75rem;
    justify-content: flex-end;
}

/* Forms */
label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
select,
textarea {
    width: 100%;
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: var(--bg-primary);
    color: var(--text-primary);
    transition: border-color 0.15s ease;
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

textarea {
    resize: vertical;
    min-height: 100px;
}

.form-group {
    margin-bottom: 1rem;
}

.form-hint {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

/* Code Editor */
.code-editor {
    font-family: 'SF Mono', Monaco, 'Consolas', 'Liberation Mono', monospace;
    font-size: 0.85rem;
    line-height: 1.5;
    tab-size: 2;
}

pre {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 1rem;
    overflow-x: auto;
    font-size: 0.85rem;
    margin: 0;
}

pre code {
    background: none;
    padding: 0;
}

code {
    font-family: 'SF Mono', Monaco, 'Consolas', 'Liberation Mono', monospace;
    font-size: 0.85em;
    background: var(--bg-secondary);
    padding: 0.1rem 0.3rem;
    border-radius: 3px;
}

/* Messages */
.error-message {
    background: var(--danger-light);
    color: var(--danger);
    padding: 0.75rem 1rem;
    border-radius: 6px;
    margin-bottom: 1rem;
    font-size: 0.875rem;
    border: 1px solid rgba(220, 38, 38, 0.2);
}

.success-message {
    background: var(--success-light);
    color: var(--success);
    padding: 0.75rem 1rem;
    border-radius: 6px;
    margin-bottom: 1rem;
    font-size: 0.875rem;
    border: 1px solid rgba(22, 163, 74, 0.2);
}

/* Toast Notifications */
#toast-container {
    position: fixed;
    top: calc(var(--header-height) + 1rem);
    right: 1rem;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.toast {
    padding: 0.75rem 1rem;
    border-radius: 6px;
    background: var(--bg-primary);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    animation: slideIn 0.3s ease-out;
    font-size: 0.875rem;
    border: 1px solid var(--border-color);
}

.toast-error {
    border-left: 3px solid var(--danger);
}

.toast-success {
    border-left: 3px solid var(--success);
}

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 3rem 2rem;
    color: var(--text-secondary);
}

.empty-state p {
    margin-bottom: 1rem;
}

/* Execution Result */
.execution-result {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 1rem;
    margin-top: 1rem;
}

.execution-result.success-result {
    border-left: 3px solid var(--success);
}

.execution-result.error-result {
    border-left: 3px solid var(--danger);
}

/* Badges */
.badge {
    display: inline-block;
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 500;
}

.badge-success {
    background: var(--success-light);
    color: var(--success);
}

.badge-error {
    background: var(--danger-light);
    color: var(--danger);
}

.badge-muted {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
}

/* Grid Layouts */
.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
}

.grid-auto {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1rem;
}

/* Button Group */
.button-group {
    display: flex;
    gap: 0.5rem;
}

/* Actions Cell in Table */
.actions-cell {
    text-align: right;
    white-space: nowrap;
}

/* Login Card (standalone pages) */
.login-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    background: var(--bg-secondary);
}

.login-card {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 2rem;
    width: 100%;
    max-width: 400px;
}

.login-card header {
    text-align: center;
    margin-bottom: 2rem;
}

.login-card header h1 {
    font-size: 1.5rem;
    margin: 0 0 0.5rem 0;
}

.login-card header p {
    color: var(--text-secondary);
    margin: 0;
}

.login-card footer {
    text-align: center;
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border-color);
}

.login-card footer small {
    color: var(--text-muted);
}

/* API Keys Table */
.api-keys-table td,
.api-keys-table th {
    vertical-align: middle;
}

/* Key Display */
.key-display {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: var(--bg-secondary);
    padding: 0.75rem 1rem;
    border-radius: 6px;
    margin-bottom: 1rem;
}

.key-display code {
    flex: 1;
    font-size: 0.875rem;
    word-break: break-all;
    background: transparent;
}

/* Placeholder */
.placeholder {
    color: var(--text-muted);
    font-style: italic;
}

/* Delete Link */
.delete-link {
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.875rem;
}

.delete-link:hover {
    color: var(--danger);
}

/* Pagination */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    margin-top: 1.5rem;
    padding-top: 1rem;
}

/* Overflow */
.overflow-auto {
    overflow-x: auto;
}

/* Loading States */
.htmx-loading {
    opacity: 0.6;
    pointer-events: none;
}

/* Section Spacing */
section {
    margin-bottom: 2rem;
}

/* Divider */
.divider {
    height: 1px;
    background: var(--border-color);
    margin: 2rem 0;
}

/* Inline Form */
.inline-form {
    display: inline;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .main-content {
        padding: 1rem;
    }

    .grid-2 {
        grid-template-columns: 1fr;
    }

    .slide-over {
        width: 100%;
    }

    .app-header {
        padding: 0 1rem;
    }
}

/* Form Section */
.form-section {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

.form-section h3 {
    font-size: 1rem;
    font-weight: 600;
    margin: 0 0 1rem 0;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border-color);
}

/* AI Panel */
.ai-panel {
    background: linear-gradient(135deg, #f0f7ff 0%, #f5f3ff 100%);
    border: 1px solid #e0e7ff;
    border-radius: 8px;
    margin-bottom: 1.5rem;
    overflow: hidden;
}

.ai-panel-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    background: rgba(255, 255, 255, 0.5);
    border-bottom: 1px solid #e0e7ff;
    font-weight: 500;
    font-size: 0.875rem;
    color: #4f46e5;
}

.ai-panel-icon {
    font-size: 1rem;
}

.ai-panel-content {
    padding: 1rem;
}

.ai-panel textarea {
    background: var(--bg-primary);
    border-color: #c7d2fe;
}

.ai-panel textarea:focus {
    border-color: #818cf8;
    box-shadow: 0 0 0 3px rgba(129, 140, 248, 0.1);
}

.ai-panel .btn {
    background: #6366f1;
    border-color: #6366f1;
    color: #fff;
}

.ai-panel .btn:hover {
    background: #4f46e5;
    border-color: #4f46e5;
}

.ai-panel .btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}
