:root {
    --bg-dark: #0f172a;
    --glass-bg: rgba(30, 41, 59, 0.7);
    --glass-border: rgba(255, 255, 255, 0.1);
    --glass-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
    --accent: #06b6d4; /* Cyan/Neon Blue */
    --accent-hover: #0891b2;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Inter', sans-serif;
}

body {
    background-color: var(--bg-dark);
    color: var(--text-main);
    min-height: 100vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.background-mesh {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    z-index: -1;
    background-image: 
        radial-gradient(at 40% 20%, hsla(228,100%,74%,0.15) 0px, transparent 50%),
        radial-gradient(at 80% 0%, hsla(189,100%,56%,0.15) 0px, transparent 50%),
        radial-gradient(at 0% 50%, hsla(355,100%,93%,0.1) 0px, transparent 50%);
    filter: blur(80px);
}

.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    padding: 1rem;
    gap: 1rem;
}

/* Glassmorphism Header */
.glass-header {
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    padding: 0.4rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: var(--glass-shadow);
    position: relative;
    z-index: 100;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.logo .icon {
    display: flex;
    align-items: center;
    color: #ffffff;
}

.logo .icon svg {
    filter: drop-shadow(0 0 5px rgba(255, 255, 255, 0.5));
}

.logo h1 {
    font-size: 1.25rem;
    font-weight: 600;
}

.badge {
    font-size: 0.65rem;
    padding: 0.2rem 0.5rem;
    border-radius: 99px;
    background: rgba(255, 255, 255, 0.1);
    vertical-align: middle;
    margin-left: 0.5rem;
}

.badge.new {
    background: var(--accent);
    color: #fff;
}

nav a {
    color: var(--text-muted);
    text-decoration: none;
    margin-left: 1.5rem;
    font-size: 0.9rem;
    font-weight: 500;
    transition: color 0.3s ease;
}

nav a.active, nav a:hover {
    color: var(--text-main);
}

main {
    flex: 1;
    display: flex;
    position: relative;
    overflow: hidden;
}

/* Glass Panel */
.glass-panel {
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    box-shadow: var(--glass-shadow);
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    transition: opacity 0.5s ease, transform 0.5s ease;
}

.centered-panel {
    align-items: center;
    justify-content: center;
}

.hidden {
    opacity: 0;
    pointer-events: none;
    position: absolute;
    transform: scale(0.95);
    z-index: -1;
}

/* Drop Zone */
.drop-zone {
    width: 80%;
    max-width: 600px;
    height: 300px;
    border: 2px dashed rgba(255, 255, 255, 0.2);
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    background: rgba(255, 255, 255, 0.02);
}
.keyboard-layout-indicator {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 10px;
    font-weight: 700;
    margin-right: 10px;
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.2);
    min-width: 24px;
}
.keyboard-en { background-color: #059669; border-color: #10b981; }
.keyboard-th { background-color: #2563eb; border-color: #3b82f6; }

/* Custom Modal Styles */
.modal-btn-cancel {
    background: transparent;
    border: 1px solid #475569;
    color: #cbd5e1;
    padding: 6px 16px;
    border-radius: 4px;
    cursor: pointer;
    font-family: 'Inter', sans-serif;
    font-size: 13px;
    transition: all 0.2s;
}
.modal-btn-cancel:hover { background: #334155; }

.modal-btn-confirm {
    background: #0ea5e9;
    border: 1px solid #0ea5e9;
    color: white;
    padding: 6px 16px;
    border-radius: 4px;
    cursor: pointer;
    font-family: 'Inter', sans-serif;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.2s;
}
.modal-btn-confirm:hover { background: #0284c7; }

.drop-zone:hover, .drop-zone.dragover {
    border-color: var(--accent);
    background: rgba(6, 182, 212, 0.05);
}

.drop-content {
    text-align: center;
}

.upload-icon {
    width: 48px;
    height: 48px;
    color: var(--accent);
    margin-bottom: 1rem;
    transition: transform 0.3s ease;
}

.drop-zone:hover .upload-icon {
    transform: translateY(-5px);
}

.drop-content h2 {
    font-size: 1.25rem;
    margin-bottom: 0.5rem;
}

.drop-content p {
    color: var(--text-muted);
    font-size: 0.9rem;
}

/* Loading State */
#loading-state {
    text-align: center;
    margin-top: 2rem;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(255, 255, 255, 0.1);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 1rem;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Viewer Section */
.toolbar {
    padding: 1rem;
    border-bottom: 1px solid var(--glass-border);
    display: flex;
    gap: 1rem;
    background: rgba(0,0,0,0.1);
    border-top-left-radius: 16px;
    border-top-right-radius: 16px;
}

.glass-btn {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: var(--text-main);
    padding: 0.5rem 1rem;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.2s ease;
}

.glass-btn:hover {
    background: rgba(255, 255, 255, 0.15);
}

.glass-btn.primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.glass-btn.primary:hover {
    background: var(--accent-hover);
}

.svg-container {
    flex: 1;
    overflow: hidden;
    position: relative;
    cursor: grab;
    background: #000; /* Contrast for vectors */
}

.svg-container:active {
    cursor: grabbing;
}

/* Make SVG fit */
.svg-container svg {
    width: 100%;
    height: 100%;
    transform-origin: center;
}

/* Editor Specific Styles */
.editor-main {
    display: flex;
    flex: 1;
    position: relative;
    padding: 0;
    min-height: 0;
}

.toolbar-side {
    position: absolute;
    left: 15px;
    top: 15px;
    bottom: 15px;
    width: 130px;
    z-index: 10;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    overflow-y: auto;
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
}

.tool-section {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(255, 255, 255, 0.03);
    border-radius: 8px;
    overflow: hidden;
    transition: all 0.3s ease;
    margin: 0 6px;
}

.tool-header {
    width: 100%;
    padding: 8px 0;
    background: transparent;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    color: rgba(255, 255, 255, 0.7);
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    gap: 4px;
    transition: color 0.2s ease, background 0.2s ease;
}

.tool-header:hover {
    color: rgba(255, 255, 255, 1);
    background: rgba(255, 255, 255, 0.05);
}

.tool-header::after {
    content: "▼";
    font-size: 8px;
    transition: transform 0.3s ease;
}

.tool-section:not(.open) .tool-header::after {
    transform: rotate(-90deg);
}

.tool-section .tool-group {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
    padding: 6px;
    justify-items: center;
    max-height: 1000px;
    opacity: 1;
    transition: all 0.3s ease;
}

.tool-section:not(.open) .tool-group {
    max-height: 0;
    padding-top: 0;
    padding-bottom: 0;
    opacity: 0;
    pointer-events: none;
    overflow: hidden;
}

.tool-group {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
    width: 100%;
}

.tool-group.bottom {
    margin-top: auto;
}

.user-profile img {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
}

.kbd-indicator {
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 10px;
    font-weight: 600;
    color: white;
    background-color: #10b981;
    margin-right: 8px;
    display: inline-block;
}

.tool-btn {
    width: 36px;
    height: 36px;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(255, 255, 255, 0.05);
    color: var(--text);
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.tool-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: translateY(-2px);
}

/* Global JS Tooltip */
#global-tooltip {
    position: fixed;
    background: rgba(15, 23, 42, 0.95);
    color: #fff;
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 12px;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    z-index: 99999;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 4px 6px rgba(0,0,0,0.3);
}

.tool-btn.active {
    background: var(--accent);
    color: var(--surface);
    border-color: var(--accent);
}

.tool-btn svg {
    width: 20px;
    height: 20px;
}

.canvas-container {
    flex: 1;
    position: relative;
    overflow: hidden;
    padding: 0;
    background: #1e2128;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

#layer-panel-container {
    position: absolute;
    right: 15px;
    top: 15px;
    bottom: 15px;
    width: 250px;
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    z-index: 10;
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
}

#cad-canvas {
    width: 100%;
    height: 100%;
    cursor: crosshair;
}

/* Top Menu Bar */
.top-menu-bar {
    display: flex;
    gap: 8px;
    height: 100%;
    align-items: center;
    margin-right: auto;
}

.top-menu-item {
    position: relative;
    padding: 6px 12px;
    cursor: pointer;
    border-radius: 6px;
    transition: background 0.2s ease;
}

.top-menu-item:hover {
    background: rgba(255, 255, 255, 0.1);
}

.menu-label {
    font-size: 14px;
    font-weight: 500;
    color: rgba(255,255,255,0.85);
    letter-spacing: 0.3px;
}

.top-menu-item:hover .menu-label {
    color: white;
}

.top-menu-dropdown {
    position: absolute;
    top: calc(100% + 5px);
    left: 0;
    background: rgba(15, 23, 42, 0.95);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid rgba(255,255,255,0.15);
    border-radius: 8px;
    min-width: 220px;
    z-index: 1000;
    box-shadow: 0 10px 25px rgba(0,0,0,0.5);
    display: flex;
    flex-direction: column;
    padding: 6px 0;
    
    /* Animation */
    opacity: 0;
    visibility: hidden;
    transform: translateY(10px);
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.top-menu-item:hover .top-menu-dropdown {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.menu-action {
    display: flex;
    align-items: center;
    padding: 8px 16px;
    color: rgba(255,255,255,0.8);
    text-decoration: none;
    font-size: 13px;
    gap: 12px;
    transition: all 0.2s ease;
    cursor: pointer;
}

.menu-action svg {
    width: 16px;
    height: 16px;
    opacity: 0.7;
}

.menu-action:hover {
    background: var(--accent);
    color: var(--surface);
}

.menu-action:hover svg {
    opacity: 1;
}

.menu-action .shortcut {
    margin-left: auto;
    font-size: 11px;
    opacity: 0.5;
}

.menu-action:hover .shortcut {
    opacity: 0.8;
}

.menu-divider {
    height: 1px;
    background: rgba(255,255,255,0.1);
    margin: 4px 0;
}

@media print {
    @page {
        size: A3 landscape;
        margin: 0;
    }
    body * {
        visibility: hidden;
    }
    #cad-canvas, #cad-canvas * {
        visibility: visible;
    }
    #cad-canvas {
        position: absolute;
        left: 0;
        top: 0;
        width: 100vw;
        height: 100vh;
    }
    /* Hide grid and UI elements during print */
    .toolbar-side, .glass-header, .layer-panel, .property-panel, #dynamic-input-container {
        display: none !important;
    }
}

/* ==========================================================================
   Context Menu Styles (Glassmorphism)
   ========================================================================== */
.cad-context-menu {
    position: fixed;
    background: rgba(30, 34, 43, 0.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.5), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
    border-radius: 8px;
    padding: 6px 0;
    min-width: 220px;
    z-index: 99999;
    color: #e2e8f0;
    font-family: 'Inter', 'Kanit', sans-serif;
    font-size: 13px;
    display: flex;
    flex-direction: column;
}

.context-menu-item {
    display: flex;
    align-items: center;
    padding: 8px 16px;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
    position: relative;
}

.context-menu-item:hover {
    background: rgba(16, 185, 129, 0.15); /* Accent color tint */
    color: #10b981;
}

.context-menu-item.danger:hover {
    background: rgba(239, 68, 68, 0.15);
    color: #ef4444;
}

.context-menu-item svg {
    width: 16px;
    height: 16px;
    margin-right: 12px;
    opacity: 0.7;
}

.context-menu-item:hover svg {
    opacity: 1;
}

.context-menu-item span {
    flex: 1;
    white-space: nowrap;
}

.context-menu-item .shortcut {
    color: #64748b;
    font-size: 11px;
    margin-left: 16px;
    background: rgba(255, 255, 255, 0.05);
    padding: 2px 6px;
    border-radius: 4px;
    flex: 0 0 auto;
}

.context-menu-item:hover .shortcut {
    color: #10b981;
    background: rgba(16, 185, 129, 0.1);
}

.context-menu-divider {
    height: 1px;
    background: rgba(255, 255, 255, 0.1);
    margin: 4px 0;
}

/* Nested Submenu */
.context-menu-item.has-submenu .submenu-arrow {
    margin-left: 12px;
    margin-right: 0;
    width: 14px;
    height: 14px;
}

.context-submenu {
    position: absolute;
    top: -6px;
    left: 100%;
    background: rgba(30, 34, 43, 0.95);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.5);
    border-radius: 8px;
    padding: 6px 0;
    min-width: 180px;
    display: none;
    max-height: 300px;
    overflow-y: auto;
}

.context-menu-item.has-submenu:hover .context-submenu {
    display: flex;
    flex-direction: column;
}

/* Layer item in submenu */
.context-layer-item {
    display: flex;
    align-items: center;
    padding: 8px 16px;
    cursor: pointer;
}
.context-layer-item:hover {
    background: rgba(255, 255, 255, 0.05);
}
.context-layer-color {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    margin-right: 12px;
}

/* Sheet Tabs */
#sheet-tabs-bar {
    scrollbar-width: none;
    -ms-overflow-style: none;
}
#sheet-tabs-bar::-webkit-scrollbar {
    display: none;
}

.sheet-tab {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-bottom: none;
    border-radius: 6px 6px 0 0;
    color: rgba(255, 255, 255, 0.6);
    padding: 6px 16px;
    cursor: pointer;
    font-family: inherit;
    font-size: 13px;
    white-space: nowrap;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 8px;
    outline: none;
}

.sheet-tab:hover {
    background: rgba(255, 255, 255, 0.1);
    color: white;
}

.sheet-tab.active {
    background: var(--bg-card, #1e293b);
    color: var(--accent, #0ea5e9);
    font-weight: 500;
    border-top: 2px solid var(--accent, #0ea5e9);
}
