/* ═══════════════════════════════════════════════════
   TrioLingo — Design System & Component Styles
   CyberChef meets hacker aesthetic
   ═══════════════════════════════════════════════════ */

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

:root {
    --bg-primary: #000000;
    --bg-secondary: #08080f;
    --bg-surface: #0e0e1a;
    --bg-editor: #050508;
    --bg-hover: #141422;

    --accent-neon-purple: #8A00C4;

    --accent-cyan: #00d4ff;
    --accent-purple: #a855f7;
    --accent-pink: #e94560;
    --accent-green: #22c55e;
    --accent-amber: #f59e0b;
    --accent-yellow: #ffd700;

    --text-primary: #e4e4ef;
    --text-secondary: #6b6b8a;
    --text-mono: #c0caf5;

    --border-subtle: #1c1c30;
    --border-active: rgba(0, 212, 255, 0.3);

    --glass-bg: rgba(14, 14, 24, 0.85);
    --glass-border: rgba(0, 212, 255, 0.12);

    --glow-cyan: 0 0 24px rgba(0, 212, 255, 0.12);
    --glow-purple: 0 0 24px rgba(168, 85, 247, 0.12);
    --glow-yellow: 0 0 24px rgba(255, 215, 0, 0.12);
    --shadow-card: 0 4px 32px rgba(0, 0, 0, 0.5);

    --sidebar-width: 280px;
    --navbar-height: 52px;
    --radius: 10px;
    --radius-sm: 6px;

    --font-ui: 'Inter', system-ui, -apple-system, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;

    --transition: 180ms cubic-bezier(0.4, 0, 0.2, 1);
}

html, body {
    height: 100%;
    font-family: var(--font-ui);
    background: var(--bg-primary);
    color: var(--text-primary);
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
}

/* ── Scrollbars ── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-subtle); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-secondary); }

/* ── Glass Card ── */
.glass-card {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
}

/* ═══ NAVBAR ═══ */
#navbar {
    height: var(--navbar-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-subtle);
    z-index: 100;
    position: relative;
}
.nav-left, .nav-right { display: flex; align-items: center; gap: 10px; }
.nav-center { flex: 1; max-width: 400px; margin: 0 24px; }

.logo {
    font-size: 1.05rem;
    letter-spacing: -0.02em;
    color: var(--accent-cyan);
}
.logo strong { color: var(--text-primary); }
.version-badge {
    font-size: 0.65rem;
    padding: 2px 6px;
    border-radius: 4px;
    background: var(--accent-purple);
    color: #fff;
    font-weight: 600;
}

/* Search */
.search-box {
    position: relative;
    width: 100%;
}
.search-icon {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    color: var(--text-secondary);
    pointer-events: none;
}
#searchInput {
    width: 100%;
    padding: 7px 12px 7px 34px;
    background: var(--bg-primary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 0.8rem;
    outline: none;
    transition: border-color var(--transition);
}
#searchInput:focus { border-color: var(--accent-cyan); box-shadow: var(--glow-cyan); }
#searchInput::placeholder { color: var(--text-secondary); }

.search-results {
    position: absolute;
    top: calc(100% + 4px);
    left: 0; right: 0;
    background: var(--bg-surface);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-sm);
    max-height: 320px;
    overflow-y: auto;
    z-index: 200;
    box-shadow: var(--shadow-card);
}
.search-results.hidden { display: none; }
.search-result-item {
    padding: 8px 12px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.82rem;
    transition: background var(--transition);
}
.search-result-item:hover { background: var(--bg-hover); }
.search-result-item .sr-key { color: var(--accent-cyan); font-family: var(--font-mono); font-size: 0.78rem; }
.search-result-item .sr-cat { color: var(--text-secondary); font-size: 0.7rem; }

/* Nav buttons */
.nav-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    border: none;
    border-radius: var(--radius-sm);
    font-family: var(--font-ui);
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    text-decoration: none;
}
.nav-btn svg { width: 16px; height: 16px; }
.accent-btn { background: var(--accent-cyan); color: #000; }
.accent-btn:hover { background: #33ddff; box-shadow: var(--glow-cyan); }
.ghost-btn { background: transparent; color: var(--text-secondary); }
.ghost-btn:hover { color: var(--text-primary); background: var(--bg-hover); }

/* ═══ LAYOUT ═══ */
#app {
    display: flex;
    height: calc(100vh - var(--navbar-height));
}

/* ═══ SIDEBAR ═══ */
#sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-subtle);
    overflow-y: auto;
    padding: 8px 0;
}
.category-group { margin-bottom: 2px; }
.category-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 14px;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-secondary);
    cursor: pointer;
    user-select: none;
    transition: color var(--transition);
}
.category-header:hover { color: var(--text-primary); }
.category-header .cat-count {
    font-size: 0.65rem;
    background: var(--bg-hover);
    padding: 1px 5px;
    border-radius: 3px;
    font-weight: 500;
}
.category-header .cat-chevron {
    transition: transform var(--transition);
    font-size: 0.65rem;
    color: var(--text-secondary);
}
.category-header.collapsed .cat-chevron { transform: rotate(-90deg); }
.category-items { overflow: hidden; }
.category-items.collapsed { display: none; }

.transform-item {
    display: flex;
    align-items: center;
    padding: 6px 14px 6px 20px;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all var(--transition);
    gap: 8px;
    border-left: 2px solid transparent;
}
.transform-item:hover {
    background: var(--bg-hover);
    border-left-color: var(--accent-cyan);
}
.transform-item.active {
    background: rgba(0, 212, 255, 0.08);
    border-left-color: var(--accent-cyan);
    color: var(--accent-cyan);
}
.transform-item .t-rev {
    font-size: 0.7rem;
    color: var(--text-secondary);
    width: 14px;
    text-align: center;
}
.transform-item .t-name {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.transform-item .t-add {
    opacity: 0;
    color: var(--accent-purple);
    font-size: 0.75rem;
    font-weight: 700;
    transition: opacity var(--transition);
}
.transform-item:hover .t-add { opacity: 1; }

/* ═══ WORKSPACE ═══ */
#workspace {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 10px;
    overflow-y: auto;
    min-width: 0;
}

/* ═══ PIPELINE BUILDER ═══ */
#pipelineBuilder {
    padding: 10px 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex-shrink: 0;
    border: 1.5px solid var(--accent-neon-purple);
}
#pipelineBuilder .section-label {
    color: var(--accent-neon-purple);
}
.pipeline-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.section-label {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-secondary);
}
.pipeline-actions { display: flex; gap: 6px; }

.pill-btn {
    padding: 4px 12px;
    border: 1px solid var(--border-subtle);
    border-radius: 20px;
    background: transparent;
    color: var(--text-secondary);
    font-family: var(--font-ui);
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
}
.pill-btn:hover { color: var(--text-primary); border-color: var(--text-secondary); }
.pill-btn.accent { border-color: var(--accent-cyan); color: var(--accent-cyan); }
.pill-btn.accent:hover { background: var(--accent-cyan); color: #000; }
.pill-btn.danger:hover { border-color: var(--accent-pink); color: var(--accent-pink); }

.pipeline-chips {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    min-height: 32px;
}
.pipeline-placeholder {
    color: var(--text-secondary);
    font-size: 0.78rem;
    font-style: italic;
}
.pipeline-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    background: rgba(168, 85, 247, 0.15);
    border: 1px solid rgba(168, 85, 247, 0.3);
    border-radius: 16px;
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--accent-purple);
    cursor: grab;
    user-select: none;
    animation: chipIn 0.2s ease-out;
}
@keyframes chipIn { from { transform: scale(0.8); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.pipeline-chip .chip-remove {
    cursor: pointer;
    opacity: 0.5;
    font-size: 0.7rem;
    transition: opacity var(--transition);
}
.pipeline-chip .chip-remove:hover { opacity: 1; color: var(--accent-pink); }
.pipeline-arrow {
    color: var(--text-secondary);
    font-size: 0.75rem;
    user-select: none;
}

/* ═══ EDITOR PANELS ═══ */
#editorPanels {
    display: flex;
    gap: 10px;
    flex: 1;
    min-height: 0;
}
.editor-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    position: relative;
    border-radius: var(--radius);
    overflow: hidden;
}

/* ── Input Panel: Electric Blue Glow ── */
.editor-panel.input-panel {
    border: 1.5px solid rgba(0, 212, 255, 0.5);
    box-shadow:
        0 0 8px rgba(0, 212, 255, 0.15),
        0 0 24px rgba(0, 212, 255, 0.08),
        0 0 60px rgba(0, 212, 255, 0.04),
        inset 0 0 30px rgba(0, 212, 255, 0.03);
    animation: inputHaze 4s ease-in-out infinite;
}
.editor-panel.input-panel .panel-header {
    border-bottom: 1px solid rgba(0, 212, 255, 0.15);
}
.editor-panel.input-panel .panel-label {
    color: var(--accent-cyan);
}
.editor-panel.input-panel .panel-status {
    border-top: 1px solid rgba(0, 212, 255, 0.1);
}
@keyframes inputHaze {
    0%, 100% {
        box-shadow:
            0 0 8px rgba(0, 212, 255, 0.15),
            0 0 24px rgba(0, 212, 255, 0.08),
            0 0 60px rgba(0, 212, 255, 0.04),
            inset 0 0 30px rgba(0, 212, 255, 0.03);
        border-color: rgba(0, 212, 255, 0.5);
    }
    50% {
        box-shadow:
            0 0 12px rgba(0, 212, 255, 0.25),
            0 0 36px rgba(0, 212, 255, 0.12),
            0 0 80px rgba(0, 212, 255, 0.06),
            inset 0 0 40px rgba(0, 212, 255, 0.04);
        border-color: rgba(0, 212, 255, 0.7);
    }
}

/* ── Output Panel: Electric Yellow Glow ── */
.editor-panel.output-panel {
    border: 1.5px solid rgba(255, 215, 0, 0.45);
    box-shadow:
        0 0 8px rgba(255, 215, 0, 0.12),
        0 0 24px rgba(255, 215, 0, 0.07),
        0 0 60px rgba(255, 215, 0, 0.03),
        inset 0 0 30px rgba(255, 215, 0, 0.02);
    animation: outputHaze 4s ease-in-out infinite;
    animation-delay: 2s;
}
.editor-panel.output-panel .panel-header {
    border-bottom: 1px solid rgba(255, 215, 0, 0.12);
}
.editor-panel.output-panel .panel-label {
    color: var(--accent-yellow);
}
.editor-panel.output-panel .panel-status {
    border-top: 1px solid rgba(255, 215, 0, 0.08);
}
@keyframes outputHaze {
    0%, 100% {
        box-shadow:
            0 0 8px rgba(255, 215, 0, 0.12),
            0 0 24px rgba(255, 215, 0, 0.07),
            0 0 60px rgba(255, 215, 0, 0.03),
            inset 0 0 30px rgba(255, 215, 0, 0.02);
        border-color: rgba(255, 215, 0, 0.45);
    }
    50% {
        box-shadow:
            0 0 12px rgba(255, 215, 0, 0.22),
            0 0 36px rgba(255, 215, 0, 0.1),
            0 0 80px rgba(255, 215, 0, 0.05),
            inset 0 0 40px rgba(255, 215, 0, 0.03);
        border-color: rgba(255, 215, 0, 0.65);
    }
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border-subtle);
}
.panel-label {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-secondary);
}
.panel-actions { display: flex; gap: 4px; }

.icon-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px;
    font-size: 0.85rem;
    border-radius: 4px;
    transition: all var(--transition);
}
.icon-btn:hover { color: var(--text-primary); background: var(--bg-hover); }

#inputText, #outputText {
    flex: 1;
    width: 100%;
    padding: 12px;
    background: var(--bg-editor);
    border: none;
    color: var(--text-mono);
    font-family: var(--font-mono);
    font-size: 0.85rem;
    line-height: 1.6;
    resize: none;
    outline: none;
}
#inputText::placeholder, #outputText::placeholder { color: var(--text-secondary); }

.panel-status {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 12px;
    font-size: 0.7rem;
    color: var(--text-secondary);
    border-top: 1px solid var(--border-subtle);
}
.file-drop-hint { color: var(--accent-purple); }

/* Action Column */
.action-column {
    display: flex;
    flex-direction: column;
    gap: 8px;
    justify-content: center;
    align-items: center;
    padding: 0 4px;
    flex-shrink: 0;
}
.action-btn {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border: 1px solid var(--border-subtle);
    background: var(--bg-surface);
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    transition: all var(--transition);
}
.action-btn svg { width: 20px; height: 20px; }
.encode-btn:hover { border-color: var(--accent-cyan); color: var(--accent-cyan); box-shadow: var(--glow-cyan); background: rgba(0, 212, 255, 0.08); }
.decode-btn:hover { border-color: var(--accent-purple); color: var(--accent-purple); box-shadow: var(--glow-purple); background: rgba(168, 85, 247, 0.08); }
.swap-btn:hover { border-color: var(--accent-amber); color: var(--accent-amber); }

/* ═══ PARAMETER PANEL ═══ */
#paramPanel {
    padding: 10px 14px;
    flex-shrink: 0;
}
#paramPanel.hidden { display: none; }
#paramControls {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    padding-top: 8px;
}
.param-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 160px;
}
.param-label {
    font-size: 0.72rem;
    color: var(--text-secondary);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.param-input, .param-select {
    padding: 6px 10px;
    background: var(--bg-editor);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 0.8rem;
    outline: none;
    transition: border-color var(--transition);
}
.param-input:focus, .param-select:focus { border-color: var(--accent-cyan); }
.param-select { cursor: pointer; }
.param-select option { background: var(--bg-surface); }

/* ═══ ANALYSIS DASHBOARD ═══ */
#analysisDashboard {
    flex-shrink: 0;
    padding: 10px;
    border: 1px solid rgba(0, 212, 255, 0.08);
}
.analysis-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 0 8px 0;
}
.analysis-header > div { display: flex; gap: 6px; align-items: center; }
.analysis-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 8px;
}
.analysis-card {
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    transition: border-color var(--transition);
}
.analysis-card:hover { border-color: var(--accent-cyan); }
.card-header {
    font-size: 0.78rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 6px;
}
.card-icon { font-size: 1rem; }
.risk-badge, .entropy-value {
    font-family: var(--font-mono);
    font-size: 0.85rem;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 4px;
    display: inline-block;
    width: fit-content;
}
.risk-high { background: rgba(233, 69, 96, 0.2); color: var(--accent-pink); }
.risk-medium { background: rgba(245, 158, 11, 0.2); color: var(--accent-amber); }
.risk-low { background: rgba(34, 197, 94, 0.2); color: var(--accent-green); }
.risk-clean { background: rgba(34, 197, 94, 0.15); color: var(--accent-green); }
.card-body {
    font-size: 0.75rem;
    color: var(--text-secondary);
    line-height: 1.5;
    max-height: 100px;
    overflow-y: auto;
}

/* ═══ TOAST ═══ */
#toastContainer {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.toast {
    padding: 10px 16px;
    background: var(--bg-surface);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-sm);
    font-size: 0.82rem;
    color: var(--text-primary);
    box-shadow: var(--shadow-card);
    animation: toastIn 0.3s ease-out;
    max-width: 340px;
}
.toast.success { border-color: var(--accent-green); }
.toast.error { border-color: var(--accent-pink); }
@keyframes toastIn { from { transform: translateX(20px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ═══ LOADING STATE ═══ */
.loading-overlay {
    position: fixed;
    inset: 0;
    background: var(--bg-primary);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    gap: 16px;
}
.loading-overlay .spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-subtle);
    border-top-color: var(--accent-cyan);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-overlay .loading-text {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

/* ═══ DESKTOP: HIDE HAMBURGER ═══ */
.sidebar-toggle { display: none; }

/* ═══ SIDEBAR OVERLAY (mobile only) ═══ */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 299;
}
.sidebar-overlay.active { display: block; }

/* ═══ RESPONSIVE: TABLET (≤1024px) ═══ */
@media (max-width: 1024px) {
    :root { --sidebar-width: 240px; }
}

/* ═══ RESPONSIVE: MOBILE (≤768px) ═══ */
@media (max-width: 768px) {
    /* Show hamburger */
    .sidebar-toggle { display: flex; }

    /* Sidebar becomes off-canvas drawer */
    #sidebar {
        position: fixed;
        top: var(--navbar-height);
        left: 0;
        bottom: 0;
        width: 280px;
        z-index: 300;
        transform: translateX(-100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        border-right: 1px solid var(--border-subtle);
    }
    #sidebar.open {
        transform: translateX(0);
    }

    /* Stack everything vertically */
    #app {
        height: auto;
        min-height: calc(100vh - var(--navbar-height));
        overflow-y: auto;
    }
    #workspace {
        overflow-y: visible;
        min-height: auto;
    }

    /* Stack editor panels vertically */
    #editorPanels {
        flex-direction: column;
        flex: none;
        min-height: 0;
    }
    .editor-panel {
        flex: none;
        min-height: 200px;
    }
    #inputText, #outputText {
        min-height: 150px;
    }

    /* Horizontal action buttons */
    .action-column {
        flex-direction: row;
        padding: 4px 0;
    }

    /* Analysis grid single column on small screens */
    .analysis-grid {
        grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    }

    /* Navbar adjustments */
    .nav-center { display: none; }
    .nav-right .ghost-btn { display: none; }

    /* Pipeline compact */
    #pipelineBuilder { padding: 8px 10px; }
}

/* ═══ RESPONSIVE: SMALL PHONE (≤480px) ═══ */
@media (max-width: 480px) {
    #workspace { padding: 6px; gap: 6px; }

    .editor-panel {
        min-height: 160px;
    }

    .analysis-grid {
        grid-template-columns: 1fr 1fr;
        gap: 6px;
    }
    .analysis-card {
        padding: 8px;
    }

    .action-btn {
        width: 36px;
        height: 36px;
    }
    .action-btn svg { width: 16px; height: 16px; }

    .logo { font-size: 0.9rem; }
    .version-badge { display: none; }
}
