:root {
  color-scheme: light;
  --app-height: 100dvh;
  --app-offset-top: 0px;
  --bg: #f7f9fb;
  --surface: #ffffff;
  --surface-soft: #f2f4f6;
  --surface-softest: #eceef0;
  --line: #dfe5ef;
  --line-strong: #c7d3e2;
  --text: #191c1e;
  --muted: #69758a;
  --primary: #2563eb;
  --primary-strong: #004ac6;
  --primary-soft: #dbe7ff;
  --primary-softest: #edf3ff;
  --shadow: 0 20px 40px rgba(25, 28, 30, 0.08);
  --radius: 24px;
  --font-heading: "Manrope", sans-serif;
  --font-body: "Inter", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
}

body {
  min-height: 100vh;
}

body[data-mobile-view="desktop"],
body[data-mobile-view="list"],
body[data-mobile-view="chat"] {
  height: var(--app-height);
  overflow: hidden;
}

button, input, textarea {
  font: inherit;
}

.hidden { display: none !important; }

.app-shell {
  min-height: var(--app-height);
}

#chat-view.app-shell {
  height: var(--app-height);
  overflow: hidden;
}

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  overflow: hidden;
  position: relative;
  padding: 32px;
  background:
    radial-gradient(circle at top left, rgba(37, 99, 235, 0.12), transparent 30%),
    radial-gradient(circle at bottom right, rgba(37, 99, 235, 0.08), transparent 28%),
    var(--bg);
}

.login-aurora {
  position: absolute;
  width: 38vw;
  height: 38vw;
  max-width: 520px;
  max-height: 520px;
  border-radius: 999px;
  filter: blur(90px);
  pointer-events: none;
  opacity: 0.7;
}

.login-aurora-left {
  top: -10%;
  left: -8%;
  background: rgba(37, 99, 235, 0.12);
}

.login-aurora-right {
  right: -8%;
  bottom: -10%;
  background: rgba(106, 30, 219, 0.08);
}

.login-panel {
  position: relative;
  width: min(100%, 480px);
  padding: 40px;
  border-radius: 32px;
  background: rgba(255,255,255,0.88);
  backdrop-filter: blur(14px);
  box-shadow: var(--shadow);
  border: 1px solid rgba(199, 211, 226, 0.55);
}

.brand-block {
  text-align: center;
  margin-bottom: 28px;
}

.brand-logo-login {
  width: min(100%, 260px);
  display: block;
  margin: 0 auto 14px;
}

.brand-block h1 {
  font-family: var(--font-heading);
  font-size: 2rem;
  line-height: 1.05;
  margin: 0 0 8px;
}

.subtitle {
  color: var(--muted);
  margin: 0;
}

.login-form {
  display: grid;
  gap: 12px;
}

.label {
  font-size: 0.82rem;
  color: var(--muted);
  font-weight: 700;
}

input, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 14px 16px;
  outline: none;
  background: #fff;
  color: var(--text);
  transition: border-color .2s ease, box-shadow .2s ease, background .2s ease;
}

input:focus, textarea:focus {
  border-color: rgba(37, 99, 235, 0.75);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.12);
}

button {
  border: 0;
  border-radius: 18px;
  cursor: pointer;
  transition: transform .18s ease, background .18s ease, box-shadow .18s ease;
}

button:active { transform: scale(0.98); }

.primary-button {
  background: linear-gradient(135deg, var(--primary-strong), var(--primary));
  color: white;
  box-shadow: 0 12px 22px rgba(37, 99, 235, 0.18);
}

.secondary-button {
  background: var(--primary-softest);
  color: var(--primary-strong);
}

.login-submit {
  margin-top: 6px;
  padding: 15px 18px;
  font-weight: 700;
}

.security-note {
  margin-top: 20px;
  border-radius: 18px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 0.92rem;
  padding: 14px 16px;
  display: flex;
  gap: 10px;
  align-items: center;
}

.workspace {
  height: var(--app-height);
  min-height: var(--app-height);
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  overflow: hidden;
}

.sidebar-shell {
  background: var(--surface);
  border-right: 1px solid rgba(223, 229, 239, 0.9);
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: var(--app-height);
  min-width: 0;
  overflow: hidden;
}

.sidebar-top {
  padding: 18px 18px 16px;
  display: grid;
  gap: 16px;
  border-bottom: 1px solid rgba(223, 229, 239, 0.9);
}

.workspace-brand {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  min-height: 64px;
}

.brand-logo-side {
  width: 144px;
  max-width: 100%;
}

.workspace-user {
  display: grid;
  gap: 14px;
  background: rgba(255,255,255,0.72);
  border: 1px solid rgba(223, 229, 239, 0.9);
  border-radius: 24px;
  padding: 14px;
}

.workspace-user-main {
  display: flex;
  align-items: center;
  gap: 12px;
}

.workspace-user-actions {
  display: grid;
  gap: 12px;
}

.workspace-rail-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.user-badge-avatar,
.chat-topbar-avatar,
.sidebar-item-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-heading);
  font-weight: 800;
  color: var(--primary-strong);
  background: linear-gradient(180deg, #ffffff, #e8efff);
  border: 1px solid rgba(37, 99, 235, 0.18);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.9);
}

.user-badge-avatar,
.chat-topbar-avatar {
  width: 44px;
  height: 44px;
  border-radius: 14px;
}

.workspace-user-copy {
  min-width: 0;
  display: grid;
}

.workspace-user-copy strong {
  font-family: var(--font-heading);
  font-size: .98rem;
}

.workspace-user-copy span {
  color: var(--muted);
  font-size: .78rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.rail-icon-button {
  width: 52px;
  height: 52px;
  padding: 0;
  border-radius: 18px;
  font-size: 1.3rem;
  background: #fff;
  border: 1px solid var(--line);
  flex: 0 0 auto;
}

.rail-icon-button.muted {
  opacity: 0.58;
}

.rail-logout {
  padding: 13px 16px;
  font-weight: 700;
  text-align: center;
  width: 100%;
}

.search-section {
  display: grid;
  gap: 10px;
}

.panel-header,
.section-heading {
  display: grid;
  gap: 6px;
}

.panel-header h2,
.section-heading h2 {
  margin: 0;
  font-family: var(--font-heading);
  font-size: 1.2rem;
}

.conversation-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 12px;
  min-height: 0;
  flex: 1;
  padding: 18px;
  overflow: hidden;
}

.sidebar-list {
  display: grid;
  gap: 8px;
  overflow-y: auto;
  min-height: 0;
  padding-right: 4px;
  overscroll-behavior: contain;
}

.search-results {
  max-height: 220px;
  overflow-y: auto;
}

.sidebar-item {
  width: 100%;
  text-align: left;
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 22px;
}

.sidebar-item:hover {
  background: rgba(236, 238, 240, 0.72);
}

.sidebar-item.active {
  background: var(--primary-softest);
  border-color: rgba(37, 99, 235, 0.12);
}

.sidebar-item-avatar {
  width: 48px;
  height: 48px;
  border-radius: 16px;
  font-size: .95rem;
}

.sidebar-item-content {
  display: grid;
  min-width: 0;
}

.sidebar-item-title {
  font-family: var(--font-heading);
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-item-subtitle,
.sidebar-empty {
  color: var(--muted);
  font-size: .84rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-empty {
  padding: 12px;
  border-radius: 18px;
  background: rgba(236, 238, 240, 0.6);
}

.chat-panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  height: var(--app-height);
  overflow: hidden;
  background:
    radial-gradient(circle at top right, rgba(37,99,235,0.06), transparent 22%),
    var(--bg);
}

.chat-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 24px 32px 18px;
  background: rgba(247, 249, 251, 0.8);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(223, 229, 239, 0.75);
}

.chat-topbar-left {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.chat-topbar h1 {
  margin: 0 0 4px;
  font-family: var(--font-heading);
  font-size: 1.35rem;
}

.chat-topbar .subtitle {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mobile-back-button {
  display: none;
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 12px;
  background: #fff;
  border: 1px solid var(--line);
  flex: 0 0 auto;
}

.error {
  color: #ba1a1a;
  padding: 0 32px;
}

.empty-state {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  place-items: center;
  margin: 24px 32px;
  background: rgba(255,255,255,0.74);
  border-radius: 32px;
  border: 1px dashed var(--line-strong);
  color: var(--muted);
  text-align: center;
  padding: 24px;
}

.messages {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 28px 32px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overscroll-behavior: contain;
  overflow-anchor: none;
  -webkit-overflow-scrolling: touch;
}

.message {
  display: flex;
  max-width: min(720px, 82%);
}

.message.other { align-self: flex-start; }
.message.own { align-self: flex-end; }

.message-bubble {
  width: 100%;
  padding: 14px 16px;
  border-radius: 20px;
  background: rgba(255,255,255,0.9);
  border: 1px solid var(--line);
  box-shadow: 0 8px 18px rgba(17, 28, 45, 0.04);
}

.message.own .message-bubble {
  background: linear-gradient(135deg, var(--primary-strong), var(--primary));
  color: white;
  border-color: transparent;
  box-shadow: 0 14px 24px rgba(37, 99, 235, 0.18);
}

.message-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
  font-size: .78rem;
  color: var(--muted);
}

.message.own .message-meta {
  color: rgba(255,255,255,0.8);
}

.message-text {
  margin: 0;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

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

.message-reactions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 34px;
}

.reaction-button,
.reaction-option,
.reaction-trigger {
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.95);
  color: var(--text);
  min-height: 34px;
}

.reaction-button,
.reaction-option {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 10px;
  font-size: .9rem;
}

.reaction-button.active,
.reaction-option.active {
  background: var(--primary-soft);
  border-color: rgba(37, 99, 235, 0.18);
}

.reaction-trigger {
  width: 34px;
  height: 34px;
  padding: 0;
}

.reaction-picker-holder {
  position: relative;
  display: flex;
  align-items: center;
}

.reaction-picker {
  position: absolute;
  right: 0;
  bottom: calc(100% + 8px);
  display: none;
  background: rgba(255,255,255,0.98);
  border: 1px solid var(--line);
  border-radius: 999px;
  box-shadow: 0 18px 30px rgba(17, 28, 45, 0.12);
  padding: 8px;
  gap: 8px;
  z-index: 5;
}

.message:hover .reaction-picker,
.reaction-picker-holder:hover .reaction-picker,
.reaction-picker:focus-within {
  display: flex;
}

.composer {
  margin: 0 32px 30px;
  background: rgba(255,255,255,0.92);
  border: 1px solid var(--line);
  box-shadow: 0 16px 28px rgba(17, 28, 45, 0.07);
  border-radius: 30px;
  padding: 12px;
  display: grid;
  gap: 10px;
}

#message-input {
  resize: none;
  min-height: 56px;
  border: 0;
  background: transparent;
  box-shadow: none;
  padding: 10px 12px;
}

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

.composer-send {
  padding: 12px 20px;
  font-weight: 700;
}

::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-thumb {
  background: #cdd6e3;
  border-radius: 999px;
}

@media (max-width: 1180px) {
  .workspace {
    grid-template-columns: 320px minmax(0, 1fr);
  }

  .brand-logo-side {
    width: 128px;
  }
}

@media (max-width: 820px) {
  .workspace {
    display: block;
    height: calc(var(--app-height) + var(--app-offset-top));
    min-height: calc(var(--app-height) + var(--app-offset-top));
    transition: none !important;
  }

  .sidebar-shell,
  .chat-panel {
    height: calc(var(--app-height) + var(--app-offset-top));
    min-height: 0;
    transition: none !important;
  }

  #chat-view.app-shell {
    position: fixed;
    inset: 0;
    width: 100%;
    height: calc(var(--app-height) + var(--app-offset-top));
    padding-top: 0;
    overflow: hidden;
    overscroll-behavior: none;
    transition: none !important;
  }

  .chat-topbar,
  .messages,
  .composer,
  .error {
    margin-left: 16px;
    margin-right: 16px;
    padding-left: 0;
    padding-right: 0;
    transition: none !important;
  }

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

  body[data-mobile-view="list"] .chat-panel {
    display: none;
  }

  body[data-mobile-view="chat"] .sidebar-shell {
    display: none;
  }

  .chat-topbar {
    padding: 20px 0 14px;
  }

  .messages {
    padding: 18px 0;
  }

  .composer {
    margin-bottom: 16px;
  }

  .message {
    max-width: 100%;
  }

  .login-panel {
    padding: 28px;
  }
}

@media (max-width: 520px) {
  .sidebar-top {
    padding: 16px;
  }

  .workspace-user-actions,
  .workspace-rail-actions,
  .composer-actions {
    grid-template-columns: 1fr;
    flex-direction: column;
    align-items: stretch;
  }

  .rail-icon-button {
    width: 100%;
    height: 46px;
  }

  .chat-topbar h1 {
    font-size: 1.15rem;
  }

  .empty-state {
    margin: 18px 16px;
  }
}
