:root {
  --bg: var(--tg-theme-bg-color, #efe6d6);
  --text: var(--tg-theme-text-color, #241c14);
  --hint: var(--tg-theme-hint-color, #6f6558);
  --card: var(--tg-theme-section-bg-color, #fffaf2);
  --btn: var(--tg-theme-button-color, #1f6b4a);
  --btn-text: var(--tg-theme-button-text-color, #fffaf2);
  --line: var(--tg-theme-section-separator-color, #e4d5c0);
  --good: #1f6b4a;
  --warn: #8d5b12;
  --bad: #8d2e2e;
  --shadow: 0 10px 30px rgba(48, 32, 12, 0.06);
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", "Avenir Next", sans-serif;
  font-size: 16px;
  line-height: 1.45;
}

button, input, select, textarea { font: inherit; color: inherit; }

button { cursor: pointer; }

#app { min-height: 100vh; }

.wrap {
  width: min(560px, 100%);
  margin: 0 auto;
  min-height: 100vh;
}

.dev {
  background: #3d3428;
  color: #f6edd9;
  text-align: center;
  font-size: 13px;
  letter-spacing: 0.02em;
  padding: 6px 12px;
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 16px 8px;
  width: 100%;
}

.top-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.logo {
  width: 44px;
  height: 44px;
  object-fit: cover;
  border-radius: 50%;
  flex-shrink: 0;
  overflow: hidden;
}

.top-titles {
  min-width: 0;
}

.top-titles .brand {
  margin: 0;
}

.top-titles h1 {
  margin: 0;
  font-family: Palatino, "Palatino Linotype", Georgia, serif;
  font-size: 24px;
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 1.1;
}

.top .back {
  width: auto;
  flex: 0 0 auto;
  margin-left: auto;
  text-align: right;
  white-space: nowrap;
}

.top h1 {
  margin: 0;
  font-family: Palatino, "Palatino Linotype", Georgia, serif;
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 1.1;
}

.brand {
  color: var(--good);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.back, .back-spacer { width: 72px; flex: 0 0 auto; }

.back {
  border: 0;
  background: transparent;
  color: var(--btn);
  padding: 8px 0;
  text-align: left;
}

.switch, .seg, .switch2, .row, .actions, .pager {
  display: flex;
  gap: 8px;
}

.switch, .seg { padding: 8px 16px 0; }

.switch button, .seg button, .switch2 label {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--line);
  background: transparent;
  border-radius: 999px;
  padding: 8px 10px;
  color: var(--text);
}

.switch button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  overflow: hidden;
}

.switch button .switch-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.switch button.on, .seg button.on, .switch2 label.on {
  background: var(--btn);
  border-color: var(--btn);
  color: var(--btn-text);
}

.count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  min-width: 1.25em;
  margin-left: 0;
  padding: 1px 7px;
  border-radius: 999px;
  background: rgba(255, 250, 242, 0.25);
  font-size: 12px;
  line-height: 1.3;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.switch button:not(.on) .count {
  background: rgba(141, 91, 18, 0.18);
  color: var(--warn);
}

.switch button.on .count {
  background: rgba(255, 255, 255, 0.28);
  color: inherit;
}

.nav button .count {
  margin-left: 4px;
  vertical-align: middle;
}

.main { padding: 14px 16px 128px; }

.card, .person, .entry {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 14px;
  margin-bottom: 12px;
}

.card h2, .person strong, .entry summary {
  font-family: Palatino, "Palatino Linotype", Georgia, serif;
}

.card h2 {
  margin: 0 0 10px;
  font-size: 22px;
}

.lead { margin-top: 0; }

.muted { color: var(--hint); font-size: 14px; }

.field { display: block; margin-bottom: 12px; }

.field > span, .toggle span, .kv span {
  display: block;
  margin-bottom: 6px;
  color: var(--hint);
  font-size: 13px;
}

.field input:disabled {
    color: #888;
    cursor: not-allowed;
}

.field select:disabled {
    background: #e5e5e5;
    color: #888;
    opacity: 1;
    cursor: not-allowed;
}

input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: transparent;
  border-radius: 12px;
  padding: 12px;
  outline: none;
}

textarea { min-height: 96px; resize: vertical; }

.switch2 { margin-top: 4px; }

.switch2 label {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
}

.switch2 input { width: auto; }

.switch2.disabled {
    opacity: 0.5;
    pointer-events: none;
}

.switch2 label.disabled {
    cursor: not-allowed;
}

.btn {
  border: 0;
  border-radius: 14px;
  padding: 12px 14px;
  background: var(--btn);
  color: var(--btn-text);
}

.btn.secondary, .btn.ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--line);
}

.btn.danger {
  background: transparent;
  color: var(--bad);
  border: 1px solid rgba(141, 46, 46, 0.35);
}

.btn.wide { width: 100%; margin-top: 4px; }

.btn.wide:disabled {
  background-color: #d0d0d0;
  color: #999;
  cursor: not-allowed;
  pointer-events: none;
}

.main > .btn.wide { margin-bottom: 12px; }

.actions { margin-top: 8px; }

.actions .btn, .row .btn, .pager .btn { flex: 1; }

.badge {
  display: inline-block;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 13px;
  border: 1px solid var(--line);
}

.badge.wait { color: var(--warn); }
.badge.ok { color: var(--good); }
.badge.no { color: var(--bad); }

.person { display: block; width: 100%; text-align: left; }
.person[data-act] { cursor: pointer; }

.person.self { border-color: var(--good); }

.person.clickable {
  cursor: pointer;
}
.person.clickable:active {
  opacity: 0.85;
}

.kv { margin-bottom: 8px; }

.kv b { font-weight: 600; }

.thread { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }

.bubble {
  max-width: 92%;
  padding: 10px 12px;
  border-radius: 14px;
  background: rgba(36, 28, 20, 0.05);
  white-space: pre-wrap;
  word-break: break-word;
}

.bubble.mine { align-self: flex-end; background: rgba(31, 107, 74, 0.14); }
.bubble.sys { align-self: center; max-width: 100%; color: var(--hint); background: transparent; text-align: center; font-size: 14px; }
.bubble small { display: block; margin-top: 4px; color: var(--hint); }

.entry summary { cursor: pointer; font-size: 18px; }
.entry-body { white-space: pre-wrap; word-break: break-word; margin-top: 10px; }

.entry-body a {
    color: var(--tg-theme-link-color, #2481cc);
    text-decoration: underline;
    font-weight: 500;
}

.entry-body a:hover {
    opacity: 0.75;
}

.toggle {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 10px 0;
  border-top: 1px solid var(--line);
}

.toggle span { margin: 0; color: var(--text); font-size: 15px; }
.toggle input { width: 22px; height: 22px; }

.bar {
  border: 1px solid rgba(141, 46, 46, 0.35);
  border-radius: 16px;
  padding: 12px;
  margin-top: 8px;
}

.empty { text-align: center; padding: 28px 10px; }

.meta { margin-top: 8px; }

.pager { margin: 8px 0 16px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 92px;
  transform: translateX(-50%) translateY(12px);
  width: min(520px, calc(100% - 24px));
  background: #241c14;
  color: #fffaf2;
  border-radius: 14px;
  padding: 12px 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
  z-index: 5;
}

.toast.on { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.bad { background: var(--bad); }

.nav {
  position: fixed;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: min(560px, 100%);
  display: flex;
  gap: 4px;
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  background: var(--card);
  border-top: 1px solid var(--line);
}

.nav button {
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  color: var(--hint);
  border-radius: 12px;
  padding: 10px 4px;
  font-size: 12px;
  line-height: 1.15;
}

.nav button.on {
  color: var(--btn-text);
  background: var(--btn);
}

button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--btn);
  outline-offset: 2px;
}
