/**
 * CodeBox Design System
 * Version: 1.0
 */

@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500&family=Outfit:wght@300;400;500;600&display=swap');

/* ===== Design Tokens ===== */
:root {
    /* Background Colors */
    --cb-bg: #0a0a0b;
    --cb-bg-elevated: #121214;
    --cb-bg-hover: #1a1a1d;

    /* Border Colors */
    --cb-border: #2a2a2d;
    --cb-border-hover: #3a3a3d;

    /* Text Colors */
    --cb-text: #fafafa;
    --cb-text-muted: #a0a0a0;
    --cb-text-dim: #6b6b6b;

    /* Accent Colors */
    --cb-accent: #6366f1;
    --cb-accent-hover: #818cf8;
    --cb-gradient: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);

    /* Status Colors */
    --cb-success: #22c55e;
    --cb-warning: #eab308;
    --cb-danger: #ef4444;

    /* Typography */
    --cb-font: 'Outfit', -apple-system, sans-serif;
    --cb-mono: 'JetBrains Mono', monospace;

    /* Spacing & Radius */
    --cb-radius: 10px;
    --cb-radius-sm: 6px;
}

/* ===== Reset ===== */
* { box-sizing: border-box; margin: 0; padding: 0; }

html {
    overflow-y: scroll; /* Always show scrollbar to prevent layout shift */
}

body {
    font-family: var(--cb-font);
    font-size: 14px;
    line-height: 1.5;
    background: var(--cb-bg);
    color: var(--cb-text);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

/* ===== Typography ===== */
h1 { font-size: 24px; font-weight: 600; line-height: 1.3; }
h2 { font-size: 20px; font-weight: 600; line-height: 1.3; }
h3 { font-size: 16px; font-weight: 500; line-height: 1.4; }
h4 { font-size: 14px; font-weight: 500; line-height: 1.4; }
p { line-height: 1.6; }

/* Alpine.js cloak */
[x-cloak] { display: none !important; }

/* ===== Navigation ===== */
.cb-nav {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--cb-bg);
    border-bottom: 1px solid var(--cb-border);
}

.cb-nav-inner {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 24px;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.cb-nav-left { display: 
    flex; align-items: center; gap: 32px; }

.cb-logo {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    font-size: 17px;
    color: var(--cb-text);
    text-decoration: none;
}

.cb-logo-icon { width: 24px; height: 24px; stroke: var(--cb-accent); }

.cb-nav-links { display: flex; align-items: center; gap: 4px; }
.cb-nav-admin { display: flex; align-items: center; gap: 4px; }
.cb-nav-divider { width: 1px; height: 16px; background: var(--cb-border); margin: 0 12px; }

.cb-nav-link {
    padding: 6px 12px;
    font-size: 14px;
    font-weight: 400;
    color: var(--cb-text-muted);
    text-decoration: none;
    border-radius: var(--cb-radius-sm);
    transition: all 0.15s;
}

.cb-nav-link:hover { color: var(--cb-text); background: var(--cb-bg-hover); }
.cb-nav-link-admin { font-size: 13px; }

.cb-nav-right { display: flex; align-items: center; gap: 8px; }

.cb-nav-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    font-size: 13px;
    color: var(--cb-text-muted);
    background: transparent;
    border: 1px solid var(--cb-border);
    border-radius: var(--cb-radius-sm);
    cursor: pointer;
    transition: all 0.15s;
}

.cb-nav-btn:hover { color: var(--cb-text); border-color: var(--cb-border-hover); background: var(--cb-bg-hover); }
.cb-nav-logout { padding: 6px 8px; }

.cb-nav-user {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 12px 4px 4px;
    font-size: 13px;
    font-weight: 500;
    color: var(--cb-text);
    text-decoration: none;
    background: var(--cb-bg-elevated);
    border: 1px solid var(--cb-border);
    border-radius: 20px;
    transition: all 0.15s;
}

.cb-nav-user:hover { border-color: var(--cb-border-hover); }

.cb-avatar {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 600;
    color: #fff;
    background: var(--cb-gradient);
    border-radius: 50%;
}

/* ===== Modal ===== */
.cb-modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: rgba(0, 0, 0, 0.7);
}

.cb-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 1;
}

.cb-modal {
    position: relative;
    z-index: 2;
    width: 100%;
    max-width: 480px;
    background: var(--cb-bg-elevated);
    border: 1px solid var(--cb-border);
    border-radius: var(--cb-radius);
    overflow: hidden;
}

.cb-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--cb-border);
}

.cb-modal-header h3 { font-size: 16px; font-weight: 600; }

.cb-modal-close {
    padding: 4px;
    color: var(--cb-text-muted);
    background: transparent;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.15s;
}

.cb-modal-close:hover { color: var(--cb-text); background: var(--cb-bg-hover); }

.cb-modal-body { padding: 20px; }

/* ===== Code Block ===== */
.cb-code-block {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    background: var(--cb-bg);
    border: 1px solid var(--cb-border);
    border-radius: var(--cb-radius-sm);
    font-family: var(--cb-mono);
    font-size: 12px;
    color: var(--cb-success);
    overflow-x: auto;
}

.cb-code-block code { flex: 1; white-space: nowrap; }

.cb-code-copy {
    flex-shrink: 0;
    padding: 4px;
    color: var(--cb-text-muted);
    background: transparent;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.15s;
}

.cb-code-copy:hover { color: var(--cb-text); }

/* ===== Download Grid ===== */
.cb-download-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}

.cb-download-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 10px;
    font-size: 13px;
    color: var(--cb-text-muted);
    text-decoration: none;
    background: var(--cb-bg);
    border: 1px solid var(--cb-border);
    border-radius: var(--cb-radius-sm);
    transition: all 0.15s;
}

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

/* ===== Card ===== */
.cb-card {
    background: var(--cb-bg-elevated);
    border: 1px solid var(--cb-border);
    border-radius: var(--cb-radius);
}

/* ===== Form Elements ===== */
.cb-label {
    display: block;
    margin-bottom: 6px;
    font-size: 13px;
    font-weight: 500;
    color: var(--cb-text-muted);
}

.cb-input {
    width: 100%;
    padding: 10px 14px;
    font-size: 14px;
    font-family: var(--cb-font);
    color: var(--cb-text);
    background: var(--cb-bg);
    border: 1px solid var(--cb-border);
    border-radius: var(--cb-radius-sm);
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.cb-input:focus {
    border-color: var(--cb-accent);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

.cb-input::placeholder {
    color: var(--cb-text-dim);
}

/* ===== Buttons ===== */
.cb-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 16px;
    font-size: 14px;
    font-weight: 500;
    font-family: var(--cb-font);
    color: var(--cb-text);
    background: var(--cb-bg-elevated);
    border: 1px solid var(--cb-border);
    border-radius: var(--cb-radius-sm);
    cursor: pointer;
    transition: all 0.15s;
    text-decoration: none;
}

.cb-btn:hover {
    background: var(--cb-bg-hover);
    border-color: var(--cb-border-hover);
}

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

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

.cb-btn-primary:hover {
    opacity: 0.9;
    background: var(--cb-gradient);
}

.cb-btn-danger {
    color: #fff;
    background: var(--cb-danger);
    border: none;
}

.cb-btn-danger:hover {
    opacity: 0.9;
}

.cb-btn-sm {
    padding: 6px 12px;
    font-size: 13px;
}

/* ===== Container ===== */
.cb-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 24px;
}

/* ===== Select ===== */
.cb-select {
    width: 100%;
    padding: 10px 36px 10px 14px;
    font-size: 14px;
    font-family: var(--cb-font);
    color: var(--cb-text);
    background: var(--cb-bg);
    border: 1px solid var(--cb-border);
    border-radius: var(--cb-radius-sm);
    outline: none;
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%23888'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 16px;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.cb-select:focus {
    border-color: var(--cb-accent);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

.cb-select option {
    background: var(--cb-bg-elevated);
    color: var(--cb-text);
}

/* ===== Checkbox ===== */
.cb-checkbox {
    width: 16px;
    height: 16px;
    accent-color: var(--cb-accent);
    cursor: pointer;
}

/* ===== Badge ===== */
.cb-badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    font-size: 11px;
    font-weight: 500;
    color: var(--cb-text-muted);
    background: var(--cb-bg);
    border-radius: 999px;
}

.cb-badge-success {
    color: #22c55e;
    background: rgba(34, 197, 94, 0.15);
}

.cb-badge-accent {
    color: var(--cb-accent);
    background: rgba(99, 102, 241, 0.15);
}

.cb-badge-warning {
    color: #eab308;
    background: rgba(234, 179, 8, 0.15);
}

.cb-badge-danger {
    color: #ef4444;
    background: rgba(239, 68, 68, 0.15);
}

/* ===== List Item ===== */
.cb-list-item {
    transition: background 0.15s;
}

.cb-list-item:hover {
    background: var(--cb-bg-hover);
}

.cb-list-item:last-child {
    border-bottom: none !important;
}

/* ===== Utility Classes ===== */
.cb-text-muted { color: var(--cb-text-muted); }
.cb-text-accent { color: var(--cb-accent); }
.cb-text-success { color: var(--cb-success); }
.cb-text-warning { color: var(--cb-warning); }
.cb-text-danger { color: var(--cb-danger); }

.mb-1 { margin-bottom: 4px; }
.mb-2 { margin-bottom: 8px; }
.mb-3 { margin-bottom: 12px; }
.mb-4 { margin-bottom: 16px; }
.mb-6 { margin-bottom: 24px; }

.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 16px; }

.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }

/* ===== Progress Bar (HTMX) ===== */
#htmx-progress {
    position: fixed;
    top: 0;
    left: 0;
    height: 2px;
    background: linear-gradient(90deg, #6366f1, #8b5cf6);
    width: 0;
    transition: width 0.3s;
    z-index: 9999;
}

/* ===== Animations ===== */
@keyframes spin {
    to { transform: rotate(360deg); }
}

.animate-spin {
    animation: spin 1s linear infinite;
}

/* ===== Toast Notifications ===== */
.cb-toast-error {
    position: fixed;
    top: 5rem;
    left: 50%;
    transform: translateX(-50%);
    max-width: 32rem;
    padding: 0.75rem 1rem;
    background: rgba(239, 68, 68, 0.95);
    border-radius: 8px;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    z-index: 1000;
    animation: toastSlideDown 0.2s ease-out;
}

.cb-toast-success {
    position: fixed;
    top: 5rem;
    left: 50%;
    transform: translateX(-50%);
    max-width: 32rem;
    padding: 0.75rem 1rem;
    background: rgba(34, 197, 94, 0.95);
    border-radius: 8px;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    z-index: 1000;
    animation: toastSlideDown 0.2s ease-out;
}

.cb-toast-icon {
    width: 1.25rem;
    height: 1.25rem;
    color: white;
    flex-shrink: 0;
}

.cb-toast-text {
    font-size: 0.875rem;
    color: white;
    flex: 1;
}

.cb-toast-close {
    color: white;
    opacity: 0.7;
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    line-height: 1;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.cb-toast-close:hover {
    opacity: 1;
    background: rgba(255, 255, 255, 0.1);
}

.cb-toast-close svg {
    width: 1rem;
    height: 1rem;
}

@keyframes toastSlideDown {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}
