:root {
  color-scheme: light;
  --navy: #102a56;
  --navy-strong: #0b1f43;
  --blue: #1769d2;
  --cyan: #06a7c8;
  --cyan-soft: #e9fbff;
  --blue-soft: #eef6ff;
  --ink: #17325d;
  --muted: #6b7e99;
  --line: #dce8f5;
  --line-strong: #c6d8ec;
  --surface: #ffffff;
  --surface-soft: #f7fbff;
  --danger: #c33b58;
  --shadow: 0 18px 50px rgba(31, 76, 127, 0.1);
  --shadow-small: 0 8px 24px rgba(31, 76, 127, 0.08);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-synthesis: none;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
  background: #ffffff;
  color: var(--ink);
}

body {
  overflow-x: hidden;
}

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

button,
a,
select,
input,
textarea {
  -webkit-tap-highlight-color: transparent;
}

button,
a {
  transition: border-color 180ms cubic-bezier(0.2, 0.8, 0.2, 1), background-color 180ms cubic-bezier(0.2, 0.8, 0.2, 1), color 180ms cubic-bezier(0.2, 0.8, 0.2, 1), box-shadow 180ms cubic-bezier(0.2, 0.8, 0.2, 1), transform 180ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgba(6, 167, 200, 0.32);
  outline-offset: 2px;
}

[hidden] {
  display: none !important;
}

.skip-link {
  position: fixed;
  z-index: 20;
  top: 12px;
  left: 12px;
  padding: 10px 14px;
  border-radius: 8px;
  background: var(--navy-strong);
  color: #ffffff;
  text-decoration: none;
  transform: translateY(-150%);
}

.skip-link:focus {
  transform: translateY(0);
}

.chat-app {
  position: relative;
  display: flex;
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  flex-direction: column;
  overflow: hidden;
  isolation: isolate;
  background: #ffffff;
}

.chat-app::before {
  position: fixed;
  z-index: -1;
  top: 0;
  right: 0;
  left: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--blue), var(--cyan), #7bdce9, var(--blue));
  background-size: 220% 100%;
  content: "";
  animation: signal-slide 8s cubic-bezier(0.42, 0, 0.58, 1) infinite;
}

.chat-topbar {
  display: flex;
  min-height: 72px;
  flex: 0 0 72px;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 14px clamp(18px, 4vw, 56px);
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
}

.brand-lockup,
.topbar-actions,
.conversation-title-wrap,
.conversation-actions,
.card-heading-row,
.modal-heading,
.composer-actions,
.estimate-row {
  display: flex;
  align-items: center;
}

.brand-lockup {
  min-width: 220px;
  gap: 11px;
}

.brand-mark {
  display: flex;
  width: 30px;
  height: 30px;
  align-items: flex-end;
  justify-content: center;
  gap: 3px;
  padding: 7px 6px;
  border: 1px solid #a9d8ed;
  border-radius: 8px;
  background: linear-gradient(145deg, #f5fdff, #e6f5ff);
  box-shadow: 0 5px 16px rgba(23, 105, 210, 0.12);
}

.brand-mark span {
  display: block;
  width: 4px;
  border-radius: 4px 4px 1px 1px;
  background: linear-gradient(180deg, var(--cyan), var(--blue));
}

.brand-mark span:nth-child(1) { height: 9px; }
.brand-mark span:nth-child(2) { height: 15px; }
.brand-mark span:nth-child(3) { height: 11px; }

.brand-name,
.brand-caption,
.section-label,
.conversation-header h2,
.conversation-header p,
.sidebar-heading h1,
.sidebar-intro,
.budget-card h2,
.budget-card p,
.state-panel h2,
.state-panel p,
.message-label,
.composer-help,
.character-count,
.stream-status,
.modal-heading h2,
.privacy-option p,
.privacy-option small {
  margin: 0;
}

.brand-name {
  color: var(--navy-strong);
  font-size: 15px;
  font-weight: 760;
  letter-spacing: 0;
}

.brand-caption {
  margin-top: 2px;
  color: var(--cyan);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0;
}

.topbar-center {
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0;
}

.signal-line {
  display: inline-block;
  width: 28px;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--cyan));
}

.topbar-actions {
  min-width: 0;
  justify-content: flex-end;
  gap: 8px;
}

.user-status {
  max-width: 150px;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.text-button,
.quiet-button,
.secondary-button,
.primary-button,
.stop-button {
  display: inline-flex;
  min-height: 38px;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 680;
  line-height: 1.2;
  text-decoration: none;
  white-space: nowrap;
}

.text-button {
  min-height: 34px;
  padding: 7px 10px;
  color: var(--blue);
  background: transparent;
}

.text-button:hover,
.text-button:focus-visible {
  color: var(--navy-strong);
  background: var(--blue-soft);
}

.primary-button {
  padding: 10px 17px;
  border-color: var(--blue);
  background: linear-gradient(135deg, var(--blue), #1598cc);
  box-shadow: 0 8px 18px rgba(23, 105, 210, 0.2);
  color: #ffffff;
}

.primary-button:hover:not(:disabled),
.primary-button:focus-visible {
  box-shadow: 0 11px 24px rgba(23, 105, 210, 0.27);
  transform: translateY(-1px);
}

.secondary-button,
.quiet-button {
  padding: 9px 13px;
  border-color: var(--line-strong);
  background: #ffffff;
  color: var(--navy);
}

.secondary-button:hover:not(:disabled),
.quiet-button:hover:not(:disabled),
.secondary-button:focus-visible,
.quiet-button:focus-visible {
  border-color: #8ecfe4;
  background: var(--cyan-soft);
  color: var(--blue);
}

.compact-button {
  min-height: 34px;
  padding: 8px 12px;
}

.inline-button {
  margin-top: 12px;
}

.stop-button {
  padding: 9px 14px;
  border-color: #e7b7c2;
  background: #fff8fa;
  color: var(--danger);
}

.stop-button:hover,
.stop-button:focus-visible {
  background: #ffedf2;
}

button:disabled,
select:disabled,
input:disabled,
textarea:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.chat-layout {
  display: grid;
  width: min(1560px, 100%);
  height: calc(100vh - 72px);
  height: calc(100dvh - 72px);
  min-height: 0;
  flex: 1;
  margin: 0 auto;
  grid-template-columns: minmax(240px, 310px) minmax(0, 1fr);
  overflow: hidden;
}

.session-sidebar {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 14px;
  padding: 26px 20px 22px;
  border-right: 1px solid var(--line);
  background: linear-gradient(180deg, #fbfdff 0%, #f7fbff 100%);
}

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

.section-label {
  color: var(--cyan);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0;
}

.sidebar-heading h1 {
  margin-top: 5px;
  color: var(--navy-strong);
  font-size: 24px;
  letter-spacing: 0;
}

.sidebar-intro {
  max-width: 250px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.65;
}

.session-list {
  display: flex;
  min-height: 100px;
  max-height: min(46vh, 470px);
  flex: 1;
  flex-direction: column;
  gap: 6px;
  overflow: auto;
  padding-right: 3px;
}

.selection-summary {
  margin: 12px 0 0;
  padding: 11px 13px;
  border: 1px solid #cfe5f4;
  border-radius: 8px;
  background: linear-gradient(180deg, #fbfeff, #f4fbff);
  color: var(--navy);
  font-size: 12px;
  line-height: 1.6;
  word-break: break-word;
}

.list-placeholder {
  margin: 12px 4px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

.session-item {
  display: flex;
  width: 100%;
  min-height: 58px;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  padding: 10px 12px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  text-align: left;
}

.session-item:hover,
.session-item:focus-visible {
  border-color: #c8e5f1;
  background: #ffffff;
}

.session-item.is-active {
  border-color: #a9d8ed;
  background: #ffffff;
  box-shadow: var(--shadow-small);
}

.session-item-title {
  width: 100%;
  overflow: hidden;
  color: var(--navy);
  font-size: 13px;
  font-weight: 720;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.session-item-meta {
  color: var(--muted);
  font-size: 11px;
}

.budget-card {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: var(--shadow-small);
}

.card-heading-row {
  justify-content: space-between;
  gap: 10px;
}

.budget-card h2 {
  margin-top: 4px;
  color: var(--navy);
  font-size: 14px;
}

.budget-mode {
  margin-top: 12px !important;
  color: var(--blue);
  font-size: 11px;
}

.budget-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  padding-top: 10px;
  color: var(--muted);
  font-size: 12px;
}

.budget-row strong {
  color: var(--navy);
  font-size: 13px;
}

.budget-note {
  margin-top: 11px !important;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.5;
}

.chat-main {
  display: flex;
  min-width: 0;
  min-height: 0;
  flex-direction: column;
  background: #ffffff;
}

.conversation-header {
  display: flex;
  min-height: 78px;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 16px clamp(18px, 4vw, 54px);
  border-bottom: 1px solid var(--line);
}

.conversation-title-wrap {
  min-width: 0;
  gap: 12px;
}

.online-dot {
  width: 10px;
  height: 10px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--cyan);
  box-shadow: 0 0 0 5px rgba(6, 167, 200, 0.1);
}

.conversation-header h2 {
  overflow: hidden;
  color: var(--navy-strong);
  font-size: 18px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-header p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.conversation-actions {
  flex-shrink: 0;
  gap: 8px;
}

.soft-badge {
  padding: 5px 8px;
  border: 1px solid #b8e8f1;
  border-radius: 999px;
  background: var(--cyan-soft);
  color: #08758e;
  font-size: 11px;
  font-weight: 700;
}

.danger-button {
  color: var(--danger);
}

.state-panel {
  display: flex;
  width: min(600px, calc(100% - 36px));
  min-height: 270px;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  margin: auto;
  padding: 34px 6px;
  animation: panel-in 560ms cubic-bezier(0.16, 1, 0.3, 1) both;
}

.state-index {
  display: inline-flex;
  min-width: 42px;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  border: 1px solid #a9d8ed;
  border-radius: 8px;
  background: var(--blue-soft);
  color: var(--blue);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0;
}

.state-panel .section-label {
  margin-top: 24px;
}

.state-panel h2 {
  margin-top: 9px;
  color: var(--navy-strong);
  font-size: 34px;
  letter-spacing: 0;
  line-height: 1.15;
}

.state-panel > p:not(.section-label) {
  max-width: 500px;
  margin-top: 13px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.75;
}

.auth-required {
  border: 1px solid #f0cbd4;
  border-radius: 8px;
  background: #fffafc;
}

.auth-required h2 {
  font-size: 28px;
}

.message-region {
  display: flex;
  min-height: 0;
  flex: 1;
  flex-direction: column;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.message-list {
  display: flex;
  width: min(900px, calc(100% - 36px));
  flex-direction: column;
  gap: 18px;
  margin: 0 auto;
  padding: 28px 0 18px;
}

.message {
  display: flex;
  gap: 11px;
  animation: message-in 420ms cubic-bezier(0.16, 1, 0.3, 1) both;
}

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

.message-marker {
  display: inline-flex;
  width: 28px;
  height: 28px;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  margin-top: 2px;
  border-radius: 8px;
  background: var(--blue-soft);
  color: var(--blue);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0;
}

.message.is-user .message-marker {
  order: 2;
  background: var(--navy);
  color: #ffffff;
}

.message-body {
  min-width: 0;
  max-width: min(760px, 86%);
}

.message.is-user .message-body {
  order: 1;
}

.message-content {
  padding: 13px 16px;
  border: 1px solid var(--line);
  border-radius: 4px 8px 8px 8px;
  background: #fbfdff;
  color: var(--ink);
  font-size: 14px;
  line-height: 1.8;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  word-break: break-word;
}

.message.is-user .message-content {
  border-color: #b9daf5;
  border-radius: 8px 4px 8px 8px;
  background: var(--blue-soft);
}

.message-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 6px;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.5;
}

.message-error .message-content {
  border-color: #f0cbd4;
  background: #fff7f9;
  color: #9b2948;
}

.streaming-cursor::after {
  display: inline-block;
  width: 6px;
  height: 16px;
  margin-left: 4px;
  vertical-align: -3px;
  border-radius: 2px;
  background: var(--cyan);
  content: "";
  animation: cursor-blink 900ms steps(2, end) infinite;
}

.stream-status {
  width: min(900px, calc(100% - 36px));
  min-height: 24px;
  margin: 0 auto;
  color: var(--blue);
  font-size: 12px;
}

.composer-shell {
  width: min(960px, calc(100% - 36px));
  margin: 0 auto;
  padding: 16px 0 26px;
  flex: 0 0 auto;
  border-top: 1px solid var(--line);
  background: #ffffff;
}

.message-label {
  display: block;
  margin-bottom: 7px;
  color: var(--navy);
  font-size: 12px;
  font-weight: 750;
}

#message-input,
.control-field input,
.control-field select,
#session-title-input {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
}

#message-input {
  display: block;
  min-height: 112px;
  resize: vertical;
  padding: 13px 15px;
  font-size: 14px;
  line-height: 1.7;
}

#message-input::placeholder,
.control-field input::placeholder {
  color: #9aabc0;
}

#message-input:focus,
.control-field input:focus,
.control-field select:focus,
#session-title-input:focus {
  border-color: var(--cyan);
  box-shadow: 0 0 0 4px rgba(6, 167, 200, 0.1);
  outline: none;
}

.composer-underbar {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 2px 12px;
}

.character-count,
.composer-help {
  color: var(--muted);
  font-size: 11px;
}

.control-grid {
  display: grid;
  grid-template-columns: 1.25fr 1.25fr 0.9fr 0.8fr;
  gap: 10px;
}

.control-field {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 6px;
}

.control-field > span {
  color: var(--navy);
  font-size: 11px;
  font-weight: 750;
}

.control-field input,
.control-field select,
#session-title-input {
  min-height: 38px;
  padding: 8px 10px;
  font-size: 12px;
}

.control-field select {
  cursor: pointer;
}

.control-field small {
  min-height: 16px;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.45;
  word-break: break-word;
}

.model-id-input {
  margin-top: 1px;
}

.estimate-row {
  min-height: 47px;
  flex-wrap: wrap;
  gap: 10px;
  border-bottom: 1px solid var(--line);
}

.estimate-result {
  min-width: 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.5;
  word-break: break-word;
}

.estimate-result.is-ready {
  color: var(--blue);
  font-weight: 680;
}

.estimate-result.is-error {
  color: var(--danger);
}

.composer-actions {
  justify-content: flex-end;
  gap: 8px;
  padding-top: 12px;
}

.send-button {
  min-width: 108px;
}

.modal-backdrop {
  position: fixed;
  z-index: 10;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(16, 42, 86, 0.16);
  backdrop-filter: blur(8px);
}

.modal-card {
  width: min(430px, 100%);
  padding: 22px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: var(--shadow);
  animation: panel-in 360ms cubic-bezier(0.16, 1, 0.3, 1) both;
}

.modal-heading {
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 20px;
}

.modal-heading h2 {
  margin-top: 5px;
  color: var(--navy-strong);
  font-size: 20px;
}

.privacy-option {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  margin-top: 15px;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  cursor: pointer;
}

.privacy-option input {
  width: 17px;
  height: 17px;
  margin: 1px 0 0;
  accent-color: var(--blue);
}

.privacy-option span {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.privacy-option strong {
  color: var(--navy);
  font-size: 12px;
}

.privacy-option small {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.5;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 22px;
}

.toast {
  position: fixed;
  z-index: 30;
  right: 18px;
  bottom: 18px;
  max-width: min(360px, calc(100% - 36px));
  padding: 11px 14px;
  border: 1px solid #b9dced;
  border-radius: 8px;
  background: #ffffff;
  box-shadow: var(--shadow-small);
  color: var(--navy);
  font-size: 12px;
  line-height: 1.5;
  word-break: break-word;
}

.sidebar-scrim {
  position: fixed;
  z-index: 4;
  inset: 0;
  background: rgba(16, 42, 86, 0.2);
}

@keyframes signal-slide {
  0%, 100% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
}

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

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

@keyframes cursor-blink {
  0%, 45% { opacity: 1; }
  46%, 100% { opacity: 0.18; }
}

@media (max-width: 1080px) {
  .topbar-center {
    display: none;
  }

  .control-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  .chat-topbar {
    min-height: 64px;
    flex-basis: 64px;
    gap: 10px;
    padding: 11px 14px;
  }

  .brand-lockup {
    min-width: 0;
  }

  .brand-caption,
  .user-status,
  .topbar-actions > .text-button:last-child {
    display: none;
  }

  .topbar-actions {
    gap: 4px;
  }

  .mobile-session-button {
    display: inline-flex;
  }

  .chat-layout {
    display: block;
    height: calc(100vh - 64px);
    height: calc(100dvh - 64px);
    min-height: 0;
  }

  .chat-main {
    height: 100%;
  }

  .session-sidebar {
    position: fixed;
    z-index: 5;
    top: 64px;
    bottom: 0;
    left: 0;
    width: min(320px, 88vw);
    border-right: 1px solid var(--line-strong);
    box-shadow: var(--shadow);
    transform: translateX(-105%);
    transition: transform 260ms cubic-bezier(0.16, 1, 0.3, 1);
  }

  .session-sidebar.is-open {
    transform: translateX(0);
  }

  .conversation-header {
    min-height: 70px;
    padding: 13px 16px;
  }

  .conversation-header h2 {
    max-width: 45vw;
    font-size: 16px;
  }

  .conversation-actions {
    gap: 4px;
  }

  .soft-badge {
    display: none;
  }

  .message-list,
  .stream-status,
  .composer-shell {
    width: calc(100% - 28px);
  }

  .selection-summary {
    margin-top: 10px;
    padding: 10px 12px;
  }

  .message-list {
    gap: 14px;
    padding-top: 18px;
  }

  .message-body {
    max-width: 88%;
  }

  .message-content {
    padding: 11px 13px;
    font-size: 13px;
    line-height: 1.7;
  }

  .composer-shell {
    padding-bottom: max(18px, env(safe-area-inset-bottom));
  }

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

  .state-panel {
    min-height: 360px;
    width: calc(100% - 28px);
  }

  .state-panel h2 {
    font-size: 28px;
  }
}

@media (max-width: 460px) {
  .conversation-header {
    align-items: flex-start;
  }

  .conversation-actions {
    flex-direction: column;
    align-items: flex-end;
  }

  .conversation-header p {
    max-width: 48vw;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

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

  .composer-underbar {
    align-items: flex-start;
    flex-direction: column;
    gap: 3px;
  }

  .selection-summary {
    font-size: 11px;
  }

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

  .composer-actions .send-button {
    grid-column: 1 / -1;
    grid-row: 1;
  }

  .composer-actions .secondary-button,
  .composer-actions .stop-button {
    grid-row: 2;
  }

  .composer-actions .secondary-button {
    grid-column: 1;
  }

  .composer-actions .stop-button {
    grid-column: 2;
  }
}

@media (min-width: 761px) {
  .mobile-session-button {
    display: none;
  }
}

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