/* ========================================
   HTTP Request Builder — Emerald Night Theme
   ======================================== */

/* --- Design Tokens --- */
:root {
    --primary: #10B981;
    --primary-hover: #059669;
    --secondary: #34D399;
    --accent: #F59E0B;
    --accent-hover: #D97706;
    --bg: #0A1628;
    --bg-surface: #111D32;
    --bg-elevated: #162240;
    --bg-input: #0D1B2E;
    --border: #1E3A5F;
    --border-focus: #10B981;
    --text: #E2E8F0;
    --text-muted: #64748B;
    --text-dim: #475569;
    --radius: 12px;
    --radius-sm: 8px;
    --radius-xs: 6px;
    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --mono: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.4);
    --glass: rgba(17, 29, 50, 0.7);
    --glass-border: rgba(30, 58, 95, 0.5);
    --transition: 0.2s ease;

    /* Status colors */
    --status-2xx: #10B981;
    --status-3xx: #3B82F6;
    --status-4xx: #F59E0B;
    --status-5xx: #EF4444;
    --method-get: #10B981;
    --method-post: #3B82F6;
    --method-put: #F59E0B;
    --method-delete: #EF4444;
    --method-patch: #8B5CF6;
}

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

html {
    font-size: 15px;
    -webkit-font-smoothing: antialiased;
}

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
}

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

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
}

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

.header-actions {
    display: flex;
    gap: 8px;
}

.header-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-muted);
    padding: 7px 14px;
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: 0.85rem;
    cursor: pointer;
    transition: all var(--transition);
}

.header-btn:hover {
    background: var(--bg-elevated);
    color: var(--text);
    border-color: var(--primary);
}

.btn-label {
    display: inline;
}

/* --- Main Layout --- */
.app-main {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0;
    flex: 1;
    min-height: 0;
}

/* --- Request Panel --- */
.request-panel {
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border);
    overflow: hidden;
}

/* URL Bar */
.url-bar {
    display: flex;
    gap: 0;
    padding: 16px 20px;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
}

.method-select {
    background: var(--bg-elevated);
    color: var(--method-get);
    border: 1px solid var(--border);
    border-right: none;
    border-radius: var(--radius-sm) 0 0 var(--radius-sm);
    padding: 10px 12px;
    font-family: var(--mono);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    min-width: 100px;
    text-align: center;
    outline: none;
    transition: color var(--transition);
}

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

.url-input {
    flex: 1;
    background: var(--bg-input);
    color: var(--text);
    border: 1px solid var(--border);
    border-left: none;
    border-right: none;
    padding: 10px 14px;
    font-family: var(--mono);
    font-size: 0.9rem;
    outline: none;
    transition: border-color var(--transition);
}

.url-input:focus {
    border-color: var(--border-focus);
}

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

.btn-send {
    display: flex;
    align-items: center;
    gap: 8px;
    background: linear-gradient(135deg, var(--primary), var(--primary-hover));
    color: #fff;
    border: none;
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    padding: 10px 20px;
    font-family: var(--font);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
}

.btn-send:hover {
    filter: brightness(1.1);
    transform: translateY(-1px);
}

.btn-send:active {
    transform: translateY(0);
}

.btn-send.loading {
    opacity: 0.7;
    pointer-events: none;
}

/* --- Tabs --- */
.request-tabs,
.response-tabs {
    display: flex;
    gap: 0;
    padding: 0 20px;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
}

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

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

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

/* --- Tab Panels --- */
.tab-panels {
    flex: 1;
    overflow-y: auto;
    padding: 16px 20px;
}

.tab-panel {
    display: none;
}

.tab-panel.active {
    display: block;
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(4px);
    }

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

/* --- Key-Value Editor --- */
.kv-header {
    display: grid;
    grid-template-columns: 1fr 1fr 36px;
    gap: 8px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 8px;
}

.kv-header span {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
}

.kv-row {
    display: grid;
    grid-template-columns: 1fr 1fr 36px;
    gap: 8px;
    margin-bottom: 6px;
    animation: fadeIn 0.15s ease;
}

.kv-row input {
    background: var(--bg-input);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
    padding: 8px 10px;
    font-family: var(--mono);
    font-size: 0.82rem;
    outline: none;
    transition: border-color var(--transition);
}

.kv-row input:focus {
    border-color: var(--border-focus);
}

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

.btn-remove-row {
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-dim);
    border-radius: var(--radius-xs);
    cursor: pointer;
    transition: all var(--transition);
    width: 36px;
    height: 36px;
}

.btn-remove-row:hover {
    color: var(--status-5xx);
    border-color: var(--status-5xx);
    background: rgba(239, 68, 68, 0.1);
}

.btn-add-row {
    background: transparent;
    border: 1px dashed var(--border);
    color: var(--text-muted);
    padding: 8px;
    border-radius: var(--radius-xs);
    font-family: var(--font);
    font-size: 0.82rem;
    cursor: pointer;
    width: 100%;
    margin-top: 4px;
    transition: all var(--transition);
}

.btn-add-row:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: rgba(16, 185, 129, 0.05);
}

/* --- Body Editors --- */
.body-type-selector,
.auth-type-selector {
    margin-bottom: 14px;
}

.body-type-selector {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
}

.body-radio {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.85rem;
    color: var(--text-muted);
    cursor: pointer;
    transition: color var(--transition);
}

.body-radio:hover {
    color: var(--text);
}

.body-radio input[type="radio"] {
    accent-color: var(--primary);
}

.body-content {
    display: none;
}

.body-content.active {
    display: block;
    animation: fadeIn 0.2s ease;
}

.code-textarea {
    width: 100%;
    min-height: 200px;
    background: var(--bg-input);
    color: var(--secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 14px;
    font-family: var(--mono);
    font-size: 0.85rem;
    line-height: 1.6;
    resize: vertical;
    outline: none;
    transition: border-color var(--transition);
}

.code-textarea:focus {
    border-color: var(--border-focus);
}

.code-textarea::placeholder {
    color: var(--text-dim);
}

/* --- Auth --- */
.auth-select {
    background: var(--bg-input);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    font-family: var(--font);
    font-size: 0.85rem;
    width: 100%;
    cursor: pointer;
    outline: none;
    appearance: none;
    -webkit-appearance: none;
}

.auth-select:focus {
    border-color: var(--border-focus);
}

.auth-content {
    display: none;
}

.auth-content.active {
    display: block;
    animation: fadeIn 0.2s ease;
}

.auth-label {
    display: block;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-muted);
    margin: 12px 0 6px;
}

.auth-input {
    width: 100%;
    background: var(--bg-input);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    font-family: var(--mono);
    font-size: 0.85rem;
    outline: none;
    transition: border-color var(--transition);
}

.auth-input:focus {
    border-color: var(--border-focus);
}

/* --- Response Panel --- */
.response-panel {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.response-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 20px;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
}

.response-title {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text);
}

.response-meta {
    display: flex;
    align-items: center;
    gap: 12px;
    font-family: var(--mono);
    font-size: 0.8rem;
}

.meta-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    border-radius: 20px;
    font-weight: 600;
    font-size: 0.78rem;
}

.meta-badge.status {
    background: rgba(16, 185, 129, 0.15);
    color: var(--status-2xx);
}

.meta-badge.status-3xx {
    background: rgba(59, 130, 246, 0.15);
    color: var(--status-3xx);
}

.meta-badge.status-4xx {
    background: rgba(245, 158, 11, 0.15);
    color: var(--status-4xx);
}

.meta-badge.status-5xx {
    background: rgba(239, 68, 68, 0.15);
    color: var(--status-5xx);
}

.meta-badge.time {
    background: rgba(100, 116, 139, 0.15);
    color: var(--text-muted);
}

.meta-badge.size {
    background: rgba(100, 116, 139, 0.15);
    color: var(--text-muted);
}

.response-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px 20px;
}

.rtab-panel {
    display: none;
}

.rtab-panel.active {
    display: block;
    animation: fadeIn 0.2s ease;
}

.response-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 60px 20px;
    color: var(--text-dim);
    font-size: 0.9rem;
}

.response-output {
    display: none;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 16px;
    font-family: var(--mono);
    font-size: 0.82rem;
    line-height: 1.6;
    color: var(--secondary);
    overflow: auto;
    max-height: calc(100vh - 280px);
    white-space: pre-wrap;
    word-break: break-word;
}

.response-output.visible {
    display: block;
}

/* Response headers table */
.response-headers-list table {
    width: 100%;
    border-collapse: collapse;
}

.response-headers-list th,
.response-headers-list td {
    text-align: left;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
    font-size: 0.82rem;
}

.response-headers-list th {
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-size: 0.75rem;
}

.response-headers-list td:first-child {
    color: var(--primary);
    font-family: var(--mono);
    font-weight: 500;
}

.response-headers-list td:last-child {
    color: var(--text);
    font-family: var(--mono);
}

/* Timing breakdown */
.timing-bar-container {
    margin-bottom: 14px;
}

.timing-label {
    display: flex;
    justify-content: space-between;
    margin-bottom: 4px;
    font-size: 0.82rem;
}

.timing-label span:first-child {
    color: var(--text-muted);
}

.timing-label span:last-child {
    color: var(--text);
    font-family: var(--mono);
}

.timing-bar {
    height: 8px;
    border-radius: 4px;
    background: var(--bg-input);
    overflow: hidden;
}

.timing-bar-fill {
    height: 100%;
    border-radius: 4px;
    background: linear-gradient(90deg, var(--primary), var(--secondary));
    transition: width 0.5s ease;
}

/* Code Gen */
.codegen-selector {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
}

.codegen-select {
    flex: 1;
    background: var(--bg-input);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 8px 12px;
    font-family: var(--font);
    font-size: 0.85rem;
    outline: none;
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
}

.codegen-select:focus {
    border-color: var(--border-focus);
}

.btn-copy {
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    color: var(--text-muted);
    padding: 8px 14px;
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: 0.82rem;
    cursor: pointer;
    transition: all var(--transition);
}

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

.codegen-output {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 16px;
    font-family: var(--mono);
    font-size: 0.82rem;
    line-height: 1.6;
    color: var(--secondary);
    overflow: auto;
    max-height: calc(100vh - 340px);
    white-space: pre-wrap;
    word-break: break-word;
}

/* --- Muted Text --- */
.muted-text {
    color: var(--text-dim);
    font-size: 0.85rem;
    text-align: center;
    padding: 20px;
}

/* --- 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;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
}

.modal-overlay.visible {
    opacity: 1;
    pointer-events: auto;
}

.modal {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    width: 90%;
    max-width: 560px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
    transform: translateY(20px);
    transition: transform 0.25s ease;
}

.modal-overlay.visible .modal {
    transform: translateY(0);
}

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

.modal-header h2 {
    font-size: 1rem;
    font-weight: 600;
}

.modal-close {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 1.4rem;
    cursor: pointer;
    padding: 4px 8px;
    transition: color var(--transition);
}

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

.modal-actions {
    display: flex;
    gap: 8px;
    padding: 12px 20px;
    border-bottom: 1px solid var(--border);
}

.collection-input {
    flex: 1;
    background: var(--bg-input);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 8px 12px;
    font-family: var(--font);
    font-size: 0.85rem;
    outline: none;
}

.collection-input:focus {
    border-color: var(--border-focus);
}

.modal-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px 20px;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    padding: 12px 20px;
    border-top: 1px solid var(--border);
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--primary-hover));
    color: #fff;
    border: none;
    border-radius: var(--radius-sm);
    padding: 8px 16px;
    font-family: var(--font);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
}

.btn-primary:hover {
    filter: brightness(1.1);
}

.btn-danger {
    background: rgba(239, 68, 68, 0.15);
    color: var(--status-5xx);
    border: 1px solid rgba(239, 68, 68, 0.3);
    border-radius: var(--radius-sm);
    padding: 8px 16px;
    font-family: var(--font);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
}

.btn-danger:hover {
    background: rgba(239, 68, 68, 0.25);
}

/* History & Collection Items */
.history-item,
.collection-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
    cursor: pointer;
    transition: all var(--transition);
}

.history-item:hover,
.collection-item:hover {
    background: var(--bg-elevated);
    border-color: var(--primary);
}

.history-method {
    font-family: var(--mono);
    font-size: 0.75rem;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 4px;
    min-width: 56px;
    text-align: center;
}

.history-method.GET {
    background: rgba(16, 185, 129, 0.15);
    color: var(--method-get);
}

.history-method.POST {
    background: rgba(59, 130, 246, 0.15);
    color: var(--method-post);
}

.history-method.PUT {
    background: rgba(245, 158, 11, 0.15);
    color: var(--method-put);
}

.history-method.DELETE {
    background: rgba(239, 68, 68, 0.15);
    color: var(--method-delete);
}

.history-method.PATCH {
    background: rgba(139, 92, 246, 0.15);
    color: var(--method-patch);
}

.history-url {
    flex: 1;
    font-family: var(--mono);
    font-size: 0.8rem;
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.history-status {
    font-family: var(--mono);
    font-size: 0.78rem;
    font-weight: 600;
}

.history-time {
    font-size: 0.75rem;
    color: var(--text-dim);
    white-space: nowrap;
}

.collection-name {
    flex: 1;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text);
}

.collection-count {
    font-size: 0.78rem;
    color: var(--text-dim);
}

.btn-delete-collection {
    background: transparent;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    padding: 4px;
    transition: color var(--transition);
}

.btn-delete-collection:hover {
    color: var(--status-5xx);
}

/* --- Loading --- */
.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(10, 22, 40, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 900;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}

.loading-overlay.visible {
    opacity: 1;
    pointer-events: auto;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* --- Toast --- */
.toast-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 18px;
    font-size: 0.85rem;
    color: var(--text);
    box-shadow: var(--shadow);
    animation: toastIn 0.3s ease, toastOut 0.3s ease 2.5s forwards;
    max-width: 320px;
}

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

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

@keyframes toastIn {
    from {
        opacity: 0;
        transform: translateX(20px);
    }

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

@keyframes toastOut {
    to {
        opacity: 0;
        transform: translateX(20px);
    }
}

/* --- Autocomplete --- */
.autocomplete-wrapper {
    position: relative;
}

.autocomplete-list {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
    max-height: 180px;
    overflow-y: auto;
    z-index: 50;
    display: none;
}

.autocomplete-list.visible {
    display: block;
}

.autocomplete-item {
    padding: 6px 10px;
    font-family: var(--mono);
    font-size: 0.8rem;
    color: var(--text-muted);
    cursor: pointer;
    transition: all var(--transition);
}

.autocomplete-item:hover,
.autocomplete-item.selected {
    background: rgba(16, 185, 129, 0.1);
    color: var(--primary);
}

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

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

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

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

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

    .request-panel {
        border-right: none;
        border-bottom: 1px solid var(--border);
    }

    .btn-label {
        display: none;
    }
}

@media (max-width: 600px) {
    .app-header {
        padding: 10px 14px;
    }

    .logo h1 {
        font-size: 0.95rem;
    }

    .url-bar {
        padding: 10px 14px;
        flex-wrap: wrap;
    }

    .method-select {
        min-width: 80px;
        border-radius: var(--radius-sm);
        border-right: 1px solid var(--border);
    }

    .url-input {
        border-left: 1px solid var(--border);
        border-radius: 0;
        flex-basis: 100%;
        order: 1;
        margin-top: 8px;
        border-radius: var(--radius-sm) 0 0 var(--radius-sm);
    }

    .btn-send {
        border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
        order: 2;
        margin-top: 8px;
    }

    .tab-panels,
    .response-body {
        padding: 12px 14px;
    }
}