:root {
  --accent: #3390ec;
  --accent-text: #ffffff;
  --header: #517da2;
  --header-text: #ffffff;
  --bg: #b9d39b;
  --bg-dot: rgba(255, 255, 255, 0.22);
  --in: #ffffff;
  --in-text: #000000;
  --out: #effdde;
  --out-text: #000000;
  --meta-in: #a0acb6;
  --meta-out: #5fae53;
  --link: #168acd;
  --chip: rgba(0, 0, 0, 0.22);
  --chip-text: #ffffff;
  --surface: #ffffff;
  --surface-text: #000000;
  --muted: #707579;
  --border: #e4e4e4;
  --danger: #e53935;
  --btn-inline: rgba(0, 0, 0, 0.18);
  --shadow: 0 1px 1px rgba(0, 0, 0, 0.13);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --accent: #8774e1;
    --header: #212121;
    --header-text: #ffffff;
    --bg: #0f1a24;
    --bg-dot: rgba(255, 255, 255, 0.035);
    --in: #212121;
    --in-text: #ffffff;
    --out: #766ac8;
    --out-text: #ffffff;
    --meta-in: #8f9aa3;
    --meta-out: #d6d0ff;
    --link: #8ec8ff;
    --chip: rgba(0, 0, 0, 0.45);
    --surface: #212121;
    --surface-text: #ffffff;
    --muted: #aaaaaa;
    --border: #2f2f2f;
    --btn-inline: rgba(255, 255, 255, 0.12);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --accent: #8774e1;
  --header: #212121;
  --bg: #0f1a24;
  --bg-dot: rgba(255, 255, 255, 0.035);
  --in: #212121;
  --in-text: #ffffff;
  --out: #766ac8;
  --out-text: #ffffff;
  --meta-in: #8f9aa3;
  --meta-out: #d6d0ff;
  --link: #8ec8ff;
  --chip: rgba(0, 0, 0, 0.45);
  --surface: #212121;
  --surface-text: #ffffff;
  --muted: #aaaaaa;
  --border: #2f2f2f;
  --btn-inline: rgba(255, 255, 255, 0.12);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  background: var(--bg);
  color: var(--surface-text);
  -webkit-text-size-adjust: 100%;
}

button { font: inherit; color: inherit; cursor: pointer; }

.avatar {
  flex: none;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 18px;
  color: #fff;
  background: linear-gradient(135deg, #72d5fd, #2a9ef1);
}
.avatar-lg { width: 88px; height: 88px; font-size: 38px; margin: 0 auto 16px; }

/* Kirish */
.login {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px 16px;
  background: var(--surface);
}
.login-card { max-width: 360px; text-align: center; line-height: 1.5; }
.login-card h1 { margin: 0 0 12px; font-size: 24px; }
.login-card p { margin: 0 0 12px; }
.login-card .muted { color: var(--muted); font-size: 14px; }
.login-error { color: var(--danger); font-weight: 600; }
.login-card form { margin-top: 20px; }
.big-btn {
  width: 100%;
  border: 0;
  border-radius: 12px;
  padding: 14px;
  font-weight: 600;
  background: var(--accent);
  color: var(--accent-text);
}

/* Asosiy */
.app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  background-color: var(--bg);
  background-image: radial-gradient(var(--bg-dot) 1.4px, transparent 1.6px);
  background-size: 22px 22px;
}

.topbar {
  position: relative;
  flex: none;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 8px 8px 12px;
  padding-top: calc(8px + env(safe-area-inset-top));
  background: var(--header);
  color: var(--header-text);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.18);
  z-index: 5;
}
.title { flex: 1; min-width: 0; }
.name { font-weight: 600; font-size: 16px; }
.status { font-size: 13.5px; opacity: 0.75; }
.status.typing { opacity: 1; }
.status.typing::after {
  content: "";
  display: inline-block;
  width: 1.2em;
  text-align: left;
  animation: dots 1.2s steps(4, end) infinite;
}
@keyframes dots {
  0% { content: ""; } 25% { content: "."; } 50% { content: ".."; } 75% { content: "..."; }
}

.icon-btn {
  border: 0;
  background: transparent;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: grid;
  place-items: center;
}
.icon-btn svg { fill: currentColor; }
.icon-btn:hover { background: rgba(255, 255, 255, 0.12); }

.menu {
  position: absolute;
  right: 8px;
  top: calc(100% - 4px);
  min-width: 210px;
  padding: 6px 0;
  border-radius: 12px;
  background: var(--surface);
  color: var(--surface-text);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.22);
}
.menu button {
  display: block;
  width: 100%;
  border: 0;
  background: transparent;
  text-align: left;
  padding: 10px 16px;
  font-size: 15px;
}
.menu button:hover { background: var(--btn-inline); }
.menu hr { border: 0; border-top: 1px solid var(--border); margin: 6px 0; }
.menu .danger { color: var(--danger); }

.scroll {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 8px 0;
}
.messages {
  max-width: 760px;
  margin: 0 auto;
  padding: 0 10px;
  display: flex;
  flex-direction: column;
}
.older { text-align: center; font-size: 13px; color: var(--chip-text); padding: 6px; }

.day {
  align-self: center;
  margin: 10px 0 6px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 13.5px;
  font-weight: 500;
  background: var(--chip);
  color: var(--chip-text);
  position: sticky;
  top: 4px;
  z-index: 2;
}

.msg {
  position: relative;
  max-width: min(85%, 520px);
  margin: 2px 0;
  padding: 6px 9px 7px 10px;
  border-radius: 14px;
  box-shadow: var(--shadow);
  line-height: 1.38;
  font-size: 15.5px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.msg.in { align-self: flex-start; background: var(--in); color: var(--in-text); border-bottom-left-radius: 5px; }
.msg.out { align-self: flex-end; background: var(--out); color: var(--out-text); border-bottom-right-radius: 5px; }
.msg.follow.in { border-bottom-left-radius: 14px; border-top-left-radius: 5px; }
.msg.follow.out { border-bottom-right-radius: 14px; border-top-right-radius: 5px; }
.msg a { color: var(--link); text-decoration: none; }
.msg.out a { color: inherit; text-decoration: underline; }
.msg a:hover { text-decoration: underline; }

.meta {
  float: right;
  margin: 6px 0 -4px 10px;
  font-size: 12px;
  line-height: 1;
  white-space: nowrap;
  user-select: none;
}
.msg.in .meta { color: var(--meta-in); }
.msg.out .meta { color: var(--meta-out); }
.meta .src { margin-right: 4px; }
.meta svg { vertical-align: -2px; margin-left: 2px; fill: currentColor; }

.msg.photo { padding: 3px; }
.msg.photo img {
  display: block;
  max-width: 100%;
  max-height: 420px;
  border-radius: 11px;
  cursor: zoom-in;
  background: var(--btn-inline);
  min-height: 80px;
}
.msg.photo .caption { padding: 5px 7px 3px; }

.inline-kb {
  display: flex;
  gap: 4px;
  margin-top: 4px;
  align-self: flex-start;
  width: min(85%, 520px);
}
.inline-kb button {
  flex: 1;
  border: 0;
  border-radius: 10px;
  padding: 9px 8px;
  font-size: 14.5px;
  font-weight: 500;
  background: var(--chip);
  color: var(--chip-text);
  backdrop-filter: blur(6px);
}
.inline-kb button:hover { filter: brightness(1.12); }
.inline-kb button:disabled { opacity: 0.6; cursor: default; }
.approval-state { font-size: 13px; margin-top: 6px; font-weight: 600; }

.down-btn {
  position: absolute;
  right: 14px;
  bottom: calc(76px + env(safe-area-inset-bottom));
  width: 46px;
  height: 46px;
  border: 0;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--surface);
  color: var(--muted);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
  z-index: 4;
}

.cmd-bar {
  flex: none;
  max-width: 760px;
  width: 100%;
  margin: 0 auto;
  background: var(--surface);
  border-radius: 12px 12px 0 0;
  max-height: 40vh;
  overflow-y: auto;
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.12);
}
.cmd-bar button {
  display: flex;
  gap: 10px;
  width: 100%;
  border: 0;
  background: transparent;
  padding: 10px 16px;
  text-align: left;
  font-size: 15px;
}
.cmd-bar button:hover, .cmd-bar button.active { background: var(--btn-inline); }
.cmd-bar b { color: var(--accent); font-weight: 600; min-width: 84px; }
.cmd-bar span { color: var(--muted); }

.composer {
  flex: none;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: 760px;
  width: 100%;
  margin: 0 auto;
  padding: 8px 10px;
  padding-bottom: calc(8px + env(safe-area-inset-bottom));
}
.composer textarea {
  flex: 1;
  min-width: 0;
  resize: none;
  border: 0;
  outline: none;
  border-radius: 22px;
  padding: 11px 16px;
  font: inherit;
  font-size: 16px;
  line-height: 1.35;
  max-height: 160px;
  background: var(--surface);
  color: var(--surface-text);
  box-shadow: var(--shadow);
}
.composer textarea::placeholder { color: var(--muted); }
.send-btn, .stop-btn {
  flex: none;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  display: grid;
  place-items: center;
  box-shadow: var(--shadow);
}
.send-btn { background: var(--accent); color: var(--accent-text); }
.send-btn svg, .stop-btn svg { fill: currentColor; }
.send-btn:disabled { opacity: 0.55; cursor: default; }
.stop-btn { background: var(--surface); color: var(--danger); }

.viewer {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.88);
  cursor: zoom-out;
  padding: 16px;
}
.viewer img { max-width: 100%; max-height: 100%; border-radius: 6px; }

.toast {
  position: fixed;
  left: 50%;
  top: calc(70px + env(safe-area-inset-top));
  transform: translateX(-50%);
  padding: 8px 14px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.78);
  color: #fff;
  font-size: 14px;
  z-index: 30;
  max-width: calc(100% - 32px);
}
