/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg: #0e1117;
    --bg-surface: #161b22;
    --bg-elevated: #1c2230;
    --bg-hover: #242c3a;
    --border: #2d3548;
    --border-focus: #0aa3e3;
    --text: #e6edf3;
    --text-muted: #8b949e;
    --text-dim: #6e7681;
    --accent: #0aa3e3;
    --accent-hover: #35baf2;
    --accent-bg: rgba(10,163,227,0.12);
    --danger: #d13239;
    --danger-bg: rgba(209,50,57,0.12);
    --success: #3fb950;
    --success-bg: rgba(63,185,80,0.12);
    --warning: #d29922;
    --radius: 8px;
    --radius-sm: 6px;
    --font: 'Inter', -apple-system, sans-serif;
    --font-mono: 'JetBrains Mono', monospace;
    --shadow: 0 4px 24px rgba(0,0,0,0.3);
}

html, body {
    height: 100%;
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    overflow: hidden;
}

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }

/* ===== TOP BAR ===== */
#topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    height: 56px;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 100;
}
.topbar-left { display: flex; align-items: center; gap: 12px; }
.topbar-left h1 { font-size: 16px; font-weight: 600; letter-spacing: -0.3px; }
.custom-logo { height: 26px; width: auto; }
.badge {
    font-size: 11px; font-weight: 500; color: var(--text-muted);
    background: var(--bg-elevated); border: 1px solid var(--border);
    padding: 2px 10px; border-radius: 12px; font-family: var(--font-mono);
}
.topbar-right { display: flex; gap: 8px; align-items: center; }

/* ===== BUTTONS ===== */
.btn {
    display: inline-flex; align-items: center; gap: 6px;
    font-family: var(--font); font-size: 13px; font-weight: 500;
    padding: 8px 14px; border-radius: var(--radius-sm);
    border: 1px solid transparent; cursor: pointer;
    transition: all 0.15s ease;
}
.btn .material-symbols-outlined { font-size: 18px; }
.btn-primary {
    background: var(--accent); color: #fff; border-color: var(--accent);
}
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-ghost {
    background: transparent; color: var(--text-muted); border-color: var(--border);
}
.btn-ghost:hover { color: var(--text); background: var(--bg-hover); border-color: var(--text-dim); }
.btn-accent {
    background: var(--accent-bg); color: var(--accent); border-color: rgba(88,166,255,0.25);
}
.btn-accent:hover { background: rgba(88,166,255,0.2); }
.btn-danger {
    background: var(--danger-bg); color: var(--danger); border-color: rgba(248,81,73,0.25);
}
.btn-danger:hover { background: rgba(248,81,73,0.2); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-sm .material-symbols-outlined { font-size: 16px; }

/* ===== MAIN LAYOUT ===== */
#app {
    display: flex;
    height: calc(100vh - 56px);
}

/* ===== SIDEBAR ===== */
#sidebar {
    width: 300px; min-width: 300px;
    background: var(--bg-surface);
    border-right: 1px solid var(--border);
    display: flex; flex-direction: column;
}
.sidebar-header { padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.search-box {
    display: flex; align-items: center; gap: 8px;
    background: var(--bg-elevated); border: 1px solid var(--border);
    border-radius: var(--radius-sm); padding: 0 12px;
}
.search-box .material-symbols-outlined { color: var(--text-dim); font-size: 20px; }
.search-box input {
    flex: 1; background: none; border: none; outline: none;
    color: var(--text); font-family: var(--font); font-size: 13px;
    padding: 10px 0;
}
.search-box input::placeholder { color: var(--text-dim); }

#machine-list {
    flex: 1; overflow-y: auto; list-style: none;
    padding: 0 8px 16px;
}
#machine-list li {
    padding: 12px 14px; margin-bottom: 2px;
    border-radius: var(--radius-sm); cursor: pointer;
    transition: all 0.12s ease; border: 1px solid transparent;
    display: flex; flex-direction: column; gap: 4px;
}
#machine-list li:hover { background: var(--bg-hover); }
#machine-list li.active {
    background: var(--accent-bg); border-color: rgba(88,166,255,0.3);
}
#machine-list li .item-title {
    font-size: 13px; font-weight: 500; color: var(--text);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#machine-list li .item-id {
    font-size: 11px; color: var(--text-dim); font-family: var(--font-mono);
}
#machine-list li.active .item-title { color: var(--accent); }

/* ===== EDITOR PANEL ===== */
#editor-panel {
    flex: 1; overflow-y: auto; padding: 32px 40px;
}
#empty-state {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    height: 100%; text-align: center; color: var(--text-dim);
}
.empty-icon { font-size: 64px; margin-bottom: 16px; opacity: 0.3; }
#empty-state h2 { font-size: 18px; font-weight: 500; color: var(--text-muted); margin-bottom: 8px; }
#empty-state p { font-size: 14px; }

.editor-header {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 28px; padding-bottom: 16px; border-bottom: 1px solid var(--border);
}
.editor-header h2 { font-size: 20px; font-weight: 600; }
.editor-actions { display: flex; gap: 8px; }

/* ===== FORM ===== */
.form-grid {
    display: grid; grid-template-columns: 1fr 1fr; gap: 20px;
}
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group.full-width { grid-column: 1 / -1; }
.form-group label {
    font-size: 12px; font-weight: 600; color: var(--text-muted);
    text-transform: uppercase; letter-spacing: 0.5px;
}
.hint { font-size: 11px; color: var(--text-dim); font-weight: 400; text-transform: none; letter-spacing: 0; }
.form-group input, .form-group textarea, .form-group select {
    background: var(--bg-elevated); border: 1px solid var(--border);
    border-radius: var(--radius-sm); padding: 10px 14px;
    color: var(--text); font-family: var(--font); font-size: 14px;
    outline: none; transition: border-color 0.15s;
}
.form-group input:focus, .form-group textarea:focus, .form-group select:focus {
    border-color: var(--border-focus);
}
.form-group textarea { resize: vertical; min-height: 80px; }
.form-group select[multiple] {
    padding: 8px;
    min-height: 100px;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}
.form-group select[multiple] option {
    padding: 6px 10px;
    margin-bottom: 2px;
    border-radius: 4px;
    font-size: 13px;
    cursor: pointer;
}
.form-group select[multiple] option:checked {
    background: var(--accent-bg);
    color: var(--accent);
}

.image-input-row { display: flex; gap: 12px; align-items: center; }
.image-input-row input { flex: 1; }
.image-thumb {
    width: 44px; height: 44px; border-radius: var(--radius-sm);
    background: var(--bg-elevated); border: 1px solid var(--border);
    display: flex; align-items: center; justify-content: center;
    overflow: hidden; flex-shrink: 0;
}
.image-thumb .material-symbols-outlined { color: var(--text-dim); font-size: 22px; }
.image-thumb img { width: 100%; height: 100%; object-fit: cover; }

/* Specs */
#specs-container { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.spec-row {
    display: flex; gap: 8px; align-items: center;
}
.spec-row input { flex: 1; }
.spec-row input {
    background: var(--bg-elevated); border: 1px solid var(--border);
    border-radius: var(--radius-sm); padding: 8px 12px;
    color: var(--text); font-family: var(--font); font-size: 13px;
    outline: none; transition: border-color 0.15s;
}
.spec-row input:focus { border-color: var(--border-focus); }
.spec-remove {
    background: none; border: none; cursor: pointer;
    color: var(--text-dim); padding: 4px; border-radius: 4px;
    transition: all 0.12s;
}
.spec-remove:hover { color: var(--danger); background: var(--danger-bg); }
.spec-remove .material-symbols-outlined { font-size: 18px; }

/* JSON Preview Area */
.json-preview-section {
    grid-column: 1 / -1;
    margin-top: 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: var(--bg-elevated);
}
.json-preview-toggle {
    width: 100%; display: flex; align-items: center; gap: 8px;
    background: var(--bg-surface); border: none; padding: 10px 14px;
    color: var(--text-muted); font-size: 13px; font-weight: 500; font-family: var(--font);
    cursor: pointer; transition: background 0.15s;
    text-align: left;
}
.json-preview-toggle:hover { background: var(--bg-hover); color: var(--text); }
.json-preview-toggle .toggle-chevron { font-size: 20px; transition: transform 0.2s; }
.json-copy-btn { margin-left: auto; padding: 4px 8px; }
.json-copy-btn .material-symbols-outlined { font-size: 16px; }

.json-preview-code {
    margin: 0; padding: 14px;
    background: #0d1117; color: #c9d1d9;
    font-family: var(--font-mono); font-size: 12px; line-height: 1.5;
    overflow-x: auto;
    border-top: 1px solid var(--border);
}

.form-footer {
    margin-top: 28px; padding-top: 20px; border-top: 1px solid var(--border);
    display: flex; justify-content: flex-end;
}

/* ===== PREVIEW PANEL ===== */
#preview-panel {
    width: 380px; min-width: 380px;
    background: var(--bg-surface);
    border-left: 1px solid var(--border);
    display: flex; flex-direction: column;
    overflow-y: auto;
}
.preview-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.preview-header h3 { font-size: 14px; font-weight: 600; color: var(--text-muted); }

#preview-card { padding: 20px; }
.preview-machine-card {
    border: 1px solid var(--border); border-radius: var(--radius);
    overflow: hidden; background: var(--bg-elevated);
}
.preview-machine-card .card-img {
    width: 100%; aspect-ratio: 4/3; object-fit: cover;
    background: var(--bg); display: flex; align-items: center; justify-content: center;
}
.preview-machine-card .card-img img {
    width: 100%; height: 100%; object-fit: cover;
}
.preview-machine-card .card-img .no-img {
    color: var(--text-dim); font-size: 40px;
}
.preview-machine-card .card-body { padding: 20px; }
.preview-machine-card .card-body h3 {
    font-size: 16px; font-weight: 600; margin-bottom: 8px;
}
.preview-machine-card .card-body p {
    font-size: 13px; color: var(--text-muted); margin-bottom: 14px; line-height: 1.6;
}
.preview-machine-card .card-cats {
    display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 16px;
}
.preview-machine-card .cat-tag {
    font-size: 10px; font-weight: 600; text-transform: uppercase;
    letter-spacing: 0.5px; padding: 3px 8px; border-radius: 4px;
    background: var(--accent-bg); color: var(--accent);
}
.preview-machine-card .specs-list {
    border-top: 1px solid var(--border); padding-top: 12px;
}
.preview-machine-card .spec-item {
    display: flex; justify-content: space-between; padding: 6px 0;
    font-size: 12px; border-bottom: 1px solid rgba(45,53,72,0.5);
}
.preview-machine-card .spec-item:last-child { border-bottom: none; }
.preview-machine-card .spec-label { color: var(--text-muted); }
.preview-machine-card .spec-value { color: var(--text); font-weight: 500; font-family: var(--font-mono); font-size: 11px; }

/* ===== MODAL ===== */
#modal-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,0.6);
    display: flex; align-items: center; justify-content: center;
    z-index: 1000; backdrop-filter: blur(4px);
}
.modal {
    position: relative;
    background: var(--bg-elevated); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 32px; text-align: center;
    width: 360px; box-shadow: var(--shadow);
}
.btn-close-corner {
    position: absolute;
    top: 16px;
    right: 16px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4px;
    border-radius: 4px;
    transition: all 0.15s;
}
.btn-close-corner:hover {
    background: var(--bg-hover);
    color: var(--text);
}
.modal-icon { font-size: 40px; color: var(--warning); margin-bottom: 12px; }
.modal h3 { font-size: 18px; font-weight: 600; margin-bottom: 8px; }
.modal p { font-size: 14px; color: var(--text-muted); margin-bottom: 24px; }
.modal-actions { display: flex; gap: 10px; justify-content: center; }

/* ===== PASTE MODAL & EXPORT MODAL ===== */
#paste-modal-overlay, #export-modal-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,0.6);
    display: flex; align-items: center; justify-content: center;
    z-index: 1000; backdrop-filter: blur(4px);
}
.paste-modal {
    width: 560px; max-width: 90vw; text-align: left;
}
.paste-modal h3 { text-align: center; }
.paste-modal > p {
    text-align: center; margin-bottom: 16px;
}
.paste-modal code {
    font-family: var(--font-mono); font-size: 13px;
    background: var(--bg); padding: 2px 6px; border-radius: 4px;
    color: var(--accent);
}
#paste-json-input {
    width: 100%; font-family: var(--font-mono); font-size: 12px;
    background: var(--bg); border: 1px solid var(--border);
    border-radius: var(--radius-sm); padding: 14px 16px;
    color: var(--text); outline: none; resize: vertical;
    min-height: 180px; line-height: 1.5;
    transition: border-color 0.15s;
}
#paste-json-input:focus { border-color: var(--border-focus); }
#paste-json-input::placeholder { color: var(--text-dim); }
.paste-meta {
    min-height: 28px; font-size: 12px; font-weight: 500;
    display: flex; align-items: center; gap: 6px;
    margin: 10px 0 6px; padding: 0 2px;
    transition: color 0.15s;
}
.paste-meta .material-symbols-outlined { font-size: 16px; }
.paste-valid { color: var(--success); }
.paste-error { color: var(--danger); }

/* ===== TOAST ===== */
#toast-container {
    position: fixed; bottom: 20px; right: 20px; z-index: 2000;
    display: flex; flex-direction: column; gap: 8px;
}
.toast {
    padding: 12px 20px; border-radius: var(--radius-sm);
    font-size: 13px; font-weight: 500;
    border: 1px solid; display: flex; align-items: center; gap: 8px;
    animation: toast-in 0.3s ease;
    box-shadow: var(--shadow);
}
.toast .material-symbols-outlined { font-size: 18px; }
.toast.success { background: var(--success-bg); border-color: rgba(63,185,80,0.3); color: var(--success); }
.toast.error { background: var(--danger-bg); border-color: rgba(248,81,73,0.3); color: var(--danger); }
.toast.info { background: var(--accent-bg); border-color: rgba(88,166,255,0.3); color: var(--accent); }

@keyframes toast-in {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

/* ===== UTILITY ===== */
.hidden { display: none !important; }

/* ===== RESPONSIVE ===== */
@media (max-width: 900px) {
    #sidebar { width: 240px; min-width: 240px; }
    #preview-panel { width: 300px; min-width: 300px; }
    #editor-panel { padding: 24px; }
}
@media (max-width: 700px) {
    #app { flex-direction: column; }
    #sidebar { width: 100%; min-width: 100%; max-height: 200px; border-right: none; border-bottom: 1px solid var(--border); }
    #preview-panel { width: 100%; min-width: 100%; border-left: none; border-top: 1px solid var(--border); }
    .form-grid { grid-template-columns: 1fr; }
}
