:root {
  color-scheme: dark;
  --bg: #0d0f10;
  --panel: #151819;
  --panel-2: #1c2021;
  --line: rgba(255, 255, 255, 0.1);
  --text: #eef2f0;
  --muted: #9ca6a2;
  --soft: #c3cac7;
  --accent: #5ee0a0;
  --accent-strong: #31c77e;
  --danger: #ff7b7b;
  --warning: #e4bd63;
  --shadow: 0 20px 70px rgba(0, 0, 0, 0.42);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

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

body {
  overflow: hidden;
}

button,
input,
textarea {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

button:disabled,
textarea:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.shell {
  width: 100%;
  min-height: var(--app-height, 100dvh);
  max-width: 100vw;
  overflow-x: hidden;
}

.login-view {
  display: grid;
  min-height: var(--app-height, 100dvh);
  place-items: center;
  padding: max(24px, env(safe-area-inset-top)) 24px max(24px, env(safe-area-inset-bottom));
}

.login-view[hidden],
.app-view[hidden] {
  display: none;
}

.brand,
.login-form {
  width: min(420px, 100%);
}

.brand {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 28px;
}

.brand-mark {
  display: grid;
  width: 56px;
  height: 56px;
  place-items: center;
  border: 1px solid rgba(94, 224, 160, 0.35);
  border-radius: 14px;
  background: linear-gradient(145deg, rgba(94, 224, 160, 0.22), rgba(255, 255, 255, 0.04));
  color: var(--accent);
  font-size: 26px;
  font-weight: 800;
}

h1,
h2,
p {
  margin: 0;
}

.brand h1,
.panel-header h1 {
  font-size: 24px;
  font-weight: 760;
}

.brand p,
.panel-header p,
.chat-header p,
.empty-state span,
.thread-preview,
.thread-meta {
  color: var(--muted);
}

.login-form {
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.login-form label {
  display: block;
  margin-bottom: 8px;
  color: var(--soft);
  font-size: 14px;
  font-weight: 650;
}

.login-form input,
.composer textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  outline: none;
  background: #101314;
  color: var(--text);
}

.login-form input {
  height: 48px;
  padding: 0 14px;
}

.login-form input:focus,
.composer textarea:focus {
  border-color: rgba(94, 224, 160, 0.6);
  box-shadow: 0 0 0 3px rgba(94, 224, 160, 0.12);
}

.login-form button,
.composer > button:not(.attach-button) {
  height: 46px;
  border-radius: 12px;
  background: var(--accent);
  color: #07110c;
  font-weight: 760;
}

.login-form button {
  width: 100%;
  margin-top: 14px;
}

.error {
  min-height: 20px;
  margin-top: 12px;
  color: var(--danger);
  font-size: 14px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.app-view {
  display: grid;
  width: 100%;
  height: var(--app-height, 100dvh);
  max-width: 100vw;
  grid-template-columns: 380px 1fr;
  overflow: hidden;
}

.threads-panel,
.chat-panel {
  min-width: 0;
  min-height: 0;
  background: var(--panel);
}

.threads-panel {
  border-right: 1px solid var(--line);
}

.panel-header,
.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 76px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}

.panel-header > div,
.chat-header > div {
  min-width: 0;
}

.panel-header {
  justify-content: space-between;
}

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

.icon-button {
  display: grid;
  width: 40px;
  height: 40px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel-2);
  color: var(--soft);
  font-size: 20px;
}

.icon-button:hover,
.thread-item:hover {
  border-color: rgba(94, 224, 160, 0.34);
  background: #202524;
}

.threads-list {
  height: calc(var(--app-height, 100dvh) - 76px);
  overflow-y: auto;
  overflow-x: hidden;
  padding: 10px;
}

.thread-item {
  width: 100%;
  margin-bottom: 8px;
  padding: 14px;
  border: 1px solid transparent;
  border-radius: 14px;
  background: transparent;
  color: var(--text);
  text-align: left;
}

.thread-item.active {
  border-color: rgba(94, 224, 160, 0.42);
  background: rgba(94, 224, 160, 0.08);
}

.thread-name {
  display: block;
  overflow: hidden;
  color: var(--text);
  font-weight: 720;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.thread-preview {
  display: -webkit-box;
  margin-top: 5px;
  overflow: hidden;
  font-size: 14px;
  line-height: 1.35;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.thread-meta {
  display: block;
  margin-top: 8px;
  font-size: 12px;
}

.chat-panel {
  display: grid;
  grid-template-rows: auto 1fr auto;
}

.back-button {
  display: none;
}

.chat-header h2 {
  overflow: hidden;
  max-width: 70vw;
  font-size: 18px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.messages {
  min-height: 0;
  overflow-y: auto;
  padding: 22px;
}

.empty-state {
  display: grid;
  min-height: 100%;
  place-content: center;
  gap: 8px;
  text-align: center;
}

.message {
  max-width: min(760px, 100%);
  margin: 0 0 14px;
  padding: 13px 15px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel-2);
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.message.user,
.message.assistant {
  position: relative;
  padding-top: 30px;
}

.message.user::before,
.message.assistant::before {
  position: absolute;
  top: 9px;
  font-size: 11px;
  font-weight: 780;
  letter-spacing: 0;
  text-transform: uppercase;
}

.message.user {
  max-width: min(640px, 86%);
  margin-left: auto;
  border-color: rgba(94, 224, 160, 0.48);
  border-bottom-right-radius: 7px;
  background: linear-gradient(145deg, rgba(94, 224, 160, 0.2), rgba(94, 224, 160, 0.08));
  box-shadow: 0 12px 34px rgba(49, 199, 126, 0.08);
  color: #f4fff9;
}

.message.user::before {
  right: 14px;
  color: var(--accent);
  content: "Вы";
}

.message.assistant {
  max-width: min(760px, 92%);
  margin-right: auto;
  border-color: rgba(255, 255, 255, 0.12);
  border-bottom-left-radius: 7px;
  background: #1b1f20;
}

.message.assistant::before {
  left: 14px;
  color: var(--muted);
  content: "Codex";
}

.message.system {
  max-width: 100%;
  border-color: rgba(228, 189, 99, 0.26);
  background: rgba(228, 189, 99, 0.08);
  color: var(--warning);
}

.message.status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 100%;
  padding: 9px 12px;
  border-color: rgba(94, 224, 160, 0.2);
  background: rgba(94, 224, 160, 0.07);
  color: var(--soft);
  font-size: 13px;
}

.message.status::before {
  content: "";
  width: 8px;
  height: 8px;
  flex: 0 0 auto;
  border-radius: 999px;
  background: var(--accent);
  box-shadow: 0 0 0 4px rgba(94, 224, 160, 0.12);
}

.message.status[data-state="thinking"] {
  border-color: rgba(94, 169, 224, 0.28);
  background: rgba(94, 169, 224, 0.08);
  color: #bdd5e7;
}

.message.status[data-state="thinking"]::before {
  background: #6fb7ea;
  box-shadow: 0 0 0 4px rgba(111, 183, 234, 0.12);
  animation: pulse 1.1s ease-in-out infinite;
}

.message.status[data-state="working"]::before {
  animation: pulse 1.1s ease-in-out infinite;
}

.message.status[data-state="working"] {
  border-color: rgba(94, 224, 160, 0.26);
  background: rgba(94, 224, 160, 0.08);
}

.message.status[data-state="done"] {
  border-color: rgba(94, 224, 160, 0.16);
  background: rgba(255, 255, 255, 0.035);
  color: var(--muted);
}

.message.status[data-state="error"] {
  border-color: rgba(255, 123, 123, 0.34);
  background: rgba(255, 123, 123, 0.08);
  color: #ffc4c4;
}

.message.status[data-state="error"]::before {
  background: var(--danger);
  box-shadow: 0 0 0 4px rgba(255, 123, 123, 0.12);
}

@keyframes pulse {
  0%,
  100% {
    opacity: 0.45;
    transform: scale(0.88);
  }
  50% {
    opacity: 1;
    transform: scale(1);
  }
}

.composer {
  position: relative;
  display: grid;
  grid-template-columns: 46px 1fr 126px;
  gap: 10px;
  padding: 14px;
  min-width: 0;
  border-top: 1px solid var(--line);
  background: rgba(13, 15, 16, 0.78);
}

.composer > * {
  min-width: 0;
}

.composer-menu {
  position: absolute;
  right: 14px;
  bottom: calc(100% - 4px);
  left: 14px;
  z-index: 5;
  display: grid;
  max-height: min(320px, 38vh);
  overflow: auto;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(21, 24, 25, 0.98);
  box-shadow: var(--shadow);
}

.composer-menu[hidden],
.attachments-list[hidden] {
  display: none;
}

.composer-menu-item {
  display: grid;
  gap: 3px;
  width: 100%;
  padding: 10px 11px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: var(--text);
  text-align: left;
}

.composer-menu-item:hover,
.composer-menu-item:focus-visible {
  border-color: rgba(94, 224, 160, 0.32);
  background: rgba(94, 224, 160, 0.08);
  outline: none;
}

.composer-menu-item strong {
  font-size: 14px;
  font-weight: 760;
}

.composer-menu-item span {
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attachments-list {
  display: flex;
  grid-column: 1 / -1;
  flex-wrap: wrap;
  gap: 8px;
}

.attachment-chip {
  display: inline-flex;
  align-items: center;
  max-width: 100%;
  gap: 7px;
  padding: 6px 8px 6px 10px;
  border: 1px solid rgba(94, 224, 160, 0.26);
  border-radius: 10px;
  background: rgba(94, 224, 160, 0.08);
  color: var(--soft);
  font-size: 13px;
}

.attachment-chip span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attachment-chip button {
  display: grid;
  width: 22px;
  height: 22px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--muted);
}

.attach-button {
  display: grid;
  width: 46px;
  height: 46px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel-2);
  color: var(--accent);
  font-size: 24px;
  font-weight: 760;
}

.attach-button:hover,
.attach-button:focus-visible {
  border-color: rgba(94, 224, 160, 0.38);
  background: #202524;
  outline: none;
}

.composer textarea {
  min-height: 48px;
  max-height: 150px;
  resize: none;
  padding: 13px 14px;
  line-height: 1.35;
}

@media (max-width: 780px) {
  body {
    overflow: hidden;
  }

  .app-view {
    display: block;
    height: var(--app-height, 100dvh);
  }

  .threads-panel,
  .chat-panel {
    width: 100%;
    height: var(--app-height, 100dvh);
    max-width: 100vw;
    overflow-x: hidden;
  }

  .app-view.thread-open .threads-panel {
    display: none;
  }

  .app-view:not(.thread-open) .chat-panel {
    display: none;
  }

  .back-button {
    display: grid;
  }

  .messages {
    padding: 16px 12px;
  }

  .composer {
    grid-template-columns: 46px 1fr;
    padding: 12px 12px calc(42px + env(safe-area-inset-bottom));
  }

  .attachments-list {
    grid-column: 1 / -1;
    grid-row: 1;
  }

  .attach-button {
    grid-row: 2;
  }

  .composer textarea {
    grid-row: 2;
  }

  .composer > button:not(.attach-button) {
    grid-column: 1 / -1;
    grid-row: 3;
    width: 100%;
  }

  .composer-menu {
    right: 12px;
    left: 12px;
    max-height: min(300px, 34vh);
  }
}
