/* API Tester - Mobile-first Styles */

:root {
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-tertiary: #334155;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --success: #22c55e;
    --warning: #f59e0b;
    --danger: #ef4444;
    --border: #475569;
    --radius: 8px;
    --radius-lg: 12px;
    --shadow: 0 4px 6px -1px rgba(0,0,0,0.3), 0 2px 4px -2px rgba(0,0,0,0.3);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 14px;
    line-height: 1.5;
}

/* ========== APP STRUCTURE ========== */

#app {
    height: 100%;
    display: flex;
    flex-direction: column;
}

.screen {
    display: none;
    height: 100%;
    flex-direction: column;
}

.screen.active {
    display: flex;
}

/* ========== LOGIN ========== */

#login-screen {
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.login-card {
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    padding: 32px 24px;
    width: 100%;
    max-width: 360px;
    box-shadow: var(--shadow);
}

.login-card h1 {
    font-size: 1.5rem;
    text-align: center;
    margin-bottom: 24px;
    color: var(--text-primary);
}

.form-group {
    margin-bottom: 16px;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 1rem;
    transition: border-color 0.2s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--accent);
}

input::placeholder,
textarea::placeholder {
    color: var(--text-muted);
}

.error-msg {
    color: var(--danger);
    font-size: 0.875rem;
    margin-top: 12px;
    text-align: center;
    min-height: 20px;
}

/* ========== BUTTONS ========== */

.btn-primary {
    width: 100%;
    padding: 14px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: var(--radius);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-primary:hover,
.btn-primary:active {
    background: var(--accent-hover);
}

.btn-secondary {
    padding: 10px 16px;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.875rem;
    cursor: pointer;
}

.btn-danger {
    padding: 10px 16px;
    background: var(--danger);
    color: white;
    border: none;
    border-radius: var(--radius);
    font-size: 0.875rem;
    cursor: pointer;
}

.btn-text {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 0.875rem;
    cursor: pointer;
    padding: 4px 8px;
}

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

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

.btn-save {
    padding: 8px 16px;
    background: var(--success);
    color: white;
    border: none;
    border-radius: var(--radius);
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
}

.icon-btn {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: var(--radius);
    transition: background 0.2s, color 0.2s;
}

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

.icon-btn.small {
    width: 32px;
    height: 32px;
}

/* ========== MAIN LAYOUT ========== */

#main-screen {
    flex: 1;
    overflow: hidden;
}

/* ========== HEADER ========== */

.app-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.app-header h2 {
    flex: 1;
    font-size: 1.125rem;
    font-weight: 600;
}

/* ========== SIDEBAR ========== */

.sidebar {
    position: fixed;
    top: 0;
    left: -280px;
    width: 280px;
    height: 100%;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    transition: left 0.3s ease;
    z-index: 100;
}

.sidebar.open {
    left: 0;
}

.sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s, visibility 0.3s;
    z-index: 99;
}

.sidebar-overlay.active {
    opacity: 1;
    visibility: visible;
}

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

.sidebar-header h3 {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
}

.sidebar-section {
    padding: 12px 8px;
    border-top: 1px solid var(--border);
    margin-top: auto;
}

.sidebar-link {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 0.875rem;
    cursor: pointer;
    border-radius: var(--radius);
    transition: background 0.2s, color 0.2s;
}

.sidebar-link:hover,
.sidebar-link:active {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

/* ========== COLLECTIONS LIST ========== */

.collections-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.collection-item {
    margin-bottom: 4px;
}

.collection-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    background: none;
    border: none;
    width: 100%;
    color: var(--text-secondary);
    font-size: 0.875rem;
    cursor: pointer;
    border-radius: var(--radius);
    transition: background 0.2s;
}

.collection-header:hover,
.collection-header:active {
    background: var(--bg-tertiary);
}

.collection-header svg {
    transition: transform 0.2s;
}

.collection-header.expanded svg:first-child {
    transform: rotate(90deg);
}

.collection-count {
    margin-left: auto;
    font-size: 0.75rem;
    color: var(--text-muted);
    background: var(--bg-primary);
    padding: 2px 8px;
    border-radius: 10px;
}

.collection-requests-list {
    display: none;
    padding-left: 20px;
}

.collection-requests-list.expanded {
    display: block;
}

.request-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: none;
    border: none;
    width: 100%;
    color: var(--text-primary);
    font-size: 0.8125rem;
    cursor: pointer;
    border-radius: var(--radius);
    transition: background 0.2s;
    text-align: left;
}

.request-item:hover,
.request-item:active {
    background: var(--bg-tertiary);
}

.method-badge {
    font-size: 0.625rem;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 4px;
    background: var(--bg-tertiary);
    color: var(--text-muted);
    min-width: 36px;
    text-align: center;
}

.method-badge.GET { color: #22c55e; }
.method-badge.POST { color: #f59e0b; }
.method-badge.PUT { color: #3b82f6; }
.method-badge.PATCH { color: #8b5cf6; }
.method-badge.DELETE { color: #ef4444; }

/* ========== CONTENT AREA ========== */

.content {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    padding-bottom: 100px;
}

/* ========== VIEWS ========== */

.view {
    display: none;
}

.view.active {
    display: block;
}

/* ========== WELCOME ========== */

.welcome-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 48px 24px;
    color: var(--text-muted);
}

.welcome-card svg {
    margin-bottom: 16px;
    opacity: 0.5;
}

.welcome-card h3 {
    font-size: 1.125rem;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.welcome-card p {
    font-size: 0.875rem;
    max-width: 280px;
}

/* ========== REQUEST EDITOR ========== */

.request-header {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
}

.request-name-input {
    flex: 1;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 1rem;
}

.method-select {
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-weight: 600;
    font-size: 0.875rem;
    min-width: 80px;
}

.url-bar {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}

.url-input {
    flex: 1;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 0.9375rem;
}

.btn-send {
    padding: 12px 24px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: var(--radius);
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-send:hover,
.btn-send:active {
    background: var(--accent-hover);
}

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

/* ========== TABS ========== */

.tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 12px;
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
}

.tab {
    padding: 10px 16px;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 0.875rem;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: color 0.2s, border-color 0.2s;
    white-space: nowrap;
}

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

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

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* ========== KEY-VALUE LISTS (Headers/Params) ========== */

.key-value-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 12px;
}

.kv-row {
    display: flex;
    gap: 8px;
    align-items: center;
}

.kv-row input {
    flex: 1;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 0.875rem;
}

.kv-row input:first-child {
    flex: 0.4;
}

.kv-row .btn-remove {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: var(--radius);
}

.kv-row .btn-remove:hover {
    color: var(--danger);
    background: rgba(239,68,68,0.1);
}

.btn-add-row {
    width: 100%;
    padding: 10px;
    background: none;
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    color: var(--text-muted);
    font-size: 0.875rem;
    cursor: pointer;
    transition: border-color 0.2s, color 0.2s;
}

.btn-add-row:hover,
.btn-add-row:active {
    border-color: var(--accent);
    color: var(--accent);
}

/* ========== BODY TAB ========== */

.body-type-select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 0.875rem;
    margin-bottom: 12px;
}

.body-textarea {
    width: 100%;
    min-height: 150px;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-family: 'SF Mono', Monaco, Consolas, monospace;
    font-size: 0.8125rem;
    resize: vertical;
}

/* ========== AUTH TAB ========== */

.auth-type-selector {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 16px;
}

.auth-type-selector label {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 0.8125rem;
    transition: border-color 0.2s;
}

.auth-type-selector input[type="radio"] {
    width: auto;
    margin: 0;
}

.auth-type-selector input:checked + span {
    color: var(--accent);
}

.auth-type-selector label:has(input:checked) {
    border-color: var(--accent);
}

.auth-fields {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.auth-input {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 0.875rem;
}

.auth-add-to {
    display: flex;
    align-items: center;
    gap: 12px;
}

.auth-add-to label {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.auth-add-to select {
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 0.875rem;
}

/* ========== RESPONSE ========== */

.response-section {
    margin-top: 24px;
    border-top: 1px solid var(--border);
    padding-top: 16px;
}

.response-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.status-badge {
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.8125rem;
    font-weight: 600;
}

.status-badge.success {
    background: rgba(34,197,94,0.15);
    color: var(--success);
}

.status-badge.redirect {
    background: rgba(59,130,246,0.15);
    color: var(--accent);
}

.status-badge.client-error {
    background: rgba(245,158,11,0.15);
    color: var(--warning);
}

.status-badge.server-error {
    background: rgba(239,68,68,0.15);
    color: var(--danger);
}

.response-time {
    color: var(--text-muted);
    font-size: 0.8125rem;
}

.response-header .btn-save {
    margin-left: auto;
}

.response-body {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
    font-family: 'SF Mono', Monaco, Consolas, monospace;
    font-size: 0.8125rem;
    overflow-x: auto;
    white-space: pre-wrap;
    word-break: break-all;
    max-height: 400px;
    overflow-y: auto;
}

.response-headers {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.response-header-item {
    display: flex;
    gap: 8px;
    padding: 8px 12px;
    background: var(--bg-secondary);
    border-radius: var(--radius);
    font-size: 0.8125rem;
}

.response-header-item strong {
    color: var(--text-secondary);
    min-width: 150px;
}

/* ========== HISTORY ========== */

.view-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.view-header h3 {
    font-size: 1.125rem;
}

.history-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.history-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    background: var(--bg-secondary);
    border-radius: var(--radius);
    cursor: pointer;
    transition: background 0.2s;
}

.history-item:hover,
.history-item:active {
    background: var(--bg-tertiary);
}

.history-method {
    font-size: 0.6875rem;
    font-weight: 700;
    padding: 4px 8px;
    border-radius: 4px;
    min-width: 44px;
    text-align: center;
}

.history-method.GET { background: rgba(34,197,94,0.15); color: #22c55e; }
.history-method.POST { background: rgba(245,158,11,0.15); color: #f59e0b; }
.history-method.PUT { background: rgba(59,130,246,0.15); color: #3b82f6; }
.history-method.DELETE { background: rgba(239,68,68,0.15); color: #ef4444; }

.history-info {
    flex: 1;
    min-width: 0;
}

.history-url {
    font-size: 0.875rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--text-primary);
}

.history-meta {
    font-size: 0.75rem;
    color: var(--text-muted);
    display: flex;
    gap: 12px;
    margin-top: 4px;
}

.history-status {
    font-weight: 600;
}

.history-status.success { color: var(--success); }
.history-status.redirect { color: var(--accent); }
.history-status.error { color: var(--danger); }

/* ========== COLLECTION VIEW ========== */

.collection-name-input {
    flex: 1;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 1rem;
}

.collection-requests {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.collection-requests .request-item {
    background: var(--bg-secondary);
    padding: 12px 16px;
}

/* ========== MODALS ========== */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.7);
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
    z-index: 200;
}

.modal-overlay.active {
    display: flex;
}

.modal {
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    padding: 24px;
    width: 100%;
    max-width: 360px;
    box-shadow: 0 25px 50px rgba(0,0,0,0.5);
}

.modal h3 {
    font-size: 1.125rem;
    margin-bottom: 20px;
}

.modal-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    margin-top: 24px;
}

.modal-actions .btn-primary,
.modal-actions .btn-secondary,
.modal-actions .btn-danger {
    width: auto;
}

/* ========== LOADING STATES ========== */

.loading {
    opacity: 0.6;
    pointer-events: none;
}

.spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid var(--text-muted);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* ========== RESPONSIVE ========== */

@media (min-width: 768px) {
    .sidebar {
        position: relative;
        left: 0;
    }
    
    .sidebar-overlay {
        display: none;
    }
    
    #menu-toggle {
        display: none;
    }
    
    #main-screen {
        flex-direction: row;
    }
    
    .content {
        padding: 24px;
    }
    
    .url-bar {
        flex-direction: row;
    }
    
    .response-header {
        flex-wrap: nowrap;
    }
}

@media (max-width: 767px) {
    .sidebar-overlay {
        position: fixed;
    }
    
    .app-header {
        padding: 12px;
    }
    
    .content {
        padding: 12px;
    }
    
    .tabs {
        gap: 0;
    }
    
    .tab {
        padding: 10px 12px;
        font-size: 0.8125rem;
    }
}
