:root {
  --bg: #eef3ef;
  --surface: #ffffff;
  --surface-soft: #f7f9f6;
  --ink: #17312f;
  --muted: #657674;
  --line: #d9e1dc;
  --teal: #176f68;
  --teal-deep: #11544f;
  --coral: #d85e48;
  --coral-soft: #fbe7e1;
  --gold: #c88a2d;
  --blue: #4c6fa8;
  --shadow: 0 12px 32px rgba(27, 58, 54, 0.1);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

* {
  box-sizing: border-box;
}

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

body {
  background: var(--bg);
  color: var(--ink);
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  color: inherit;
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: 3px solid rgba(23, 111, 104, 0.22);
  outline-offset: 2px;
}

[hidden] {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.icon-sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

svg {
  display: block;
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.app-shell {
  min-height: 100dvh;
}

.side-nav {
  display: none;
}

.mobile-header {
  position: sticky;
  z-index: 20;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: calc(64px + var(--safe-top));
  padding: calc(10px + var(--safe-top)) 16px 10px;
  background: rgba(243, 246, 242, 0.94);
  border-bottom: 1px solid rgba(217, 225, 220, 0.82);
  backdrop-filter: blur(16px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
}

.brand img {
  width: 42px;
  height: 42px;
  border-radius: 12px;
}

.brand div {
  display: grid;
  min-width: 0;
}

.brand strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 16px;
}

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

.brand.compact img {
  width: 38px;
  height: 38px;
  border-radius: 10px;
}

.status-toggle {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 36px;
  padding: 7px 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  cursor: pointer;
}

.status-toggle > span:first-child {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: #2e9b73;
  box-shadow: 0 0 0 4px rgba(46, 155, 115, 0.12);
}

.status-toggle[aria-pressed="true"] > span:first-child {
  background: var(--coral);
  box-shadow: 0 0 0 4px rgba(216, 94, 72, 0.13);
}

.status-toggle-label {
  font-size: 13px;
  font-weight: 650;
}

.main-content {
  width: 100%;
}

.view {
  display: none;
  min-height: calc(100dvh - 64px - var(--safe-top));
  padding: 16px 16px calc(104px + var(--safe-bottom));
}

.view.active {
  display: block;
}

#view-chat.active {
  display: flex;
  flex-direction: column;
  padding: 12px 12px calc(90px + var(--safe-bottom));
}

.identity-banner {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  max-width: 760px;
  margin: 0 auto 14px;
  padding: 10px 12px;
  color: #745121;
  background: #fff7e8;
  border: 1px solid #efdfbd;
  border-radius: 8px;
}

.identity-banner p {
  margin: 0;
  font-size: 13px;
  line-height: 1.45;
}

.ai-dot {
  flex: 0 0 auto;
  width: 8px;
  height: 8px;
  margin-top: 6px;
  border-radius: 999px;
  background: var(--gold);
}

.messages {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  max-width: 760px;
  min-height: 240px;
  margin: 0 auto;
  padding: 8px 0 28px;
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 220px;
  padding: 30px;
  color: var(--muted);
  text-align: center;
}

.empty-state strong {
  display: block;
  margin-bottom: 5px;
  color: var(--ink);
  font-size: 17px;
}

.empty-state p {
  max-width: 320px;
  margin: 0;
  font-size: 14px;
}

.message-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  animation: message-in 180ms ease-out;
}

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

.bot-avatar {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 30px;
  height: 30px;
  border: 1px solid #c6d9d3;
  border-radius: 9px;
  color: var(--teal);
  background: #eaf4f0;
  font-size: 12px;
  font-weight: 800;
}

.message-stack {
  display: grid;
  max-width: min(78%, 560px);
  gap: 4px;
}

.message-row.user .message-stack {
  justify-items: end;
}

.message-bubble {
  padding: 10px 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 3px 12px rgba(27, 58, 54, 0.055);
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.message-row.user .message-bubble {
  color: #ffffff;
  background: var(--teal);
  border-color: var(--teal);
  border-bottom-right-radius: 3px;
}

.message-row.assistant .message-bubble {
  border-bottom-left-radius: 3px;
}

.message-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 16px;
  padding: 0 3px;
  color: var(--muted);
  font-size: 11px;
}

.message-action {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 0;
  border: 0;
  color: var(--teal);
  background: transparent;
  cursor: pointer;
  font-size: 11px;
}

.message-action svg {
  width: 13px;
  height: 13px;
}

.typing-row {
  display: flex;
  gap: 4px;
  width: calc(100% - 24px);
  max-width: 736px;
  margin: 0 auto 12px;
  padding: 0 0 0 42px;
}

.typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: var(--teal);
  animation: typing 1s ease-in-out infinite;
}

.typing-dot:nth-child(2) {
  animation-delay: 140ms;
}

.typing-dot:nth-child(3) {
  animation-delay: 280ms;
}

.composer {
  position: sticky;
  z-index: 12;
  bottom: 0;
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) 44px;
  gap: 8px;
  width: calc(100% + 24px);
  max-width: 784px;
  margin: 0 -12px -82px;
  padding: 10px 12px calc(10px + var(--safe-bottom));
  background: rgba(238, 243, 239, 0.96);
  border-top: 1px solid rgba(217, 225, 220, 0.86);
  backdrop-filter: blur(18px);
}

.message-input {
  display: flex;
  align-items: center;
  min-height: 44px;
  padding: 4px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.message-input textarea {
  width: 100%;
  max-height: 126px;
  padding: 8px 0;
  border: 0;
  outline: 0;
  resize: none;
  background: transparent;
  color: var(--ink);
  line-height: 1.45;
}

.icon-button,
.send-button {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  cursor: pointer;
}

.icon-button:hover {
  border-color: #b8c9c3;
  background: var(--surface-soft);
}

.send-button {
  width: 44px;
  height: 44px;
  color: #ffffff;
  background: var(--coral);
  border-color: var(--coral);
}

.send-button:hover {
  background: #c84f3a;
}

.icon-button:disabled,
.send-button:disabled {
  cursor: wait;
  opacity: 0.55;
}

.icon-button.recording {
  color: #ffffff;
  background: var(--coral);
  border-color: var(--coral);
  animation: pulse 1.4s infinite;
}

.section-toolbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 14px;
  width: 100%;
  max-width: 760px;
  margin: 4px auto 18px;
}

.eyebrow {
  margin: 0 0 2px;
  color: var(--coral);
  font-size: 12px;
  font-weight: 750;
}

h1,
h2,
p {
  margin-top: 0;
}

.section-toolbar h1 {
  margin: 0;
  font-size: 24px;
  line-height: 1.2;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 42px;
  padding: 9px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
  font-weight: 650;
}

.button.primary {
  color: #ffffff;
  background: var(--teal);
  border-color: var(--teal);
}

.button.primary:hover {
  background: var(--teal-deep);
}

.button.secondary {
  background: var(--surface);
}

.button.wide {
  width: 100%;
}

.compact-button {
  min-height: 38px;
  padding: 7px 12px;
}

.search-bar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 42px;
  gap: 8px;
  width: 100%;
  max-width: 760px;
  margin: 0 auto 14px;
}

.search-bar input {
  width: 100%;
  min-height: 42px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.item-list {
  display: grid;
  gap: 10px;
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
}

.memory-item,
.relay-item {
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 3px 12px rgba(27, 58, 54, 0.04);
}

.item-head,
.item-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.item-head {
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
}

.chip {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  border-radius: 999px;
  color: var(--teal-deep);
  background: #e7f2ef;
  font-size: 12px;
  font-weight: 700;
}

.item-text {
  margin: 0 0 10px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.item-note {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 13px;
  white-space: pre-wrap;
}

.item-actions {
  justify-content: flex-end;
}

.item-actions .icon-button {
  width: 34px;
  height: 34px;
}

.relay-item.pending {
  border-left: 4px solid var(--coral);
}

.relay-item.done,
.relay-item.notified {
  border-left: 4px solid var(--teal);
}

.relay-item.ignored {
  opacity: 0.66;
}

.settings-group {
  width: 100%;
  max-width: 760px;
  margin: 0 auto 14px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 66px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

.setting-row:last-child {
  border-bottom: 0;
}

.setting-row > span {
  display: grid;
  gap: 2px;
}

.setting-row strong {
  font-size: 15px;
}

.setting-row small {
  color: var(--muted);
  font-size: 12px;
}

.setting-row.static {
  min-height: 60px;
}

.switch {
  position: relative;
  flex: 0 0 auto;
  width: 48px;
  height: 28px;
  margin: 0;
  appearance: none;
  border: 1px solid #b9c7c2;
  border-radius: 999px;
  background: #d7dfdb;
  cursor: pointer;
  transition:
    background 160ms,
    border-color 160ms;
}

.switch::after {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 999px;
  background: #ffffff;
  box-shadow: 0 2px 5px rgba(20, 45, 42, 0.2);
  content: "";
  transition: transform 160ms;
}

.switch:checked {
  background: var(--teal);
  border-color: var(--teal);
}

.switch:checked::after {
  transform: translateX(20px);
}

.settings-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
}

.setting-actions-inline {
  display: flex;
  flex: 0 0 auto;
  gap: 7px;
}

.bottom-nav {
  position: fixed;
  z-index: 30;
  right: 0;
  bottom: 0;
  left: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  min-height: calc(66px + var(--safe-bottom));
  padding: 6px 8px var(--safe-bottom);
  border-top: 1px solid rgba(217, 225, 220, 0.94);
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(18px);
}

.bottom-nav-item {
  position: relative;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 2px;
  min-height: 52px;
  padding: 4px;
  border: 0;
  border-radius: 8px;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
  font-size: 11px;
}

.bottom-nav-item svg {
  width: 21px;
  height: 21px;
}

.bottom-nav-item.active {
  color: var(--teal);
  background: #edf6f3;
}

.nav-badge {
  position: absolute;
  top: 0;
  right: calc(50% - 20px);
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border: 2px solid var(--surface);
  border-radius: 999px;
  color: #ffffff;
  background: var(--coral);
  font-size: 10px;
  font-weight: 750;
  line-height: 14px;
  text-align: center;
}

.auth-gate {
  position: fixed;
  z-index: 100;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 22px;
  background: var(--bg);
}

.auth-panel {
  display: grid;
  width: min(100%, 390px);
  padding: 26px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.auth-mark {
  width: 60px;
  height: 60px;
  margin-bottom: 16px;
  border-radius: 16px;
}

.auth-panel h1 {
  margin-bottom: 4px;
  font-size: 24px;
}

.auth-panel > p {
  margin-bottom: 18px;
  color: var(--muted);
  font-size: 14px;
}

.auth-panel label,
.dialog label {
  display: grid;
  gap: 6px;
  margin-bottom: 14px;
}

.auth-panel label span,
.dialog label span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

.auth-panel input,
.dialog input,
.dialog textarea,
.dialog select {
  width: 100%;
  min-height: 44px;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: var(--surface);
}

.dialog textarea {
  resize: vertical;
}

.form-error {
  min-height: 20px;
  margin: 10px 0 0;
  color: #b23b34;
  font-size: 13px;
}

.dialog {
  width: min(92vw, 520px);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 22px 60px rgba(21, 49, 46, 0.24);
}

.dialog::backdrop {
  background: rgba(17, 42, 40, 0.42);
  backdrop-filter: blur(2px);
}

.dialog form {
  padding: 18px;
}

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.dialog-header h2 {
  margin: 0;
  font-size: 20px;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 4px;
}

.toast {
  position: fixed;
  z-index: 120;
  right: 16px;
  bottom: calc(82px + var(--safe-bottom));
  left: 16px;
  width: fit-content;
  max-width: min(92vw, 560px);
  margin: 0 auto;
  padding: 11px 14px;
  border: 1px solid #c8d7d2;
  border-radius: 8px;
  color: #ffffff;
  background: #203c3a;
  box-shadow: var(--shadow);
  font-size: 13px;
}

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

@keyframes typing {
  0%,
  60%,
  100% {
    transform: translateY(0);
    opacity: 0.45;
  }
  30% {
    transform: translateY(-4px);
    opacity: 1;
  }
}

@keyframes pulse {
  50% {
    box-shadow: 0 0 0 7px rgba(216, 94, 72, 0.14);
  }
}

@media (min-width: 900px) {
  .app-shell {
    display: grid;
    grid-template-columns: 224px minmax(0, 1fr);
  }

  .side-nav {
    position: sticky;
    top: 0;
    display: flex;
    flex-direction: column;
    height: 100dvh;
    padding: 24px 16px;
    border-right: 1px solid var(--line);
    background: #f7faf7;
  }

  .side-nav .brand {
    padding: 0 8px 24px;
  }

  .nav-list {
    display: grid;
    gap: 5px;
  }

  .nav-item {
    position: relative;
    display: flex;
    align-items: center;
    gap: 11px;
    min-height: 46px;
    padding: 9px 11px;
    border: 0;
    border-radius: 8px;
    color: var(--muted);
    background: transparent;
    cursor: pointer;
    text-align: left;
    font-weight: 650;
  }

  .nav-item:hover {
    background: #eaf2ee;
  }

  .nav-item.active {
    color: var(--teal-deep);
    background: #e2f0ec;
  }

  .mobile-header,
  .bottom-nav {
    display: none;
  }

  .main-content {
    min-width: 0;
  }

  .view {
    min-height: 100dvh;
    padding: 30px 36px 40px;
  }

  #view-chat.active {
    min-height: 100dvh;
    padding: 20px 28px 24px;
  }

  .messages {
    padding-bottom: 86px;
  }

  .composer {
    bottom: 16px;
    width: 100%;
    max-width: 784px;
    margin: -74px auto 0;
    padding: 10px 0;
    background: transparent;
    border-top: 0;
    backdrop-filter: none;
  }

  .typing-row {
    width: 100%;
    max-width: 760px;
  }

  .toast {
    right: 28px;
    bottom: 28px;
    left: auto;
  }
}

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