:root {
    /* Colors */
    --bg-primary: #0a0e17;
    --bg-secondary: #111827;
    --bg-card: rgba(17, 24, 39, 0.8);
    --bg-card-hover: rgba(24, 34, 56, 0.9);
    --border-color: rgba(56, 189, 248, 0.15);
    --border-hover: rgba(56, 189, 248, 0.35);
    
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    
    --accent-primary: #38bdf8;
    --accent-secondary: #818cf8;
    --accent-gradient: linear-gradient(135deg, #38bdf8, #818cf8);
    
    --success: #34d399;
    --error: #f87171;
    --warning: #fbbf24;
    
    --terminal-bg: #0d1117;
    --terminal-text: #c9d1d9;
    
    /* Typography */
    --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
    
    /* Layout */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --shadow-glow: 0 0 20px rgba(56, 189, 248, 0.1);
    --shadow-glow-active: 0 0 30px rgba(56, 189, 248, 0.25);
}

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

html {
    scroll-behavior: smooth;
}

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

/* Animated Background */
.bg-animated {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    z-index: -1;
    background: radial-gradient(circle at 15% 50%, rgba(56, 189, 248, 0.05), transparent 25%),
                radial-gradient(circle at 85% 30%, rgba(129, 140, 248, 0.05), transparent 25%);
    animation: gradientShift 15s ease-in-out infinite alternate;
}

@keyframes gradientShift {
    0% { transform: scale(1) translate(0, 0); }
    100% { transform: scale(1.1) translate(-2%, 2%); }
}

/* Header */
header {
    position: sticky;
    top: 0;
    background: rgba(10, 14, 23, 0.7);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    z-index: 100;
    border-bottom: 1px solid var(--border-color);
}

.header-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

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

.logo-icon {
    width: 32px;
    height: 32px;
    color: var(--accent-primary);
}

.logo-text h1 {
    font-size: 1.25rem;
    font-weight: 700;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    line-height: 1.2;
}

.logo-text .subtitle {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.asn-badge {
    background: var(--accent-gradient);
    color: #fff;
    padding: 0.25rem 0.75rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    margin-left: auto;
}

/* Main Layout */
main {
    flex: 1;
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem;
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

/* Glass Cards */
.card.glass {
    background: var(--bg-card);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 2rem;
    transition: all 0.3s ease;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

/* Router Select */
.router-select {
    margin-bottom: 2rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.router-select label {
    font-size: 0.9rem;
    color: var(--text-secondary);
    font-weight: 500;
}

select {
    appearance: none;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 0.75rem 1rem;
    border-radius: var(--radius-md);
    font-family: var(--font-sans);
    font-size: 1rem;
    outline: none;
    cursor: pointer;
    transition: all 0.2s ease;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%2394a3b8'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 1rem center;
    background-size: 1rem;
}

select:focus {
    border-color: var(--accent-primary);
    box-shadow: var(--shadow-glow);
}

/* Command Grid */
.command-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
    margin-bottom: 2rem;
}

.command-card input[type="radio"] {
    display: none;
}

.command-card label {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 1.25rem 1rem;
    cursor: pointer;
    transition: all 0.2s ease;
    height: 100%;
}

.cmd-icon {
    font-size: 1.75rem;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.2));
}

.cmd-name {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-secondary);
    text-align: center;
}

.command-card label:hover {
    border-color: var(--border-hover);
    transform: translateY(-2px);
    background: var(--bg-card-hover);
}

.command-card input[type="radio"]:checked + label {
    border-color: var(--accent-primary);
    background: rgba(56, 189, 248, 0.1);
    box-shadow: var(--shadow-glow);
}

.command-card input[type="radio"]:checked + label .cmd-name {
    color: var(--accent-primary);
    font-weight: 600;
}

/* Query Input */
.query-input {
    display: flex;
    gap: 1rem;
    margin-bottom: 0.5rem;
}

.input-wrapper {
    flex: 1;
    position: relative;
}

#target-input {
    width: 100%;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 1rem 1.25rem;
    border-radius: var(--radius-md);
    font-family: var(--font-mono);
    font-size: 1rem;
    outline: none;
    transition: all 0.2s ease;
}

#target-input::placeholder {
    color: var(--text-muted);
    font-family: var(--font-sans);
}

#target-input:focus {
    border-color: var(--accent-primary);
    box-shadow: var(--shadow-glow);
}

#target-input.invalid {
    border-color: var(--error);
}

#execute-btn {
    background: var(--accent-gradient);
    color: white;
    border: none;
    border-radius: var(--radius-md);
    padding: 0 2rem;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 140px;
}

#execute-btn:hover:not(:disabled) {
    box-shadow: var(--shadow-glow-active);
    filter: brightness(1.1);
}

#execute-btn:active:not(:disabled) {
    transform: scale(0.98);
}

#execute-btn:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}

.spinner {
    animation: rotate 2s linear infinite;
    width: 24px;
    height: 24px;
}

.spinner .path {
    stroke: #ffffff;
    stroke-linecap: round;
    animation: dash 1.5s ease-in-out infinite;
}

@keyframes rotate { 100% { transform: rotate(360deg); } }
@keyframes dash {
    0% { stroke-dasharray: 1, 150; stroke-dashoffset: 0; }
    50% { stroke-dasharray: 90, 150; stroke-dashoffset: -35; }
    100% { stroke-dasharray: 90, 150; stroke-dashoffset: -124; }
}

.error-msg {
    color: var(--error);
    font-size: 0.85rem;
    margin-top: -0.25rem;
    margin-bottom: 1rem;
    animation: fadeIn 0.3s ease;
}

.error-shake {
    animation: shake 0.4s cubic-bezier(.36,.07,.19,.97) both;
}

@keyframes shake {
    10%, 90% { transform: translate3d(-1px, 0, 0); }
    20%, 80% { transform: translate3d(2px, 0, 0); }
    30%, 50%, 70% { transform: translate3d(-4px, 0, 0); }
    40%, 60% { transform: translate3d(4px, 0, 0); }
}

/* Query Info */
.query-info {
    display: flex;
    justify-content: space-between;
    margin-top: 1rem;
}

.badge {
    font-size: 0.75rem;
    padding: 0.25rem 0.75rem;
    border-radius: 999px;
    background: rgba(56, 189, 248, 0.1);
    color: var(--accent-primary);
    border: 1px solid var(--border-color);
}

.badge.bg-muted {
    background: rgba(100, 116, 139, 0.1);
    color: var(--text-secondary);
    border-color: rgba(100, 116, 139, 0.2);
}

.badge.warning {
    background: rgba(251, 191, 36, 0.1);
    color: var(--warning);
    border-color: rgba(251, 191, 36, 0.3);
}

.badge.error {
    background: rgba(248, 113, 113, 0.1);
    color: var(--error);
    border-color: rgba(248, 113, 113, 0.3);
}

/* Result Section */
.result-header {
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.result-meta {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.meta-pill {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.8rem;
    background: var(--bg-secondary);
    padding: 0.35rem 0.85rem;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}

.meta-pill .icon {
    font-size: 1rem;
}

.terminal-container {
    position: relative;
    border-radius: var(--radius-md);
    overflow: hidden;
    border: 1px solid var(--border-color);
    background: var(--terminal-bg);
    margin-bottom: 1.5rem;
}

.terminal-output {
    padding: 1.5rem;
    font-family: var(--font-mono);
    color: var(--terminal-text);
    font-size: 0.9rem;
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-all;
    max-height: 600px;
    overflow-y: auto;
    overflow-x: auto;
}

/* Custom Scrollbar */
.terminal-output::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}
.terminal-output::-webkit-scrollbar-track {
    background: rgba(0,0,0,0.2);
}
.terminal-output::-webkit-scrollbar-thumb {
    background: var(--border-hover);
    border-radius: 4px;
}
.terminal-output::-webkit-scrollbar-thumb:hover {
    background: var(--accent-primary);
}

#loading-overlay {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(13, 17, 23, 0.8);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
}

.terminal-loader {
    width: 48px;
    height: 48px;
    border: 3px solid var(--text-muted);
    border-bottom-color: var(--accent-primary);
    border-radius: 50%;
    animation: rotate 1s linear infinite;
}

.result-actions {
    display: flex;
    gap: 1rem;
    justify-content: flex-end;
}

.btn-secondary {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    padding: 0.6rem 1.25rem;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

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

/* History Section */
#history-section h3 {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 1.5rem;
    color: var(--text-primary);
}

#history-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.history-item {
    display: grid;
    grid-template-columns: auto 1fr auto auto;
    align-items: center;
    gap: 1rem;
    padding: 1rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.2s ease;
    animation: slideUp 0.3s ease;
}

.history-item:hover {
    border-color: var(--accent-primary);
    background: var(--bg-card-hover);
    transform: translateX(4px);
}

.hist-icon { font-size: 1.25rem; }
.hist-target { font-family: var(--font-mono); font-weight: 500; color: var(--text-primary); }
.hist-router { font-size: 0.85rem; color: var(--text-secondary); }
.hist-time { font-size: 0.8rem; color: var(--text-muted); }

.empty-state {
    text-align: center;
    padding: 2rem;
    color: var(--text-muted);
    font-style: italic;
}

/* Footer */
footer {
    margin-top: auto;
    padding: 2rem;
    border-top: 1px solid rgba(56, 189, 248, 0.05);
}

.footer-content {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.footer-main {
    font-weight: 500;
    color: var(--text-secondary);
}

.footer-links a {
    color: var(--accent-primary);
    text-decoration: none;
    transition: color 0.2s;
}

.footer-links a:hover {
    color: var(--accent-secondary);
    text-decoration: underline;
}

.separator {
    margin: 0 0.5rem;
    opacity: 0.5;
}

/* Utilities */
.hidden { display: none !important; }

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Responsive */
@media (max-width: 768px) {
    .command-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .query-input {
        flex-direction: column;
    }
    
    #execute-btn {
        width: 100%;
        padding: 1rem;
    }
    
    .result-header {
        flex-direction: column;
    }
    
    .history-item {
        grid-template-columns: auto 1fr;
        grid-template-rows: auto auto;
    }
    
    .hist-router { grid-column: 2; }
    .hist-time { grid-column: 1 / -1; text-align: right; margin-top: -1.5rem; }
}

@media (max-width: 480px) {
    main { padding: 1rem; }
    .header-container { padding: 1rem; }
    .card.glass { padding: 1.25rem; }
}
