:root {
  color-scheme: light;
  --bg: #f5f7f6;
  --panel: #ffffff;
  --panel-soft: #eef4f2;
  --ink: #142126;
  --muted: #66777b;
  --line: rgba(20, 33, 38, 0.12);
  --line-strong: rgba(20, 33, 38, 0.18);
  --teal: #147f86;
  --teal-dark: #0d5f67;
  --coral: #e2604f;
  --gold: #d7a440;
  --blue: #3a67c7;
  --danger: #bb3b2f;
  --shadow: 0 22px 70px rgba(20, 33, 38, 0.12);
}

* {
  box-sizing: border-box;
}

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

body {
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(20, 127, 134, 0.08), rgba(255, 255, 255, 0) 36%),
    var(--bg);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  letter-spacing: 0;
}

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

button,
select {
  cursor: pointer;
}

button:disabled,
textarea:disabled {
  cursor: not-allowed;
}

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

.is-hidden {
  display: none !important;
}

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

.auth-view {
  height: 100svh;
  display: grid;
  place-items: center;
  padding: 28px;
  overflow: hidden;
}

.auth-shell {
  width: min(920px, 100%);
  min-height: 500px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.auth-copy {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 16px;
  padding: 42px;
  color: #fff;
  background:
    linear-gradient(135deg, rgba(20, 33, 38, 0.94), rgba(20, 127, 134, 0.76)),
    linear-gradient(45deg, rgba(226, 96, 79, 0.7), rgba(215, 164, 64, 0.42));
}

.brand-mark {
  width: max-content;
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  padding: 0 10px;
  border: 1px solid currentColor;
  border-radius: 4px;
  font-size: 13px;
  font-weight: 850;
  letter-spacing: 0;
}

.brand-mark.compact {
  min-height: 30px;
  font-size: 12px;
}

.auth-copy h1 {
  margin: 0;
  font-size: 64px;
  line-height: 0.94;
  letter-spacing: 0;
}

.auth-copy p {
  margin: 0;
  color: rgba(255, 255, 255, 0.78);
  font-size: 18px;
}

.login-panel {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 18px;
  padding: 38px;
}

.pattern-lock {
  width: min(284px, 100%);
  aspect-ratio: 1;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 22px;
  place-self: center;
  position: relative;
  padding: 12px;
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(20, 127, 134, 0.08), rgba(255, 255, 255, 0));
  touch-action: none;
  user-select: none;
}

.pattern-lines {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.pattern-lines polyline {
  fill: none;
  stroke: var(--teal);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 4.5;
}

.pattern-dot {
  width: 100%;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  position: relative;
  z-index: 1;
  border: 1px solid transparent;
  border-radius: 999px;
  background: transparent;
  color: transparent;
  font-size: 0;
  transition:
    background 0.16s ease,
    border-color 0.16s ease,
    transform 0.16s ease;
}

.pattern-dot::after {
  content: "";
  width: 17px;
  height: 17px;
  border: 2px solid rgba(20, 33, 38, 0.36);
  border-radius: 999px;
  background: #fff;
  box-shadow: 0 2px 8px rgba(20, 33, 38, 0.08);
  transition:
    width 0.16s ease,
    height 0.16s ease,
    background 0.16s ease,
    border-color 0.16s ease;
}

.pattern-dot.is-active {
  background: rgba(20, 127, 134, 0.08);
  transform: scale(0.94);
}

.pattern-dot.is-active::after {
  width: 24px;
  height: 24px;
  border-color: var(--teal);
  background: var(--teal);
}

.pattern-lock.is-error .pattern-dot.is-active {
  background: rgba(187, 59, 47, 0.08);
}

.pattern-lock.is-error .pattern-dot.is-active::after {
  border-color: var(--danger);
  background: var(--danger);
}

.pattern-lock.is-error .pattern-lines polyline {
  stroke: var(--danger);
}

.field,
.select-field {
  display: grid;
  gap: 8px;
}

.field span,
.select-field span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.field input,
.select-field select,
.mobile-actions select {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  outline: none;
}

.field input,
.select-field select {
  padding: 0 12px;
}

.field input:focus,
.select-field select:focus,
.mobile-actions select:focus,
textarea:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(20, 127, 134, 0.12);
}

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

.primary-button,
.ghost-button,
.icon-button,
.send-button,
.prompt-chip {
  border: 0;
  border-radius: 6px;
  transition:
    transform 0.16s ease,
    background 0.16s ease,
    border-color 0.16s ease,
    color 0.16s ease;
}

.primary-button:active,
.ghost-button:active,
.icon-button:active,
.send-button:active,
.prompt-chip:active {
  transform: translateY(1px);
}

.primary-button {
  min-height: 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 0 18px;
  background: var(--teal);
  color: #fff;
  font-weight: 800;
}

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

.app-shell {
  height: 100svh;
  display: grid;
  grid-template-columns: 292px minmax(0, 1fr);
}

.sidebar {
  min-width: 0;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto auto;
  gap: 18px;
  padding: 24px;
  border-right: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: blur(16px);
}

.session-section {
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 10px;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

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

.mini-button {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
}

.mini-button:hover {
  border-color: rgba(20, 127, 134, 0.32);
  background: var(--panel-soft);
}

.session-list {
  min-height: 0;
  display: grid;
  align-content: start;
  gap: 8px;
  overflow-y: auto;
  padding-right: 2px;
}

.session-item {
  width: 100%;
  min-height: 58px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 34px;
  gap: 8px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.78);
  color: var(--ink);
}

.session-open-button {
  min-width: 0;
  display: grid;
  gap: 5px;
  align-content: center;
  border: 0;
  background: transparent;
  color: inherit;
  padding: 4px 6px;
  text-align: left;
}

.session-open-button strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
}

.session-open-button span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.session-delete-button {
  width: 34px;
  min-height: 44px;
  display: grid;
  place-items: center;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
}

.session-delete-button span {
  display: none;
  font-size: 12px;
  font-weight: 850;
}

.session-item:hover,
.session-item.is-active {
  border-color: rgba(20, 127, 134, 0.35);
  background: #fff;
}

.session-item.is-active {
  box-shadow: inset 3px 0 0 var(--teal);
}

.session-delete-button:hover {
  border-color: rgba(187, 59, 47, 0.24);
  background: rgba(187, 59, 47, 0.08);
  color: var(--danger);
}

.session-item.is-confirm-delete {
  border-color: rgba(187, 59, 47, 0.34);
}

.session-item.is-confirm-delete .session-delete-button {
  background: var(--danger);
  color: #fff;
}

.session-item.is-confirm-delete .session-delete-button .trash-icon {
  display: none;
}

.session-item.is-confirm-delete .session-delete-button span {
  display: block;
}

.sidebar-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.sidebar-title {
  margin: 12px 0 0;
  font-size: 28px;
  font-weight: 850;
  line-height: 1;
}

.status-badge {
  min-height: 26px;
  display: inline-flex;
  align-items: center;
  padding: 0 9px;
  border: 1px solid rgba(20, 127, 134, 0.22);
  border-radius: 999px;
  background: rgba(20, 127, 134, 0.1);
  color: var(--teal-dark);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.session-summary {
  min-height: 126px;
  align-self: start;
  display: grid;
  gap: 10px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(215, 164, 64, 0.1), rgba(255, 255, 255, 0)),
    #fff;
}

.session-summary span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.session-summary strong {
  font-size: 22px;
  line-height: 1.1;
}

.session-summary p {
  min-width: 0;
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.sidebar-actions {
  display: grid;
  gap: 10px;
}

.ghost-button {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  padding: 0 12px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  font-weight: 750;
}

.ghost-button:hover,
.icon-button:hover,
.prompt-chip:hover {
  border-color: rgba(20, 127, 134, 0.32);
  background: var(--panel-soft);
}

.chat-area {
  min-width: 0;
  height: 100svh;
  display: grid;
  grid-template-rows: 1fr auto;
  position: relative;
}

.mobile-bar {
  display: none;
}

.mobile-session-strip {
  display: none;
}

.messages {
  min-height: 0;
  overflow-y: auto;
  padding: 38px max(24px, calc((100vw - 1050px) / 2)) 28px;
  scroll-behavior: smooth;
}

.message-row {
  display: grid;
  grid-template-columns: 42px minmax(0, 780px);
  gap: 12px;
  margin: 0 auto 18px;
  justify-content: center;
}

.message-row.user {
  grid-template-columns: minmax(0, 780px) 42px;
}

.avatar {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  font-size: 12px;
  font-weight: 850;
}

.message-row.user .avatar {
  grid-column: 2;
  background: var(--teal);
}

.message-row.user .bubble {
  grid-column: 1;
  grid-row: 1;
  justify-self: end;
  background: #fff;
}

.bubble {
  min-width: 0;
  max-width: 100%;
  padding: 15px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.82);
  box-shadow: 0 8px 30px rgba(20, 33, 38, 0.05);
}

.bubble-text {
  margin: 0;
  color: var(--ink);
  font-size: 15px;
  line-height: 1.72;
  overflow-wrap: anywhere;
  white-space: normal;
}

.bubble-text p,
.bubble-text ul,
.bubble-text ol,
.bubble-text blockquote {
  margin: 0 0 12px;
}

.bubble-text p:last-child,
.bubble-text ul:last-child,
.bubble-text ol:last-child,
.bubble-text blockquote:last-child,
.bubble-text pre:last-child {
  margin-bottom: 0;
}

.bubble-text h3,
.bubble-text h4,
.bubble-text h5,
.bubble-text h6 {
  margin: 2px 0 10px;
  font-size: 16px;
  line-height: 1.35;
}

.bubble-text ul,
.bubble-text ol {
  padding-left: 22px;
}

.bubble-text li + li {
  margin-top: 4px;
}

.bubble-text blockquote {
  padding: 8px 12px;
  border-left: 3px solid var(--teal);
  background: rgba(20, 127, 134, 0.08);
  color: var(--muted);
}

.bubble-text hr {
  height: 1px;
  margin: 14px 0;
  border: 0;
  background: var(--line);
}

.bubble-text a {
  color: var(--blue);
  text-decoration: none;
  border-bottom: 1px solid rgba(58, 103, 199, 0.35);
}

.bubble-text pre {
  margin: 12px 0;
  padding: 14px;
  overflow: auto;
  border-radius: 6px;
  background: #101a1f;
  color: #edf4f2;
  white-space: pre;
}

.bubble-text code {
  font-family:
    "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 13px;
}

.bubble-text :not(pre) > code {
  padding: 2px 5px;
  border-radius: 4px;
  background: rgba(20, 33, 38, 0.08);
  color: var(--teal-dark);
}

.message-row.pending .bubble-text::after {
  content: "";
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-left: 6px;
  border-radius: 999px;
  background: var(--coral);
  animation: blink 0.9s infinite;
}

@keyframes blink {
  0%,
  100% {
    opacity: 0.25;
  }
  50% {
    opacity: 1;
  }
}

.empty-state {
  width: min(780px, calc(100% - 48px));
  position: absolute;
  left: 50%;
  top: 45%;
  transform: translate(-50%, -50%);
  display: grid;
  gap: 20px;
  text-align: center;
  pointer-events: none;
}

.empty-state h2 {
  margin: 0;
  color: var(--ink);
  font-size: 40px;
  line-height: 1.05;
  letter-spacing: 0;
}

.prompt-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  pointer-events: auto;
}

.prompt-chip {
  min-height: 48px;
  padding: 0 13px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.76);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.25;
}

.composer {
  width: min(900px, calc(100% - 48px));
  min-height: 76px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 48px;
  gap: 10px;
  align-items: end;
  margin: 0 auto 22px;
  padding: 10px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 14px 48px rgba(20, 33, 38, 0.1);
}

textarea {
  width: 100%;
  max-height: 180px;
  resize: none;
  border: 0;
  outline: none;
  padding: 13px 12px;
  background: transparent;
  color: var(--ink);
  font-size: 15px;
  line-height: 1.45;
}

textarea::placeholder {
  color: #8b999c;
}

.send-button,
.icon-button {
  display: grid;
  place-items: center;
  border: 1px solid transparent;
}

.send-button {
  width: 48px;
  height: 48px;
  align-self: end;
  background: var(--teal);
  color: #fff;
}

.send-button:hover {
  background: var(--teal-dark);
}

.send-button:disabled {
  background: #a7b2b4;
}

.send-button .stop-icon {
  display: none;
}

.send-button.is-running .send-icon {
  display: none;
}

.send-button.is-running .stop-icon {
  display: block;
}

.icon-button {
  width: 40px;
  height: 40px;
  background: #fff;
  color: var(--ink);
  border-color: var(--line);
}

@media (max-width: 860px) {
  .auth-view {
    min-height: 0;
    align-items: stretch;
    padding: 10px;
  }

  .auth-shell {
    height: calc(100svh - 20px);
    min-height: 0;
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr);
  }

  .auth-copy {
    min-height: 116px;
    gap: 8px;
    padding: 18px 22px;
  }

  .auth-copy h1 {
    font-size: 38px;
  }

  .auth-copy p {
    font-size: 15px;
  }

  .login-panel {
    min-height: 0;
    justify-content: center;
    gap: 14px;
    padding: 16px 18px 18px;
  }

  .pattern-lock {
    width: min(340px, 100%, 58svh);
    gap: clamp(18px, 4svh, 26px);
    padding: 8px;
  }

  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    display: none;
  }

  .chat-area {
    grid-template-rows: auto auto 1fr auto;
  }

  .mobile-bar {
    min-height: 62px;
    grid-row: 1;
    grid-column: 1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.86);
    backdrop-filter: blur(16px);
  }

  .mobile-actions {
    min-width: 0;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
  }

  .mobile-actions select {
    width: min(40vw, 180px);
    min-width: 132px;
    min-height: 40px;
    padding: 0 8px;
    font-size: 13px;
  }

  .mobile-session-strip {
    grid-row: 2;
    grid-column: 1;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 44px;
    gap: 8px;
    padding: 8px 12px;
    border-bottom: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.78);
  }

  .mobile-session-strip select {
    width: 100%;
    min-height: 40px;
    padding: 0 10px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #fff;
    color: var(--ink);
    outline: none;
    font-size: 14px;
  }

  .mobile-delete-button {
    width: 44px;
    min-height: 40px;
    display: grid;
    place-items: center;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #fff;
    color: var(--muted);
  }

  .mobile-delete-button span {
    display: none;
    font-size: 12px;
    font-weight: 850;
  }

  .mobile-delete-button:hover {
    border-color: rgba(187, 59, 47, 0.24);
    background: rgba(187, 59, 47, 0.08);
    color: var(--danger);
  }

  .mobile-delete-button.is-confirm-delete {
    border-color: var(--danger);
    background: var(--danger);
    color: #fff;
  }

  .mobile-delete-button.is-confirm-delete .trash-icon {
    display: none;
  }

  .mobile-delete-button.is-confirm-delete span {
    display: block;
  }

  .messages {
    grid-row: 3;
    grid-column: 1;
    padding: 22px 12px 18px;
  }

  .message-row,
  .message-row.user {
    grid-template-columns: 34px minmax(0, 1fr);
    gap: 9px;
    margin-bottom: 14px;
    justify-content: stretch;
  }

  .message-row.user {
    grid-template-columns: minmax(0, 1fr) 34px;
  }

  .avatar {
    width: 34px;
    height: 34px;
    border-radius: 7px;
    font-size: 11px;
  }

  .bubble {
    padding: 12px 13px;
  }

  .bubble-text {
    font-size: 14px;
    line-height: 1.68;
  }

  .empty-state {
    width: calc(100% - 28px);
    max-width: 620px;
    grid-row: 3;
    grid-column: 1;
    align-self: center;
    justify-self: center;
    position: relative;
    left: auto;
    top: auto;
    transform: none;
    z-index: 1;
  }

  .empty-state h2 {
    font-size: 30px;
  }

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

  .prompt-chip {
    min-height: 44px;
  }

  .composer {
    grid-row: 4;
    grid-column: 1;
    width: calc(100% - 20px);
    min-height: 66px;
    grid-template-columns: minmax(0, 1fr) 44px;
    margin-bottom: 10px;
    padding: 8px;
  }

  textarea {
    max-height: 140px;
    padding: 11px 8px;
    font-size: 16px;
  }

  .send-button {
    width: 44px;
    height: 44px;
  }
}

@media (max-width: 420px) {
  .auth-copy {
    min-height: 98px;
    padding: 14px 18px;
  }

  .auth-copy h1 {
    font-size: 32px;
  }

  .auth-copy p {
    font-size: 14px;
  }

  .login-panel {
    padding: 14px 14px 16px;
  }

  .mobile-actions select {
    width: 142px;
    min-width: 0;
  }

  .brand-mark.compact {
    padding: 0 8px;
  }
}

@media (max-width: 860px) and (max-height: 640px) {
  .auth-copy {
    min-height: 78px;
    padding: 12px 16px;
  }

  .auth-copy h1 {
    font-size: 28px;
  }

  .auth-copy p {
    display: none;
  }

  .login-panel {
    gap: 10px;
    padding: 10px 14px 12px;
  }

  .pattern-lock {
    width: min(330px, 100%, 64svh);
    gap: clamp(16px, 3.2svh, 22px);
  }

  .form-error {
    min-height: 18px;
    font-size: 12px;
  }
}
