/* =========================================
   Climasoft™ Climasoft™ Piping v8.0 Pro - Design System
   ========================================= */

/* -----------------------------------------
   CSS Variables / Design Tokens
   ----------------------------------------- */
:root {
    /* Colors - Light Theme */
    --color-bg-primary: #f8fafc;
    --color-bg-secondary: #ffffff;
    --color-bg-tertiary: #f1f5f9;
    --color-bg-hover: #e2e8f0;

    --color-text-primary: #0f172a;
    --color-text-secondary: #475569;
    --color-text-tertiary: #94a3b8;
    --color-text-inverse: #ffffff;

    --color-border: #e2e8f0;
    --color-border-focus: #3b82f6;

    /* Accent Colors */
    --color-primary: #3b82f6;
    --color-primary-hover: #2563eb;
    --color-primary-light: #dbeafe;

    --color-accent-cyan: #00d4ff;
    --color-accent-purple: #7b2fff;
    --color-accent-green: #10b981;
    --color-accent-orange: #f59e0b;
    --color-accent-red: #ef4444;

    /* Gradients */
    --gradient-primary: var(--color-primary);
    --gradient-success: linear-gradient(135deg, #10b981 0%, #059669 100%);
    --gradient-card-plastic: var(--gradient-card-metal);
    --gradient-card-metal: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
    --gradient-card-fiber: var(--gradient-card-metal);

    /* Shadows */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    --shadow-glow: 0 0 20px rgba(59, 130, 246, 0.3);

    /* Typography */
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-size-xs: 0.75rem;
    --font-size-sm: 0.875rem;
    --font-size-base: 1rem;
    --font-size-lg: 1.125rem;
    --font-size-xl: 1.25rem;
    --font-size-2xl: 1.5rem;
    --font-size-3xl: 1.875rem;

    /* Spacing */
    --spacing-1: 0.25rem;
    --spacing-2: 0.5rem;
    --spacing-3: 0.75rem;
    --spacing-4: 1rem;
    --spacing-5: 1.25rem;
    --spacing-6: 1.5rem;
    --spacing-8: 2rem;
    --spacing-10: 2.5rem;
    --spacing-12: 3rem;

    /* Border Radius */
    --radius-sm: 0.375rem;
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
    --radius-xl: 1rem;
    --radius-full: 9999px;

    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-base: 250ms ease;
    --transition-slow: 350ms ease;

    /* Layout */
    --header-height: 64px;
    --footer-height: 48px;
    --panel-gap: 16px;
}

/* Dark Theme */
[data-theme="dark"] {
    --color-bg-primary: #0f172a;
    --color-bg-secondary: #1e293b;
    --color-bg-tertiary: #334155;
    --color-bg-hover: #475569;

    --color-text-primary: #f8fafc;
    --color-text-secondary: #cbd5e1;
    --color-text-tertiary: #64748b;

    --color-border: #334155;

    --gradient-card-plastic: linear-gradient(135deg, #0c4a6e 0%, #164e63 100%);
    --gradient-card-metal: linear-gradient(135deg, #1e293b 0%, #334155 100%);
    --gradient-card-fiber: linear-gradient(135deg, #422006 0%, #451a03 100%);

    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.3), 0 2px 4px -1px rgba(0, 0, 0, 0.2);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.3), 0 4px 6px -2px rgba(0, 0, 0, 0.2);
}

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

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-family);
    font-size: var(--font-size-sm);
    line-height: 1.5;
    color: var(--color-text-primary);
    background-color: var(--color-bg-primary);
    min-height: 100vh;
    min-height: 100dvh;
    scrollbar-width: none;
}

/* Hide scrollbar for Chrome, Safari and Opera - UNIVERSAL */
*::-webkit-scrollbar {
    display: none;
}

/* Hide scrollbar for Firefox - UNIVERSAL */
* {
    scrollbar-width: none;
    -ms-overflow-style: none;
}

#app {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    min-height: 100dvh;
    overflow: visible;
    /* Ensure sticky works */
}

/* -----------------------------------------
   Header
   ----------------------------------------- */
.header {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    height: var(--header-height);
    padding: 0 var(--spacing-6);
    background: var(--color-bg-secondary);
    border-bottom: 1px solid var(--color-border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header__brand {
    display: flex;
    align-items: center;
    gap: var(--spacing-3);
}

.header__logo {
    display: flex;
    align-items: center;
    justify-content: center;
}

.header__title h1 {
    font-size: var(--font-size-lg);
    font-weight: 700;
    color: var(--color-text-primary);
}

.header__subtitle {
    font-size: var(--font-size-xs);
    color: var(--color-text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.language-selector {
    background: transparent;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    padding: 2px 4px;
    font-size: 11px;
    font-weight: 600;
    color: var(--color-text-secondary);
    cursor: pointer;
    outline: none;
    height: 24px;
    font-family: inherit;
    transition: all var(--transition-fast);
}

.language-selector:hover {
    border-color: var(--color-primary);
    background: var(--color-bg-tertiary);
}

.header__actions {
    display: flex;
    align-items: center;
    gap: 0;
}

/* Responsive Header for Demo */
@media (max-width: 768px) {
    .header {
        flex-wrap: wrap;
        height: auto !important;
        padding-top: 8px;
        padding-bottom: 8px;
        justify-content: space-between !important;
    }

    .header__brand {
        order: 1;
        margin-right: auto;
    }

    .header__actions {
        order: 2;
        margin-left: auto;
    }

    .header>.btn--upgrade-pro {
        order: 3;
        width: 100%;
        margin-top: 8px;
        justify-content: center;
        margin-left: 0 !important;
    }
}

/* Text link button style */
.btn--text-link {
    font-size: 1.1rem;
    font-weight: 500;
    color: var(--color-text-secondary);
    text-decoration: none;
    padding: 0.25rem 0.5rem;
    background: transparent;
    border: none;
}

.btn--text-link:hover {
    color: var(--color-primary);
    background: transparent;
}

/* Demo Disabled State */
.demo-disabled {
    opacity: 0.5;
    cursor: not-allowed !important;
    pointer-events: auto !important;
    /* Allow click interception */
    filter: grayscale(100%);
}

.demo-disabled:hover {
    background: transparent !important;
    transform: none !important;
    box-shadow: none !important;
}

/* -----------------------------------------
   Buttons
   ----------------------------------------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-2);
    padding: var(--spacing-2) var(--spacing-4);
    font-family: inherit;
    font-size: var(--font-size-sm);
    font-weight: 500;
    line-height: 1;
    color: var(--color-text-primary);
    background: var(--color-bg-tertiary);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
}

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

.btn:active {
    transform: scale(0.98);
}

.btn--ghost {
    background: transparent;
    border-color: transparent;
}

.btn--ghost:hover {
    background: var(--color-bg-tertiary);
    border-color: transparent;
}

/* Orange Gradient for Pro Upgrade */
.btn--upgrade-pro {
    color: white;
    background: linear-gradient(135deg, #f97316 0%, #ea580c 100%);
    border: none;
    box-shadow: 0 4px 6px -1px rgba(249, 115, 22, 0.3), 0 2px 4px -1px rgba(249, 115, 22, 0.2);
    font-weight: 600;
}

.btn--upgrade-pro:hover {
    background: linear-gradient(135deg, #fb923c 0%, #f97316 100%);
    box-shadow: 0 10px 15px -3px rgba(249, 115, 22, 0.4), 0 4px 6px -2px rgba(249, 115, 22, 0.2);
    transform: translateY(-1px);
}

.btn--primary {
    color: var(--color-text-inverse);
    background: var(--color-primary);
    border-color: var(--color-primary);
}

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

.btn--gradient {
    color: var(--color-text-inverse);
    background: var(--gradient-primary);
    border: none;
    box-shadow: var(--shadow-md);
}

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

.btn--icon {
    padding: var(--spacing-2);
    border-radius: var(--radius-full);
}

.btn--sm {
    padding: var(--spacing-1) var(--spacing-3);
    font-size: var(--font-size-xs);
}

.btn--lg {
    padding: var(--spacing-4) var(--spacing-8);
    font-size: var(--font-size-base);
    border-radius: var(--radius-lg);
}

/* -----------------------------------------
   Main Layout
   ----------------------------------------- */
.main {
    flex: 1;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--panel-gap);
    padding: var(--panel-gap);
    height: calc(100vh - var(--header-height) - var(--footer-height));
    overflow: hidden;
}

/* -----------------------------------------
   Panels
   ----------------------------------------- */
.panel {
    display: flex;
    flex-direction: column;
    background: var(--color-bg-secondary);
    border-radius: var(--radius-xl);
    border: 1px solid var(--color-border);
    overflow: hidden;
}

.panel__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--spacing-4) var(--spacing-5);
    border-bottom: 1px solid var(--color-border);
    background: var(--color-bg-tertiary);
}

.panel__title {
    font-size: var(--font-size-base);
    font-weight: 600;
}

/* -----------------------------------------
   Canvas Panel
   ----------------------------------------- */
.panel--canvas {
    min-height: 400px;
}

/* Wrapper for arrows */
.toolbar-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    max-width: 100%;
    background: var(--color-bg-secondary);
    border-radius: var(--radius-md);
}

.toolbar {
    display: flex;
    align-items: center;
    /* Gap 0 as requested */
    gap: 0;
    padding: 0;

    /* Responsive Scroll */
    overflow-x: auto;
    width: 100%;
    scrollbar-width: none;
    -ms-overflow-style: none;
    -webkit-overflow-scrolling: touch;

    /* Scroll Behavior */
    scroll-behavior: smooth;

    /* Masking for arrows */
    mask-image: linear-gradient(to right, transparent 0%, black 10px, black calc(100% - 10px), transparent 100%);
    -webkit-mask-image: linear-gradient(to right, transparent 0%, black 10px, black calc(100% - 10px), transparent 100%);
}

/* Hide scrollbar for Chrome/Safari */
.toolbar::-webkit-scrollbar {
    display: none;
}

.toolbar__btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    color: var(--color-text-secondary);
    cursor: pointer;
    transition: all var(--transition-fast);
    padding: 0;
    /* Clear padding */
    margin: 0;
    /* Clear margin */

    /* Prevent shrinking */
    flex-shrink: 0;
}

/* Scroll Buttons */
.toolbar-scroll-btn {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    z-index: 10;
    width: 24px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--color-bg-secondary);
    /* Match bg */
    border: none;
    color: var(--color-text-primary);
    cursor: pointer;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
    opacity: 0.9;
}

.toolbar-scroll-btn:hover {
    background: var(--color-bg-hover);
}

.toolbar-scroll-btn--left {
    left: 0;
    border-radius: var(--radius-md) 0 0 var(--radius-md);
    border-right: 1px solid var(--color-border);
}

.toolbar-scroll-btn--right {
    right: 0;
    border-radius: 0 var(--radius-md) var(--radius-md) 0;
    border-left: 1px solid var(--color-border);
}

.toolbar-scroll-btn.hidden {
    display: none;
}

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

.toolbar__btn.active {
    background: var(--color-primary);
    color: var(--color-text-inverse);
}

.toolbar__divider {
    width: 1px;
    height: 24px;
    background: var(--color-border);
    margin: 0 var(--spacing-1);
}

.canvas-container {
    flex: 1;
    position: relative;
    /* Grid background explicitly removed (transparent) */
    background-color: var(--color-bg-primary);
    background-image: none !important;
    background-size: 0 0 !important;
    overflow: hidden;
}

.canvas-container canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    cursor: crosshair;
    touch-action: none;
    /* Prevent browser default touch behaviors */
}

#mainCanvas {
    z-index: 1;
}

#overlayCanvas {
    z-index: 2;
    pointer-events: none;
}

.canvas-info {
    display: flex;
    justify-content: space-between;
    padding: var(--spacing-2) var(--spacing-4);
    font-size: var(--font-size-xs);
    color: var(--color-text-tertiary);
    background: var(--color-bg-tertiary);
    border-top: 1px solid var(--color-border);
}

/* -----------------------------------------
   Data Panel
   ----------------------------------------- */
.panel--data {
    overflow: hidden;
}

.table-container {
    flex: 1;
    overflow: auto;
    padding: var(--spacing-4) var(--spacing-5);
}

.data-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: var(--font-size-xs);
}

.data-table th,
.data-table td {
    padding: var(--spacing-2) var(--spacing-2);
    text-align: center;
    border-bottom: 1px solid var(--color-border);
    white-space: nowrap;
}

.data-table th {
    position: sticky;
    top: 0;
    background: var(--color-bg-tertiary);
    font-weight: 600;
    color: var(--color-text-secondary);
    text-transform: uppercase;
    font-size: 0.65rem;
    letter-spacing: 0.05em;
    z-index: 10;
}

.data-table tbody tr:hover {
    background: var(--color-bg-hover);
}

.data-table input {
    width: 100%;
    min-width: 50px;
    max-width: 80px;
    padding: var(--spacing-1) var(--spacing-2);
    font-family: inherit;
    font-size: var(--font-size-xs);
    text-align: center;
    color: var(--color-text-primary);
    background: var(--color-bg-primary);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
}

.data-table input:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px var(--color-primary-light);
}

.data-table input:disabled {
    background: var(--color-bg-tertiary);
    color: var(--color-text-secondary);
    cursor: not-allowed;
}

.data-table input.highlight {
    background: var(--color-primary-light);
    font-weight: 600;
}

.col-ramal {
    width: 50px;
}

.col-terminal {
    width: 80px;
    text-align: center;
}

.terminal-icon {
    display: inline-block;
    font-size: 1rem;
    line-height: 1;
}

.terminal-dim {
    font-size: 0.7rem;
    font-weight: 500;
    white-space: nowrap;
}

.col-parent {
    width: 50px;
}

.col-actions {
    width: 40px;
}

.btn-delete-row {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    color: var(--color-text-tertiary);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.btn-delete-row:hover {
    background: rgba(239, 68, 68, 0.1);
    color: var(--color-accent-red);
}

/* -----------------------------------------
   Calculate Section
   ----------------------------------------- */
.calculate-section {
    display: flex;
    justify-content: center;
    padding: var(--spacing-4) var(--spacing-5);
    border-top: 1px solid var(--color-border);
    background: var(--color-bg-tertiary);
}

/* -----------------------------------------
   Results Section
   ----------------------------------------- */
.results-section {
    padding: var(--spacing-4) var(--spacing-5);
    background: var(--color-bg-primary);
    border-top: 1px solid var(--color-border);
}

.results__title {
    font-size: var(--font-size-sm);
    font-weight: 600;
    margin-bottom: var(--spacing-4);
    color: var(--color-text-secondary);
}

.results-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--spacing-3);
}

.result-card {
    display: flex;
    align-items: center;
    gap: var(--spacing-3);
    padding: var(--spacing-4);
    background: var(--gradient-card-metal);
    border-radius: var(--radius-lg);
    border: 1px solid var(--color-border);
    transition: all var(--transition-base);
}

.result-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.result-card--plastic {
    background: var(--gradient-card-plastic);
}

.result-card--plastic .result-card__icon {
    color: var(--color-text-tertiary);
}

.result-card--metal .result-card__icon {
    color: var(--color-text-tertiary);
}

.result-card--fiber {
    background: var(--gradient-card-fiber);
}

.result-card--fiber .result-card__icon {
    color: var(--color-text-tertiary);
}

.result-card__content {
    display: flex;
    flex-direction: column;
}

.result-card__label {
    font-size: var(--font-size-xs);
    color: var(--color-text-secondary);
    font-weight: 500;
}

.result-card__value {
    font-size: var(--font-size-xl);
    font-weight: 700;
    color: var(--color-text-primary);
}

.result-card__unit {
    font-size: 0.65rem;
    color: var(--color-text-tertiary);
}

.auth-view.hidden {
    display: none !important;
}

/* Terminals Summary */
.terminals-summary {
    margin-top: var(--spacing-4);
    padding: var(--spacing-3);
    background: var(--color-bg-tertiary);
    border-radius: var(--radius-md);
    border: 1px solid var(--color-border);
}

.terminals-summary__title {
    font-weight: 600;
    font-size: var(--font-size-sm);
    margin-bottom: var(--spacing-2);
    color: var(--color-text-primary);
}

.terminals-summary__content {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-1);
}

.terminals-summary__item {
    font-size: var(--font-size-sm);
    color: var(--color-text-secondary);
}

/* -----------------------------------------
   Footer
   ----------------------------------------- */
.footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: var(--footer-height);
    padding: 0 var(--spacing-6);
    background: var(--color-bg-secondary);
    border-top: 1px solid var(--color-border);
    font-size: var(--font-size-xs);
    color: var(--color-text-tertiary);
}

.footer__links a {
    color: var(--color-primary);
    text-decoration: none;
}

.footer__links a:hover {
    text-decoration: underline;
}

/* -----------------------------------------
   Toast Notifications
   ----------------------------------------- */
.toast-container {
    position: fixed;
    bottom: var(--spacing-6);
    right: var(--spacing-6);
    display: flex;
    flex-direction: column;
    gap: var(--spacing-2);
    z-index: 1000;
}

.toast {
    display: flex;
    align-items: center;
    gap: var(--spacing-3);
    padding: var(--spacing-3) var(--spacing-4);
    background: var(--color-bg-secondary);
    border-radius: var(--radius-md);
    border: 1px solid var(--color-border);
    box-shadow: var(--shadow-lg);
    animation: slideIn 0.3s ease;
}

.toast--success {
    border-left: 4px solid var(--color-text-tertiary);
}

.toast--error {
    border-left: 4px solid var(--color-text-tertiary);
}

.toast--info {
    border-left: 4px solid var(--color-text-tertiary);
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }

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

/* -----------------------------------------
   Tramos Table
   ----------------------------------------- */
.tramos-section {
    margin-top: 1.5rem;
    padding: 1.5rem var(--spacing-5) 0 var(--spacing-5);
    border-top: 1px solid var(--color-border);
}

.data-table--compact th,
.data-table--compact td {
    padding: 0.5rem 0.75rem;
    font-size: 0.85rem;
}

.tramo-max-loss {
    background: rgba(0, 0, 0, 0.05) !important;
}

.tramo-max-loss td {
    font-weight: 600;
    color: var(--color-text-primary) !important;
}

.tramo-max-loss .text-danger {
    color: var(--color-text-primary) !important;
}

.tramo-max-loss .badge--danger {
    background: var(--color-text-tertiary);
    color: var(--color-bg-secondary);
}

.ramal-chip {
    display: inline-block;
    background: var(--color-bg-tertiary);
    color: var(--color-text-primary);
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 500;
}

.badge {
    display: inline-block;
    font-size: 0.65rem;
    padding: 2px 6px;
    border-radius: 4px;
    margin-left: 6px;
    font-weight: 600;
    text-transform: uppercase;
}

.badge--danger {
    background: var(--color-accent-red);
    color: white;
}

.text-danger {
    color: var(--color-accent-red) !important;
}

.input-override {
    background: rgba(59, 130, 246, 0.08) !important;
    border: 1px dashed var(--color-primary) !important;
}

.input-override:focus {
    background: rgba(59, 130, 246, 0.15) !important;
    border-color: var(--color-primary) !important;
}

/* -----------------------------------------
   Responsive
   ----------------------------------------- */
@media (max-width: 1200px) {
    .main {
        display: block;
        height: auto;
        overflow: visible;
        /* Changed from overflow-y: auto to allow sticky header */
    }

    .panel--canvas {
        /* Canvas siempre tiene una altura grande fija en móvil */
        height: 83vh;
        min-height: 400px;
    }

    .panel--data {
        /* Panel de datos ocupa lo que necesite */
        height: auto;
    }

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

@media (max-width: 768px) {

    /* Prevent horizontal scroll on mobile */
    html,
    body {
        overflow-x: hidden;
        max-width: 100vw;
    }

    /* Hide elements marked for mobile */
    .mobile-hide {
        display: none !important;
    }

    /* Simple Fixed Header - Always visible */
    body {
        padding-top: var(--header-height);
    }

    .header {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        z-index: 10000;
        width: 100%;
        background: var(--color-bg-secondary);
        padding: 0 var(--spacing-3);
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    }

    .main {
        display: block;
        padding-bottom: 80px;
        /* Scroll Gutters Implementation */
        padding-left: 24px;
        padding-right: 24px;
        position: relative;
        /* Anchor for scroll handles */
        border: none;
    }

    /* Dynamic Scroll Handles */
    .scroll-handle {
        position: fixed;
        width: 6px;
        height: 80px;
        background-color: #60a5fa;
        /* Azul suave (Blue 400) */
        border-radius: 999px;
        opacity: 0.6;
        /* Un poco más visible */
        pointer-events: none;
        z-index: 90;
        transition: top 0.1s ease-out, opacity 0.3s;
        display: block;
    }

    .scroll-handle--right {
        right: 8px;
    }

    .header__brand {
        gap: var(--spacing-2);
    }

    .header__logo svg {
        width: 32px;
        height: 32px;
    }

    /* Hide all button text, keep icons */
    .header__actions .btn {
        padding: 4px;
        min-width: auto;
    }

    /* Help link - transparent background, larger font on mobile */
    .header__actions .btn--text-link {
        background: transparent !important;
        border: none !important;
        font-size: 1.25rem;
        padding: 0.25rem;
    }

    .header__actions .btn svg {
        width: 20px;
        height: 20px;
    }

    .panel__header {
        flex-direction: column;
        gap: var(--spacing-3);
        align-items: flex-start;
    }

    /* Table scrolls horizontally */
    .table-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Main content takes full width */
    .main {
        padding: var(--spacing-2);
    }

    .panel {
        padding: var(--spacing-3);
    }

    /* Center toolbar and prevent overflow */
    .toolbar {
        justify-content: center;
        gap: var(--spacing-1);
        width: 100%;
    }

    /* Hide dividers on mobile */
    .toolbar__divider {
        display: none;
    }

    /* FIX: Revert to normal flow but ensure initial visibility */
    .toolbar-wrapper {
        position: relative;
        /* Default */
        z-index: 1;
        background: var(--color-bg-secondary);
        border-radius: var(--radius-md);
        box-shadow: none;
        /* Remove fixed shadow */
        padding: 0;
        margin: 0;
    }

    /* Pushed down to ensure visibility below fixed header */
    .panel--canvas {
        margin-top: var(--spacing-4);
        /* Add extra breathing room */
        padding-top: var(--spacing-2);
    }

    .panel__header {
        flex-direction: column;
        gap: var(--spacing-3);
        align-items: flex-start;
        padding: var(--spacing-3);
    }


    /* All toolbar buttons same size */
    .toolbar__btn {
        padding: var(--spacing-2);
        min-width: auto;
        width: 40px;
        height: 40px;
    }

    /* Make analyze button same as others (no blue background on mobile) */
    .toolbar__btn.btn--primary {
        background: transparent !important;
        color: var(--color-text-primary) !important;
        padding: var(--spacing-2);
        width: 40px;
        height: 40px;
    }

    .toolbar__btn.btn--primary:hover {
        background: var(--color-bg-hover) !important;
    }

    /* Panel header centers content */
    .panel__header {
        width: 100%;
        justify-content: center;
    }

    /* Hide panel titles on mobile for more space */
    .panel__title {
        display: none;
    }

    /* Hide results/materials title on mobile */
    .results__title {
        display: none;
    }

    /* Fix input text colors for readability */
    .table-container input,
    .ramal-table input {
        color: var(--color-text-primary) !important;
    }

    /* VS input specifically - ensure black text */
    .col-vs input {
        color: #000000 !important;
        background: #f1f5f9 !important;
    }
}

/* -----------------------------------------
   Scrollbar Styling
   ----------------------------------------- */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--color-bg-tertiary);
}

::-webkit-scrollbar-thumb {
    background: var(--color-text-tertiary);
    border-radius: var(--radius-full);
}

::-webkit-scrollbar-thumb:hover {
    background: var(--color-text-secondary);
}

/* -----------------------------------------
   Animations
   ----------------------------------------- */
@keyframes pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.5;
    }
}

/* -----------------------------------------
   Auth Modal Styles
   ----------------------------------------- */
/* -----------------------------------------
   Auth Modal Styles (Redesigned)
   ----------------------------------------- */
/* -----------------------------------------
   Auth Modal Styles (Redesigned)
   ----------------------------------------- */
.auth-modal-overlay,
.projects-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.4);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.auth-modal-overlay.active,
.projects-modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.auth-modal {
    background: #e0e0e0;
    /* Fondo gris por defecto */
    border-radius: 40px;
    /* Bordes muy redondeados */
    padding: 2rem 3rem 3rem;
    width: 100%;
    max-width: 380px;
    /* Perfil más delgado */
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
    transform: translateY(20px) scale(0.95);
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow:
        20px 20px 60px #bebebe,
        -5px -5px 20px rgba(255, 255, 255, 0.5);
    /* Efecto neumórfico/sombra suave */
    display: flex;
    flex-direction: column;
    align-items: center;
}

[data-theme="dark"] .auth-modal {
    background: #1a1a1a;
    box-shadow:
        20px 20px 60px #161616,
        -20px -20px 60px #1e1e1e;
}

.auth-modal-overlay.active .auth-modal {
    transform: translateY(0) scale(1);
}

.auth-modal__close {
    position: absolute;
    top: 1.5rem;
    right: 1.5rem;
    background: transparent;
    border: none;
    font-size: 1.5rem;
    color: #64748b;
    cursor: pointer;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s;
    opacity: 0;
    /* Oculto por defecto en este diseño, o hacerlo muy sutil */
}

.auth-modal:hover .auth-modal__close {
    opacity: 1;
}

.auth-modal__icon {
    font-size: 3rem;
    color: #9ca3af;
    margin-bottom: 1.5rem;
    display: flex;
    justify-content: center;
    align-items: center;
    width: 80px;
    height: 80px;
    background: transparent;
}

.auth-modal__title {
    font-size: 1.5rem;
    font-weight: 500;
    color: #4b5563;
    /* Texto apagado */
    text-align: center;
    margin-bottom: 2rem;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    width: 100%;
}

[data-theme="dark"] .auth-modal__title {
    color: #e5e7eb;
}

.auth-modal__subtitle {
    color: #9ca3af;
    text-align: center;
    font-size: 0.85rem;
    margin-bottom: 1rem;
    margin-top: 4rem;
    line-height: 1.4;
    font-weight: 400;
}

.auth-form {
    width: 100%;
}

.auth-form .form-group {
    margin-bottom: 1rem;
    position: relative;
    /* For password toggle positioning */
}

.password-group input {
    padding-right: 40px;
    /* Space for the eye icon */
}

.password-toggle {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #9ca3af;
    transition: color 0.2s;
}

.password-toggle:hover {
    color: #4b5563;
}

[data-theme="dark"] .password-toggle:hover {
    color: #e5e7eb;
}

.auth-form input {
    width: 100%;
    padding: 1rem 1.25rem;
    background: #e0e0e0;
    border: none;
    border-radius: 12px;
    font-size: 16px;
    /* Prevent iOS zoom */
    color: #4b5563;
    box-shadow: inset 5px 5px 10px #bebebe,
        inset -5px -5px 10px #ffffff;
    transition: all 0.2s;
}

[data-theme="dark"] .auth-form input {
    background: #1a1a1a;
    color: #e5e7eb;
    box-shadow: inset 5px 5px 10px #0f0f0f,
        inset -5px -5px 10px #252525;
}

.auth-form input:focus {
    outline: none;
    box-shadow: inset 2px 2px 5px #bebebe,
        inset -2px -2px 5px #ffffff;
}

[data-theme="dark"] .auth-form input:focus {
    box-shadow: inset 2px 2px 5px #0f0f0f,
        inset -2px -2px 5px #252525;
}

/* Placeholder styling */
.auth-form input::placeholder {
    color: #9ca3af;
}

.auth-form .forgot-password-link {
    display: block;
    text-align: right;
    font-size: 0.75rem;
    color: #6b7280;
    text-decoration: none;
    margin-top: 0.5rem;
    margin-bottom: 1.5rem;
    font-weight: 600;
}

.auth-btn-primary {
    width: 100%;
    padding: 1rem;
    border: none;
    border-radius: 12px;
    background: #e0e0e0;
    color: #1f2937;
    font-size: 0.95rem;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 5px 5px 10px #bebebe,
        -5px -5px 10px #ffffff;
    transition: all 0.2s;
    margin-bottom: 1.5rem;
}

[data-theme="dark"] .auth-btn-primary {
    background: #1a1a1a;
    color: #e5e7eb;
    box-shadow: 5px 5px 10px #0f0f0f,
        -5px -5px 10px #252525;
}

.auth-btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 7px 7px 14px #bebebe,
        -7px -7px 14px #ffffff;
}

[data-theme="dark"] .auth-btn-primary:hover {
    box-shadow: 7px 7px 14px #0f0f0f,
        -7px -7px 14px #252525;
}

.auth-btn-primary:active {
    transform: translateY(1px);
    box-shadow: inset 3px 3px 6px #bebebe,
        inset -3px -3px 6px #ffffff;
}

.auth-divider {
    display: flex;
    align-items: center;
    text-align: center;
    color: #9ca3af;
    font-size: 0.75rem;
    margin: 1.5rem 0;
    width: 100%;
}

.auth-divider::before,
.auth-divider::after {
    content: '';
    flex: 1;
    border-bottom: 1px solid #d1d5db;
}

[data-theme="dark"] .auth-divider::before,
[data-theme="dark"] .auth-divider::after {
    border-color: #374151;
}

.auth-divider span {
    padding: 0 1rem;
}

.social-buttons {
    display: flex;
    gap: 1.5rem;
    justify-content: center;
    margin-bottom: 2rem;
}

.btn-social {
    width: 50px;
    height: 50px;
    border-radius: 12px;
    background: #e0e0e0;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 5px 5px 10px #bebebe,
        -5px -5px 10px #ffffff;
    transition: all 0.2s;
}

[data-theme="dark"] .btn-social {
    background: #1a1a1a;
    box-shadow: 5px 5px 10px #0f0f0f,
        -5px -5px 10px #252525;
}

.btn-social:hover {
    transform: translateY(-2px);
}

.btn-social img,
.btn-social svg {
    width: 24px;
    height: 24px;
}

.auth-footer {
    text-align: center;
    font-size: 0.75rem;
    color: #6b7280;
    margin-top: auto;
}

.auth-footer a {
    color: #4b5563;
    text-decoration: none;
    font-weight: 700;
    margin-left: 0.25rem;
}

[data-theme="dark"] .auth-footer a {
    color: #d1d5db;
}

.auth-message {
    padding: 0.75rem;
    border-radius: 8px;
    font-size: 0.8rem;
    margin-bottom: 1rem;
    text-align: center;
}

.auth-message--success {
    color: #059669;
    background: rgba(16, 185, 129, 0.1);
}

.auth-message--error {
    color: #dc2626;
    background: rgba(239, 68, 68, 0.1);
}

.auth-links {
    text-align: center;
    margin-top: 2rem;
    font-size: 0.95rem;
    color: #64748b;
}

.auth-links a {
    color: #3b82f6;
    text-decoration: none;
    font-weight: 600;
    transition: color 0.2s;
}

.auth-links a:hover {
    color: #2563eb;
    text-decoration: underline;
}

/* -----------------------------------------
   Projects Modal Styles
   ----------------------------------------- */
.projects-modal {
    background: #ffffff;
    border-radius: 24px;
    width: 100%;
    max-width: 500px;
    max-height: 80vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    transform: translateY(20px) scale(0.95);
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.projects-modal-overlay.active .projects-modal {
    transform: translateY(0) scale(1);
}

.projects-modal__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.5rem 2rem;
    border-bottom: 1px solid #e2e8f0;
}

.projects-modal__header h2 {
    font-size: 1.25rem;
    font-weight: 700;
    color: #0f172a;
    letter-spacing: -0.025em;
}

.projects-modal__close {
    background: #f1f5f9;
    border: none;
    font-size: 1.25rem;
    color: #64748b;
    cursor: pointer;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s;
}

.projects-modal__close:hover {
    background: #e2e8f0;
    color: #1e293b;
    transform: rotate(90deg);
}

.projects-modal__content {
    padding: 1rem;
    overflow-y: auto;
    flex: 1;
    max-height: 70vh;
    /* Asegurar altura máxima para scroll */
}

.projects-loading,
.projects-empty {
    text-align: center;
    padding: 3rem 2rem;
    color: #64748b;
}

.projects-empty svg {
    margin-bottom: 1rem;
    opacity: 0.5;
    color: #94a3b8;
}

.projects-empty__hint {
    font-size: 0.9rem;
    margin-top: 0.5rem;
    color: #94a3b8;
}

.projects-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.project-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.5rem;
    border-radius: 12px;
    transition: background 0.2s;
    margin-bottom: 0.5rem;
    border: 1px solid transparent;
}

.project-item:hover {
    background: #f8fafc;
    border-color: #e2e8f0;
}

.project-item__info {
    flex: 1;
    min-width: 0;
}

.project-item__name {
    display: block;
    font-weight: 600;
    color: #334155;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 1rem;
}

.project-item__date {
    display: block;
    font-size: 0.8rem;
    color: #94a3b8;
    margin-top: 0.25rem;
}

.project-item__actions {
    display: flex;
    gap: 0.5rem;
    margin-left: 1rem;
}

@media (max-width: 480px) {
    .auth-modal {
        padding: 2rem 1.5rem;
        width: 80%;
        max-height: 85vh;
        border-radius: 24px;
        /* Adjust for fixed header if needed */
        margin-top: 60px;
    }

    .auth-modal__title {
        font-size: 1.25rem;
        margin-bottom: 1.5rem;
    }

    .auth-modal__icon {
        width: 60px;
        height: 60px;
        margin-bottom: 1rem;
    }

    .auth-modal__icon svg {
        width: 32px;
        height: 32px;
    }

    .social-buttons {
        gap: 1rem;
    }

    .btn-social {
        width: 44px;
        height: 44px;
    }
}

/* -----------------------------------------
   User Info in Header
   ----------------------------------------- */
#userInfo {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 0rem;
    /* Padding similar a los botones */
    height: 32px;
    /* Coincidir con la altura del botón usualmente */
}


#userInfo.hidden {
    display: none;
}

.user-indicator {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 10px;
    height: 10px;
    background: #10b981;
    border-radius: 50%;
    box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.2);
    position: relative;
    margin: 0 auto;
}

.user-indicator::after {
    content: '';
    position: absolute;
    inset: -2px;
    border-radius: 50%;
    border: 1px solid rgba(16, 185, 129, 0.3);
    animation: pulse 2s infinite;
}

#authButtons.hidden {
    display: none;
}

.calculating {
    animation: pulse 1s infinite;
}

/* -----------------------------------------
   Login Gate - Premium Redesign
   ----------------------------------------- */
.login-gate {
    position: fixed;
    inset: 0;
    background: radial-gradient(circle at top right, #1e293b 0%, #0f172a 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.login-gate.hidden {
    display: none;
}

.login-gate::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 100%;
    background-image:
        linear-gradient(45deg, rgba(255, 255, 255, 0.03) 25%, transparent 25%),
        linear-gradient(-45deg, rgba(255, 255, 255, 0.03) 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, rgba(255, 255, 255, 0.03) 75%),
        linear-gradient(-45deg, transparent 75%, rgba(255, 255, 255, 0.03) 75%);
    background-size: 60px 60px;
    background-position: 0 0, 0 30px, 30px -30px, -30px 0px;
    opacity: 0.5;
    pointer-events: none;
}

.login-gate__content {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px);
    padding: 3.5rem;
    border-radius: 24px;
    box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.1), 0 40px 80px -20px rgba(0, 0, 0, 0.5);
    text-align: center;
    max-width: 440px;
    width: 90%;
    position: relative;
    z-index: 1;
    transform: translateY(0);
    animation: gateEnter 0.8s cubic-bezier(0.2, 0.8, 0.2, 1);
}

@keyframes gateEnter {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

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

.login-gate__logo {
    margin-bottom: 2rem;
    filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.1));
}

.login-gate__title {
    font-size: 2rem;
    font-weight: 800;
    background: linear-gradient(135deg, #0f172a 0%, #334155 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 0.75rem;
    letter-spacing: -0.05em;
}

.login-gate__subtitle {
    color: #64748b;
    font-size: 1.1rem;
    margin-bottom: 2.5rem;
    line-height: 1.5;
}

.login-gate__register {
    margin-top: 2rem;
    font-size: 0.95rem;
    color: #64748b;
    padding-top: 1.5rem;
    border-top: 1px solid #e2e8f0;
}

.btn--large {
    padding: 1rem 2.5rem;
    font-size: 1.125rem;
    font-weight: 600;
    border-radius: 12px;
    box-shadow: 0 10px 15px -3px rgba(59, 130, 246, 0.3), 0 4px 6px -2px rgba(59, 130, 246, 0.15);
    transition: all 0.2s;
}

.btn--large:hover {
    transform: translateY(-2px);
    box-shadow: 0 20px 25px -5px rgba(59, 130, 246, 0.4), 0 10px 10px -5px rgba(59, 130, 246, 0.2);
}

.app-hidden {
    display: none !important;
}