:root {
  color-scheme: dark;
  --bg: oklch(0.155 0.012 215);
  --panel: oklch(0.19 0.014 215);
  --panel-2: oklch(0.235 0.016 215);
  --line: oklch(0.35 0.018 215 / 0.5);
  --ink: oklch(0.95 0.01 215);
  --muted: oklch(0.72 0.018 215);
  --accent: oklch(0.72 0.14 158);
  --accent-strong: oklch(0.78 0.16 158);
  --user: oklch(0.37 0.085 165);
  --assistant: oklch(0.255 0.02 225);
  --danger: oklch(0.68 0.18 28);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  direction: rtl;
  font-family: "Segoe UI", Tahoma, Arial, system-ui, sans-serif;
}

button, .message-input { font: inherit; }

.shell {
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100dvh;
  max-width: 920px;
  margin: 0 auto;
  background: var(--panel);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 52px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
}

.status {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 0.85rem;
}

.status.online { color: var(--accent-strong); }
.status.error { color: var(--danger); }

.tabs {
  display: flex;
  flex: 1 1 auto;
  gap: 8px;
  min-width: 0;
  overflow-x: auto;
  padding: 0 0 2px;
  scrollbar-width: none;
}

.tabs::-webkit-scrollbar {
  display: none;
}

.tabs-list {
  display: flex;
  gap: 8px;
}

.tab {
  min-height: 34px;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
}

.tab.active {
  background: var(--accent);
  color: oklch(0.14 0.02 158);
  border-color: transparent;
  font-weight: 800;
}

.add-tab {
  min-width: 36px;
  padding: 0;
  font-size: 1.25rem;
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
  padding: 18px;
}

.bubble {
  max-width: min(82%, 70ch);
  padding: 12px 14px;
  border-radius: 18px;
  line-height: 1.75;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  box-shadow: 0 1px 0 oklch(1 0 0 / 0.04) inset;
}

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

.bubble.assistant,
.bubble.system {
  align-self: flex-end;
  background: var(--assistant);
}

.bubble.rtl {
  direction: rtl;
  text-align: right;
}

.bubble.ltr {
  direction: ltr;
  text-align: left;
}

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

.bubble a {
  color: var(--accent-strong);
  text-decoration-thickness: 1px;
  text-underline-offset: 4px;
}

.composer {
  display: grid;
  grid-template-columns: 54px 54px 54px 1fr auto;
  gap: 10px;
  padding: 14px;
  border-top: 1px solid var(--line);
  background: oklch(0.17 0.013 215);
}

.composer button,
.composer .message-input {
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--ink);
  border-radius: 16px;
}

.composer button {
  min-height: 54px;
  cursor: pointer;
  transition: background 180ms ease, border-color 180ms ease, transform 180ms ease;
}

.composer button:hover {
  background: oklch(0.28 0.018 215);
}

.composer button:active {
  transform: translateY(1px);
}

.icon-btn {
  display: grid;
  place-items: center;
  padding: 0;
}

.icon-btn svg {
  width: 25px;
  height: 25px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.composer button:focus-visible,
.composer .message-input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

#voiceBtn.recording {
  color: var(--danger);
  border-color: var(--danger);
  background: oklch(0.25 0.08 28);
}

#sendBtn {
  min-width: 82px;
  background: var(--accent);
  color: oklch(0.14 0.02 158);
  font-weight: 800;
}

.message-input {
  min-height: 54px;
  max-height: 160px;
  overflow-y: auto;
  padding: 14px 16px;
  direction: rtl;
  text-align: right;
}

.message-input:empty::before {
  content: attr(data-placeholder);
  color: oklch(0.62 0.014 215);
  pointer-events: none;
}

@media (max-width: 560px) {
  .shell { max-width: none; }

  .topbar {
    padding: 8px 10px;
  }

  .messages {
    padding: 14px;
  }

  .composer {
    grid-template-columns: 56px 1fr 78px;
    grid-template-areas:
      "attach voice camera"
      "text text send";
    align-items: center;
    gap: 12px;
    padding: 16px 14px 14px;
  }

  #attachBtn,
  #cameraBtn {
    width: 56px;
    height: 56px;
    border-radius: 18px;
    background: oklch(0.24 0.016 215);
  }

  #attachBtn { grid-area: attach; justify-self: end; }
  #cameraBtn { grid-area: camera; justify-self: start; }

  #attachBtn svg,
  #cameraBtn svg {
    width: 29px;
    height: 29px;
  }

  #voiceBtn {
    grid-area: voice;
    width: 88px;
    height: 88px;
    border-radius: 999px;
    justify-self: center;
    background: var(--accent);
    color: oklch(0.13 0.018 158);
    border-color: oklch(0.82 0.12 158 / 0.35);
    box-shadow: 0 10px 28px oklch(0.08 0.03 160 / 0.45);
  }

  #voiceBtn svg {
    width: 38px;
    height: 38px;
    stroke-width: 2.25;
  }

  #textInput {
    grid-area: text;
    min-width: 0;
  }

  #sendBtn {
    grid-area: send;
    min-width: 78px;
  }

  .bubble {
    max-width: 92%;
    border-radius: 17px;
  }
}
