/* CutArc - Mobile-First Responsive Styles */

/* CSS Custom Properties */
:root {
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --secondary-color: #64748b;
    --background: #0f172a;
    --surface: #1e293b;
    --surface-light: #334155;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --border-color: #475569;
    --success: #22c55e;
    --warning: #f59e0b;
    --error: #ef4444;
    --rapid-color: #22c55e;
    --cut-color: #ef4444;
    --leadin-color: #f59e0b;
    --shape-color: #64748b;
    --radius: 8px;
    --spacing-xs: 4px;
    --spacing-sm: 8px;
    --spacing-md: 16px;
    --spacing-lg: 24px;
}

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

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background-color: var(--background);
    color: var(--text-primary);
    line-height: 1.5;
    min-height: 100vh;
    overflow-x: hidden;
}

/* App Container */
.app-container {
    max-width: 100%;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--spacing-md);
    background: var(--surface);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 100;
}

.app-title {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary-color);
}

.unit-toggle {
    display: flex;
    background: var(--surface-light);
    border-radius: var(--radius);
    overflow: hidden;
}

.unit-btn {
    padding: var(--spacing-sm) var(--spacing-md);
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.unit-btn.active {
    background: var(--primary-color);
    color: white;
}

.unit-btn:not(.active):hover {
    background: var(--border-color);
}

/* Shape Selector */
.shape-selector {
    display: flex;
    justify-content: center;
    gap: var(--spacing-sm);
    padding: var(--spacing-md);
    background: var(--surface);
    border-bottom: 1px solid var(--border-color);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.shape-btn {
    width: 48px;
    height: 48px;
    padding: var(--spacing-sm);
    border: 2px solid var(--border-color);
    border-radius: var(--radius);
    background: var(--surface-light);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.shape-btn svg {
    width: 100%;
    height: 100%;
}

.shape-btn.active {
    border-color: var(--primary-color);
    background: rgba(37, 99, 235, 0.2);
    color: var(--primary-color);
}

.shape-btn:not(.active):hover {
    border-color: var(--text-secondary);
    color: var(--text-primary);
}

/* Preview Container */
.preview-container {
    position: relative;
    background: var(--surface);
    border-bottom: 1px solid var(--border-color);
    aspect-ratio: 4 / 3;
    max-height: 300px;
    touch-action: none;
}

#preview-canvas {
    width: 100%;
    height: 100%;
    display: block;
}

.preview-controls {
    position: absolute;
    bottom: var(--spacing-sm);
    right: var(--spacing-sm);
    display: flex;
    gap: var(--spacing-xs);
}

.preview-controls button {
    width: 36px;
    height: 36px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text-primary);
    font-size: 1rem;
    cursor: pointer;
    opacity: 0.8;
    transition: opacity 0.2s;
}

.preview-controls button:hover:not(:disabled) {
    opacity: 1;
    background: var(--surface-light);
}

.preview-controls button:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.preview-controls button.active {
    background: var(--primary-color);
    border-color: var(--primary-color);
}

/* Trim mode button - orange/warning color when active */
#trim-mode.active {
    background: #f97316;
    border-color: #f97316;
}

.preview-controls button svg {
    display: block;
}

.control-divider {
    width: 1px;
    height: 24px;
    background: var(--border-color);
    margin: 0 4px;
}

.preview-hint {
    position: absolute;
    top: var(--spacing-sm);
    left: 50%;
    transform: translateX(-50%);
    padding: 6px 12px;
    background: rgba(37, 99, 235, 0.9);
    color: white;
    font-size: 0.75rem;
    font-weight: 500;
    border-radius: var(--radius);
    pointer-events: none;
    opacity: 0.9;
    transition: opacity 0.3s;
}

.preview-hint.hidden {
    opacity: 0;
}

/* Trace Image Bar */
.trace-image-bar {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
    padding: var(--spacing-sm) var(--spacing-md);
    background: var(--surface);
    border-bottom: 1px solid var(--border-color);
    flex-wrap: wrap;
}

.trace-upload-btn {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    padding: var(--spacing-sm) var(--spacing-md);
    background: var(--surface-light);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    color: var(--text-secondary);
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.2s;
}

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

.trace-controls {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
    flex: 1;
}

.trace-controls.hidden {
    display: none;
}

.trace-opacity-label,
.trace-scale-label {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.trace-opacity-label input[type="range"] {
    width: 80px;
    height: 4px;
    cursor: pointer;
}

.trace-scale-label input {
    width: 60px;
    padding: 4px 8px;
    min-height: auto;
}

#clear-trace-image {
    width: 28px;
    height: 28px;
    padding: 0;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.875rem;
}

#clear-trace-image:hover {
    background: var(--error);
    border-color: var(--error);
    color: white;
}

/* Custom Path Controls */
.custom-path-instructions {
    padding: var(--spacing-md);
    background: rgba(37, 99, 235, 0.1);
    border: 1px solid var(--primary-color);
    border-radius: var(--radius);
    color: var(--primary-color);
    font-size: 0.875rem;
    text-align: center;
}

.custom-path-controls {
    display: flex;
    gap: var(--spacing-sm);
    flex-wrap: wrap;
}

.custom-path-controls .secondary-btn {
    flex: 1;
    min-width: 100px;
}

.secondary-btn {
    padding: var(--spacing-sm) var(--spacing-md);
    background: var(--surface-light);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.2s;
}

.secondary-btn:hover:not(:disabled) {
    background: var(--border-color);
}

.secondary-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.custom-point-count {
    font-size: 0.875rem;
    color: var(--text-secondary);
    text-align: center;
    padding: var(--spacing-sm);
}

.text-preview-label {
    font-size: 0.875rem;
    color: var(--text-secondary);
    padding: var(--spacing-sm);
    background: var(--surface);
    border-radius: var(--radius);
    text-align: center;
}

.text-preview-label span {
    color: var(--primary-color);
    font-weight: 600;
}

#custom-points[readonly] {
    background: var(--surface);
    cursor: default;
}

/* Sidebar Tabs */
.sidebar-tabs {
    display: flex;
    flex-direction: column;
    background: var(--surface);
    overflow: hidden;
}

.tab-buttons {
    display: flex;
    background: var(--surface-light);
    border-bottom: 2px solid var(--border-color);
    flex-shrink: 0;
}

.tab-btn {
    flex: 1;
    padding: 12px 8px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
}

.tab-btn:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.05);
}

.tab-btn.active {
    color: var(--primary-color);
    background: var(--surface);
}

.tab-btn.active::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--primary-color);
}

.tab-content {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
}

.tab-panel {
    display: none;
    padding: var(--spacing-md);
}

.tab-panel.active {
    display: block;
}

/* Section spacing within tabs */
.tab-panel > * + * {
    margin-top: var(--spacing-md);
}

.tab-panel .param-section {
    margin: 0;
}

.tab-panel .param-section + .param-section {
    margin-top: var(--spacing-md);
}

/* Shape List Panel */
.shape-list-panel {
    background: var(--surface-light);
    border-radius: var(--radius);
    max-height: 180px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.shape-list-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--spacing-sm) var(--spacing-md);
    background: var(--surface-light);
    font-weight: 600;
    font-size: 0.875rem;
}

.shape-list-header button {
    padding: 4px 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.75rem;
    cursor: pointer;
    transition: all 0.2s;
}

.shape-list-header button:hover {
    background: var(--error);
    border-color: var(--error);
    color: white;
}

.shape-list {
    flex: 1;
    overflow-y: auto;
    padding: var(--spacing-sm);
}

.shape-list-empty {
    color: var(--text-secondary);
    font-size: 0.875rem;
    text-align: center;
    padding: var(--spacing-lg);
    font-style: italic;
}

.shape-item {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    padding: var(--spacing-sm) var(--spacing-md);
    background: var(--background);
    border: 2px solid var(--border-color);
    border-radius: var(--radius);
    margin-bottom: var(--spacing-sm);
    cursor: pointer;
    transition: all 0.2s;
}

.shape-item:hover {
    border-color: var(--text-secondary);
}

.shape-item.selected {
    border-color: var(--primary-color);
    background: rgba(37, 99, 235, 0.1);
}

.shape-item-icon {
    width: 24px;
    height: 24px;
    color: var(--text-secondary);
    flex-shrink: 0;
}

.shape-item.selected .shape-item-icon {
    color: var(--primary-color);
}

.shape-item-info {
    flex: 1;
    min-width: 0;
}

.shape-item-type {
    font-weight: 600;
    font-size: 0.875rem;
    text-transform: capitalize;
}

.shape-item-dims {
    font-size: 0.75rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.shape-item-actions {
    display: flex;
    gap: 4px;
}

.shape-item-actions button {
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 4px;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.shape-item-actions button:hover {
    background: var(--surface-light);
    color: var(--text-primary);
}

.shape-item-actions button.delete-btn:hover {
    background: var(--error);
    color: white;
}

/* Parameters Panel */
.params-panel {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: var(--spacing-md);
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
    min-height: 400px;
}

.param-section {
    background: var(--surface);
    border-radius: var(--radius);
    border: 1px solid var(--border-color);
    overflow: visible;
}

.param-section summary {
    padding: var(--spacing-md);
    font-weight: 600;
    cursor: pointer;
    background: var(--surface-light);
    user-select: none;
    list-style: none;
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.param-section summary::before {
    content: '▶';
    font-size: 0.75rem;
    transition: transform 0.2s;
}

.param-section[open] summary::before {
    transform: rotate(90deg);
}

.param-content {
    padding: var(--spacing-lg);
    display: flex;
    flex-direction: column;
    gap: var(--spacing-lg);
    overflow: visible;
}

.param-content label {
    overflow: visible;
}

.param-group {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
}

.param-group.hidden {
    display: none;
}

/* Form Elements */
label {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
}

label > span {
    font-size: 1rem;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.input-with-unit {
    display: flex;
    align-items: stretch;
    width: 100%;
    overflow: visible;
}

.input-with-unit input {
    flex: 1;
    border-radius: var(--radius) 0 0 var(--radius);
    border-right: none;
    min-width: 80px;
}

.input-with-unit .unit-label {
    padding: 12px 16px;
    background: var(--surface-light);
    border: 2px solid var(--border-color);
    border-left: none;
    border-radius: 0 var(--radius) var(--radius) 0;
    color: var(--text-secondary);
    font-size: 1rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    min-width: 60px;
    justify-content: center;
}

input[type="number"],
input[type="text"],
select,
textarea {
    padding: 12px 16px;
    background: var(--background);
    border: 2px solid var(--border-color);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 1.125rem;
    font-weight: 500;
    width: 100%;
    min-height: 48px;
    transition: border-color 0.2s;
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--primary-color);
}

select {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2394a3b8' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
}

textarea {
    resize: vertical;
    min-height: 100px;
    font-family: 'SF Mono', Monaco, 'Courier New', monospace;
    font-size: 0.875rem;
}

.checkbox-label {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: var(--spacing-sm);
    cursor: pointer;
}

.checkbox-label input[type="checkbox"] {
    width: 20px;
    height: 20px;
    cursor: pointer;
}

/* Material Settings */
.param-row {
    display: flex;
    gap: var(--spacing-sm);
}

.param-row .half-width {
    flex: 1;
    min-width: 0;
}

.bounds-warning {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    padding: var(--spacing-sm) var(--spacing-md);
    background: rgba(239, 68, 68, 0.15);
    border: 1px solid var(--error);
    border-radius: var(--radius);
    color: var(--error);
    font-size: 0.875rem;
    font-weight: 500;
    margin-top: var(--spacing-sm);
}

.bounds-warning.hidden {
    display: none;
}

.bounds-warning svg {
    flex-shrink: 0;
}

/* Project Bar */
.project-bar {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    padding: var(--spacing-md);
    background: var(--surface-light);
    border-radius: var(--radius);
}

.project-label {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-right: var(--spacing-xs);
}

.project-bar .secondary-btn {
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
    padding: var(--spacing-sm) var(--spacing-md);
    font-size: 0.875rem;
}

.project-bar .import-btn {
    cursor: pointer;
}

/* Action Bar */
.action-bar {
    padding: var(--spacing-md);
    background: var(--surface-light);
    border-radius: var(--radius);
}

.gcode-units-row {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    margin-bottom: var(--spacing-sm);
    font-size: 0.85rem;
}

.gcode-units-row label {
    color: var(--text-muted);
    white-space: nowrap;
}

.gcode-units-row select {
    flex: 1;
    padding: var(--spacing-xs) var(--spacing-sm);
    background: var(--background);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    color: var(--text-color);
    font-size: 0.85rem;
    cursor: pointer;
}

.gcode-units-row select:focus {
    outline: none;
    border-color: var(--primary-color);
}

.primary-btn {
    width: 100%;
    padding: var(--spacing-md);
    background: var(--primary-color);
    border: none;
    border-radius: var(--radius);
    color: white;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

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

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

/* Estimation Panel */
#estimation-panel {
    background: var(--surface-light);
    border-radius: var(--radius);
    overflow: hidden;
}

#estimation-panel .panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--spacing-md);
    background: var(--surface-light);
    cursor: pointer;
    user-select: none;
    font-size: 0.875rem;
    font-weight: 500;
}

#estimation-panel .panel-header:hover {
    background: var(--border-color);
}

#estimation-panel .panel-toggle {
    transition: transform 0.2s ease;
    color: var(--text-secondary);
}

#estimation-panel.collapsed .panel-toggle {
    transform: rotate(-90deg);
}

#estimation-panel.collapsed .panel-content {
    display: none;
}

#estimation-panel .panel-content {
    padding: var(--spacing-md);
}

.estimation-stats {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
    margin-bottom: var(--spacing-md);
}

.stat-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--spacing-xs) 0;
}

.stat-row.highlight {
    background: var(--surface-light);
    padding: var(--spacing-sm);
    border-radius: var(--radius);
    margin-top: var(--spacing-xs);
}

.stat-label {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.stat-value {
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--text-primary);
}

.stat-row.highlight .stat-value {
    color: var(--success);
    font-size: 1rem;
}

.estimation-cost {
    border-top: 1px solid var(--border-color);
    padding-top: var(--spacing-md);
}

.estimation-cost .section-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-bottom: var(--spacing-sm);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.estimation-cost .input-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--spacing-sm);
}

.estimation-cost .input-row label {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.estimation-cost .input-with-unit {
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
}

.estimation-cost .currency-symbol {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.estimation-cost input {
    width: 80px;
    padding: var(--spacing-xs) var(--spacing-sm);
    background: var(--background);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 0.875rem;
    text-align: right;
}

.estimation-cost .unit-label {
    color: var(--text-secondary);
    font-size: 0.75rem;
}

/* G-Code Output */
.gcode-output {
    background: var(--surface-light);
    border-radius: var(--radius);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.gcode-header {
    display: flex;
    justify-content: space-between;
    padding: var(--spacing-md);
    background: var(--surface-light);
    font-size: 0.875rem;
}

.gcode-header span:last-child {
    color: var(--text-secondary);
}

#gcode-display {
    padding: var(--spacing-md);
    background: var(--background);
    font-family: 'SF Mono', Monaco, 'Courier New', monospace;
    font-size: 0.75rem;
    line-height: 1.6;
    overflow-x: auto;
    max-height: 200px;
    overflow-y: auto;
    white-space: pre;
    color: var(--text-secondary);
    min-height: 100px;
}

#gcode-display:empty::before {
    content: 'G-code will appear here after generation...';
    color: var(--text-secondary);
    font-style: italic;
}

.export-buttons {
    display: flex;
    gap: var(--spacing-sm);
    padding: var(--spacing-md);
}

.export-buttons button {
    flex: 1;
    padding: var(--spacing-sm) var(--spacing-md);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    background: var(--surface-light);
    color: var(--text-primary);
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.2s;
}

.export-buttons button:hover:not(:disabled) {
    background: var(--border-color);
}

.export-buttons button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Design Export Section */
.design-export {
    margin-top: var(--spacing-md);
    padding: var(--spacing-md);
    background: var(--surface-dark);
    border-radius: var(--radius);
}

.design-export .section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--spacing-sm);
    font-weight: 500;
}

.design-export-buttons {
    padding: 0;
}

.design-export-buttons .export-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-xs);
}

.design-export-buttons .export-btn svg {
    flex-shrink: 0;
}

.tier-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.7rem;
    font-weight: 500;
    text-transform: uppercase;
}

.tier-badge.tier-free {
    background: #555;
    color: #fff;
}

.tier-badge.tier-basic {
    background: #2196f3;
    color: #fff;
}

.tier-badge.tier-pro {
    background: #9c27b0;
    color: #fff;
}

.tier-badge.tier-enterprise {
    background: #ff9800;
    color: #000;
}

.upgrade-hint {
    margin-top: var(--spacing-sm);
    padding: var(--spacing-sm);
    background: rgba(255, 152, 0, 0.1);
    border-radius: var(--radius);
    font-size: 0.75rem;
    color: var(--warning);
    text-align: center;
}

/* Utility Classes */
.hidden {
    display: none !important;
}

/* Tablet and Desktop Styles */
@media (min-width: 768px) {
    .app-container {
        max-width: 600px;
        margin: 0 auto;
        border-left: 1px solid var(--border-color);
        border-right: 1px solid var(--border-color);
    }

    .preview-container {
        max-height: 400px;
    }

    .shape-btn {
        width: 56px;
        height: 56px;
    }

    #gcode-display {
        max-height: 300px;
        font-size: 0.875rem;
    }
}

@media (min-width: 1024px) {
    .app-container {
        max-width: 1400px;
        display: grid;
        grid-template-columns: 3fr 2fr;
        grid-template-rows: auto auto 1fr;
    }

    .app-header {
        grid-column: 1 / -1;
    }

    .shape-selector {
        grid-column: 1 / -1;
    }

    .preview-container {
        grid-column: 1;
        grid-row: 3;
        max-height: none;
        aspect-ratio: auto;
        min-height: 500px;
    }

    .sidebar-tabs {
        grid-column: 2;
        grid-row: 3;
        max-height: calc(100vh - 200px);
        overflow: hidden;
    }

    .tab-content {
        max-height: calc(100vh - 250px);
        overflow-y: auto;
    }

    #gcode-display {
        max-height: 200px;
    }
}

/* Wider screens - even more canvas space */
@media (min-width: 1400px) {
    .app-container {
        max-width: 1800px;
        grid-template-columns: 2fr 1fr;
    }

    .preview-container {
        min-height: 600px;
    }

    .sidebar-tabs {
        max-height: calc(100vh - 180px);
    }

    .tab-content {
        max-height: calc(100vh - 230px);
    }
}

/* Touch-friendly adjustments */
@media (hover: none) and (pointer: coarse) {
    .shape-btn {
        width: 52px;
        height: 52px;
    }

    input[type="number"],
    select {
        font-size: 16px; /* Prevents iOS zoom on focus */
        padding: var(--spacing-md);
    }

    .primary-btn {
        padding: var(--spacing-lg);
    }
}

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

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

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

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

/* Selection styling */
::selection {
    background: var(--primary-color);
    color: white;
}

/* Modal Styles */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: var(--spacing-md);
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: var(--surface);
    border-radius: var(--radius);
    max-width: 400px;
    width: 100%;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    border: 1px solid var(--border-color);
}

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

.modal-header h3 {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0;
    line-height: 1;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius);
}

.modal-close:hover {
    color: var(--text-primary);
    background: var(--surface-light);
}

.modal-body {
    padding: var(--spacing-md);
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: var(--spacing-sm);
    padding: var(--spacing-md);
    border-top: 1px solid var(--border-color);
}

/* Projects Modal */
.projects-modal {
    max-width: 500px;
}

.projects-modal .modal-header {
    gap: var(--spacing-sm);
}

.project-count {
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin-left: auto;
    margin-right: var(--spacing-md);
}

.projects-list {
    max-height: 400px;
    overflow-y: auto;
    min-height: 100px;
}

.projects-empty {
    text-align: center;
    color: var(--text-secondary);
    padding: var(--spacing-lg);
    font-style: italic;
}

.project-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--spacing-md);
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    transition: background 0.2s;
}

.project-item:hover {
    background: var(--surface-light);
}

.project-item:last-child {
    border-bottom: none;
}

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

.project-item-name {
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.project-item-date {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.project-item-actions {
    display: flex;
    gap: var(--spacing-xs);
    flex-shrink: 0;
}

.project-item-actions button {
    padding: var(--spacing-xs) var(--spacing-sm);
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.75rem;
    transition: all 0.2s;
}

.project-item-actions button:hover {
    background: var(--surface-light);
    color: var(--text-primary);
}

.project-item-actions .delete-btn:hover {
    background: var(--error);
    border-color: var(--error);
    color: white;
}

/* Project name display in header */
.project-name {
    font-size: 0.875rem;
    color: var(--primary-color);
    font-weight: 500;
    max-width: 120px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.array-inputs {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
}

.array-inputs .input-row {
    display: flex;
    gap: var(--spacing-md);
}

.array-inputs label {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: var(--spacing-xs);
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.array-inputs input[type="number"] {
    padding: var(--spacing-sm);
    background: var(--background);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 1rem;
    width: 100%;
}

.array-inputs .checkbox-row {
    flex-direction: row;
}

.array-inputs .checkbox-row label {
    flex-direction: row;
    align-items: center;
    gap: var(--spacing-sm);
    cursor: pointer;
}

.array-inputs input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

.array-preview-info {
    display: flex;
    justify-content: space-between;
    margin-top: var(--spacing-md);
    padding: var(--spacing-sm);
    background: var(--background);
    border-radius: var(--radius);
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.secondary-btn {
    padding: var(--spacing-sm) var(--spacing-md);
    background: var(--surface-light);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    color: var(--text-primary);
    cursor: pointer;
    font-size: 0.875rem;
}

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

/* Section Divider */
.section-divider {
    border: none;
    border-top: 1px solid var(--border-color);
    margin: var(--spacing-md) 0;
}

/* Auto-Nest Button */
.nest-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-xs);
    width: 100%;
    padding: var(--spacing-sm) var(--spacing-md);
    background: var(--info);
    border: none;
    border-radius: var(--radius);
    color: white;
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    transition: background 0.2s;
}

.nest-btn:hover {
    background: #2563eb;
}

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

/* Cut Simulation Styles */
.simulation-controls {
    padding: var(--spacing-md);
    background: var(--surface-light);
    border-radius: var(--radius);
}

.simulation-controls hr.section-divider {
    display: none;
}

.simulation-header {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: var(--spacing-sm);
}

.simulation-row {
    display: flex;
    gap: var(--spacing-sm);
    margin-bottom: var(--spacing-sm);
}

.simulate-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-xs);
    padding: var(--spacing-sm) var(--spacing-md);
    background: var(--success);
    border: none;
    border-radius: var(--radius);
    color: white;
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    transition: background 0.2s;
}

.simulate-btn:hover {
    background: #16a34a;
}

.simulate-btn:disabled {
    background: var(--text-muted);
    cursor: not-allowed;
}

.sim-speed-select {
    width: 70px;
    padding: var(--spacing-xs) var(--spacing-sm);
    font-size: 0.875rem;
}

.sim-control-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-xs);
    padding: var(--spacing-sm);
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    color: var(--text-primary);
    cursor: pointer;
    font-size: 0.8rem;
    transition: background 0.2s;
}

.sim-control-btn:hover {
    background: var(--background);
}

.sim-stop-btn {
    background: var(--danger);
    border-color: var(--danger);
    color: white;
}

.sim-stop-btn:hover {
    background: #dc2626;
}

.sim-running-controls.hidden,
.simulate-btn.hidden {
    display: none !important;
}

.progress-container {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.progress-bar {
    flex: 1;
    height: 8px;
    background: var(--surface);
    border-radius: 4px;
    overflow: hidden;
    border: 1px solid var(--border-color);
}

.progress-fill {
    height: 100%;
    width: 0%;
    background: var(--success);
    transition: width 0.1s linear;
}

.progress-text {
    font-size: 0.75rem;
    color: var(--text-muted);
    min-width: 35px;
    text-align: right;
}

/* Auto Trace Styles */
.trace-divider {
    width: 1px;
    height: 24px;
    background: var(--border-color);
    margin: 0 var(--spacing-xs);
}

.auto-trace-btn {
    padding: var(--spacing-xs) var(--spacing-sm);
    background: var(--warning);
    border: none;
    border-radius: var(--radius);
    color: var(--background);
    cursor: pointer;
    font-size: 0.75rem;
    font-weight: 600;
    white-space: nowrap;
}

.auto-trace-btn:hover {
    background: #d97706;
}

.auto-trace-modal {
    max-width: 600px;
}

.trace-preview-container {
    background: var(--background);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    margin-bottom: var(--spacing-md);
    overflow: hidden;
    position: relative;
}

#trace-preview-canvas {
    width: 100%;
    height: 250px;
    display: block;
}

.trace-settings {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
}

.trace-settings .input-group {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.trace-settings label {
    min-width: 80px;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.trace-settings input[type="range"] {
    flex: 1;
    height: 6px;
    -webkit-appearance: none;
    appearance: none;
    background: var(--surface-light);
    border-radius: 3px;
    cursor: pointer;
}

.trace-settings input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    background: var(--primary-color);
    border-radius: 50%;
    cursor: pointer;
}

.trace-settings input[type="range"]::-moz-range-thumb {
    width: 16px;
    height: 16px;
    background: var(--primary-color);
    border-radius: 50%;
    cursor: pointer;
    border: none;
}

.trace-settings span {
    min-width: 40px;
    text-align: right;
    font-size: 0.875rem;
    color: var(--text-primary);
}

.trace-settings .checkbox-group {
    display: flex;
    align-items: center;
}

.trace-settings .checkbox-group label {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    cursor: pointer;
    min-width: auto;
}

.trace-settings .checkbox-group input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

/* ==========================================
   User Menu & Authentication
   ========================================== */

.header-controls {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
}

.user-menu {
    display: flex;
    align-items: center;
}

.user-btn {
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
    padding: var(--spacing-xs) var(--spacing-sm);
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 0.875rem;
    cursor: pointer;
    transition: background 0.2s;
}

.user-btn:hover {
    background: var(--surface-light);
}

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

.user-info {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.user-name {
    font-weight: 500;
    color: var(--text-primary);
}

.user-tier {
    padding: 2px 6px;
    background: var(--primary-color);
    border-radius: 4px;
    font-size: 0.75rem;
    text-transform: uppercase;
}

.user-tier.free { background: var(--secondary-color); }
.user-tier.basic { background: var(--success); }
.user-tier.pro { background: var(--primary-color); }
.user-tier.enterprise { background: var(--warning); color: #000; }

.logout-btn {
    padding: var(--spacing-xs) var(--spacing-sm);
    background: transparent;
    border: 1px solid var(--error);
    border-radius: var(--radius);
    color: var(--error);
    font-size: 0.75rem;
    cursor: pointer;
    transition: background 0.2s;
}

.logout-btn:hover {
    background: var(--error);
    color: white;
}

/* Auth Modal */
.auth-modal {
    width: 100%;
    max-width: 400px;
}

.auth-tabs {
    display: flex;
    margin-bottom: var(--spacing-md);
    border-bottom: 1px solid var(--border-color);
}

.auth-tab {
    flex: 1;
    padding: var(--spacing-sm) var(--spacing-md);
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-secondary);
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.2s;
}

.auth-tab:hover {
    color: var(--text-primary);
}

.auth-tab.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
}

.auth-form .input-group {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-xs);
}

.auth-form label {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.auth-form input {
    padding: var(--spacing-sm) var(--spacing-md);
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 1rem;
}

.auth-form input:focus {
    outline: none;
    border-color: var(--primary-color);
}

.auth-error {
    padding: var(--spacing-sm);
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid var(--error);
    border-radius: var(--radius);
    color: var(--error);
    font-size: 0.875rem;
}

.auth-submit {
    width: 100%;
    padding: var(--spacing-sm) var(--spacing-md);
    margin-top: var(--spacing-sm);
}

/* Responsive adjustments */
@media (max-width: 480px) {
    .user-btn span {
        display: none;
    }

    .header-controls {
        gap: var(--spacing-sm);
    }
}

/* ==========================================
   Login Gate - Full Screen Auth Wall
   ========================================== */

.login-gate {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, var(--background) 0%, #1a1a2e 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
}

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

.login-gate-content {
    width: 100%;
    max-width: 400px;
    padding: var(--spacing-lg);
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.login-gate-logo {
    text-align: center;
    margin-bottom: var(--spacing-lg);
    color: var(--primary-color);
}

.login-gate-logo svg {
    margin-bottom: var(--spacing-sm);
}

.login-gate-logo h1 {
    font-size: 1.75rem;
    margin-bottom: var(--spacing-xs);
    color: var(--text-primary);
}

.login-gate-logo p {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.login-gate-tabs {
    display: flex;
    margin-bottom: var(--spacing-md);
    border-bottom: 1px solid var(--border-color);
}

.gate-tab {
    flex: 1;
    padding: var(--spacing-sm) var(--spacing-md);
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-secondary);
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.2s;
}

.gate-tab:hover {
    color: var(--text-primary);
}

.gate-tab.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
}

.gate-form {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
}

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

.gate-form .input-group {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-xs);
}

.gate-form label {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.gate-form input {
    padding: var(--spacing-sm) var(--spacing-md);
    background: var(--background);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 1rem;
}

.gate-form input:focus {
    outline: none;
    border-color: var(--primary-color);
}

.gate-error {
    padding: var(--spacing-sm);
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid var(--error);
    border-radius: var(--radius);
    color: var(--error);
    font-size: 0.875rem;
}

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

.gate-submit {
    width: 100%;
    padding: var(--spacing-md);
    font-size: 1rem;
    margin-top: var(--spacing-sm);
}

.login-gate-footer {
    margin-top: var(--spacing-lg);
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.75rem;
}

/* Loading state */
.login-gate-loading {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 42, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-primary);
}

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

@media (max-width: 480px) {
    .login-gate-content {
        margin: var(--spacing-md);
        padding: var(--spacing-md);
    }
}
