:root {
  color-scheme: light dark;
  --bg: var(--tg-theme-bg-color, #f4f6f8);
  --text: var(--tg-theme-text-color, #1c2430);
  --hint: var(--tg-theme-hint-color, #6b7280);
  --btn: var(--tg-theme-button-color, #2aabee);
  --btn-text: var(--tg-theme-button-text-color, #ffffff);
  --secondary: var(--tg-theme-secondary-bg-color, #ffffff);
  --user-bubble: #dce6f2;
  --user-text: #152033;
  --admin-bubble: var(--btn);
  --admin-text: #ffffff;
  --border: rgba(28, 36, 48, 0.12);
  --unread: #2aabee;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
}

body {
  display: flex;
  flex-direction: column;
}

.screen {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}

.screen[hidden] {
  display: none !important;
}

.gate {
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.gate-card {
  max-width: 320px;
  text-align: center;
}

.gate-title {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 12px;
}

.gate-text {
  margin: 0 0 8px;
  font-size: 15px;
  line-height: 1.4;
}

.gate-hint {
  margin: 0;
  font-size: 13px;
  color: var(--hint);
}

.header {
  padding: 12px 16px 10px;
  border-bottom: 1px solid var(--border);
  background: var(--secondary);
  flex-shrink: 0;
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 8px;
}

.chat-header .header-text {
  flex: 1;
  min-width: 0;
}

.chat-header .back-btn {
  flex-shrink: 0;
}

.header-text {
  min-width: 0;
  flex: 1;
}

.header-title {
  font-weight: 600;
  font-size: 16px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-sub {
  margin-top: 2px;
  font-size: 12px;
  color: var(--hint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.header-actions input[type="search"] {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}

.icon-btn {
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font-size: 18px;
  cursor: pointer;
  flex-shrink: 0;
}

.back-btn {
  border: none;
  background: transparent;
  font-size: 22px;
  width: 32px;
}

.inbox-list {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}

.inbox-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  background: var(--secondary);
}

.inbox-row:active {
  opacity: 0.85;
}

.inbox-row.unread .inbox-name {
  font-weight: 700;
}

.avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  object-fit: cover;
  background: #c5cdd8;
  flex-shrink: 0;
}

.inbox-body {
  flex: 1;
  min-width: 0;
}

.inbox-top {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: baseline;
}

.inbox-name {
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.inbox-time {
  font-size: 11px;
  color: var(--hint);
  flex-shrink: 0;
}

.inbox-preview {
  margin-top: 2px;
  font-size: 13px;
  color: var(--hint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.unread-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--unread);
  flex-shrink: 0;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--bg);
  min-height: 0;
}

.bubble {
  max-width: 85%;
  padding: 8px 12px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.35;
  white-space: pre-wrap;
  word-break: break-word;
}

.bubble.user {
  align-self: flex-start;
  background: var(--user-bubble);
  color: var(--user-text);
}

.bubble.admin {
  align-self: flex-end;
  background: var(--admin-bubble);
  color: var(--admin-text);
}

.bubble.callback {
  align-self: flex-start;
  background: var(--user-bubble);
  color: var(--user-text);
  border: 1px dashed rgba(28, 36, 48, 0.25);
  font-style: italic;
}

.bubble .meta {
  margin-top: 4px;
  font-size: 10px;
  opacity: 0.65;
}

.bubble img,
.bubble video {
  display: block;
  max-width: 100%;
  border-radius: 10px;
  margin-top: 6px;
}

.bubble a.file-link {
  color: inherit;
  text-decoration: underline;
}

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

.attach-preview {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-top: 1px solid var(--border);
  background: var(--secondary);
  font-size: 13px;
  color: var(--hint);
}

.attach-preview[hidden] {
  display: none;
}

.attach-preview span {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
}

.composer .attach-btn {
  width: 44px;
  height: 44px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  color: var(--text);
  font-size: 18px;
  cursor: pointer;
  flex-shrink: 0;
}

.composer textarea {
  flex: 1;
  resize: none;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  max-height: 120px;
}

.composer button#sendBtn {
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 12px;
  background: var(--btn);
  color: var(--btn-text);
  font-size: 18px;
  cursor: pointer;
  flex-shrink: 0;
}

.composer button:disabled {
  opacity: 0.5;
  cursor: default;
}

.error {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: 80px;
  padding: 10px 12px;
  border-radius: 10px;
  background: #b42318;
  color: #fff;
  font-size: 13px;
  z-index: 10;
}

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

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

.schedule-screen {
  overflow: hidden;
}

.schedule-nav {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.schedule-nav button {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 6px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.schedule-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 8px 12px 24px;
}

.schedule-day {
  margin-bottom: 14px;
}

.schedule-day-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--hint);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin: 0 0 8px;
}

.schedule-event {
  display: block;
  width: 100%;
  text-align: left;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 6px;
  background: var(--secondary);
  color: var(--text);
  font: inherit;
  cursor: default;
}

.schedule-event.clickable {
  cursor: pointer;
}

.schedule-event.clickable:active {
  opacity: 0.75;
}

.schedule-event-time {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 2px;
}

.schedule-event-title {
  font-size: 14px;
  line-height: 1.35;
}

.schedule-event-hint {
  margin-top: 4px;
  font-size: 12px;
  color: var(--btn);
}

.schedule-day-empty {
  font-size: 13px;
  color: var(--hint);
  padding: 4px 2px 8px;
}
