:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --line: #dfe4ea;
  --text: #20242a;
  --muted: #6a7280;
  --green: #19a15f;
  --blue: #246bfe;
  --red: #e44646;
  --bubble: #eef2f7;
  --mine: #d9f8e8;
  --sidebar: 300px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  color: var(--text);
  background: var(--bg);
}

button,
input,
textarea {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

.client-page {
  min-height: 100vh;
  min-height: 100dvh;
  background: linear-gradient(180deg, #eef6ff 0, #f7f7f5 38%, #f5f6f8 100%);
}

.phone-shell {
  display: grid;
  grid-template-rows: auto 1fr auto;
  width: min(760px, 100%);
  height: 100vh;
  height: 100dvh;
  margin: 0 auto;
  background: var(--panel);
}

.client-top,
.desk-top,
.admin-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 64px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.92);
}

.client-top strong,
.desk-top strong,
.admin-head strong {
  display: block;
  font-size: 18px;
}

.client-top span,
.desk-top span,
.admin-head span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 13px;
}

.online-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 5px rgba(25, 161, 95, 0.12);
}

.messages {
  overflow-y: auto;
  padding: 18px;
}

.bubble-row {
  display: flex;
  margin: 10px 0;
}

.bubble-row.mine {
  justify-content: flex-end;
}

.bubble {
  max-width: min(72%, 560px);
  padding: 10px 12px 7px;
  border-radius: 8px;
  background: var(--bubble);
  box-shadow: 0 1px 2px rgba(20, 30, 40, 0.06);
}

.bubble-row.mine .bubble {
  background: var(--mine);
}

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

.bubble time {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 11px;
  text-align: right;
}

.composer {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  padding: 12px max(14px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
  border-top: 1px solid var(--line);
  background: var(--panel);
}

.composer textarea {
  width: 100%;
  min-height: 42px;
  max-height: 120px;
  resize: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  outline: none;
}

.composer textarea:focus {
  border-color: var(--blue);
}

.composer button,
.login-box button,
.entry-link button,
.desk-top button,
.icon-button {
  min-width: 72px;
  border-radius: 8px;
  padding: 0 16px;
  color: #fff;
  background: var(--blue);
}

.tool-button {
  width: 42px;
  min-width: 42px !important;
  height: 42px;
  padding: 0 !important;
  border: 1px solid var(--line);
  color: var(--blue) !important;
  background: #fff !important;
  font-size: 24px;
  line-height: 1;
}

.login-page {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 18px;
}

.login-box {
  display: grid;
  gap: 14px;
  width: min(380px, 100%);
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 12px 34px rgba(20, 30, 40, 0.08);
}

.login-box h1 {
  margin: 0 0 8px;
  font-size: 24px;
}

.login-box label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 14px;
}

.login-box input {
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
}

.login-box button {
  height: 44px;
}

#loginError {
  min-height: 20px;
  margin: 0;
  color: var(--red);
}

.admin-page {
  display: grid;
  grid-template-columns: var(--sidebar) minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: #edf1f5;
}

.sidebar {
  display: grid;
  grid-template-rows: auto auto 1fr;
  min-width: 0;
  border-right: 1px solid var(--line);
  background: var(--panel);
  min-height: 0;
}

.icon-button {
  min-width: auto;
  height: 36px;
}

.entry-link {
  display: grid;
  gap: 8px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}

.entry-link label {
  color: var(--muted);
  font-size: 13px;
}

.entry-link button {
  height: 34px;
}

.entry-link code {
  display: block;
  overflow: hidden;
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.session-list {
  overflow-y: auto;
  min-height: 0;
}

.session-item {
  position: relative;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 5px 10px;
  width: 100%;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  color: var(--text);
  text-align: left;
  background: var(--panel);
}

.session-item.active {
  background: #eef6ff;
}

.session-item.unread .session-title {
  color: var(--blue);
  font-weight: 700;
}

.session-title,
.session-preview {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.session-time,
.session-preview {
  color: var(--muted);
  font-size: 12px;
}

.session-preview {
  grid-column: 1 / 3;
}

.session-item b {
  position: absolute;
  top: 14px;
  right: 18px;
  min-width: 20px;
  height: 20px;
  border-radius: 10px;
  color: #fff;
  background: var(--red);
  font-size: 12px;
  line-height: 20px;
  text-align: center;
}

.desk {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-width: 0;
  min-height: 0;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: #f3f6f9;
}

.desk-top button {
  height: 36px;
  background: #4b5563;
}

.desk-top button:disabled,
.composer button:disabled,
.composer textarea:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.desk-messages {
  padding: 18px 22px;
  min-height: 0;
  overflow-y: auto;
}

.admin-composer {
  position: sticky;
  bottom: 0;
  padding: 10px 12px;
  border-top: 1px solid #d8dee6;
  background: #fff;
  box-shadow: 0 -6px 18px rgba(20, 30, 40, 0.05);
}

.admin-composer textarea {
  min-height: 40px;
  max-height: 86px;
}

.chat-image {
  display: block;
  max-width: min(320px, 64vw);
  max-height: 360px;
  border-radius: 7px;
  object-fit: contain;
  cursor: zoom-in;
}

.recall-button {
  display: block;
  min-width: auto !important;
  margin-top: 5px;
  padding: 0 !important;
  color: var(--muted) !important;
  background: transparent !important;
  font-size: 12px;
  text-align: right;
}

.recall-button:hover {
  color: var(--red) !important;
}

.recalled {
  color: var(--muted);
  font-style: italic;
}

.image-viewer {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(8, 12, 18, 0.82);
}

.image-viewer[hidden] {
  display: none;
}

.image-viewer img {
  max-width: 96vw;
  max-height: 92vh;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 18px 80px rgba(0, 0, 0, 0.45);
  object-fit: contain;
}

.image-viewer button {
  position: fixed;
  top: 18px;
  right: 22px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  color: #fff;
  background: rgba(255, 255, 255, 0.16);
  font-size: 30px;
  line-height: 1;
}

@media (max-width: 820px) {
  .admin-page {
    grid-template-columns: 1fr;
    grid-template-rows: 36vh 64vh;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .entry-link {
    display: none;
  }

  .admin-head,
  .desk-top {
    min-height: 58px;
    padding: 10px 14px;
  }

  .session-item {
    padding: 12px 14px;
  }

  .desk-messages,
  .messages {
    padding: 14px;
  }

  .bubble {
    max-width: 84%;
  }

  .chat-image {
    max-width: 68vw;
  }

  .composer {
    gap: 8px;
  }

  .composer button {
    min-width: 60px;
    padding: 0 12px;
  }
}
