:root {
  --paper: #f7f4ef;
  --paper-deep: #eee8df;
  --ink: #26231f;
  --muted: #787269;
  --line: #ded8cf;
  --line-soft: #eae5de;
  --white: #fffdf9;
  --coral: #e57462;
  --coral-dark: #bd5145;
  --coral-soft: #f8dfd8;
  --sage: #819982;
  --sage-soft: #dfe8df;
  --blue: #6d89a6;
  --blue-soft: #e2eaf1;
  --danger: #b64c43;
  --shadow: 0 28px 80px rgba(56, 46, 36, 0.12);
  --shadow-soft: 0 14px 38px rgba(56, 46, 36, 0.08);
  --radius-xl: 28px;
  --radius-lg: 20px;
  --radius-md: 14px;
  --sidebar-width: 294px;
  --font-serif: "Songti SC", "STSong", "Noto Serif CJK SC", "Times New Roman", serif;
  --font-sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
}

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

button {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: 3px solid rgba(109, 137, 166, 0.28);
  outline-offset: 2px;
}

[hidden] {
  display: none !important;
}

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

.boot-screen {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-content: center;
  gap: 18px;
  text-align: center;
  background:
    radial-gradient(circle at 52% 42%, rgba(229, 116, 98, 0.09), transparent 24rem),
    var(--paper);
  color: var(--muted);
}

.boot-screen p {
  margin: 0;
  font-size: 13px;
  letter-spacing: 0.08em;
}

.boot-mark {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.boot-mark span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--coral);
  animation: boot-bounce 1s infinite ease-in-out;
}

.boot-mark span:nth-child(2) {
  animation-delay: 0.15s;
}

.boot-mark span:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes boot-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.45; }
  30% { transform: translateY(-8px); opacity: 1; }
}

.auth-page {
  position: relative;
  min-height: 100dvh;
  padding: 32px;
  display: grid;
  place-items: center;
  overflow: hidden;
  background:
    radial-gradient(circle at 12% 14%, rgba(223, 232, 223, 0.8), transparent 26rem),
    radial-gradient(circle at 88% 82%, rgba(248, 223, 216, 0.74), transparent 27rem),
    var(--paper);
}

.auth-page::before,
.auth-page::after {
  content: "";
  position: absolute;
  border: 1px solid rgba(129, 153, 130, 0.28);
  border-radius: 50%;
  pointer-events: none;
}

.auth-page::before {
  width: 28vw;
  height: 28vw;
  min-width: 280px;
  min-height: 280px;
  top: -18vw;
  right: 9vw;
}

.auth-page::after {
  width: 18vw;
  height: 18vw;
  min-width: 220px;
  min-height: 220px;
  bottom: -12vw;
  left: 4vw;
}

.auth-card {
  position: relative;
  z-index: 1;
  width: min(100%, 460px);
  padding: 42px;
  border: 1px solid rgba(255, 255, 255, 0.9);
  border-radius: var(--radius-xl);
  background: rgba(255, 253, 249, 0.86);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.auth-card-wide {
  width: min(100%, 900px);
  display: grid;
  grid-template-columns: 0.82fr 1.18fr;
  gap: 52px;
  align-items: center;
}

.auth-portrait {
  position: relative;
  min-height: 470px;
  display: grid;
  place-items: end center;
  overflow: hidden;
  border-radius: 22px;
  background:
    linear-gradient(160deg, rgba(223, 232, 223, 0.9), rgba(248, 223, 216, 0.85)),
    var(--paper-deep);
}

.auth-portrait::after {
  content: "✦";
  position: absolute;
  top: 28px;
  right: 30px;
  color: rgba(255, 253, 249, 0.85);
  font-size: 32px;
}

.auth-portrait img {
  width: 118%;
  max-height: 108%;
  object-fit: contain;
  object-position: center bottom;
  transform: translateY(4%);
}

.auth-content {
  padding: 12px 4px;
}

.eyebrow {
  margin: 0 0 10px;
  color: var(--coral-dark);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.2em;
  text-transform: uppercase;
}

.auth-card h1,
.welcome-view h1 {
  margin: 0;
  font-family: var(--font-serif);
  font-weight: 600;
  letter-spacing: -0.04em;
}

.auth-card h1 {
  font-size: clamp(34px, 5vw, 46px);
  line-height: 1.12;
}

.auth-lead {
  margin: 15px 0 30px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.75;
}

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

.mini-portrait {
  width: 76px;
  height: 76px;
  display: grid;
  place-items: center;
  overflow: hidden;
  border-radius: 26px 26px 26px 9px;
  background: linear-gradient(145deg, var(--sage-soft), var(--coral-soft));
}

.mini-portrait img {
  width: 115%;
  height: 115%;
  object-fit: cover;
  object-position: center 23%;
}

.login-brand .eyebrow {
  margin-bottom: 4px;
}

.form-stack {
  display: grid;
  gap: 17px;
}

.form-stack label,
.field-label,
.form-field {
  display: grid;
  gap: 8px;
}

.form-stack label > span:first-child,
.field-label > span:first-child,
.form-field > label {
  color: #555047;
  font-size: 12px;
  font-weight: 650;
}

label small {
  margin-left: 5px;
  color: #9a9389;
  font-weight: 400;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.78);
  transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
}

input,
select {
  min-height: 47px;
  padding: 0 14px;
}

input:hover,
textarea:hover,
select:hover {
  border-color: #c8c0b5;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--blue);
  background: #fff;
  box-shadow: 0 0 0 4px rgba(109, 137, 166, 0.1);
}

.password-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.password-field {
  position: relative;
  display: block;
}

.password-field input {
  padding-right: 64px;
}

.password-toggle {
  position: absolute;
  top: 50%;
  right: 11px;
  padding: 5px 6px;
  border: 0;
  transform: translateY(-50%);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
}

.primary-button,
.secondary-button,
.danger-button {
  min-height: 46px;
  border-radius: 12px;
  padding: 0 18px;
  cursor: pointer;
  font-weight: 650;
  transition: transform 0.2s, box-shadow 0.2s, background 0.2s, opacity 0.2s;
}

.primary-button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border: 1px solid #2c2925;
  background: #2c2925;
  color: #fffdfa;
  box-shadow: 0 8px 18px rgba(44, 41, 37, 0.14);
}

.primary-button:hover {
  transform: translateY(-1px);
  background: #191714;
  box-shadow: 0 10px 24px rgba(44, 41, 37, 0.18);
}

.primary-button:disabled,
.secondary-button:disabled,
.danger-button:disabled {
  cursor: wait;
  opacity: 0.55;
  transform: none;
}

.primary-button.compact {
  min-height: 42px;
  justify-content: center;
}

.button-arrow {
  font-size: 19px;
}

.secondary-button {
  border: 1px solid var(--line);
  background: var(--white);
}

.secondary-button:hover {
  border-color: #c7bfb4;
  background: #faf7f2;
}

.danger-button {
  border: 1px solid var(--danger);
  background: var(--danger);
  color: white;
}

.form-error {
  margin: 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: #fae7e3;
  color: #993c34;
  font-size: 12px;
  line-height: 1.5;
}

.security-note {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  margin: 24px 0 -8px;
  color: #938c82;
  font-size: 11px;
}

.app-shell {
  height: 100dvh;
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  overflow: hidden;
  background: var(--white);
}

.sidebar {
  position: relative;
  z-index: 20;
  min-width: 0;
  height: 100dvh;
  padding: max(20px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--line-soft);
  background: var(--paper);
}

.brand-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 3px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 0;
  border: 0;
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.brand-avatar {
  width: 42px;
  height: 42px;
  display: block;
  overflow: hidden;
  border-radius: 15px 15px 15px 5px;
  background: linear-gradient(145deg, var(--sage-soft), var(--coral-soft));
}

.brand-avatar img {
  width: 118%;
  height: 118%;
  object-fit: cover;
  object-position: center 24%;
  transform: translate(-7%, -4%);
}

.brand strong,
.brand small {
  display: block;
}

.brand strong {
  font-family: var(--font-serif);
  font-size: 18px;
  letter-spacing: 0.02em;
}

.brand small {
  margin-top: 2px;
  color: var(--muted);
  font-size: 10px;
  letter-spacing: 0.1em;
}

.brand .bridge-status {
  display: flex;
  align-items: center;
  gap: 5px;
  letter-spacing: 0.04em;
}

.bridge-status i {
  width: 5px;
  height: 5px;
  flex: 0 0 5px;
  border-radius: 50%;
  background: #b4ada4;
}

.bridge-status[data-state="online"] i {
  background: var(--sage);
  box-shadow: 0 0 0 3px rgba(129, 153, 130, 0.14);
}

.bridge-status[data-state="offline"] {
  color: var(--coral-dark);
}

.bridge-status[data-state="offline"] i {
  background: var(--coral);
}

.icon-button,
.tiny-icon-button {
  display: grid;
  place-items: center;
  border: 0;
  background: transparent;
  color: #766f66;
  cursor: pointer;
  transition: color 0.2s, background 0.2s;
}

.icon-button {
  width: 38px;
  height: 38px;
  border-radius: 11px;
  font-size: 18px;
}

.icon-button:hover,
.tiny-icon-button:hover {
  background: var(--paper-deep);
  color: var(--ink);
}

.sidebar-close,
.mobile-menu-button {
  display: none;
}

.new-chat-button {
  width: 100%;
  min-height: 48px;
  margin: 23px 0 20px;
  padding: 0 13px;
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid #d8d1c8;
  border-radius: 14px;
  background: rgba(255, 253, 249, 0.92);
  color: var(--ink);
  cursor: pointer;
  font-weight: 600;
  box-shadow: 0 4px 14px rgba(55, 46, 38, 0.04);
  transition: transform 0.2s, border-color 0.2s, box-shadow 0.2s;
}

.new-chat-button:hover {
  transform: translateY(-1px);
  border-color: #bdb5aa;
  box-shadow: var(--shadow-soft);
}

.new-chat-button .plus {
  width: 25px;
  height: 25px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--ink);
  color: white;
  font-size: 17px;
  line-height: 1;
}

.new-chat-button kbd {
  margin-left: auto;
  border: 0;
  color: #aaa399;
  background: transparent;
  font-family: inherit;
  font-size: 10px;
}

.conversation-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 9px 9px;
  color: #918a80;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.12em;
}

.tiny-icon-button {
  width: 27px;
  height: 27px;
  border-radius: 8px;
  font-size: 15px;
}

.conversation-list {
  min-height: 0;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: #d6cfc6 transparent;
}

.conversation-item {
  position: relative;
  width: 100%;
  min-height: 58px;
  margin-bottom: 4px;
  padding: 9px 9px 9px 12px;
  display: grid;
  grid-template-columns: 7px minmax(0, 1fr);
  gap: 11px;
  align-items: center;
  border: 0;
  border-radius: 12px;
  background: transparent;
  text-align: left;
  cursor: pointer;
  transition: background 0.2s;
}

.conversation-item:hover {
  background: rgba(255, 253, 249, 0.8);
}

.conversation-item[aria-current="page"] {
  background: var(--white);
  box-shadow: 0 5px 18px rgba(55, 46, 38, 0.06);
}

.conversation-mode-mark {
  width: 6px;
  height: 26px;
  border-radius: 99px;
  background: var(--sage);
}

.conversation-mode-mark[data-mode="chat"] {
  background: var(--blue);
}

.conversation-item strong,
.conversation-item small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-item strong {
  font-size: 12px;
  font-weight: 600;
}

.conversation-item small {
  margin-top: 5px;
  color: #9b948a;
  font-size: 10px;
}

.conversation-empty {
  padding: 38px 10px;
  color: #9b948a;
  text-align: center;
  font-size: 11px;
  line-height: 1.7;
}

.conversation-empty span {
  color: var(--coral);
  font-size: 19px;
}

.sidebar-footer {
  position: relative;
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid var(--line-soft);
}

.user-menu-button {
  width: 100%;
  min-height: 52px;
  padding: 7px;
  display: flex;
  align-items: center;
  gap: 10px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  cursor: pointer;
  text-align: left;
}

.user-menu-button:hover {
  background: rgba(255, 253, 249, 0.82);
}

.user-avatar {
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--coral-soft);
  color: var(--coral-dark);
  font-family: var(--font-serif);
  font-weight: 700;
}

.user-copy {
  min-width: 0;
}

.user-copy strong,
.user-copy small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-copy strong {
  font-size: 12px;
}

.user-copy small {
  margin-top: 3px;
  color: #9a9389;
  font-size: 10px;
}

.more-dots {
  margin-left: auto;
  color: #aaa399;
  font-size: 9px;
  letter-spacing: 1px;
}

.user-menu {
  position: absolute;
  z-index: 5;
  left: 0;
  right: 0;
  bottom: calc(100% + 8px);
  padding: 7px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--white);
  box-shadow: var(--shadow-soft);
}

.user-menu button {
  width: 100%;
  padding: 10px 11px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  text-align: left;
  cursor: pointer;
  font-size: 12px;
}

.user-menu button:hover {
  background: var(--paper);
}

.menu-rule {
  height: 1px;
  margin: 5px 3px;
  background: var(--line-soft);
}

.danger-text {
  color: var(--danger) !important;
}

.workspace {
  position: relative;
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: 70px minmax(0, 1fr);
  background:
    linear-gradient(rgba(255, 253, 249, 0.94), rgba(255, 253, 249, 0.94)),
    radial-gradient(circle at 20% 0, var(--sage-soft), transparent 30rem);
}

.workspace-header {
  min-width: 0;
  height: 70px;
  padding: 0 25px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid var(--line-soft);
  background: rgba(255, 253, 249, 0.82);
  backdrop-filter: blur(14px);
}

.conversation-title-wrap {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 11px;
}

.conversation-title-wrap h2,
.conversation-title-wrap p {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-title-wrap h2 {
  max-width: 56vw;
  margin: 0;
  font-family: var(--font-serif);
  font-size: 16px;
  font-weight: 650;
}

.conversation-title-wrap p {
  margin: 3px 0 0;
  color: #9a9389;
  font-size: 10px;
}

.mode-dot {
  width: 8px;
  height: 8px;
  flex: 0 0 8px;
  border-radius: 50%;
  background: var(--sage);
  box-shadow: 0 0 0 5px var(--sage-soft);
}

.mode-dot[data-mode="chat"] {
  background: var(--blue);
  box-shadow: 0 0 0 5px var(--blue-soft);
}

.header-actions {
  margin-left: auto;
  display: flex;
  gap: 3px;
}

.danger-hover:hover {
  background: #fae7e3;
  color: var(--danger);
}

.welcome-view {
  min-height: 0;
  padding: clamp(28px, 5vh, 72px) 24px 32px;
  overflow-y: auto;
  text-align: center;
}

.welcome-orbit {
  position: relative;
  width: clamp(120px, 18vh, 162px);
  height: clamp(120px, 18vh, 162px);
  margin: 0 auto 20px;
  display: grid;
  place-items: center;
  border-radius: 48% 52% 47% 53% / 52% 47% 53% 48%;
  background: linear-gradient(145deg, var(--sage-soft), var(--coral-soft));
  animation: orbit-morph 8s ease-in-out infinite;
}

.welcome-orbit::before {
  content: "";
  position: absolute;
  inset: -13px;
  border: 1px dashed rgba(129, 153, 130, 0.38);
  border-radius: 50%;
  animation: slow-spin 24s linear infinite;
}

.welcome-orbit img {
  width: 118%;
  height: 118%;
  object-fit: cover;
  object-position: center 22%;
  transform: translateY(-2%);
}

.orbit-note {
  position: absolute;
  z-index: 2;
  width: 31px;
  height: 31px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--white);
  box-shadow: 0 7px 15px rgba(55, 46, 38, 0.08);
  color: var(--coral-dark);
  font-family: var(--font-serif);
  font-size: 12px;
  animation: float-note 4s ease-in-out infinite;
}

.note-one {
  top: 7px;
  left: -23px;
}

.note-two {
  right: -22px;
  bottom: 15px;
  animation-delay: -2s;
  color: var(--blue);
}

@keyframes orbit-morph {
  0%, 100% { border-radius: 48% 52% 47% 53% / 52% 47% 53% 48%; }
  50% { border-radius: 55% 45% 53% 47% / 46% 56% 44% 54%; }
}

@keyframes slow-spin {
  to { transform: rotate(360deg); }
}

@keyframes float-note {
  0%, 100% { transform: translateY(0) rotate(-5deg); }
  50% { transform: translateY(-7px) rotate(5deg); }
}

.welcome-view h1 {
  font-size: clamp(29px, 4vw, 43px);
  line-height: 1.25;
}

.welcome-copy {
  margin: 10px auto 27px;
  color: var(--muted);
  font-size: 13px;
}

.mode-cards {
  width: min(100%, 690px);
  margin: 0 auto;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.mode-card {
  position: relative;
  min-height: 118px;
  padding: 19px;
  display: grid;
  grid-template-columns: 51px minmax(0, 1fr) 20px;
  gap: 14px;
  align-items: center;
  overflow: hidden;
  border: 1px solid var(--line-soft);
  border-radius: 19px;
  background: var(--white);
  text-align: left;
  cursor: pointer;
  box-shadow: 0 10px 28px rgba(55, 46, 38, 0.05);
  transition: transform 0.24s, box-shadow 0.24s, border-color 0.24s;
}

.mode-card::after {
  content: "";
  position: absolute;
  width: 80px;
  height: 80px;
  right: -35px;
  bottom: -46px;
  border-radius: 50%;
  background: var(--sage-soft);
  opacity: 0.55;
  transition: transform 0.3s;
}

.chat-card::after {
  background: var(--blue-soft);
}

.mode-card:hover {
  transform: translateY(-4px);
  border-color: #cfc7bd;
  box-shadow: 0 17px 38px rgba(55, 46, 38, 0.09);
}

.mode-card:hover::after {
  transform: scale(1.35);
}

.mode-icon {
  width: 51px;
  height: 51px;
  position: relative;
  display: block;
  border-radius: 15px;
}

.paper-icon {
  background: var(--sage-soft);
}

.paper-icon::before {
  content: "";
  position: absolute;
  inset: 11px 12px;
  border: 1.5px solid #657f68;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.45);
}

.paper-icon i {
  position: absolute;
  z-index: 1;
  left: 17px;
  width: 17px;
  height: 1px;
  background: #7e9580;
}

.paper-icon i:nth-child(1) { top: 20px; }
.paper-icon i:nth-child(2) { top: 25px; }
.paper-icon i:nth-child(3) { top: 30px; width: 11px; }

.chat-icon {
  background: var(--blue-soft);
}

.chat-icon::before {
  content: "";
  position: absolute;
  inset: 12px 10px 14px;
  border: 1.5px solid #66839d;
  border-radius: 10px 10px 10px 4px;
  background: rgba(255, 255, 255, 0.42);
}

.chat-icon i {
  position: absolute;
  z-index: 1;
  top: 24px;
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: #6d89a6;
}

.chat-icon i:nth-child(1) { left: 19px; }
.chat-icon i:nth-child(2) { left: 25px; }
.chat-icon i:nth-child(3) { left: 31px; }

.mode-card-copy {
  min-width: 0;
}

.mode-card-copy strong,
.mode-card-copy small {
  display: block;
}

.mode-card-copy strong {
  margin-bottom: 7px;
  font-family: var(--font-serif);
  font-size: 17px;
}

.mode-card-copy small {
  color: var(--muted);
  font-size: 10px;
  line-height: 1.6;
}

.mode-arrow {
  color: #9c958b;
  font-size: 17px;
}

.privacy-pill {
  width: fit-content;
  margin: 26px auto 0;
  padding: 8px 13px;
  display: flex;
  align-items: center;
  gap: 7px;
  border: 1px solid var(--line-soft);
  border-radius: 99px;
  color: #918a80;
  background: rgba(247, 244, 239, 0.55);
  font-size: 10px;
}

.lock-mark {
  color: var(--sage);
  font-size: 14px;
}

.chat-view {
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  overflow: hidden;
}

.message-scroll {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scroll-behavior: smooth;
}

.message-column,
.typing-row {
  width: min(100%, 830px);
  margin: 0 auto;
}

.message-column {
  padding: 35px 28px 18px;
  display: flex;
  flex-direction: column;
  gap: 30px;
}

.message-row {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr);
  gap: 13px;
  align-items: start;
}

.message-row.user {
  grid-template-columns: minmax(0, 1fr) 38px;
}

.message-avatar {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  overflow: hidden;
  border-radius: 14px 14px 14px 5px;
  background: linear-gradient(145deg, var(--sage-soft), var(--coral-soft));
}

.message-avatar img {
  width: 122%;
  height: 122%;
  object-fit: cover;
  object-position: center 23%;
  transform: translate(-7%, -4%);
}

.message-row.user .message-avatar {
  grid-column: 2;
  grid-row: 1;
  border-radius: 50%;
  background: var(--paper-deep);
  color: #736c63;
  font-family: var(--font-serif);
  font-weight: 700;
}

.message-body {
  min-width: 0;
}

.message-row.user .message-body {
  justify-self: end;
  grid-column: 1;
  grid-row: 1;
  max-width: min(88%, 680px);
}

.message-who {
  margin: 1px 0 8px;
  color: #918a80;
  font-size: 10px;
  font-weight: 650;
  letter-spacing: 0.06em;
}

.message-row.user .message-who {
  text-align: right;
}

.message-text {
  margin: 0;
  color: #393530;
  font-family: var(--font-serif);
  font-size: 15px;
  line-height: 1.9;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.message-row.user .message-text {
  padding: 13px 17px;
  border-radius: 16px 16px 5px 16px;
  background: var(--paper-deep);
  font-family: var(--font-sans);
  font-size: 13px;
  line-height: 1.75;
}

.message-tools {
  min-height: 25px;
  margin-top: 8px;
  display: flex;
  align-items: center;
  gap: 5px;
  opacity: 0;
  transition: opacity 0.2s;
}

.message-row:hover .message-tools,
.message-tools:focus-within {
  opacity: 1;
}

.copy-button {
  padding: 5px 8px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: #918a80;
  cursor: pointer;
  font-size: 10px;
}

.copy-button:hover {
  background: var(--paper);
  color: var(--ink);
}

.message-time {
  color: #aaa399;
  font-size: 9px;
}

.message-empty {
  margin: 10vh auto 0;
  max-width: 520px;
  padding: 32px;
  border: 1px dashed var(--line);
  border-radius: 18px;
  color: var(--muted);
  text-align: center;
  font-size: 12px;
  line-height: 1.8;
}

.message-empty strong {
  display: block;
  margin-bottom: 8px;
  color: var(--ink);
  font-family: var(--font-serif);
  font-size: 20px;
}

.typing-row {
  padding: 0 28px 20px;
  display: grid;
  grid-template-columns: 38px 1fr;
  gap: 13px;
}

.typing-bubble {
  width: fit-content;
  margin-top: 4px;
  padding: 11px 14px;
  display: flex;
  gap: 5px;
  border-radius: 13px;
  background: var(--paper);
}

.typing-bubble i {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #9c958b;
  animation: typing 1.2s infinite ease-in-out;
}

.typing-bubble i:nth-child(2) { animation-delay: 0.13s; }
.typing-bubble i:nth-child(3) { animation-delay: 0.26s; }

@keyframes typing {
  0%, 65%, 100% { transform: translateY(0); opacity: 0.45; }
  30% { transform: translateY(-4px); opacity: 1; }
}

.composer-zone {
  padding: 9px max(24px, calc((100% - 830px) / 2)) max(15px, env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--white) 78%, rgba(255, 253, 249, 0));
}

.composer {
  padding: 12px 13px 10px 16px;
  border: 1px solid #d8d1c8;
  border-radius: 18px;
  background: #fff;
  box-shadow: 0 12px 35px rgba(55, 46, 38, 0.09);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.composer:focus-within {
  border-color: #aaa095;
  box-shadow: 0 15px 42px rgba(55, 46, 38, 0.12);
}

.composer textarea {
  min-height: 30px;
  max-height: 210px;
  padding: 5px 2px 7px;
  resize: none;
  border: 0;
  border-radius: 0;
  background: transparent;
  line-height: 1.65;
}

.composer textarea:focus {
  box-shadow: none;
}

.composer textarea::placeholder {
  color: #aaa399;
}

.composer-footer {
  min-height: 32px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.composer-mode {
  display: flex;
  align-items: center;
  gap: 5px;
  color: var(--sage);
  font-size: 10px;
  font-weight: 650;
}

.composer-mode[data-mode="chat"] {
  color: var(--blue);
}

.composer-hint {
  margin-left: auto;
  color: #b1aaa0;
  font-size: 9px;
}

.send-button {
  width: 31px;
  height: 31px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 10px;
  background: var(--ink);
  color: white;
  cursor: pointer;
  font-size: 17px;
  transition: transform 0.2s, opacity 0.2s;
}

.send-button:hover:not(:disabled) {
  transform: translateY(-1px);
}

.send-button:disabled {
  cursor: default;
  opacity: 0.25;
}

.model-note {
  margin: 7px 0 0;
  color: #aaa399;
  text-align: center;
  font-size: 9px;
}

.modal {
  width: min(calc(100% - 32px), 570px);
  max-height: min(88dvh, 760px);
  padding: 0;
  overflow: visible;
  border: 0;
  border-radius: var(--radius-lg);
  background: transparent;
  color: var(--ink);
}

.modal::backdrop {
  background: rgba(37, 32, 28, 0.36);
  backdrop-filter: blur(6px);
}

.modal-card {
  max-height: min(88dvh, 760px);
  padding: 29px;
  overflow-y: auto;
  border: 1px solid rgba(255, 255, 255, 0.85);
  border-radius: var(--radius-lg);
  background: var(--white);
  box-shadow: var(--shadow);
}

.small-modal {
  width: min(calc(100% - 32px), 460px);
}

.modal-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 24px;
}

.modal-heading h2,
.delete-dialog h2,
.modal-card > h2 {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 24px;
  font-weight: 650;
}

.modal-close {
  flex: 0 0 auto;
  margin: -8px -8px 0 0;
}

.mode-options {
  margin: 0 0 20px;
  padding: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  border: 0;
}

.mode-options label {
  cursor: pointer;
}

.mode-options input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.mode-option {
  min-height: 88px;
  padding: 13px;
  display: grid;
  grid-template-columns: 39px minmax(0, 1fr) 15px;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 14px;
  transition: border-color 0.2s, background 0.2s, box-shadow 0.2s;
}

.mode-options input:checked + .mode-option {
  border-color: #9aae9b;
  background: rgba(223, 232, 223, 0.4);
  box-shadow: 0 0 0 3px rgba(129, 153, 130, 0.09);
}

.mode-options label:nth-child(3) input:checked + .mode-option {
  border-color: #94a9bc;
  background: rgba(226, 234, 241, 0.48);
  box-shadow: 0 0 0 3px rgba(109, 137, 166, 0.08);
}

.mode-option-symbol {
  width: 39px;
  height: 39px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  font-family: var(--font-serif);
  font-weight: 700;
}

.polish-symbol {
  background: var(--sage-soft);
  color: #617b63;
}

.chat-symbol {
  background: var(--blue-soft);
  color: #607e99;
}

.mode-option strong,
.mode-option small {
  display: block;
}

.mode-option strong {
  font-size: 12px;
}

.mode-option small {
  margin-top: 4px;
  color: var(--muted);
  font-size: 9px;
}

.mode-option i {
  width: 14px;
  height: 14px;
  position: relative;
  border: 1px solid #c7bfb5;
  border-radius: 50%;
}

.mode-options input:checked + .mode-option i {
  border-color: var(--sage);
  box-shadow: inset 0 0 0 3px var(--white);
  background: var(--sage);
}

.mode-options label:nth-child(3) input:checked + .mode-option i {
  border-color: var(--blue);
  background: var(--blue);
}

.modal-actions {
  margin-top: 23px;
  display: flex;
  justify-content: flex-end;
  gap: 9px;
}

.warning-mark {
  width: 43px;
  height: 43px;
  margin-bottom: 17px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #fae7e3;
  color: var(--danger);
  font-family: var(--font-serif);
  font-size: 20px;
  font-weight: 700;
}

.modal-card > p:not(.eyebrow):not(.form-error) {
  margin: 9px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.7;
}

.account-summary {
  margin: -3px 0 21px;
  padding: 12px;
  display: flex;
  align-items: center;
  gap: 11px;
  border-radius: 13px;
  background: var(--paper);
}

.account-summary strong,
.account-summary small {
  display: block;
}

.account-summary strong {
  font-size: 12px;
}

.account-summary small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 10px;
}

#passwordForm {
  display: grid;
  gap: 15px;
}

#editUserForm {
  display: grid;
  gap: 15px;
}

#passwordForm .modal-heading,
#passwordForm .modal-actions,
#editUserForm .modal-heading,
#editUserForm .modal-actions {
  margin-bottom: 0;
}

.switch-field {
  min-height: 58px;
  padding: 9px 11px;
  display: flex;
  align-items: center;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
}

.switch-field > span {
  min-width: 0;
  margin-right: auto;
}

.switch-field strong,
.switch-field small {
  display: block;
}

.switch-field strong {
  font-size: 12px;
}

.switch-field small {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 9px;
}

.switch-field input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.switch-field i {
  position: relative;
  width: 39px;
  height: 22px;
  flex: 0 0 39px;
  border-radius: 99px;
  background: #d7d1c9;
  cursor: pointer;
  transition: background 0.2s;
}

.switch-field i::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: white;
  box-shadow: 0 2px 5px rgba(40, 34, 29, 0.2);
  transition: transform 0.2s;
}

.switch-field input:checked + i {
  background: var(--sage);
}

.switch-field input:checked + i::after {
  transform: translateX(17px);
}

.switch-field input:focus-visible + i {
  outline: 3px solid rgba(109, 137, 166, 0.28);
  outline-offset: 2px;
}

.admin-modal {
  width: min(calc(100% - 32px), 760px);
}

.admin-toolbar {
  margin: -7px 0 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 15px;
}

.admin-toolbar p {
  margin: 0;
  color: var(--muted);
  font-size: 11px;
}

.create-user-panel {
  margin-bottom: 20px;
  padding: 17px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--paper);
}

.panel-title {
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
}

.panel-title button {
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 11px;
}

.admin-field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.create-user-panel .primary-button {
  margin: 14px 0 0 auto;
}

.user-table-wrap {
  position: relative;
  min-height: 110px;
  overflow-x: auto;
  border: 1px solid var(--line-soft);
  border-radius: 14px;
}

.user-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
}

.user-table th,
.user-table td {
  padding: 13px 14px;
  border-bottom: 1px solid var(--line-soft);
  text-align: left;
  white-space: nowrap;
}

.user-table th {
  color: #918a80;
  background: var(--paper);
  font-size: 9px;
  letter-spacing: 0.08em;
}

.user-table tr:last-child td {
  border-bottom: 0;
}

.table-user {
  display: flex;
  align-items: center;
  gap: 9px;
}

.table-user .user-avatar {
  width: 29px;
  height: 29px;
  flex-basis: 29px;
  font-size: 11px;
}

.table-user strong,
.table-user small {
  display: block;
}

.table-user strong {
  font-size: 11px;
}

.table-user small {
  margin-top: 2px;
  color: var(--muted);
  font-size: 9px;
}

.status-chip,
.role-chip {
  display: inline-flex;
  padding: 4px 7px;
  border-radius: 99px;
  font-size: 9px;
}

.status-chip {
  background: var(--sage-soft);
  color: #58705a;
}

.status-chip.inactive {
  background: #eeeae5;
  color: #8f887e;
}

.role-chip {
  background: var(--blue-soft);
  color: #5e7891;
}

.role-chip.user {
  background: var(--paper-deep);
  color: #736c63;
}

.user-action {
  padding: 5px 7px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 10px;
}

.user-action:hover {
  background: var(--paper);
  color: var(--ink);
}

.table-loading {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(255, 253, 249, 0.86);
  color: var(--muted);
  font-size: 11px;
}

.toast-region {
  position: fixed;
  z-index: 200;
  right: 22px;
  bottom: 22px;
  display: grid;
  gap: 8px;
  pointer-events: none;
}

.toast {
  min-width: 220px;
  max-width: min(360px, calc(100vw - 32px));
  padding: 12px 15px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: #2d2a26;
  color: #fff;
  box-shadow: var(--shadow-soft);
  font-size: 11px;
  line-height: 1.5;
  animation: toast-in 0.22s ease-out;
}

.toast.error {
  background: #8f3f38;
}

@keyframes toast-in {
  from { transform: translateY(8px); opacity: 0; }
}

.is-busy {
  cursor: wait !important;
  opacity: 0.6;
}

@media (max-width: 840px) {
  .auth-card-wide {
    max-width: 540px;
    grid-template-columns: 1fr;
  }

  .auth-portrait {
    display: none;
  }

  .app-shell {
    grid-template-columns: minmax(0, 1fr);
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(86vw, var(--sidebar-width));
    transform: translateX(-103%);
    box-shadow: 22px 0 60px rgba(35, 30, 25, 0.18);
    transition: transform 0.25s ease;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-scrim {
    position: fixed;
    z-index: 15;
    inset: 0;
    background: rgba(37, 32, 28, 0.3);
    backdrop-filter: blur(2px);
  }

  .sidebar-close,
  .mobile-menu-button {
    display: grid;
  }

  .mobile-menu-button {
    margin-right: 6px;
  }

  .workspace-header {
    padding: 0 14px;
  }

  .composer-zone {
    padding-inline: 15px;
  }
}

@media (max-width: 620px) {
  .auth-page {
    padding: 18px;
    align-items: center;
  }

  .auth-card {
    padding: 28px 23px;
    border-radius: 22px;
  }

  .auth-card h1 {
    font-size: 34px;
  }

  .password-grid,
  .mode-cards,
  .mode-options,
  .admin-field-grid {
    grid-template-columns: 1fr;
  }

  .welcome-view {
    padding: 32px 17px 25px;
  }

  .welcome-orbit {
    width: 126px;
    height: 126px;
  }

  .welcome-view h1 {
    font-size: 29px;
  }

  .mode-card {
    min-height: 96px;
    padding: 15px;
  }

  .privacy-pill {
    border-radius: 15px;
    line-height: 1.5;
  }

  .conversation-title-wrap h2 {
    max-width: 46vw;
  }

  .message-column {
    padding: 25px 16px 14px;
    gap: 24px;
  }

  .message-row {
    grid-template-columns: 32px minmax(0, 1fr);
    gap: 10px;
  }

  .message-row.user {
    grid-template-columns: minmax(0, 1fr) 32px;
  }

  .message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 12px 12px 12px 4px;
  }

  .message-text {
    font-size: 14px;
    line-height: 1.82;
  }

  .message-row.user .message-body {
    max-width: 94%;
  }

  .message-tools {
    opacity: 1;
  }

  .typing-row {
    padding-inline: 16px;
    grid-template-columns: 32px 1fr;
    gap: 10px;
  }

  .composer-hint {
    display: none;
  }

  .modal-card {
    padding: 23px 19px;
  }

  .admin-toolbar {
    align-items: flex-start;
  }

  .user-table th,
  .user-table td {
    padding: 11px 10px;
  }

  .toast-region {
    right: 16px;
    bottom: 16px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
