:root {
    --bg: #1a1a2e;
    --bg2: #16213e;
    --bg3: #0f3460;
    --accent: #e94560;
    --accent2: #ff6b6b;
    --text: #eee;
    --text2: #aab;
    --success: #4ecdc4;
    --warning: #f9a825;
    --border: #2a3a5e;
    --radius: 6px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
    height: 100vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* ==========================================
   Header
   ========================================== */

header {
    background: var(--bg2);
    border-bottom: 1px solid var(--border);
    padding: 8px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    z-index: 10;
}

.header-left { display: flex; align-items: center; gap: 12px; }
.header-right { display: flex; align-items: center; gap: 10px; }

header h1 { font-size: 1.15rem; font-weight: 600; white-space: nowrap; }
header h1 span { color: var(--accent); }

.badge {
    background: var(--accent);
    color: white;
    font-size: 0.55rem;
    padding: 2px 7px;
    border-radius: 10px;
    text-transform: uppercase;
    font-weight: 700;
}

.user-info { font-size: 0.8rem; color: var(--text2); }

.connection-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.8rem;
    color: var(--text2);
    margin-left: 8px;
    padding-left: 12px;
    border-left: 1px solid var(--border);
}

/* ==========================================
   Editor layout
   ========================================== */

.editor {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.toolbar {
    background: var(--bg2);
    border-bottom: 1px solid var(--border);
    padding: 4px 8px;
    display: flex;
    align-items: center;
    gap: 2px;
    flex-shrink: 0;
}

.toolbar-group {
    display: flex;
    align-items: center;
    gap: 2px;
}

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

.toolbar-btn {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 5px 8px;
    background: transparent;
    color: var(--text2);
    border: 1px solid transparent;
    border-radius: var(--radius);
    font-size: 0.75rem;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.15s;
}

.toolbar-btn:hover {
    background: var(--bg3);
    color: var(--text);
    border-color: var(--border);
}

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

.toolbar-btn.btn-accent {
    color: var(--accent);
    font-weight: 600;
}

.toolbar-btn.btn-accent:hover {
    background: rgba(233, 69, 96, 0.15);
    border-color: var(--accent);
}

.toolbar-btn.btn-danger-text {
    color: #c0392b;
}

.toolbar-btn.btn-danger-text:hover {
    background: rgba(192, 57, 43, 0.15);
    border-color: #c0392b;
}

/* Toolbar dropdowns */
.toolbar-dropdown {
    position: relative;
}
.toolbar-dropdown-menu {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    padding-top: 6px;
    z-index: 50;
    min-width: 140px;
}
.toolbar-dropdown-menu-inner {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 4px 0;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}
.toolbar-dropdown:hover .toolbar-dropdown-menu,
.toolbar-dropdown.open .toolbar-dropdown-menu { display: block; }
.toolbar-dropdown-menu-inner button {
    display: block;
    width: 100%;
    padding: 6px 14px;
    background: none;
    border: none;
    color: var(--text2);
    font-size: 0.78rem;
    text-align: left;
    cursor: pointer;
}
.toolbar-dropdown-menu-inner button:hover {
    background: var(--bg3);
    color: var(--text);
}
.dropdown-divider {
    height: 1px;
    background: var(--border);
    margin: 4px 0;
}

/* Color palette bar */
.color-palette {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 3px 8px;
    background: var(--bg2);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    min-height: 24px;
}
.color-palette-label {
    font-size: 0.68rem;
    color: var(--text2);
    margin-right: 4px;
    white-space: nowrap;
}
.color-swatch {
    width: 20px;
    height: 20px;
    border-radius: 3px;
    border: 2px solid transparent;
    cursor: pointer;
    transition: all 0.12s;
    position: relative;
}
.color-swatch:hover {
    transform: scale(1.15);
    border-color: rgba(255,255,255,0.5);
}
.color-swatch.active {
    border-color: #fff;
    box-shadow: 0 0 0 1px rgba(255,255,255,0.3);
}
.color-swatch .swatch-count {
    position: absolute;
    bottom: -1px;
    right: -1px;
    background: var(--bg);
    color: var(--text2);
    font-size: 0.55rem;
    font-weight: 700;
    padding: 0 3px;
    border-radius: 3px;
    line-height: 1.4;
    pointer-events: none;
}

/* Connection mode picker */
.connect-picker {
    position: fixed;
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 6px;
    z-index: 20;
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 240px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}

.picker-btn {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
    padding: 10px 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    cursor: pointer;
    text-align: left;
    transition: all 0.15s;
}

.picker-btn:hover {
    border-color: var(--accent);
    background: rgba(233, 69, 96, 0.08);
}

.picker-btn strong { font-size: 0.82rem; }
.picker-btn span { font-size: 0.7rem; color: var(--text2); line-height: 1.3; }
.picker-help {
    display: block; text-align: center; font-size: 0.7rem;
    color: var(--accent); padding: 6px 0 2px;
    text-decoration: none;
}
.picker-help:hover { text-decoration: underline; }

.editor-main {
    flex: 1;
    display: flex;
    overflow: hidden;
}

.canvas-wrap {
    flex: 1;
    position: relative;
    overflow: hidden;
}

.canvas-wrap canvas {
    display: block;
    width: 100%;
    height: 100%;
}

/* Drop overlay */
.drop-overlay {
    position: absolute;
    inset: 0;
    background: rgba(233, 69, 96, 0.15);
    border: 2px dashed var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--accent);
    pointer-events: none;
    z-index: 5;
}

/* ==========================================
   Sidebar
   ========================================== */

.sidebar {
    width: 260px;
    background: var(--bg2);
    border-left: 1px solid var(--border);
    overflow-y: auto;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
}

.panel {
    border-bottom: 1px solid var(--border);
    padding: 12px;
}

.panel h3 {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text2);
    font-weight: 600;
    margin-bottom: 10px;
}

/* Collapsible panels */
.collapsible .panel-toggle {
    cursor: pointer;
    user-select: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0;
}

.collapsible .panel-body { margin-top: 10px; }
.collapsible.collapsed .panel-body { display: none; }
.collapsible.collapsed .panel-toggle { margin-bottom: 0; }
.caret { font-size: 0.6rem; }

/* ==========================================
   Shape toolbar
   ========================================== */

.shape-toolbar {
    background: var(--bg2);
    border-bottom: 1px solid var(--border);
    padding: 4px 12px;
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
    position: relative;
}

.shape-btn {
    width: 36px;
    height: 36px;
    padding: 6px;
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--radius);
    color: var(--text2);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
}

.shape-btn:hover {
    background: var(--bg3);
    color: var(--text);
    border-color: var(--border);
}

.shape-btn:active {
    background: rgba(233, 69, 96, 0.15);
    border-color: var(--accent);
    color: var(--accent);
}

.shape-btn.active {
    background: rgba(233, 69, 96, 0.15);
    border-color: var(--accent);
    color: var(--accent);
}

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

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

/* Text popover */
.text-popover {
    position: fixed;
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px;
    z-index: 20;
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-width: 220px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}

.text-popover input[type="text"] { width: 100%; }

.text-popover-row {
    display: flex;
    align-items: center;
    gap: 6px;
}

.text-popover-row label {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.75rem;
    color: var(--text2);
    font-weight: 600;
    white-space: nowrap;
}

.text-popover-row label input { width: 50px; }
.text-popover-row select { flex: 1; }

/* ==========================================
   Position panel
   ========================================== */

.pos-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
}

.pos-grid label {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.75rem;
    color: var(--text2);
    font-weight: 600;
}

.pos-grid input {
    flex: 1;
    width: 100%;
    min-width: 0;
}

.pos-actions {
    display: flex;
    gap: 6px;
    margin-top: 8px;
}

/* ==========================================
   Layer panel
   ========================================== */

.layer-empty {
    color: var(--text2);
    font-size: 0.8rem;
    text-align: center;
    padding: 12px 0;
}

.layer-row {
    padding: 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 6px;
    background: var(--bg);
}

.layer-row.layer-disabled {
    opacity: 0.45;
}

.layer-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    font-size: 0.82rem;
    font-weight: 500;
}

.layer-toggle input[type="checkbox"] {
    accent-color: var(--accent);
    width: 14px;
    height: 14px;
}

.layer-swatch {
    width: 14px;
    height: 14px;
    border-radius: 3px;
    border: 1px solid rgba(255,255,255,0.2);
    flex-shrink: 0;
}

.layer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
}

.layer-mode {
    font-size: 0.7rem;
    padding: 2px 4px;
    min-width: 60px;
    flex-shrink: 0;
}
.layer-mode option:disabled {
    color: #666;
}

.layer-name { flex: 1; }

.layer-material {
    display: flex;
    gap: 4px;
    margin-top: 4px;
}
.layer-material select {
    flex: 1;
    font-size: 0.7rem;
    padding: 2px 4px;
    min-width: 0;
}

.layer-params {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 4px;
    margin-top: 6px;
}
.layer-params-4 { grid-template-columns: repeat(4, 1fr); }

.layer-params label {
    font-size: 0.65rem;
    color: var(--text2);
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.layer-params input {
    width: 100%;
    padding: 3px 4px;
    font-size: 0.75rem;
}

/* ==========================================
   Jog controls
   ========================================== */

.jog-grid {
    display: grid;
    grid-template-columns: repeat(3, 44px);
    grid-template-rows: repeat(3, 44px);
    gap: 3px;
    justify-content: center;
}

.jog-btn {
    font-size: 1rem;
    background: var(--bg3);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: all 0.15s;
}

.jog-btn:hover { background: #1a4a7a; }
.jog-btn:active { background: var(--accent); transform: scale(0.95); }
.jog-center { background: var(--bg) !important; border: none !important; cursor: default !important; font-size: 0.9rem; color: var(--text2); }

.jog-settings {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 8px;
    justify-content: center;
    font-size: 0.78rem;
    color: var(--text2);
}

/* ==========================================
   Machine info (compact)
   ========================================== */

.info-grid-sm {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.info-row {
    display: flex;
    justify-content: space-between;
    font-size: 0.78rem;
    padding: 3px 0;
    border-bottom: 1px solid rgba(42, 58, 94, 0.3);
}

.info-row span:first-child { color: var(--text2); }
.info-row span:last-child { font-weight: 500; }
.mono { font-family: 'SF Mono', 'Fira Code', monospace; font-size: 0.75rem; }

/* ==========================================
   Context menu
   ========================================== */

.context-menu {
    position: fixed;
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    min-width: 180px;
    padding: 4px 0;
    z-index: 10000;
    box-shadow: 0 8px 24px rgba(0,0,0,0.5);
}

.context-menu-item {
    display: flex;
    align-items: center;
    width: 100%;
    padding: 6px 14px;
    background: none;
    border: none;
    color: var(--text);
    font-size: 0.8rem;
    cursor: pointer;
    text-align: left;
    gap: 8px;
    transition: background 0.1s;
}

.context-menu-item:hover { background: var(--bg3); }
.context-menu-item:disabled { color: var(--text2); opacity: 0.4; cursor: default; }
.context-menu-item:disabled:hover { background: none; }
.context-menu-label { flex: 1; }
.context-menu-shortcut { font-size: 0.7rem; color: var(--text2); opacity: 0.7; }
.context-menu-divider { height: 1px; background: var(--border); margin: 3px 0; }

/* ==========================================
   Shared components
   ========================================== */

.hidden { display: none !important; }

.status-dot {
    width: 8px; height: 8px; border-radius: 50%;
    background: #555; transition: background 0.3s;
    flex-shrink: 0;
}
.status-dot.connected { background: var(--success); box-shadow: 0 0 6px var(--success); }
.status-dot.error { background: var(--accent); }

/* Buttons */
.btn {
    padding: 7px 14px; border: none; border-radius: var(--radius);
    cursor: pointer; font-size: 0.8rem; font-weight: 600; transition: all 0.2s;
}
.btn-sm { padding: 4px 10px; font-size: 0.75rem; }
.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover { background: var(--accent2); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-secondary { background: var(--bg3); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: #1a4a7a; }
.btn-secondary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-danger { background: #c0392b; color: white; }
.btn-danger:hover { background: #e74c3c; }
.btn-row { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }

/* Alerts */
.alert { padding: 8px 16px; text-align: center; font-weight: 600; font-size: 0.85rem; }
.alert-error { background: var(--accent); color: white; }

/* Forms */
select, input[type="text"], input[type="number"], input[type="email"], input[type="password"] {
    background: var(--bg); border: 1px solid var(--border); color: var(--text);
    padding: 5px 8px; border-radius: 4px; font-size: 0.8rem;
}
select:focus, input:focus { outline: none; border-color: var(--accent); }
.form-group { margin-bottom: 10px; }
.form-group label { display: block; font-size: 0.78rem; color: var(--text2); margin-bottom: 3px; }
.form-group input { width: 100%; }
.text-muted { color: var(--text2); font-size: 0.82rem; margin-bottom: 14px; }

/* Log */
.log-container {
    background: #0d0d1a; border: 1px solid var(--border); border-radius: var(--radius);
    padding: 8px; max-height: 200px; overflow-y: auto;
    font-family: 'SF Mono', 'Fira Code', monospace; font-size: 0.72rem; line-height: 1.5;
}
.log-entry { margin-bottom: 1px; }
.log-info { color: var(--text2); }
.log-send { color: #5dade2; }
.log-recv { color: var(--success); }
.log-error { color: var(--accent2); }
.log-success { color: var(--success); font-weight: 600; }
.log-time { color: #555; margin-right: 6px; }

/* Modal */
.modal {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.6); display: flex;
    align-items: center; justify-content: center; z-index: 100;
}
.modal-content {
    background: var(--bg2); border: 1px solid var(--border);
    border-radius: var(--radius); width: 90%; max-width: 400px;
}
.modal-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 14px 18px; border-bottom: 1px solid var(--border);
}
.modal-header h2 { font-size: 1rem; }
.modal-close {
    background: none; border: none; color: var(--text2);
    font-size: 1.4rem; cursor: pointer; line-height: 1;
}
.modal-body { padding: 18px; }
.modal-footer {
    padding: 14px 18px; border-top: 1px solid var(--border);
    display: flex; gap: 8px; justify-content: flex-end;
}

/* Progress bar */
.progress-bar {
    position: relative;
    height: 22px;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    overflow: hidden;
}
.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--success), #2ecc71);
    width: 0%;
    transition: width 0.4s ease;
}
.progress-label {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text);
    text-shadow: 0 1px 2px rgba(0,0,0,0.5);
}

/* Machine setup */
.cap-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    align-items: center;
}
.cap-badge {
    font-size: 0.68rem;
    padding: 2px 7px;
    border-radius: 3px;
    font-weight: 600;
}
.cap-on {
    background: rgba(78, 205, 196, 0.15);
    color: var(--success);
    border: 1px solid rgba(78, 205, 196, 0.3);
}
.cap-off {
    background: rgba(255, 255, 255, 0.04);
    color: #555;
    border: 1px solid rgba(255, 255, 255, 0.08);
}

/* Modal sizes */
.modal-md { max-width: 520px; }
.modal-lg { max-width: 800px; width: 95%; }

/* Textarea */
textarea {
    background: var(--bg); border: 1px solid var(--border); color: var(--text);
    padding: 8px; border-radius: 4px; font-size: 0.82rem; font-family: inherit;
}
textarea:focus { outline: none; border-color: var(--accent); }

/* Feedback button */
.feedback-btn {
    background: none; border: 1px solid var(--border); color: var(--text2);
    width: 32px; height: 32px; border-radius: var(--radius);
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; transition: all 0.15s;
}
.feedback-btn:hover { background: var(--accent); color: #fff; border-color: var(--accent); }

/* Feedback modal */
.feedback-type-selector { display: flex; gap: 8px; }
.feedback-type-option { flex: 1; }
.feedback-type-option input { display: none; }
.feedback-type-label {
    display: flex; align-items: center; justify-content: center; gap: 6px;
    padding: 8px 12px; border-radius: var(--radius); cursor: pointer;
    font-size: 0.82rem; font-weight: 600; border: 1px solid var(--border);
    background: var(--bg); color: var(--text2); transition: all 0.15s;
}
.feedback-type-option input:checked + .feedback-type-label.feature {
    background: rgba(34,197,94,0.12); color: #22c55e; border-color: rgba(34,197,94,0.4);
}
.feedback-type-option input:checked + .feedback-type-label.bug {
    background: rgba(239,68,68,0.12); color: #ef4444; border-color: rgba(239,68,68,0.4);
}
.char-count { text-align: right; font-size: 0.72rem; color: var(--text2); margin-top: 4px; }
.feedback-note {
    display: flex; align-items: center; gap: 8px;
    padding: 10px 12px; background: rgba(255,255,255,0.04);
    border-radius: var(--radius); font-size: 0.78rem; color: var(--text2);
    margin-top: 4px;
}
.feedback-note svg { flex-shrink: 0; }

/* Spinner */
.spinner {
    width: 24px; height: 24px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 8px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ==========================================
   Test Grid
   ========================================== */
.tg-grid {
    display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
}
.tg-grid label {
    display: flex; align-items: center; gap: 4px;
    font-size: 0.75rem; color: var(--text2); font-weight: 600; white-space: nowrap;
}
.tg-grid label input { width: 60px; }
.tg-group {
    border: 1px solid var(--border); border-radius: var(--radius);
    padding: 8px 10px;
}
.tg-group legend {
    font-size: 0.72rem; font-weight: 600; color: var(--text2);
    padding: 0 4px;
}
.tg-range {
    display: flex; gap: 8px; align-items: center;
}
.tg-range label {
    display: flex; align-items: center; gap: 4px;
    font-size: 0.72rem; color: var(--text2); font-weight: 600;
}
.tg-range label input { width: 50px; }

/* ==========================================
   Job Preview
   ========================================== */
.preview-controls {
    display: flex; align-items: center; gap: 14px;
    padding: 8px 4px; margin-bottom: 8px;
    flex-wrap: wrap;
}
.preview-controls label {
    display: flex; align-items: center; gap: 4px;
    font-size: 0.75rem; color: var(--text2); font-weight: 600; white-space: nowrap;
}
.preview-controls input[type="number"] { width: 60px; }
.preview-controls select { min-width: 100px; }
.preview-controls .preview-unit { font-size: 0.68rem; color: var(--text2); }
.preview-canvas-wrap {
    background: var(--bg); border: 1px solid var(--border);
    border-radius: var(--radius); overflow: hidden;
    display: flex; align-items: center; justify-content: center;
    min-height: 360px;
}
.preview-canvas-wrap canvas { max-width: 100%; max-height: 500px; display: block; }

/* ==========================================
   AI Generate Modal
   ========================================== */
.ai-usage {
    display: flex; align-items: center; gap: 8px;
    padding: 8px 10px; margin-bottom: 12px;
    background: var(--bg); border-radius: var(--radius);
    font-size: 0.75rem; color: var(--text2);
}
.ai-usage span { flex: 1; }
.ai-buy-btn {
    background: none; border: 1px solid var(--accent); color: var(--accent);
    padding: 3px 10px; border-radius: var(--radius); font-size: 0.72rem;
    font-weight: 600; cursor: pointer; white-space: nowrap; transition: all 0.15s;
}
.ai-buy-btn:hover { background: var(--accent); color: #fff; }
.ai-credit-packs {
    display: flex; gap: 8px; margin-bottom: 12px;
}
.ai-credit-pack {
    flex: 1; display: flex; flex-direction: column; align-items: center;
    gap: 4px; padding: 12px 8px; background: var(--bg);
    border: 1px solid var(--border); border-radius: var(--radius);
    cursor: pointer; transition: all 0.15s; position: relative;
}
.ai-credit-pack:hover {
    border-color: var(--accent); background: rgba(233,69,96,0.06);
}
.pack-credits { font-size: 0.85rem; font-weight: 600; color: var(--text); }
.pack-price { font-size: 0.78rem; color: var(--accent); font-weight: 600; }
.pack-badge {
    position: absolute; top: -8px; right: -4px;
    background: var(--accent); color: #fff;
    font-size: 0.6rem; font-weight: 700; padding: 2px 6px;
    border-radius: 8px; text-transform: uppercase;
}
.ai-preview {
    background: var(--bg); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 12px;
    text-align: center; margin-top: 10px;
    max-height: 320px; overflow: auto;
}
.ai-preview svg { max-width: 100%; max-height: 280px; }

/* ==========================================
   Library Modal
   ========================================== */
.library-bar {
    display: flex; align-items: center; justify-content: space-between;
    padding: 10px 14px; border-bottom: 1px solid var(--border);
}
.library-tabs { display: flex; gap: 4px; }
.library-tab {
    padding: 5px 12px; background: transparent; border: 1px solid transparent;
    border-radius: var(--radius); color: var(--text2); font-size: 0.78rem;
    font-weight: 600; cursor: pointer; transition: all 0.15s;
}
.library-tab:hover { background: var(--bg3); color: var(--text); }
.library-tab.active { background: var(--accent); color: white; border-color: var(--accent); }
.library-credits { font-size: 0.72rem; color: var(--text2); }
.library-filters {
    display: flex; gap: 6px; padding: 10px 14px;
    border-bottom: 1px solid var(--border);
}
.library-filters select, .library-filters input { flex: 1; min-width: 0; }
.library-grid {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 10px; padding: 14px; max-height: 420px; overflow-y: auto;
}
.library-card {
    background: var(--bg); border: 1px solid var(--border);
    border-radius: var(--radius); cursor: pointer;
    transition: all 0.15s; overflow: hidden;
}
.library-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.library-card-img {
    width: 100%; height: 100px; display: flex;
    align-items: center; justify-content: center;
    padding: 8px; background: #fff;
}
.library-card-img svg { max-width: 100%; max-height: 100%; }
.library-card-info {
    padding: 6px 8px; display: flex;
    justify-content: space-between; align-items: center;
}
.library-card-title {
    font-size: 0.7rem; font-weight: 600;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    flex: 1;
}
.library-card-cost {
    font-size: 0.65rem; padding: 1px 5px;
    border-radius: 3px; font-weight: 700; flex-shrink: 0; margin-left: 4px;
}
.library-card-cost.owned { background: rgba(78,205,196,0.15); color: var(--success); }
.library-card-cost.free { background: rgba(78,205,196,0.15); color: var(--success); }
.library-card-cost.paid { background: rgba(233,69,96,0.15); color: var(--accent); }
.library-loading, .library-empty {
    grid-column: 1 / -1; text-align: center;
    padding: 30px; color: var(--text2); font-size: 0.82rem;
}
.library-pagination {
    display: flex; justify-content: center; gap: 8px;
    padding: 10px 14px; border-top: 1px solid var(--border);
}
.library-detail-preview {
    background: #fff; border: 1px solid var(--border);
    border-radius: var(--radius); padding: 16px;
    text-align: center; margin-bottom: 12px;
    max-height: 260px; overflow: auto;
}
.library-detail-preview svg { max-width: 100%; max-height: 230px; }
.library-detail-info { font-size: 0.8rem; color: var(--text2); }
.library-detail-info .detail-tags {
    display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px;
}
.library-detail-info .detail-tag {
    font-size: 0.68rem; padding: 2px 6px;
    background: var(--bg3); border-radius: 3px; color: var(--text2);
}

/* ==========================================
   Image Trace Modal
   ========================================== */
.trace-preview {
    background: var(--bg); border: 1px solid var(--border);
    border-radius: var(--radius); text-align: center;
    margin-bottom: 12px; overflow: hidden;
}
.trace-preview canvas { max-width: 100%; height: auto; display: block; margin: 0 auto; }
.trace-settings {
    display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
}
.trace-settings .form-group { margin-bottom: 0; }
.trace-settings input[type="range"] { width: 100%; accent-color: var(--accent); }

/* ==========================================
   Photo Engrave Modal
   ========================================== */
.photo-layout {
    display: grid; grid-template-columns: 1fr 220px; gap: 14px;
}
.photo-previews { display: flex; flex-direction: column; gap: 6px; min-height: 0; }
.photo-preview-pair {
    display: grid; grid-template-columns: 1fr 1fr; gap: 6px; flex: 1;
}
.photo-preview-wrap {
    background: var(--bg); border: 1px solid var(--border);
    border-radius: var(--radius); overflow: hidden;
    display: flex; align-items: center; justify-content: center;
    min-height: 160px; position: relative;
}
.photo-preview-wrap canvas { max-width: 100%; max-height: 340px; display: block; image-rendering: pixelated; }
#photo-crop-overlay {
    position: absolute; top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    max-width: 100%; max-height: 340px;
    pointer-events: auto; cursor: default;
}
.photo-preview-label {
    position: absolute; top: 4px; left: 6px;
    font-size: 0.62rem; font-weight: 700; text-transform: uppercase;
    letter-spacing: 0.04em; color: var(--text2); opacity: 0.7;
    pointer-events: none;
}
.photo-controls {
    display: flex; flex-direction: column; gap: 6px;
}
.photo-controls .form-group { margin-bottom: 0; }
.photo-controls input[type="range"] { width: 100%; accent-color: var(--accent); }
.photo-controls select { width: 100%; }
.photo-size-row {
    display: flex; gap: 6px; align-items: center;
    flex-wrap: wrap;
}
.photo-size-row label {
    display: flex; align-items: center; gap: 3px;
    font-size: 0.72rem; color: var(--text2); font-weight: 600; white-space: nowrap;
}
.photo-size-row label input[type="number"] { width: 54px; }
.photo-lock-label { cursor: pointer; }
.photo-lock-label input { accent-color: var(--accent); width: 14px; height: 14px; }
.photo-stats {
    font-size: 0.68rem; color: var(--text2);
    padding: 6px 8px; background: var(--bg);
    border-radius: var(--radius); line-height: 1.5;
}

/* Responsive */
@media (max-width: 800px) {
    .sidebar { width: 220px; }
}

@media (max-width: 600px) {
    .editor-main { flex-direction: column; }
    .sidebar {
        width: 100%;
        border-left: none;
        border-top: 1px solid var(--border);
        max-height: 40vh;
    }
    .canvas-wrap { min-height: 300px; }
    .library-grid { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); }
    .trace-settings { grid-template-columns: 1fr; }
    .photo-layout { grid-template-columns: 1fr; }
    .photo-preview-pair { grid-template-columns: 1fr; }
}
