:root,
html[data-theme="dark"] {
  --bg: #0e1621;
  --card: #17212b;
  --text: #c5d0da;
  --title: #e4ecf2;
  --muted: #7d8b99;
  --primary: #6ab3f3;
  --primary-soft: rgba(106, 179, 243, 0.16);
  --success: #71dd37;
  --success-soft: rgba(113, 221, 55, 0.16);
  --danger: #f28b82;
  --danger-soft: rgba(242, 139, 130, 0.16);
  --warning: #f0b429;
  --warning-soft: rgba(240, 180, 41, 0.16);
  --line: rgba(255, 255, 255, 0.08);
  --shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
  --radius: 16px;
  --input: #242f3d;
  --elevated: #1c2733;
  --nav-bg: rgba(23, 33, 43, 0.94);
  --map-bg: #1c2733;
  --hero-from: #2b5278;
  --hero-to: #1e3a5f;
  --chat-bg: #0e1621;
  --chat-panel: #17212b;
  --chat-mine: #2b5278;
  --chat-theirs: #182533;
  --chat-border: rgba(255, 255, 255, 0.06);
  --tooltip-bg: rgba(20, 24, 32, 0.88);
  --color-scheme: dark;
  --theme-color: #0e1621;
}

html[data-theme="light"] {
  --bg: #f2f4f7;
  --card: #ffffff;
  --text: #3d4f5f;
  --title: #1a2332;
  --muted: #6b7c8d;
  --primary: #2b7fd4;
  --primary-soft: rgba(43, 127, 212, 0.12);
  --success: #2e9e3a;
  --success-soft: rgba(46, 158, 58, 0.12);
  --danger: #d64545;
  --danger-soft: rgba(214, 69, 69, 0.12);
  --warning: #c4890a;
  --warning-soft: rgba(196, 137, 10, 0.12);
  --line: rgba(15, 30, 45, 0.1);
  --shadow: 0 2px 10px rgba(15, 30, 45, 0.08);
  --input: #eef1f5;
  --elevated: #f7f9fb;
  --nav-bg: rgba(255, 255, 255, 0.94);
  --map-bg: #e8edf2;
  --hero-from: #3a7ebd;
  --hero-to: #2b5278;
  --chat-bg: #e8edf3;
  --chat-panel: #ffffff;
  --chat-mine: #2b7fd4;
  --chat-theirs: #ffffff;
  --chat-border: rgba(15, 30, 45, 0.1);
  --tooltip-bg: rgba(30, 40, 52, 0.92);
  --color-scheme: light;
  --theme-color: #f2f4f7;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  height: 100%;
  color-scheme: var(--color-scheme, dark);
}

.card, .bottom-nav, .app-header {
  -webkit-transform: translateZ(0);
  transform: translateZ(0);
  will-change: auto;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 'Public Sans', system-ui, sans-serif;
  min-height: 100%;
  min-height: 100dvh;
  min-height: var(--tg-viewport-stable-height, 100dvh);
  overflow-x: hidden;
  overscroll-behavior-y: none;
}

main {
  max-width: 680px;
  margin: 0 auto;
  padding: calc(16px + env(safe-area-inset-top, 0px)) 16px 96px;
  overflow-x: hidden;
  width: 100%;
}

.loading {
  min-height: 70vh;
  display: grid;
  place-content: center;
  gap: 10px;
  text-align: center;
  color: var(--muted);
}

.logo-mark {
  width: 72px;
  height: 72px;
  margin: 0 auto;
  border-radius: 20px;
  background: var(--primary-soft);
  color: var(--primary);
  display: grid;
  place-items: center;
  font-size: 34px;
}

.loading b {
  font-size: 30px;
  color: var(--title);
}

.back-btn {
  margin-bottom: 12px;
}

.app-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

h1 {
  font-size: 26px;
  line-height: 1.2;
  margin: 0;
  color: var(--title);
}

h2 {
  font-size: 18px;
  margin: 0 0 12px;
  color: var(--title);
}

.badge, .pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  padding: 7px 12px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary);
}

.pill.on { background: var(--success-soft); color: var(--success); }
.pill.off { background: var(--danger-soft); color: var(--danger); }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  margin: 12px 0;
  box-shadow: var(--shadow);
}

.hero-card {
  background: linear-gradient(135deg, var(--hero-from) 0%, var(--hero-to) 100%);
  color: #fff;
  border: 0;
}

.hero-card h2, .hero-card p { color: #fff; }
.hero-card .hint { color: rgba(255,255,255,.85); }

.order-top {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: flex-start;
}

.status {
  font-size: 12px;
  font-weight: 700;
  color: var(--primary);
  text-align: right;
}

.priority-card {
  border-color: rgba(240, 180, 41, 0.45);
  background: linear-gradient(180deg, rgba(240, 180, 41, 0.12) 0%, var(--card) 55%);
  box-shadow: 0 8px 24px rgba(0, 0, 0, .25);
}

.priority-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 8px;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(240, 180, 41, 0.2);
  color: #f0b429;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .02em;
}

.route { margin: 12px 0; line-height: 1.55; }
.route span { display: block; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.route b { color: var(--title); font-weight: 600; }

.details {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  color: var(--muted);
  font-size: 14px;
}

button, .primary {
  border: 0;
  border-radius: 12px;
  padding: 12px 16px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: .15s ease;
}

button:active { transform: scale(.98); }

.primary {
  color: #fff;
  background: var(--primary);
  width: 100%;
}

.secondary { background: var(--primary-soft); color: var(--primary); }
.danger { background: var(--danger-soft); color: var(--danger); }
.ghost { background: transparent; color: var(--primary); padding: 0; }
.light { background: var(--elevated); color: var(--title); border: 1px solid var(--line); }

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
  max-width: 100%;
}
.actions button {
  flex: 1 1 calc(50% - 4px);
  min-width: 0;
  max-width: 100%;
  white-space: normal;
  overflow-wrap: anywhere;
  line-height: 1.25;
}

.rating-block {
  margin-top: 12px;
  padding: 12px;
  border-radius: 14px;
  background: var(--primary-soft);
  border: 1px solid rgba(106, 179, 243, 0.25);
}
.rating-block .hint {
  margin: 0 0 10px;
  color: var(--title);
  font-weight: 600;
}
.rating-row {
  display: flex;
  gap: 6px;
  justify-content: space-between;
}
.rating-btn {
  flex: 1 1 0;
  min-width: 0;
  margin: 0;
  padding: 10px 4px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--input);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}
.rating-btn:active {
  transform: scale(.96);
  background: var(--primary-soft);
}
.rating-done {
  margin-top: 10px;
  font-weight: 600;
  color: var(--title);
}
.admin-actions {
  flex-direction: column;
}
.admin-actions button {
  flex: none;
  width: 100%;
}

.form { display: grid; gap: 12px; }
.form label { font-size: 13px; font-weight: 500; color: var(--title); }

input, textarea, select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--input);
  color: var(--title);
  padding: 12px 14px;
  font: inherit;
  /* iOS иначе зумит страницу при фокусе, если меньше 16px */
  font-size: 16px;
  margin-top: 6px;
}

input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(106, 179, 243, .2);
}

input::placeholder, textarea::placeholder {
  color: var(--muted);
}

textarea { resize: vertical; min-height: 80px; }

.hint { color: var(--muted); font-size: 13px; margin: 0; }
.empty { color: var(--muted); text-align: center; padding: 28px; }

.error {
  color: var(--danger);
  background: var(--danger-soft);
  padding: 12px 14px;
  border-radius: 12px;
  font-size: 14px;
}

.success-box {
  color: var(--success);
  background: var(--success-soft);
  padding: 12px 14px;
  border-radius: 12px;
}

.stop { display: flex; gap: 8px; align-items: flex-start; }
.stop .field { flex: 1; }
.stop button { padding: 10px 12px; margin-top: 6px; }

.route-points { display: grid; gap: 10px; }
.route-point {
  display: grid;
  grid-template-columns: 36px 1fr auto;
  gap: 8px;
  align-items: start;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--elevated);
}
.route-point.is-dragging {
  opacity: .72;
  border-color: var(--primary);
  box-shadow: 0 8px 20px rgba(0, 0, 0, .35);
}
.route-point-main { min-width: 0; }
.route-point-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 2px;
}
.drag-handle {
  touch-action: none;
  user-select: none;
  cursor: grab;
  width: 36px;
  min-height: 44px;
  margin-top: 18px;
  padding: 8px 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--input);
  color: var(--muted);
  font-size: 14px;
  letter-spacing: -2px;
  line-height: 1;
}
.drag-handle:active { cursor: grabbing; }
.route-point-remove {
  margin-top: 18px;
  padding: 10px 12px;
}
.waiting-box {
  margin-top: 12px;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(106, 179, 243, 0.1) 0%, var(--elevated) 100%);
}
.waiting-box.waiting-paid {
  border-color: rgba(240, 180, 41, 0.45);
  background: linear-gradient(180deg, rgba(240, 180, 41, 0.14) 0%, var(--elevated) 100%);
}
.waiting-label {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 4px;
}
.waiting-timer {
  font-size: 16px;
  font-weight: 600;
  color: var(--title);
  margin-bottom: 4px;
}
.waiting-timer b {
  font-variant-numeric: tabular-nums;
  letter-spacing: .02em;
}
.waiting-box.waiting-driver {
  margin-top: 10px;
  margin-bottom: 4px;
  border-color: var(--primary);
  background: linear-gradient(180deg, rgba(106, 179, 243, 0.14) 0%, var(--elevated) 100%);
}
.waiting-box.waiting-driver .waiting-timer {
  font-size: 28px;
  font-weight: 700;
  line-height: 1.2;
}
.waiting-box .details {
  margin-top: 8px;
}

.quick-row, .choice-row, .stats-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.quick-row button, .choice-row button {
  flex: 1;
  min-width: 140px;
  background: var(--elevated);
  color: var(--title);
  border: 1px solid var(--line);
}

.quick-row button:disabled {
  opacity: .45;
  cursor: not-allowed;
}

.suggest-wrap { position: relative; z-index: 1; }
.suggest-wrap:focus-within { z-index: 40; }

.suggest-list {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 4px);
  z-index: 50;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  max-height: 180px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}

.suggest-list button {
  display: block;
  width: 100%;
  text-align: left;
  border-radius: 0;
  background: var(--card);
  color: var(--title);
  font-weight: 500;
  padding: 10px 14px;
  font-size: 14px;
  border-bottom: 1px solid var(--line);
}

.tabs, .bottom-nav {
  display: flex;
  gap: 6px;
}

.tabs { margin-bottom: 12px; }
.tabs button {
  flex: 1;
  background: var(--elevated);
  color: var(--muted);
  border: 1px solid var(--line);
}

.tabs button.active, .filter-row button.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10000;
  padding: 8px 6px calc(8px + env(safe-area-inset-bottom, 0px));
  background: var(--nav-bg);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(10px);
  pointer-events: auto;
  max-width: 100vw;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.bottom-nav button {
  flex: 1 1 0;
  min-width: 0;
  background: transparent;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.15;
  padding: 8px 2px;
  white-space: normal;
  overflow-wrap: anywhere;
  touch-action: manipulation;
  cursor: pointer;
  position: relative;
  z-index: 1;
  pointer-events: auto;
}

.bottom-nav button.active {
  color: var(--primary);
  background: var(--primary-soft);
}

.auth-card {
  max-width: 460px;
  margin: 4vh auto 0;
}

.auth-card .logo-mark { margin-bottom: 8px; }

.login-widget {
  display: flex;
  justify-content: center;
  margin: 18px 0;
}

.divider {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
  margin: 16px 0;
}

.divider::before, .divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--line);
}

.info-text {
  white-space: pre-line;
  color: var(--text);
  line-height: 1.65;
}

.stats-row .stat {
  flex: 1;
  min-width: 120px;
  background: var(--elevated);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
}

.stats-row .stat b {
  display: block;
  font-size: 22px;
  color: var(--title);
}

.cabinet-links {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.theme-toggle-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  margin-top: 10px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--elevated);
  color: var(--title);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.theme-toggle-btn:active {
  transform: scale(0.99);
}

.cabinet-link-card {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--elevated);
  color: var(--title);
  text-align: left;
  box-shadow: var(--shadow);
}

.cabinet-link-card:active {
  transform: scale(0.99);
}

.cabinet-link-icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--primary-soft);
  display: grid;
  place-items: center;
  font-size: 22px;
  flex-shrink: 0;
}

.cabinet-link-body {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.cabinet-link-body b {
  color: var(--title);
  font-size: 15px;
}

.filter-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.filter-row button {
  background: var(--elevated);
  color: var(--title);
  border: 1px solid var(--line);
  font-size: 13px;
  padding: 8px 12px;
}

.shift-bar {
  display: flex;
  gap: 8px;
  align-items: center;
}

.shift-bar button { flex: 1; }

.role-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.role-card {
  text-align: left;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--elevated);
}

.role-card.active {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.role-card b { display: block; color: var(--title); margin-bottom: 4px; }

.active-order-card {
  border-color: var(--primary);
  background: linear-gradient(180deg, rgba(106, 179, 243, 0.12) 0%, var(--card) 55%);
}

.active-order-badge {
  display: inline-flex;
  margin-bottom: 10px;
  font-size: 12px;
  font-weight: 700;
  color: var(--primary);
  background: var(--primary-soft);
  padding: 6px 10px;
  border-radius: 999px;
}

.active-status { color: var(--success); }

.client-block {
  margin: 12px 0;
  padding: 12px;
  border-radius: 12px;
  background: var(--elevated);
  border: 1px solid var(--line);
}

.client-block span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.client-block b { color: var(--title); }

.phone-link {
  display: inline-block;
  margin-top: 6px;
  color: var(--primary);
  font-weight: 600;
  text-decoration: none;
}

.map-links {
  margin-top: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.map-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  flex: 1;
  min-width: 140px;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 600;
  text-decoration: none;
  text-align: center;
}

.map-link.route-link {
  background: var(--primary);
  color: #fff;
}

.compact-card { margin: 8px 0; }

.compact-card .actions button { font-size: 14px; }

.compact-card .client-block {
  margin: 10px 0 8px;
  padding: 12px 14px;
}

.compact-card .client-block b {
  font-size: 18px;
  font-weight: 700;
  line-height: 1.3;
}

.compact-card .details {
  margin: 0 0 4px;
  gap: 14px;
  font-size: 16px;
  font-weight: 600;
  color: var(--title);
}

.compact-card .details .order-time {
  font-size: 17px;
  font-weight: 700;
}

.compact-card .route {
  margin: 10px 0 4px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.compact-card .route b {
  font-size: 14px;
  font-weight: 500;
}

.order-map-wrap { margin-top: 12px; }

.order-map {
  width: 100%;
  height: 220px;
  min-height: 220px;
  border-radius: 14px;
  border: 1px solid var(--line);
  overflow: hidden;
  position: relative;
  z-index: 1;
  background: var(--map-bg);
}

.order-map .leaflet-container {
  width: 100% !important;
  height: 100% !important;
  z-index: 1 !important;
  background: var(--map-bg);
  /* iOS Safari: pan-x/pan-y без pinch-zoom блокирует pinch на карте.
     none — жесты отдаём Leaflet (как в дефолте библиотеки). */
  touch-action: none;
}

.admin-drivers-map .leaflet-container {
  width: 100% !important;
  height: 100% !important;
  z-index: 1 !important;
  background: var(--map-bg);
  touch-action: none;
}

.order-map .leaflet-control-zoom {
  border: 0 !important;
  box-shadow: var(--shadow);
}

.order-map .leaflet-control-zoom a {
  width: 34px !important;
  height: 34px !important;
  line-height: 34px !important;
  color: var(--title) !important;
  background: var(--card) !important;
  border-bottom: 1px solid var(--line) !important;
}

.location-hint {
  margin-top: 8px;
  font-size: 12px;
  color: var(--muted);
}

.location-warn {
  margin-top: 12px;
  padding: 12px;
  border-radius: 14px;
  background: var(--warning-soft);
  border: 1px solid rgba(240, 180, 41, 0.35);
}
.location-warn .hint {
  margin: 0;
  color: var(--title);
}
.location-warn .hint + .hint {
  margin-top: 6px;
  font-weight: 400;
  color: var(--text);
}
.location-warn .actions {
  margin-top: 10px;
}

.admin-drivers-map {
  width: 100%;
  height: 320px;
  min-height: 280px;
  margin-top: 10px;
  border-radius: 14px;
  border: 1px solid var(--line);
  overflow: hidden;
  position: relative;
  z-index: 1;
  background: var(--map-bg);
}

.admin-driver-tooltip {
  background: var(--tooltip-bg);
  color: #fff;
  border: 0;
  border-radius: 8px;
  padding: 4px 8px;
  font-size: 12px;
  line-height: 1.25;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  white-space: nowrap;
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.admin-driver-tooltip::before {
  border-top-color: var(--tooltip-bg);
}

.notify-banner {
  border-color: rgba(106, 179, 243, 0.35);
  background: linear-gradient(180deg, rgba(106, 179, 243, 0.12) 0%, var(--card) 100%);
}

.impersonation-banner {
  border-color: rgba(240, 180, 41, 0.45);
  background: linear-gradient(180deg, rgba(240, 180, 41, 0.14) 0%, var(--card) 100%);
  margin-bottom: 12px;
}

.impersonation-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.impersonation-row .hint {
  margin: 4px 0 0;
}

.impersonation-row button {
  flex-shrink: 0;
}

.notify-banner h2 { margin-bottom: 8px; }

.notify-steps {
  margin: 10px 0 0;
  padding-left: 1.2em;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

.notify-steps li { margin: 4px 0; }
.notify-steps b { color: var(--title); font-weight: 600; }

.admin-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  width: 100%;
  max-width: 100%;
  margin: 0 0 16px;
  padding: 0;
  box-sizing: border-box;
}

.admin-tile {
  min-height: 72px;
  width: 100%;
  max-width: 100%;
  padding: 12px 10px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--elevated);
  color: var(--title);
  font-weight: 600;
  font-size: 13px;
  line-height: 1.3;
  text-align: left;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.admin-item { cursor: pointer; }

.admin-back {
  min-width: 44px;
  flex-shrink: 0;
  padding: 8px 12px;
}

.admin-info-row {
  display: grid;
  grid-template-columns: 88px 1fr;
  gap: 8px;
  align-items: start;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}
.admin-info-row:last-of-type { border-bottom: 0; }
.admin-info-row span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}
.admin-info-row b {
  color: var(--title);
  font-weight: 600;
  overflow-wrap: anywhere;
  word-break: break-word;
}

@media (max-width: 380px) {
  .admin-grid { grid-template-columns: 1fr; }
}

@media (min-width: 700px) {
  .bottom-nav {
    max-width: 680px;
    margin: 0 auto;
    border-radius: 18px 18px 0 0;
  }
}

/* —— Order chat (Telegram-like) —— */
body.chat-open {
  overflow: hidden;
  height: 100%;
  height: 100dvh;
  height: var(--tg-viewport-stable-height, 100dvh);
  touch-action: manipulation;
}

#app.chat-mode {
  position: fixed;
  inset: 0;
  z-index: 30;
  width: 100%;
  max-width: none;
  margin: 0;
  padding: 0;
  height: 100%;
  height: 100dvh;
  height: var(--tg-viewport-stable-height, 100dvh);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--chat-bg);
}

.chat-screen {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  height: 100%;
  overflow: hidden;
  background: var(--chat-bg);
  color: var(--title);
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 12px 10px;
  background: var(--chat-panel);
  border-bottom: 1px solid var(--chat-border);
  flex-shrink: 0;
}

.chat-back {
  color: var(--primary) !important;
  font-size: 22px;
  padding: 4px 8px;
  margin: 0;
}

.chat-header-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.chat-header-info b {
  color: var(--title);
  font-size: 16px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-header-info .hint {
  color: var(--muted);
  font-size: 12px;
}

.chat-closed-banner {
  text-align: center;
  font-size: 13px;
  padding: 8px 12px;
  background: var(--elevated);
  color: var(--muted);
  flex-shrink: 0;
}

.chat-messages {
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 12px 10px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  background:
    radial-gradient(ellipse at 20% 0%, var(--primary-soft), transparent 50%),
    var(--chat-bg);
  -webkit-overflow-scrolling: touch;
}

.chat-empty {
  margin: auto;
  color: var(--muted);
  font-size: 14px;
  text-align: center;
  padding: 24px;
}

.chat-bubble {
  position: relative;
  max-width: 82%;
  padding: 8px 10px 6px;
  border-radius: 12px;
  font-size: 15px;
  line-height: 1.35;
  word-break: break-word;
  box-shadow: 0 1px 2px rgba(0,0,0,0.2);
}

.chat-bubble.mine {
  align-self: flex-end;
  background: var(--chat-mine);
  border-bottom-right-radius: 4px;
  color: #fff;
}

.chat-bubble.theirs {
  align-self: flex-start;
  background: var(--chat-theirs);
  border-bottom-left-radius: 4px;
  color: var(--title);
  border: 1px solid transparent;
}

html[data-theme="light"] .chat-bubble.theirs {
  border-color: var(--line);
  box-shadow: 0 1px 2px rgba(15, 30, 45, 0.06);
}

.chat-bubble.deleted {
  opacity: 0.75;
  font-style: italic;
}

.chat-deleted { color: var(--muted); font-size: 14px; }

.chat-text { white-space: pre-wrap; }

.chat-photo {
  display: block;
  margin: 0 0 4px;
}

.chat-photo img {
  display: block;
  max-width: 100%;
  max-height: 260px;
  border-radius: 8px;
  object-fit: cover;
}

.chat-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  text-align: right;
  font-size: 11px;
  color: rgba(255,255,255,0.55);
  margin-top: 4px;
}

.chat-bubble.theirs .chat-meta { color: var(--muted); }

.chat-sender {
  font-size: 12px;
  font-weight: 600;
  color: var(--primary);
  margin-bottom: 4px;
  line-height: 1.2;
}

.chat-sender.admin {
  color: var(--warning);
}

.chat-ticks {
  letter-spacing: -2px;
  font-size: 12px;
  line-height: 1;
  color: rgba(255,255,255,0.45);
  flex-shrink: 0;
}

.chat-ticks.read {
  color: #53bdeb;
}

.chat-bubble.deleted .chat-ticks {
  color: var(--muted);
}

.chat-bubble.deleted .chat-ticks.read {
  color: #53bdeb;
}

.chat-edited {
  margin-right: 2px;
  font-style: italic;
}

.chat-action { margin-top: 8px; }

.chat-btn {
  position: relative;
}

.chat-unread-dot {
  position: absolute;
  top: -3px;
  right: -3px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #e53935;
  border: 2px solid #fff;
  pointer-events: none;
}

.chat-bubble.chat-actionable {
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
}

.chat-composer {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom, 0px)) 2px;
  background: var(--chat-panel);
  border-top: 1px solid var(--chat-border);
  flex-shrink: 0;
}

.chat-composer textarea {
  flex: 1;
  min-width: 0;
  width: 0;
  resize: none;
  border: 0;
  border-radius: 20px;
  height: 40px;
  min-height: 40px;
  max-height: 120px;
  padding: 10px 14px;
  line-height: 20px;
  background: var(--input);
  color: var(--title);
  font: inherit;
  outline: none;
  box-sizing: border-box;
  overflow-y: auto;
}

.chat-composer textarea::placeholder { color: var(--muted); }

.chat-attach,
.chat-send {
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: var(--chat-mine);
  color: #fff;
  font-size: 18px;
  cursor: pointer;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  line-height: 1;
}

.chat-attach {
  background: transparent;
  color: var(--primary);
  font-size: 22px;
  width: 36px;
  margin: 0;
}

.chat-send-icon {
  display: block;
  line-height: 1;
  transform: translate(1px, 0.5px);
  font-size: 17px;
}

.chat-ctx {
  position: fixed;
  z-index: 40;
  width: min(180px, calc(100% - 24px));
  background: var(--elevated);
  border-radius: 12px;
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
  overflow: hidden;
}

.chat-ctx button {
  display: block;
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--title);
  text-align: left;
  padding: 12px 14px;
  font: inherit;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}

.chat-ctx button:last-child {
  border-bottom: 0;
}

.chat-ctx button[data-chat-delete] {
  color: var(--danger);
}

