:root {
  color-scheme: light;
  --bg: #eaf3f6;
  --bg-soft: #f7fbfc;
  --surface: rgba(255, 255, 255, 0.94);
  --surface-strong: #ffffff;
  --surface-muted: #f1f7f9;
  --text: #071525;
  --text-soft: #5b7080;
  --border: #cfdee5;
  --primary: #05758f;
  --primary-hover: #078aa7;
  --primary-dark: #06384f;
  --primary-soft: #d8eef4;
  --accent: #0b2638;
  --assistant: #f0f7fa;
  --user: #d7edf4;
  --danger-bg: #fee2e2;
  --danger-text: #991b1b;
  --shadow: 0 18px 50px rgba(7, 43, 58, 0.12);
  --shadow-soft: 0 10px 30px rgba(7, 43, 58, 0.08);
  --radius-xl: 24px;
  --radius-lg: 18px;
  --radius-md: 14px;
  --transition: 180ms ease;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #101820;
  --bg-soft: #141d26;
  --surface: rgba(27, 35, 45, 0.96);
  --surface-strong: #1f2933;
  --surface-muted: #24313d;
  --text: #f5f7fa;
  --text-soft: #c7d2dc;
  --border: #344554;
  --primary: #0b8ca8;
  --primary-hover: #0ba0c0;
  --primary-dark: #0a5f79;
  --primary-soft: #173746;
  --accent: #e8f3f6;
  --assistant: #24313d;
  --user: #0b5368;
  --danger-bg: #4b1d24;
  --danger-text: #ffd8df;
  --shadow: 0 20px 52px rgba(0, 0, 0, 0.34);
  --shadow-soft: 0 12px 34px rgba(0, 0, 0, 0.24);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  font-family: Arial, sans-serif;
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at top center, rgba(5, 117, 143, 0.18), transparent 34%),
    linear-gradient(180deg, var(--bg-soft) 0%, var(--bg) 100%);
  color: var(--text);
  transition: background-color var(--transition), color var(--transition);
}

:root[data-theme="dark"] body {
  background:
    radial-gradient(circle at top center, rgba(11, 140, 168, 0.16), transparent 36%),
    linear-gradient(180deg, #141d26 0%, #0f171f 100%);
}

.container {
  max-width: 1280px;
  margin: 0 auto;
  padding: 24px;
}

a {
  color: var(--primary);
  text-decoration: none;
  transition: color var(--transition), opacity var(--transition);
}

a:hover { color: var(--primary-hover); }

:root[data-theme="dark"] a { color: #8ad7e8; }
:root[data-theme="dark"] a:hover { color: #b7edf6; }

.auth-card,
.sidebar,
.main {
  background: var(--surface);
  border: 1px solid color-mix(in srgb, var(--border) 84%, transparent);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
  transition: background-color var(--transition), border-color var(--transition), box-shadow var(--transition);
}

.auth-card {
  max-width: 500px;
  margin: 34px auto;
  padding: 28px;
}

.auth-card-login {
  max-width: 620px;
  padding: 34px;
}

.auth-card form {
  display: grid;
  gap: 10px;
  margin-bottom: 12px;
}

.auth-topline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 18px;
}

.version-badge {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  color: var(--text-soft);
  font-size: 12px;
  line-height: 1;
  white-space: nowrap;
}

label {
  font-size: 14px;
  color: var(--text);
  font-weight: 600;
}

input,
textarea,
button {
  font: inherit;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid var(--border);
  transition: border-color var(--transition), box-shadow var(--transition), transform var(--transition), background-color var(--transition), color var(--transition);
}

input,
textarea {
  background: var(--surface-strong);
  color: var(--text);
}

input:focus,
textarea:focus {
  outline: none;
  border-color: rgba(5, 117, 143, 0.52);
  box-shadow: 0 0 0 4px rgba(5, 117, 143, 0.12);
}

button {
  background: linear-gradient(180deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: #fff;
  cursor: pointer;
  border: none;
  font-weight: 700;
  box-shadow: 0 10px 24px rgba(5, 117, 143, 0.22);
}

button:hover {
  transform: translateY(-1px);
  background: linear-gradient(180deg, var(--primary-hover) 0%, var(--primary) 100%);
}

button:disabled {
  opacity: .75;
  cursor: default;
  transform: none;
}

button.secondary {
  background: linear-gradient(180deg, #14526a 0%, #0c3b51 100%);
  box-shadow: 0 10px 24px rgba(12, 59, 81, 0.18);
}

:root[data-theme="dark"] button.secondary {
  background: #eef3f6;
  color: #24313d;
}

.theme-toggle {
  padding: 9px 12px;
  min-height: 34px;
  border: 1px solid var(--border);
  background: var(--surface-muted);
  color: var(--text);
  box-shadow: none;
  font-size: 12px;
  font-weight: 700;
}

.theme-toggle:hover {
  background: var(--primary-soft);
  color: var(--text);
  box-shadow: none;
}

.full-width { width: 100%; }

.error {
  background: var(--danger-bg);
  color: var(--danger-text);
  padding: 10px 12px;
  border-radius: 12px;
  margin-bottom: 12px;
}

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

.sidebar {
  padding: 18px;
}

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

.sidebar-actions {
  display: grid;
  gap: 10px;
}

.sidebar-actions form { margin: 0; }
.sidebar-actions form button { width: 100%; }

.muted {
  color: var(--text-soft);
  font-size: 12px;
}

.muted-link {
  color: var(--text-soft);
  font-size: 12px;
  margin-top: 6px;
}

.muted-link a { color: inherit; }

.chat-list {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.chat-item {
  display: block;
  text-decoration: none;
  color: inherit;
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--surface-muted);
  border: 1px solid transparent;
  transition: transform var(--transition), box-shadow var(--transition), border-color var(--transition), background-color var(--transition);
}

.chat-item:hover {
  transform: translateY(-1px);
  border-color: rgba(5, 117, 143, 0.26);
  box-shadow: var(--shadow-soft);
}

.chat-item.active {
  background: var(--primary-soft);
  border-color: rgba(5, 117, 143, 0.24);
}

.chat-title {
  font-weight: 700;
  margin-bottom: 4px;
}

.main {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: 82vh;
  overflow: hidden;
}

.chat-head {
  padding: 20px 22px;
  border-bottom: 1px solid var(--border);
}

.chat-head h2 {
  margin: 0;
  font-size: 24px;
}

.messages {
  padding: 20px 22px;
  display: grid;
  gap: 14px;
  align-content: start;
  overflow-y: auto;
  max-height: calc(82vh - 164px);
}

.msg {
  padding: 12px 14px;
  border-radius: 16px;
  max-width: 82%;
  box-shadow: var(--shadow-soft);
  animation: msgIn 220ms ease;
}

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

.msg.assistant {
  background: var(--assistant);
}

.msg.pending {
  border: 1px dashed rgba(5, 117, 143, 0.34);
}

.msg.pending .content {
  color: var(--text-soft);
}

.role {
  font-size: 12px;
  color: var(--text-soft);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: .06em;
}

.content {
  line-height: 1.55;
}

.send-form {
  padding: 16px 18px 18px;
  border-top: 1px solid var(--border);
  display: grid;
  gap: 10px;
}

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

textarea {
  resize: vertical;
  min-height: 96px;
}

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

.app-brand h1 {
  margin: 0;
  font-size: 30px;
  line-height: 1.08;
  letter-spacing: .02em;
}

.brand-subtitle {
  margin: 8px 0 0;
  font-size: 14px;
}

.app-brand-login {
  align-items: center;
  margin-bottom: 22px;
}

.app-brand-register {
  margin-bottom: 18px;
}

.app-logo {
  object-fit: cover;
  flex: 0 0 auto;
  border-radius: 22px;
  box-shadow: 0 16px 30px rgba(11, 49, 70, 0.18);
  display: block;
}

.app-logo-sidebar {
  width: 54px !important;
  height: 54px !important;
  border-radius: 16px;
}

.app-logo-login {
  width: 128px !important;
  height: 128px !important;
  border-radius: 28px;
}

.app-logo-register {
  width: 68px !important;
  height: 68px !important;
  border-radius: 18px;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 13px;
  margin-bottom: 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.sidebar-brand-title {
  font-size: 20px;
  font-weight: 800;
  line-height: 1.08;
  letter-spacing: .04em;
}

small { color: var(--text-soft); }

::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}
::-webkit-scrollbar-thumb {
  background: rgba(5, 117, 143, 0.28);
  border-radius: 999px;
}
::-webkit-scrollbar-track { background: transparent; }

@keyframes msgIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 900px) {
  .container { padding: 12px; }
  .layout { grid-template-columns: 1fr; }
  .main { min-height: 70vh; }
  .messages { max-height: none; }
  .msg { max-width: 94%; }
  .chat-head h2 { font-size: 21px; }
  .auth-card { margin: 14px auto; padding: 24px; }
  .auth-card-login { padding: 24px; }
  .app-brand-login {
    align-items: center;
    gap: 14px;
  }
  .app-logo-login {
    width: 108px !important;
    height: 108px !important;
  }
  .app-brand h1 { font-size: 26px; }
  .send-row { align-items: stretch; }
  .send-row button { min-width: 130px; }
}

@media (max-width: 560px) {
  .container { padding: 10px; }
  .auth-topline { align-items: stretch; }
  .app-brand-login {
    flex-direction: row;
  }
  .app-logo-login {
    width: 88px !important;
    height: 88px !important;
    border-radius: 22px;
  }
  .brand-subtitle { font-size: 12px; }
  .layout { gap: 12px; }
  .sidebar, .main, .auth-card { border-radius: 20px; }
  .send-row { flex-direction: row; }
  .version-badge { font-size: 11px; padding-inline: 9px; }
}

/* 0.23.2: mobile drawer */
.mobile-chat-bar,
.mobile-drawer-head,
.drawer-backdrop {
  display: none;
}

.drawer-close,
.drawer-open {
  appearance: none;
  border: 0;
}

.version-in-menu {
  justify-content: center;
}

@media (max-width: 900px) {
  html,
  body {
    min-height: 100%;
    overflow: hidden;
  }

  .container {
    max-width: none;
    width: 100%;
    height: 100dvh;
    padding: 0;
  }

  .layout {
    display: block;
    width: 100%;
    height: 100dvh;
  }

  .main {
    width: 100%;
    height: 100dvh;
    min-height: 100dvh;
    border-radius: 0;
    border: 0;
    box-shadow: none;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    overflow: hidden;
  }

  .mobile-chat-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 58px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
    backdrop-filter: blur(10px);
    position: relative;
    z-index: 2;
  }

  .drawer-open {
    width: 42px;
    height: 38px;
    min-width: 42px;
    padding: 0;
    border-radius: 13px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    line-height: 1;
    background: linear-gradient(180deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: #fff;
    box-shadow: 0 8px 18px rgba(5, 117, 143, 0.20);
  }

  .mobile-chat-title {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 16px;
    font-weight: 800;
    color: var(--text);
  }

  .chat-head {
    display: none;
  }

  .messages {
    min-height: 0;
    max-height: none;
    overflow-y: auto;
    padding: 14px 12px 16px;
    gap: 12px;
    align-content: start;
  }

  .msg {
    max-width: 94%;
    padding: 11px 13px;
    border-radius: 16px;
  }

  .send-form {
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
    gap: 9px;
    background: var(--surface);
    border-top: 1px solid var(--border);
  }

  textarea {
    min-height: 58px;
    max-height: 140px;
    resize: none;
  }

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

  .desktop-version {
    font-size: 11px;
    padding: 6px 9px;
    min-height: 28px;
  }

  #send-button {
    min-width: 116px;
    min-height: 42px;
  }

  .drawer-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: rgba(3, 13, 22, 0.48);
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition);
  }

  body.drawer-opened .drawer-backdrop {
    opacity: 1;
    pointer-events: auto;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 1001;
    width: min(86vw, 360px);
    height: 100dvh;
    padding: 14px;
    border-radius: 0 24px 24px 0;
    transform: translateX(-105%);
    visibility: hidden;
    pointer-events: none;
    overflow-y: auto;
    transition: transform 220ms ease, visibility 220ms ease;
    box-shadow: 24px 0 60px rgba(0, 0, 0, 0.22);
  }

  body.drawer-opened .sidebar {
    transform: translateX(0);
    visibility: visible;
    pointer-events: auto;
  }

  body.drawer-opened {
    overflow: hidden;
  }

  .desktop-sidebar-brand {
    display: none;
  }

  .mobile-drawer-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
    padding-bottom: 12px;
    margin-bottom: 12px;
    border-bottom: 1px solid var(--border);
  }

  .mobile-drawer-head .sidebar-brand {
    border-bottom: 0;
    margin-bottom: 0;
    padding-bottom: 0;
  }

  .drawer-close {
    width: 38px;
    height: 38px;
    min-width: 38px;
    padding: 0;
    border-radius: 13px;
    background: var(--surface-muted);
    color: var(--text);
    box-shadow: none;
    font-size: 26px;
    line-height: 1;
  }

  .drawer-close:hover {
    background: var(--primary-soft);
    color: var(--text);
    box-shadow: none;
  }

  .sidebar-head {
    margin-bottom: 14px;
  }

  .sidebar-actions {
    margin-bottom: 12px;
  }

  .chat-list {
    padding-bottom: 18px;
  }

  .app-logo-sidebar {
    width: 50px !important;
    height: 50px !important;
  }
}

@media (max-width: 560px) {
  .auth-card {
    margin: 14px 10px;
  }

  .msg {
    max-width: 96%;
  }

  .mobile-chat-bar {
    min-height: 56px;
  }

  .mobile-chat-title {
    font-size: 15px;
  }

  .drawer-open {
    width: 40px;
    min-width: 40px;
    height: 38px;
  }

  .desktop-version {
    max-width: 150px;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}
