:root {
    --bg-canvas: #07090E;
    --bg-surface: #0F1422;
    --bg-studio: #181825;
    --bg-card: #1E1E2E;
    --bg-input: #11111B;
    --border-subtle: rgba(255, 255, 255, 0.08);
    --border-studio: #313244;
    --text-primary: #CDD6F4;
    --text-muted: #94A3B8;
    --accent-mint: #26CEAF;
    --accent-cyan: #22D3EE;
}

/* Custom Scrollbar */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: #0B0F19; }
::-webkit-scrollbar-thumb { background: #2A3656; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent-mint); }

html, body {
    width: 100%;
    min-height: 100%;
    margin: 0;
    padding: 0;
    overflow-x: hidden;
    background-color: var(--bg-canvas);
    color: #F1F5F9;
}

/* RTL & Typography Support */
html[dir="rtl"] {
    direction: rtl;
    text-align: right;
}
html[dir="rtl"] body,
html[dir="rtl"] h1,
html[dir="rtl"] h2,
html[dir="rtl"] h3,
html[dir="rtl"] h4,
html[dir="rtl"] p,
html[dir="rtl"] span,
html[dir="rtl"] a,
html[dir="rtl"] button,
html[dir="rtl"] li,
html[dir="rtl"] div,
html[dir="rtl"] label,
html[dir="rtl"] input {
    font-family: 'Cairo', system-ui, -apple-system, sans-serif !important;
}
html[dir="rtl"] code,
html[dir="rtl"] pre,
html[dir="rtl"] .font-mono {
    font-family: 'JetBrains Mono', monospace !important;
    direction: ltr !important;
    unicode-bidi: isolate;
}

bdi {
    unicode-bidi: isolate;
}
html[dir="rtl"] bdi {
    direction: ltr;
    unicode-bidi: isolate;
}

/* Force strictly LTR on CAD canvases, Revit Ribbon, and Before/After architectural stages */
#revitRibbonWrapper,
#revitRibbonWrapper *,
.visual-diagram-card,
.visual-diagram-card *,
.studio-canvas-ltr,
.studio-canvas-ltr *,
.before-after-stage,
.before-after-stage * {
    direction: ltr !important;
    unicode-bidi: isolate;
}
#revitRibbonWrapper,
#revitRibbonWrapper *,
.visual-diagram-card,
.visual-diagram-card * {
    font-family: 'Plus Jakarta Sans', system-ui, sans-serif !important;
}
.visual-diagram-card.font-mono,
.visual-diagram-card .font-mono {
    font-family: 'JetBrains Mono', monospace !important;
}

html[dir="rtl"] #heroInspectorContainer {
    direction: rtl !important;
    text-align: right !important;
}

/* Ambient Drafting Grid & Glows */
.bg-grid {
    background-size: 40px 40px;
    background-image:
        linear-gradient(to right, rgba(255, 255, 255, 0.025) 1px, transparent 1px),
        linear-gradient(to bottom, rgba(255, 255, 255, 0.025) 1px, transparent 1px);
}

.hero-glow {
    background:
        radial-gradient(ellipse 680px 380px at 50% 120px, rgba(38, 206, 175, 0.14), transparent 72%),
        radial-gradient(circle 520px at 50% 200px, rgba(34, 211, 238, 0.12), rgba(59, 130, 246, 0.06), transparent 75%);
}

/* Glassmorphism & Catppuccin Studio Surfaces */
.glass-panel {
    background: rgba(11, 15, 25, 0.82);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
    border: 1px solid rgba(255, 255, 255, 0.08);
}

.glass-card {
    background: linear-gradient(145deg, rgba(24, 24, 37, 0.86) 0%, rgba(17, 23, 38, 0.72) 100%);
    backdrop-filter: blur(14px);
    border: 1px solid rgba(255, 255, 255, 0.08);
    transition: transform 0.28s cubic-bezier(0.16, 1, 0.3, 1), border-color 0.28s ease, box-shadow 0.28s ease;
}
.glass-card:hover {
    border-color: rgba(38, 206, 175, 0.42);
    transform: translateY(-3px);
    box-shadow: 0 18px 38px -12px rgba(38, 206, 175, 0.22);
}

.studio-shell {
    background: linear-gradient(180deg, #1E1E2E 0%, #181825 100%);
    border: 1px solid #313244;
    box-shadow: 0 28px 64px -18px rgba(0, 0, 0, 0.75), 0 0 0 1px rgba(38, 206, 175, 0.08);
}

.studio-card {
    background: #181825;
    border: 1px solid #313244;
}

.studio-input {
    background: #11111B;
    border: 1px solid #45475A;
    color: #CDD6F4;
}
.studio-input:focus {
    outline: none;
    border-color: var(--accent-mint);
    box-shadow: 0 0 0 2px rgba(38, 206, 175, 0.2);
}

/* Navbar Scroll-Spy Active State */
.nav-link {
    position: relative;
    transition: color 0.2s ease;
}
.nav-link.is-active {
    color: var(--accent-mint);
}
.nav-link.is-active::after {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    bottom: -6px;
    height: 2px;
    border-radius: 2px;
    background: linear-gradient(90deg, var(--accent-mint), var(--accent-cyan));
}

/* Skip Link & WCAG 2.2 Keyboard Focus */
.skip-link {
    position: fixed;
    top: -120px;
    inset-inline-start: 16px;
    z-index: 100;
    padding: 10px 16px;
    border-radius: 10px;
    background: #26CEAF;
    color: #07090E;
    font-size: 13px;
    font-weight: 800;
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.55);
    transition: top 0.16s ease;
}
.skip-link:focus {
    top: 14px;
}

:focus-visible {
    outline: 2px solid var(--accent-mint);
    outline-offset: 2px;
}
button:focus:not(:focus-visible),
a:focus:not(:focus-visible),
summary:focus:not(:focus-visible),
input[type="range"]:focus:not(:focus-visible) {
    outline: none;
}

.hero-title-balance {
    text-wrap: balance;
}

/* Responsive Revit 2027 Ribbon Styling */
.ribbon-scroll-shell {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
}
.ribbon-rail {
    display: flex;
    align-items: stretch;
    justify-content: space-between;
    width: 100%;
    min-width: 1040px;
    gap: 2px;
}
@media (min-width: 1280px) {
    .ribbon-rail {
        min-width: 0;
    }
}

.ribbon-panel-box {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: center;
    padding: 3px 3px 2px 3px;
    border-radius: 7px;
    border: 1px solid transparent;
    transition: background-color 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
    min-width: 0;
}
.ribbon-panel-box.is-active-panel {
    background-color: #e4e9f2;
    border-color: #cbd5e1;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.65);
}

.ribbon-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    text-align: center;
    padding: 4px 2px 3px 2px;
    min-height: 62px;
    border-radius: 6px;
    border: 1px solid transparent;
    transition: background-color 0.16s ease, border-color 0.16s ease, transform 0.16s ease;
    cursor: pointer;
    position: relative;
}
.ribbon-btn:hover {
    background-color: #e2e7ef;
    border-color: #bfdbfe;
}
.ribbon-btn.is-active-tool {
    background-color: #dbeafe;
    border-color: #60a5fa;
    box-shadow: 0 1px 3px rgba(37, 99, 235, 0.18);
}
.ribbon-btn img {
    margin: 0 auto 3px auto;
    display: block;
    flex-shrink: 0;
}
.ribbon-btn-text {
    font-size: 10px;
    line-height: 1.15;
    letter-spacing: -0.01em;
    color: #1e293b;
    font-weight: 600;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 2.3em;
    width: 100%;
}
.ribbon-panel-title {
    font-size: 10px;
    line-height: 1.15;
    font-weight: 700;
    color: #475569;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    margin-top: 3px;
    white-space: nowrap;
}

/* Interactive Chips, Tabs & Toggle Buttons */
.ls-chip {
    background: #11111B;
    color: #94A3B8;
    border: 1px solid #313244;
    transition: all 0.2s ease;
    cursor: pointer;
}
.ls-chip:hover {
    color: #E2E8F0;
    border-color: #45475A;
}
.ls-chip.is-active {
    background: rgba(38, 206, 175, 0.16);
    color: #26CEAF;
    border-color: rgba(38, 206, 175, 0.65);
    box-shadow: 0 0 0 1px rgba(38, 206, 175, 0.2);
}

.hero-tab-btn {
    transition: all 0.2s ease;
    cursor: pointer;
}
.hero-tab-btn.is-active {
    background: rgba(38, 206, 175, 0.16);
    color: #5EEAD4;
    border-color: rgba(38, 206, 175, 0.6);
    box-shadow: 0 4px 14px -4px rgba(38, 206, 175, 0.3);
    font-weight: 700;
}
.hero-tab-btn:not(.is-active) {
    background: #111726;
    color: #94A3B8;
    border-color: #1E293B;
}
.hero-tab-btn:not(.is-active):hover {
    color: #F8FAFC;
    border-color: #334155;
}

.tool-chip.is-highlighted {
    border-color: rgba(38, 206, 175, 0.75) !important;
    background: rgba(38, 206, 175, 0.15) !important;
    transform: translateY(-1px);
}

/* Catppuccin Range Sliders */
input[type="range"].ls-slider {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 6px;
    border-radius: 999px;
    background: #313244;
    outline: none;
    cursor: pointer;
}
input[type="range"].ls-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--accent-mint);
    border: 2px solid #11111B;
    box-shadow: 0 0 0 2px rgba(38, 206, 175, 0.3);
    transition: transform 0.15s ease;
}
input[type="range"].ls-slider::-webkit-slider-thumb:hover {
    transform: scale(1.15);
}
input[type="range"].ls-slider::-moz-range-thumb {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--accent-mint);
    border: 2px solid #11111B;
    cursor: pointer;
}

/* 9-Point Pivot Grid Matrix */
.pivot-dot-btn {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    border: 1px solid #45475A;
    background: #11111B;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.15s ease;
}
@media (pointer: coarse) {
    .pivot-dot-btn {
        width: 44px;
        height: 44px;
    }
}
.pivot-dot-btn::after {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 999px;
    background: #64748B;
    transition: all 0.15s ease;
}
.pivot-dot-btn:hover {
    border-color: var(--accent-mint);
}
.pivot-dot-btn.is-active {
    background: rgba(38, 206, 175, 0.2);
    border-color: var(--accent-mint);
    box-shadow: 0 0 10px rgba(38, 206, 175, 0.28);
}
.pivot-dot-btn.is-active::after {
    width: 9px;
    height: 9px;
    background: #EF4444;
    box-shadow: 0 0 0 2px #FEE2E2;
}

/* Interactive Before/After Drag Comparison Stage */
.before-after-stage {
    position: relative;
    overflow: hidden;
    user-select: none;
    -webkit-user-select: none;
    touch-action: pan-y;
    cursor: ew-resize;
}
.ba-layer-before,
.ba-layer-after {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}
.ba-layer-after {
    clip-path: inset(0 0 0 50%);
    will-change: clip-path;
}
.ba-divider {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 50%;
    width: 2px;
    background: linear-gradient(180deg, var(--accent-cyan), var(--accent-mint));
    box-shadow: 0 0 14px rgba(38, 206, 175, 0.75);
    pointer-events: none;
    transform: translateX(-50%);
    z-index: 20;
}
.ba-handle {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 36px;
    height: 36px;
    border-radius: 999px;
    background: #11111B;
    border: 2px solid var(--accent-mint);
    color: var(--accent-mint);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.7);
    pointer-events: none;
    z-index: 25;
}
.ba-range-overlay {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: ew-resize;
    z-index: 30;
    margin: 0;
}

/* Clash Pulse Animation for PanelX Live Preview */
@keyframes clashPulse {
    0%, 100% { opacity: 0.95; transform: scale(1); }
    50% { opacity: 0.45; transform: scale(1.12); }
}
.mep-clash-halo {
    transform-box: fill-box;
    transform-origin: center;
    animation: clashPulse 1.3s ease-in-out infinite;
}

/* Subtle Scroll Reveal */
.reveal {
    opacity: 1;
    transform: translateY(0);
    transition: opacity 0.55s ease, transform 0.55s cubic-bezier(0.16, 1, 0.3, 1);
}
.reveal.is-pending {
    opacity: 0;
    transform: translateY(18px);
}
@media (prefers-reduced-motion: reduce) {
    html.scroll-smooth {
        scroll-behavior: auto !important;
    }
    .reveal,
    .reveal.is-pending {
        opacity: 1 !important;
        transform: none !important;
        transition: none !important;
    }
    .glass-card:hover {
        transform: none !important;
    }
    .mep-clash-halo,
    .animate-ping,
    .animate-pulse {
        animation: none !important;
    }
}

.before-after-stage:has(.ba-range-overlay:focus-visible) .ba-handle {
    outline: 2px solid var(--accent-mint);
    outline-offset: 3px;
}

/* Mobile Slide-Over Drawer */
#mobileDrawer {
    transition: opacity 0.25s ease, visibility 0.25s ease;
}
#mobileDrawer.is-open {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}
#mobileDrawer:not(.is-open) {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}
#mobileDrawerPanel {
    transition: transform 0.28s cubic-bezier(0.16, 1, 0.3, 1);
}
#mobileDrawer:not(.is-open) #mobileDrawerPanel {
    transform: translateX(100%);
}
html[dir="rtl"] #mobileDrawer:not(.is-open) #mobileDrawerPanel {
    transform: translateX(-100%);
}
#mobileDrawer.is-open #mobileDrawerPanel {
    transform: translateX(0);
}

/* No Scrollbar Helper */
.no-scrollbar::-webkit-scrollbar { display: none; }
.no-scrollbar { -ms-overflow-style: none; scrollbar-width: none; }
