/* ── PipelineCalc Pro — Modern Dark Theme v2 ── */

:root {
    --bg-primary: #0f1117;
    --bg-secondary: #161922;
    --bg-card: #1c1f2e;
    --bg-card-hover: #232740;
    --bg-input: #232740;
    --border: #2a2e45;
    --border-focus: #4f7df9;
    --text-primary: #e8eaf0;
    --text-secondary: #8a8fa8;
    --text-muted: #5c6178;
    --accent: #4f7df9;
    --accent-hover: #6b93ff;
    --accent-glow: rgba(79, 125, 249, .25);
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --premium: #a855f7;
    --enterprise: #f59e0b;
    --radius: 12px;
    --radius-sm: 8px;
    --radius-lg: 18px;
    --shadow: 0 4px 24px rgba(0, 0, 0, .35);
    --transition: .2s ease;
}

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

html { scroll-behavior: smooth; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    margin: 0;
    min-height: 100vh;
}

/* ── Typography ── */
h1, h2, h3, h4, h5, h6 { font-weight: 700; letter-spacing: -.02em; }
a { color: var(--accent); text-decoration: none; transition: color var(--transition); }
a:hover { color: var(--accent-hover); }

/* ── Top Nav ── */
.top-nav {
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    height: 56px;
    background: rgba(15, 17, 23, .85);
    backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--border);
}
.top-nav .brand {
    font-size: 1.15rem;
    font-weight: 800;
    background: linear-gradient(135deg, var(--accent), #a855f7);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}
.top-nav .nav-links { display: flex; align-items: center; gap: 8px; }

/* ── Buttons ── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 18px;
    font-size: .875rem;
    font-weight: 600;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition);
    text-decoration: none;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); box-shadow: 0 0 20px var(--accent-glow); color: #fff; }
.btn-ghost { background: transparent; color: var(--text-secondary); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--bg-card); color: var(--text-primary); border-color: var(--text-muted); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #0da574; color: #fff; }
.btn-warning { background: var(--warning); color: #1a1a2e; }
.btn-warning:hover { background: #e08e0a; color: #1a1a2e; }
.btn-danger { background: var(--danger); color: #fff; padding: 6px 14px; }
.btn-danger:hover { background: #d33; color: #fff; }
.btn-premium { background: linear-gradient(135deg, #a855f7, #6366f1); color: #fff; }
.btn-premium:hover { box-shadow: 0 0 24px rgba(168, 85, 247, .4); color: #fff; }
.btn-sm { padding: 6px 14px; font-size: .8rem; }
.btn-lg { padding: 14px 32px; font-size: 1rem; }

/* ── Layout ── */
.container { max-width: 1200px; margin: 0 auto; padding: 0 20px; }
.page { padding: 32px 0 64px; }

/* ── Cards ── */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    transition: all var(--transition);
}
.card:hover { border-color: rgba(79, 125, 249, .3); }
.card-glow:hover { box-shadow: 0 0 30px var(--accent-glow); }

/* ── Forms ── */
.form-group { margin-bottom: 16px; }
.form-group label {
    display: block;
    margin-bottom: 6px;
    font-size: .8rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: .04em;
}
.form-control {
    width: 100%;
    padding: 10px 14px;
    font-size: .9rem;
    color: var(--text-primary);
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    outline: none;
    transition: border-color var(--transition), box-shadow var(--transition);
}
.form-control:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }
.form-control::placeholder { color: var(--text-muted); }

/* Override Django's default form rendering */
form p { margin-bottom: 14px; }
form p label {
    display: block;
    margin-bottom: 6px;
    font-size: .8rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: .04em;
}
form p input, form p select {
    width: 100%;
    padding: 10px 14px;
    font-size: .9rem;
    color: var(--text-primary);
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    outline: none;
    transition: border-color var(--transition), box-shadow var(--transition);
}
form p input:focus, form p select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }
form .helptext { display: block; font-size: .7rem; color: var(--text-muted); margin-top: 3px; }
form .errorlist { list-style: none; padding: 0; margin: 4px 0 0; }
form .errorlist li { font-size: .75rem; color: var(--danger); }

/* ── Tabs ── */
.tab-bar {
    display: flex;
    gap: 4px;
    padding: 4px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 24px;
    overflow-x: auto;
}
.tab-btn {
    flex: 1;
    min-width: max-content;
    padding: 10px 20px;
    font-size: .85rem;
    font-weight: 600;
    color: var(--text-secondary);
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition);
    text-align: center;
    white-space: nowrap;
}
.tab-btn:hover { color: var(--text-primary); background: var(--bg-card); }
.tab-btn.active { color: #fff; background: var(--accent); box-shadow: 0 2px 12px var(--accent-glow); }
.tab-btn .badge-lock {
    display: inline-block;
    font-size: .6rem;
    padding: 2px 6px;
    border-radius: 4px;
    margin-left: 6px;
    vertical-align: middle;
}
.badge-premium { background: rgba(168, 85, 247, .2); color: #c084fc; }
.badge-enterprise { background: rgba(245, 158, 11, .2); color: #fbbf24; }

.tab-pane { display: none; }
.tab-pane.active { display: block; animation: fadeIn .25s ease; }

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

/* ── Calculator Grid ── */
.calc-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
    gap: 20px;
}
.calc-card { position: relative; }
.calc-card h4 { font-size: 1rem; margin: 0 0 4px; }
.calc-card .calc-desc { font-size: .78rem; color: var(--text-muted); margin-bottom: 16px; }

/* ── Results ── */
.result-box {
    margin-top: 16px;
    padding: 14px 16px;
    background: rgba(16, 185, 129, .08);
    border: 1px solid rgba(16, 185, 129, .25);
    border-radius: var(--radius-sm);
}
.result-box .result-label {
    font-size: .7rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--success);
    margin-bottom: 4px;
}
.result-box .result-value { font-size: 1.35rem; font-weight: 700; color: var(--success); }
.result-box .result-detail { font-size: .8rem; color: var(--text-secondary); margin-top: 2px; }

.locked-overlay {
    padding: 20px;
    text-align: center;
    background: rgba(79, 125, 249, .05);
    border: 1px dashed var(--border);
    border-radius: var(--radius-sm);
    margin-top: 16px;
}
.locked-overlay .lock-icon { font-size: 1.5rem; margin-bottom: 8px; }
.locked-overlay p { font-size: .85rem; color: var(--text-secondary); margin: 0 0 12px; }

/* ── Hero ── */
.hero { text-align: center; padding: 80px 20px 60px; }
.hero h1 { font-size: 3rem; line-height: 1.1; margin-bottom: 20px; }
.hero h1 .gradient-text {
    background: linear-gradient(135deg, var(--accent), #a855f7, #ec4899);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}
.hero p {
    font-size: 1.15rem;
    color: var(--text-secondary);
    max-width: 600px;
    margin: 0 auto 32px;
    line-height: 1.6;
}

.features-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 20px;
    margin-top: 48px;
}
.feature-card { text-align: left; }
.feature-card .feature-icon {
    width: 44px; height: 44px;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.3rem; border-radius: 10px; margin-bottom: 14px;
}
.feature-card .icon-blue { background: rgba(79, 125, 249, .12); }
.feature-card .icon-purple { background: rgba(168, 85, 247, .12); }
.feature-card .icon-amber { background: rgba(245, 158, 11, .12); }
.feature-card .icon-green { background: rgba(16, 185, 129, .12); }
.feature-card h4 { font-size: .95rem; margin: 0 0 6px; }
.feature-card p { font-size: .82rem; color: var(--text-secondary); margin: 0; line-height: 1.5; }

/* ── Pricing ── */
.pricing-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 24px;
}
.pricing-card { text-align: center; position: relative; overflow: hidden; }
.pricing-card.popular { border-color: var(--accent); }
.pricing-card.popular::before {
    content: "MOST POPULAR";
    position: absolute; top: 14px; right: -30px;
    transform: rotate(45deg);
    background: var(--accent); color: #fff;
    font-size: .6rem; font-weight: 700;
    padding: 4px 40px; letter-spacing: .06em;
}
.pricing-card .price { font-size: 2.4rem; font-weight: 800; margin: 16px 0 4px; }
.pricing-card .price span { font-size: .9rem; font-weight: 400; color: var(--text-muted); }
.pricing-card .plan-name { font-size: 1.1rem; font-weight: 700; margin-bottom: 6px; }
.pricing-card .plan-desc { font-size: .82rem; color: var(--text-secondary); margin-bottom: 20px; }
.pricing-card ul { list-style: none; padding: 0; margin: 0 0 24px; text-align: left; }
.pricing-card ul li {
    padding: 7px 0; font-size: .82rem; color: var(--text-secondary);
    border-bottom: 1px solid var(--border);
}
.pricing-card ul li::before { content: "✓ "; color: var(--success); font-weight: 700; }
.pricing-card .current-badge {
    display: inline-block; padding: 4px 12px;
    font-size: .7rem; font-weight: 700; border-radius: 20px;
    background: rgba(16, 185, 129, .15); color: var(--success);
    margin-bottom: 12px;
}

/* ── Profile ── */
.profile-header { display: flex; align-items: center; gap: 20px; margin-bottom: 32px; }
.profile-avatar {
    width: 72px; height: 72px; border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), #a855f7);
    display: flex; align-items: center; justify-content: center;
    font-size: 1.6rem; font-weight: 700; color: #fff;
}
.profile-info h2 { margin: 0 0 4px; font-size: 1.3rem; }
.profile-info p { margin: 0; font-size: .85rem; color: var(--text-secondary); }
.tier-badge {
    display: inline-block; padding: 3px 10px;
    font-size: .7rem; font-weight: 700; border-radius: 20px;
    text-transform: uppercase; letter-spacing: .04em;
}
.tier-free { background: rgba(79, 125, 249, .12); color: var(--accent); }
.tier-premium { background: rgba(168, 85, 247, .12); color: #c084fc; }
.tier-enterprise { background: rgba(245, 158, 11, .12); color: #fbbf24; }

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
}
.stat-card { text-align: center; }
.stat-card .stat-value { font-size: 1.5rem; font-weight: 800; }
.stat-card .stat-label { font-size: .75rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }

/* ── Alerts ── */
.alert { padding: 14px 18px; border-radius: var(--radius-sm); font-size: .85rem; margin-bottom: 16px; }
.alert-info { background: rgba(79, 125, 249, .1); border: 1px solid rgba(79, 125, 249, .25); color: var(--accent); }
.alert-success { background: rgba(16, 185, 129, .1); border: 1px solid rgba(16, 185, 129, .25); color: var(--success); }
.alert-warning { background: rgba(245, 158, 11, .1); border: 1px solid rgba(245, 158, 11, .25); color: var(--warning); }
.alert-danger { background: rgba(239, 68, 68, .1); border: 1px solid rgba(239, 68, 68, .25); color: var(--danger); }

/* ── Auth pages ── */
.auth-page {
    display: flex; align-items: center; justify-content: center;
    min-height: calc(100vh - 56px); padding: 40px 20px;
}
.auth-box { width: 100%; max-width: 440px; }
.auth-box h2 { text-align: center; margin-bottom: 6px; }
.auth-box .auth-subtitle {
    text-align: center; font-size: .88rem; color: var(--text-secondary); margin-bottom: 28px;
}

/* ── Dashboard header ── */
.dash-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 24px; flex-wrap: wrap; gap: 12px;
}
.dash-header h1 { font-size: 1.5rem; margin: 0; }
.dash-header .tier-info { font-size: .8rem; color: var(--text-muted); }

/* ── Utilities ── */
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mb-2 { margin-bottom: 16px; }
.mb-3 { margin-bottom: 24px; }
.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }

/* ── Responsive ── */
@media (max-width: 768px) {
    .hero h1 { font-size: 2rem; }
    .calc-grid { grid-template-columns: 1fr; }
    .pricing-grid { grid-template-columns: 1fr; }
    .tab-bar { flex-wrap: nowrap; }
    .tab-btn { font-size: .78rem; padding: 8px 14px; }
    .sim-card-wide { grid-column: span 1; }
    .visual-wide svg { min-height: 140px; }
}

/* ── Project Grid ── */
.project-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 20px;
}
.project-card { position: relative; }

/* ── SVG Visual Boxes ── */
.visual-box {
    margin-top: 14px;
    padding: 12px;
    background: rgba(15, 17, 23, .5);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
}
.visual-box svg { width: 100%; height: auto; }
.visual-wide svg { min-height: 160px; }

/* Simulator wide cards span 2 columns */
.sim-card-wide { grid-column: span 2; }

/* ── SVG Animations ── */
.pulse-dot {
    animation: pulseDot 2s ease-in-out infinite;
}
@keyframes pulseDot {
    0%, 100% { r: 4; opacity: 1; }
    50% { r: 7; opacity: .5; }
}

.arrow-pulse { animation: arrowSlide 2s ease-in-out infinite; }
.arrow-pulse-2 { animation: arrowSlide 2s ease-in-out .3s infinite; }
.arrow-pulse-3 { animation: arrowSlide 2s ease-in-out .6s infinite; }
@keyframes arrowSlide {
    0%, 100% { opacity: .3; transform: translateX(0); }
    50% { opacity: .9; transform: translateX(4px); }
}

.pig-animate {
    animation: pigMove 3s ease-in-out infinite;
}
@keyframes pigMove {
    0%, 100% { transform: translateX(0); }
    50% { transform: translateX(12px); }
}

.pig-fitting-animate {
    animation: pigApproach 3s ease-in-out infinite;
}
@keyframes pigApproach {
    0%, 100% { transform: translateX(0); }
    50% { transform: translateX(20px); }
}

.disc-bend-1 {
    animation: discBend 2.5s ease-in-out infinite;
}
.disc-bend-2 {
    animation: discBend 2.5s ease-in-out .4s infinite;
}
@keyframes discBend {
    0%, 100% { rx: 6; }
    50% { rx: 10; }
}

.friction-heat {
    animation: heatPulse 1s ease-in-out infinite;
}
@keyframes heatPulse {
    0%, 100% { opacity: .3; }
    50% { opacity: .8; }
}

.turbulent-path {
    animation: turbulence 4s linear infinite;
    stroke-dasharray: 8 4;
    stroke-dashoffset: 0;
}
.turbulent-path-2 {
    animation: turbulence 4s linear .5s infinite;
    stroke-dasharray: 8 4;
}
@keyframes turbulence {
    to { stroke-dashoffset: -48; }
}

.batch-interface {
    animation: batchPulse 2s ease-in-out infinite;
}
@keyframes batchPulse {
    0%, 100% { opacity: .5; }
    50% { opacity: 1; }
}

/* ── Risk-level result colours ── */
.result-low { color: var(--success) !important; }
.result-medium { color: var(--warning) !important; }
.result-high { color: var(--danger) !important; }
.result-critical { color: #ff3333 !important; font-weight: 800; }

/* ── Save-to-Project Modal ── */
.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 200;
    background: rgba(0, 0, 0, .6);
    backdrop-filter: blur(6px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.modal-box {
    width: 100%;
    max-width: 480px;
    animation: fadeIn .2s ease;
}
.modal-box textarea {
    width: 100%;
    padding: 10px 14px;
    font-size: .9rem;
    font-family: inherit;
    color: var(--text-primary);
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    outline: none;
    resize: vertical;
    transition: border-color var(--transition);
}
.modal-box textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

/* ══════════════════════════════════════════════════════════════════════════
   PIPE CONFIGURATION BAR
   ══════════════════════════════════════════════════════════════════════════ */
.pipe-config-bar {
    margin-bottom: 20px;
    padding: 16px 20px;
    border: 1px solid var(--accent);
    border-image: linear-gradient(135deg, var(--accent), #a855f7) 1;
    background: linear-gradient(135deg, rgba(79,125,249,.06), rgba(168,85,247,.04));
}
.pipe-config-row {
    display: flex;
    align-items: center;
    gap: 20px;
    flex-wrap: wrap;
}
.pipe-field { flex: 0 0 180px; }
.pipe-field label {
    display: block;
    font-size: .7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--accent);
    margin-bottom: 5px;
}
.pipe-field select {
    width: 100%;
    padding: 8px 12px;
    font-size: .85rem;
    color: var(--text-primary);
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    outline: none;
    cursor: pointer;
}
.pipe-field select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }
.pipe-field select:disabled { opacity: .5; cursor: not-allowed; }

.pipe-readouts {
    display: flex;
    gap: 16px;
    flex: 1;
    min-width: 0;
}
.readout {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 65px;
}
.readout-label {
    font-size: .65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--text-muted);
    margin-bottom: 3px;
}
.readout-value {
    font-size: .95rem;
    font-weight: 700;
    color: var(--success);
    white-space: nowrap;
}

.pipe-mini-svg {
    flex: 0 0 70px;
    height: 70px;
}
.pipe-mini-svg svg { width: 70px; height: 70px; }

/* ══════════════════════════════════════════════════════════════════════════
   CATEGORY BAR (static tabs row 1)
   ══════════════════════════════════════════════════════════════════════════ */
.category-bar {
    display: flex;
    gap: 4px;
    padding: 4px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 16px;
}
.cat-btn {
    flex: 1;
    min-width: max-content;
    padding: 10px 20px;
    font-size: .85rem;
    font-weight: 600;
    color: var(--text-secondary);
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition);
    text-align: center;
    white-space: nowrap;
}
.cat-btn:hover { color: var(--text-primary); background: var(--bg-card); }
.cat-btn.active { color: #fff; background: var(--accent); box-shadow: 0 2px 12px var(--accent-glow); }

/* ══════════════════════════════════════════════════════════════════════════
   LAUNCHER GRID (calculator cards you click to open)
   ══════════════════════════════════════════════════════════════════════════ */
.launcher-pane { display: none; }
.launcher-pane.active { display: block; animation: fadeIn .25s ease; }

.launcher-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 12px;
    margin-bottom: 20px;
}
.launcher-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 18px 14px;
    cursor: pointer;
    border: 1px solid var(--border);
    background: var(--bg-card);
    position: relative;
    transition: all var(--transition);
}
.launcher-card:hover {
    border-color: var(--accent);
    background: var(--bg-card-hover);
    transform: translateY(-2px);
    box-shadow: 0 6px 24px rgba(0,0,0,.3);
}
.launcher-icon { font-size: 1.6rem; margin-bottom: 8px; }
.launcher-label { font-size: .88rem; font-weight: 700; color: var(--text-primary); margin-bottom: 4px; }
.launcher-desc { font-size: .72rem; color: var(--text-muted); line-height: 1.4; }
.launcher-lock {
    position: absolute;
    top: 8px;
    right: 8px;
    font-size: .6rem;
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: 700;
}

/* ══════════════════════════════════════════════════════════════════════════
   DYNAMIC TAB BAR (row 2 — browser-like tabs)
   ══════════════════════════════════════════════════════════════════════════ */
.dyn-tab-bar {
    display: flex;
    gap: 2px;
    padding: 3px 4px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius) var(--radius) 0 0;
    overflow-x: auto;
    margin-bottom: 0;
}
.dyn-tab {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    font-size: .8rem;
    font-weight: 600;
    color: var(--text-muted);
    background: transparent;
    border: none;
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
    cursor: pointer;
    white-space: nowrap;
    transition: all var(--transition);
    max-width: 200px;
}
.dyn-tab:hover { color: var(--text-primary); background: var(--bg-card); }
.dyn-tab.active {
    color: var(--text-primary);
    background: var(--bg-card);
    border-bottom: 2px solid var(--accent);
}
.dyn-tab-launcher {
    color: var(--accent);
    font-weight: 700;
    font-size: .82rem;
    border-right: 1px solid var(--border);
    margin-right: 4px;
    padding-right: 16px;
    flex-shrink: 0;
}
.dyn-tab-launcher:hover { color: var(--accent-hover); background: rgba(79,125,249,.08); }
.dyn-tab-launcher.active { color: var(--accent); background: rgba(79,125,249,.12); border-bottom: 2px solid var(--accent); }
.dyn-tab-label { overflow: hidden; text-overflow: ellipsis; }
.dyn-tab-close {
    font-size: .65rem;
    opacity: .4;
    padding: 2px 4px;
    border-radius: 3px;
    transition: all var(--transition);
}
.dyn-tab-close:hover { opacity: 1; background: var(--danger); color: #fff; }

/* ══════════════════════════════════════════════════════════════════════════
   DYNAMIC PANELS (calculator form + results side by side)
   ══════════════════════════════════════════════════════════════════════════ */
.dyn-panel {
    display: none;
    border: 1px solid var(--border);
    border-top: none;
    border-radius: 0 0 var(--radius) var(--radius);
    background: var(--bg-card);
    animation: fadeIn .2s ease;
    margin-bottom: 20px;
}
.dyn-panel.active { display: block; }

.calc-panel-layout {
    display: grid;
    grid-template-columns: 1fr 1.2fr;
    min-height: 300px;
}
.calc-form-side {
    padding: 24px;
    border-right: 1px solid var(--border);
}
.calc-result-side {
    padding: 24px;
    overflow-y: auto;
}
.calc-form-actions {
    display: flex;
    gap: 8px;
    margin-top: 18px;
    align-items: center;
}

/* Empty state */
.empty-result {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    min-height: 200px;
    color: var(--text-muted);
}
.empty-icon { font-size: 2.5rem; margin-bottom: 12px; opacity: .5; }
.empty-result p { font-size: .88rem; }

/* Loading state */
.calc-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 200px;
    color: var(--text-muted);
}
.spinner {
    width: 32px; height: 32px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin .6s linear infinite;
    margin-bottom: 12px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Auto-filled highlight */
@keyframes autofillPulse {
    0%   { box-shadow: 0 0 0 0 rgba(16,185,129,.5); }
    50%  { box-shadow: 0 0 0 4px rgba(16,185,129,.25); }
    100% { box-shadow: 0 0 0 0 rgba(16,185,129,0); }
}
.autofilled {
    animation: autofillPulse .8s ease;
    border-color: var(--success) !important;
}

/* ══════════════════════════════════════════════════════════════════════════
   RESPONSIVE — Dynamic panels stack on mobile
   ══════════════════════════════════════════════════════════════════════════ */
@media (max-width: 900px) {
    .calc-panel-layout {
        grid-template-columns: 1fr;
    }
    .calc-form-side { border-right: none; border-bottom: 1px solid var(--border); }
    .pipe-config-row { flex-direction: column; align-items: stretch; }
    .pipe-field { flex: 1 1 100%; }
    .pipe-readouts { flex-wrap: wrap; justify-content: center; }
    .launcher-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
}

/* ══════════════════════════════════════════════════════════════════════════
   PROJECT CANVAS
   ══════════════════════════════════════════════════════════════════════════ */
.canvas-chrome {
    position: fixed;
    inset: 56px 0 0 0;  /* below top-nav */
    display: flex;
    flex-direction: column;
    background: var(--bg-primary);
    overflow: hidden;
}

.canvas-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    z-index: 10;
    gap: 12px;
}
.canvas-toolbar-left, .canvas-toolbar-center, .canvas-toolbar-right {
    display: flex;
    align-items: center;
    gap: 8px;
}
.canvas-title {
    font-size: 1rem;
    font-weight: 700;
    margin: 0;
    white-space: nowrap;
}
.canvas-zoom-label {
    font-size: .75rem;
    color: var(--text-muted);
    font-weight: 600;
    min-width: 40px;
    text-align: center;
}

/* Viewport */
.canvas-viewport {
    flex: 1;
    position: relative;
    overflow: hidden;
    cursor: default;
    background:
        radial-gradient(circle at 1px 1px, rgba(79,125,249,.08) 1px, transparent 0);
    background-size: 30px 30px;
}

.canvas-world {
    position: absolute;
    top: 0;
    left: 0;
    width: 0;
    height: 0;
}

.canvas-links-svg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 5;
    overflow: visible;
}
.canvas-link-path {
    fill: none;
    stroke: var(--accent);
    stroke-width: 2.5;
    stroke-dasharray: 8 4;
    pointer-events: stroke;
    cursor: pointer;
    transition: stroke var(--transition);
    animation: linkDash 1.5s linear infinite;
}
.canvas-link-path:hover {
    stroke: var(--danger);
    stroke-width: 3;
}
@keyframes linkDash {
    to { stroke-dashoffset: -24; }
}
.canvas-link-dot {
    fill: var(--accent);
    pointer-events: none;
}

/* ── Canvas Card ── */
.canvas-card {
    position: absolute;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 4px 20px rgba(0,0,0,.3);
    min-width: 280px;
    max-width: 400px;
    z-index: 6;
    transition: box-shadow var(--transition);
}
.canvas-card:hover {
    box-shadow: 0 6px 30px rgba(0,0,0,.45);
    border-color: rgba(79,125,249,.4);
}
.canvas-card.dragging {
    box-shadow: 0 12px 40px rgba(0,0,0,.5);
    z-index: 20;
    opacity: .92;
}
.canvas-card.collapsed .cv-body { display: none; }

.cv-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    background: linear-gradient(135deg, rgba(79,125,249,.08), rgba(168,85,247,.05));
    border-bottom: 1px solid var(--border);
    border-radius: var(--radius) var(--radius) 0 0;
    cursor: grab;
    user-select: none;
}
.cv-header:active { cursor: grabbing; }
.cv-icon { font-size: 1.1rem; }
.cv-title { font-size: .85rem; font-weight: 700; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cv-header-actions { display: flex; gap: 4px; }
.cv-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: .75rem;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 4px;
    transition: all var(--transition);
}
.cv-btn:hover { color: var(--text-primary); background: rgba(255,255,255,.08); }
.cv-delete-btn:hover { color: var(--danger); background: rgba(239,68,68,.1); }

.cv-body { padding: 12px 14px; }

.cv-section-label {
    font-size: .6rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.cv-field { margin-bottom: 8px; }
.cv-field label {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: .7rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 3px;
}
.cv-field-row {
    display: flex;
    align-items: center;
    gap: 4px;
}
.cv-field-row .form-control-sm {
    padding: 6px 10px;
    font-size: .8rem;
    flex: 1;
}
.linked-field .form-control-sm {
    border-color: var(--accent);
    background: rgba(79,125,249,.06);
}
.link-badge {
    font-size: .65rem;
    opacity: .7;
}

/* Ports */
.cv-port {
    display: none;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    font-size: .55rem;
    border-radius: 50%;
    border: 2px solid var(--border);
    background: var(--bg-card);
    cursor: crosshair;
    flex-shrink: 0;
    transition: all var(--transition);
}
.cv-port.visible {
    display: flex;
}
.cv-port:hover {
    border-color: var(--accent);
    background: rgba(79,125,249,.15);
    transform: scale(1.2);
}
.cv-port.selected {
    border-color: var(--success);
    background: rgba(16,185,129,.2);
    animation: portPulse 1s ease infinite;
}
.cv-port-in { color: var(--accent); }
.cv-port-out { color: var(--success); }

@keyframes portPulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(16,185,129,.4); }
    50% { box-shadow: 0 0 0 6px rgba(16,185,129,0); }
}

.cv-actions {
    margin: 10px 0;
    display: flex;
    gap: 6px;
}

.cv-results-section { margin-top: 8px; border-top: 1px solid var(--border); padding-top: 10px; }

.cv-result-row {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 0;
    font-size: .78rem;
}
.cv-result-label { color: var(--text-muted); flex: 1; }
.cv-result-value { color: var(--success); font-weight: 700; }
.cv-empty-results {
    text-align: center;
    padding: 12px;
    color: var(--text-muted);
    font-size: .8rem;
}

/* ── Add Card Drawer ── */
.drawer-backdrop {
    position: fixed;
    inset: 0;
    z-index: 300;
    background: rgba(0,0,0,.5);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.drawer-panel {
    width: 100%;
    max-width: 480px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.drawer-search { margin-bottom: 12px; }
.drawer-list {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.drawer-group-label {
    font-size: .7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--text-muted);
    padding: 10px 4px 4px;
}
.drawer-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    background: var(--bg-secondary);
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    cursor: pointer;
    text-align: left;
    transition: all var(--transition);
    color: var(--text-primary);
}
.drawer-item:hover {
    border-color: var(--accent);
    background: rgba(79,125,249,.06);
}
.drawer-item-icon { font-size: 1.3rem; flex-shrink: 0; }
.drawer-item-info { display: flex; flex-direction: column; }
.drawer-item-label { font-size: .88rem; font-weight: 700; }
.drawer-item-desc { font-size: .72rem; color: var(--text-muted); }

/* ── Link Mode Bar ── */
.link-mode-bar {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 50;
    background: var(--bg-card);
    border: 1px solid var(--accent);
    border-radius: var(--radius);
    padding: 10px 20px;
    display: flex;
    align-items: center;
    gap: 16px;
    box-shadow: 0 8px 30px rgba(0,0,0,.4);
    font-size: .85rem;
    color: var(--text-secondary);
}
.link-mode-bar em { color: var(--accent); }
.link-mode-bar strong { color: var(--text-primary); }

/* Active state for toggle button */
.canvas-toolbar .btn.active {
    background: rgba(79,125,249,.15);
    color: var(--accent);
    border-color: var(--accent);
}
