  :root {
    --bg: #f4f6fa;
    --card: #ffffff;
    --border: #e1e5ee;
    --text: #1d2330;
    --muted: #6b7280;
    --accent: #2563eb;
    --accent-light: #eff4ff;
    --accent-dark: #1d4ed8;
    --green: #16a34a;
    --green-light: #ecfdf5;
    --red: #dc2626;
    --red-light: #fef2f2;
    --purple: #7c3aed;
    --purple-light: #f5f3ff;
  }
  * { box-sizing: border-box; margin: 0; padding: 0; }
  body { font-family: 'Segoe UI', system-ui, sans-serif; background: var(--bg); color: var(--text); line-height: 1.5; font-size: 15px; min-height: 100vh; padding: 24px 16px; }

  /* ===== App shell ===== */
  .app { max-width: 760px; margin: 0 auto; }
  .app .inner { display: flex; flex-direction: column; gap: 16px; }

  /* ===== Header ===== */
  header { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px; }
  header h1 { font-size: 1.25rem; letter-spacing: -0.01em; }
  header .sub { color: var(--muted); font-size: 0.84rem; margin-top: 2px; }

  /* ===== Cards ===== */
  .card { background: var(--card); border: 1px solid var(--border); border-radius: 14px; padding: 18px 20px; }
  .card h2 { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.6px; color: var(--muted); margin-bottom: 12px; font-weight: 700; }

  /* ===== Top form (store + contacts) ===== */
  .form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
  .field { display: flex; flex-direction: column; gap: 5px; }
  .field.full { grid-column: 1 / -1; }
  .field label { font-weight: 600; font-size: 0.86rem; }
  .field label .req { color: var(--red); }
  .field input, .field select { width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; font-family: inherit; font-size: 0.95rem; background: #fff; transition: border-color 0.15s, box-shadow 0.15s; }
  .field input:focus, .field select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-light); }
  .field.invalid input, .field.invalid select { border-color: var(--red); background: var(--red-light); }

  /* ===== Chat ===== */
  .chat { display: flex; flex-direction: column; padding: 0; overflow: hidden; }
  .chat-head { display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
  .chat-head .bot-ava { width: 34px; height: 34px; border-radius: 50%; background: var(--purple); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 1.1rem; }
  .chat-head .bot-name { font-weight: 700; font-size: 0.92rem; }
  .chat-head .bot-status { font-size: 0.76rem; color: var(--green); }

  .chat-window { padding: 18px; display: flex; flex-direction: column; gap: 12px; min-height: 280px; max-height: 56vh; overflow-y: auto; background: linear-gradient(#fbfcfe, #f7f9fc); }

  .msg { display: flex; gap: 8px; align-items: flex-end; max-width: 90%; }
  .msg .ava { width: 26px; height: 26px; border-radius: 50%; flex-shrink: 0; display: flex; align-items: center; justify-content: center; font-size: 0.85rem; color: #fff; }
  .msg .bubble { padding: 9px 14px; border-radius: 14px; font-size: 0.93rem; line-height: 1.45; white-space: pre-wrap; word-break: break-word; }
  .msg.bot { align-self: flex-start; }
  .msg.bot .ava { background: var(--purple); }
  .msg.bot .bubble { background: #fff; border: 1px solid var(--border); border-bottom-left-radius: 4px; }
  .msg.user { align-self: flex-end; flex-direction: row-reverse; }
  .msg.user .ava { background: var(--accent); }
  .msg.user .bubble { background: var(--accent); color: #fff; border-bottom-right-radius: 4px; }
  .msg .bubble b { font-weight: 700; }


  .typing { align-self: flex-start; display: flex; gap: 8px; align-items: center; }
  .typing .ava { width: 26px; height: 26px; border-radius: 50%; background: var(--purple); color:#fff; display:flex; align-items:center; justify-content:center; font-size: 0.85rem;}
  .typing .dots { background: #fff; border: 1px solid var(--border); border-radius: 14px; padding: 11px 14px; display: flex; gap: 4px; }
  .typing .dots span { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite; }
  .typing .dots span:nth-child(2) { animation-delay: 0.2s; }
  .typing .dots span:nth-child(3) { animation-delay: 0.4s; }
  @keyframes blink { 0%,60%,100% { opacity: 0.25; } 30% { opacity: 1; } }

  /* ===== Controls (options + input) ===== */
  .chat-controls { border-top: 1px solid var(--border); padding: 12px 16px; background: #fff; }
  .options { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
  .options:empty { display: none; margin: 0; }
  .options button { background: var(--accent-light); border: 1px solid #c7d6fe; color: var(--accent-dark); border-radius: 999px; padding: 8px 15px; font-family: inherit; font-size: 0.88rem; font-weight: 600; cursor: pointer; transition: all 0.12s; }
  .options button:hover { background: var(--accent); color: #fff; border-color: var(--accent); }
  .options button.ghost { background: #fff; color: var(--muted); border-color: var(--border); }
  .options button.ghost:hover { background: var(--bg); color: var(--text); border-color: var(--muted); }
  .options button.warn { background: #fff7ed; border-color: #fed7aa; color: #ea580c; }

  .input-row { display: flex; gap: 8px; align-items: center; }
  .input-row input[type="text"] { flex: 1; padding: 11px 14px; border: 1px solid var(--border); border-radius: 999px; font-family: inherit; font-size: 0.95rem; }
  .input-row input[type="text"]:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-light); }
  .input-row input:disabled { background: var(--bg); color: var(--muted); }
  .input-row .send { width: 42px; height: 42px; flex-shrink: 0; border: none; border-radius: 50%; background: var(--accent); color: #fff; font-size: 1.1rem; cursor: pointer; display: flex; align-items: center; justify-content: center; }
  .input-row .send:disabled { background: #b9c4d6; cursor: not-allowed; }

  .ctrl-meta { font-size: 0.76rem; color: var(--muted); margin-top: 8px; display: flex; justify-content: space-between; align-items: center; }
  .ctrl-meta .ok { color: var(--green); font-weight: 600; }
  .ctrl-meta .file-pick { font-size: 0.8rem; }

  .reset-row { display: flex; justify-content: center; padding: 14px; }
  .reset-row button { background: #fff; border: 1px solid var(--border); border-radius: 8px; padding: 9px 18px; font-family: inherit; font-weight: 600; cursor: pointer; color: var(--text); }
  .reset-row button:hover { border-color: var(--accent); color: var(--accent); }

  .hint-line { font-size: 0.78rem; color: var(--muted); }
  .checkbox-line { display: flex; align-items: center; gap: 8px; cursor: pointer; font-weight: 500; font-size: 0.9rem; }
  .checkbox-line input { width: 17px; height: 17px; accent-color: var(--accent); }

  /* ticket card inside chat */
  .tcard { align-self: stretch; background: #fff; border: 1px solid var(--border); border-left: 4px solid var(--accent); border-radius: 12px; padding: 12px 14px; max-width: 96%; box-shadow: 0 2px 8px rgba(0,0,0,0.05); }
  .tcard.done { border-left-color: var(--green); background: var(--green-light); }
  .tcard-head { display: flex; justify-content: space-between; align-items: center; font-weight: 700; font-size: 0.95rem; margin-bottom: 10px; padding-bottom: 8px; border-bottom: 1px dashed var(--border); }
  .tcard-pri { font-size: 0.72rem; font-weight: 800; padding: 2px 9px; border-radius: 999px; }
  .tcard-pri.p1 { background: var(--red-light); color: var(--red); }
  .tcard-pri.p2 { background: #fff7ed; color: #ea580c; }
  .tcard-pri.p3 { background: var(--green-light); color: var(--green); }
  .tcard-key { font-family: Consolas, monospace; font-weight: 800; background: #fff; border: 1px solid #bbf7d0; color: var(--green); padding: 2px 10px; border-radius: 6px; font-size: 0.9rem; }
  .tc-row { display: grid; grid-template-columns: 92px 1fr; gap: 8px; font-size: 0.86rem; padding: 3px 0; }
  .tc-row span { color: var(--muted); }
  .tc-row b { font-weight: 600; word-break: break-word; }
  .advice-card { align-self: flex-start; display: flex; gap: 10px; background: #fffbeb; border: 1px solid #fde68a; border-left: 4px solid #f59e0b; border-radius: 12px; padding: 12px 14px; max-width: 92%; font-size: 0.92rem; line-height: 1.45; }
  .advice-card .ac-ic { font-size: 1.2rem; line-height: 1; }
  .advice-card b { color: #b45309; }
  .callout-card { align-self: flex-start; display: flex; gap: 10px; background: #fef2f2; border: 1px solid #fecaca; border-left: 4px solid #dc2626; border-radius: 12px; padding: 12px 14px; max-width: 92%; font-size: 0.92rem; line-height: 1.45; }
  .callout-card .co-ic { font-size: 1.2rem; line-height: 1; }
  .callout-card b { color: #b91c1c; }
  .tcard-call { margin-top: 10px; background: #fef2f2; border: 1px solid #fecaca; border-radius: 8px; padding: 8px 12px; font-size: 0.84rem; color: #b91c1c; font-weight: 600; }
  .tcard-foot { margin-top: 10px; padding-top: 8px; border-top: 1px dashed #bbf7d0; font-size: 0.84rem; color: var(--green); display: flex; gap: 8px; align-items: flex-start; }
  .tcard-thumbs { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }
  .tcard-thumbs img { width: 46px; height: 46px; object-fit: cover; border-radius: 6px; border: 1px solid var(--border); }

  /* attach button + media bubbles */
  .input-wrap { position: relative; flex: 1; display: flex; }
  .input-wrap input[type="text"] { width: 100%; padding-left: 44px !important; }
  .attach-btn { position: absolute; left: 5px; top: 50%; transform: translateY(-50%); width: 34px; height: 34px; border: none; border-radius: 50%; background: transparent; font-size: 1.15rem; line-height: 1; cursor: pointer; display: flex; align-items: center; justify-content: center; transition: all 0.15s; opacity: 0.7; z-index: 2; }
  .attach-btn:hover:not(:disabled) { background: var(--accent-light); opacity: 1; }
  .attach-btn:disabled { opacity: 0.3; cursor: not-allowed; }
  .msg .bubble.media { padding: 6px; }
  .media-thumb { max-width: 180px; max-height: 180px; border-radius: 8px; display: block; }
  .media-name { font-size: 0.74rem; opacity: 0.85; margin-top: 4px; }
  .gate-msg { text-align: center; color: var(--muted); font-size: 0.92rem; padding: 40px 18px; line-height: 1.6; }
  .gate-msg b { color: var(--accent); }
  .err-hint { color: var(--red); font-size: 0.78rem; margin-top: 4px; display: none; }
  .err-hint.show { display: block; }

  /* ===== Mobile: авто-переключение по ширине экрана ===== */
  @media (max-width: 640px) {
    header h1 { font-size: 1.05rem; }
    .card { padding: 14px 14px; border-radius: 12px; }
    .form-grid { grid-template-columns: 1fr; }
    .chat-window { max-height: 60vh; padding: 14px; }
  }
