:root {
      --bg-page: #0f172a;
      --bg-panel: #1e293b;
      --bg-input: #0f172a;
      --bg-hover: #263445;
      --border: #334155;
      --border-hover: #475569;
      --text-primary: #f8fafc;
      --text-secondary: #94a3b8;
      --text-muted: #64748b;
      --accent: #3b82f6;
      --accent-hover: #2563eb;
      --success: #22c55e;
      --success-hover: #16a34a;
      --danger: #ef4444;
      --danger-hover: #dc2626;
      --warning: #f59e0b;
      --radius: 8px;
      --radius-sm: 6px;
      --shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24);
      --shadow-lg: 0 10px 30px rgba(0,0,0,0.25);
    }

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

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

    #cdn-error {
      display: none;
      position: fixed; top: 0; left: 0; right: 0; bottom: 0;
      background: var(--bg-page); color: var(--text-primary); z-index: 9999;
      justify-content: center; align-items: center;
      flex-direction: column; gap: 16px;
      font-size: 16px; text-align: center; padding: 40px;
    }
    #cdn-error h2 { color: var(--danger); }

    /* ===== ICONS ===== */
    .icon {
      width: 16px; height: 16px;
      display: inline-flex; align-items: center; justify-content: center;
      flex-shrink: 0;
    }
    .icon svg {
      width: 100%; height: 100%; fill: currentColor;
    }

    /* ===== HEADER ===== */
    #app-header {
      height: 56px;
      background: rgba(15, 23, 42, 0.95);
      backdrop-filter: blur(8px);
      display: flex; align-items: center;
      padding: 0 16px; flex-shrink: 0;
      border-bottom: 1px solid var(--border); gap: 8px;
    }
    #app-header h1 {
      font-size: 15px; font-weight: 600; color: var(--text-primary);
      flex: 1; white-space: nowrap; letter-spacing: 0.2px;
    }
    .header-logo {
      width: 32px; height: 32px;
      background: linear-gradient(135deg, #3b82f6, #2563eb);
      border-radius: var(--radius-sm);
      display: flex; align-items: center; justify-content: center;
      margin-right: 4px; flex-shrink: 0;
      box-shadow: 0 2px 8px rgba(59,130,246,0.3);
    }
    .header-logo svg { width: 18px; height: 18px; fill: white; }
    .header-sep { width: 1px; height: 24px; background: var(--border); flex-shrink: 0; }

    .header-btn {
      padding: 6px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm);
      background: transparent; color: var(--text-secondary); font-size: 12px;
      font-family: inherit; cursor: pointer;
      display: inline-flex; align-items: center; gap: 6px;
      transition: all 0.15s ease; white-space: nowrap; flex-shrink: 0;
    }
    .header-btn:hover { background: var(--bg-hover); color: var(--text-primary); border-color: var(--border-hover); }
    .header-btn.active { background: var(--accent); color: white; border-color: var(--accent); }
    .header-btn.disabled { opacity: 0.4; cursor: default; pointer-events: none; }
    .header-btn .icon { opacity: 0.85; }

    #app-body { display: flex; flex: 1; overflow: hidden; }

    /* ===== SIDE PANELS ===== */
    .side-panel {
      background: var(--bg-panel); overflow-y: auto; flex-shrink: 0;
      transition: width 0.25s ease, padding 0.25s ease, opacity 0.25s ease;
    }
    .side-panel.collapsed { width: 0 !important; padding: 0 !important; overflow: hidden; opacity: 0; }

    #panel-params { width: 300px; padding: 16px; border-right: 1px solid var(--border); }
    #panel-tools { width: 280px; padding: 16px; border-left: 1px solid var(--border); }

    .panel-section { margin-bottom: 20px; padding-bottom: 16px; border-bottom: 1px solid var(--border); }
    .panel-section:last-child { border-bottom: none; margin-bottom: 0; padding-bottom: 0; }
    .panel-section h3 {
      font-size: 11px; text-transform: uppercase; color: var(--text-secondary);
      margin-bottom: 12px; letter-spacing: 0.6px; font-weight: 700;
      display: flex; align-items: center; gap: 6px;
    }
    .panel-section label {
      display: block; font-size: 13px; color: #cbd5e1; margin-bottom: 6px; margin-top: 12px;
      font-weight: 500;
    }
    .panel-section label:first-of-type { margin-top: 0; }
    .field-hint {
      font-size: 11px; color: var(--text-muted); margin-top: 2px; line-height: 1.4;
    }

    select, input[type="number"], textarea {
      width: 100%; padding: 8px 12px; border: 1px solid var(--border);
      border-radius: var(--radius-sm); background: var(--bg-input); color: var(--text-primary);
      font-size: 13px; font-family: inherit; margin-bottom: 6px; outline: none;
      transition: border-color 0.15s, box-shadow 0.15s;
    }
    select:focus, input[type="number"]:focus, textarea:focus {
      border-color: var(--accent);
      box-shadow: 0 0 0 3px rgba(59,130,246,0.15);
    }
    select:hover, input[type="number"]:hover, textarea:hover { border-color: var(--border-hover); }
    input[type="number"] { -moz-appearance: textfield; }
    input[type="number"]::-webkit-outer-spin-button,
    input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
    textarea { resize: vertical; min-height: 64px; line-height: 1.5; }
    input[type="color"] {
      width: 100%; height: 38px; border: 1px solid var(--border);
      border-radius: var(--radius-sm); background: none; cursor: pointer; padding: 3px;
    }
    input[type="range"] { width: 100%; accent-color: var(--accent); cursor: pointer; }
    input:invalid { border-color: var(--danger) !important; }

    .radio-group label {
      display: flex; align-items: center; gap: 8px;
      font-size: 13px; color: #cbd5e1; margin-bottom: 6px;
      cursor: pointer; transition: color 0.15s;
      padding: 4px 0;
    }
    .radio-group label:hover { color: var(--text-primary); }
    input[type="radio"] { accent-color: var(--accent); cursor: pointer; width: 15px; height: 15px; }

    .static-value {
      display: inline-flex; align-items: center; padding: 6px 12px; background: var(--bg-input);
      border: 1px solid var(--border); border-radius: var(--radius-sm);
      font-size: 13px; color: var(--text-secondary); margin-bottom: 6px;
      min-height: 34px;
    }

    .uid-status { font-size: 12px; margin-top: 6px; padding: 6px 10px; border-radius: var(--radius-sm); display: none; }
    .uid-status.ok { display: block; background: rgba(34,197,94,0.12); color: #4ade80; border: 1px solid rgba(34,197,94,0.25); }
    .uid-status.err { display: block; background: rgba(239,68,68,0.12); color: #f87171; border: 1px solid rgba(239,68,68,0.25); }

    /* ===== CANVAS ===== */
    #panel-canvas {
      flex: 1; display: flex; flex-direction: column;
      align-items: center; justify-content: center;
      padding: 24px; position: relative; min-width: 0;
      background: radial-gradient(circle at center, #1e293b 0%, #0f172a 100%);
    }
    #canvas-wrapper {
      box-shadow: var(--shadow-lg); border-radius: var(--radius);
      overflow: hidden; position: relative;
      background: white;
    }
    #canvas-wrapper.show-grid { outline: 2px solid var(--accent); }
    #canvas-info {
      margin-top: 14px; display: inline-flex; align-items: center; gap: 12px;
      font-size: 12px; color: var(--text-muted);
      background: rgba(15,23,42,0.6); padding: 6px 14px; border-radius: 20px;
      backdrop-filter: blur(4px);
    }
    #canvas-info span { display: inline-flex; align-items: center; gap: 4px; }

    /* ===== BUTTONS ===== */
    button {
      padding: 9px 14px; border: none; border-radius: var(--radius-sm);
      cursor: pointer; font-size: 13px; font-weight: 500;
      font-family: inherit; transition: all 0.15s ease;
      display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    }
    button:active { transform: scale(0.98); }
    button:disabled { opacity: 0.5; cursor: not-allowed; }

    .btn-primary {
      background: var(--accent); color: white; width: 100%; margin-bottom: 8px;
      box-shadow: 0 2px 6px rgba(59,130,246,0.25);
    }
    .btn-primary:hover { background: var(--accent-hover); box-shadow: 0 4px 12px rgba(59,130,246,0.35); }
    .btn-danger { background: var(--danger); color: white; width: 100%; margin-bottom: 8px; }
    .btn-danger:hover { background: var(--danger-hover); }
    .btn-success {
      background: var(--success); color: white; font-size: 15px; font-weight: 600;
      box-shadow: 0 2px 8px rgba(34,197,94,0.25);
    }
    .btn-success:hover { background: var(--success-hover); box-shadow: 0 4px 14px rgba(34,197,94,0.35); }
    .btn-secondary { background: var(--bg-hover); color: var(--text-primary); width: 100%; margin-bottom: 8px; border: 1px solid var(--border); }
    .btn-secondary:hover { background: #334155; border-color: var(--border-hover); }
    .btn-toggle {
      width: 40px; height: 40px; background: var(--bg-hover); color: var(--text-primary);
      font-weight: 700; font-size: 14px; display: inline-flex;
      align-items: center; justify-content: center; border-radius: var(--radius-sm);
      border: 1px solid var(--border);
    }
    .btn-toggle:hover { background: #334155; }
    .btn-toggle.active { background: var(--accent); color: white; border-color: var(--accent); }
    .btn-icon { padding: 8px; }

    .align-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
    .align-grid button {
      padding: 10px 4px; font-size: 11px; font-weight: 600;
      background: var(--bg-hover); color: var(--text-secondary); line-height: 1;
      border: 1px solid var(--border);
    }
    .align-grid button:hover { background: #334155; color: var(--text-primary); }

    .font-size-row { display: flex; align-items: center; gap: 10px; }
    .font-size-row input[type="range"] { flex: 1; }
    .font-size-row span { font-size: 12px; color: var(--text-secondary); min-width: 36px; text-align: right; font-weight: 500; }

    .style-row { display: flex; gap: 8px; margin-top: 8px; }
    .layer-row { display: flex; gap: 6px; margin-top: 8px; }
    .layer-row button { flex: 1; font-size: 12px; }
    .mirror-row { display: flex; gap: 6px; margin-top: 8px; }
    .mirror-row button { flex: 1; font-size: 12px; }
    .template-row { display: flex; gap: 6px; margin-top: 8px; align-items: center; }
    .template-row input { margin-bottom: 0; }
    .clip-row { display: flex; gap: 6px; margin-top: 8px; }
    .clip-row button { flex: 1; font-size: 12px; }

    /* ===== HINTS ===== */
    .hint-box {
      background: rgba(59, 130, 246, 0.08); border: 1px solid rgba(59, 130, 246, 0.2);
      border-radius: var(--radius-sm); padding: 10px 12px; font-size: 12px;
      color: #93c5fd; line-height: 1.6;
    }
    .hint-box strong { color: #bfdbfe; }
    .hint-box.touch-hint { background: rgba(148,163,184,0.08); border-color: rgba(148,163,184,0.2); color: var(--text-secondary); }
    .hint-box.touch-hint strong { color: #cbd5e1; }

    /* ===== MODAL ===== */
    #modal-overlay {
      position: fixed; top: 0; left: 0; right: 0; bottom: 0;
      background: rgba(2,6,23,0.75); display: none;
      align-items: center; justify-content: center; z-index: 1000;
      backdrop-filter: blur(4px);
    }
    #modal-order {
      background: var(--bg-panel); border-radius: 16px; padding: 32px;
      max-width: 600px; width: 90%; max-height: 88vh;
      overflow-y: auto; box-shadow: var(--shadow-lg);
      border: 1px solid var(--border);
    }
    #modal-order h2 { color: var(--text-primary); margin-bottom: 24px; font-size: 22px; display: flex; align-items: center; gap: 10px; }
    .order-summary-box {
      background: var(--bg-input); border: 1px solid var(--border); border-radius: var(--radius);
      padding: 16px; margin-bottom: 20px;
    }
    .order-table { width: 100%; border-collapse: collapse; }
    .order-table tr:not(:last-child) td { border-bottom: 1px solid var(--border); }
    .order-table td { padding: 10px 12px; font-size: 14px; vertical-align: top; }
    .order-table td:first-child { color: var(--text-secondary); width: 45%; font-weight: 500; }
    .order-table td:last-child { color: var(--text-primary); font-weight: 400; }
    #order-preview-image { margin: 20px 0; text-align: center; }
    #order-preview-image img { max-width: 100%; border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
    .modal-buttons { display: flex; gap: 12px; margin-top: 24px; }
    .modal-buttons button { flex: 1; padding: 13px; border-radius: var(--radius-sm); }

    .contact-field { margin-bottom: 14px; }
    .contact-field label { display: block; font-size: 13px; color: var(--text-secondary); margin-bottom: 6px; font-weight: 500; }
    .contact-field label .required { color: var(--danger); }
    .contact-field input, .contact-field textarea {
      width: 100%; padding: 10px 12px; border: 1px solid var(--border);
      border-radius: var(--radius-sm); background: var(--bg-input); color: var(--text-primary);
      font-size: 14px; font-family: inherit; outline: none;
      transition: border-color 0.15s, box-shadow 0.15s;
    }
    .contact-field input:focus, .contact-field textarea:focus {
      border-color: var(--accent); box-shadow: 0 0 0 3px rgba(59,130,246,0.15);
    }
    .contact-field input.error, .contact-field textarea.error { border-color: var(--danger); }
    .field-error { font-size: 12px; color: #f87171; margin-top: 4px; display: none; }
    .field-error.visible { display: block; }

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

    #template-select { width: 100%; margin-bottom: 8px; }

    /* ===== LAYERS LIST (список слоёв) ===== */
    #layers-list { max-height: 200px; overflow-y: auto; display:flex;flex-direction:column;gap:2px; }
    .layer-item {
      display: flex; align-items: center; gap: 6px; padding: 5px 8px;
      background: var(--bg-input); border: 1px solid var(--border); border-radius: 4px;
      cursor: grab; font-size: 12px; transition: border-color 0.15s, background 0.15s;
      user-select: none;
    }
    .layer-item:hover { border-color: var(--accent); }
    .layer-item.active { border-color: var(--accent); background: rgba(59,130,246,0.1); }
    .layer-item.dragging { opacity: 0.5; }
    .layer-item.dragover { border-color: var(--success); }
    .layer-icon { width: 18px; height: 18px; flex-shrink: 0; display:flex;align-items:center;justify-content:center;font-size:14px;color:var(--text-muted); }
    .layer-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-secondary); font-size: 11px; }
    .layer-eye, .layer-delete {
      width: 24px; height: 24px; border: none; background: transparent; cursor: pointer;
      display:flex;align-items:center;justify-content:center; flex-shrink: 0;
      color: var(--text-muted); font-size: 14px; padding: 0; border-radius: 4px; transition: color 0.15s;
    }
    .layer-eye:hover { color: var(--text-primary); background: var(--bg-hover); }
    .layer-eye.hidden { color: var(--border); }

    /* ===== BG PRESETS (градиенты/узоры) ===== */
    .bg-presets { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; margin-bottom: 8px; }
    .bg-preset-tile {
      aspect-ratio: 16 / 9; border-radius: var(--radius-sm); cursor: pointer;
      border: 2px solid var(--border); transition: border-color 0.15s, transform 0.1s;
      background-size: cover; background-position: center;
    }
    .bg-preset-tile:hover { border-color: var(--accent); transform: scale(1.05); }
    .bg-preset-tile.active { border-color: var(--text-primary); box-shadow: 0 0 0 2px var(--bg-panel), 0 0 0 3px var(--accent); }
    .touch-hint { display: none; }

    /* ===== PRESET ICONS (готовые логотипы) ===== */
    .icon-style-toggle, .icon-cat-toggle { display: flex; gap: 6px; margin-bottom: 10px; }
    .icon-style-btn, .icon-cat-btn {
      flex: 1; padding: 7px 4px; font-size: 12px; font-weight: 500;
      background: var(--bg-hover); color: var(--text-secondary);
      border: 1px solid var(--border); border-radius: var(--radius-sm);
      cursor: pointer; transition: all 0.15s ease;
    }
    .icon-style-btn:hover, .icon-cat-btn:hover { background: #334155; color: var(--text-primary); }
    .icon-style-btn.active, .icon-cat-btn.active {
      background: var(--accent); color: white; border-color: var(--accent);
    }
    .icon-cat-btn { font-size: 11px; }

    .icon-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
    .icon-tile {
      aspect-ratio: 1 / 1; min-height: 46px; width: 100%; padding: 8px;
      background: var(--bg-hover); border: 1px solid var(--border); border-radius: var(--radius-sm);
      cursor: pointer; display: flex; align-items: center; justify-content: center;
      transition: all 0.15s ease;
    }
    .icon-tile:hover { border-color: var(--accent); background: #334155; }
    .icon-tile svg { width: 100%; height: 100%; color: var(--text-secondary); }
    .icon-tile:hover svg { color: var(--text-primary); }

    /* ===== ICON COLOR (цвет логотипа) ===== */
    .icon-color-row { display: flex; gap: 8px; margin-bottom: 10px; align-items: flex-start; }
    .icon-color-row input[type="color"] { width: 40px; height: 40px; flex-shrink: 0; }
    .icon-color-swatches { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; flex: 1; }
    .icon-color-swatches .swatch { min-height: 18px; }

    /* ===== COLOR SWATCHES (быстрые цвета) ===== */
    .color-swatches { display: grid; grid-template-columns: repeat(8, 1fr); gap: 5px; margin-bottom: 6px; }
    .swatch {
      width: 100%; aspect-ratio: 1 / 1; min-height: 26px; padding: 0;
      border: 2px solid var(--border); border-radius: var(--radius-sm);
      cursor: pointer; transition: transform 0.1s ease, border-color 0.15s ease;
    }
    .swatch:hover { transform: scale(1.12); border-color: var(--text-secondary); }
    .swatch.active { border-color: var(--text-primary); box-shadow: 0 0 0 2px var(--bg-panel), 0 0 0 3px var(--accent); }

    /* ===== HISTORY MODAL ===== */
    #history-overlay { position:fixed;top:0;left:0;right:0;bottom:0;background:rgba(2,6,23,0.75);display:none;align-items:center;justify-content:center;z-index:1000;backdrop-filter:blur(4px); }
    .history-modal { background:var(--bg-panel);border-radius:16px;padding:28px;max-width:500px;width:90%;max-height:80vh;overflow-y:auto;box-shadow:var(--shadow-lg);border:1px solid var(--border); }
    .history-modal h2 { color:var(--text-primary);margin-bottom:20px;font-size:18px;display:flex;align-items:center;gap:8px; }
    .history-list { display:flex;flex-direction:column;gap:6px; }
    .history-item { display:flex;justify-content:space-between;align-items:center;padding:10px 14px;background:var(--bg-input);border:1px solid var(--border);border-radius:var(--radius-sm);transition:border-color 0.15s; }
    .history-item:hover { border-color:var(--accent); }
    .history-time { font-size:13px;color:var(--text-secondary); }
    .history-empty { text-align:center;padding:30px 20px;color:var(--text-muted);font-size:14px;line-height:1.6; }

    /* ===== 3D MODAL ===== */
    #modal-3d-overlay { position:fixed;top:0;left:0;right:0;bottom:0;background:rgba(2,6,23,0.75);display:none;align-items:center;justify-content:center;z-index:1000;backdrop-filter:blur(4px); }
    .modal-3d { background:var(--bg-panel);border-radius:16px;padding:28px;max-width:420px;width:90%;box-shadow:var(--shadow-lg);border:1px solid var(--border);text-align:center; }
    .modal-3d h2 { color:var(--text-primary);margin-bottom:20px;font-size:18px;display:flex;align-items:center;justify-content:center;gap:8px; }
    .modal-3d-scene { position:relative;display:block;min-height:200px;margin:0 auto 12px; }
    .modal-3d-angle { font-size:14px;color:var(--text-muted);margin-bottom:12px;font-weight:500; }
    .modal-3d-controls { display:flex;align-items:center;justify-content:center;gap:16px;margin-bottom:8px; }

    @media (max-width: 1200px) {
      #panel-params { width: 260px; }
      #panel-tools { width: 240px; }
      #app-header h1 { font-size: 13px; }
    }
    @media (max-width: 900px) {
      #app-body { flex-direction: column; }
      #panel-params, #panel-tools { width: 100%; height: auto; max-height: 38vh; padding: 12px; overflow-y: auto; }
      #panel-canvas { order: -1; min-height: 42vh; padding: 10px; }
      #app-header { flex-wrap: wrap; height: auto; min-height: 48px; padding: 6px; gap: 4px; }
      #app-header h1 { font-size: 12px; flex: 1 1 100%; margin-bottom: 2px; text-align: center; }
      .header-btn { padding: 4px 6px; font-size: 10px; gap: 3px; }
      .header-btn .icon { width: 14px; height: 14px; }
      .header-logo { width: 26px; height: 26px; }
      .header-logo svg { width: 14px; height: 14px; }
      .header-sep { height: 18px; }
      #modal-order { padding: 20px; width: 95%; }
      .order-table td { padding: 8px; font-size: 13px; }
      .touch-hint { display: block; }
      .desktop-only { display: none; }
      /* Фикс панелей на мобильных — скрыты по умолчанию */
      .side-panel { width: 0 !important; padding: 0 !important; overflow: hidden; opacity: 0; }
      .side-panel.active { width: 100% !important; padding: 12px !important; opacity: 1; overflow-y: auto; height: auto; max-height: 38vh; }
    }
    @media (max-width: 480px) {
      #panel-params, #panel-tools { max-height: 40vh; }
      #panel-canvas { min-height: 30vh; }
      #app-header h1 { font-size: 11px; }
      .header-btn { padding: 3px 5px; font-size: 9px; }
      .header-btn .label-text { display: none; }
      #canvas-info { font-size: 10px; gap: 6px; padding: 4px 10px; }
      #canvas-wrapper { max-width: 100vw; overflow: hidden; }
    }
