:root {
    --bg-dark: #0a0a0c;
    --card-bg: rgba(255, 255, 255, 0.05);
    --accent-color: #00e5ff;
    --text-primary: #f0f0f5;
    --text-secondary: #a0a0b0;
    --glass-border: rgba(255, 255, 255, 0.1);
    /* Space reserved below fixed .menu-bar so the canvas can extend upward to this line */
    --app-menu-offset: 2.5rem;
}

html {
    height: 100%;
}

body {
    margin: 0;
    padding: 0;
    background-color: var(--bg-dark);
    color: var(--text-primary);
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    height: 100vh;
    box-sizing: border-box;
    padding-top: var(--app-menu-offset);
    overflow: hidden;
}

.app-container {
    position: relative;
    text-align: center;
    width: 100%;
    max-width: 100vw;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    flex: 1 1 auto;
    min-height: 0;
}

h1 {
    font-weight: 300;
    letter-spacing: 2px;
    margin-bottom: 2rem;
    color: var(--accent-color);
    text-shadow: 0 0 10px rgba(0, 229, 255, 0.3);
}

.canvas-wrapper {
    position: relative;
    border-radius: 16px;
    overflow: auto;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
    border: 1px solid var(--glass-border);
    /* Fill viewport below the menu, above the status/command strip */
    flex: 1 1 auto;
    min-height: 0;
    width: 100%;
    background: #000;
}

#webgl-canvas {
    display: block;
    cursor: crosshair;
}

.ui-overlay {
    position: relative;
    margin-top: 2px;
    padding: 0 2px;
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
    align-items: flex-end;
    gap: 3px;
    z-index: 10;
    flex-shrink: 0;
}

.menu-bar {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    min-height: var(--app-menu-offset);
    box-sizing: border-box;
    padding: 0 8px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    align-content: center;
    gap: 20px;
    z-index: 1000;
    border-radius: 0;
    border-top: none;
    border-left: none;
    border-right: none;
}

.menu-item {
    position: relative;
    cursor: pointer;
}

/* CADMAX trigger + current JSON path (right of menu label) */
#cadmax-menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    max-width: min(560px, 52vw);
}

#cadmax-menu-item .menu-trigger {
    flex-shrink: 0;
}

.document-path-label {
    font-size: 0.72rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    min-width: 0;
    opacity: 0.92;
    pointer-events: auto;
    cursor: default;
}
.menu-trigger {
    font-size: 0.9rem;
    color: var(--text-secondary);
    transition: color 0.3s;
}

.menu-trigger:hover {
    color: var(--accent-color);
}

.dropdown-content {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    min-width: 100px;
    margin-top: 0px;
    padding: 0px 0;
    z-index: 1001;
}

.dropdown:hover .dropdown-content {
    display: block;
}

/* After choosing a command, :hover can still apply until the pointer moves; JS adds this class on link click. */
.menu-item.dropdown.dropdown--dismiss .dropdown-content,
.menu-item.dropdown.dropdown--dismiss .dropdown-submenu {
    display: none !important;
}
.dropdown-content a {
    display: block;
    color: var(--text-primary);
    text-decoration: none;
    font-size: 0.85rem;
    transition: background 0.3s;
}

.dropdown-content>a {
    padding: 4px 10px;
}

.dropdown-content a:hover {
    background: rgba(0, 229, 255, 0.1);
    color: var(--accent-color);
}

/* Nested submenu (e.g. Draw → Arc → …) opens to the right */
.dropdown-submenu-item {
    position: relative;
}

.submenu-trigger {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5em;
    padding: 4px 10px;
    color: var(--text-primary);
    font-size: 0.85rem;
    cursor: default;
    user-select: none;
    transition: background 0.3s, color 0.3s;
}

.submenu-trigger:hover {
    background: rgba(0, 229, 255, 0.1);
    color: var(--accent-color);
}

.submenu-chevron {
    display: inline-block;
    margin-left: 0.35em;
    opacity: 0.75;
    font-size: 1.1em;
    line-height: 1;
}

.dropdown-submenu {
    display: none;
    position: absolute;
    left: 100%;
    top: 0;
    margin-left: 2px;
    min-width: 110px;
    padding: 4px 0;
    z-index: 1002;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
}

.dropdown-submenu-item:hover .dropdown-submenu {
    display: block;
}

.dropdown-submenu a {
    display: block;
    padding: 4px 12px;
    color: var(--text-primary);
    text-decoration: none;
    font-size: 0.85rem;
    transition: background 0.3s, color 0.3s;
}

.dropdown-submenu a:hover {
    background: rgba(0, 229, 255, 0.1);
    color: var(--accent-color);
}

.menu-divider {
    border: none;
    border-top: 1px solid var(--glass-border);
    margin: 4px 0;
}

.coordinate-box,
.color-box,
.zoom-box,
.unit-box,
.layer-box {
    display: flex;
    flex-direction: column;
    padding: 6px 10px;
    align-items: flex-start;
    gap: 4px;
    min-width: 150px;
    pointer-events: auto;
}

.color-box-row {
    min-width: 180px;
}

.coordinate-box {
    min-width: 300px;
}

.ui-overlay #line-color,
.ui-overlay #aci-select,
.ui-overlay #unit-selector {
    background: transparent;
    border: 1px solid var(--glass-border);
    border-radius: 3px;
    width: 100%;
    height: 15px;
    min-height: 14px;
    box-sizing: border-box;
    cursor: pointer;
    padding: 0 4px;
    color: var(--text-primary);
    outline: none;
    font-size: 0.65rem;
    line-height: 1.1;
}

#line-color,
#aci-select,
#unit-selector {
    background: transparent;
    border: 1px solid var(--glass-border);
    border-radius: 4px;
    width: 100%;
    height: 30px;
    cursor: pointer;
    padding: 0 5px;
    color: var(--text-primary);
    outline: none;
}

.ui-overlay #aci-select {
    cursor: default;
}

#aci-select {
    cursor: default;
    font-size: 0.8rem;
}

#aci-select option {
    background: #1a1a1f;
    color: var(--text-primary);
}

#unit-selector option {
    background: #1a1a1f;
    color: var(--text-primary);
}

#line-color::-webkit-color-swatch-wrapper {
    padding: 0;
}

#line-color::-webkit-color-swatch {
    border: none;
    border-radius: 3px;
}

.glass {
    background: rgba(15, 15, 20, 0.7);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
}

.ui-overlay>.glass {
    border-radius: 8px;
}

.label {
    font-size: 0.75rem;
    text-transform: uppercase;
    color: var(--text-secondary);
    letter-spacing: 1px;
}

.ui-overlay .label {
    font-size: 0.6rem;
    letter-spacing: 0.5px;
    line-height: 1.1;
}

#current-layer-name {
    text-transform: none;
    color: var(--accent-color);
    max-width: 9rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#zoom-level {
    display: block;
    font-size: 0.75rem;
    line-height: 1.1;
    font-family: 'JetBrains Mono', 'Courier New', monospace;
    color: var(--text-primary);
}

#coord-input {
    background: transparent;
    border: none;
    color: var(--accent-color);
    font-family: 'JetBrains Mono', 'Courier New', monospace;
    font-size: 1rem;
    width: 100%;
    outline: none;
    text-shadow: 0 0 5px rgba(0, 229, 255, 0.2);
    line-height: 1.2;
}

.ui-overlay #coord-input {
    font-size: 0.75rem;
    line-height: 1.15;
}

.instruction {
    margin-top: 2rem;
    font-size: 0.9rem;
    color: var(--text-secondary);
    opacity: 0.7;
}

@keyframes pulse {
    0% {
        opacity: 0.6;
    }

    50% {
        opacity: 1;
    }

    100% {
        opacity: 0.6;
    }
}

#coord-input:focus {
    animation: pulse 2s infinite ease-in-out;
}

/* Command Prompt Area */
.command-box {
    margin-top: 10px;
    padding: 10px 15px;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 5px;
    text-align: left;
    width: auto;
    max-width: 100%;
    flex-shrink: 0;
}

.command-history {
    font-family: 'JetBrains Mono', 'Courier New', monospace;
    font-size: 0.85rem;
    line-height: 1.4;
    color: var(--text-secondary);
    /* ~3 visible lines; older messages are reached by scrolling up (thumb / wheel / track). */
    max-height: calc(0.85rem * 1.4 * 3 + 6px);
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    width: 100%;
    scrollbar-gutter: stable;
    scrollbar-width: thin;
    scrollbar-color: var(--glass-border) rgba(0, 0, 0, 0.15);
}

.command-history div {
    margin: 0;
    /* Each entry is a single line; 2px between rows without blowing past 3-line cap */
    line-height: 1.4;
    padding: 0 0 2px 0;
}

.command-input-area {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    font-family: 'JetBrains Mono', 'Courier New', monospace;
    font-size: 0.95rem;
}

.command-label {
    color: var(--accent-color);
    font-weight: bold;
}

#command-prompt-text {
    color: var(--accent-color);
    white-space: nowrap;
}

.command-input {
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-family: 'JetBrains Mono', 'Courier New', monospace;
    font-size: 0.95rem;
    width: 100%;
    outline: none;
    caret-color: var(--accent-color);
}

.command-input::placeholder {
    color: rgba(255, 255, 255, 0.2);
}

.command-history::-webkit-scrollbar {
    width: 8px;
}

.command-history::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 4px;
}

.command-history::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.22);
    border-radius: 4px;
    min-height: 1.5rem;
}

.command-history::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 229, 255, 0.4);
}

/* Modal Styles */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 2000;
}

.modal-overlay.active {
    display: flex;
}

.modal-content {
    width: 400px;
    max-width: 90%;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
    animation: slideIn 0.3s ease-out;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--glass-border);
    padding-bottom: 0.5rem;
}

.modal-header h3 {
    margin: 0;
    font-weight: 400;
    font-size: 1rem;
    color: var(--accent-color);
}

#close-modal-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 1.5rem;
    cursor: pointer;
    line-height: 1;
}

#close-modal-btn:hover {
    color: var(--accent-color);
}

#about-close-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 1.5rem;
    cursor: pointer;
    line-height: 1;
}

#about-close-btn:hover {
    color: var(--accent-color);
}

.about-modal-box {
    text-align: center;
    border-radius: 16px;
    border: 1px solid var(--glass-border);
    background: linear-gradient(145deg, rgba(255, 255, 255, 0.09), rgba(255, 255, 255, 0.03));
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    max-width: 22rem;
}

.about-modal-body {
    max-height: none;
    overflow: visible;
    padding: 0.25rem 0 0.5rem;
}

.about-modal-body .about-tagline {
    margin: 0 0 0.75rem;
    font-size: 0.85rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--text-secondary);
}

.about-modal-body .about-company {
    margin: 0;
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--accent-color);
    line-height: 1.5;
    letter-spacing: 0.03em;
}

.modal-body {
    max-height: 300px;
    overflow-y: auto;
}

/* BEAMD Z dialog: no horizontal scrollbar; inputs stay within panel width. */
.beamd-z-modal-content {
    width: min(420px, calc(100vw - 2rem));
    max-width: min(420px, calc(100vw - 2rem));
    box-sizing: border-box;
    overflow-x: hidden;
}

.beamd-z-modal-body {
    max-height: none;
    overflow-x: hidden;
    overflow-y: visible;
}

.beamd-z-modal-body .command-input {
    min-width: 0;
    max-width: 100%;
    box-sizing: border-box;
}

.beamd-z-modal-body select.command-input {
    background-color: #000;
    border: 1px solid var(--glass-border);
    border-radius: 4px;
    padding: 6px 8px;
    color: var(--text-primary);
    cursor: pointer;
    color-scheme: dark;
    appearance: auto;
}

.beamd-z-modal-body select.command-input option {
    background-color: #000;
    color: var(--text-primary);
}

.beamd-z-modal-body p {
    overflow-wrap: anywhere;
    word-wrap: break-word;
}

/* RESLAB slab params: compact rows, viewport-bound, OK/Cancel always visible */
#reslab-params-modal .reslab-params-modal-content {
    width: min(440px, calc(100vw - 2rem));
    max-width: min(440px, calc(100vw - 2rem));
    max-height: min(88vh, 100dvh - 2rem);
    padding: 0.85rem 1.1rem;
    gap: 0.45rem;
    overflow: hidden;
}

#reslab-params-modal .modal-header {
    flex-shrink: 0;
    padding-bottom: 0.35rem;
}

#reslab-params-modal .reslab-params-modal-body {
    flex: 1 1 auto;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    max-height: none;
    padding: 0.15rem 0;
}

#reslab-params-modal .reslab-params-hint {
    margin: 0 0 3px;
    font-size: 0.78rem;
    line-height: 1.3;
    color: #aaa;
}

#reslab-params-modal .reslab-params-mat-hint {
    color: #8cf;
    margin-bottom: 6px;
}

#reslab-params-modal .reslab-params-form {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

#reslab-params-modal .reslab-params-field {
    display: grid;
    grid-template-columns: 1fr minmax(76px, 92px);
    align-items: center;
    gap: 8px;
    margin: 0;
    cursor: default;
}

#reslab-params-modal .reslab-params-label {
    font-size: 0.8rem;
    line-height: 1.2;
    color: var(--text-primary);
}

#reslab-params-modal .reslab-params-modal-body select.command-input {
    padding: 3px 6px;
    font-size: 0.82rem;
    min-height: 26px;
}

#reslab-params-modal .reslab-params-footer {
    flex-shrink: 0;
    gap: 8px;
    padding-top: 0.4rem;
    margin-top: 0.15rem;
    border-top: 1px solid var(--glass-border);
}

/* Hatch pattern picker: scrollable list fills modal (override generic .modal-body 300px cap). */
.hatch-pattern-modal-content {
    max-height: min(88vh, 100dvh - 2.5rem);
    display: flex;
    flex-direction: column;
}

.modal-body.hatch-pattern-modal-body {
    max-height: none;
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    padding-top: 0.25rem;
}

.hatch-pattern-list {
    flex: 1 1 auto;
    min-height: 12rem;
    max-height: min(72vh, calc(100dvh - 10rem));
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.25);
    font-size: 0.8rem;
    text-align: left;
    outline: none;
}

.hatch-pattern-row {
    padding: 6px 10px;
    cursor: pointer;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.hatch-pattern-row:hover {
    background: rgba(0, 229, 255, 0.08);
}

.hatch-pattern-row.selected {
    background: rgba(0, 229, 255, 0.18);
    color: var(--accent-color);
}

.hatch-pattern-modal-footer {
    display: flex;
    flex-direction: row;
    justify-content: flex-end;
    gap: 8px;
    padding-top: 0.5rem;
}

.layer-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8rem;
    /* Reduced font size */
}

.layer-table th {
    text-align: left;
    color: var(--text-secondary);
    text-transform: uppercase;
    font-weight: 500;
    padding: 8px;
    border-bottom: 1px solid var(--glass-border);
    letter-spacing: 0.5px;
}

.layer-table td {
    padding: 8px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.layer-table tr:hover {
    background: rgba(255, 255, 255, 0.03);
}

.layer-table .layer-delete-btn {
    font-size: 0.72rem;
    padding: 3px 10px;
    min-width: 4.5rem;
}

.layer-table .layer-delete-btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    padding-top: 0.5rem;
}

.ui-button {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid var(--glass-border);
    color: var(--text-primary);
    padding: 6px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.8rem;
    transition: all 0.2s;
}

.ui-button:hover {
    background: rgba(0, 229, 255, 0.2);
    border-color: var(--accent-color);
}

.ui-overlay .ui-button {
    padding: 3px 8px;
    font-size: 0.65rem;
    line-height: 1.2;
    border-radius: 4px;
}

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

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

/* Idle entity selection — properties popup (right-click on selection) */
.entity-props-popup {
    position: fixed;
    z-index: 2000;
    min-width: 220px;
    max-width: min(360px, calc(100vw - 16px));
    padding: 0;
    border-radius: 10px;
    border: 1px solid var(--glass-border);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
    pointer-events: auto;
}

.entity-props-popup[hidden] {
    display: none !important;
}

.entity-props-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    border-bottom: 1px solid var(--glass-border);
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--accent-color);
}

.entity-props-close {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 1.25rem;
    line-height: 1;
    cursor: pointer;
    padding: 0 4px;
    border-radius: 4px;
}

.entity-props-close:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.08);
}

.entity-props-body {
    padding: 10px 12px 12px;
    font-size: 0.82rem;
    color: var(--text-primary);
}

.entity-props-body dl {
    margin: 0;
    display: grid;
    grid-template-columns: 7.5rem 1fr;
    gap: 6px 10px;
}

.entity-props-body dt {
    margin: 0;
    color: var(--text-secondary);
    font-weight: 500;
}

.entity-props-body dd {
    margin: 0;
    word-break: break-word;
}

.osnap-options {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    padding: 10px;
}

.osnap-options label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 0.9em;
    color: #ccc;
    transition: color 0.2s;
}

.osnap-options label:hover {
    color: #fff;
}

.osnap-options input[type='checkbox'] {
    accent-color: #00ffff;
    width: 16px;
    height: 16px;
}

/* ========================================================================
   Splash Screen & Authentication (Niroobini: mustard, olive, black, white)
   ======================================================================== */

/* Until /api/auth/me succeeds, keep the CAD shell hidden so Google sign-in is never missed. */
body.nirts-auth-gate .menu-bar,
body.nirts-auth-gate .app-container {
    display: none !important;
}
body.nirts-auth-gate #chat-toggle-btn,
body.nirts-auth-gate #user-menu {
    display: none !important;
}

/* Splash must sit above .modal (z-index 100000) and any other overlays so the Google button receives clicks. */
body.nirts-auth-gate #splash-screen {
    z-index: 2147483647;
    pointer-events: auto;
}
body.nirts-auth-gate .modal {
    display: none !important;
    pointer-events: none !important;
    visibility: hidden !important;
}

#splash-screen {
    --splash-mustard: #d4a82a;
    --splash-olive: #3d4a2c;
    --splash-olive-deep: #252b1c;
    --splash-black: #0d0d0d;
    --splash-white: #faf9f6;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background:
        radial-gradient(ellipse 120% 80% at 50% 0%, rgba(212, 168, 42, 0.12) 0%, transparent 55%),
        linear-gradient(160deg, var(--splash-olive) 0%, var(--splash-olive-deep) 45%, var(--splash-black) 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 99999;
}

.splash-container {
    text-align: center;
    color: var(--splash-white);
    max-width: 520px;
    padding: 2.25rem 1.75rem;
    background: rgba(13, 13, 13, 0.55);
    border: 1px solid rgba(212, 168, 42, 0.35);
    border-radius: 12px;
    box-shadow:
        0 24px 48px rgba(0, 0, 0, 0.45),
        inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.splash-logo {
    width: auto;
    max-width: 200px;
    height: auto;
    max-height: 140px;
    margin-bottom: 1.25rem;
    object-fit: contain;
    filter: drop-shadow(0 6px 16px rgba(0, 0, 0, 0.4));
}

.splash-container h1 {
    font-size: 2.75rem;
    margin: 0 0 8px 0;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--splash-white);
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
    border: none;
    outline: none;
    background: transparent;
    box-shadow: none;
    user-select: none;
}

.tagline {
    font-size: 1.1rem;
    margin: 0 0 1.5rem 0;
    color: rgba(250, 249, 246, 0.88);
    font-weight: 400;
}

.splash-legal {
    text-align: left;
    font-size: 0.8rem;
    line-height: 1.55;
    color: rgba(250, 249, 246, 0.82);
    margin: 0 0 1.5rem 0;
    padding: 1rem 1.1rem;
    background: rgba(0, 0, 0, 0.25);
    border-radius: 8px;
    border-left: 3px solid var(--splash-mustard);
}

.splash-legal-lead {
    display: block;
}

.splash-legal-follow {
    display: block;
    margin-top: 0.65rem;
}

.splash-legal a {
    color: var(--splash-mustard);
    text-decoration: underline;
    text-underline-offset: 2px;
    font-weight: 500;
}

.splash-legal a:hover {
    color: #e8bc4a;
}

.google-btn {
    background: var(--splash-white);
    color: var(--splash-black);
    border: 2px solid rgba(212, 168, 42, 0.5);
    padding: 12px 24px;
    font-size: 16px;
    border-radius: 6px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
    transition: background 0.2s, border-color 0.2s, transform 0.15s, box-shadow 0.2s;
    font-weight: 600;
}

.google-btn:hover {
    background: #ffffff;
    border-color: var(--splash-mustard);
    box-shadow: 0 6px 20px rgba(212, 168, 42, 0.2);
    transform: translateY(-1px);
}

.google-btn:focus-visible {
    outline: 2px solid var(--splash-mustard);
    outline-offset: 3px;
}

.google-btn svg {
    flex-shrink: 0;
}

.splash-footer {
    margin-top: 1.5rem;
    font-size: 0.88rem;
    color: rgba(250, 249, 246, 0.75);
}

.splash-footer a {
    color: var(--splash-mustard);
    text-decoration: underline;
    text-underline-offset: 2px;
}

.splash-footer a:hover {
    color: #e8bc4a;
}

/* ========================================================================
   AI Chat Panel
   ======================================================================== */
.chat-panel {
    position: fixed;
    right: -400px;
    top: 0;
    width: 400px;
    height: 100vh;
    background: rgba(26, 26, 30, 0.98);
    backdrop-filter: blur(10px);
    box-shadow: -2px 0 10px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    transition: right 0.3s ease;
    z-index: 10000;
    border-left: 1px solid var(--glass-border);
}

.chat-panel.open {
    right: 0;
}

.chat-header {
    background: rgba(102, 126, 234, 0.1);
    backdrop-filter: blur(5px);
    color: var(--text-primary);
    padding: 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--glass-border);
}

.chat-header h3 {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 600;
}

.chat-close-btn {
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 20px;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: background 0.2s;
}

.chat-close-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 15px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.chat-messages::-webkit-scrollbar {
    width: 8px;
}

.chat-messages::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
}

.chat-messages::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 4px;
}

.chat-message {
    display: flex;
    margin-bottom: 8px;
}

.chat-message.user {
    justify-content: flex-end;
}

.chat-message.ai {
    justify-content: flex-start;
}

.chat-message.system {
    justify-content: center;
}

.chat-message.help {
    justify-content: flex-start;
}

.chat-message.thinking {
    justify-content: flex-start;
}

.chat-message .bubble {
    display: inline-block;
    padding: 10px 15px;
    border-radius: 15px;
    max-width: 80%;
    word-wrap: break-word;
    line-height: 1.4;
}

.chat-message.user .bubble {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.chat-message.ai .bubble {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
}

.chat-welcome-bubble {
    max-width: 92%;
}

.chat-welcome-lead {
    margin: 0 0 10px;
}

.chat-welcome-examples-label {
    margin: 0 0 6px;
    font-size: 0.95em;
}

.chat-welcome-examples {
    margin: 0;
    padding-left: 1.15em;
}

.chat-welcome-examples li {
    margin: 4px 0;
}

.chat-message.system .bubble {
    background: rgba(100, 200, 255, 0.15);
    color: #60d0ff;
    font-size: 0.9em;
    font-style: italic;
    max-width: 90%;
}

.chat-message.help .bubble {
    background: rgba(255, 200, 100, 0.15);
    color: #ffc866;
    border-left: 3px solid #ffc866;
}

.chat-message.thinking .bubble {
    background: rgba(150, 150, 255, 0.1);
    color: #a0a0ff;
    border-left: 3px solid #8080ff;
    cursor: pointer;
}

/* Thinking block after agent finished — muted so it doesn't compete with the reply */
.chat-message.thinking-done .bubble {
    background: rgba(100, 100, 100, 0.08);
    color: var(--text-secondary);
    border-left: 3px solid rgba(128, 128, 128, 0.4);
    font-size: 0.88em;
    opacity: 0.75;
    transition: opacity 0.2s;
}
.chat-message.thinking-done .bubble:hover {
    opacity: 1;
}

.thinking-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 0;
}

.thinking-icon {
    font-size: 1.2em;
}

.thinking-text {
    flex: 1;
    font-weight: 500;
}

.thinking-toggle {
    font-size: 0.8em;
    transition: transform 0.2s;
}

.bubble.expanded .thinking-toggle {
    transform: rotate(180deg);
}

.thinking-details {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
    margin-top: 8px;
    padding-left: 24px;
}

.bubble.expanded .thinking-details {
    max-height: 500px;
}

.thinking-line {
    padding: 2px 0;
    font-size: 0.9em;
    opacity: 0.8;
}

.chat-input-container {
    border-top: 1px solid var(--glass-border);
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    background: rgba(0, 0, 0, 0.2);
}

#chat-input {
    flex: 1;
    resize: none;
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    padding: 10px;
    font-family: inherit;
    font-size: 14px;
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
    min-height: 60px;
}

#chat-input:focus {
    outline: none;
    border-color: var(--accent-color);
}

.chat-send-btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.2s;
}

.chat-send-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(102, 126, 234, 0.3);
}

.floating-btn {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    padding: 15px 20px;
    border-radius: 50px;
    cursor: pointer;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
    z-index: 9999;
    font-size: 14px;
    font-weight: 600;
    transition: all 0.2s;
}

.floating-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(102, 126, 234, 0.4);
}

/* ========================================================================
   User Menu (top right, aligned with .menu-bar strip — avoids overlapping CADMAX)
   ======================================================================== */
.user-menu {
    position: fixed;
    top: 0;
    left: auto;
    right: 12px;
    transform: none;
    box-sizing: border-box;
    min-height: var(--app-menu-offset);
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 4px 14px;
    background: rgba(26, 26, 30, 0.92);
    backdrop-filter: blur(10px);
    border: 1px solid var(--glass-border);
    border-radius: 0 0 8px 8px;
    border-top: none;
    z-index: 1002;
    font-size: 14px;
    max-width: min(92vw, 520px);
}

#user-email-display {
    color: var(--text-secondary);
    max-width: min(240px, 38vw);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.user-menu-btn {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: var(--text-primary);
    padding: 6px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    transition: background 0.2s;
}

.user-menu-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Power-style sign-out (IEC standby symbol) — circular icon control (sized to match ⚙️ settings) */
.user-menu-power-btn {
    width: 28px;
    height: 28px;
    min-width: 28px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, 0.14);
    background: rgba(255, 255, 255, 0.07);
    box-shadow:
        0 1px 0 rgba(255, 255, 255, 0.06) inset,
        0 2px 6px rgba(0, 0, 0, 0.22);
    color: rgba(250, 250, 250, 0.92);
    transition:
        background 0.2s,
        border-color 0.2s,
        color 0.2s,
        box-shadow 0.2s,
        transform 0.15s;
}

.user-menu-power-btn:hover {
    background: rgba(248, 113, 113, 0.16);
    border-color: rgba(248, 113, 113, 0.42);
    color: #fecaca;
    box-shadow:
        0 1px 0 rgba(255, 255, 255, 0.08) inset,
        0 2px 10px rgba(239, 68, 68, 0.2);
    transform: translateY(-1px);
}

.user-menu-power-btn:focus-visible {
    outline: 2px solid rgba(248, 113, 113, 0.65);
    outline-offset: 2px;
}

.user-menu-power-icon {
    width: 14px;
    height: 14px;
    display: block;
    flex-shrink: 0;
}

/* ========================================================================
   Settings Modal
   ======================================================================== */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100000;
}

.modal-content {
    background: rgba(26, 26, 30, 0.98);
    backdrop-filter: blur(20px);
    padding: 30px;
    border-radius: 12px;
    max-width: 500px;
    width: 90%;
    border: 1px solid var(--glass-border);
    position: relative;
}

.modal-close {
    position: absolute;
    top: 15px;
    right: 15px;
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 20px;
    cursor: pointer;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: background 0.2s;
}

.modal-close:hover {
    background: rgba(255, 255, 255, 0.1);
}

.modal-content h2 {
    margin-top: 0;
    color: var(--accent-color);
}

.settings-instructions {
    color: var(--text-secondary);
    line-height: 1.6;
    padding-left: 20px;
}

.settings-instructions a {
    color: var(--accent-color);
    text-decoration: none;
}

.settings-instructions a:hover {
    text-decoration: underline;
}

.modal-content label {
    display: block;
    margin-top: 15px;
    margin-bottom: 8px;
    font-weight: 600;
    color: var(--text-primary);
}

.modal-content input[type="password"] {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
    font-family: 'Courier New', monospace;
    font-size: 14px;
    box-sizing: border-box;
}

.modal-content input[type="password"]:focus {
    outline: none;
    border-color: var(--accent-color);
}

.modal-actions {
    margin-top: 20px;
    display: flex;
    gap: 10px;
}

.modal-actions button {
    flex: 1;
    padding: 10px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.2s;
}

.btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(102, 126, 234, 0.3);
}

.btn-success {
    background: linear-gradient(135deg, #4caf50 0%, #2e7d32 100%);
    color: white;
}

.btn-success:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(76, 175, 80, 0.3);
}

.settings-status {
    margin-top: 15px;
    font-weight: 600;
    text-align: center;
    min-height: 20px;
}

/* ============================================================================
   Billing & License UI
   ============================================================================ */

/* -- Plan badge in user menu -- */
.plan-badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    white-space: nowrap;
}
.plan-badge-trial {
    background: rgba(34, 197, 94, 0.18);
    color: #22c55e;
    border: 1px solid rgba(34, 197, 94, 0.4);
}
.plan-badge-warning {
    background: rgba(251, 146, 60, 0.18);
    color: #fb923c;
    border: 1px solid rgba(251, 146, 60, 0.4);
}
.plan-badge-active {
    background: rgba(99, 102, 241, 0.18);
    color: #818cf8;
    border: 1px solid rgba(99, 102, 241, 0.4);
}

/* -- Upgrade button in user menu -- */
.upgrade-btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
    color: #fff !important;
    border: none !important;
    font-weight: 700 !important;
    padding: 4px 14px !important;
}
.upgrade-btn:hover {
    opacity: 0.88;
    transform: translateY(-1px);
}

/* -- Expired overlay (full-screen lockout) -- */
#expired-overlay {
    position: fixed;
    inset: 0;
    z-index: 9000;
    background: rgba(10, 10, 20, 0.88);
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
}
.expired-card {
    background: #1a1a2e;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 20px;
    padding: 48px 40px;
    text-align: center;
    max-width: 440px;
    width: calc(100% - 40px);
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.6);
}
.expired-logo {
    margin-bottom: 20px;
}
.expired-card h2 {
    font-size: 22px;
    font-weight: 700;
    color: #f1f5f9;
    margin: 0 0 12px;
}
.expired-card p {
    font-size: 14px;
    color: #94a3b8;
    margin: 0 0 28px;
    line-height: 1.6;
}
.expired-subscribe-btn {
    display: inline-block;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #fff;
    border: none;
    border-radius: 12px;
    padding: 14px 36px;
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    transition: opacity 0.2s, transform 0.15s;
    margin-bottom: 20px;
}
.expired-subscribe-btn:hover {
    opacity: 0.88;
    transform: translateY(-2px);
}
.expired-links a {
    color: #64748b;
    font-size: 13px;
    text-decoration: underline;
    cursor: pointer;
}
.expired-links a:hover {
    color: #94a3b8;
}

.expired-signout-btn {
    background: transparent;
    border: 1px solid rgba(148, 163, 184, 0.45);
    color: #94a3b8;
    font-size: 13px;
    padding: 8px 18px;
    border-radius: 8px;
    cursor: pointer;
    font-family: inherit;
}
.expired-signout-btn:hover {
    color: #e2e8f0;
    border-color: rgba(148, 163, 184, 0.75);
}

/* Billing upgrade — not exposed in UI until public launch */
#upgrade-btn,
.user-menu .upgrade-btn {
    display: none !important;
}

/* When license is expired, dim all CAD UI under the overlay */
body.license-expired .menu-bar,
body.license-expired .app-container,
body.license-expired #ai-chat-panel,
body.license-expired #chat-toggle-btn {
    pointer-events: none;
    opacity: 0.25;
    user-select: none;
}

/* -- Billing / upgrade modal -- */
.billing-modal-content {
    max-width: 540px;
    width: calc(100% - 40px);
}
.billing-subtitle {
    color: #94a3b8;
    font-size: 14px;
    margin: 0 0 24px;
    text-align: center;
}
.billing-plans {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 20px;
}
.billing-plans-inr {
    grid-template-columns: 1fr 1fr;
}
@media (max-width: 480px) {
    .billing-plans { grid-template-columns: 1fr; }
    .billing-plans-inr { grid-template-columns: 1fr; }
}
.plan-btn {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 10px;
    padding: 12px 14px;
    cursor: pointer;
    transition: background 0.18s, border-color 0.18s, transform 0.12s;
    width: 100%;
    text-align: left;
}
.plan-btn:hover {
    background: rgba(102, 126, 234, 0.16);
    border-color: rgba(102, 126, 234, 0.4);
    transform: translateY(-1px);
}
.plan-btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}
.plan-btn.plan-yearly {
    border-color: rgba(99, 102, 241, 0.3);
}
.plan-label {
    font-size: 12px;
    color: #94a3b8;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 6px;
}
.plan-save {
    background: rgba(34, 197, 94, 0.2);
    color: #22c55e;
    border-radius: 4px;
    padding: 1px 5px;
    font-size: 10px;
    font-weight: 700;
}
.plan-price {
    font-size: 20px;
    font-weight: 700;
    color: #f1f5f9;
    margin-top: 4px;
}
.plan-period {
    font-size: 12px;
    font-weight: 400;
    color: #64748b;
}
.billing-footer {
    text-align: center;
    font-size: 12px;
    color: #475569;
    margin: 0;
}
