/*
 * Visual compatibility layer for the front-test-v2 interface.
 * Loaded after styles.css: it intentionally changes presentation only.
 */

@font-face {
  font-family: "Roboto";
  src: url("/assets/fonts/Roboto-Variable.ttf") format("truetype");
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
}

:root {
  --ink: #0f172a;
  --ink-soft: #334155;
  --muted: #64748b;
  --muted-light: #94a3b8;
  --canvas: #f1f5f9;
  --paper: #ffffff;
  --line: #e2e8f0;
  --line-dark: #cbd5e1;
  --blue: #2563eb;
  --blue-dark: #1e3a8a;
  --blue-wash: #eff6ff;
  --yellow: #2563eb;
  --yellow-hover: #1d4ed8;
  --green: #15803d;
  --orange: #c2410c;
  --violet: #6d28d9;
  --slate: #64748b;
  --radius: 14px;
  --v2-shadow: 0 6px 18px rgba(15, 23, 42, .04);
  --v2-appbar-height: 85px;
  color: var(--ink);
  background: var(--canvas);
  /* Keep the visual layer aligned with Pedant PRO's UI typeface. */
  --font-sans: "Instrument Sans", ui-sans-serif, system-ui, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
  font-family: var(--font-sans);
  font-synthesis: none;
}

html,
body {
  color: var(--ink);
  background: var(--canvas);
  font-family: var(--font-sans);
  overscroll-behavior-x: none;
}

/* Keep the layout width unchanged when individual views gain a scrollbar. */
html { scrollbar-gutter: stable; }

button,
input,
textarea,
select {
  font-family: inherit;
}

body :is(button, a, input, textarea, select, summary):focus-visible {
  outline: 3px solid rgba(37, 99, 235, .3) !important;
  outline-offset: 2px;
}

::selection {
  color: #fff;
  background: #2563eb;
}

/* App bar */
.site-header,
body[data-role="operator"] .site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  padding: 10px;
  height: 85px;
  border: 0;
  background: var(--canvas);
  backdrop-filter: none;
}

.header-inner,
body[data-role="user"] .header-inner,
.header-inner-operator {
  width: min(1440px, 100%);
  height: 65px;
  min-height: 0;
  margin: 0 auto;
  padding: 0 16px;
  gap: 28px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
  box-shadow: var(--v2-shadow);
}

.brand,
.header-inner-operator .brand {
  color: #1e3a8a;
}

.brand-copy strong {
  display: block;
  color: #1e3a8a;
  font-size: 18px;
  font-weight: 800;
  line-height: 1.15;
  letter-spacing: .01em;
}

.brand-copy small,
.header-inner-operator .brand-copy small {
  color: var(--muted);
}

.user-nav {
  align-self: auto;
  align-items: center;
  gap: 7px;
}

.header-nav,
span.header-nav {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  border: 0;
  border-radius: 999px;
  padding: 0 13px;
  color: #0f172a;
  background: #e2e8f0;
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  letter-spacing: .02em;
  text-transform: uppercase;
  text-decoration: none;
  white-space: nowrap;
  transition: color .18s ease, background-color .18s ease, box-shadow .18s ease, transform .18s ease;
}

.header-nav::after { display: none; }

.header-nav:hover {
  color: #0f172a;
  background: #cbd5e1;
}

.header-nav.is-active,
.header-nav[aria-current="page"] {
  color: #f8fafc;
  background: #0f172a;
  box-shadow: 0 8px 18px rgba(15, 23, 42, .2);
}

.header-actions,
.operator-header-right {
  gap: 14px;
}

.profile-copy {
  display: grid;
  gap: 1px;
  color: var(--ink);
  text-align: right;
  line-height: 1.1;
}

.profile-copy strong {
  font-size: 13px;
  font-weight: 700;
}

.profile-copy small {
  color: var(--muted);
  font-size: 11px;
}

.workspace-link,
.header-inner-operator .header-link {
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 11px;
  color: var(--muted);
  background: #f8fafc;
  font-size: 12px;
  font-weight: 600;
}

.workspace-link:hover,
.header-inner-operator .header-link:hover {
  border-color: #bfdbfe;
  color: var(--blue-dark);
  background: var(--blue-wash);
}

.operator-presence {
  color: var(--muted);
  font-size: 12px;
}

.operator-presence i {
  box-shadow: 0 0 0 3px rgba(34, 197, 94, .12);
  background: #22c55e;
}

.operator-avatar {
  width: 38px;
  height: 38px;
  border: 2px solid #fff;
  color: #fff;
  background: linear-gradient(135deg, #2563eb, #4f46e5);
  box-shadow: 0 4px 12px rgba(37, 99, 235, .2);
  font-size: 12px;
}

/* Shared controls */
.primary-button,
.secondary-button,
.details-toggle {
  border-radius: 10px;
  font-weight: 700;
}

.primary-button {
  border-color: #2563eb;
  color: #fff;
  background: #2563eb;
  box-shadow: 0 8px 18px rgba(37, 99, 235, .18);
}

.primary-button:hover {
  border-color: #1d4ed8;
  color: #fff;
  background: #1d4ed8;
}

.ticket-submit-button:disabled {
  cursor: wait;
  opacity: .78;
}

.ticket-submit-button:disabled:hover {
  border-color: #2563eb;
  background: #2563eb;
}

.ticket-submit-spinner {
  display: none;
  width: 15px;
  height: 15px;
  border: 2px solid rgba(255, 255, 255, .45);
  border-top-color: #fff;
  border-radius: 50%;
  animation: ticket-submit-spin .7s linear infinite;
}

.ticket-submit-button.is-loading .ticket-submit-spinner {
  display: inline-block;
}

.ticket-submit-button.is-loading [data-submit-arrow] {
  display: none;
}

@keyframes ticket-submit-spin {
  to { transform: rotate(360deg); }
}

.secondary-button {
  border-color: #dbe2ea;
  color: #334155;
  background: #fff;
}

.secondary-button:hover {
  border-color: #bfdbfe;
  color: #1e3a8a;
  background: #eff6ff;
}

.resolved-button {
  min-height: 42px;
  border: 1px solid #16a34a;
  border-radius: 10px;
  padding: 0 15px;
  color: #fff;
  background: #16a34a;
  box-shadow: 0 8px 18px rgba(22, 163, 74, .18);
  font-weight: 700;
}

.resolved-button:hover {
  border-color: #15803d;
  color: #fff;
  background: #15803d;
}

.resolution-notice {
  position: fixed;
  z-index: 100;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(15, 23, 42, .16);
  opacity: 0;
  pointer-events: none;
  transition: opacity .22s ease;
}

.resolution-notice.is-visible { opacity: 1; pointer-events: auto; }

.resolution-notice-card {
  display: flex;
  align-items: center;
  gap: 13px;
  width: min(360px, 100%);
  border: 1px solid #bbf7d0;
  border-radius: 16px;
  padding: 17px;
  color: #166534;
  background: #fff;
  box-shadow: 0 18px 50px rgba(15, 23, 42, .2);
  font-family: var(--font-sans);
  transform: translateY(10px) scale(.96);
  transition: transform .28s cubic-bezier(.2, .8, .2, 1);
}

.resolution-notice.is-visible .resolution-notice-card { transform: translateY(0) scale(1); }

.resolution-notice-card > .icon {
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  padding: 6px;
  color: #fff;
  background: #16a34a;
}

.resolution-notice-card strong,
.resolution-notice-card span { display: block; }
.resolution-notice-card strong { font-size: 15px; font-weight: 700; line-height: 1.25; }
.resolution-notice-card span { margin-top: 3px; color: #64748b; font-size: 13px; line-height: 1.35; }

@media (prefers-reduced-motion: reduce) {
  .resolution-notice,
  .resolution-notice-card { transition: none; }
}

.back-button,
.quiet-action,
.text-button,
.resource-links a,
.help-contact button,
.form-note button,
.details-toggle {
  color: #2563eb;
}

.form-note,
.form-note button {
  font-family: var(--font-sans);
}

.form-note { font-weight: 400; }
.form-note button { font-weight: 600; }

.eyebrow {
  color: #2563eb;
  font-weight: 600;
}

h1,
h2,
h3 {
  color: #0f172a;
  letter-spacing: -.025em;
}

/* Loading state, matching the v2 preloader */
.topics-load-state {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: calc(100dvh - var(--v2-appbar-height) - 20px);
  padding: 32px 16px;
  background:
    radial-gradient(1000px 500px at 20% -10%, rgba(59, 130, 246, .13), transparent 55%),
    radial-gradient(850px 420px at 95% 110%, rgba(14, 165, 233, .11), transparent 58%);
}

.topics-load-state .preloader-card {
  display: flex;
  align-items: center;
  flex-direction: column;
  min-width: 290px;
  max-width: 92%;
  border: 1px solid rgba(148, 163, 184, .24);
  border-radius: 16px;
  padding: 20px 22px 18px;
  background: rgba(255, 255, 255, .94);
  box-shadow: 0 14px 32px rgba(15, 23, 42, .12);
  text-align: center;
}

.preloader-orbit {
  position: relative;
  width: 56px;
  height: 56px;
  margin-bottom: 12px;
  border: 3px solid rgba(37, 99, 235, .16);
  border-top-color: #2563eb;
  border-right-color: #0ea5e9;
  border-radius: 50%;
  animation: v2-preloader-spin .92s linear infinite;
}

.preloader-orbit::after {
  position: absolute;
  inset: 10px;
  border: 2px solid rgba(59, 130, 246, .18);
  border-bottom-color: #60a5fa;
  border-radius: 50%;
  animation: v2-preloader-spin-reverse 1.25s linear infinite;
  content: "";
}

.preloader-title {
  color: #1e293b;
  font-size: 16px;
  font-weight: 800;
  line-height: 1.2;
}

.preloader-subtitle {
  margin-top: 6px;
  color: #64748b;
  font-size: 13px;
  line-height: 1.25;
}

@keyframes v2-preloader-spin { to { transform: rotate(360deg); } }
@keyframes v2-preloader-spin-reverse { to { transform: rotate(-360deg); } }

/* User workspace */
.app-main {
  width: min(1180px, calc(100% - 40px));
  min-height: calc(100vh - var(--v2-appbar-height));
  padding: 22px 0 52px;
}

body[data-role="user"] .app-main {
  min-height: calc(100vh - var(--v2-appbar-height));
  padding-top: 12px;
}

.user-hero {
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 24px 26px;
  background: #fff;
  box-shadow: var(--v2-shadow);
}

body[data-role="user"] .user-hero {
  border-bottom: 1px solid var(--line);
  padding: 22px 24px;
}

.user-hero h1 { font-size: clamp(24px, 2.4vw, 30px); }
.user-hero p:not(.eyebrow) { color: var(--muted); }

.topic-section,
body[data-role="user"] .topic-section {
  padding-top: 14px;
}

.section-heading {
  align-items: center;
  margin-bottom: 12px;
  padding: 0 4px;
}

.section-heading h1,
.section-heading h2 { font-size: 22px; }

.topic-grid { gap: 10px; }

.topic-card {
  min-height: 96px;
  border-color: var(--line);
  border-radius: 14px;
  padding: 14px;
  background: #fff;
  box-shadow: var(--v2-shadow);
  transition: border-color .16s ease, box-shadow .16s ease, transform .16s ease, background-color .16s ease;
}

.topic-card:hover {
  border-color: #bfdbfe;
  background: #fff;
  box-shadow: 0 10px 24px rgba(37, 99, 235, .09);
  transform: translateY(-1px);
}

.topic-icon {
  border-radius: 10px;
  color: #2563eb;
  background: #eff6ff;
}

.topic-copy strong { color: #0f172a; font-weight: 600; }
.topic-copy small { color: #64748b; }
.topic-arrow { color: #2563eb; }

.knowledge-page,
.form-page,
.thread-page,
.list-page {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 24px;
  background: #fff;
  box-shadow: var(--v2-shadow);
}

.knowledge-page { width: min(900px, 100%); }
.form-page { width: min(720px, 100%); }
.thread-page { width: min(900px, 100%); }
.list-page { width: min(980px, 100%); }

.breadcrumbs { margin-top: 15px; }
.knowledge-heading { padding-bottom: 22px; }
.knowledge-body {
  border-top-color: var(--line);
  border-bottom: 0;
  padding: 20px 0 2px;
}

.decision-list { gap: 9px; }

.decision-row {
  min-height: 58px;
  border-color: #dbe2ea;
  border-radius: 11px;
  background: #f8fafc;
  box-shadow: none;
}

.decision-row:hover {
  border-color: #93c5fd;
  color: #1e3a8a;
  background: #eff6ff;
  box-shadow: 0 7px 18px rgba(37, 99, 235, .08);
}

.decision-row .icon {
  color: #2563eb;
  background: #dbeafe;
}

.answer-mark {
  color: #2563eb;
  background: #dbeafe;
}

.answer-actions { border-top-color: var(--line); }

.media-preview,
.form-context,
.ticket-details-inline,
.attachment-list > span {
  border-color: #dbeafe;
  background: #f8fbff;
}

.media-preview { border-radius: 11px; }

.ticket-tools {
  gap: 10px;
  padding-bottom: 14px;
}

.search-control,
.sort-control select,
.extra-filter select,
.status-select select,
.request-form input:not([type="file"]),
.request-form textarea,
.reply-form textarea {
  border-color: #dbe2ea;
  border-radius: 10px;
  background: #f8fafc;
  box-shadow: none;
}

.search-control:focus-within,
.request-form input:focus,
.request-form textarea:focus,
.reply-form textarea:focus {
  border-color: #93c5fd;
  background: #fff;
  box-shadow: 0 0 0 4px rgba(37, 99, 235, .1);
}

.filter-pill {
  border-color: var(--line);
  color: #64748b;
  background: #fff;
}

.filter-pill.is-active {
  border-color: #bfdbfe;
  color: #1e3a8a;
  background: #eff6ff;
}

.ticket-list,
.user-ticket-list,
body[data-role="user"] .ticket-list {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
}

.ticket-row,
.user-ticket-row,
body[data-role="user"] .ticket-row {
  border-bottom-color: var(--line);
  padding-right: 14px;
  padding-left: 14px;
  background: #fff;
}

.ticket-row:hover,
.user-ticket-row:hover,
body[data-role="user"] .ticket-row:hover {
  background: #f8fbff;
}

.user-ticket-row.is-awaiting-response,
body[data-role="user"] .ticket-row.is-awaiting-response {
  background: #fff7f7;
  box-shadow: inset 3px 0 #dc2626;
}

.user-ticket-row.is-awaiting-response:hover,
body[data-role="user"] .ticket-row.is-awaiting-response:hover {
  background: #fff1f2;
}

.ticket-awaiting-response {
  min-height: 22px;
  border: 1px solid #fecaca;
  border-radius: 999px;
  padding: 3px 8px;
  color: #b42318;
  background: #fee2e2;
}

.ticket-awaiting-response i {
  background: #dc2626;
  box-shadow: 0 0 0 3px rgba(220, 38, 38, .12);
}

.request-form {
  border-color: var(--line);
  border-radius: 14px;
  background: #fff;
  box-shadow: var(--v2-shadow);
}

.form-context {
  border: 1px solid #dbeafe;
  border-left: 3px solid #2563eb;
  border-radius: 10px;
  padding: 10px 12px;
}

.thread-heading {
  border-bottom-color: var(--line);
}

.messages {
  gap: 14px;
}

.message-avatar {
  width: 32px;
  height: 32px;
  color: #1e40af;
  background: #dbeafe;
  font-size: 10px;
}

.message-item.is-own .message-avatar {
  color: #fff;
  background: linear-gradient(135deg, #2563eb, #4f46e5);
}

.message-bubble {
  max-width: 100%;
  border-color: #e2e8f0;
  border-radius: 4px 12px 12px 12px;
  padding: 10px 13px;
  color: #334155;
  background: #fff;
  box-shadow: 0 2px 6px rgba(15, 23, 42, .04);
  overflow-wrap: anywhere;
  word-break: break-word;
}

.message-link {
  color: #2563eb;
  text-decoration: underline;
  text-decoration-color: rgba(37, 99, 235, .4);
  text-underline-offset: 2px;
}

.message-link:hover {
  color: #1d4ed8;
  text-decoration-color: currentColor;
}

.message-item.is-own .message-bubble {
  border-color: #bfdbfe;
  border-radius: 12px 4px 12px 12px;
  color: #1e3a8a;
  background: #eff6ff;
}

.message-item.is-system .message-bubble {
  border-color: #fde68a;
  color: #854d0e;
  background: #fffbeb;
}

.reply-form {
  border-top-color: var(--line);
}

.reply-form textarea { background: #fff; }

.closed-thread {
  border-radius: 10px;
  padding: 12px 14px;
  color: #166534;
  background: #f0fdf4;
}

/* Operator: three independent CRM cards */
body[data-role="operator"] {
  background: var(--canvas);
}

body[data-role="operator"] .app-main {
  width: min(1600px, calc(100% - 20px));
  min-height: 0;
  padding: 0 0 10px;
}

.operator-workspace {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr) 300px;
  gap: 8px;
  height: calc(100dvh - 95px);
  min-height: 520px;
  overflow: visible;
  border: 0;
  border-radius: 0;
  background: var(--canvas);
}

.queue-panel,
.operator-thread-head,
.operator-messages,
.operator-thread .reply-form,
.context-profile,
.context-section {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
  box-shadow: var(--v2-shadow);
}

.queue-panel {
  overflow: hidden;
  border-right: 1px solid var(--line);
}

.queue-title {
  align-items: center;
  padding: 16px 16px 11px;
}

.queue-title .eyebrow { margin-bottom: 3px; }
.queue-title h1 { font-size: 23px; }

.queue-title > span {
  min-width: 27px;
  height: 27px;
  color: #1e3a8a;
  background: #dbeafe;
}

.queue-search {
  min-height: 40px;
  margin: 0 14px 10px;
  background: #f8fafc;
}

.queue-panel .status-filters {
  padding: 0 14px 11px;
}

.queue-panel .filter-pill {
  min-height: 29px;
  padding: 0 9px;
  font-size: 10px;
}

.extra-filter {
  margin: 0 14px 10px;
  border-color: var(--line);
}

.queue-list {
  flex: 1 1 auto;
  min-height: 0;
  border-top-color: var(--line);
  scrollbar-color: #cbd5e1 transparent;
  scrollbar-width: thin;
}

.queue-item {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  padding: 11px 13px;
  border-bottom-color: #eef2f7;
  background: #fff;
}

.queue-item:hover { background: #f8fafc; }

.queue-item.is-active {
  box-shadow: inset 3px 0 0 #2563eb;
  background: #eff6ff;
}

.queue-avatar,
.operator-client-avatar,
.context-avatar {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 50%;
  color: #1e40af;
  background: #bfdbfe;
  font-weight: 800;
}

.queue-avatar {
  width: 42px;
  height: 42px;
  font-size: 13px;
}

.queue-item-content { min-width: 0; }

.queue-item-content > strong {
  display: block;
  overflow: hidden;
  margin-top: 5px;
  color: #0f172a;
  font-size: 13px;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.queue-item-content > small {
  display: block;
  overflow: hidden;
  margin-top: 3px;
  color: #64748b;
  font-size: 11px;
  line-height: 1.3;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.queue-item-content > small b {
  color: #334155;
  font-weight: 600;
}

.queue-item-top time { font-size: 10px; }
.queue-panel .pagination { margin: auto 14px 12px; }

.operator-thread {
  display: flex;
  min-width: 0;
  min-height: 0;
  gap: 8px;
  flex-direction: column;
  overflow: hidden;
  background: transparent;
}

.operator-thread-head {
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr) auto;
  gap: 11px;
  align-items: center;
  flex: 0 0 auto;
  padding: 11px 14px;
  border-bottom: 1px solid var(--line);
}

.operator-client-avatar {
  width: 46px;
  height: 46px;
  font-size: 14px;
}

.operator-ticket-title { min-width: 0; }
.operator-ticket-title p { margin-bottom: 2px; font-size: 10px; }
.operator-ticket-title h2 { overflow: hidden; font-size: 17px; text-overflow: ellipsis; white-space: nowrap; }
.operator-ticket-title > span { margin-top: 5px; }

.operator-messages {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 18px 20px;
  scrollbar-color: #cbd5e1 transparent;
  scrollbar-width: thin;
}

.operator-thread .reply-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 9px;
  align-items: end;
  flex: 0 0 auto;
  margin: 0;
  padding: 10px 12px;
  border-top: 1px solid var(--line);
}

.operator-thread .reply-form textarea {
  grid-column: 1;
  grid-row: 1;
  min-height: 46px;
  max-height: 112px;
  padding: 12px 13px;
  resize: vertical;
}

.operator-thread .reply-form > div { display: contents; }

.operator-thread .reply-form .form-error {
  grid-column: 1 / -1;
  grid-row: 2;
}

.operator-thread .reply-form .message-send {
  grid-column: 2;
  grid-row: 1;
  min-width: 46px;
  min-height: 46px;
  border-radius: 50%;
  padding: 0;
}

.operator-thread .reply-form .message-send span { display: none; }

.operator-context {
  display: flex;
  gap: 8px;
  flex-direction: column;
  overflow-y: auto;
  border: 0;
  background: transparent;
  scrollbar-color: #cbd5e1 transparent;
  scrollbar-width: thin;
}

.context-profile {
  display: grid;
  justify-items: center;
  flex: 0 0 auto;
  padding: 15px;
  text-align: center;
}

.context-avatar {
  width: 60px;
  height: 60px;
  color: #fff;
  background: linear-gradient(135deg, #2563eb, #4f46e5);
  font-size: 18px;
}

.context-profile h2 {
  margin-top: 8px;
  font-size: 18px;
}

.context-profile p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 11px;
}

.context-section {
  flex: 0 0 auto;
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.context-section .eyebrow {
  margin-bottom: 9px;
  color: #64748b;
}

.context-list { gap: 0; }

.context-list div {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 0;
  border-top: 1px solid #eef2f7;
}

.context-list div:first-child { border-top: 0; padding-top: 0; }
.context-list dt { flex: 0 0 38%; color: #64748b; font-size: 12px; }
.context-list dd { max-width: 60%; color: #0f172a; text-align: right; font-size: 12px; }

.status-select select {
  min-height: 42px;
  border-color: #dbe2ea;
  background: #f8fafc;
}

/* Tablet: preserve the v2 columns until the stateful mobile switch takes over. */
@media (max-width: 1180px) {
  .operator-workspace { grid-template-columns: 310px minmax(0, 1fr) 260px; }
  .context-list div { display: grid; }
  .context-list dd { max-width: none; text-align: left; }
}

@media (max-width: 850px) {
  .site-header,
  body[data-role="operator"] .site-header {
    height: 74px;
    padding: 7px;
  }

  .header-inner,
  body[data-role="user"] .header-inner,
  .header-inner-operator {
    width: 100%;
    height: 60px;
    min-height: 0;
    padding: 0 13px;
  }

  .app-main { width: min(100% - 24px, 1180px); }

  .topic-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }

  body[data-role="operator"] .app-main {
    width: 100%;
    padding: 0 7px 7px;
  }

  .operator-workspace {
    display: block;
    height: calc(100dvh - 81px);
    min-height: 0;
    border-radius: 14px;
  }

  .queue-panel,
  .operator-thread,
  .operator-context {
    width: 100%;
    height: 100%;
  }

  .queue-panel { border-radius: 14px; }

  .operator-thread-head,
  .operator-messages,
  .operator-thread .reply-form,
  .context-profile,
  .context-section { border-radius: 12px; }

  .mobile-queue-back { grid-column: 1 / -1; }

  .operator-context { padding-bottom: 8px; }
}

@media (max-width: 640px) {
  :root {
    --v2-appbar-height: 68px;
    --mobile-header-h: 74px;
  }

  .site-header,
  body[data-role="operator"] .site-header {
    height: 68px;
    padding: 6px;
  }

  .header-inner,
  body[data-role="user"] .header-inner,
  .header-inner-operator {
    height: 56px;
    min-height: 0;
    border-radius: 12px;
    padding: 0 12px;
  }

  .brand-copy strong {
    max-width: none;
    font-size: 16px;
  }

  .operator-avatar {
    width: 34px;
    height: 34px;
  }

  body[data-role="operator"] .header-inner-operator {
    gap: 7px;
  }

  body[data-role="operator"] .brand-copy strong {
    max-width: 112px;
    font-size: 14px;
  }

  body[data-role="operator"] .user-nav {
    gap: 4px;
    margin-left: auto;
  }

  body[data-role="operator"] .header-nav {
    min-height: 30px;
    padding: 0 8px;
    font-size: 10px;
  }

  body[data-role="operator"] .operator-header-right {
    gap: 5px;
  }

  .app-main,
  body[data-role="user"] .app-main {
    width: min(100% - 16px, 1180px);
    padding-top: 8px;
  }

  .user-hero,
  body[data-role="user"] .user-hero {
    border-radius: 12px;
    padding: 16px;
  }

  body[data-role="user"] .user-hero h1 { font-size: 25px; }

  .topic-grid { grid-template-columns: 1fr; }

  .topic-card,
  body[data-role="user"] .topic-card {
    min-height: 68px;
    border-radius: 12px;
    padding: 12px;
    box-shadow: 0 4px 12px rgba(15, 23, 42, .04);
  }

  .knowledge-page,
  .form-page,
  .thread-page,
  .list-page {
    border-radius: 12px;
    padding: 16px;
  }

  body[data-role="user"] .mobile-bottom-nav {
    right: 6px;
    bottom: 6px;
    left: 6px;
    overflow: hidden;
    min-height: calc(58px + env(safe-area-inset-bottom));
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 4px 7px calc(4px + env(safe-area-inset-bottom));
    background: rgba(255, 255, 255, .98);
    box-shadow: 0 -2px 20px rgba(15, 23, 42, .1);
    font-family: var(--font-sans);
  }

  .mobile-nav-item {
    min-height: 48px;
    border-radius: 10px;
    font-family: var(--font-sans) !important;
    font-size: 11px;
    font-weight: 500;
    line-height: 1.2;
    letter-spacing: 0;
  }

  .mobile-nav-item.is-active { font-weight: 600; }

  .mobile-nav-item b.unread-dot {
    top: 4px;
    right: calc(50% - 20px);
    min-width: 11px;
    width: 11px;
    height: 11px;
    padding: 0;
    border: 2px solid #fff;
    border-radius: 50%;
    background: linear-gradient(145deg, #ff6868, #e11d48);
    box-shadow:
      0 0 0 2px rgba(225, 29, 72, .12),
      0 2px 5px rgba(190, 18, 60, .28);
  }

  body[data-role="operator"] .app-main { padding: 0 6px 6px; }

  .operator-workspace {
    height: calc(100dvh - var(--mobile-header-h));
    border-radius: 12px;
  }

  .queue-panel,
  .operator-thread,
  .operator-context {
    height: calc(100dvh - var(--mobile-header-h));
  }

  .queue-title { padding: 14px 13px 10px; }
  .queue-title h1 { font-size: 21px; }
  .queue-search { margin-right: 12px; margin-left: 12px; }
  .queue-panel .status-filters { padding-right: 12px; padding-left: 12px; }
  .extra-filter { margin-right: 12px; margin-left: 12px; }
  .queue-item { padding-right: 12px; padding-left: 12px; }

  .operator-thread-head {
    grid-template-columns: 40px minmax(0, 1fr) auto;
    padding: 10px 12px;
  }

  .mobile-queue-back {
    grid-column: 1 / -1;
    padding-bottom: 4px;
  }

  .operator-client-avatar {
    width: 40px;
    height: 40px;
  }

  .operator-messages { padding: 14px 12px; }

  .operator-thread .reply-form {
    grid-template-columns: minmax(0, 1fr) 44px;
    padding: 9px 10px max(9px, env(safe-area-inset-bottom));
  }

  .operator-thread .reply-form textarea {
    min-height: 44px;
    border-radius: 22px;
  }

  .operator-thread .reply-form .message-send {
    min-width: 44px;
    min-height: 44px;
  }

  .context-section,
  .context-profile { margin-right: 0; margin-left: 0; }

  body[data-role="user"][data-view="ticket"] .thread-page {
    border: 0;
    border-radius: 0;
    padding: 0;
    box-shadow: none;
  }

  body[data-role="user"][data-view="ticket"] .thread-heading,
  body[data-role="user"][data-view="ticket"] .thread .messages,
  body[data-role="user"][data-view="ticket"] .thread-page > .back-button {
    padding-right: 14px;
    padding-left: 14px;
  }
}

@media (max-width: 390px) {
  body[data-role="operator"] .operator-avatar { display: none; }

  body[data-role="operator"] .brand-copy strong {
    max-width: 96px;
    font-size: 13px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .preloader-orbit,
  .preloader-orbit::after { animation-duration: 2.4s; }

  .topic-card,
  .header-nav { transition: none; }
}

/* Viewport-locked conversations: the document stays still, feeds scroll. */
body[data-role="user"][data-view="ticket"],
body[data-role="operator"] {
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
}

body[data-role="user"][data-view="ticket"] .thread-page {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

body[data-role="user"][data-view="ticket"] .thread-page > .back-button,
body[data-role="user"][data-view="ticket"] .thread-heading,
body[data-role="user"][data-view="ticket"] .reply-form,
body[data-role="user"][data-view="ticket"] .closed-thread {
  flex: 0 0 auto;
}

body[data-role="user"][data-view="ticket"] .ticket-details-inline {
  flex: 0 1 auto;
  min-height: 0;
  max-height: min(32dvh, 260px);
  overflow-y: auto;
  overscroll-behavior: contain;
}

body[data-role="user"][data-view="ticket"] .thread {
  display: flex;
  flex: 1 1 0;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

body[data-role="user"][data-view="ticket"] .thread .messages {
  flex: 1 1 0;
  min-height: 0;
  max-height: none;
  align-content: start;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
}

body[data-role="user"][data-view="ticket"] .reply-form textarea {
  max-height: min(160px, 25dvh);
}

body[data-role="operator"] .app-main { overflow: hidden; }

body[data-role="operator"] .operator-workspace,
body[data-role="operator"] .queue-panel,
body[data-role="operator"] .operator-thread,
body[data-role="operator"] .operator-context {
  min-height: 0;
}

body[data-role="operator"] :is(.queue-list, .operator-messages, .operator-context) {
  overscroll-behavior: contain;
}

body[data-role="operator"] .operator-messages {
  align-content: start;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
}

@media (min-width: 641px) {
  body[data-role="user"][data-view="ticket"] .app-main {
    height: calc(100dvh - var(--v2-appbar-height));
    min-height: 0;
    padding: 12px 0;
    overflow: hidden;
  }

  body[data-role="user"][data-view="ticket"] .thread-page { height: 100%; }
}

@media (min-width: 641px) and (max-width: 850px) {
  :root { --v2-appbar-height: 74px; }
}

@media (max-width: 640px) {
  body[data-role="user"][data-view="ticket"] .app-main {
    width: 100%;
    height: calc(100dvh - var(--mobile-nav-h) - env(safe-area-inset-bottom));
    min-height: 0;
    padding: 0;
    overflow: hidden;
  }

  body[data-role="user"][data-view="ticket"] .thread-page { height: 100%; }

  body.keyboard-open[data-role="user"][data-view="ticket"] .app-main {
    height: var(--visual-viewport-height);
  }
}

/* Chat media composer */
.reply-form.chat-composer,
.operator-thread .reply-form.chat-composer {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.reply-form.chat-composer > .composer-extras,
.operator-thread .reply-form.chat-composer > .composer-extras {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.chat-composer [data-pending-attachments] {
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
  min-width: 0;
}

.chat-composer [data-pending-attachments]:empty { display: none; }

.pending-attachment {
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr) 26px;
  gap: 7px;
  align-items: center;
  min-width: min(230px, 100%);
  max-width: 310px;
  min-height: 38px;
  border: 1px solid #dbeafe;
  border-radius: 10px;
  padding: 4px 5px;
  background: #f8fbff;
}

.pending-attachment-preview {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  color: #2563eb;
  background: #dbeafe;
}

.pending-attachment-preview .icon { width: 16px; height: 16px; }

.pending-attachment-copy {
  display: grid;
  min-width: 0;
  line-height: 1.15;
}

.pending-attachment-copy strong,
.pending-attachment-copy small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pending-attachment-copy strong { color: #0f172a; font-size: 11px; }
.pending-attachment-copy small { margin-top: 2px; color: #64748b; font-size: 10px; }

.pending-attachment > button {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border: 0;
  border-radius: 50%;
  padding: 0;
  color: #64748b;
  background: transparent;
}

.pending-attachment > button:hover { color: #b91c1c; background: #fee2e2; }
.pending-attachment > button .icon { width: 14px; height: 14px; }

.recording-state {
  display: inline-flex;
  align-items: center;
  justify-self: start;
  gap: 7px;
  min-height: 28px;
  border-radius: 999px;
  padding: 0 10px;
  color: #991b1b;
  background: #fef2f2;
  font-size: 11px;
  font-weight: 700;
}

.recording-state[hidden] { display: none; }

.recording-state::before {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #ef4444;
  box-shadow: 0 0 0 4px rgba(239, 68, 68, .12);
  content: "";
  animation: recording-pulse 1.25s ease-in-out infinite;
}

@keyframes recording-pulse {
  50% { opacity: .42; transform: scale(.82); }
}

.reply-form.chat-composer > .composer-controls,
.operator-thread .reply-form.chat-composer > .composer-controls {
  position: relative;
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr) 46px;
  gap: 7px;
  align-items: center;
  min-width: 0;
}

.composer-action {
  position: relative;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 1px solid #dbe2ea;
  border-radius: 50%;
  padding: 0;
  color: #475569;
  background: #f8fafc;
  cursor: pointer;
  transition: color .16s ease, border-color .16s ease, background-color .16s ease, transform .16s ease;
}

.composer-action:hover {
  border-color: #93c5fd;
  color: #1d4ed8;
  background: #eff6ff;
}

.composer-action:active { transform: scale(.95); }
.composer-action:disabled { cursor: not-allowed; opacity: .42; }
.composer-action .icon { width: 18px; height: 18px; }

.composer-action[data-chat-record][aria-pressed="true"] {
  border-color: #fecaca;
  color: #fff;
  background: #ef4444;
  box-shadow: 0 0 0 4px rgba(239, 68, 68, .12);
}

/* The microphone belongs to the text field, not to the row of actions. */
.composer-action[data-chat-record] {
  position: absolute;
  z-index: 1;
  right: 58px;
  width: 32px;
  height: 32px;
  border: 0;
  color: #64748b;
  background: transparent;
}

.composer-action[data-chat-record] .icon {
  width: 20px;
  height: 20px;
}

.reply-form.chat-composer .composer-controls textarea,
.operator-thread .reply-form.chat-composer .composer-controls textarea {
  grid-column: 2;
  grid-row: 1;
  min-height: 44px;
  max-height: min(128px, 25dvh);
  margin: 0;
  border-radius: 22px;
  padding: 11px 52px 11px 15px;
  resize: none;
  /* The field grows while typing; keep any overflow scrollable but unobtrusive. */
  scrollbar-width: none;
}

.reply-form.chat-composer .composer-controls textarea:focus,
.operator-thread .reply-form.chat-composer .composer-controls textarea:focus {
  box-shadow: none;
}

body .reply-form.chat-composer .composer-controls textarea:focus-visible,
body .operator-thread .reply-form.chat-composer .composer-controls textarea:focus-visible {
  outline: none !important;
  outline-offset: 0;
}

.reply-form.chat-composer .composer-controls textarea::-webkit-scrollbar,
.operator-thread .reply-form.chat-composer .composer-controls textarea::-webkit-scrollbar {
  display: none;
}

.reply-form.chat-composer .composer-controls .message-send,
.operator-thread .reply-form.chat-composer .composer-controls .message-send {
  grid-column: 3;
  grid-row: 1;
  width: 46px;
  min-width: 46px;
  min-height: 46px;
  border-radius: 50%;
  padding: 0;
}

.reply-form.chat-composer .composer-controls .message-send span { display: none; }

.chat-composer .form-error:empty { display: none; }

/* Media inside chat messages */
.message-item > div { min-width: 0; }

.message-files {
  display: grid;
  gap: 7px;
  min-width: 0;
  margin-top: 7px;
}

.message-attachment {
  overflow: hidden;
  width: min(360px, 100%);
  border: 1px solid #dbe2ea;
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 2px 6px rgba(15, 23, 42, .04);
}

.message-item.is-own .message-files { justify-items: end; }
.message-item.is-own .message-attachment { border-color: #bfdbfe; background: #f8fbff; }

.message-attachment-frame {
  display: grid;
  place-items: center;
  overflow: hidden;
  min-height: 54px;
  color: #2563eb;
  background: #eff6ff;
}

.message-attachment-frame img,
.message-attachment-frame video {
  display: block;
  width: 100%;
  max-height: min(280px, 42dvh);
  object-fit: contain;
  background: #0f172a;
}

.message-attachment-frame img { object-fit: cover; background: #e2e8f0; }

.message-image-button {
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  cursor: zoom-in;
  background: transparent;
}

.message-image-button img { pointer-events: none; }

.image-viewer {
  box-sizing: border-box;
  width: 100dvw;
  max-width: none;
  height: 100dvh;
  max-height: none;
  margin: 0;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  border: 0;
  color: #fff;
  background: transparent;
}

.image-viewer[open] {
  display: grid;
  place-items: center;
}

.image-viewer::backdrop { background: rgba(2, 6, 23, .92); }

.image-viewer > img {
  display: block;
  max-width: 100%;
  max-height: 100%;
  border-radius: 6px;
  object-fit: contain;
  box-shadow: 0 12px 40px rgba(0, 0, 0, .35);
}

.image-viewer-close {
  position: fixed;
  z-index: 1;
  top: max(12px, env(safe-area-inset-top));
  right: max(12px, env(safe-area-inset-right));
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, .22);
  border-radius: 999px;
  color: #fff;
  cursor: pointer;
  background: rgba(15, 23, 42, .72);
}

.image-viewer-close .icon { width: 18px; height: 18px; }

body.has-image-viewer { overflow: hidden; }

.message-attachment.is-audio .message-attachment-frame {
  min-height: 58px;
  padding: 8px 10px;
  background: #f8fafc;
}

.message-attachment-frame audio {
  display: block;
  width: 100%;
  min-width: 0;
  height: 40px;
}

.message-document {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 58px;
  padding: 9px 11px;
  color: #1e3a8a;
  text-decoration: none;
  background: #f8fafc;
}

.message-document:hover { background: #eff6ff; }
.message-document .icon { width: 24px; height: 24px; color: #2563eb; }
.message-document span { min-width: 0; }
.message-document strong,
.message-document small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.message-document strong { font-size: 12px; }
.message-document small { margin-top: 3px; color: #64748b; font-size: 10px; }

@media (max-width: 640px) {
  /* Compact knowledge articles so the useful answer appears above the fold. */
  .knowledge-page {
    padding: 10px 12px 12px;
  }

  .knowledge-page > .back-button {
    min-height: 20px;
    font-size: 13px;
  }

  .knowledge-page .breadcrumbs {
    margin: 4px 0;
    font-size: 11px;
  }

  .knowledge-page .knowledge-heading {
    padding-bottom: 8px;
  }

  .knowledge-page .knowledge-heading h1 {
    font-size: 25px;
    line-height: 1.14;
  }

  .knowledge-page .knowledge-heading p:not(.eyebrow) {
    margin-top: 4px;
    font-size: 13px;
    line-height: 1.4;
  }

  .knowledge-page .knowledge-body {
    padding: 9px 0 12px;
  }

  .knowledge-page .answer-block {
    gap: 9px;
    padding: 0 0 8px;
  }

  .knowledge-page .answer-block h2 {
    margin: 2px 0 5px;
    font-size: 17px;
  }

  .knowledge-page .answer-block p {
    font-size: 13px;
    line-height: 1.48;
  }

  .knowledge-page .media-list { gap: 6px; margin-top: 0; }
  .knowledge-page .media-preview { gap: 8px; padding: 8px; }
  .knowledge-page .answer-actions { margin-top: 14px; padding-top: 12px; }

  body.keyboard-open[data-role="user"] .mobile-bottom-nav {
    display: none;
  }

  .reply-form.chat-composer,
  .operator-thread .reply-form.chat-composer {
    gap: 6px;
    padding: 8px 6px max(8px, env(safe-area-inset-bottom));
  }

  .chat-composer [data-pending-attachments] {
    overflow-x: auto;
    flex-wrap: nowrap;
    padding-bottom: 2px;
    scrollbar-width: thin;
  }

  .pending-attachment {
    flex: 0 0 min(245px, 78vw);
    min-width: 0;
  }

  .reply-form.chat-composer > .composer-controls,
  .operator-thread .reply-form.chat-composer > .composer-controls {
    align-self: stretch;
    width: 100%;
    margin: 0;
    padding: 0;
    grid-template-columns: 32px minmax(0, 1fr) 38px;
    gap: 4px;
    align-items: center;
  }

  .composer-action { width: 32px; height: 32px; }
  .composer-action .icon { width: 16px; height: 16px; }
  .composer-action[data-chat-record] { right: 46px; }

  .reply-form.chat-composer .composer-controls textarea,
  .operator-thread .reply-form.chat-composer .composer-controls textarea {
    grid-column: 2;
    height: 42px;
    min-height: 42px;
    max-height: min(104px, 24dvh);
    line-height: 20px;
    overflow-y: auto;
    padding-right: 42px;
    padding-left: 13px;
  }

  .reply-form.chat-composer .composer-controls .message-send,
  .operator-thread .reply-form.chat-composer .composer-controls .message-send {
    grid-column: 3;
    grid-row: 1;
    width: 38px;
    min-width: 38px;
    min-height: 38px;
  }

  .message-attachment { width: min(310px, 100%); }
  .message-attachment-frame img,
  .message-attachment-frame video { max-height: min(220px, 34dvh); }
}

@media (prefers-reduced-motion: reduce) {
  .recording-state::before { animation: none; }
}

/* В открытом обращении нижняя навигация не нужна: экран занят диалогом. */
.ticket-compact-header { display: none; }

.thread-heading-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.ticket-actions {
  position: relative;
  flex: 0 0 auto;
}

.ticket-actions-toggle {
  display: grid;
  width: 34px;
  height: 34px;
  padding: 0 0 7px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--ink-soft);
  font-family: Arial, sans-serif;
  font-size: 25px;
  font-weight: 700;
  line-height: 1;
  place-items: center;
}

.ticket-actions-toggle:hover,
.ticket-actions-toggle[aria-expanded="true"] {
  background: #f1f5f9;
  color: var(--ink);
}

.ticket-actions-menu {
  position: absolute;
  z-index: 30;
  top: calc(100% + 5px);
  right: 0;
  width: max-content;
  min-width: 170px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 14px 35px rgba(15, 23, 42, .16);
}

.ticket-actions-menu[hidden] { display: none; }

.ticket-actions-menu button {
  width: 100%;
  padding: 9px 11px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #b42318;
  font-size: 14px;
  font-weight: 600;
  text-align: left;
}

.ticket-actions-menu button:hover { background: #fff1f0; }

.ticket-close-dialog {
  width: min(440px, calc(100% - 28px));
  max-width: none;
  padding: 0;
  border: 0;
  border-radius: 20px;
  background: transparent;
  color: var(--ink);
  box-shadow: 0 24px 70px rgba(15, 23, 42, .24);
}

.ticket-close-dialog::backdrop {
  background: rgba(15, 23, 42, .52);
  backdrop-filter: blur(2px);
}

.ticket-close-card {
  position: relative;
  display: grid;
  gap: 16px;
  padding: 24px;
  border-radius: 20px;
  background: #fff;
}

.ticket-close-card h2 {
  margin: 0;
  padding-right: 34px;
  font-size: 21px;
  line-height: 1.25;
}

.ticket-close-card > p {
  margin: -8px 0 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

.ticket-close-card label {
  display: grid;
  gap: 7px;
  color: var(--ink-soft);
  font-size: 13px;
  font-weight: 650;
}

.ticket-close-card textarea {
  width: 100%;
  min-height: 104px;
  resize: vertical;
  padding: 12px 13px;
  border: 1px solid var(--line);
  border-radius: 12px;
  outline: none;
  color: var(--ink);
  font: inherit;
  font-size: 15px;
  font-weight: 400;
  line-height: 1.45;
}

.ticket-close-card textarea:focus {
  border-color: #94a3b8;
  box-shadow: 0 0 0 3px rgba(148, 163, 184, .18);
}

.ticket-close-x {
  position: absolute;
  top: 17px;
  right: 17px;
  display: grid;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  place-items: center;
}

.ticket-close-x:hover { background: #f1f5f9; }
.ticket-close-x .icon { width: 18px; height: 18px; }

.ticket-close-buttons {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.ticket-close-buttons button {
  min-height: 42px;
  padding: 0 17px;
  border-radius: 11px;
  font-size: 14px;
  font-weight: 650;
}

.danger-button {
  border: 1px solid #d92d20;
  background: #d92d20;
  color: #fff;
}

.danger-button:hover { background: #b42318; }
.danger-button:disabled { cursor: wait; opacity: .65; }

@media (max-width: 640px) {
  body[data-role="user"][data-view="ticket"] .mobile-bottom-nav {
    display: none;
  }

  body[data-role="user"][data-view="ticket"] .app-main,
  body[data-role="user"][data-view="ticket"] .thread-page {
    height: 100dvh;
    min-height: 0;
  }

  body.keyboard-open[data-role="user"][data-view="ticket"] .app-main,
  body.keyboard-open[data-role="user"][data-view="ticket"] .thread-page {
    height: var(--visual-viewport-height);
    min-height: 0;
  }

  body.keyboard-open[data-role="user"][data-view="ticket"] .thread .messages {
    scroll-padding-bottom: 18px;
  }

  body[data-role="user"][data-view="ticket"] .thread-page > .back-button,
  body[data-role="user"][data-view="ticket"] .thread-heading {
    display: none;
  }

  body[data-role="user"][data-view="ticket"] .ticket-compact-header {
    display: grid;
    gap: 6px;
    flex: 0 0 auto;
    padding: 9px 14px 10px;
    border-bottom: 1px solid var(--line);
    background: #fff;
  }

  .ticket-compact-top,
  .ticket-compact-title {
    display: flex;
    align-items: center;
    min-width: 0;
  }

  .ticket-compact-top { gap: 9px; }
  .ticket-compact-top .ticket-actions { margin-left: auto; }
  .ticket-compact-top .ticket-actions-toggle { width: 28px; height: 28px; }

  .ticket-compact-top .back-button {
    display: inline-flex;
    min-height: 24px;
    padding: 0;
    color: var(--ink);
    font-size: 14px;
    font-weight: 600;
  }

  .ticket-compact-top .back-button .icon { width: 17px; height: 17px; }
  .ticket-compact-id { padding-left: 9px; border-left: 1px solid var(--line); color: var(--muted); font-size: 13px; white-space: nowrap; }
  .ticket-compact-top .status-chip { min-height: 22px; padding: 0 8px; font-size: 11px; white-space: nowrap; }
  .ticket-compact-title { justify-content: space-between; gap: 10px; }
  .ticket-compact-topic {
    min-width: 0;
    color: var(--ink-soft);
    font-size: 13px;
    font-weight: 500;
    line-height: 1.25;
  }
  .ticket-compact-topic > span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .ticket-compact-title time { flex: 0 0 auto; color: var(--muted); font-size: 11px; white-space: nowrap; }

  .ticket-close-card { padding: 21px 18px 18px; }
  .ticket-close-buttons { display: grid; grid-template-columns: 1fr 1fr; }
}

/* Fluid type scale: keeps information dense on phones and comfortably readable on larger screens. */
:root {
  --type-caption: clamp(10px, .12vw + 9.6px, 11px);
  --type-small: clamp(12px, .18vw + 11.3px, 13px);
  --type-body: clamp(14px, .2vw + 13.2px, 15px);
  --type-card-title: clamp(14px, .15vw + 13.4px, 15px);
  --type-section-title: clamp(18px, .45vw + 16px, 20px);
  --type-page-title: clamp(22px, 1vw + 18px, 28px);
}

body[data-role="user"] .user-hero h1,
.knowledge-heading h1 { font-size: var(--type-page-title); }

.user-hero p:not(.eyebrow),
.knowledge-heading p:not(.eyebrow) {
  font-size: var(--type-body);
  line-height: 1.55;
}

.section-heading h1,
.section-heading h2 { font-size: var(--type-section-title); }

.section-heading p,
.breadcrumbs,
.choice-caption { font-size: var(--type-small); }

.topic-copy strong { font-size: var(--type-card-title); line-height: 1.32; }
.topic-copy small { font-size: var(--type-caption); line-height: 1.42; }

.decision-row { font-size: var(--type-card-title); }
.answer-block h2 { font-size: clamp(17px, .55vw + 15px, 20px); }
.answer-block p { font-size: var(--type-body); line-height: 1.6; }

.request-form > label { font-size: var(--type-small); }
.request-form label small { font-size: var(--type-caption); }

/* Keep desktop forms compact; iOS receives 16px below to prevent focus zoom. */
.request-form input:not([type="file"]),
.request-form textarea,
.reply-form textarea { font-size: 15px; }

.message-bubble { font-size: 14px; line-height: 1.55; }
.message-info strong { font-size: var(--type-caption); }
.message-info time { font-size: clamp(10px, .12vw + 9.6px, 11px); }

.mobile-nav-item { font-size: clamp(10px, .2vw + 9.5px, 11px); }

@media (max-width: 640px) {
  .request-form input:not([type="file"]),
  .request-form textarea,
  .reply-form textarea { font-size: 16px; }

  .knowledge-page .knowledge-heading h1 {
    font-size: clamp(20px, 5.6vw, 22px);
    line-height: 1.18;
  }

  .knowledge-page .knowledge-heading p:not(.eyebrow) {
    font-size: 13px;
    line-height: 1.45;
  }

  .knowledge-page .choice-caption { font-size: 12px; }

  .knowledge-page .answer-actions { gap: 8px; }

  .knowledge-page .answer-actions > button,
  .knowledge-page .answer-actions > a {
    min-height: 38px;
    border-radius: 9px;
    padding: 0 12px;
    font-size: 12px;
  }
}
