/* ========================================
   JSON Mock API Builder — Premium Dark Theme
   Electric Violet Palette
   ======================================== */

/* --- Design Tokens --- */
:root {
    --primary: #8B5CF6;
    --primary-hover: #7C3AED;
    --primary-glow: rgba(139, 92, 246, 0.3);
    --secondary: #A78BFA;
    --accent: #34D399;
    --accent-hover: #2DD4A0;
    --danger: #F87171;
    --danger-hover: #EF4444;

    --bg-base: #0F0A1E;
    --bg-surface: #1A1333;
    --bg-elevated: #231B42;
    --bg-input: #1E1639;
    --bg-hover: #2A2050;

    --text-primary: #F1F0F5;
    --text-secondary: #A09BB5;
    --text-muted: #6B6580;

    --border: rgba(139, 92, 246, 0.15);
    --border-active: rgba(139, 92, 246, 0.4);

    --radius: 12px;
    --radius-sm: 8px;
    --radius-xs: 6px;

    --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', monospace;

    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
    --shadow-glow: 0 0 20px var(--primary-glow);

    --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);

    --glass-bg: rgba(26, 19, 51, 0.7);
    --glass-border: rgba(139, 92, 246, 0.12);
    --glass-blur: blur(16px);
}

/* --- Reset & Base --- */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-sans);
    background: var(--bg-base);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    overflow-x: hidden;
    background-image:
        radial-gradient(ellipse at 20% 0%, rgba(139, 92, 246, 0.08) 0%, transparent 60%),
        radial-gradient(ellipse at 80% 100%, rgba(52, 211, 153, 0.05) 0%, transparent 60%);
}

/* --- Scrollbar --- */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--text-muted);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--secondary);
}

/* --- Header --- */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1.5rem;
    background: var(--glass-bg);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border-bottom: 1px solid var(--glass-border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.logo h1 {
    font-size: 1.15rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.header-actions {
    display: flex;
    gap: 0.5rem;
}

/* --- Buttons --- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 1rem;
    border: none;
    border-radius: var(--radius-sm);
    font-family: var(--font-sans);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--primary-hover));
    color: white;
    box-shadow: 0 2px 8px rgba(139, 92, 246, 0.3);
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 16px rgba(139, 92, 246, 0.4);
}

.btn-secondary {
    background: var(--bg-elevated);
    color: var(--text-primary);
    border: 1px solid var(--border);
}

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

.btn-accent {
    background: linear-gradient(135deg, var(--accent), #10B981);
    color: #0F0A1E;
    font-weight: 700;
}

.btn-accent:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 16px rgba(52, 211, 153, 0.3);
}

.btn-danger {
    background: transparent;
    color: var(--danger);
    border: 1px solid rgba(248, 113, 113, 0.3);
}

.btn-danger:hover {
    background: rgba(248, 113, 113, 0.1);
    border-color: var(--danger);
}

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

.btn-full {
    width: 100%;
    justify-content: center;
}

.btn-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: none;
    border-radius: var(--radius-xs);
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition);
}

.btn-icon:hover {
    background: var(--bg-hover);
    color: var(--primary);
}

/* --- Main Layout --- */
.app-main {
    display: grid;
    grid-template-columns: 240px 1fr 320px;
    height: calc(100vh - 53px);
    overflow: hidden;
}

/* --- Sidebar --- */
.sidebar {
    background: var(--bg-surface);
    border-right: 1px solid var(--border);
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    overflow-y: auto;
}

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

.sidebar-header h2 {
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
}

.collection-list {
    list-style: none;
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.collection-group {
    margin-bottom: 0.5rem;
}

.collection-name {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0.5rem;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: var(--radius-xs);
    transition: all var(--transition);
    border: none;
    background: none;
    width: 100%;
    text-align: left;
}

.collection-name:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.collection-name .arrow {
    transition: transform var(--transition);
    font-size: 0.65rem;
    color: var(--text-muted);
}

.collection-name.open .arrow {
    transform: rotate(90deg);
}

.endpoint-list {
    list-style: none;
    padding-left: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.endpoint-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0.5rem;
    border-radius: var(--radius-xs);
    cursor: pointer;
    transition: all var(--transition);
    font-size: 0.82rem;
    border: none;
    background: none;
    color: var(--text-primary);
    width: 100%;
    text-align: left;
}

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

.endpoint-item.active {
    background: var(--primary-glow);
    border-left: 2px solid var(--primary);
}

.method-badge {
    font-size: 0.65rem;
    font-weight: 700;
    font-family: var(--font-mono);
    padding: 0.15rem 0.35rem;
    border-radius: 4px;
    min-width: 38px;
    text-align: center;
    text-transform: uppercase;
}

.method-GET {
    background: rgba(52, 211, 153, 0.15);
    color: #34D399;
}

.method-POST {
    background: rgba(139, 92, 246, 0.15);
    color: #A78BFA;
}

.method-PUT {
    background: rgba(251, 191, 36, 0.15);
    color: #FBBF24;
}

.method-PATCH {
    background: rgba(96, 165, 250, 0.15);
    color: #60A5FA;
}

.method-DELETE {
    background: rgba(248, 113, 113, 0.15);
    color: #F87171;
}

.method-OPTIONS {
    background: rgba(167, 139, 250, 0.1);
    color: #A78BFA;
}

.method-HEAD {
    background: rgba(209, 213, 219, 0.1);
    color: #D1D5DB;
}

.endpoint-path {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text-secondary);
    font-family: var(--font-mono);
    font-size: 0.78rem;
}

/* --- Editor Panel --- */
.editor-panel {
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    padding: 1.5rem;
}

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    gap: 1rem;
    text-align: center;
}

.empty-icon {
    opacity: 0.5;
}

.empty-state h3 {
    font-size: 1.2rem;
    color: var(--text-secondary);
}

.empty-state p {
    color: var(--text-muted);
    font-size: 0.9rem;
}

.endpoint-editor {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.hidden {
    display: none !important;
}

/* Method + Path row */
.method-path-row {
    display: flex;
    gap: 0.5rem;
    align-items: stretch;
}

.method-select {
    font-family: var(--font-mono);
    font-weight: 700;
    font-size: 0.85rem;
    padding: 0.6rem 0.75rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--bg-input);
    color: var(--accent);
    cursor: pointer;
    appearance: none;
    min-width: 100px;
    transition: border-color var(--transition);
}

.method-select:focus {
    border-color: var(--primary);
    outline: none;
}

.path-input {
    flex: 1;
    font-family: var(--font-mono);
    font-size: 0.95rem;
    padding: 0.6rem 1rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--bg-input);
    color: var(--text-primary);
    transition: border-color var(--transition);
}

.path-input:focus {
    border-color: var(--primary);
    outline: none;
    box-shadow: var(--shadow-glow);
}

/* Tabs */
.editor-tabs {
    display: flex;
    gap: 0;
    border-bottom: 1px solid var(--border);
}

.tab {
    padding: 0.6rem 1rem;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-muted);
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    transition: all var(--transition);
}

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

.tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

/* Tab Panels */
.tab-panel {
    display: none;
    padding: 1rem 0;
    flex: 1;
    flex-direction: column;
    gap: 0.75rem;
}

.tab-panel.active {
    display: flex;
}

.panel-toolbar {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.panel-toolbar label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.status-select {
    font-family: var(--font-mono);
    font-size: 0.82rem;
    padding: 0.35rem 0.6rem;
    border-radius: var(--radius-xs);
    border: 1px solid var(--border);
    background: var(--bg-input);
    color: var(--text-primary);
    cursor: pointer;
}

.status-select:focus {
    border-color: var(--primary);
    outline: none;
}

.code-editor {
    flex: 1;
    min-height: 200px;
    font-family: var(--font-mono);
    font-size: 0.85rem;
    line-height: 1.6;
    padding: 1rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--bg-input);
    color: var(--accent);
    resize: vertical;
    transition: border-color var(--transition);
}

.code-editor:focus {
    border-color: var(--primary);
    outline: none;
    box-shadow: var(--shadow-glow);
}

.code-editor::placeholder {
    color: var(--text-muted);
}

/* Headers */
.header-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.header-row {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.header-row input {
    flex: 1;
    font-family: var(--font-mono);
    font-size: 0.82rem;
    padding: 0.4rem 0.6rem;
    border-radius: var(--radius-xs);
    border: 1px solid var(--border);
    background: var(--bg-input);
    color: var(--text-primary);
    transition: border-color var(--transition);
}

.header-row input:focus {
    border-color: var(--primary);
    outline: none;
}

.btn-remove-header {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1.1rem;
    padding: 0.25rem;
    border-radius: 4px;
    transition: all var(--transition);
}

.btn-remove-header:hover {
    color: var(--danger);
    background: rgba(248, 113, 113, 0.1);
}

/* Settings */
.settings-grid {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.setting-group label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 0.35rem;
}

.setting-input {
    width: 100%;
    font-family: var(--font-sans);
    font-size: 0.85rem;
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--bg-input);
    color: var(--text-primary);
    transition: border-color var(--transition);
}

.setting-input:focus {
    border-color: var(--primary);
    outline: none;
}

select.setting-input {
    cursor: pointer;
}

/* Variables */
.variables-info h4 {
    margin-bottom: 0.25rem;
    color: var(--text-primary);
}

.variables-info p {
    color: var(--text-secondary);
    font-size: 0.85rem;
    margin-bottom: 1rem;
}

.variable-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.chip {
    font-family: var(--font-mono);
    font-size: 0.78rem;
    padding: 0.35rem 0.65rem;
    border-radius: 20px;
    border: 1px solid var(--border);
    background: var(--bg-elevated);
    color: var(--secondary);
    cursor: pointer;
    transition: all var(--transition);
}

.chip:hover {
    border-color: var(--primary);
    background: var(--primary-glow);
    color: var(--primary);
    transform: translateY(-1px);
}

/* Editor Actions */
.editor-actions {
    display: flex;
    justify-content: space-between;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
}

/* --- Preview Panel --- */
.preview-panel {
    background: var(--bg-surface);
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

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

.preview-header h2 {
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
}

.badge {
    font-size: 0.72rem;
    font-weight: 600;
    padding: 0.2rem 0.6rem;
    border-radius: 20px;
    background: var(--primary-glow);
    color: var(--primary);
}

.preview-code {
    flex: 1;
    overflow: auto;
    padding: 1rem;
    margin: 0;
    font-family: var(--font-mono);
    font-size: 0.78rem;
    line-height: 1.7;
    color: var(--accent);
    background: transparent;
}

.preview-code code {
    white-space: pre-wrap;
    word-break: break-word;
}

/* --- Modals --- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: fadeIn 0.2s ease;
}

.modal {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    width: min(90vw, 640px);
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
    animation: slideUp 0.3s ease;
}

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

.modal-header h2 {
    font-size: 1.1rem;
    font-weight: 700;
}

.btn-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.25rem;
    transition: color var(--transition);
}

.btn-close:hover {
    color: var(--text-primary);
}

.modal-body {
    padding: 1.5rem;
    overflow-y: auto;
    flex: 1;
}

.modal-actions {
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border);
}

/* Export tabs */
.export-tabs {
    display: flex;
    gap: 0.25rem;
    margin-bottom: 1rem;
    background: var(--bg-elevated);
    border-radius: var(--radius-sm);
    padding: 0.25rem;
}

.export-tab {
    flex: 1;
    padding: 0.5rem;
    font-size: 0.82rem;
    font-weight: 600;
    border: none;
    border-radius: var(--radius-xs);
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    transition: all var(--transition);
}

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

.export-tab.active {
    background: var(--primary);
    color: white;
}

.export-code {
    background: var(--bg-input);
    border-radius: var(--radius-sm);
    padding: 1rem;
    overflow: auto;
    max-height: 300px;
    font-family: var(--font-mono);
    font-size: 0.8rem;
    line-height: 1.6;
    color: var(--accent);
    margin: 0;
}

.import-instructions {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-bottom: 1rem;
}

/* --- Toast --- */
.toast-container {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.toast {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    font-weight: 500;
    box-shadow: var(--shadow-md);
    animation: slideIn 0.3s ease, fadeOut 0.3s ease 2.5s forwards;
}

.toast-success {
    background: rgba(52, 211, 153, 0.15);
    color: var(--accent);
    border: 1px solid rgba(52, 211, 153, 0.3);
}

.toast-error {
    background: rgba(248, 113, 113, 0.15);
    color: var(--danger);
    border: 1px solid rgba(248, 113, 113, 0.3);
}

.toast-info {
    background: rgba(139, 92, 246, 0.15);
    color: var(--secondary);
    border: 1px solid rgba(139, 92, 246, 0.3);
}

/* --- Animations --- */
@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(16px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(40px);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes fadeOut {
    from {
        opacity: 1;
    }

    to {
        opacity: 0;
        pointer-events: none;
    }
}

/* --- Responsive --- */
@media (max-width: 1024px) {
    .app-main {
        grid-template-columns: 200px 1fr 260px;
    }
}

@media (max-width: 768px) {
    .app-main {
        grid-template-columns: 1fr;
        grid-template-rows: auto 1fr auto;
        height: auto;
        min-height: calc(100vh - 53px);
    }

    .sidebar {
        border-right: none;
        border-bottom: 1px solid var(--border);
        max-height: 200px;
    }

    .preview-panel {
        border-left: none;
        border-top: 1px solid var(--border);
        max-height: 250px;
    }

    .app-header {
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .header-actions {
        width: 100%;
        justify-content: flex-end;
    }
}

@media (max-width: 480px) {
    .method-path-row {
        flex-direction: column;
    }

    .method-select {
        min-width: unset;
    }

    .editor-tabs {
        flex-wrap: wrap;
    }

    .modal {
        width: 95vw;
        max-height: 90vh;
    }
}