/* ========================================
   WebCAD - Professional CAD Styling
   Dark theme with cyan accents
   ======================================== */

:root {
    /* Color palette - Dark industrial theme */
    --bg-primary: #0d1117;
    --bg-secondary: #161b22;
    --bg-tertiary: #21262d;
    --bg-hover: #30363d;
    --bg-active: #1f6feb20;
    
    --accent-primary: #00d4aa;
    --accent-secondary: #58a6ff;
    --accent-warning: #f0883e;
    --accent-danger: #f85149;
    
    --text-primary: #e6edf3;
    --text-secondary: #8b949e;
    --text-muted: #6e7681;
    
    --border-primary: #30363d;
    --border-secondary: #21262d;
    
    /* Canvas colors */
    --canvas-bg: #0a0e14;
    --grid-major: #1a2332;
    --grid-minor: #111820;
    --crosshair: #00d4aa;
    
    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.5);
    
    /* Spacing */
    --toolbar-height: 56px;
    --panel-width: 280px;
    
    /* Typography */
    --font-ui: 'Outfit', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
    
    /* Transitions */
    --transition-fast: 0.15s ease;
    --transition-normal: 0.25s ease;
}

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

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: var(--font-ui);
    font-size: 14px;
    color: var(--text-primary);
    background: var(--bg-primary);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    position: relative;
}

/* ========================================
   Toolbar
   ======================================== */

.toolbar {
    display: flex;
    align-items: center;
    height: var(--toolbar-height);
    padding: 0 16px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-primary);
    gap: 16px;
    z-index: 100;
}

.toolbar-section {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Brand */
.brand {
    gap: 10px;
    padding-right: 16px;
    border-right: 1px solid var(--border-primary);
}

.logo {
    width: 32px;
    height: 32px;
    color: var(--accent-primary);
    filter: drop-shadow(0 0 8px var(--accent-primary));
}

.brand-name {
    font-size: 18px;
    font-weight: 600;
    letter-spacing: -0.5px;
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* Tool Groups */
.tool-group {
    display: flex;
    gap: 4px;
    padding: 4px;
    background: var(--bg-tertiary);
    border-radius: 8px;
}

.tool-divider {
    width: 1px;
    height: 32px;
    background: var(--border-primary);
    margin: 0 8px;
}

/* Tool Buttons */
.tool-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 6px 12px;
    background: transparent;
    border: none;
    border-radius: 6px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition-fast);
}

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

.tool-btn span {
    font-size: 10px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

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

.tool-btn.active {
    background: var(--accent-primary);
    color: var(--bg-primary);
    box-shadow: 0 0 12px var(--accent-primary);
}

.tool-btn.active svg {
    stroke: var(--bg-primary);
}

/* Action Buttons */
.action-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-primary);
    border-radius: 6px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.action-btn svg {
    width: 18px;
    height: 18px;
}

.action-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    border-color: var(--accent-primary);
}

.action-btn:active {
    transform: scale(0.95);
}

/* Snap Toggle */
.snap-toggle {
    display: flex;
    align-items: center;
}

.snap-toggle input {
    display: none;
}

.snap-toggle label {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-primary);
    border-radius: 6px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.snap-toggle label svg {
    width: 16px;
    height: 16px;
}

.snap-toggle label span {
    font-size: 12px;
    font-weight: 500;
}

.snap-toggle input:checked + label {
    background: var(--accent-primary)20;
    border-color: var(--accent-primary);
    color: var(--accent-primary);
}

/* Ortho Step Input */
.ortho-step {
    display: flex;
    align-items: center;
    gap: 2px;
}

.ortho-step input {
    width: 38px;
    padding: 6px 4px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-primary);
    border-radius: 4px;
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 12px;
    text-align: center;
    /* Hide spinner arrows */
    -moz-appearance: textfield;
}

.ortho-step input::-webkit-outer-spin-button,
.ortho-step input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.ortho-step input:focus {
    outline: none;
    border-color: var(--accent-primary);
}

.ortho-step span {
    color: var(--text-muted);
    font-size: 12px;
}

/* Unit Selector */
.unit-selector select {
    padding: 8px 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-primary);
    border-radius: 6px;
    color: var(--text-primary);
    font-family: var(--font-ui);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238b949e' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
    padding-right: 28px;
}

.unit-selector select:hover {
    border-color: var(--accent-primary);
}

.unit-selector select:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 2px var(--accent-primary)30;
}

.unit-selector select option {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

/* File Controls */
.file-controls {
    margin-left: auto;
}

.file-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-primary);
    border-radius: 6px;
    color: var(--text-secondary);
    font-family: var(--font-ui);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.file-btn svg {
    width: 16px;
    height: 16px;
}

.file-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    border-color: var(--accent-secondary);
}

.file-btn.primary {
    background: linear-gradient(135deg, var(--accent-primary), #00a88a);
    border: none;
    color: var(--bg-primary);
}

.file-btn.primary:hover {
    box-shadow: 0 0 16px var(--accent-primary);
    transform: translateY(-1px);
}

/* ========================================
   Canvas Container
   ======================================== */

.canvas-container {
    flex: 1;
    position: relative;
    overflow: hidden;
    background: var(--canvas-bg);
}

#cadCanvas {
    display: block;
    width: 100%;
    height: 100%;
    cursor: crosshair;
}

/* Coordinates Display */
.coords-display {
    position: absolute;
    bottom: 88px; /* Above history bar + status bar */
    left: 16px;
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 8px 16px;
    background: var(--bg-secondary);
    backdrop-filter: blur(8px);
    border: 1px solid var(--border-primary);
    z-index: 15;
    border-radius: 8px;
    font-family: var(--font-mono);
    font-size: 13px;
}

.coord-item {
    display: flex;
    align-items: center;
    gap: 6px;
}

.coord-label {
    color: var(--text-muted);
    font-weight: 500;
}

.coord-value {
    color: var(--accent-primary);
    min-width: 70px;
}

.coord-divider {
    width: 1px;
    height: 16px;
    background: var(--border-primary);
}

/* Status Bar */
.status-bar {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    align-items: center;
    gap: 16px;
    height: 32px;
    padding: 0 16px;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-primary);
    font-size: 12px;
}

.status-tool {
    color: var(--accent-primary);
    font-weight: 500;
}

.status-hint {
    color: var(--text-muted);
}

/* ========================================
   Dimension Input Panel
   ======================================== */

.dimension-input {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--bg-secondary);
    border: 1px solid var(--border-primary);
    border-radius: 12px;
    padding: 0;
    min-width: 300px;
    box-shadow: var(--shadow-lg);
    z-index: 200;
    display: none;
    animation: slideIn 0.2s ease;
}

.dimension-input.visible {
    display: block;
}

.dimension-input.dragging {
    animation: none;
    user-select: none;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }
}

.dim-input-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-primary);
    background: var(--bg-tertiary);
    border-radius: 12px 12px 0 0;
    cursor: move;
}

.dim-input-header:active {
    cursor: grabbing;
}

.dim-input-title {
    font-weight: 600;
    color: var(--text-primary);
}

.dim-input-close {
    width: 24px;
    height: 24px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all var(--transition-fast);
}

.dim-input-close:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.dim-input-fields {
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

#rectInputFields {
    flex-direction: column;
}

.dim-field {
    display: flex;
    align-items: center;
    gap: 10px;
}

.dim-field label {
    flex: 0 0 60px;
    font-size: 13px;
    color: var(--text-secondary);
    font-weight: 500;
}

.dim-field input {
    flex: 1;
    padding: 10px 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-primary);
    border-radius: 6px;
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 14px;
    transition: all var(--transition-fast);
}

.dim-field input:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 2px var(--accent-primary)30;
}

.dim-field input::placeholder {
    color: var(--text-muted);
}

.dim-unit {
    flex: 0 0 30px;
    font-size: 12px;
    color: var(--text-muted);
    font-family: var(--font-mono);
}

.dim-input-actions {
    display: flex;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid var(--border-primary);
    background: var(--bg-tertiary);
    border-radius: 0 0 12px 12px;
}

.dim-btn {
    flex: 1;
    padding: 10px 16px;
    background: var(--accent-primary);
    border: none;
    border-radius: 6px;
    color: var(--bg-primary);
    font-family: var(--font-ui);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.dim-btn:hover {
    box-shadow: 0 0 12px var(--accent-primary);
}

.dim-btn.secondary {
    background: var(--bg-hover);
    color: var(--text-secondary);
}

.dim-btn.secondary:hover {
    background: var(--border-primary);
    color: var(--text-primary);
    box-shadow: none;
}

/* ========================================
   Save Dialog
   ======================================== */

.save-dialog {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 300;
}

.save-dialog.visible {
    display: flex;
}

.save-dialog-content {
    background: var(--bg-secondary);
    border: 1px solid var(--border-primary);
    border-radius: 12px;
    min-width: 350px;
    box-shadow: var(--shadow-lg);
    animation: slideIn 0.2s ease;
}

.save-dialog-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-primary);
    background: var(--bg-tertiary);
    border-radius: 12px 12px 0 0;
}

.save-dialog-title {
    font-weight: 600;
    font-size: 16px;
    color: var(--text-primary);
}

.save-dialog-body {
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.save-dialog-body .dim-field {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
}

.save-dialog-body .dim-field label {
    font-size: 13px;
    color: var(--text-secondary);
}

.save-dialog-body .dim-field input,
.save-dialog-body .dim-field select {
    padding: 10px 12px;
    font-size: 14px;
}

.save-dialog-actions {
    display: flex;
    gap: 12px;
    padding: 16px 20px;
    border-top: 1px solid var(--border-primary);
    background: var(--bg-tertiary);
    border-radius: 0 0 12px 12px;
}

/* ========================================
   Properties Panel
   ======================================== */

.properties-panel {
    position: absolute;
    top: var(--toolbar-height);
    right: 0;
    width: var(--panel-width);
    height: calc(100% - var(--toolbar-height));
    background: var(--bg-secondary);
    border-left: 1px solid var(--border-primary);
    transform: translateX(100%);
    transition: transform var(--transition-normal);
    z-index: 50;
    display: flex;
    flex-direction: column;
}

.properties-panel.open {
    transform: translateX(0);
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px;
    border-bottom: 1px solid var(--border-primary);
}

.panel-header h3 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
}

.panel-close {
    width: 24px;
    height: 24px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all var(--transition-fast);
}

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

.panel-content {
    flex: 1;
    padding: 16px;
    overflow-y: auto;
}

.no-selection {
    color: var(--text-muted);
    text-align: center;
    padding: 32px 16px;
}

/* Property Items */
.prop-group {
    margin-bottom: 16px;
}

.prop-group-title {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.prop-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

.prop-label {
    flex: 0 0 60px;
    font-size: 12px;
    color: var(--text-secondary);
}

.prop-value {
    flex: 1;
    padding: 6px 10px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-primary);
    border-radius: 4px;
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 12px;
}

.prop-value:focus {
    outline: none;
    border-color: var(--accent-primary);
}

/* ========================================
   Scrollbar Styling
   ======================================== */

::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

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

::-webkit-scrollbar-thumb {
    background: var(--bg-hover);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--border-primary);
}

/* ========================================
   Animations
   ======================================== */

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

@keyframes glow {
    0%, 100% { box-shadow: 0 0 8px var(--accent-primary); }
    50% { box-shadow: 0 0 16px var(--accent-primary); }
}

/* Tool active state animation */
.tool-btn.active {
    animation: glow 2s ease-in-out infinite;
}

/* ========================================
   Responsive adjustments
   ======================================== */

@media (max-width: 1200px) {
    .tool-btn span {
        display: none;
    }
    
    .tool-btn {
        padding: 8px;
    }
    
    .file-btn span {
        display: none;
    }
}

@media (max-width: 768px) {
    .brand-name {
        display: none;
    }
    
    .tool-divider {
        display: none;
    }
    
    .toolbar {
        padding: 0 8px;
        gap: 8px;
    }
}

/* ============================================
   HISTORY BAR
   ============================================ */

.history-bar {
    position: absolute;
    bottom: 32px; /* Just above status bar */
    left: 0;
    right: 0;
    height: 48px;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-primary);
    display: flex;
    align-items: center;
    padding: 4px 8px;
    gap: 4px;
    overflow-x: auto;
    overflow-y: hidden;
    z-index: 10;
}

.history-bar::-webkit-scrollbar {
    height: 4px;
}

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

.history-bar::-webkit-scrollbar-thumb {
    background: rgba(0, 212, 255, 0.3);
    border-radius: 2px;
}

.history-bar::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 212, 255, 0.5);
}

.history-item {
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 3px;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.15s ease;
    border: 1px solid transparent;
    opacity: 0.6;
}

.history-item:hover {
    background: rgba(0, 212, 255, 0.15);
    border-color: rgba(0, 212, 255, 0.3);
    opacity: 1;
}

.history-item.active {
    background: rgba(0, 212, 255, 0.2);
    border-color: rgba(0, 212, 255, 0.6);
    opacity: 1;
}

.history-item.future {
    opacity: 0.3;
}

.history-item.future:hover {
    opacity: 0.6;
}

.history-item canvas {
    border-radius: 2px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.history-item.active canvas {
    border-color: rgba(0, 212, 255, 0.5);
}

.history-label {
    font-size: 9px;
    color: rgba(255, 255, 255, 0.5);
    font-family: 'JetBrains Mono', monospace;
}

.history-item.active .history-label {
    color: #00d4ff;
}

