:root {
  color-scheme: light;
  --bg: #ffffff;
  --canvas: #f7f7f5;
  --sidebar: #f9f9f7;
  --ink: #0d0d0d;
  --muted: #6b6b6b;
  --faint: #8f8f8b;
  --line: #e5e5df;
  --line-strong: #d7d7d0;
  --panel: #ffffff;
  --panel-soft: #f4f4f0;
  --blue: #2563eb;
  --teal: #0f766e;
  --green: #10a37f;
  --coral: #e86f51;
  --amber: #d97706;
  --danger: #dc2626;
  --shadow: 0 24px 70px rgba(15, 23, 42, 0.14);
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled,
textarea:disabled {
  cursor: default;
}

svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

input,
textarea {
  width: 100%;
  color: var(--ink);
  outline: none;
}

input::placeholder,
textarea::placeholder {
  color: #8a8a85;
}

.hidden {
  display: none !important;
}

.error {
  min-height: 20px;
  margin: 12px 0 0;
  color: var(--danger);
  font-size: 14px;
  line-height: 1.45;
}

.primary,
.ghost,
.small,
.new-chat,
.send,
.icon-button,
.side-action,
.nav-login,
.entry-submit,
.head-menu {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 0;
  font-weight: 650;
}

.primary {
  min-height: 46px;
  border-radius: 8px;
  color: white;
  background: var(--ink);
  padding: 0 16px;
}

.ghost {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: #343431;
  background: white;
  padding: 0 14px;
}

.full {
  width: 100%;
}

.small {
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: #343431;
  background: white;
}

.danger-small {
  color: var(--danger);
}

label {
  display: grid;
  gap: 8px;
}

label span {
  color: #44443f;
  font-size: 13px;
  font-weight: 700;
}

.form,
.invite-grid {
  display: grid;
  gap: 14px;
}

.form input,
.invite-grid input {
  height: 46px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.form input:focus,
.invite-grid input:focus {
  border-color: rgba(16, 163, 127, 0.7);
  box-shadow: 0 0 0 4px rgba(16, 163, 127, 0.12);
}

/* Entry */
.entry-shell {
  position: relative;
  min-height: 100vh;
  overflow: hidden;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.96), rgba(247, 247, 245, 0.96)),
    repeating-linear-gradient(90deg, rgba(13, 13, 13, 0.035) 0 1px, transparent 1px 86px),
    repeating-linear-gradient(0deg, rgba(13, 13, 13, 0.025) 0 1px, transparent 1px 86px);
}

.entry-shell::before {
  content: "";
  position: absolute;
  inset: -26%;
  background:
    conic-gradient(from 70deg at 50% 50%, rgba(16, 163, 127, 0.18), rgba(37, 99, 235, 0.13), rgba(232, 111, 81, 0.12), rgba(16, 163, 127, 0.18));
  filter: blur(70px);
  opacity: 0.58;
  animation: turnField 18s linear infinite;
}

.entry-nav {
  position: relative;
  z-index: 2;
  height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
}

.brand-button {
  display: inline-flex;
  align-items: center;
  min-height: 42px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
}

.brand-button strong {
  font-size: 18px;
  letter-spacing: 0;
}

.nav-login {
  height: 40px;
  min-width: 78px;
  padding: 0 18px;
  border-radius: 999px;
  color: white;
  background: #0d0d0d;
}

.entry-stage {
  position: relative;
  z-index: 1;
  min-height: calc(100vh - 72px);
  display: grid;
  align-content: center;
  justify-items: center;
  padding: 24px 20px 12vh;
}

.entry-emblem {
  width: 151px;
  height: 47px;
  display: grid;
  place-items: center;
  margin-bottom: 28px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: transparent;
  box-shadow: none;
  backdrop-filter: none;
  animation: floatMark 5s ease-in-out infinite;
}

.entry-emblem img {
  display: block;
  width: 151px;
  height: 47px;
  object-fit: contain;
}

.entry-stage h1 {
  margin: 0 0 28px;
  color: #242421;
  font-size: 30px;
  font-weight: 600;
  line-height: 1.15;
  text-align: center;
}

.entry-auth {
  width: min(430px, calc(100vw - 34px));
  display: grid;
  gap: 12px;
}

.entry-tabs {
  width: 100%;
  height: 42px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  border: 1px solid rgba(13, 13, 13, 0.1);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.86);
  backdrop-filter: blur(22px);
}

.entry-tab {
  min-width: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: #5f5f5a;
  font-size: 14px;
  font-weight: 650;
}

.entry-tab.active {
  background: #0d0d0d;
  color: white;
}

.entry-account-form {
  min-width: 0;
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px solid rgba(13, 13, 13, 0.1);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 24px 70px rgba(15, 23, 42, 0.12);
  backdrop-filter: blur(22px);
}

.entry-account-form input {
  min-width: 0;
  height: 48px;
  padding: 0 14px;
  border: 1px solid rgba(13, 13, 13, 0.1);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.78);
  font-size: 15px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.entry-account-form input:focus {
  border-color: rgba(13, 13, 13, 0.3);
  background: white;
  box-shadow: 0 0 0 4px rgba(13, 13, 13, 0.08);
}

.entry-account-submit {
  height: 48px;
  border: 0;
  border-radius: 8px;
  background: #0d0d0d;
  color: white;
  font-size: 15px;
  font-weight: 700;
  transition: transform 0.16s ease, background 0.16s ease;
}

.entry-account-submit:hover {
  transform: translateY(-1px);
  background: #232320;
}

.entry-error {
  width: min(720px, calc(100vw - 40px));
  text-align: center;
}

.motion-field {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.motion-line {
  position: absolute;
  left: 12%;
  width: 76%;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(13, 13, 13, 0.2), transparent);
  opacity: 0.42;
  transform: rotate(-12deg);
  animation: driftLine 10s ease-in-out infinite;
}

.line-a {
  top: 28%;
}

.line-b {
  top: 48%;
  animation-delay: -3s;
  opacity: 0.34;
}

.line-c {
  top: 68%;
  animation-delay: -6s;
  opacity: 0.28;
}

.admin-modal {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 20px;
}

.modal-scrim {
  position: absolute;
  inset: 0;
  border: 0;
  background: rgba(13, 13, 13, 0.28);
  backdrop-filter: blur(8px);
}

.admin-login-card {
  position: relative;
  width: min(420px, calc(100vw - 34px));
  padding: 18px;
  border: 1px solid rgba(255, 255, 255, 0.68);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.95);
  box-shadow: var(--shadow);
}

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

.modal-head span {
  color: var(--muted);
  font-size: 13px;
}

.modal-head h2 {
  margin: 3px 0 0;
  font-size: 24px;
  line-height: 1.2;
}

/* Admin */
.shell {
  width: min(1180px, calc(100vw - 32px));
  min-height: 100vh;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 250px 1fr;
  align-items: start;
  gap: 24px;
  padding: 28px 0;
}

.brand-panel {
  position: sticky;
  top: 28px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--ink);
  color: white;
  margin-bottom: 18px;
}

.brand-panel h1 {
  margin: 0;
  font-size: 32px;
  line-height: 1;
}

.admin-panel {
  padding: 22px;
  border: 1px solid rgba(13, 13, 13, 0.08);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 18px 60px rgba(15, 23, 42, 0.09);
}

.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 22px;
}

.panel-head h2,
.panel-head p,
.admin-panel h3 {
  margin: 0;
}

.panel-head h2 {
  font-size: 26px;
}

.panel-head p {
  color: var(--muted);
  margin-top: 6px;
  line-height: 1.55;
}

.invite-grid {
  grid-template-columns: minmax(180px, 2fr) repeat(3, minmax(150px, 1fr)) auto;
  align-items: end;
  padding: 16px;
  background: var(--panel-soft);
  border-radius: 8px;
  margin-bottom: 16px;
}

.new-invite {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-radius: 8px;
  background: #ecfdf5;
  color: #064e3b;
  margin-bottom: 18px;
}

.new-invite strong {
  font-size: 24px;
  letter-spacing: 0.08em;
}

.icon-button {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  color: #064e3b;
  background: white;
}

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

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 14px;
}

.section-head h3 {
  margin: 0;
}

.section-head span {
  color: var(--muted);
  font-size: 13px;
}

.history-panel {
  margin-top: 22px;
}

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

.history-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  overflow: hidden;
}

.history-item summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 70px;
  padding: 14px;
  cursor: pointer;
}

.history-item summary::marker {
  color: var(--muted);
}

.history-item summary div {
  display: grid;
  gap: 4px;
}

.history-item summary span,
.history-item summary small {
  color: var(--muted);
  font-size: 13px;
}

.history-messages {
  display: grid;
  gap: 10px;
  padding: 0 14px 14px;
  border-top: 1px solid var(--line);
  background: #f8fafc;
}

.history-message {
  margin-top: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
}

.history-message header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.history-message header span {
  color: var(--muted);
  font-size: 12px;
}

.history-message p {
  margin: 0;
  color: #1f2937;
  line-height: 1.65;
  white-space: normal;
  overflow-wrap: anywhere;
}

.history-message.user {
  border-color: rgba(37, 99, 235, 0.24);
}

.history-message.assistant {
  border-color: rgba(16, 163, 127, 0.24);
}

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

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 72px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
}

.row div {
  display: grid;
  gap: 4px;
}

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

.row span,
.row small {
  color: var(--muted);
  font-size: 13px;
}

.empty {
  color: var(--muted);
}

/* Chat */
.chat-shell {
  height: 100vh;
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  background: var(--bg);
}

.sidebar {
  min-width: 0;
  display: grid;
  grid-template-rows: auto auto 1fr auto auto;
  gap: 12px;
  padding: 12px;
  background: var(--sidebar);
}

.side-brand {
  min-height: 42px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 6px;
}

.side-logo {
  width: 54px;
  height: 18px;
  flex: 0 0 auto;
  object-fit: contain;
}

.side-brand-text {
  min-width: 0;
  display: grid;
  gap: 1px;
}

.side-brand strong {
  font-size: 15px;
}

.side-brand span,
.quota small,
.quota span {
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.new-chat {
  height: 40px;
  justify-content: flex-start;
  padding: 0 12px;
  border-radius: 8px;
  color: #22221f;
  background: transparent;
}

.new-chat:hover,
.side-action:hover,
.conv:hover,
.conv.active {
  background: #eeeeea;
}

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

.conversation-list .empty {
  padding: 10px 12px;
  font-size: 13px;
}

.conv {
  display: grid;
  gap: 3px;
  width: 100%;
  min-height: 48px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  padding: 8px 10px;
  text-align: left;
}

.conv span {
  min-width: 0;
  overflow: hidden;
  font-size: 14px;
  font-weight: 500;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conv small {
  overflow: hidden;
  color: var(--muted);
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.quota {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  min-height: 42px;
  padding: 10px 12px;
  border-top: 1px solid var(--line);
}

.side-action {
  height: 40px;
  justify-content: flex-start;
  padding: 0 12px;
  border-radius: 8px;
  color: #343431;
  background: transparent;
}

.chat-main {
  min-width: 0;
  height: 100vh;
  display: grid;
  grid-template-rows: 56px minmax(0, 1fr) auto;
  background: white;
}

.chat-head {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  padding: 0 18px;
}

.chat-head h2 {
  min-width: 0;
  overflow: hidden;
  margin: 0;
  color: #343431;
  font-size: 18px;
  font-weight: 600;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.head-menu {
  display: none;
  width: 38px;
  height: 38px;
  border-radius: 8px;
  color: #343431;
  background: transparent;
}

.messages {
  min-height: 0;
  overflow: auto;
  padding: 18px 20px 34px;
  scroll-behavior: smooth;
}

.message-column {
  width: min(768px, 100%);
  min-height: 100%;
  margin: 0 auto;
  display: grid;
  align-content: start;
  gap: 22px;
}

.message {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  min-width: 0;
}

.message.user {
  justify-content: flex-end;
}

.message.assistant {
  justify-content: flex-start;
}

.message-avatar {
  width: 48px;
  height: 16px;
  flex: 0 0 auto;
  object-fit: contain;
  margin-top: 8px;
}

.bubble {
  max-width: min(690px, 100%);
  overflow-wrap: anywhere;
  white-space: normal;
  color: var(--ink);
  font-size: 16px;
  line-height: 1.72;
}

.message.user .bubble {
  max-width: min(610px, 78%);
  padding: 10px 16px;
  border-radius: 22px;
  background: #f1f1ee;
  line-height: 1.55;
}

.message.assistant .bubble {
  padding: 2px 0;
}

.typing-cursor {
  display: inline-block;
  width: 7px;
  height: 1.1em;
  margin-left: 2px;
  border-radius: 8px;
  background: #343431;
  vertical-align: -0.18em;
  animation: cursorBlink 1s steps(2, start) infinite;
}

.thinking-state {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 32px;
  color: #6f6f6a;
  font-size: 15px;
  line-height: 1;
}

.thinking-state span {
  margin-right: 2px;
}

.thinking-state i {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.35;
  animation: thinkingDot 1.2s ease-in-out infinite;
}

.thinking-state i:nth-child(3) {
  animation-delay: 0.16s;
}

.thinking-state i:nth-child(4) {
  animation-delay: 0.32s;
}

.empty-chat {
  min-height: calc(100vh - 260px);
  display: grid;
  place-items: center;
  color: #343431;
  text-align: center;
}

.empty-chat h3 {
  margin: 0;
  font-size: 30px;
  font-weight: 600;
  line-height: 1.2;
}

.composer-wrap {
  padding: 0 20px 24px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0), #ffffff 32%);
}

.composer {
  width: min(768px, 100%);
  min-height: 58px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 1fr 38px;
  align-items: end;
  gap: 10px;
  padding: 10px 10px 10px 18px;
  border: 1px solid var(--line-strong);
  border-radius: 30px;
  background: white;
  box-shadow: 0 8px 28px rgba(15, 23, 42, 0.08);
}

.composer:focus-within {
  border-color: #c8c8c0;
  box-shadow: 0 10px 34px rgba(15, 23, 42, 0.12);
}

.composer textarea {
  height: 38px;
  min-height: 38px;
  max-height: 190px;
  resize: none;
  border: 0;
  background: transparent;
  padding: 7px 0;
  line-height: 1.5;
}

.composer.busy textarea {
  color: var(--faint);
}

.send {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  color: white;
  background: #0d0d0d;
  transition: background 0.16s ease, transform 0.16s ease;
}

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

.send:disabled {
  opacity: 0.38;
}

@keyframes turnField {
  to {
    transform: rotate(360deg);
  }
}

@keyframes driftLine {
  0%,
  100% {
    transform: translateX(-7%) rotate(-12deg);
  }
  50% {
    transform: translateX(7%) rotate(-12deg);
  }
}

@keyframes floatMark {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-8px);
  }
}

@keyframes cursorBlink {
  0%,
  45% {
    opacity: 1;
  }
  46%,
  100% {
    opacity: 0;
  }
}

@keyframes thinkingDot {
  0%,
  80%,
  100% {
    transform: translateY(0);
    opacity: 0.35;
  }
  40% {
    transform: translateY(-4px);
    opacity: 0.92;
  }
}

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

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

  .brand-panel {
    position: static;
  }

  .invite-grid,
  .columns {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 820px) {
  .chat-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    display: none;
  }

  .chat-shell.sidebar-open .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 8;
    width: min(310px, 86vw);
    display: grid;
    box-shadow: 18px 0 44px rgba(15, 23, 42, 0.18);
  }

  .chat-main {
    grid-template-rows: 56px minmax(0, 1fr) auto;
  }

  .head-menu {
    display: inline-flex;
  }

  .messages {
    padding-left: 16px;
    padding-right: 16px;
  }

  .message.user .bubble {
    max-width: 86%;
  }
}

@media (max-width: 560px) {
  .entry-nav {
    padding: 0 16px;
  }

  .entry-stage {
    align-content: start;
    padding-top: 14vh;
  }

  .entry-stage h1,
  .empty-chat h3 {
    font-size: 26px;
  }

  .entry-auth,
  .entry-error {
    width: calc(100vw - 24px);
  }

  .admin-login-card {
    width: calc(100vw - 24px);
  }

  .shell {
    width: calc(100vw - 22px);
    padding: 14px 0;
  }

  .admin-panel {
    padding: 16px;
  }

  .panel-head,
  .history-item summary,
  .row {
    align-items: flex-start;
    flex-direction: column;
  }

  .chat-head {
    padding: 0 12px;
  }

  .composer-wrap {
    padding: 0 10px 12px;
  }

  .composer {
    border-radius: 26px;
    padding-left: 14px;
  }
}
