:root {
  --bg: #ecf2f8;
  --bg-2: #dce8f4;
  --panel: #ffffffcc;
  --panel-solid: #ffffff;
  --line: #d5e0ec;
  --text: #152f45;
  --muted: #60748a;
  --accent: #1da390;
  --accent-strong: #117569;
  --bubble-me: #d7f9eb;
  --bubble-other: #ffffff;
  --danger: #b83333;
  --shadow-soft: 0 10px 30px rgba(15, 37, 58, 0.1);
  --shadow-panel: 0 8px 24px rgba(20, 42, 64, 0.14);
}

body[data-theme="dark"] {
  --bg: #0c131b;
  --bg-2: #111f2c;
  --panel: #142130cc;
  --panel-solid: #17273a;
  --line: #26384d;
  --text: #e2efff;
  --muted: #9db3c8;
  --accent: #2dc7b2;
  --accent-strong: #1ea38f;
  --bubble-me: #1a4f48;
  --bubble-other: #1a2a3b;
  --danger: #ef7a7a;
  --shadow-soft: 0 18px 36px rgba(0, 0, 0, 0.45);
  --shadow-panel: 0 14px 36px rgba(0, 0, 0, 0.5);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100dvh;
}

body {
  font-family: "Segoe UI", "Noto Sans", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 5% 8%, color-mix(in oklab, var(--accent) 12%, transparent), transparent 32%),
    radial-gradient(circle at 95% 90%, color-mix(in oklab, var(--accent) 10%, transparent), transparent 30%),
    linear-gradient(145deg, var(--bg), var(--bg-2));
  overflow: hidden;
  transition: background 220ms ease, color 220ms ease;
}

.auth-screen {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 16px;
}

.auth-card {
  width: min(96vw, 430px);
  background: var(--panel-solid);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 24px;
  display: grid;
  gap: 10px;
  box-shadow: var(--shadow-soft);
}

.auth-card h1 {
  margin: 0;
  font-size: 1.2rem;
}

.auth-card p {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 0.92rem;
}

.auth-card input,
.group-create input,
.db-form input,
.db-form textarea,
.composer input {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 11px;
  color: var(--text);
  background: var(--panel-solid);
}

.db-form textarea {
  resize: vertical;
  min-height: 88px;
  font-family: inherit;
}

.auth-card button,
.composer button,
.db-form button {
  border: 0;
  background: var(--accent);
  color: #fff;
  border-radius: 11px;
  padding: 10px 14px;
  cursor: pointer;
  transition: filter 160ms ease, transform 160ms ease;
}

.auth-card .ghost-btn {
  margin-top: 0;
}

.auth-card button:hover,
.composer button:hover,
.db-form button:hover {
  filter: brightness(1.08);
}

.auth-card button:active,
.composer button:active,
.db-form button:active {
  transform: translateY(1px);
}

.app-shell {
  display: grid;
  grid-template-columns: 290px 1fr 330px;
  height: 100dvh;
  min-height: 0;
}

.left-panel,
.config-panel {
  background: var(--panel);
  backdrop-filter: blur(8px);
  border-right: 1px solid var(--line);
  padding: 16px;
  min-height: 0;
  overflow-y: auto;
}

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

.config-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.config-panel-head h3 {
  margin: 0;
}

.hidden {
  display: none;
}

.left-panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.left-panel-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
  max-width: 56%;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-dot {
  width: 14px;
  height: 14px;
  border-radius: 999px;
  background: linear-gradient(120deg, var(--accent), #63e0cd);
}

.brand h1 {
  margin: 0;
  font-size: 1.1rem;
}

.brand p {
  margin: 0;
  color: var(--muted);
  font-size: 0.84rem;
}

.session-box,
.hint-box {
  margin-top: 16px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: color-mix(in oklab, var(--panel-solid) 92%, transparent);
}

.hint-box p {
  margin: 0 0 8px;
  font-size: 0.85rem;
}

.hint-box p:last-child {
  margin-bottom: 0;
}

code {
  background: color-mix(in oklab, var(--accent) 20%, transparent);
  border-radius: 6px;
  padding: 2px 6px;
}

.ghost-btn {
  margin-top: 12px;
  width: 100%;
  border: 1px solid var(--line);
  background: color-mix(in oklab, var(--panel-solid) 90%, transparent);
  color: var(--text);
  border-radius: 10px;
  padding: 9px 12px;
  cursor: pointer;
  transition: background 160ms ease, border-color 160ms ease;
}

.ghost-btn:hover {
  border-color: color-mix(in oklab, var(--accent) 45%, var(--line));
}

.ghost-btn.inline {
  width: auto;
  margin-top: 0;
}

.icon-btn {
  width: auto;
  min-width: 84px;
  margin-top: 0;
  padding: 8px 10px;
  font-size: 0.82rem;
}

.ghost-btn.active,
.user-item-btn.active,
.conversation-item-btn.active {
  background: color-mix(in oklab, var(--accent) 24%, var(--panel-solid));
  border-color: color-mix(in oklab, var(--accent) 60%, var(--line));
}

.users-list,
.conversations-list,
.profiles-list,
.db-form,
.group-create {
  display: grid;
  gap: 8px;
}

.users-list,
.conversations-list {
  margin-top: 10px;
}

.user-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
}

.user-item-actions {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.user-item-new-btn {
  border: 1px solid var(--line);
  background: color-mix(in oklab, var(--panel-solid) 90%, transparent);
  color: var(--text);
  border-radius: 8px;
  padding: 5px 8px;
  cursor: pointer;
  font-size: 0.76rem;
}

.user-item-btn,
.conversation-item-btn {
  width: 100%;
  text-align: left;
  border: 1px solid var(--line);
  background: color-mix(in oklab, var(--panel-solid) 88%, transparent);
  color: var(--text);
  border-radius: 10px;
  padding: 9px 10px;
  cursor: pointer;
}

.user-item-select {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.group-help {
  margin: 8px 0 0;
  font-size: 0.8rem;
  color: var(--muted);
}

.search-limit-row {
  margin-top: 8px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
}

.search-limit-row label {
  font-size: 0.8rem;
  color: var(--muted);
}

.search-limit-row select {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 8px;
  background: var(--panel-solid);
  color: var(--text);
}

.search-result-item {
  width: 100%;
  text-align: left;
  border: 1px solid var(--line);
  background: color-mix(in oklab, var(--panel-solid) 88%, transparent);
  color: var(--text);
  border-radius: 10px;
  padding: 8px 10px;
  cursor: pointer;
}

.search-result-item strong {
  display: block;
  font-size: 0.9rem;
}

.search-result-item small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.78rem;
}

.chat-panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.chat-header {
  background: var(--panel);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
  padding: 14px 18px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
}

.chat-header-actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.chat-header-mobile {
  display: none;
}

.chat-header h2 {
  margin: 0;
  font-size: 1rem;
}

.chat-header p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.secret-panel {
  margin: 10px 14px 0;
  padding: 10px;
  border: 1px dashed var(--line);
  border-radius: 12px;
  background: color-mix(in oklab, var(--panel-solid) 90%, transparent);
}

.secret-panel label {
  display: block;
  font-size: 0.82rem;
  color: var(--muted);
  margin-bottom: 6px;
}

.secret-panel p {
  margin: 8px 0 0;
  font-size: 0.78rem;
  color: var(--muted);
}

.home-panel {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 16px;
}

.home-panel-card {
  width: min(100%, 960px);
  margin: 0 auto;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: color-mix(in oklab, var(--panel-solid) 93%, transparent);
  box-shadow: var(--shadow-soft);
  padding: 16px;
}

.home-panel-card h3 {
  margin: 0;
  font-size: 1rem;
}

.home-panel-card p {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.home-search-grid {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.home-search-grid input {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 11px;
  color: var(--text);
  background: var(--panel-solid);
}

.home-conversations-list {
  margin-top: 12px;
}

.secret-row {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  gap: 8px;
  align-items: center;
}

.secret-row input {
  min-width: 0;
}

.messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 16px;
}

.history-actions {
  padding: 0 16px 10px;
  display: flex;
  justify-content: center;
}

.slash-menu {
  margin: 0 12px 8px;
  border: 1px solid var(--line);
  background: color-mix(in oklab, var(--panel-solid) 95%, transparent);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: var(--shadow-soft);
  max-height: 220px;
  overflow-y: auto;
}

.slash-item {
  width: 100%;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  padding: 10px 12px;
}

.slash-item:last-child {
  border-bottom: 0;
}

.slash-item strong {
  display: inline-block;
  margin-right: 8px;
}

.slash-item small {
  display: block;
  color: var(--muted);
  margin-top: 4px;
  font-size: 0.78rem;
}

.slash-item.active {
  background: color-mix(in oklab, var(--accent) 22%, var(--panel-solid));
}

.msg {
  max-width: 78%;
  border-radius: 14px;
  padding: 10px 12px;
  margin-bottom: 10px;
  background: var(--bubble-other);
  border: 1px solid var(--line);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.08);
}

.msg.me {
  margin-left: auto;
  background: var(--bubble-me);
}

.msg.system {
  max-width: 100%;
  border-style: dashed;
  color: var(--muted);
}

.msg header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 4px;
  font-size: 0.8rem;
  color: var(--muted);
}

.msg .content {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
}

.msg .continue-btn {
  margin-top: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 5px 8px;
  background: color-mix(in oklab, var(--panel-solid) 90%, transparent);
  color: var(--text);
  cursor: pointer;
  font-size: 0.78rem;
}

.msg.system .continue-btn {
  display: none;
}

.file-attachment {
  display: grid;
  gap: 6px;
}

.file-attachment .file-preview {
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  background: color-mix(in oklab, var(--panel-solid) 90%, transparent);
}

.file-attachment img,
.file-attachment video,
.file-attachment audio {
  width: 100%;
  max-height: 320px;
  display: block;
}

.file-attachment audio {
  max-height: none;
}

.file-attachment .file-meta {
  font-size: 0.8rem;
  color: var(--muted);
}

.file-attachment .download-link {
  display: inline-block;
  width: fit-content;
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 6px 10px;
  text-decoration: none;
  color: var(--text);
  background: color-mix(in oklab, var(--panel-solid) 92%, transparent);
}

.composer {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px;
  border-top: 1px solid var(--line);
  background: var(--panel);
  backdrop-filter: blur(8px);
}

.composer input {
  flex: 1;
  min-width: 0;
  font-size: 0.96rem;
}

.composer .attach-btn {
  margin-top: 0;
  width: auto;
  white-space: nowrap;
  flex-shrink: 0;
}

.composer .mic-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.mic-icon {
  width: 12px;
  height: 15px;
  border: 2px solid currentColor;
  border-radius: 7px;
  display: inline-block;
  position: relative;
}

.mic-icon::before {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -8px;
  width: 2px;
  height: 7px;
  background: currentColor;
  transform: translateX(-50%);
}

.mic-icon::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -12px;
  width: 12px;
  height: 6px;
  border: 2px solid currentColor;
  border-top: 0;
  border-radius: 0 0 10px 10px;
  transform: translateX(-50%);
}

.mic-btn.recording {
  border-color: color-mix(in oklab, var(--danger) 55%, var(--line));
  background: color-mix(in oklab, var(--danger) 16%, var(--panel-solid));
}

.hidden-file-input {
  display: none;
}

.file-action-modal {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: grid;
  place-items: center;
  background: rgba(2, 8, 18, 0.6);
  padding: 16px;
}

.file-action-modal.hidden {
  display: none !important;
}

.file-action-dialog {
  width: min(96vw, 560px);
  background: var(--panel-solid);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow-panel);
  padding: 16px;
  display: grid;
  gap: 12px;
}

.file-action-dialog h3 {
  margin: 0;
  font-size: 1.02rem;
}

.file-action-meta {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.file-action-choices {
  display: grid;
  gap: 9px;
}

.file-action-option {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  cursor: pointer;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px;
  align-items: flex-start;
  background: color-mix(in oklab, var(--panel-solid) 90%, transparent);
  transition: border-color 160ms ease, background 160ms ease;
}

.file-action-option:hover {
  border-color: color-mix(in oklab, var(--accent) 45%, var(--line));
  background: color-mix(in oklab, var(--accent) 10%, var(--panel-solid));
}

.file-action-option:has(input:checked) {
  border-color: color-mix(in oklab, var(--accent) 60%, var(--line));
  background: color-mix(in oklab, var(--accent) 16%, var(--panel-solid));
}

.file-action-option input {
  margin-top: 2px;
}

.file-action-option strong {
  display: block;
}

.file-action-option small {
  display: block;
  color: var(--muted);
  margin-top: 3px;
}

.file-action-buttons {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.profile-item button {
  margin-top: 6px;
  border: 0;
  border-radius: 8px;
  padding: 7px 10px;
  cursor: pointer;
}

.profile-item .active {
  background: color-mix(in oklab, var(--accent) 24%, var(--panel-solid));
  color: var(--text);
}

.settings-block {
  margin-top: 14px;
}

.settings-actions {
  display: grid;
  gap: 8px;
}

.settings-check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.84rem;
  color: var(--muted);
}

.settings-check input {
  accent-color: var(--accent);
}

.danger-zone {
  border: 1px solid color-mix(in oklab, var(--danger) 40%, var(--line));
  border-radius: 12px;
  padding: 10px;
  background: color-mix(in oklab, var(--danger) 8%, var(--panel-solid));
}

#deleteDataBtn {
  background: var(--danger);
}

.mobile-only {
  display: none;
}

.mobile-menu-overlay {
  display: none;
}

.mobile-menu-overlay.hidden {
  display: none;
}

@media (max-width: 1200px) {
  .app-shell {
    grid-template-columns: 260px 1fr;
  }

  .config-panel {
    position: fixed;
    right: 0;
    top: 0;
    bottom: 0;
    width: min(88vw, 360px);
    z-index: 45;
    box-shadow: var(--shadow-panel);
  }
}

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

  .app-shell {
    grid-template-columns: 1fr;
    height: 100dvh;
  }

  .left-panel {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: min(88vw, 360px);
    z-index: 50;
    transform: translateX(-102%);
    transition: transform 220ms ease;
    box-shadow: var(--shadow-panel);
    border-right: 1px solid var(--line);
  }

  .app-shell.menu-open .left-panel {
    transform: translateX(0);
  }

  .mobile-menu-overlay {
    position: fixed;
    inset: 0;
    z-index: 40;
    display: block;
    background: rgba(2, 9, 18, 0.55);
  }

  .mobile-menu-overlay.hidden {
    display: none;
  }

  .chat-panel {
    height: 100dvh;
    min-height: 100dvh;
  }

  .chat-header {
    grid-template-columns: 1fr;
    gap: 8px;
    padding-top: 10px;
  }

  .chat-header-actions {
    justify-content: flex-start;
  }

  .chat-header-mobile {
    display: flex;
    gap: 8px;
    justify-content: space-between;
  }

  .mobile-only {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .icon-btn.mobile-only {
    min-width: 72px;
  }

  .messages {
    padding: 12px;
  }

  .home-panel {
    padding: 12px;
  }

  .home-panel-card {
    padding: 12px;
  }

  .history-actions {
    padding: 0 12px 8px;
  }

  .msg {
    max-width: 94%;
  }

  .composer {
    display: grid;
    grid-template-columns: auto auto minmax(0, 1fr) auto;
    align-items: center;
    padding: 10px;
    gap: 8px;
  }

  .composer .attach-btn,
  .composer .mic-btn {
    min-width: 42px;
    min-height: 42px;
    padding: 8px 10px;
    justify-content: center;
  }

  .composer .mic-label {
    display: none;
  }

  .secret-row {
    grid-template-columns: 1fr 1fr;
  }

  .composer button {
    padding: 10px 12px;
  }

  .config-panel {
    width: min(94vw, 380px);
  }

  .file-action-dialog {
    width: min(96vw, 640px);
  }
}
