/* ============================================================
   gRPC Web Tester — Styles
   Theme: Dark mode with Flame palette
   ============================================================ */

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

:root {
    --primary: #E84118;
    --primary-rgb: 232, 65, 24;
    --secondary: #FF6348;
    --secondary-rgb: 255, 99, 72;
    --accent: #FFC312;
    --accent-rgb: 255, 195, 18;
    --bg: #1A0D08;
    --bg-hover: rgba(232, 65, 24, 0.1);
    --border: rgba(232, 65, 24, 0.15);
    --border-hover: rgba(232, 65, 24, 0.3);
    --text: #F5E6D3;
    --text-secondary: #D4A574;
    --text-muted: rgba(245, 230, 211, 0.45);
    --success: #00B894;
    --danger: #FF6B6B;
    --warning: #FFC312;
    --radius: 12px;
    --radius-sm: 8px;
    --font: 'Inter', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
    --font-mono: 'JetBrains Mono', monospace;
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.35);
    --transition: 250ms ease;
    --glass-bg: rgba(26, 13, 8, 0.65);
    --glass-border: rgba(232, 65, 24, 0.12);
    --glass-blur: blur(20px);
}

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

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

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
}

body::before {
    content: '';
    position: fixed;
    inset: 0;
    background:
        radial-gradient(ellipse at 20% 15%, rgba(var(--primary-rgb), 0.1) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 80%, rgba(var(--accent-rgb), 0.05) 0%, transparent 50%);
    pointer-events: none;
    z-index: 0;
}

.app {
    position: relative;
    z-index: 1;
    max-width: 1300px;
    margin: 0 auto;
    padding: 2rem 1.5rem;
}

/* Header */
.header {
    text-align: center;
    margin-bottom: 2rem;
}

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

.header p {
    color: var(--text-secondary);
    font-size: 1rem;
    font-weight: 300;
}

/* Grid */
.main-grid {
    display: grid;
    grid-template-columns: 400px 1fr;
    gap: 1.5rem;
    align-items: start;
}

/* Card */
.card {
    background: var(--glass-bg);
    backdrop-filter: var(--glass-blur);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: var(--shadow);
}

.card+.card {
    margin-top: 1rem;
}

.card h2 {
    font-size: 0.95rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
}

/* Form Controls */
.form-group {
    margin-bottom: 0.75rem;
}

.form-group label {
    display: block;
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 0.3rem;
}

.form-input {
    width: 100%;
    padding: 0.55rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: rgba(0, 0, 0, 0.35);
    color: var(--text);
    font-family: var(--font-mono);
    font-size: 0.85rem;
    transition: all var(--transition);
}

.form-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(var(--primary-rgb), 0.1);
}

.form-input::placeholder {
    color: var(--text-muted);
}

.form-select {
    width: 100%;
    padding: 0.55rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: rgba(0, 0, 0, 0.35);
    color: var(--text);
    font-family: var(--font);
    font-size: 0.85rem;
}

.form-select option {
    background: var(--bg);
}

.form-row {
    display: flex;
    gap: 0.5rem;
}

.form-row>* {
    flex: 1;
}

textarea.form-input {
    min-height: 120px;
    resize: vertical;
    font-size: 0.8rem;
    line-height: 1.6;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.6rem 1.2rem;
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    border: none;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary), #d63a14);
    color: #fff;
}

.btn-primary:hover {
    box-shadow: 0 4px 16px rgba(var(--primary-rgb), 0.3);
    transform: translateY(-1px);
}

.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

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

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

/* Metadata rows */
.metadata-rows {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.meta-row {
    display: flex;
    gap: 0.4rem;
    align-items: center;
}

.meta-row input {
    flex: 1;
    padding: 0.4rem 0.6rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: rgba(0, 0, 0, 0.3);
    color: var(--text);
    font-family: var(--font-mono);
    font-size: 0.8rem;
}

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

.meta-remove {
    padding: 0.3rem 0.5rem;
    border: 1px solid rgba(255, 107, 107, 0.3);
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--danger);
    font-size: 0.8rem;
    cursor: pointer;
}

.meta-remove:hover {
    background: rgba(255, 107, 107, 0.1);
}

.add-meta-btn {
    padding: 0.4rem 0.7rem;
    border: 1px dashed var(--border);
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-muted);
    font-family: var(--font);
    font-size: 0.8rem;
    cursor: pointer;
    transition: all var(--transition);
    margin-top: 0.4rem;
}

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

/* Call Type Tabs */
.call-tabs {
    display: flex;
    gap: 0;
    margin-bottom: 0.75rem;
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.call-tab {
    flex: 1;
    padding: 0.5rem;
    border: none;
    background: rgba(0, 0, 0, 0.2);
    color: var(--text-muted);
    font-family: var(--font);
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
}

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

.call-tab.active {
    background: rgba(var(--primary-rgb), 0.15);
    color: var(--primary);
}

/* Response panel */
.response-card {
    min-height: 200px;
}

.response-status {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem 0;
    margin-bottom: 0.75rem;
    border-bottom: 1px solid var(--border);
}

.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

.status-dot.ok {
    background: var(--success);
    box-shadow: 0 0 8px rgba(0, 184, 148, 0.4);
}

.status-dot.error {
    background: var(--danger);
    box-shadow: 0 0 8px rgba(255, 107, 107, 0.4);
}

.status-dot.pending {
    background: var(--accent);
    animation: pulse 1.5s ease infinite;
}

.status-text {
    font-size: 0.85rem;
    font-weight: 500;
}

.status-time {
    margin-left: auto;
    font-family: var(--font-mono);
    font-size: 0.8rem;
    color: var(--text-muted);
}

.response-body {
    background: rgba(0, 0, 0, 0.3);
    border-radius: var(--radius-sm);
    padding: 1rem;
    max-height: 400px;
    overflow-y: auto;
    font-family: var(--font-mono);
    font-size: 0.8rem;
    line-height: 1.6;
    color: var(--text-secondary);
    white-space: pre-wrap;
    word-break: break-word;
}

.response-body::-webkit-scrollbar {
    width: 6px;
}

.response-body::-webkit-scrollbar-thumb {
    background: rgba(var(--primary-rgb), 0.2);
    border-radius: 3px;
}

/* Streaming messages */
.stream-msg {
    padding: 0.5rem 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.03);
}

.stream-msg:last-child {
    border-bottom: none;
}

.stream-idx {
    color: var(--accent);
    font-size: 0.7rem;
}

/* Error codes */
.error-ref {
    margin-top: 1rem;
}

.error-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 0.4rem;
}

.error-item {
    padding: 0.45rem 0.6rem;
    border-radius: var(--radius-sm);
    background: rgba(0, 0, 0, 0.2);
    font-size: 0.72rem;
    display: flex;
    flex-direction: column;
}

.error-code {
    font-family: var(--font-mono);
    color: var(--secondary);
    font-weight: 600;
}

.error-name {
    color: var(--text-muted);
    font-size: 0.65rem;
    margin-top: 0.1rem;
}

/* History */
.history-list {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    max-height: 300px;
    overflow-y: auto;
}

.history-item {
    padding: 0.5rem 0.7rem;
    border-radius: var(--radius-sm);
    background: rgba(0, 0, 0, 0.2);
    cursor: pointer;
    transition: all var(--transition);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

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

.history-method {
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--accent);
    min-width: 55px;
}

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

.history-status {
    font-size: 0.7rem;
    font-weight: 600;
}

.history-status.ok {
    color: var(--success);
}

.history-status.err {
    color: var(--danger);
}

/* Actions bar */
.actions-bar {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.75rem;
    flex-wrap: wrap;
}

/* Toast */
.toast {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    padding: 0.8rem 1.5rem;
    border-radius: var(--radius);
    background: var(--primary);
    color: #fff;
    font-size: 0.875rem;
    font-weight: 500;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    transform: translateY(100px);
    opacity: 0;
    transition: all 300ms ease;
    z-index: 1000;
}

.toast.visible {
    transform: translateY(0);
    opacity: 1;
}

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

@media (max-width: 500px) {
    .app {
        padding: 1rem;
    }

    .header h1 {
        font-size: 1.5rem;
    }

    .form-row {
        flex-direction: column;
    }

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

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

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

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.4;
    }
}

.card {
    animation: fadeIn 250ms ease forwards;
}