:root {
  color-scheme: dark;
  --bg: #111316;
  --panel: #191d22;
  --panel-2: #20262d;
  --text: #edf1f5;
  --muted: #9aa5b1;
  --line: #303842;
  --accent: #7dd3fc;
  --accent-2: #f7c948;
  --danger: #fb7185;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  width: 100%;
}

body {
  margin: 0;
  min-height: 100dvh;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  padding: 0 16px;
  background: var(--accent);
  color: #061018;
  font-weight: 700;
  cursor: pointer;
}

a {
  color: inherit;
  text-decoration: none;
}

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

.ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--line);
}

.shell {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  width: 100%;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 28px;
  padding: 28px;
  min-height: 0;
  overflow: hidden;
  border-right: 1px solid var(--line);
  background: #15191e;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent-2);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  font-size: 30px;
  line-height: 1.1;
}

h2 {
  margin-bottom: 0;
  font-size: 24px;
}

h3 {
  font-size: 18px;
}

.user-box {
  min-height: 84px;
  color: var(--muted);
}

.user-box strong {
  display: block;
  color: var(--text);
}

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

.nav-btn {
  width: 100%;
  justify-content: flex-start;
  background: transparent;
  color: var(--muted);
  border: 1px solid transparent;
  text-align: left;
}

.nav-btn.active {
  color: var(--text);
  border-color: var(--line);
  background: var(--panel-2);
}

.chat-list-panel {
  min-height: 0;
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr);
  gap: 10px;
}

.chat-list-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.chat-list-head .eyebrow {
  margin: 0;
}

.chat-head-actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.small-btn {
  min-height: 34px;
  padding: 0 10px;
  font-size: 13px;
}

.small-btn.active {
  border-color: var(--accent);
  color: var(--accent);
}

.search-box {
  position: relative;
  display: grid;
  gap: 8px;
}

.search-box input {
  height: 40px;
  padding: 0 10px;
  font-size: 14px;
}

.search-results {
  display: grid;
  gap: 6px;
  max-height: 220px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px;
  background: #12161b;
}

.search-result {
  display: grid;
  gap: 4px;
  min-height: 0;
  padding: 8px;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  text-align: left;
}

.search-result:hover,
.search-result:focus {
  background: var(--panel-2);
  color: var(--text);
}

.search-result strong,
.search-result span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.search-result span,
.search-empty {
  color: var(--muted);
  font-size: 12px;
}

.archive-panel {
  min-height: 0;
  max-height: 260px;
  overflow: hidden;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #12161b;
}

.archive-head,
.archive-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.archive-head strong {
  font-size: 14px;
}

.archive-list {
  min-height: 0;
  overflow: auto;
  display: grid;
  align-content: start;
  gap: 8px;
}

.archive-row {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  background: var(--panel);
}

.archive-row > div {
  min-width: 0;
  display: grid;
  gap: 3px;
}

.archive-row strong,
.archive-row span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.archive-row span {
  color: var(--muted);
  font-size: 12px;
}

.archive-restore {
  display: grid;
  place-items: center;
  width: 34px;
  min-height: 34px;
  padding: 0;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 34px;
  min-height: 34px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  color: var(--text);
  font-size: 22px;
  line-height: 1;
}

.chat-list {
  min-height: 0;
  overflow: auto;
  display: grid;
  align-content: start;
  gap: 8px;
  padding-right: 2px;
}

.chat-list-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 58px;
  padding: 6px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  text-align: left;
}

.chat-list-item.active {
  border-color: var(--line);
  background: var(--panel-2);
  color: var(--text);
}

.chat-open {
  display: grid;
  gap: 4px;
  min-width: 0;
  min-height: 46px;
  padding: 4px 6px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: inherit;
  text-align: left;
}

.chat-actions {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.chat-rename {
  display: grid;
  place-items: center;
  width: 34px;
  min-height: 34px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 18px;
  line-height: 1;
}

.chat-archive {
  display: grid;
  place-items: center;
  width: 34px;
  min-height: 34px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 18px;
  line-height: 1;
}

.chat-rename:hover,
.chat-rename:focus,
.chat-archive:hover,
.chat-archive:focus {
  border-color: var(--line);
  color: var(--text);
  background: #15191e;
}

.chat-archive:hover,
.chat-archive:focus {
  color: var(--danger);
}

.chat-rename-form {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 6px;
}

.chat-title-input {
  height: 42px;
  min-width: 0;
  padding: 0 10px;
}

.chat-rename-save,
.chat-rename-cancel {
  display: grid;
  place-items: center;
  width: 34px;
  min-height: 34px;
  padding: 0;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
}

.chat-rename-cancel {
  background: transparent;
  color: var(--muted);
}

.chat-list-item span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-list-item small {
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.panel {
  min-width: 0;
  min-height: 0;
  height: 100%;
  overflow: hidden;
  padding: 28px;
}

.hidden {
  display: none !important;
}

.auth-panel {
  display: grid;
  place-items: center;
}

.access-panel {
  overflow-x: hidden;
  overflow-y: auto;
  padding-bottom: 48px;
}

.auth-card,
.tool-card {
  width: min(100%, 460px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 24px;
}

form {
  display: grid;
  gap: 14px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 14px;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0d1014;
  color: var(--text);
  padding: 12px 14px;
  outline: none;
}

input[type="file"] {
  display: none;
}

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
}

.row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.error {
  min-height: 22px;
  color: var(--danger);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}

.topbar-actions {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.button-link {
  display: inline-grid;
  place-items: center;
  min-height: 42px;
  border-radius: 8px;
  padding: 0 16px;
  font-weight: 700;
}

.button-link.disabled {
  pointer-events: none;
  opacity: 0.55;
}

.chat-panel {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-height: 100%;
  min-height: 0;
}

.files-panel {
  min-height: 0;
  max-height: 210px;
  overflow: hidden;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 10px;
  margin-bottom: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--panel);
}

.files-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.files-list {
  min-height: 0;
  overflow: auto;
  display: grid;
  align-content: start;
  gap: 8px;
}

.file-row {
  display: grid;
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 10px;
  background: #12161b;
}

.file-row:hover,
.file-row:focus {
  border-color: var(--accent);
}

.file-row strong,
.file-row span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-row span,
.empty-state {
  color: var(--muted);
  font-size: 13px;
}

.message-area {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr);
  overflow: hidden;
}

.messages {
  min-height: 0;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-right: 6px;
  padding-bottom: 72px;
}

.message {
  max-width: 860px;
  min-width: min(100%, 280px);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px 16px;
  background: var(--panel);
  overflow-wrap: anywhere;
}

.message-content {
  display: grid;
  gap: 10px;
  white-space: normal;
}

.message-content p,
.message-content ul,
.message-content pre,
.message-content blockquote,
.message-content h4 {
  margin: 0;
}

.message-content ul {
  padding-left: 22px;
}

.message-content li + li {
  margin-top: 4px;
}

.message-content a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.message-content code {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 1px 5px;
  background: #0d1014;
  color: var(--text);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.92em;
}

.message-content pre {
  max-width: 100%;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #0d1014;
}

.message-content pre code {
  border: 0;
  padding: 0;
  background: transparent;
}

.message-content blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 10px;
  color: var(--muted);
}

.message-content h4 {
  font-size: 15px;
  line-height: 1.35;
}

.message.user {
  align-self: flex-end;
  background: #10202a;
  border-color: #22536a;
}

.message-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.message small {
  display: block;
  color: var(--muted);
}

.copy-message {
  min-height: 28px;
  flex: 0 0 auto;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.agent-status {
  position: absolute;
  left: 0;
  bottom: 0;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 14px;
  background: rgba(25, 29, 34, 0.96);
  color: var(--muted);
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.22);
}

.typing-dots {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.typing-dots i {
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: var(--accent);
  animation: typing-pulse 1s infinite ease-in-out;
}

.typing-dots i:nth-child(2) {
  animation-delay: 0.15s;
}

.typing-dots i:nth-child(3) {
  animation-delay: 0.3s;
}

.jump-bottom {
  position: absolute;
  right: 12px;
  bottom: 10px;
  display: grid;
  place-items: center;
  width: 42px;
  min-height: 42px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--text);
  z-index: 2;
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.24);
}

@keyframes typing-pulse {
  0%,
  80%,
  100% {
    opacity: 0.35;
    transform: translateY(0);
  }

  40% {
    opacity: 1;
    transform: translateY(-3px);
  }
}

.composer {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: end;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  margin-top: 20px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0;
}

.composer.dragging {
  border-color: var(--accent);
  background: rgba(125, 211, 252, 0.08);
}

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

.file-pick {
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 42px;
  border-radius: 8px;
  padding: 0 14px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}

.composer textarea {
  min-width: 0;
  max-width: 100%;
}

.composer button,
.composer .file-pick {
  max-width: 100%;
  white-space: nowrap;
}

.file-chip {
  display: inline-flex;
  align-items: center;
  max-width: min(100%, 360px);
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 9px;
  background: #12161b;
  color: var(--muted);
  font-size: 13px;
}

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

.file-chip button {
  display: grid;
  place-items: center;
  width: 24px;
  min-height: 24px;
  padding: 0;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
}

.attachment-list {
  display: grid;
  gap: 6px;
  margin-top: 10px;
}

.attachment-item {
  width: fit-content;
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 9px;
  background: #12161b;
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.access-grid {
  display: grid;
  grid-template-columns: minmax(240px, 320px) minmax(0, 1fr);
  gap: 16px;
}

.tool-card {
  width: auto;
}

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

.list-item {
  display: grid;
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #12161b;
}

.user-admin {
  grid-template-columns: minmax(0, 1fr);
  align-items: start;
  gap: 12px;
}

.sessions-card {
  grid-column: 1 / -1;
}

.user-admin > div:first-child,
.session-admin > div:first-child {
  min-width: 0;
  display: grid;
  gap: 4px;
}

.user-admin strong,
.user-admin span,
.session-admin strong,
.session-admin span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.session-admin {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
}

.expired-session {
  opacity: 0.64;
}

.online-dot {
  display: inline-grid;
  place-items: center;
  min-height: 22px;
  margin-left: 6px;
  border: 1px solid rgba(125, 211, 252, 0.5);
  border-radius: 999px;
  padding: 0 8px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
}

.disabled-user {
  opacity: 0.68;
}

.user-actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-start;
  min-width: 0;
}

.user-actions select {
  width: 130px;
  height: 38px;
  padding: 0 10px;
}

.user-actions button {
  min-height: 38px;
  padding: 0 10px;
  font-size: 13px;
}

.mono {
  overflow-wrap: anywhere;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color: var(--accent);
}

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

  .shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr);
    height: 100dvh;
    min-height: 0;
    overflow: hidden;
  }

  .sidebar {
    gap: 12px;
    max-height: 34dvh;
    padding: 14px;
    overflow: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .sidebar h1 {
    margin-bottom: 0;
    font-size: 24px;
  }

  .user-box {
    min-height: 0;
  }

  .chat-list-panel {
    min-height: 140px;
  }

  .panel {
    overflow: hidden;
    padding: 18px;
  }

  .access-panel {
    overflow-x: hidden;
    overflow-y: auto;
    padding-bottom: max(48px, calc(18px + env(safe-area-inset-bottom)));
  }

  .chat-panel {
    height: 100%;
    max-height: 100%;
    min-height: 0;
  }

  .topbar {
    margin-bottom: 12px;
  }

  .topbar {
    align-items: flex-start;
  }

  .topbar-actions {
    justify-content: flex-start;
  }

  .composer,
  .access-grid,
  .user-admin,
  .session-admin {
    grid-template-columns: 1fr;
  }

  .user-actions {
    justify-content: flex-start;
  }

  .composer {
    margin-top: 10px;
    padding-bottom: max(0px, env(safe-area-inset-bottom));
  }
}

@media (max-width: 560px) {
  .sidebar,
  .panel {
    padding: 14px;
  }

  .topbar {
    flex-direction: column;
    gap: 10px;
  }

  .topbar-actions {
    width: 100%;
  }

  .topbar-actions > * {
    flex: 1 1 auto;
  }

  .composer {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px;
  }

  .composer textarea {
    grid-column: 1 / -1;
    grid-row: 1;
    min-height: 76px;
    max-height: 34dvh;
  }

  .file-pick {
    grid-column: 1;
    grid-row: 2;
    width: 100%;
  }

  #sendBtn {
    grid-column: 2;
    grid-row: 2;
    padding: 0 12px;
  }
}
