﻿:root {
  --cream-0: #fffefb;
  --cream-1: #fbf6ef;
  --cream-2: #f5e8d7;
  --ink-1: #5f4838;
  --ink-2: #8b715d;
  --line: rgba(191, 156, 128, 0.42);
  --line-strong: rgba(181, 141, 109, 0.56);
  --glass: rgba(255, 250, 244, 0.52);
  --glass-strong: rgba(255, 248, 238, 0.86);
  --brand-1: #d7ad86;
  --brand-2: #b9835d;
  --danger: #9c3f31;
  --bg-a: #fff9f0;
  --bg-b: #f9e8d3;
  --bg-c: #f2dcc4;
  --orb-a-1: #fffaf1;
  --orb-a-2: #ebd6bc;
  --orb-b-1: #fff3e4;
  --orb-b-2: #dfc2a2;
  --orb-c-1: #fff7eb;
  --orb-c-2: #edd3b7;
  --shadow-tint: rgba(154, 109, 74, 0.18);
  --user-bubble-1: rgba(210, 170, 137, 0.95);
  --user-bubble-2: rgba(187, 141, 102, 0.93);
}

body[data-theme="ocean"] {
  --cream-0: #f9fcff;
  --cream-1: #eef6ff;
  --cream-2: #deecfa;
  --ink-1: #2d4b60;
  --ink-2: #51718a;
  --line: rgba(116, 152, 186, 0.42);
  --line-strong: rgba(94, 137, 174, 0.56);
  --brand-1: #76b3df;
  --brand-2: #4b8ec3;
  --bg-a: #f3fbff;
  --bg-b: #dcefff;
  --bg-c: #c7e1f7;
  --orb-a-1: #f7fcff;
  --orb-a-2: #d2e6f7;
  --orb-b-1: #eaf5ff;
  --orb-b-2: #bfd9f0;
  --orb-c-1: #f2f9ff;
  --orb-c-2: #d4e9fb;
  --shadow-tint: rgba(92, 132, 170, 0.2);
  --user-bubble-1: rgba(121, 177, 220, 0.95);
  --user-bubble-2: rgba(77, 136, 188, 0.93);
}

body[data-theme="mint"] {
  --cream-0: #fbfffd;
  --cream-1: #f0faf6;
  --cream-2: #dff1e8;
  --ink-1: #2f5b4e;
  --ink-2: #4e7a6b;
  --line: rgba(122, 169, 151, 0.4);
  --line-strong: rgba(94, 149, 128, 0.56);
  --brand-1: #78c2a5;
  --brand-2: #4f9d82;
  --bg-a: #f0fff8;
  --bg-b: #d9f4e7;
  --bg-c: #c4e9d7;
  --orb-a-1: #f8fff9;
  --orb-a-2: #cbe8d9;
  --orb-b-1: #eafff6;
  --orb-b-2: #bbdecd;
  --orb-c-1: #f2fff9;
  --orb-c-2: #d2efdf;
  --shadow-tint: rgba(80, 137, 116, 0.2);
  --user-bubble-1: rgba(122, 190, 161, 0.95);
  --user-bubble-2: rgba(79, 154, 126, 0.93);
}

body[data-theme="sunset"] {
  --cream-0: #fffaf7;
  --cream-1: #fff1e8;
  --cream-2: #ffdccc;
  --ink-1: #5e3e36;
  --ink-2: #8e6053;
  --line: rgba(197, 136, 112, 0.45);
  --line-strong: rgba(181, 112, 84, 0.58);
  --brand-1: #f08d63;
  --brand-2: #cf6f4a;
  --bg-a: #fff6ef;
  --bg-b: #ffe2cf;
  --bg-c: #ffd1bc;
  --orb-a-1: #fff7f0;
  --orb-a-2: #f7cfbb;
  --orb-b-1: #ffeadc;
  --orb-b-2: #f0c1ac;
  --orb-c-1: #fff2e8;
  --orb-c-2: #f6d1be;
  --shadow-tint: rgba(183, 109, 83, 0.2);
  --user-bubble-1: rgba(239, 148, 105, 0.95);
  --user-bubble-2: rgba(204, 108, 76, 0.93);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  color: var(--ink-1);
  font-family: "Manrope", "Noto Sans SC", sans-serif;
}

body {
  min-height: 100svh;
  min-height: 100dvh;
  background:
    radial-gradient(circle at 15% 18%, var(--bg-a) 0%, transparent 33%),
    radial-gradient(circle at 84% 17%, var(--bg-b) 0%, transparent 29%),
    radial-gradient(circle at 78% 83%, var(--bg-c) 0%, transparent 32%),
    linear-gradient(140deg, var(--cream-0), var(--cream-1), var(--cream-2));
  position: relative;
}

body::before,
body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
}

body::before {
  background:
    linear-gradient(112deg, rgba(255, 255, 255, 0.34) 0%, transparent 33%, rgba(255, 255, 255, 0.2) 62%, transparent 100%),
    repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.03), rgba(255, 255, 255, 0.03) 1px, transparent 1px, transparent 3px);
  mix-blend-mode: screen;
}

body::after {
  background: radial-gradient(68% 36% at 76% -3%, rgba(255, 255, 255, 0.48), transparent 70%);
  animation: float-lilt 8s ease-in-out infinite alternate;
  opacity: 0.86;
}

.bg-orb {
  position: fixed;
  border-radius: 999px;
  pointer-events: none;
  z-index: -1;
  filter: blur(11px);
  mix-blend-mode: multiply;
  animation: orb-drift 14s ease-in-out infinite alternate;
}

.orb-a {
  width: 30vw;
  height: 30vw;
  min-width: 230px;
  min-height: 230px;
  left: -8vw;
  top: -12vh;
  background: radial-gradient(circle at 34% 34%, var(--orb-a-1), var(--orb-a-2));
}

.orb-b {
  width: 28vw;
  height: 28vw;
  min-width: 210px;
  min-height: 210px;
  right: -10vw;
  bottom: -12vh;
  background: radial-gradient(circle at 37% 37%, var(--orb-b-1), var(--orb-b-2));
  animation-duration: 18s;
}

.orb-c {
  width: 17vw;
  height: 17vw;
  min-width: 150px;
  min-height: 150px;
  right: 28vw;
  top: 8vh;
  background: radial-gradient(circle at 40% 35%, var(--orb-c-1), var(--orb-c-2));
  animation-duration: 12s;
}

.glass {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 26px;
  background: var(--glass);
  box-shadow:
    0 18px 38px var(--shadow-tint),
    inset 0 1px 0 rgba(255, 255, 255, 0.82);
  backdrop-filter: blur(6px) saturate(180%) brightness(1.03);
  -webkit-backdrop-filter: blur(6px) saturate(180%) brightness(1.03);
  overflow: hidden;
}

.glass::before,
.glass::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.glass::before {
  background:
    radial-gradient(128% 60% at 7% 0%, rgba(255, 255, 255, 0.52), transparent 47%),
    radial-gradient(120% 56% at 94% 100%, rgba(255, 255, 255, 0.2), transparent 54%),
    linear-gradient(112deg, rgba(255, 255, 255, 0.22), rgba(255, 255, 255, 0.03) 45%, rgba(255, 255, 255, 0.16));
  mix-blend-mode: screen;
}

.glass::after {
  inset: -28%;
  border-radius: 40px;
  background:
    radial-gradient(circle at 24% 18%, rgba(255, 255, 255, 0.28), transparent 34%),
    radial-gradient(circle at 74% 76%, rgba(255, 255, 255, 0.18), transparent 38%);
  filter: blur(13px);
  opacity: 0.78;
}

.hidden {
  display: none !important;
}

.auth-screen {
  height: 100%;
  display: grid;
  place-items: center;
  padding: 20px;
}

.auth-card {
  width: min(500px, 96vw);
  padding: 26px;
  border-radius: 34px 24px 32px 20px;
  animation: shell-in 0.45s ease;
}

.auth-card h1 {
  margin: 0;
  font-family: "Sora", "Noto Sans SC", sans-serif;
  letter-spacing: 0.02em;
}

.auth-card p {
  margin: 10px 0 18px;
  color: var(--ink-2);
}

.auth-intro {
  margin: -8px 0 14px;
  display: grid;
  gap: 6px;
  font-size: 13px;
  color: var(--ink-2);
}

.auth-intro div {
  padding-left: 12px;
  position: relative;
}

.auth-intro div::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0.65em;
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: linear-gradient(140deg, var(--brand-1), var(--brand-2));
}

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 10px;
}

.auth-form {
  display: grid;
  gap: 10px;
}

.auth-error {
  min-height: 20px;
  margin-top: 8px;
  color: var(--danger);
  font-size: 13px;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 251, 246, 0.9);
  color: var(--ink-1);
  padding: 11px 13px;
  font-size: 14px;
  transition: border-color 0.14s ease, box-shadow 0.14s ease;
}

input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus,
textarea:-webkit-autofill,
textarea:-webkit-autofill:hover,
textarea:-webkit-autofill:focus {
  -webkit-text-fill-color: var(--ink-1);
  box-shadow: 0 0 0 1000px rgba(255, 251, 246, 0.94) inset;
  transition: background-color 9999s ease-in-out 0s;
}

input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--line-strong);
  box-shadow: 0 0 0 3px rgba(204, 161, 125, 0.18);
}

textarea {
  min-height: 46px;
  max-height: 180px;
  line-height: 1.5;
  resize: none;
  overflow-y: hidden;
}

.btn {
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 250, 244, 0.86);
  color: var(--ink-1);
  padding: 10px 14px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.16s ease, border-color 0.16s ease;
}

.btn:hover {
  transform: translateY(-1px);
  border-color: var(--line-strong);
  box-shadow: 0 12px 24px rgba(158, 112, 76, 0.16);
}

.btn.primary {
  color: #fff;
  border-color: rgba(170, 124, 92, 0.94);
  background: linear-gradient(146deg, var(--brand-1), var(--brand-2));
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.tab-btn {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 250, 244, 0.86);
  padding: 10px;
  color: var(--ink-1);
  cursor: pointer;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.tab-btn.active {
  color: #fff;
  background: linear-gradient(146deg, var(--brand-1), var(--brand-2));
}

.auth-tab-icon,
.auth-submit-icon {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
  flex: 0 0 auto;
}

.auth-submit-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.app-shell {
  --sidebar-width: 320px;
  width: 100%;
  height: 100%;
  min-height: 100svh;
  min-height: 100dvh;
  padding:
    max(10px, env(safe-area-inset-top))
    max(10px, env(safe-area-inset-right))
    max(10px, env(safe-area-inset-bottom))
    max(10px, env(safe-area-inset-left));
  display: grid;
  grid-template-columns: minmax(230px, var(--sidebar-width)) 12px minmax(0, 1fr);
  gap: clamp(10px, 1.5vw, 16px);
  animation: shell-in 0.48s ease;
}

.sidebar {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  border-radius: 34px 22px 28px 18px;
  min-height: 0;
}

.sidebar-splitter {
  align-self: stretch;
  justify-self: center;
  width: 12px;
  border-radius: 999px;
  cursor: col-resize;
  position: relative;
  z-index: 4;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.58), rgba(229, 204, 179, 0.72));
  border: 1px solid rgba(193, 156, 125, 0.38);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.38);
}

.sidebar-splitter::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 4px;
  height: 56px;
  transform: translate(-50%, -50%);
  border-radius: 999px;
  background: rgba(164, 124, 91, 0.5);
}

body.resizing-sidebar,
body.resizing-sidebar * {
  cursor: col-resize !important;
  user-select: none !important;
}

.sidebar-top {
  padding: 14px;
  border-bottom: 1px solid var(--line);
  display: grid;
  gap: 10px;
}

.sidebar-menu {
  grid-row: 3;
  display: none;
  gap: 8px;
  padding: 8px 12px 12px;
  border-top: 1px solid rgba(191, 156, 128, 0.28);
  background: linear-gradient(180deg, rgba(255, 250, 243, 0.45), rgba(255, 250, 243, 0.74));
}

.sidebar-icon-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  align-items: stretch;
}

.mobile-theme-wrap {
  display: none;
  gap: 6px;
}

.mobile-theme-wrap label {
  font-size: 12px;
  color: var(--ink-2);
  font-weight: 700;
}

.mobile-theme-wrap select {
  border-radius: 12px;
  padding: 7px 10px;
}

.sidebar-icon-btn {
  width: 100%;
  min-height: 44px;
  height: auto;
  border-radius: 14px;
  padding: 10px 12px;
  display: inline-flex;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  font-size: 14px;
  line-height: 1.2;
}

#mobileAdminBtn,
#mobileLogoutBtn {
  display: none;
}

.mobile-user-badge {
  display: none;
  border-radius: 14px;
  padding: 7px 10px;
  text-align: center;
  font-size: 11px;
  line-height: 1.2;
}

.sidebar-top h2 {
  margin: 0;
  font-family: "Sora", "Noto Sans SC", sans-serif;
  letter-spacing: 0.01em;
}

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

.conversation-item {
  border: 1px solid var(--line);
  border-radius: 20px 14px 20px 12px;
  background: rgba(255, 250, 244, 0.78);
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: start;
  padding: 8px;
}

.conversation-item.active {
  border-color: rgba(177, 131, 96, 0.92);
  box-shadow: 0 0 0 3px rgba(181, 137, 103, 0.18), 0 8px 20px rgba(162, 117, 81, 0.16);
}

.conversation-open {
  border: none;
  background: transparent;
  text-align: left;
  padding: 2px;
  cursor: pointer;
  color: var(--ink-1);
}

.conversation-delete {
  width: 30px;
  height: 30px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 250, 243, 0.94);
  color: var(--danger);
  font-size: 16px;
  cursor: pointer;
}

.conversation-title {
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conversation-meta {
  color: var(--ink-2);
  font-size: 12px;
}

.main-panel {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 10px;
  overflow: hidden;
  position: relative;
}

.chat-watermark {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  display: grid;
  place-content: center;
  gap: 8px;
  color: rgba(124, 95, 74, 0.18);
}

.chat-watermark-icon {
  width: min(240px, 28vw);
  height: auto;
  margin: 0 auto;
  opacity: 0.36;
}

.chat-watermark-text {
  text-align: center;
  font-family: "Sora", "Noto Sans SC", sans-serif;
  font-size: clamp(11px, 1.2vw, 14px);
  letter-spacing: 0.12em;
  color: rgba(124, 95, 74, 0.24);
  text-transform: uppercase;
}

.topbar {
  padding: 11px 14px;
  border-radius: 30px 18px 28px 18px;
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  position: relative;
  z-index: 3;
}

#mobileMenuBtn {
  display: none;
}

.control-group {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  padding: 6px 10px;
  border-radius: 14px;
  border: 1px solid rgba(194, 161, 133, 0.5);
  background: rgba(255, 249, 240, 0.66);
}

.control-group label {
  font-size: 12px;
  color: var(--ink-2);
  font-weight: 700;
  letter-spacing: 0.01em;
}

.control-group select {
  border-radius: 12px;
  padding: 7px 10px;
  min-width: 110px;
}

.topbar-actions {
  margin-left: auto;
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.theme-group {
  min-width: 184px;
}

.theme-group select {
  min-width: 126px;
}

.user-badge {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 11px;
  background: rgba(255, 250, 243, 0.8);
  font-size: 12px;
  font-weight: 700;
}

.status {
  position: absolute;
  right: 18px;
  bottom: -18px;
  font-size: 12px;
  color: var(--ink-2);
}

.icon-btn {
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 250, 243, 0.82);
  color: var(--ink-1);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.icon-btn .icon-svg {
  width: 20px;
  height: 20px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
}

.icon-leading {
  width: 20px;
  height: 20px;
  flex: 0 0 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.icon-with-text {
  width: auto;
  min-height: 38px;
  padding: 0 12px;
  gap: 8px;
  justify-content: flex-start;
}

.icon-text {
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

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

.messages {
  position: relative;
  z-index: 1;
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 0;
  padding: 10px 12px max(14px, calc(18px + var(--messages-bottom-gap)));
  display: grid;
  gap: 9px;
  align-content: start;
  overscroll-behavior-y: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  contain: paint;
}

.empty-state {
  margin: auto;
  color: var(--ink-2);
  text-align: center;
  max-width: 420px;
}

.message {
  justify-self: start;
  width: auto;
  max-width: min(72ch, 92%);
  min-width: 0;
  border-radius: 22px 16px 20px 14px;
  border: 1px solid var(--line);
  background: rgba(255, 251, 246, 0.8);
  padding: 8px 11px;
  line-height: 1.5;
  white-space: normal;
  word-break: break-word;
  box-shadow: 0 10px 24px rgba(158, 113, 77, 0.13);
  animation: rise 0.2s ease;
}

.message.user {
  justify-self: end;
  color: #fff;
  border-color: rgba(170, 120, 88, 0.88);
  border-radius: 16px 22px 14px 20px;
  background: linear-gradient(150deg, var(--user-bubble-1), var(--user-bubble-2));
}

.message-role {
  display: none;
}

.message-content {
  max-width: 100%;
  min-width: 0;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.message-content > :first-child {
  margin-top: 0;
}

.message-content > :last-child {
  margin-bottom: 0;
}

.message-content p,
.message-content ul,
.message-content ol,
.message-content pre,
.message-content blockquote,
.message-content table {
  max-width: 100%;
  min-width: 0;
  margin: 0.46em 0;
}

.message-content ul,
.message-content ol {
  padding-left: 1.2em;
}

.message-content li + li {
  margin-top: 0.2em;
}

.message-content a {
  color: #895636;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.message.user .message-content a {
  color: #fff;
}

.message-content blockquote {
  margin-left: 0;
  padding: 0.36em 0.78em;
  border-left: 3px solid rgba(173, 126, 94, 0.6);
  background: rgba(255, 247, 237, 0.68);
  border-radius: 10px;
}

.message.user .message-content blockquote {
  border-left-color: rgba(255, 255, 255, 0.72);
  background: rgba(255, 255, 255, 0.15);
}

.message-content code {
  font-family: "JetBrains Mono", "Cascadia Code", Consolas, monospace;
  font-size: 0.92em;
  padding: 0.12em 0.35em;
  border-radius: 8px;
  background: rgba(141, 104, 72, 0.12);
  white-space: break-spaces;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.message.user .message-content code {
  background: rgba(255, 255, 255, 0.18);
}

.message-content pre {
  display: block;
  max-width: 100%;
  overflow: auto;
  padding: 0.64em 0.74em;
  border-radius: 12px;
  border: 1px solid rgba(192, 154, 124, 0.45);
  background: rgba(255, 247, 237, 0.9);
}

.message-content pre code {
  display: block;
  padding: 0;
  background: transparent;
  white-space: pre;
  word-break: normal;
  overflow-wrap: normal;
}

.message.user .message-content pre {
  border-color: rgba(255, 255, 255, 0.3);
  background: rgba(255, 255, 255, 0.16);
}

.message-content table {
  width: 100%;
  border-collapse: collapse;
}

.message-content th,
.message-content td {
  border: 1px solid rgba(192, 154, 124, 0.44);
  padding: 0.3em 0.52em;
}

.message.user .message-content th,
.message.user .message-content td {
  border-color: rgba(255, 255, 255, 0.34);
}

.stream-cursor {
  display: inline-block;
  margin-left: 2px;
  opacity: 0.95;
  animation: cursor-blink 0.92s steps(1) infinite;
}

.message-content .katex-display {
  display: block;
  max-width: 100%;
  margin: 0.5em 0;
  overflow-x: auto;
  overflow-y: hidden;
}

.message-content .math-block-source {
  display: block;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
}

.message-content img,
.message-content svg,
.message-content video,
.message-content canvas,
.message-content iframe {
  display: block;
  max-width: 100%;
  height: auto;
}

.message-content .table-scroll {
  display: block;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
}

.message-content .table-scroll table {
  min-width: max-content;
  width: 100%;
  white-space: nowrap;
}

.message-searching {
  margin-top: 6px;
  padding: 7px 9px;
  border-radius: 11px;
  border: 1px solid rgba(192, 154, 124, 0.4);
  background:
    linear-gradient(120deg, rgba(255, 251, 244, 0.88), rgba(255, 245, 235, 0.75)),
    radial-gradient(circle at 0% 50%, rgba(231, 195, 163, 0.5), transparent 42%);
  color: var(--ink-2);
  font-size: 12px;
  line-height: 1.5;
  display: flex;
  align-items: center;
  gap: 8px;
}

.message-searching::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: linear-gradient(150deg, var(--brand-1), var(--brand-2));
  box-shadow: 0 0 0 0 rgba(189, 142, 104, 0.42);
  animation: search-pulse 1.15s ease-out infinite;
  flex: 0 0 8px;
}

.message-files {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

.message-sources {
  margin-top: 8px;
}

.source-heading {
  font-size: 11px;
  color: var(--ink-2);
  font-weight: 700;
  margin-bottom: 5px;
}

.source-list {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
}

.source-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  border: 1px solid rgba(192, 154, 124, 0.45);
  border-radius: 12px;
  padding: 6px 9px;
  text-decoration: none;
  background: rgba(255, 248, 238, 0.78);
  color: var(--ink-1);
  min-width: 0;
}

.source-item:hover {
  border-color: rgba(176, 133, 99, 0.72);
  background: rgba(255, 246, 232, 0.88);
}

.source-title {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.source-domain {
  font-size: 11px;
  color: var(--ink-2);
  white-space: nowrap;
}

.message.user .message-sources {
  display: none;
}

.file-pill {
  border-radius: 999px;
  border: 1px solid rgba(192, 154, 124, 0.72);
  background: rgba(255, 248, 238, 0.9);
  color: var(--ink-1);
  font-size: 12px;
  padding: 2px 8px;
  text-decoration: none;
}

.message.user .file-pill {
  border-color: rgba(245, 227, 210, 0.62);
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
}

.composer-wrap {
  position: relative;
  z-index: 6;
  border-radius: 24px 24px 28px 22px;
  padding: 11px;
  padding-bottom: max(11px, env(safe-area-inset-bottom));
  background: var(--glass-strong);
  display: grid;
  gap: 10px;
}

.pending-files {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 2px;
}

.pending-item {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 248, 237, 0.94);
  padding: 4px 9px;
  font-size: 12px;
  display: inline-flex;
  gap: 6px;
  align-items: center;
}

.pending-item button {
  border: none;
  background: transparent;
  color: var(--danger);
  cursor: pointer;
}

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

.message-input-wrap {
  position: relative;
  min-width: 0;
}

#messageInput {
  min-height: 62px;
  max-height: clamp(170px, 28vh, 240px);
  padding: 13px 108px 13px 15px;
  font-size: 16px;
  font-weight: 400;
  line-height: 1.5;
  letter-spacing: 0;
  color: var(--ink-1);
  background: rgba(255, 252, 247, 0.96);
  border-color: rgba(182, 144, 112, 0.52);
  caret-color: var(--brand-2);
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

.inside-search-btn {
  position: absolute;
  top: 50%;
  right: 58px;
  transform: translateY(-50%);
  width: 40px;
  height: 40px;
  border-radius: 999px;
  border: 1px solid rgba(182, 144, 112, 0.52);
  background: rgba(255, 250, 244, 0.92);
  color: rgba(127, 95, 72, 0.9);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.14s ease, box-shadow 0.16s ease, border-color 0.16s ease, color 0.16s ease, background 0.16s ease;
}

.inside-search-btn.active {
  color: #fff;
  border-color: rgba(170, 124, 92, 0.9);
  background: linear-gradient(146deg, var(--brand-1), var(--brand-2));
  box-shadow: 0 8px 16px rgba(158, 112, 76, 0.16);
}

.inside-search-btn.inactive {
  color: rgba(123, 113, 104, 0.92);
  border-color: rgba(181, 168, 155, 0.66);
  background: rgba(229, 224, 218, 0.94);
  box-shadow: none;
}

.inside-search-btn:hover {
  transform: translateY(-50%) scale(1.03);
  border-color: var(--line-strong);
}

.inside-search-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: translateY(-50%);
  box-shadow: none;
}

.inside-search-icon {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
}

.inside-upload-btn {
  position: absolute;
  top: 50%;
  right: 10px;
  transform: translateY(-50%);
  width: 40px;
  height: 40px;
  border-radius: 999px;
  border: 1px solid rgba(182, 144, 112, 0.52);
  background: rgba(255, 250, 244, 0.92);
  color: var(--ink-1);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.14s ease, box-shadow 0.16s ease, border-color 0.16s ease;
}

.inside-upload-btn:hover {
  transform: translateY(-50%) scale(1.03);
  border-color: var(--line-strong);
  box-shadow: 0 8px 16px rgba(158, 112, 76, 0.16);
}

.inside-upload-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: translateY(-50%);
  box-shadow: none;
}

.inside-upload-icon {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
}

#messageInput::placeholder {
  color: rgba(110, 87, 70, 0.86);
  font-weight: 500;
  opacity: 0.92;
}

#messageInput:focus {
  border-color: rgba(168, 125, 92, 0.86);
  box-shadow:
    0 0 0 3px rgba(197, 156, 123, 0.22),
    0 10px 20px rgba(148, 107, 75, 0.14);
}

.composer-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.send-btn {
  width: 46px;
  height: 46px;
  min-width: 46px;
  border-radius: 999px;
  padding: 0;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.send-btn-icon {
  width: 20px;
  height: 20px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2.1;
  stroke-linecap: round;
  stroke-linejoin: round;
  transform: translateX(0.5px);
  pointer-events: none;
}

.stop-btn {
  min-height: 46px;
  min-width: 92px;
  color: var(--danger);
}

.overlay {
  display: none;
}

.overlay.show {
  display: block;
  position: fixed;
  inset: 0;
  background: rgba(50, 34, 22, 0.24);
  z-index: 30;
}

.service-notice-modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding:
    max(16px, env(safe-area-inset-top))
    max(16px, env(safe-area-inset-right))
    max(16px, env(safe-area-inset-bottom))
    max(16px, env(safe-area-inset-left));
  background: rgba(43, 30, 20, 0.32);
}

.service-notice-card {
  width: min(460px, 94vw);
  border-radius: 24px;
  padding: 16px 16px 14px;
  background: rgba(255, 249, 241, 0.95);
}

.service-notice-card h3 {
  margin: 0;
  font-family: "Sora", "Noto Sans SC", sans-serif;
  font-size: 20px;
}

.service-notice-card p {
  margin: 10px 0 0;
  color: var(--ink-2);
  line-height: 1.55;
  font-size: 14px;
}

.service-notice-actions {
  margin-top: 14px;
  display: flex;
  justify-content: flex-end;
}

.powered-bubble {
  position: fixed;
  left: clamp(10px, 1.7vw, 20px);
  bottom: calc(max(12px, env(safe-area-inset-bottom)) + 2px);
  z-index: 22;
  border-radius: 20px 20px 22px 9px;
  padding: 10px 12px;
  min-width: 128px;
  pointer-events: none;
  transform: rotate(-2.4deg);
  animation: bubble-float 4.6s ease-in-out infinite;
}

.powered-bubble span {
  display: block;
  line-height: 1.1;
  color: var(--ink-1);
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.6);
}

.powered-bubble span:first-child {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--ink-2);
}

.powered-bubble span:last-child {
  margin-top: 3px;
  font-family: "Sora", "Noto Sans SC", sans-serif;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 0.02em;
}

.settings-panel,
.admin-panel {
  position: fixed;
  top: 10px;
  right: 10px;
  bottom: 10px;
  width: min(940px, 94vw);
  z-index: 40;
  padding: 12px;
  display: grid;
  grid-template-rows: auto 1fr;
  animation: slide-in 0.2s ease;
}

.settings-panel {
  width: min(700px, 94vw);
  z-index: 41;
}

.admin-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 4px 10px;
}

.admin-head h3 {
  margin: 0;
  font-family: "Sora", "Noto Sans SC", sans-serif;
}

.settings-body {
  min-height: 0;
  overflow: auto;
  display: grid;
  gap: 10px;
  align-content: start;
  padding-right: 2px;
}

.settings-col,
.admin-col {
  border: 1px solid var(--line);
  border-radius: 20px;
  background: rgba(255, 250, 243, 0.7);
  padding: 10px;
}

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

.settings-col h4,
.admin-col h4 {
  margin: 0;
}

.settings-hint {
  font-size: 12px;
  color: var(--ink-2);
  line-height: 1.4;
}

.settings-grid {
  display: grid;
  grid-template-columns: 108px 1fr;
  gap: 8px;
  align-items: center;
}

.settings-grid label {
  font-size: 13px;
  color: var(--ink-2);
}

.settings-textarea {
  min-height: 120px;
  max-height: 240px;
}

.settings-actions {
  display: flex;
  justify-content: flex-end;
}

.admin-body {
  min-height: 0;
  display: grid;
  grid-template-columns: 220px 300px 1fr;
  gap: 10px;
}

.admin-stack {
  min-height: 0;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 10px;
}

.admin-provider {
  align-content: start;
}

.admin-models-input {
  min-height: 88px;
  max-height: 180px;
}

.admin-provider-status {
  font-size: 12px;
  color: var(--ink-2);
}

.admin-col {
  min-height: 0;
  display: grid;
  grid-template-rows: auto 1fr;
}

.admin-list,
.admin-messages {
  overflow: auto;
  display: grid;
  gap: 7px;
  align-content: start;
}

.admin-item,
.admin-msg {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 250, 243, 0.82);
  padding: 9px;
  font-size: 12px;
  color: var(--ink-1);
}

.admin-item {
  cursor: pointer;
}

.admin-item.active {
  border-color: rgba(177, 133, 97, 0.88);
  box-shadow: 0 0 0 3px rgba(190, 148, 113, 0.2);
}

.admin-msg {
  line-height: 1.52;
}

@keyframes orb-drift {
  from {
    transform: translate(0, 0) scale(1);
  }
  to {
    transform: translate(12px, 14px) scale(1.08);
  }
}

@keyframes float-lilt {
  from {
    transform: translate3d(0, 0, 0);
  }
  to {
    transform: translate3d(-12px, 8px, 0);
  }
}

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

@keyframes slide-in {
  from {
    opacity: 0;
    transform: translateX(20px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes shell-in {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.995);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes cursor-blink {
  0%,
  49% {
    opacity: 0.98;
  }
  50%,
  100% {
    opacity: 0;
  }
}

@keyframes search-pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(189, 142, 104, 0.42);
  }
  70% {
    box-shadow: 0 0 0 8px rgba(189, 142, 104, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(189, 142, 104, 0);
  }
}

@keyframes bubble-float {
  0%,
  100% {
    transform: rotate(-2.4deg) translateY(0);
  }
  50% {
    transform: rotate(-1.6deg) translateY(-4px);
  }
}

@media (max-width: 1180px) {
  .topbar-actions {
    margin-left: 0;
  }

  .status {
    position: static;
    width: 100%;
    order: 99;
  }
}

@media (max-width: 980px) {
  .sidebar {
    grid-template-rows: auto minmax(0, 1fr) auto;
  }

  .sidebar-menu {
    display: grid;
  }

  .app-shell {
    grid-template-columns: 1fr;
    gap: 8px;
    padding:
      max(8px, env(safe-area-inset-top))
      max(8px, env(safe-area-inset-right))
      max(8px, env(safe-area-inset-bottom))
      max(8px, env(safe-area-inset-left));
  }

  .sidebar-splitter {
    display: none;
  }

  #mobileMenuBtn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .mobile-menu-btn {
    display: inline-flex;
    min-height: 46px;
    border-radius: 14px;
    padding: 0 12px;
    justify-content: flex-start;
  }

  .sidebar {
    position: fixed;
    top: max(8px, env(safe-area-inset-top));
    left: max(8px, env(safe-area-inset-left));
    bottom: max(8px, env(safe-area-inset-bottom));
    width: min(360px, 92vw);
    z-index: 35;
    transform: translateX(calc(-100% - 12px));
    transition: transform 0.2s ease;
  }

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

  .topbar {
    border-radius: 22px 14px 20px 14px;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) minmax(0, 1fr);
    align-items: end;
    gap: 7px;
  }

  #mobileMenuBtn {
    grid-column: 1;
    grid-row: 1;
  }

  .control-group {
    width: auto;
    min-width: 0;
  }

  .control-group:nth-of-type(1) {
    grid-column: 2;
    grid-row: 1;
  }

  .control-group:nth-of-type(2) {
    grid-column: 3;
    grid-row: 1;
  }

  .control-group label {
    display: none;
  }

  .control-group select {
    min-width: 0;
  }

  .topbar-actions {
    display: none;
  }

  .status {
    grid-column: 1 / -1;
    grid-row: 2;
  }

  #mobileAdminBtn,
  #mobileLogoutBtn,
  .mobile-user-badge {
    display: inline-flex;
  }

  .mobile-user-badge {
    display: block;
  }

  .mobile-theme-wrap {
    display: grid;
  }

  .sidebar-icon-row {
    align-items: stretch;
  }

  .icon-btn {
    width: 46px;
    height: 46px;
    border-radius: 15px;
    font-size: 18px;
  }

  .mobile-menu-btn {
    width: auto;
    min-width: 78px;
    padding: 0 12px;
  }

  .sidebar-icon-btn {
    width: 100%;
    min-height: 46px;
    height: auto;
    flex: 1 1 auto;
    border-radius: 14px;
    padding: 10px 12px;
    justify-content: flex-start;
    gap: 10px;
  }

  .btn {
    min-height: 44px;
    padding: 11px 14px;
  }

  .mobile-theme-wrap select {
    min-height: 44px;
    font-size: 14px;
  }

  .messages {
    padding: 10px 10px 14px;
  }

  .chat-watermark-icon {
    width: min(180px, 46vw);
    opacity: 0.3;
  }

  .chat-watermark-text {
    font-size: 11px;
    letter-spacing: 0.1em;
  }

  .message {
    max-width: min(95%, calc(100vw - 26px));
  }

  .composer-wrap {
    border-radius: 22px 22px 24px 18px;
    padding: 10px;
    padding-bottom: max(10px, env(safe-area-inset-bottom));
  }

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

  .composer-actions {
    justify-content: center;
    width: auto;
  }

  .composer-actions .stop-btn {
    width: 100%;
  }

  .send-btn {
    width: 54px;
    height: 54px;
    min-width: 54px;
  }

  .send-btn-icon {
    width: 22px;
    height: 22px;
  }

  .stop-btn {
    min-height: 50px;
    min-width: 106px;
  }

  .control-group select {
    min-height: 42px;
    font-size: 14px;
  }

  .settings-panel,
  .admin-panel {
    left: max(8px, env(safe-area-inset-left));
    right: max(8px, env(safe-area-inset-right));
    top: max(8px, env(safe-area-inset-top));
    bottom: max(8px, env(safe-area-inset-bottom));
    width: auto;
  }

  .service-notice-card {
    width: min(520px, 96vw);
    padding: 14px 14px 12px;
    border-radius: 22px;
  }

  .service-notice-card h3 {
    font-size: 18px;
  }

  .service-notice-card p {
    font-size: 13px;
  }

  .service-notice-actions .btn {
    min-height: 42px;
    padding: 9px 14px;
  }

  .admin-body {
    grid-template-columns: 1fr;
    grid-template-rows: 170px 210px 1fr;
  }

  .admin-stack {
    grid-template-rows: auto 1fr;
  }

  .settings-grid {
    grid-template-columns: 1fr;
  }

  .powered-bubble {
    display: none;
  }
}

@media (max-width: 640px) {
  .auth-card {
    padding: 20px;
  }

  .topbar-actions .btn {
    padding: 9px 11px;
  }

  .user-badge {
    padding: 6px 9px;
  }

  .control-group {
    width: auto;
  }

  .composer-actions {
    width: auto;
  }

  .powered-bubble {
    display: none;
  }
}

@media (max-width: 980px) {
  .auth-screen {
    min-height: var(--app-vh, 100dvh);
    display: flex;
    align-items: center;
    justify-content: center;
    padding:
      max(12px, env(safe-area-inset-top))
      max(12px, env(safe-area-inset-right))
      max(14px, env(safe-area-inset-bottom))
      max(12px, env(safe-area-inset-left));
  }

  .auth-card {
    width: min(560px, 100%);
    margin-top: 0;
    padding: clamp(18px, 4.6vw, 26px);
    border-radius: 30px 24px 30px 20px;
    background:
      radial-gradient(120% 84% at 14% 0%, rgba(255, 255, 255, 0.62), transparent 58%),
      linear-gradient(150deg, rgba(255, 251, 246, 0.94), rgba(255, 248, 241, 0.88));
  }

  .auth-card h1 {
    font-size: clamp(32px, 8.2vw, 46px);
    line-height: 1.05;
    margin-bottom: 10px;
    letter-spacing: 0.01em;
  }

  .auth-card p {
    margin: 0 0 12px;
    font-size: clamp(15px, 3.8vw, 19px);
    line-height: 1.45;
  }

  .auth-intro {
    margin: 0 0 14px;
    gap: 8px;
    font-size: clamp(14px, 3.5vw, 17px);
    line-height: 1.45;
  }

  .auth-intro div {
    padding-left: 13px;
  }

  .auth-tabs {
    gap: 10px;
    margin-bottom: 12px;
  }

  .tab-btn {
    min-height: 46px;
    border-radius: 18px;
    font-size: clamp(16px, 4.2vw, 18px);
  }

  .auth-form {
    gap: 10px;
  }

  .auth-form input {
    min-height: 52px;
    padding: 0 16px;
    border-radius: 20px;
    font-size: clamp(17px, 4.4vw, 19px);
    line-height: 1.2;
  }

  .auth-form .btn.primary {
    min-height: 50px;
    border-radius: 22px;
    font-size: clamp(17px, 4.3vw, 19px);
    letter-spacing: 0.01em;
  }

  .auth-error {
    min-height: 24px;
    font-size: 14px;
    line-height: 1.4;
    margin-top: 4px;
  }
}

@media (max-height: 760px) {
  .topbar {
    padding: 9px 12px;
  }

  #messageInput {
    min-height: 58px;
    font-size: 16px;
    line-height: 1.5;
    max-height: 156px;
  }

  .powered-bubble {
    opacity: 0.78;
  }
}

/* ===== Viewport Hardening + Admin Tabs Overrides ===== */
:root {
  --app-vh: 100dvh;
  --messages-bottom-gap: 0px;
}

html,
body {
  height: var(--app-vh);
}

body {
  min-height: var(--app-vh);
}

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

.main-panel {
  height: 100%;
}

.messages {
  padding-bottom: max(14px, calc(18px + var(--messages-bottom-gap)));
}

.admin-tabs {
  display: flex;
  gap: 8px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 250, 243, 0.72);
  overflow-x: auto;
}

.admin-tab-btn {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 251, 245, 0.82);
  color: var(--ink-1);
  padding: 7px 12px;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
}

.admin-tab-btn.active {
  color: #fff;
  border-color: rgba(170, 124, 92, 0.94);
  background: linear-gradient(146deg, var(--brand-1), var(--brand-2));
}

.admin-pages {
  min-height: 0;
  display: grid;
}

.admin-page {
  display: none;
  min-height: 0;
  overflow: auto;
}

.admin-page.active {
  display: grid;
}

.admin-stack {
  grid-template-rows: auto minmax(0, 1fr);
}

@media (max-width: 980px) {
  .app-shell {
    height: var(--app-vh);
    min-height: var(--app-vh);
  }

  .sidebar {
    height: calc(var(--app-vh) - max(8px, env(safe-area-inset-top)) - max(8px, env(safe-area-inset-bottom)));
  }

  #messageInput {
    padding-right: 112px;
  }

  .inside-search-btn {
    width: 44px;
    height: 44px;
    right: 60px;
  }

  .inside-upload-btn {
    width: 44px;
    height: 44px;
    right: 8px;
  }

  .inside-upload-icon {
    width: 20px;
    height: 20px;
  }

  .inside-search-icon {
    width: 20px;
    height: 20px;
  }

  .mobile-upload-collapsed .pending-files {
    display: none;
  }

  .admin-tabs {
    position: sticky;
    top: 0;
    z-index: 2;
  }
}
