:root {
  color-scheme: light;
  --bg: #eef2f6;
  --panel: #ffffff;
  --panel-soft: #f8fafc;
  --line: #d8e0e8;
  --text: #1d2633;
  --muted: #64748b;
  --accent: #0f8f7a;
  --accent-dark: #087462;
  --accent-soft: #def7f1;
  --warm: #f59e0b;
  --user: #dff3ff;
  --admin: #eefdf5;
  --shadow: 0 18px 48px rgba(31, 41, 55, 0.14);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(135deg, rgba(15, 143, 122, 0.14), transparent 36%),
    linear-gradient(225deg, rgba(245, 158, 11, 0.13), transparent 34%),
    var(--bg);
  color: var(--text);
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
  border-radius: 7px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  padding: 10px 14px;
  transition: background 0.16s ease, transform 0.16s ease, box-shadow 0.16s ease;
}

button:hover {
  background: var(--accent-dark);
  transform: translateY(-1px);
}

input,
select {
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 11px 12px;
  background: #fff;
  color: var(--text);
  outline: none;
  transition: border-color 0.16s ease, box-shadow 0.16s ease;
}

input:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 143, 122, 0.14);
}

.hidden {
  display: none !important;
}

.chat-shell {
  width: min(820px, calc(100% - 28px));
  height: calc(100vh - 28px);
  margin: 14px auto;
  display: grid;
  grid-template-rows: auto 1fr auto;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(216, 224, 232, 0.9);
  border-radius: 8px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.topbar {
  min-height: 72px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: linear-gradient(180deg, #ffffff, #f9fbfd);
}

.brand-block,
.top-actions,
.session-top {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-dot {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 5px var(--accent-soft), 0 0 24px rgba(15, 143, 122, 0.6);
  flex: 0 0 auto;
}

.brand-block h1,
.login-panel h1 {
  margin: 0;
  font-size: 20px;
  line-height: 1.1;
}

.brand-block p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.icon-button {
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--accent);
  position: relative;
}

.icon-button:hover {
  background: var(--accent-soft);
}

.icon-button::before,
.icon-button::after {
  content: "";
  position: absolute;
}

.icon-button::before {
  width: 10px;
  height: 14px;
  left: 11px;
  top: 13px;
  background: currentColor;
  clip-path: polygon(0 32%, 38% 32%, 100% 0, 100% 100%, 38% 68%, 0 68%);
}

.icon-button::after {
  width: 9px;
  height: 16px;
  left: 21px;
  top: 11px;
  border: 2px solid currentColor;
  border-left: 0;
  border-top-color: transparent;
  border-bottom-color: transparent;
  border-radius: 50%;
}

.icon-button.is-muted {
  color: #94a3b8;
}

.icon-button.is-muted::after {
  width: 18px;
  height: 2px;
  left: 12px;
  top: 19px;
  border: 0;
  border-radius: 2px;
  background: currentColor;
  transform: rotate(-38deg);
}

.messages {
  overflow-y: auto;
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background:
    linear-gradient(180deg, rgba(248, 250, 252, 0.74), rgba(255, 255, 255, 0.5)),
    var(--panel-soft);
}

.message {
  max-width: min(540px, 86%);
  border: 1px solid rgba(216, 224, 232, 0.9);
  border-radius: 8px;
  padding: 11px 13px;
  background: #fff;
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.06);
  animation: message-in 0.18s ease-out;
}

@keyframes message-in {
  from {
    opacity: 0;
    transform: translateY(5px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.message p {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.5;
}

.message img {
  display: block;
  max-width: 280px;
  max-height: 280px;
  border-radius: 7px;
}

.message.user {
  align-self: flex-end;
  background: linear-gradient(180deg, #e7f7ff, var(--user));
  border-color: #b8e6fb;
}

.message.admin {
  align-self: flex-start;
  background: linear-gradient(180deg, #f7fff9, var(--admin));
  border-color: #bcebd0;
}

.composer {
  padding: 14px;
  border-top: 1px solid var(--line);
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 9px;
  background: #fff;
}

.file-button {
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 11px 13px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
}

.file-button:hover {
  background: var(--panel-soft);
}

.file-button input {
  display: none;
}

.send-button {
  min-width: 76px;
  box-shadow: 0 8px 20px rgba(15, 143, 122, 0.22);
}

.system-error,
.error-text {
  color: #b42318;
}

.admin-shell {
  min-height: 100vh;
}

.login-panel {
  width: min(390px, calc(100% - 32px));
  margin: 12vh auto 0;
  padding: 26px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.login-form,
.stack-form {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.admin-panel {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
  background: rgba(255, 255, 255, 0.72);
}

.admin-grid {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr) 270px;
  min-height: 0;
}

.sessions-pane,
.tools-pane {
  border-right: 1px solid var(--line);
  padding: 14px;
  background: rgba(255, 255, 255, 0.86);
  overflow-y: auto;
}

.tools-pane {
  border-left: 1px solid var(--line);
  border-right: 0;
}

.tools-pane h2 {
  margin: 0 0 12px;
  font-size: 16px;
}

.conversation-pane {
  min-height: 0;
  display: grid;
  grid-template-rows: auto 1fr auto;
  background: #fff;
}

.active-session {
  min-height: 50px;
  padding: 15px 18px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  background: #fbfcfe;
}

.sessions {
  display: grid;
  gap: 9px;
  margin-top: 12px;
}

.session-item {
  width: 100%;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  display: grid;
  gap: 5px;
  box-shadow: 0 6px 16px rgba(15, 23, 42, 0.05);
}

.session-item:hover,
.session-item.active {
  border-color: var(--accent);
  background: #f0fbf8;
}

.session-top {
  justify-content: space-between;
}

.session-top em {
  min-width: 24px;
  height: 22px;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-style: normal;
  font-size: 12px;
  text-align: center;
}

.session-item span,
.session-item small,
.muted {
  color: var(--muted);
}

.session-item small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.button-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

@media (max-width: 900px) {
  .chat-shell {
    width: 100%;
    height: 100vh;
    margin: 0;
    border-radius: 0;
    border-left: 0;
    border-right: 0;
  }

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

  .sessions-pane,
  .tools-pane {
    border: 0;
    border-bottom: 1px solid var(--line);
    max-height: 260px;
  }

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

/* Admin conversation direction fix */
.admin-page .conversation-pane .message.user {
  align-self: flex-start;
  background: linear-gradient(180deg, #e7f7ff, var(--user));
  border-color: #b8e6fb;
}

.admin-page .conversation-pane .message.admin {
  align-self: flex-end;
  background: linear-gradient(180deg, #f7fff9, var(--admin));
  border-color: #bcebd0;
}

.meiqia-shell {
  width: min(1380px, 100%);
  height: min(100vh, 900px);
  margin: 0 auto;
  border-radius: 8px;
}

.meiqia-header {
  min-height: 168px;
  padding: 34px 72px 28px;
  background: #0b82f3;
  color: #fff;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
}

.meiqia-header h1 {
  margin: 0;
  font-size: 36px;
  line-height: 1.2;
  font-weight: 800;
}

.meiqia-header p {
  margin: 10px 0 0;
  font-size: 26px;
  line-height: 1.25;
  font-weight: 700;
}

.meiqia-header .icon-button,
.meiqia-header select {
  border-color: rgba(255,255,255,.36);
}

.meiqia-body {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 370px;
}

.meiqia-chat {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: 1fr auto;
  background: #eef1f6;
  border-right: 1px solid #d8dde8;
}

.meiqia-chat .messages {
  background: #eef1f6;
  padding: 28px 34px;
}

.system-message-block {
  display: grid;
  justify-items: start;
  gap: 8px;
}

.system-message-block time {
  color: #98a2b3;
  font-size: 24px;
}

.system-message-block strong {
  color: #596273;
  font-size: 25px;
}

.system-message-block .message {
  max-width: min(600px, 86%);
  font-size: 26px;
  font-weight: 700;
  line-height: 1.55;
  color: #171d2a;
  background: #e2e5eb;
  border-color: transparent;
  box-shadow: none;
}

.rich-composer {
  margin: 0 22px 18px;
  min-height: 126px;
  border: 1px solid #d9dee8;
  border-radius: 14px;
  grid-template-columns: 1fr;
  align-content: space-between;
  box-shadow: 0 8px 22px rgba(20, 35, 55, .08);
}

.rich-composer input[type="text"] {
  border: 0;
  box-shadow: none;
  font-size: 26px;
  padding: 12px 22px;
}

.composer-tools {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.composer-tools .file-button {
  border: 0;
  font-size: 22px;
}

.rich-composer .send-button {
  min-width: 144px;
  min-height: 64px;
  border-radius: 14px;
  font-size: 26px;
  font-weight: 800;
  background: #62a2ff;
}

.faq-panel {
  background: #fff;
  min-height: 0;
  overflow-y: auto;
}

.faq-panel h2 {
  margin: 0;
  padding: 26px 24px;
  font-size: 28px;
  color: #0f2552;
  border-bottom: 3px solid #1688ff;
  box-shadow: 0 14px 24px rgba(16, 24, 40, .14);
}

.faq-list {
  display: grid;
  padding: 0 10px;
}

.faq-item {
  min-height: 67px;
  border-radius: 0;
  border-bottom: 1px solid #d8dde6;
  background: #fff;
  color: #3f4a5d;
  text-align: left;
  font-size: 25px;
  font-weight: 700;
  padding: 14px 16px;
  transform: none;
}

.faq-item:hover {
  background: #f2f7ff;
  color: #0b82f3;
  transform: none;
}

.settings-form textarea {
  min-height: 76px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 10px 12px;
  font: inherit;
}

.admin-page .conversation-pane .message.customer-message {
  align-self: flex-start !important;
  background: linear-gradient(180deg, #e7f7ff, var(--user));
  border-color: #b8e6fb;
}

.admin-page .conversation-pane .message.support-message {
  align-self: flex-end !important;
  background: linear-gradient(180deg, #f7fff9, var(--admin));
  border-color: #bcebd0;
}

.client-page {
  overflow: hidden;
}

.client-page .meiqia-shell {
  width: min(1380px, 100vw) !important;
  height: 100vh !important;
  margin: 0 auto !important;
  display: grid !important;
  grid-template-rows: auto minmax(0, 1fr) !important;
  background: #fff !important;
  border: 1px solid rgba(10, 132, 255, .24) !important;
  border-radius: 8px !important;
}

.client-page .meiqia-header {
  min-height: 168px !important;
  background: #0b82f3 !important;
  color: #fff !important;
}

.client-page .meiqia-header h1,
.client-page .meiqia-header p {
  color: #fff !important;
}

.client-page .meiqia-body {
  min-height: 0 !important;
  display: grid !important;
  grid-template-columns: minmax(0, 1fr) 370px !important;
}

.client-page .meiqia-chat {
  min-height: 0 !important;
}

.client-page .faq-panel {
  display: block !important;
}

@media (max-width: 980px) {
  .meiqia-header {
    padding: 24px 18px;
  }

  .meiqia-header h1 {
    font-size: 26px;
  }

  .meiqia-header p,
  .rich-composer input[type="text"],
  .faq-item,
  .system-message-block .message {
    font-size: 18px;
  }

  .meiqia-body {
    grid-template-columns: 1fr;
  }

  .faq-panel {
    display: none;
  }
}
