/* Custom components layered on top of the compiled Tailwind build (app/css/style.css). */

/* ---------------------------------------------------------------------------
   iOS Safari fixes
   --------------------------------------------------------------------------- */

/* 100vh on iOS includes the browser chrome, which cuts off the layout.
   Use the dynamic viewport height where supported, with a -webkit fallback. */
html,
body {
  height: 100%;
  min-height: -webkit-fill-available;
}

#app-shell,
#auth-screen {
  min-height: -webkit-fill-available;
}

@supports (height: 100dvh) {
  html,
  body,
  #app-shell,
  #auth-screen {
    height: 100dvh;
    min-height: 100dvh;
  }
}

/* Fallback driven by JS (--app-vh is set to 1% of the real viewport height). */
@supports not (height: 100dvh) {
  html,
  body,
  #app-shell,
  #auth-screen {
    height: calc(var(--app-vh, 1vh) * 100);
    min-height: calc(var(--app-vh, 1vh) * 100);
  }
}

/* Respect the notch and the home indicator. */
body {
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

#app-shell > aside:first-child {
  padding-top: env(safe-area-inset-top);
}

/* iOS zooms the page when focusing an input smaller than 16px. */
@media (max-width: 767px) {
  input,
  select,
  textarea {
    font-size: 16px;
  }
}

/* Smooth momentum scrolling inside scrollable panes. */
#ticket-list,
#chat-container,
#management-pages,
.rooms-list,
.room-messages,
.creation-dialog {
  -webkit-overflow-scrolling: touch;
}

/* Prevent the rubber-band effect from revealing the page behind the app. */
body {
  overscroll-behavior: none;
}

/* The fixed composer must sit above the home indicator. */
@media (max-width: 767px) {
  #message-form {
    padding-bottom: calc(0.9rem + env(safe-area-inset-bottom, 0px));
  }
  #chat-container {
    padding-bottom: calc(5.5rem + env(safe-area-inset-bottom, 0px));
  }
}

/* Standalone mode: hide the extra top padding the browser would add. */
@media (display-mode: standalone) {
  #app-shell > aside:first-child {
    padding-top: env(safe-area-inset-top);
  }
}

@layer base {
  :root {
    /* Палитра в стиле Element Matrix (Dark) */
    --color-bg-base: #12161c;
    --color-bg-panel: #1e232b;
    --color-bg-header: #191d24;
    --color-bg-list: #151920;
    --color-bg-hover: #2a303a;
    --color-border: #333a46;
    --color-accent: #3b82f6;
    --color-accent-soft: rgba(59, 130, 246, 0.14);
    --shadow-panel: 0 18px 40px rgba(0, 0, 0, 0.28);
  }
}

@layer utilities {
  .bg-matrix-bg { background-color: var(--color-bg-base); }
  .bg-matrix-panel { background-color: var(--color-bg-panel); }
  .bg-matrix-header { background-color: var(--color-bg-header); }
  .bg-matrix-list { background-color: var(--color-bg-list); }
  .bg-matrix-hover { background-color: var(--color-bg-hover); }
  .border-matrix-border { border-color: var(--color-border); }
}

/* Кастомный скроллбар */
::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: #333a46;
  border: 2px solid transparent;
  background-clip: padding-box;
  border-radius: 999px;
}
::-webkit-scrollbar-thumb:hover {
  background: #4b5363;
  background-clip: padding-box;
}

/* Авторасширение textarea */
textarea {
    scrollbar-width: none;
}
textarea::-webkit-scrollbar {
    display: none;
}

.page-title {
  font-size: clamp(1.5rem, 2vw, 2.1rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.page-subtitle {
  color: #9ca3af;
  line-height: 1.5;
  margin-top: 0.55rem;
}

.eyebrow {
  color: #60a5fa;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.primary-action,
.secondary-action {
  border-radius: 0.55rem;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.65rem 0.95rem;
  transition: background-color 150ms ease, border-color 150ms ease, box-shadow 150ms ease, transform 120ms ease;
}

.primary-action {
  background: linear-gradient(180deg, #3b82f6 0%, #2563eb 100%);
  box-shadow: 0 6px 16px rgba(37, 99, 235, 0.28);
}
.primary-action:hover {
  background: linear-gradient(180deg, #4f8ff7 0%, #2f6fe0 100%);
  box-shadow: 0 8px 20px rgba(37, 99, 235, 0.36);
}
.primary-action:active { transform: translateY(1px); }
.secondary-action { background: #232a34; border: 1px solid #3b4350; }
.secondary-action:hover { background: #2d3542; border-color: #4a5464; }
.danger-action { background: transparent; border: 1px solid #71343a; border-radius: 0.45rem; color: #fca5a5; font-size: 0.68rem; padding: 0.35rem 0.5rem; }
.danger-action:hover { background: #4c2027; color: #fecaca; }

#ticket-list-expand-btn { white-space: nowrap; }

#ticket-sidebar > div:nth-child(2) {
  align-items: center;
  display: flex;
  gap: 0.35rem;
}
#ticket-sidebar > div:nth-child(2) > input,
#ticket-sidebar > div:nth-child(2) > select {
  flex: 1 1 0;
  min-width: 0;
  width: auto;
}
#ticket-sidebar > div:nth-child(2) > select { max-width: 180px; }

.mobile-ticket-nav { display: none; }
.mobile-ticket-nav button {
  align-items: center;
  background: #252b35;
  border: 1px solid #3b4350;
  border-radius: 0.45rem;
  color: #dbeafe;
  display: inline-flex;
  font-size: 1.25rem;
  height: 2rem;
  justify-content: center;
  line-height: 1;
  width: 2rem;
}
.mobile-ticket-nav button:disabled { cursor: not-allowed; opacity: 0.35; }

#app-shell.tickets-fullscreen #ticket-sidebar {
  flex: 1 1 auto;
  width: auto;
}

#app-shell.tickets-fullscreen #workspace-main {
  display: none;
}

#app-shell.tickets-fullscreen #ticket-list {
  display: grid;
  align-content: start;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
}

#app-shell.tickets-fullscreen #ticket-list .ticket-item {
  border-bottom: 1px solid var(--color-border);
  border-right: 1px solid var(--color-border);
  min-height: 132px;
}

#app-shell.tickets-table-view #ticket-list {
  display: block;
}

#app-shell.tickets-table-view #ticket-list .ticket-item {
  border-bottom: 1px solid var(--color-border);
  border-left-width: 4px;
  min-height: auto;
  padding: 0.9rem 1.1rem;
}

#app-shell.tickets-fullscreen.tickets-table-view #ticket-list .ticket-item {
  align-items: center;
  display: grid;
  gap: 1rem;
  grid-template-columns: 50px minmax(220px, 2fr) minmax(140px, 1fr) minmax(160px, 1.1fr) minmax(130px, 1fr) minmax(140px, 1fr) minmax(105px, 0.8fr) 100px 120px 100px;
  min-width: 1250px;
}

#app-shell.tickets-fullscreen.tickets-table-view #ticket-list .ticket-item > div {
  margin: 0;
}

#app-shell.org-admin-ticket-table.tickets-fullscreen.tickets-table-view #ticket-list .ticket-item,
#app-shell.org-admin-ticket-table .ticket-table-header {
  grid-template-columns: 50px minmax(220px, 2fr) minmax(140px, 1fr) minmax(130px, 1fr) minmax(140px, 1fr) minmax(105px, 0.8fr) 100px 120px 100px;
  min-width: 1150px;
}

.ticket-table-header {
  color: #9ca3af;
  display: grid;
  font-size: 0.68rem;
  font-weight: 600;
  gap: 1rem;
  grid-template-columns: 50px minmax(220px, 2fr) minmax(140px, 1fr) minmax(160px, 1.1fr) minmax(130px, 1fr) minmax(140px, 1fr) minmax(105px, 0.8fr) 100px 120px 100px;
  letter-spacing: 0.04em;
  min-width: 1250px;
  padding: 0.75rem 1.1rem;
  text-transform: uppercase;
}

#app-shell.tickets-fullscreen.tickets-table-view #ticket-list {
  overflow-x: auto;
}

.management-grid {
  display: grid;
  gap: 1.35rem;
  grid-template-columns: repeat(auto-fit, minmax(255px, 1fr));
}

.management-card {
  background: linear-gradient(145deg, #1f2732 0%, #1a2029 100%);
  border: 1px solid #333c4a;
  border-radius: 0.9rem;
  padding: 1.4rem;
  box-shadow: var(--shadow-panel);
  transition: border-color 160ms ease, transform 160ms ease, box-shadow 160ms ease;
}
.management-card:hover {
  border-color: #3f4a5c;
  transform: translateY(-1px);
  box-shadow: 0 22px 48px rgba(0, 0, 0, 0.34);
}

.management-card h3 { font-weight: 700; }
.management-card .muted { color: #9ca3af; font-size: 0.75rem; }
.management-card .metric { font-size: 1.65rem; font-weight: 700; margin-top: 1rem; }

.toolbar-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
}

.table-search {
  background: #1a2028;
  border: 1px solid #333c49;
  border-radius: 0.55rem;
  color: #fff;
  font-size: 0.78rem;
  min-width: 210px;
  padding: 0.65rem 0.85rem;
  transition: border-color 150ms ease, box-shadow 150ms ease;
}
.table-search:focus {
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px var(--color-accent-soft);
  outline: none;
}

.table-shell {
  background: #1d232b;
  border: 1px solid #343c49;
  border-radius: 0.7rem;
  overflow-x: auto;
}

.ticket-create-form {
  background: linear-gradient(180deg, #1f262f 0%, #1a2028 100%);
  border: 1px solid #333c4a;
  border-radius: 0.9rem;
  box-shadow: var(--shadow-panel);
  padding: 1.5rem;
}

.ticket-create-grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.ticket-create-grid label,
.ticket-create-description label {
  color: #cbd5e1;
  display: block;
  font-size: 0.76rem;
}

.ticket-create-grid input,
.ticket-create-grid select,
.ticket-create-description textarea {
  background: #151a20;
  border: 1px solid #3a4452;
  border-radius: 0.5rem;
  color: #fff;
  display: block;
  margin-top: 0.4rem;
  outline: none;
  padding: 0.7rem 0.8rem;
  width: 100%;
}

.ticket-create-grid input:focus,
.ticket-create-grid select:focus,
.ticket-create-description textarea:focus {
  border-color: #60a5fa;
  box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.12);
}

.ticket-create-description {
  margin-top: 1.2rem;
}

.ticket-create-description textarea {
  font-family: inherit;
  line-height: 1.55;
  min-height: 220px;
  resize: vertical;
}

.ticket-create-dropzone {
  background: #1a2028;
  border: 1px dashed #3a4452;
  border-radius: 0.7rem;
  margin-top: 1.2rem;
  padding: 1.1rem;
  transition: border-color 150ms ease, background-color 150ms ease;
}

.ticket-create-dropzone-inner {
  align-items: center;
  display: flex;
  gap: 1rem;
  justify-content: space-between;
}

.ticket-create-dropzone-icon {
  font-size: 1.5rem;
}

.ticket-create-attachment-name {
  color: #93c5fd;
  font-size: 0.75rem;
  margin-top: 0.6rem;
  overflow-wrap: anywhere;
}

.rooms-layout { display: grid; gap: 1rem; grid-template-columns: minmax(220px, 0.7fr) minmax(0, 1.8fr); height: calc(100vh - 230px); min-height: 420px; }
.rooms-list, .room-chat-panel { background: #1d232b; border: 1px solid #343c49; border-radius: 0.7rem; overflow: hidden; }
.rooms-list { overflow-y: auto; }
.room-list-item { border-bottom: 1px solid #303743; cursor: pointer; display: flex; flex-direction: column; gap: 0.35rem; padding: 1rem; text-align: left; width: 100%; transition: background-color 140ms ease, border-color 140ms ease; }
.room-list-item:hover { background: #232c38; }
.room-list-item.active { background: #273342; border-left: 3px solid var(--color-accent); }
.room-list-item .danger-action { align-self: flex-end; }
.room-actions { align-items: center; align-self: flex-end; display: flex; gap: 0.4rem; }
.room-list-name { color: #f8fafc; font-size: 0.86rem; font-weight: 700; }
.room-list-meta, .room-list-count, .room-chat-meta { color: #94a3b8; font-size: 0.7rem; }
.room-chat-panel { display: flex; flex-direction: column; min-height: 0; }
.room-chat-header { align-items: center; border-bottom: 1px solid #343c49; display: flex; gap: 0.75rem; justify-content: space-between; padding: 1rem 1.2rem; }
.room-messages { display: flex; flex: 1 1 auto; flex-direction: column; gap: 1rem; min-height: 0; overflow-y: auto; padding: 1.2rem; }
.room-message-row { align-items: flex-start; display: flex; gap: 0.65rem; max-width: 85%; }
.room-message-row.own { align-self: flex-end; flex-direction: row-reverse; }
.room-message-avatar { align-items: center; background: #4b5563; border-radius: 999px; color: #e5e7eb; display: flex; flex: 0 0 2rem; font-size: 0.7rem; height: 2rem; justify-content: center; margin-top: 1.35rem; width: 2rem; }
.room-message-row.own .room-message-avatar { background: #2563eb; }
.room-message { background: #252d38; border: 1px solid #3b4656; border-radius: 1rem; border-top-left-radius: 0.25rem; max-width: min(680px, calc(100vw - 180px)); padding: 0.75rem 0.9rem; white-space: pre-wrap; }
.room-message-row.own .room-message { background: rgba(37, 99, 235, 0.25); border-color: rgba(96, 165, 250, 0.35); border-radius: 1rem; border-top-right-radius: 0.25rem; }
.room-message-author { color: #93c5fd; font-size: 0.7rem; font-weight: 600; margin-bottom: 0.35rem; }
.room-message-author span { color: #64748b; font-weight: 400; margin-left: 0.35rem; }
.room-attachment-preview { display: block; margin-top: 0.65rem; max-width: min(360px, 100%); }
.room-attachment-preview img { border: 1px solid #465366; border-radius: 0.5rem; display: block; max-height: 260px; max-width: 100%; object-fit: contain; }
.room-audio-player { display: block; margin-top: 0.65rem; max-width: 100%; width: 320px; }
.room-attachment-preview span, .room-file-link { color: #93c5fd; display: block; font-size: 0.72rem; margin-top: 0.4rem; overflow-wrap: anywhere; }
.room-message-form { align-items: flex-end; background: #1a2028; border-top: 1px solid #343c49; display: flex; gap: 0.65rem; padding: 0.9rem; }
.room-attachment-btn { background: #252d38; border: 1px solid #3a4452; border-radius: 0.5rem; color: #bfdbfe; font-size: 1rem; padding: 0.68rem 0.8rem; }
.room-attachment-btn:hover { background: #303b4b; }
.room-composer-main { flex: 1; min-width: 0; }
.room-composer-main input,
.room-composer-main textarea { background: #151a20; border: 1px solid #3a4452; border-radius: 0.5rem; color: #fff; font-family: inherit; max-height: 8rem; min-width: 0; padding: 0.7rem 0.8rem; resize: none; width: 100%; }
.room-attachment-name { color: #93c5fd; font-size: 0.7rem; min-height: 0; overflow: hidden; padding: 0 0.2rem 0.3rem; text-overflow: ellipsis; white-space: nowrap; }
.empty-panel { color: #64748b; font-size: 0.8rem; margin: auto; text-align: center; }
.recording { background: #991b1b !important; color: #fecaca !important; }

.drop-active {
  outline: 2px dashed #60a5fa;
  outline-offset: -6px;
  background: rgba(96, 165, 250, 0.06);
}

.auth-screen {
  background:
    radial-gradient(900px 500px at 50% -10%, rgba(59, 130, 246, 0.18), transparent 60%),
    radial-gradient(700px 400px at 90% 110%, rgba(96, 165, 250, 0.10), transparent 60%),
    var(--color-bg-base);
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  /* Center the login card both horizontally and vertically. */
  align-items: center;
  justify-content: center;
}

.auth-card {
  margin: auto;
}

.auth-card {
  background: linear-gradient(180deg, #1f262f 0%, #1a2028 100%);
  border-color: #3a4453;
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.55), 0 0 0 1px rgba(96, 165, 250, 0.06);
}

.auth-logo {
  align-items: center;
  background: linear-gradient(180deg, #3b82f6 0%, #2563eb 100%);
  border-radius: 0.9rem;
  box-shadow: 0 10px 26px rgba(37, 99, 235, 0.4);
  display: inline-flex;
  font-size: 1.5rem;
  height: 3rem;
  justify-content: center;
  margin-bottom: 0.9rem;
  width: 3rem;
}

.ticket-search-highlight {
  background: #60a5fa;
  color: #0b1220;
  border-radius: 2px;
}

/* Constrain chat attachments so a large photo never overflows the bubble
   or hides the bottom of the conversation. */
.chat-attachment-link {
  display: inline-block;
  margin-top: 0.5rem;
  max-width: 100%;
}

.chat-attachment-image {
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 0.5rem;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
  display: block;
  height: auto;
  max-height: 320px;
  max-width: min(320px, 100%);
  object-fit: contain;
  width: auto;
}

/* Inline video player, constrained to the chat bubble width. */
.chat-attachment-video {
  background: #000;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 0.5rem;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
  display: block;
  margin-top: 0.5rem;
  max-height: 360px;
  max-width: min(480px, 100%);
  width: 100%;
}

/* The chat bubble must not grow wider than its column, and the chat column
   itself must be allowed to shrink below its content width. */
#chat-container > div {
  min-width: 0;
}
#chat-container .max-w-\[80\%\] {
  min-width: 0;
  max-width: min(80%, 100%);
}
#chat-container .whitespace-pre-wrap {
  overflow-wrap: anywhere;
}

/* Keep the composer visible even when a tall attachment is in the chat. */
#ticket-workspace {
  min-height: 0;
}
#chat-container {
  min-height: 0;
}
#message-form {
  flex-shrink: 0;
}

#ticket-list .ticket-item {
  transition: background-color 140ms ease, border-color 140ms ease;
}
#ticket-list .ticket-item:hover {
  background: #232a34;
}
#ticket-list .ticket-item.bg-matrix-hover {
  background: #273342;
}
.voice-level-meter { align-items: center; display: inline-flex; gap: 2px; height: 28px; min-width: 48px; }
.voice-level-meter i { background: #60a5fa; border-radius: 2px; display: block; height: 4px; min-width: 3px; transition: height 80ms ease, opacity 80ms ease; width: 3px; }
.voice-send-now { background: #2563eb; border-radius: 0.4rem; color: #dbeafe; font-size: 0.68rem; padding: 0.45rem 0.55rem; white-space: nowrap; }
.voice-send-now:hover { background: #3b82f6; }

@media (max-width: 560px) {
  .room-message-row { max-width: 94%; }
  .room-message { max-width: calc(100vw - 100px); }
}

.data-table { min-width: 760px; width: 100%; border-collapse: collapse; }
.data-table th {
  background: #202731;
  color: #9ca3af;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  padding: 0.8rem 1rem;
  text-align: left;
  text-transform: uppercase;
}
.data-table td { border-top: 1px solid #303743; padding: 0.9rem 1rem; vertical-align: top; }
.data-table tr:hover td { background: #232a34; }
.tag { background: #29384f; border-radius: 999px; color: #bfdbfe; display: inline-block; font-size: 0.68rem; margin: 0.15rem; padding: 0.25rem 0.5rem; }
.tag-muted { background: #2a2f37; color: #aeb7c4; }

.room-unread-badge { color: #60a5fa; font-size: 0.85rem; line-height: 1; }

.toast-stack { position: fixed; right: 1rem; bottom: 1rem; display: flex; flex-direction: column; gap: 0.5rem; z-index: 100; }
.toast { background: #1f2732; border: 1px solid #3b4656; border-left: 3px solid #60a5fa; border-radius: 0.7rem; box-shadow: 0 18px 40px rgba(0,0,0,0.45); color: #e5e7eb; font-size: 0.8rem; max-width: 340px; padding: 0.8rem 1.05rem; animation: toast-in 180ms ease-out; backdrop-filter: blur(6px); }
.toast.toast-error { border-left-color: #f87171; }
.toast.toast-success { border-left-color: #4ade80; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

.skeleton { background: linear-gradient(90deg, #232a34 25%, #2c3543 50%, #232a34 75%); background-size: 200% 100%; animation: skeleton-shimmer 1.2s infinite; border-radius: 0.4rem; }
@keyframes skeleton-shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
.skeleton-ticket { height: 92px; margin: 0.6rem; }

.creation-dialog {
  background: linear-gradient(180deg, #1f262f 0%, #1a2028 100%);
  border: 1px solid #3d4858;
  border-radius: 1.1rem;
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.55);
  max-height: min(720px, 92vh);
  overflow: auto;
  width: min(620px, 100%);
}

.creation-dialog-header {
  align-items: flex-start;
  border-bottom: 1px solid #343c49;
  display: flex;
  justify-content: space-between;
  padding: 1.35rem 1.5rem;
}

.icon-close {
  color: #9ca3af;
  font-size: 1.5rem;
  line-height: 1;
  padding: 0.2rem 0.4rem;
}
.icon-close:hover { color: #fff; }

.creation-tabs {
  background: #181e25;
  border-bottom: 1px solid #343c49;
  display: flex;
  gap: 0.25rem;
  padding: 0.55rem 1.5rem 0;
}

.creation-tab {
  border-bottom: 2px solid transparent;
  color: #9ca3af;
  font-size: 0.78rem;
  padding: 0.7rem 0.65rem;
}
.creation-tab:hover { color: #fff; }
.creation-tab.active { border-color: #60a5fa; color: #fff; }

.creation-dialog-body { padding: 1.5rem; }
.quick-create-form label { color: #cbd5e1; display: block; font-size: 0.76rem; }
.quick-create-form input,
.quick-create-form select {
  background: #151a20;
  border: 1px solid #3a4452;
  border-radius: 0.5rem;
  color: #fff;
  display: block;
  margin-top: 0.4rem;
  outline: none;
  padding: 0.7rem 0.8rem;
  width: 100%;
}
.quick-create-form input:focus,
.quick-create-form select:focus { border-color: #60a5fa; box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.12); }
.form-intro { border-left: 3px solid #60a5fa; display: flex; flex-direction: column; gap: 0.25rem; padding-left: 0.8rem; }
.form-intro span, .field-hint { color: #9ca3af; font-size: 0.72rem; }
.form-grid-2 { display: grid; gap: 0.8rem; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.relationship-field { background: #202731; border: 1px solid #343c49; border-radius: 0.65rem; padding: 0.8rem; }
.field-heading { align-items: center; display: flex; justify-content: space-between; gap: 0.5rem; }
.inline-create { color: #93c5fd; font-size: 0.7rem; white-space: nowrap; }
.inline-create:hover { color: #dbeafe; }
.form-actions { border-top: 1px solid #343c49; display: flex; gap: 0.6rem; justify-content: flex-end; margin-top: 1.2rem; padding-top: 1.1rem; }

@media (max-width: 560px) {
  .form-grid-2 { grid-template-columns: 1fr; }
  .creation-dialog-header, .creation-dialog-body { padding: 1rem; }
  .creation-tabs { padding-left: 1rem; padding-right: 1rem; overflow-x: auto; }
  .ticket-table-header { display: none; }
  .ticket-create-dropzone-inner { align-items: flex-start; flex-direction: column; }
}

/* ---------------------------------------------------------------------------
   iPhone / mobile layout
   --------------------------------------------------------------------------- */

.mobile-tabbar,
.mobile-sheet,
.mobile-back-btn,
.mobile-menu-btn {
  display: none;
}

@media (max-width: 767px) {
  /* The desktop sidebar is replaced by the bottom tab bar. */
  #app-shell {
    flex-direction: column;
    overflow: hidden;
  }
  #app-shell > aside:first-child.mobile-hide {
    display: none;
  }

  /* The ticket list becomes a full-screen screen of its own. */
  #ticket-sidebar.mobile-ticket-list {
    border-right: 0;
    display: flex;
    flex: 1 1 auto;
    height: 100%;
    min-height: 0;
    width: 100%;
  }
  #ticket-sidebar.mobile-ticket-list > div:first-child {
    flex-wrap: wrap;
    gap: 0.45rem;
    padding: 0.7rem;
  }
  #ticket-sidebar.mobile-ticket-list > div:first-child > div {
    margin-left: auto;
  }
  #ticket-sidebar.mobile-ticket-list > div:nth-child(2) {
    align-items: stretch;
    flex-direction: column;
  }
  #ticket-sidebar.mobile-ticket-list > div:nth-child(2) > select { max-width: none; }

  /* The workspace is hidden until a ticket is opened. */
  #workspace-main {
    display: none;
    flex: 1 1 auto;
    height: 100%;
    min-height: 0;
    overflow: hidden;
    width: 100%;
  }

  /* When a ticket is open, hide the list and show the workspace. */
  #app-shell.mobile-ticket-open #ticket-sidebar.mobile-ticket-list {
    display: none;
  }
  #app-shell.mobile-ticket-open #workspace-main {
    display: flex;
  }

  /* Management pages take the full screen too. */
  #app-shell.mobile-management #ticket-sidebar.mobile-ticket-list {
    display: none;
  }
  #app-shell.mobile-management #workspace-main {
    display: flex;
  }

  #ticket-workspace {
    flex: 1 1 0;
    height: 100%;
    min-height: 0;
    overflow: hidden;
  }

  /* Compact ticket header with a back button and a "⋯" menu. */
  .ticket-header {
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 0.75rem;
  }
  .ticket-header-main {
    flex: 1 1 auto;
    min-width: 0;
  }
  .ticket-header-main h1 {
    font-size: 0.95rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .ticket-header-main .text-xs {
    flex-wrap: wrap;
    gap: 0.35rem 0.75rem;
  }
  .ticket-header-actions {
    display: none;
  }
  .mobile-back-btn,
  .mobile-menu-btn {
    align-items: center;
    background: #252b35;
    border: 1px solid #3b4350;
    border-radius: 0.5rem;
    color: #dbeafe;
    display: inline-flex;
    flex: 0 0 auto;
    font-size: 1.1rem;
    height: 2.25rem;
    justify-content: center;
    line-height: 1;
    width: 2.25rem;
  }
  .mobile-back-btn { font-size: 1.5rem; }

  /* The composer stays in normal flow so the keyboard does not break it. */
  #chat-container {
    flex: 1 1 0;
    min-height: 0;
    overflow-y: auto;
    padding-bottom: 0.5rem;
  }
  #message-form {
    background: #1a2028;
    border-top: 1px solid var(--color-border);
    padding: 0.6rem 0.6rem calc(0.6rem + env(safe-area-inset-bottom, 0px));
    position: static;
    width: 100%;
  }

  /* Bottom tab bar. */
  .mobile-tabbar {
    background: #191d24;
    border-top: 1px solid var(--color-border);
    display: flex;
    flex: 0 0 auto;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    width: 100%;
    z-index: 20;
  }
  .mobile-tab {
    align-items: center;
    color: #9ca3af;
    display: flex;
    flex: 1 1 0;
    flex-direction: column;
    font-size: 0.62rem;
    gap: 0.15rem;
    padding: 0.5rem 0.25rem;
  }
  .mobile-tab.active { color: #60a5fa; }
  .mobile-tab-icon { font-size: 1.15rem; line-height: 1; }
  .mobile-tab-label { font-weight: 600; }

  /* Bottom sheets for the "⋯" menus. */
  .mobile-sheet {
    display: block;
    inset: 0;
    position: fixed;
    z-index: 60;
  }
  .mobile-sheet.hidden { display: none; }
  .mobile-sheet-backdrop {
    background: rgba(0, 0, 0, 0.6);
    inset: 0;
    position: absolute;
  }
  .mobile-sheet-panel {
    background: #1f262f;
    border-radius: 1rem 1rem 0 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    left: 0;
    padding: 0.5rem 0.5rem calc(0.5rem + env(safe-area-inset-bottom, 0px));
    position: absolute;
    right: 0;
  }
  .mobile-sheet-item {
    border-radius: 0.6rem;
    color: #e5e7eb;
    font-size: 0.9rem;
    padding: 0.9rem 1rem;
    text-align: left;
    width: 100%;
  }
  .mobile-sheet-item:hover { background: #2a303a; }
  .mobile-sheet-item.danger { color: #fca5a5; }
  .mobile-sheet-item.cancel { color: #9ca3af; font-weight: 600; margin-top: 0.35rem; }

  #management-pages { padding: 1rem; }
  .table-search { flex: 1 1 100%; min-width: 0; }
  .rooms-layout { grid-template-columns: 1fr; height: auto; }
}
