:root {
  color-scheme: light dark;
  --bg: var(--tg-theme-bg-color, #f4f6f8);
  --panel: var(--tg-theme-secondary-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #17202a);
  --muted: var(--tg-theme-hint-color, #657282);
  --line: color-mix(in srgb, var(--muted) 24%, transparent);
  --accent: var(--tg-theme-button-color, #1769e0);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --danger: #d92d20;
  --danger-soft: color-mix(in srgb, var(--danger) 12%, var(--panel));
  --ok: #079455;
  --ok-soft: color-mix(in srgb, var(--ok) 14%, var(--panel));
  --radius: 8px;
  --shadow: 0 12px 32px rgb(15 23 42 / 8%);
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg);
}

body {
  margin: 0;
  min-width: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.42 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text);
  padding: 10px 14px;
  cursor: pointer;
}

button:disabled {
  cursor: default;
  opacity: .48;
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}

button.danger {
  background: var(--danger-soft);
  border-color: color-mix(in srgb, var(--danger) 32%, transparent);
  color: var(--danger);
}

button.active {
  border-color: var(--accent);
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 13%, var(--panel));
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 22px;
  line-height: 1.16;
}

h2 {
  font-size: 17px;
  line-height: 1.25;
}

h3 {
  font-size: 15px;
  line-height: 1.25;
}

.app {
  width: min(100%, 920px);
  margin: 0 auto;
  padding: 14px 12px 28px;
}

.topbar {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}

#screenSubtitle {
  color: var(--muted);
  margin-top: 3px;
  overflow-wrap: anywhere;
}

.hidden {
  display: none !important;
}

.muted {
  color: var(--muted);
}

.status {
  padding: 10px 12px;
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--accent) 10%, var(--panel));
  border-radius: var(--radius);
  margin-bottom: 12px;
}

.status[data-variant="error"] {
  background: var(--danger-soft);
  color: var(--danger);
}

.icon-button {
  width: 44px;
  min-width: 44px;
  padding: 0;
  font-size: 22px;
}

.chat-list,
.stack {
  display: grid;
  gap: 10px;
}

.card,
.empty-state {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.card {
  padding: 13px;
}

.empty-state {
  padding: 16px;
  color: var(--muted);
}

.chat-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
}

.chat-card p,
.member p,
.fine-card p {
  margin-top: 3px;
  overflow-wrap: anywhere;
}

.chat-actions,
.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chat-actions {
  justify-content: flex-end;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  margin-top: 8px;
  padding: 3px 8px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--muted) 13%, var(--panel));
  color: var(--muted);
  font-size: 13px;
}

.badge.on {
  background: var(--ok-soft);
  color: var(--ok);
}

.badge.off {
  background: var(--danger-soft);
  color: var(--danger);
}

.tabs {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 7px;
  margin-bottom: 12px;
}

.tabs button {
  padding: 9px 8px;
  min-width: 0;
}

.section-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: start;
  margin-bottom: 12px;
}

.member {
  display: grid;
  gap: 12px;
}

.member-head,
.fine-main {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.member-title {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 10px;
  min-width: 0;
}

.queue-number {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--accent) 13%, var(--panel));
  color: var(--accent);
  font-weight: 700;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.form-grid.compact {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
}

input,
select {
  width: 100%;
  min-width: 0;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 9px 11px;
  color: var(--text);
  background: var(--bg);
}

.block-title {
  margin: 16px 0 9px;
}

.days {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 6px;
}

.days label {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 4px;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
}

.actions {
  margin-top: 2px;
}

.fine-card {
  display: grid;
  gap: 10px;
}

.fine-main strong {
  color: var(--accent);
  font-size: 18px;
  white-space: nowrap;
}

.fine-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.fine-meta span {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 8px;
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: end center;
  padding: 12px;
  background: rgb(0 0 0 / 42%);
}

.modal-card {
  width: min(100%, 680px);
  max-height: min(82vh, 720px);
  overflow: hidden;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px 14px var(--radius) var(--radius);
  box-shadow: 0 18px 50px rgb(0 0 0 / 24%);
}

.modal-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: start;
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.known-list {
  display: grid;
  gap: 8px;
  overflow-y: auto;
  padding: 12px;
}

.known-user {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg);
}

.error-text {
  color: var(--danger);
}

.brand-footer {
  display: grid;
  gap: 2px;
  justify-items: center;
  margin-top: 22px;
  color: var(--muted);
  font-size: 13px;
}

.brand-footer strong {
  color: var(--text);
  font-size: 14px;
}

@media (max-width: 720px) {
  .app {
    padding-inline: 10px;
  }

  .chat-card,
  .section-head,
  .member-head,
  .fine-main,
  .known-user {
    grid-template-columns: 1fr;
  }

  .member-head,
  .fine-main {
    display: grid;
  }

  .chat-actions,
  .section-head > button,
  .known-user button {
    width: 100%;
  }

  .chat-actions button,
  .section-head > button,
  .known-user button {
    flex: 1 1 120px;
  }

  .form-grid,
  .form-grid.compact {
    grid-template-columns: 1fr;
  }

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

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

@media (max-width: 360px) {
  .tabs,
  .days {
    grid-template-columns: 1fr;
  }
}
