/* ============================================
   PyAbel Web — Design System
   ============================================ */

/* --- CSS Custom Properties --- */
:root {
    /* Colors */
    --bg-primary: #0d1117;
    --bg-secondary: #161b22;
    --bg-tertiary: #1c2333;
    --bg-elevated: #21283b;
    --bg-hover: #292e3d;

    --surface-glass: rgba(22, 27, 34, 0.75);
    --surface-glass-border: rgba(99, 115, 148, 0.15);

    --text-primary: #e6edf3;
    --text-secondary: #8b949e;
    --text-muted: #525a65;

    --accent-primary: #58a6ff;
    --accent-secondary: #7c6aef;
    --accent-gradient: linear-gradient(135deg, #58a6ff 0%, #7c6aef 100%);
    --accent-glow: rgba(88, 166, 255, 0.15);

    --success: #3fb950;
    --warning: #d29922;
    --error: #f85149;

    /* Typography */
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-mono: 'JetBrains Mono', 'SF Mono', monospace;

    /* Spacing */
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 16px;
    --space-lg: 24px;
    --space-xl: 32px;
    --space-2xl: 48px;

    /* Radii */
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --radius-xl: 20px;

    /* Shadows */
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
    --shadow-glow: 0 0 20px var(--accent-glow);

    /* Transitions */
    --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
    --duration-fast: 150ms;
    --duration-normal: 250ms;
    --duration-slow: 400ms;

    /* Layout */
    --sidebar-width: 450px;
    --header-height: 60px;

}

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

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

body {
    font-family: var(--font-sans);
    font-size: 14px;
    color: var(--text-primary);
    background: var(--bg-primary);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.hidden {
    display: none !important;
}

/* --- Loading Overlay --- */
.loading-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-primary);
}

.loading-content {
    text-align: center;
    max-width: 380px;
    padding: var(--space-xl);
}

.loading-spinner {
    width: 48px;
    height: 48px;
    margin: 0 auto var(--space-lg);
    border: 3px solid rgba(88, 166, 255, 0.15);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

.loading-title {
    font-size: 28px;
    font-weight: 700;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: var(--space-sm);
}

.loading-status {
    color: var(--text-secondary);
    font-size: 13px;
    margin-bottom: var(--space-lg);
    min-height: 20px;
}

.loading-bar-track {
    width: 100%;
    height: 3px;
    background: var(--bg-tertiary);
    border-radius: 3px;
    overflow: hidden;
}

.loading-bar {
    height: 100%;
    width: 0%;
    background: var(--accent-gradient);
    border-radius: 3px;
    transition: width 0.8s var(--ease-out);
}

/* --- App Layout --- */
.app {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* --- Header --- */
.header {
    height: var(--header-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 var(--space-lg);
    background: var(--surface-glass);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--surface-glass-border);
    flex-shrink: 0;
}

.header-left {
    display: flex;
    align-items: baseline;
    gap: var(--space-md);
}

.logo {
    font-size: 20px;
    font-weight: 700;
    letter-spacing: -0.5px;
    color: var(--text-primary);
}

.logo-accent {
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.tagline {
    font-size: 13px;
    color: var(--text-secondary);
    font-weight: 400;
}

.header-link {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 13px;
    font-weight: 500;
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-sm);
    transition: all var(--duration-fast) ease;
}

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

/* --- Main Layout --- */
.main-layout {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* --- Controls Sidebar --- */
.controls {
    width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--surface-glass-border);
    overflow-y: auto;
    flex-shrink: 0;
    padding: var(--space-md);
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
}

.controls::-webkit-scrollbar {
    width: 6px;
}

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

.control-section {
    background: var(--bg-tertiary);
    border: 1px solid var(--surface-glass-border);
    border-radius: var(--radius-md);
    padding: var(--space-md);
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.section-title {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.control-row {
    display: flex;
    gap: var(--space-sm);
    align-items: center;
}

/* --- Buttons --- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    padding: 8px 16px;
    font-family: var(--font-sans);
    font-size: 13px;
    font-weight: 600;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--duration-fast) ease;
    white-space: nowrap;
    flex-shrink: 0;
}

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

.btn-primary {
    background: var(--accent-primary);
    color: #fff;
}

.btn-primary:hover:not(:disabled) {
    background: #79bbff;
    box-shadow: var(--shadow-glow);
}

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

.btn-secondary:hover:not(:disabled) {
    background: var(--bg-hover);
    border-color: var(--text-muted);
}

.btn-accent {
    background: var(--accent-gradient);
    color: #fff;
}

.btn-accent:hover:not(:disabled) {
    box-shadow: var(--shadow-glow);
    transform: translateY(-1px);
}

.btn-sm {
    padding: 5px 10px;
    font-size: 12px;
    font-weight: 500;
}

.btn-full {
    width: 100%;
}

/* --- Select --- */
.select {
    flex: 1;
    min-width: 0;
    padding: 8px 12px;
    font-family: var(--font-sans);
    font-size: 13px;
    color: var(--text-primary);
    background: var(--bg-elevated);
    border: 1px solid var(--surface-glass-border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: border-color var(--duration-fast) ease;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1L5 5L9 1' stroke='%238b949e' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    padding-right: 28px;
}

.select:hover {
    border-color: var(--text-muted);
}

.select:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 2px var(--accent-glow);
}

.select option {
    background: var(--bg-elevated);
    color: var(--text-primary);
}

/* --- Drop Zone --- */
.drop-zone {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--space-xs);
    padding: var(--space-lg) var(--space-md);
    border: 2px dashed var(--surface-glass-border);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--duration-normal) var(--ease-out);
    text-align: center;
}

.drop-zone:hover,
.drop-zone.drag-over {
    border-color: var(--accent-primary);
    background: var(--accent-glow);
}

.drop-zone.drag-over {
    transform: scale(0.98);
}

.drop-zone-text {
    font-size: 13px;
    color: var(--text-secondary);
}

.drop-zone-browse {
    color: var(--accent-primary);
    font-weight: 600;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.drop-zone-hint {
    font-size: 11px;
    color: var(--text-muted);
}

.sample-buttons {
    display: flex;
    gap: var(--space-sm);
}

.sample-buttons .btn {
    flex: 1;
}

/* --- Visualization Area --- */
.viz-area {
    flex: 1;
    padding: var(--space-md);
    overflow: hidden;
}

.viz-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
    gap: var(--space-md);
    height: 100%;
}

.viz-panel {
    background: var(--bg-secondary);
    border: 1px solid var(--surface-glass-border);
    border-radius: var(--radius-md);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: border-color var(--duration-normal) ease;
}

.viz-panel:hover {
    border-color: rgba(99, 115, 148, 0.3);
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-sm) var(--space-md);
    border-bottom: 1px solid var(--surface-glass-border);
    background: var(--bg-tertiary);
    flex-shrink: 0;
}

.panel-title {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
}

.panel-badge {
    font-size: 11px;
    font-weight: 500;
    color: var(--accent-primary);
    font-family: var(--font-mono);
}

.panel-content {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
}

.panel-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-sm);
    color: var(--text-muted);
    font-size: 13px;
}

.plot-container {
    width: 100%;
    height: 100%;
}

.panel-content {
    overflow: hidden;
}

/* --- Python Terminal --- */
.python-terminal {
    display: flex;
    flex-direction: column;
    padding: var(--space-md);
    margin-top: auto;
    border-top: 1px solid var(--surface-glass-border);
    background: #1e1e1e;
    min-height: 180px;
    max-height: 250px;
}

.terminal-header {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    margin-bottom: var(--space-sm);
    font-size: 11px;
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.python-code-output {
    flex: 1;
    overflow-y: auto;
    font-family: var(--font-mono);
    font-size: 12px;
    line-height: 1.5;
    color: #ce9178;
    white-space: pre-wrap;
    word-break: break-all;
    padding-bottom: var(--space-sm);
}

.terminal-comment {
    color: #6a9955;
    font-style: italic;
}

.terminal-string {
    color: #ce9178;
}

.terminal-keyword {
    color: #c586c0;
}

.terminal-builtin {
    color: #dcdcaa;
}

.terminal-number {
    color: #b5cea8;
}

.terminal-error {
    color: #f14c4c;
    font-weight: bold;
}

.terminal-default {
    color: #d4d4d4;
}

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

.status-ready {
    background: var(--success);
    box-shadow: 0 0 8px rgba(63, 185, 80, 0.4);
}

.status-busy {
    background: var(--warning);
    box-shadow: 0 0 8px rgba(210, 153, 34, 0.4);
    animation: pulse 1.2s ease-in-out infinite;
}

.status-error {
    background: var(--error);
    box-shadow: 0 0 8px rgba(248, 81, 73, 0.4);
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.4;
    }
}

/* --- Coordinate Inputs --- */
.coord-inputs {
    display: flex;
    gap: var(--space-sm);
    flex: 1;
}

.input-number {
    width: 100%;
    background: var(--surface-bg);
    border: 1px solid var(--input-border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    padding: var(--space-xs) var(--space-sm);
    font-family: var(--font-mono);
    font-size: 13px;
    text-align: right;
    transition: all var(--duration-fast);
}

.input-number:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 2px rgba(88, 166, 255, 0.2);
}

.input-number:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* --- Processing Overlay --- */
.processing-overlay {
    position: fixed;
    inset: 0;
    z-index: 500;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: rgba(13, 17, 23, 0.65);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    gap: var(--space-md);
}

.processing-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(88, 166, 255, 0.15);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.processing-text {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
}

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

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

.app:not(.hidden) {
    animation: fadeIn var(--duration-slow) var(--ease-out);
}

/* --- Responsive --- */
@media (max-width: 900px) {
    .main-layout {
        flex-direction: column;
    }

    .controls {
        width: 100%;
        flex-direction: row;
        flex-wrap: wrap;
        overflow-x: auto;
        overflow-y: hidden;
        max-height: 220px;
        border-right: none;
        border-bottom: 1px solid var(--surface-glass-border);
    }

    .control-section {
        min-width: 200px;
        flex: 1;
    }

    .viz-grid {
        grid-template-columns: 1fr;
        grid-template-rows: repeat(4, 1fr);
    }

    .tagline {
        display: none;
    }
}