:root {
  color-scheme: light;
  --page: #e9eeeb;
  --surface: #ffffff;
  --surface-soft: #f5f7f4;
  --ink: #1f2723;
  --muted: #66736d;
  --line: #d8dfd9;
  --accent: #176b5b;
  --accent-strong: #0f4d41;
  --accent-soft: #e2f1ed;
  --danger-line: #ead6b5;
  --shadow: 0 18px 48px rgba(23, 37, 31, 0.16);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
}

button,
input,
textarea {
  font: inherit;
}

button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
}

button:hover {
  border-color: var(--accent);
}

button:disabled {
  cursor: wait;
  opacity: 0.58;
}

.app-shell {
  display: flex;
  flex-direction: column;
  width: min(100vw, 520px);
  min-height: 100svh;
  margin: 0 auto;
  background: var(--surface);
  border-left: 1px solid var(--line);
  border-right: 1px solid var(--line);
}

.topbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto 42px;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  min-width: 0;
  overflow: hidden;
  font-size: 20px;
  line-height: 1.15;
  text-overflow: ellipsis;
  white-space: nowrap;
}

h2 {
  font-size: 18px;
}

.mode-tabs {
  display: inline-grid;
  grid-template-columns: 1fr 1fr;
  gap: 3px;
  width: 126px;
  padding: 3px;
  border: 1px solid var(--line);
  background: var(--surface-soft);
  border-radius: 8px;
}

.tab {
  min-height: 34px;
  border: 0;
  background: transparent;
  font-size: 14px;
}

.tab.active {
  background: var(--accent);
  color: #fff;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 42px;
  min-height: 38px;
  padding: 0;
  font-size: 22px;
  line-height: 1;
}

.state-strip {
  min-height: 32px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  background: var(--surface-soft);
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.auth-banner {
  display: grid;
  gap: 12px;
  margin: auto 16px;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  text-align: center;
}

.auth-banner[hidden] {
  display: none;
}

.auth-banner p {
  margin: 0;
  line-height: 1.5;
}

.auth-action {
  display: grid;
  place-items: center;
  min-height: 42px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  text-decoration: none;
}

body.auth-blocked .mode-tabs,
body.auth-blocked #menuButton,
body.auth-blocked .state-strip,
body.auth-blocked .question-panel,
body.auth-blocked .message-list,
body.auth-blocked .bottom-bar {
  display: none;
}

.question-panel {
  max-height: 32dvh;
  overflow: auto;
  padding: 12px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfa;
}

.panel-label {
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 12px;
}

pre {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-family: inherit;
  line-height: 1.5;
}

.message-list {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  background: #f0f4f1;
}

.message {
  width: fit-content;
  max-width: min(92%, 420px);
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.message.user {
  align-self: flex-end;
  background: var(--accent-soft);
  border-color: #b7d8d0;
}

.message.system {
  align-self: center;
  max-width: 100%;
  color: var(--muted);
  background: transparent;
  border: 0;
  font-size: 13px;
  text-align: center;
}

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

.bottom-bar {
  position: sticky;
  bottom: 0;
  display: grid;
  gap: 8px;
  padding: 8px 10px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.97);
  backdrop-filter: blur(8px);
}

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

.quick-actions button {
  min-height: 34px;
  padding: 0 4px;
  font-size: 13px;
}

.review-prompt {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 13px;
}

.review-prompt[hidden] {
  display: none;
}

.review-prompt div {
  display: grid;
  grid-template-columns: repeat(3, auto);
  gap: 5px;
}

.review-prompt button {
  min-height: 30px;
  padding: 0 8px;
  font-size: 13px;
}

.composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 72px;
  gap: 8px;
}

textarea,
input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
}

textarea {
  min-height: 44px;
  max-height: 120px;
  resize: none;
  padding: 11px 12px;
  line-height: 1.4;
}

input {
  height: 42px;
  padding: 0 10px;
}

textarea:focus,
input:focus,
button:focus-visible {
  outline: 2px solid #8ac2b4;
  outline-offset: 2px;
}

.primary-action {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.primary-action:hover {
  background: var(--accent-strong);
}

.overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: end center;
  padding: 14px;
  background: rgba(20, 28, 24, 0.42);
  z-index: 20;
}

.overlay[hidden] {
  display: none;
}

.sheet,
.modal {
  width: min(100%, 500px);
  max-height: min(82dvh, 680px);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.modal {
  align-self: center;
}

.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

.menu-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 14px;
}

.menu-grid button:last-child {
  grid-column: 1 / -1;
}

.modal-body {
  max-height: calc(min(82dvh, 680px) - 64px);
  overflow: auto;
  padding: 14px;
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.history-list {
  display: grid;
  gap: 10px;
}

.history-item {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  white-space: pre-wrap;
}

.lookup {
  display: grid;
  gap: 8px;
}

.lookup label {
  color: var(--muted);
  font-size: 13px;
}

.lookup div {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 64px;
  gap: 8px;
}

.telegram-link {
  display: grid;
  gap: 12px;
}

.telegram-link p,
.telegram-link ol {
  margin: 0;
}

.telegram-link form {
  display: grid;
  gap: 8px;
}

.telegram-link form label,
.telegram-link-message {
  color: var(--muted);
  font-size: 13px;
}

.telegram-link form div {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 64px;
  gap: 8px;
}

.telegram-link input {
  text-transform: uppercase;
}

@media (min-width: 760px) {
  body {
    padding: 16px 0;
  }

  .app-shell {
    min-height: calc(100svh - 32px);
    border: 1px solid var(--line);
    box-shadow: var(--shadow);
  }
}
