 /* ─── TOKENS ─── */
  :root {
    --bg: #0f1117;
    --surface: #1a1d27;
    --surface2: #22263a;
    --border: #2e3350;
    --accent: #5b7fff;
    --accent2: #7c3aed;
    --accent-glow: rgba(91,127,255,0.18);
    --text: #e8eaf6;
    --text2: #8890b5;
    --text3: #555e8a;
    --red: #ef4444;
    --green: #22c55e;
    --yellow: #f59e0b;
    --radius: 10px;
    --radius-sm: 6px;
    --font: 'Inter', system-ui, sans-serif;
    --mono: 'JetBrains Mono', 'Fira Mono', monospace;
    --shadow: 0 4px 24px rgba(0,0,0,0.4);
    --transition: 0.18s ease;
  }

  @import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;600&display=swap');

  *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

  body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
  }

  /* ─── TOPBAR ─── */
  .topbar {
    height: 56px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 24px;
    gap: 16px;
    position: sticky;
    top: 0;
    z-index: 100;
  }
  .topbar-logo {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: -0.5px;
    background: linear-gradient(135deg, var(--accent), var(--accent2));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
  }
  .topbar-sep { flex: 1; }
  .topbar-actions { display: flex; gap: 8px; }

  /* ─── LAYOUT ─── */
  .app-body {
    display: grid;
    grid-template-columns: 340px 1fr;
    flex: 1;
    min-height: 0;
    overflow: hidden;
  }

  /* ─── SIDEBAR ─── */
  .sidebar {
    background: var(--surface);
    border-right: 1px solid var(--border);
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
  }
  .sidebar::-webkit-scrollbar { width: 4px; }
  .sidebar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

  /* ─── SECTIONS ─── */
  .section {
    border-bottom: 1px solid var(--border);
  }
  .section-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 20px;
    cursor: pointer;
    user-select: none;
    transition: background var(--transition);
  }
  .section-header:hover { background: var(--surface2); }
  .section-badge {
    width: 22px; height: 22px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), var(--accent2));
    display: flex; align-items: center; justify-content: center;
    font-size: 11px; font-weight: 700; color: #fff; flex-shrink: 0;
  }
  .section-title { font-size: 13px; font-weight: 600; flex: 1; }
  .section-chevron {
    color: var(--text3);
    font-size: 11px;
    transition: transform var(--transition);
  }
  .section-chevron.open { transform: rotate(90deg); }
  .section-body {
    padding: 4px 20px 16px;
    display: none;
  }
  .section-body.open { display: block; }

  /* ─── FORM CONTROLS ─── */
  .field { margin-bottom: 12px; }
  .field label {
    display: block;
    font-size: 11px;
    font-weight: 500;
    color: var(--text2);
    margin-bottom: 5px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
  }
  .field input[type=text],
  .field input[type=number],
  .field select {
    width: 100%;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 7px 10px;
    color: var(--text);
    font-family: var(--font);
    font-size: 13px;
    outline: none;
    transition: border-color var(--transition);
  }
  .field input:focus, .field select:focus { border-color: var(--accent); }
  .field select option { background: var(--surface2); }

  .field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
  .field-row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }

  .toggle-row {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 12px;
  }
  .toggle-label { font-size: 13px; color: var(--text); }
  .toggle {
    position: relative;
    width: 36px; height: 20px;
  }
  .toggle input { display: none; }
  .toggle-track {
    position: absolute; inset: 0;
    background: var(--border);
    border-radius: 10px;
    cursor: pointer;
    transition: background var(--transition);
  }
  .toggle input:checked + .toggle-track { background: var(--accent); }
  .toggle-track::after {
    content: '';
    position: absolute;
    width: 14px; height: 14px;
    background: #fff;
    border-radius: 50%;
    top: 3px; left: 3px;
    transition: transform var(--transition);
  }
  .toggle input:checked + .toggle-track::after { transform: translateX(16px); }

  /* Color input */
  .color-field {
    display: flex; align-items: center; gap: 8px;
  }
  .color-field input[type=color] {
    width: 32px; height: 32px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 2px;
    background: var(--bg);
    cursor: pointer;
  }
  .color-field input[type=text] {
    flex: 1;
  }

  /* ─── BUTTONS ─── */
  .btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 7px 14px;
    border: none; border-radius: var(--radius-sm);
    font-family: var(--font); font-size: 13px; font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
  }
  .btn-primary {
    background: var(--accent);
    color: #fff;
  }
  .btn-primary:hover { background: #4a6ef5; box-shadow: 0 0 16px var(--accent-glow); }
  .btn-secondary {
    background: var(--surface2);
    color: var(--text);
    border: 1px solid var(--border);
  }
  .btn-secondary:hover { background: var(--border); }
  .btn-danger {
    background: transparent;
    color: var(--red);
    border: 1px solid var(--red);
  }
  .btn-danger:hover { background: rgba(239,68,68,0.1); }
  .btn-success {
    background: var(--green);
    color: #fff;
  }
  .btn-success:hover { background: #16a34a; }
  .btn-ghost {
    background: transparent;
    color: var(--text2);
    border: 1px solid var(--border);
  }
  .btn-ghost:hover { color: var(--text); background: var(--surface2); }
  .btn-icon {
    padding: 6px 10px;
  }
  .btn-full { width: 100%; justify-content: center; }
  .btn-group { display: flex; gap: 8px; flex-wrap: wrap; }

  /* ─── PRESETS ─── */
  .preset-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
  .preset-item {
    display: flex; align-items: center; gap: 8px;
    padding: 8px 10px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: border-color var(--transition);
  }
  .preset-item:hover { border-color: var(--accent); }
  .preset-item.active { border-color: var(--accent); background: var(--accent-glow); }
  .preset-name { flex: 1; font-size: 12px; font-weight: 500; }
  .preset-info { font-size: 11px; color: var(--text3); }
  .preset-del {
    background: none; border: none; cursor: pointer;
    color: var(--text3); font-size: 14px; padding: 2px 4px;
    border-radius: 3px;
  }
  .preset-del:hover { color: var(--red); background: rgba(239,68,68,0.1); }

  /* ─── MAIN AREA ─── */
  .main-area {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--bg);
  }

  /* ─── DATA TABLE ─── */
  .data-section {
    border-bottom: 1px solid var(--border);
    background: var(--surface);
  }
  .data-header {
    display: flex; align-items: center; gap: 12px;
    padding: 12px 20px;
    border-bottom: 1px solid var(--border);
  }
  .data-title { font-size: 13px; font-weight: 600; flex: 1; }
  .table-wrap {
    overflow-x: auto;
    max-height: 220px;
    overflow-y: auto;
  }
  table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
  }
  thead { position: sticky; top: 0; z-index: 2; }
  thead th {
    background: var(--surface2);
    padding: 8px 12px;
    text-align: left;
    font-size: 11px;
    font-weight: 600;
    color: var(--text2);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid var(--border);
  }
  tbody tr { border-bottom: 1px solid var(--border); }
  tbody tr:hover { background: var(--surface2); }
  tbody td {
    padding: 4px 8px;
  }
  tbody td input {
    width: 100%;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 4px;
    padding: 4px 6px;
    color: var(--text);
    font-family: var(--mono);
    font-size: 12px;
    outline: none;
  }
  tbody td input:focus {
    background: var(--bg);
    border-color: var(--accent);
  }
  .row-num {
    width: 32px;
    text-align: center;
    color: var(--text3);
    font-size: 11px;
    font-family: var(--mono);
    user-select: none;
  }
  .row-del {
    width: 36px;
    text-align: center;
  }
  .row-del-btn {
    background: none; border: none; cursor: pointer;
    color: var(--text3); font-size: 15px; line-height: 1;
    padding: 3px 6px; border-radius: 3px;
  }
  .row-del-btn:hover { color: var(--red); background: rgba(239,68,68,0.1); }

  /* ─── PREVIEW ─── */
  .preview-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }
  .preview-header {
    display: flex; align-items: center; gap: 12px;
    padding: 12px 20px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
    flex-shrink: 0;
  }
  .preview-title { font-size: 13px; font-weight: 600; flex: 1; }
  .preview-tabs { display: flex; gap: 4px; }
  .preview-tab {
    padding: 5px 12px;
    border-radius: var(--radius-sm);
    font-size: 12px; font-weight: 500;
    cursor: pointer;
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text2);
    transition: all var(--transition);
  }
  .preview-tab.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
  }
  .preview-body {
    flex: 1;
    overflow: auto;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 24px;
    background: #181b2a;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
  }
  .preview-body::-webkit-scrollbar { width: 6px; height: 6px; }
  .preview-body::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

  /* ─── LABEL PREVIEW RENDERING ─── */
  .preview-pages-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
  }
  .preview-page-label {
    font-size: 11px;
    color: var(--text3);
    font-family: var(--mono);
    align-self: flex-start;
    margin-bottom: -12px;
  }
  .preview-page {
    background: #fff;
    box-shadow: 0 8px 40px rgba(0,0,0,0.6);
    position: relative;
    overflow: visible;
  }
  .preview-label-cell {
    position: absolute;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    background: #fff;
  }
  .preview-label-cell .lbl-title {
    font-weight: 700;
    color: #111;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
  }
  .preview-label-cell .lbl-barcode-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
    max-width: 100%;
    overflow: hidden;
  }
  .preview-label-cell .lbl-barcode-wrap svg { display: block; }
  .preview-label-cell .lbl-barcode-wrap canvas { display: block; }
  .preview-label-cell .lbl-code {
    color: #444;
    font-family: 'Courier New', monospace;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
  }
  .preview-label-cell .lbl-desc {
    color: #666;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
    text-align: center;
  }

  /* ─── GENERATE PDF BUTTON AREA ─── */
  .generate-bar {
    padding: 12px 20px;
    background: var(--surface);
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
  }
  .gen-info { font-size: 12px; color: var(--text2); flex: 1; }
  .gen-info strong { color: var(--text); }
  .progress-wrap {
    display: none;
    align-items: center;
    gap: 10px;
    font-size: 12px;
    color: var(--text2);
  }
  .progress-wrap.show { display: flex; }
  .progress-bar {
    width: 120px; height: 4px;
    background: var(--border);
    border-radius: 2px;
    overflow: hidden;
  }
  .progress-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 2px;
    transition: width 0.3s ease;
    width: 0%;
  }

  /* ─── NOTIFICATION ─── */
  .notif {
    position: fixed;
    bottom: 24px; right: 24px;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 18px;
    font-size: 13px;
    box-shadow: var(--shadow);
    transform: translateY(80px);
    opacity: 0;
    transition: all 0.3s ease;
    z-index: 999;
    max-width: 320px;
  }
  .notif.show { transform: translateY(0); opacity: 1; }
  .notif.success { border-color: var(--green); color: var(--green); }
  .notif.error { border-color: var(--red); color: var(--red); }
  .notif.info { border-color: var(--accent); color: var(--accent); }

  /* ─── MODAL ─── */
  .modal-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.7);
    backdrop-filter: blur(4px);
    z-index: 200;
    display: none; align-items: center; justify-content: center;
  }
  .modal-overlay.show { display: flex; }
  .modal {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    min-width: 320px;
    box-shadow: var(--shadow);
  }
  .modal h3 { font-size: 15px; margin-bottom: 16px; }
  .modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }

  /* ─── SECTION PRESET INPUT ─── */
  .preset-input-row {
    display: flex; gap: 8px; margin-bottom: 10px;
  }
  .preset-input-row input {
    flex: 1;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 7px 10px;
    color: var(--text);
    font-family: var(--font);
    font-size: 13px;
    outline: none;
  }
  .preset-input-row input:focus { border-color: var(--accent); }

  /* ─── RANGE ─── */
  input[type=range] {
    -webkit-appearance: none;
    width: 100%;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    outline: none;
    cursor: pointer;
  }
  input[type=range]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px; height: 16px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
  }
  .range-row { display: flex; align-items: center; gap: 10px; }
  .range-val {
    font-size: 12px;
    font-family: var(--mono);
    color: var(--accent);
    min-width: 28px;
    text-align: right;
  }

  /* ─── LOADING ─── */
  .loading-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.7);
    backdrop-filter: blur(4px);
    z-index: 300;
    display: none;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 16px;
    color: var(--text);
    font-size: 15px;
  }
  .loading-overlay.show { display: flex; }
  .spinner {
    width: 40px; height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
  }
  @keyframes spin { to { transform: rotate(360deg); } }

  /* ─── DESIGN GROUP LABEL ─── */
  .design-group-label {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text3);
    margin-bottom: 8px;
    padding: 4px 0 4px 0;
    border-bottom: 1px solid var(--border);
  }
  .pos-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 6px;
    margin-bottom: 10px;
  }
  .pos-grid .field label { font-size: 10px; }
  .pos-grid .field input { font-size: 11px; padding: 5px 6px; }

  /* ─── LOCATION GENERATOR ─── */
  #locPreviewList::-webkit-scrollbar { width: 3px; }
  #locPreviewList::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

  /* ─── SCROLLBAR ─── */
  .sidebar { scrollbar-width: thin; }

  /* Responsive */
  @media (max-width: 900px) {
    .app-body { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
    .sidebar { max-height: 50vh; overflow-y: auto; }
  }