:root {
    --bg-primary: #0a0a1a;
    --bg-secondary: #12122a;
    --bg-surface: #1a1a36;
    --bg-elevated: #222244;
    --text-primary: #e8e8f0;
    --text-secondary: #8888aa;
    --text-muted: #555570;
    --accent: #00d4aa;
    --accent-dim: #00a888;
    --accent-glow: rgba(0, 212, 170, 0.15);
    --error: #ff5566;
    --danger: #ff4455;
    --border: #2a2a4a;
    --radius: 12px;
    --radius-sm: 8px;
    --font: 'Inter', -apple-system, sans-serif;
    --mono: 'JetBrains Mono', 'SF Mono', monospace;
}

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

body {
    font-family: var(--font);
    background: var(--bg-primary);
    color: var(--text-primary);
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Header */
.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.header-left {
    display: flex;
    align-items: center;
    gap: 10px;
}
.logo-icon {
    width: 28px;
    height: 28px;
    color: var(--accent);
}
.header h1 {
    font-size: 18px;
    font-weight: 600;
    letter-spacing: -0.3px;
}
.header-right { display: flex; gap: 8px; }

/* Buttons */
.btn-icon {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    padding: 8px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    display: flex;
    align-items: center;
    transition: all 0.15s;
}
.btn-icon:hover, .btn-icon.active {
    background: var(--bg-elevated);
    color: var(--accent);
    border-color: var(--accent);
}
.btn-sm {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 6px 12px;
    font-size: 12px;
    font-weight: 500;
    font-family: var(--font);
    border-radius: 6px;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.15s;
    background: var(--accent);
    color: var(--bg-primary);
    border: none;
}
.btn-sm:hover { background: var(--accent-dim); }
.btn-sm:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-sm.btn-outline {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-secondary);
}
.btn-sm.btn-outline:hover {
    border-color: var(--accent);
    color: var(--accent);
}
.btn-sm.btn-danger {
    background: var(--danger);
}
.btn-sm.btn-danger:hover {
    background: #dd3344;
}
.btn-sm.btn-danger-outline {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-muted);
}
.btn-sm.btn-danger-outline:hover {
    border-color: var(--danger);
    color: var(--danger);
}
.btn-text {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 11px;
    font-family: var(--font);
    cursor: pointer;
    padding: 4px 0;
}
.btn-text:hover { color: var(--accent); }
.btn-spinner {
    display: inline-block;
    width: 12px;
    height: 12px;
    border: 2px solid rgba(0,0,0,0.2);
    border-top-color: var(--bg-primary);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

/* Layout */
.layout {
    display: flex;
    flex: 1;
    min-height: 0;
}

/* Chat Panel */
.chat-panel {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 0;
    border-right: 1px solid var(--border);
}
.chat-panel.full-width { border-right: none; }

.messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}
.messages::-webkit-scrollbar { width: 6px; }
.messages::-webkit-scrollbar-track { background: transparent; }
.messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* Welcome */
.welcome {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    flex: 1;
    padding: 40px 20px;
    gap: 16px;
}
.welcome-icon { color: var(--accent); opacity: 0.6; }
.welcome h2 {
    font-size: 22px;
    font-weight: 600;
    letter-spacing: -0.3px;
}
.welcome p {
    color: var(--text-secondary);
    font-size: 14px;
    max-width: 400px;
}
.examples {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    margin-top: 8px;
    max-width: 500px;
}
.example-chip {
    padding: 8px 16px;
    font-size: 13px;
    font-family: var(--font);
    background: var(--bg-surface);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.15s;
}
.example-chip:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-glow);
}

/* Messages */
.message { display: flex; }
.message.user { justify-content: flex-end; }
.message.assistant { justify-content: flex-start; }
.message-content {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: var(--radius);
    font-size: 14px;
    line-height: 1.6;
}
.message.user .message-content {
    background: var(--accent);
    color: var(--bg-primary);
    border-bottom-right-radius: 4px;
}
.message.assistant .message-content {
    background: var(--bg-surface);
    border-bottom-left-radius: 4px;
}

/* Loading */
.loading-msg {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text-secondary);
}
.spinner {
    width: 16px;
    height: 16px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Error */
.error-msg { color: var(--error); }

/* Model Card */
.model-msg { display: flex; flex-direction: column; gap: 10px; }
.model-card {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
    cursor: pointer;
    transition: border-color 0.15s;
}
.model-card:hover { border-color: var(--accent); }
.model-preview {
    height: 200px;
    background: #1a1a2e;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-size: 13px;
}
.model-info {
    display: flex;
    justify-content: space-between;
    padding: 8px 12px;
    font-size: 12px;
    color: var(--text-secondary);
}
.model-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

/* Code block */
.code-block {
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px;
    overflow-x: auto;
    font-family: var(--mono);
    font-size: 12px;
    line-height: 1.5;
    color: var(--text-secondary);
    max-height: 300px;
    overflow-y: auto;
}

/* Slice result */
.slice-msg { display: flex; flex-direction: column; gap: 8px; }
.slice-result {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--accent);
    font-size: 14px;
}
.slice-meta {
    font-size: 12px;
    color: var(--text-secondary);
}
.text-muted { color: var(--text-muted); font-size: 12px; }

/* Input Area */
.input-area {
    padding: 16px 20px;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border);
}
.input-row {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 8px 12px;
    transition: border-color 0.15s;
}
.input-row:focus-within { border-color: var(--accent); }
.refine-badge {
    font-size: 11px;
    color: var(--accent);
    background: var(--accent-glow);
    padding: 4px 8px;
    border-radius: 4px;
    white-space: nowrap;
    flex-shrink: 0;
}
textarea {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-primary);
    font-family: var(--font);
    font-size: 14px;
    resize: none;
    min-height: 24px;
    max-height: 120px;
    line-height: 1.5;
}
textarea::placeholder { color: var(--text-muted); }
.btn-send {
    background: var(--accent);
    border: none;
    color: var(--bg-primary);
    padding: 8px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
    flex-shrink: 0;
}
.btn-send:hover { background: var(--accent-dim); }
.btn-send:disabled { opacity: 0.3; cursor: not-allowed; }

/* 3D Viewer Panel */
.viewer-panel {
    width: 50%;
    display: flex;
    flex-direction: column;
    background: var(--bg-secondary);
    min-width: 300px;
}
.viewer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border);
}
.viewer-container {
    flex: 1;
    min-height: 0;
}
.viewer-controls {
    display: flex;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid var(--border);
}

/* Slice Panel */
.slice-panel {
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.slice-row {
    display: flex;
    gap: 8px;
    align-items: center;
}
.slice-advanced {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}
.slice-advanced label {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    color: var(--text-secondary);
}
.slice-advanced .unit {
    font-size: 11px;
    color: var(--text-muted);
}
.checkbox-label {
    cursor: pointer;
}
.checkbox-label input[type="checkbox"] {
    accent-color: var(--accent);
}

/* Form inputs */
.select-sm {
    background: var(--bg-surface);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 6px 8px;
    font-size: 12px;
    font-family: var(--font);
    cursor: pointer;
    outline: none;
}
.select-sm:focus { border-color: var(--accent); }
.select-sm option { background: var(--bg-surface); }

.input-sm {
    background: var(--bg-surface);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 6px 8px;
    font-size: 12px;
    font-family: var(--font);
    width: 60px;
    outline: none;
}
.input-sm:focus { border-color: var(--accent); }
.input-sm::placeholder { color: var(--text-muted); }
.full-width { width: 100%; }

/* Library */
.library-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 100;
    display: flex;
    justify-content: flex-end;
}
.library-panel {
    width: 320px;
    background: var(--bg-secondary);
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    height: 100%;
}
.library-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px;
    border-bottom: 1px solid var(--border);
}
.library-header h3 { font-size: 16px; font-weight: 600; }
.library-list {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.library-empty {
    color: var(--text-muted);
    text-align: center;
    padding: 40px 20px;
    font-size: 14px;
}
.library-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: border-color 0.15s;
}
.library-item:hover { border-color: var(--accent); }
.library-item-info { display: flex; flex-direction: column; gap: 2px; }
.model-id { font-family: var(--mono); font-size: 12px; }
.model-size { font-size: 11px; color: var(--text-muted); }
.badge-sliced {
    font-size: 10px;
    color: var(--accent);
    background: var(--accent-glow);
    padding: 2px 6px;
    border-radius: 3px;
}

/* Printer Panel */
.printer-panel-wide { width: 380px; }

.printer-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
}
.printer-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
}
.printer-name {
    font-size: 13px;
    font-weight: 600;
}
.printer-type {
    font-size: 11px;
    color: var(--text-muted);
    display: block;
}
.printer-status {
    font-size: 11px;
    font-weight: 500;
    padding: 3px 8px;
    border-radius: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.status-offline { background: #332233; color: #886688; }
.status-idle { background: #1a3322; color: #44cc66; }
.status-printing { background: #1a2833; color: #44aaff; }
.status-paused { background: #332a1a; color: #ddaa44; }
.status-completed { background: #1a3322; color: var(--accent); }
.status-error { background: #331a1a; color: var(--error); }

.printer-card-body {
    padding: 10px 12px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.printer-ip {
    font-family: var(--mono);
    font-size: 12px;
    color: var(--text-muted);
}
.printer-temps {
    font-size: 12px;
    color: var(--text-secondary);
}
.printer-progress {
    display: flex;
    align-items: center;
    gap: 8px;
}
.progress-bar {
    flex: 1;
    height: 6px;
    background: var(--bg-elevated);
    border-radius: 3px;
    overflow: hidden;
}
.progress-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 3px;
    transition: width 0.3s ease;
}
.progress-text {
    font-size: 12px;
    font-weight: 600;
    color: var(--accent);
    min-width: 35px;
    text-align: right;
}
.printer-card-actions {
    display: flex;
    gap: 6px;
    padding: 8px 12px;
    border-top: 1px solid var(--border);
}

/* Add Printer Form */
.add-printer-form {
    background: var(--bg-surface);
    border: 1px dashed var(--border);
    border-radius: var(--radius-sm);
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.add-printer-form h4 {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
}
.add-printer-form > div {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* Drop Overlay */
.drop-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 212, 170, 0.08);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
}
.drop-zone {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    padding: 48px;
    border: 3px dashed var(--accent);
    border-radius: 24px;
    color: var(--accent);
    font-size: 18px;
    font-weight: 600;
}

/* Upload welcome button */
.btn-upload-welcome {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    font-size: 14px;
    font-family: var(--font);
    background: var(--bg-surface);
    border: 1px dashed var(--border);
    color: var(--text-secondary);
    border-radius: var(--radius);
    cursor: pointer;
    transition: all 0.15s;
    margin-top: 4px;
}
.btn-upload-welcome:hover {
    border-color: var(--accent);
    color: var(--accent);
}

/* Model name */
.model-name {
    font-size: 13px;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 180px;
}
.model-name-sm {
    font-size: 12px;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Upload badge */
.badge-upload {
    font-size: 10px;
    color: #44aaff;
    background: rgba(68, 170, 255, 0.15);
    padding: 2px 6px;
    border-radius: 3px;
}

/* Library item actions */
.library-item-actions {
    display: flex;
    gap: 4px;
    align-items: center;
    flex-shrink: 0;
}

/* Small icon button for delete */
.btn-icon-xs {
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-muted);
    padding: 4px;
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    transition: all 0.15s;
}
.btn-icon-xs:hover {
    color: var(--danger);
    border-color: var(--danger);
    background: rgba(255, 68, 85, 0.1);
}

/* Mobile */
@media (max-width: 768px) {
    .layout { flex-direction: column; }
    .chat-panel { border-right: none; }
    .viewer-panel {
        width: 100%;
        height: 50vh;
        min-width: unset;
        border-top: 1px solid var(--border);
    }
    .welcome h2 { font-size: 18px; }
    .examples { max-width: 100%; }
    .message-content { max-width: 90%; }
    .library-panel { width: 280px; }
    .printer-panel-wide { width: 300px; }
    .slice-advanced { flex-direction: column; }
}
