@import url("https://fonts.googleapis.com/css2?family=Noto+Sans:wght@400;500;700&family=Noto+Sans+TC:wght@400;500;700&display=swap");

:root {
  color-scheme: light;
  --bg: #f6f7fb;
  --panel: #ffffff;
  --line: #d9dce5;
  --text: #111111;
  --muted: #6d7280;
  --bubble-user: #2f6cf6;
  --bubble-peer: #eff1f6;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: "Noto Sans", "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
  background: radial-gradient(circle at 16% 10%, #eef3ff 0%, #f8f9fd 42%, #f1f2f8 100%);
  color: var(--text);
}

body.a11y-mode,
body.a11y-mode h1,
body.a11y-mode h2,
body.a11y-mode h3,
body.a11y-mode button,
body.a11y-mode input {
  font-family: "Noto Sans", "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
}

h1,
h2,
h3,
p {
  margin: 0;
}

.ig-shell {
  width: 100%;
  height: 100vh;
  display: grid;
  grid-template-columns: 340px 1fr;
  overflow: hidden;
}

.ig-inbox,
.dm-panel {
  background: var(--panel);
}

.ig-inbox {
  border-right: 1px solid var(--line);
  display: grid;
  grid-template-rows: auto auto 1fr auto;
}

.inbox-head {
  padding: 18px 16px 12px;
}

.inbox-head-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.inbox-head h1 {
  font-size: 1.7rem;
  font-weight: 700;
}

.back-link {
  color: #2f6cf6;
  font-size: 0.88rem;
  text-decoration: none;
  white-space: nowrap;
}

.back-link:hover {
  text-decoration: underline;
}

.msg-headline {
  padding: 2px 16px 10px;
  font-size: 1.4rem;
  font-weight: 700;
}

.thread-list {
  padding: 8px;
  overflow: auto;
}

.thread {
  padding: 10px;
  border-radius: 12px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: center;
}

.active-thread {
  background: #f3f5fb;
}

.avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 700;
  color: #111;
}

.avatar.photo {
  background: #f6d76a;
}

.thread-copy {
  min-width: 0;
}

.thread-name {
  font-size: 0.95rem;
  font-weight: 600;
}

.thread-preview {
  color: var(--muted);
  font-size: 0.83rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.thread-preview:empty::before {
  content: "開始一段新對話";
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #2cd46b;
}

.rail-foot {
  padding: 12px;
  border-top: 1px solid var(--line);
}

.meta-row {
  font-size: 0.78rem;
  color: var(--muted);
  margin-bottom: 5px;
}

.control-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 8px;
}

.ghost-btn {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #ffffff;
  color: var(--text);
  padding: 8px 10px;
  cursor: pointer;
}

.ghost-btn:hover {
  background: #f3f5fa;
}

.dm-panel {
  display: grid;
  grid-template-rows: auto 1fr auto;
}

.dm-top {
  border-bottom: 1px solid var(--line);
  padding: 14px 18px;
}

.dm-user {
  display: flex;
  align-items: center;
  gap: 12px;
}

.dm-user h2 {
  font-size: 1.05rem;
}

.dm-user p {
  color: var(--muted);
  font-size: 0.86rem;
  margin-top: 2px;
}

.messages {
  padding: 16px 22px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.welcome-card {
  border: 1px solid #e6e9f2;
  border-radius: 14px;
  background: #fbfcff;
  padding: 14px;
}

.welcome-card h3 {
  font-size: 0.98rem;
  margin-bottom: 6px;
}

.welcome-card p {
  font-size: 0.9rem;
  color: var(--muted);
}

.message {
  max-width: min(78%, 520px);
  border-radius: 16px;
  padding: 10px 12px;
  line-height: 1.45;
  word-break: break-word;
}

.message.user {
  align-self: flex-end;
  background: var(--bubble-user);
  color: #fff;
  border-bottom-right-radius: 6px;
}

.message.assistant {
  align-self: flex-start;
  background: var(--bubble-peer);
  color: #111;
  border-bottom-left-radius: 6px;
}

.message.system {
  align-self: center;
  background: #fff6de;
  border: 1px solid #f0ddaa;
  color: #7a5a00;
}

.typing {
  display: inline-flex;
  gap: 5px;
  align-items: center;
}

.typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #838aa2;
  animation: bounce 0.9s infinite ease-in-out;
}

.typing span:nth-child(2) {
  animation-delay: 0.15s;
}

.typing span:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes bounce {
  0%,
  80%,
  100% {
    transform: translateY(0);
    opacity: 0.45;
  }
  40% {
    transform: translateY(-4px);
    opacity: 1;
  }
}

.composer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  padding: 14px 18px;
  border-top: 1px solid var(--line);
}

.composer input {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 10px 14px;
  font-size: 0.95rem;
}

.composer input:focus {
  outline: 2px solid #b6cbff;
  outline-offset: 1px;
}

.composer button {
  border: none;
  border-radius: 999px;
  background: #2f6cf6;
  color: #fff;
  font-weight: 600;
  min-width: 90px;
  cursor: pointer;
}

.composer button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

@media (max-width: 980px) {
  .ig-shell {
    grid-template-columns: 64px 300px 1fr;
  }
}

@media (max-width: 840px) {
  .ig-shell {
    grid-template-columns: 1fr;
  }

  .ig-left-nav,
  .ig-inbox {
    display: none;
  }

  .dm-panel {
    height: 100vh;
  }

  .messages {
    padding: 14px;
  }

  .message {
    max-width: 88%;
  }
}
