:root {
  --navy-950: #09192f;
  --navy-900: #10284a;
  --navy-850: #173457;
  --navy-700: #2d4a6c;
  --ink: #1b2638;
  --muted: #697386;
  --soft-muted: #8c95a4;
  --canvas: #f7f5f0;
  --surface: #ffffff;
  --surface-soft: #f1f3f5;
  --line: #e2e4e8;
  --line-strong: #ced3da;
  --gold: #c69a3d;
  --gold-soft: #fbf3df;
  --coral: #c95b56;
  --coral-soft: #fcecea;
  --purple: #6e5793;
  --purple-soft: #f1edf8;
  --sage: #7e958c;
  --sage-soft: #ebf1ee;
  --lime: #efff77;
  --success: #247653;
  --success-soft: #e8f5ef;
  --danger: #b43d3d;
  --danger-soft: #fff0ef;
  --shadow-sm: 0 2px 10px rgba(9, 25, 47, 0.06);
  --shadow-md: 0 14px 44px rgba(9, 25, 47, 0.11);
  --shadow-lg: 0 28px 90px rgba(9, 25, 47, 0.18);
  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 24px;
  --radius-xl: 32px;
  --sidebar-width: 318px;
  --header-height: 74px;
  --font-sans: "DM Sans", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-serif: "Libre Caslon Display", Georgia, serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--canvas);
  color-scheme: light;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background: var(--canvas);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

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

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

button,
a {
  touch-action: manipulation;
}

button {
  border: 0;
}

button,
select {
  cursor: pointer;
}

a {
  color: inherit;
  text-decoration: none;
}

img,
svg {
  display: block;
}

svg {
  width: 20px;
  height: 20px;
  stroke-width: 1.8;
}

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

h1,
h2 {
  text-wrap: balance;
}

::selection {
  color: var(--navy-950);
  background: var(--lime);
}

:focus-visible {
  outline: 3px solid rgba(198, 154, 61, 0.34);
  outline-offset: 3px;
}

.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  color: var(--gold);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.12em;
  line-height: 1.4;
  text-transform: uppercase;
}

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

.brand-mark {
  width: 48px;
  height: 48px;
  flex: 0 0 auto;
  border-radius: 12px;
  box-shadow: 0 6px 18px rgba(9, 25, 47, 0.12);
}

.brand-copy {
  display: grid;
  gap: 1px;
  min-width: 0;
}

.brand-copy strong {
  color: var(--navy-900);
  font-family: var(--font-serif);
  font-size: 19px;
  font-weight: 400;
  letter-spacing: 0.01em;
  line-height: 1.2;
}

.brand-copy small {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  line-height: 1.3;
  text-transform: uppercase;
}

.button {
  min-height: 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 12px 18px;
  border-radius: 12px;
  font-weight: 700;
  line-height: 1.2;
  transition: transform 160ms ease, background 160ms ease, color 160ms ease, border-color 160ms ease, box-shadow 160ms ease;
}

.button:hover {
  transform: translateY(-1px);
}

.button:active {
  transform: translateY(0);
}

.button svg {
  width: 18px;
  height: 18px;
}

.button-primary {
  color: #fff;
  background: var(--navy-900);
  box-shadow: 0 10px 26px rgba(16, 40, 74, 0.18);
}

.button-primary:hover {
  background: var(--navy-950);
  box-shadow: 0 14px 32px rgba(16, 40, 74, 0.23);
}

.button-secondary {
  color: var(--navy-900);
  border: 1px solid var(--line-strong);
  background: var(--surface);
}

.button-secondary:hover {
  border-color: var(--navy-700);
}

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

.button-danger:hover {
  background: #942f2f;
}

.button-block {
  width: 100%;
}

.icon-button {
  width: 40px;
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  padding: 0;
  border-radius: 10px;
  color: var(--muted);
  background: transparent;
  transition: color 150ms ease, background 150ms ease, transform 150ms ease;
}

.icon-button:hover {
  color: var(--navy-900);
  background: rgba(16, 40, 74, 0.07);
}

.icon-button:active {
  transform: scale(0.97);
}

.field {
  display: grid;
  gap: 8px;
  color: var(--ink);
  font-size: 14px;
  font-weight: 600;
}

.field > small,
.field-note {
  color: var(--muted);
  font-size: 12px;
  font-weight: 400;
  line-height: 1.5;
}

.input-wrap {
  min-height: 50px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 13px;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: 0 1px 0 rgba(9, 25, 47, 0.02);
  transition: border-color 150ms ease, box-shadow 150ms ease, background 150ms ease;
}

.input-wrap:focus-within {
  border-color: var(--gold);
  box-shadow: 0 0 0 4px rgba(198, 154, 61, 0.12);
}

.input-wrap > svg {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  color: var(--soft-muted);
}

.input-wrap input,
.input-wrap select {
  width: 100%;
  min-width: 0;
  height: 48px;
  padding: 0;
  border: 0;
  outline: 0;
  color: var(--ink);
  background: transparent;
}

.input-wrap input::placeholder,
textarea::placeholder {
  color: #9ca3af;
}

.password-toggle {
  width: 34px;
  height: 34px;
  margin-right: -6px;
}

.stack-form {
  display: grid;
  gap: 18px;
}

.alert {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 20px;
  padding: 13px 14px;
  border: 1px solid transparent;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.5;
}

.alert svg {
  width: 19px;
  height: 19px;
  flex: 0 0 auto;
  margin-top: 1px;
}

.alert-error {
  color: #8f3030;
  border-color: #f1c5c2;
  background: var(--danger-soft);
}

.alert-success {
  color: var(--success);
  border-color: #bfe1d1;
  background: var(--success-soft);
}

/* Authentication */
.auth-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(380px, 0.92fr) minmax(520px, 1.08fr);
  background: var(--surface);
}

.auth-brand-panel {
  position: relative;
  overflow: hidden;
  padding: clamp(34px, 5vw, 70px);
  color: #fff;
  background:
    radial-gradient(circle at 10% 15%, rgba(239, 255, 119, 0.14), transparent 28%),
    radial-gradient(circle at 90% 85%, rgba(201, 91, 86, 0.18), transparent 35%),
    linear-gradient(145deg, var(--navy-950), var(--navy-900) 55%, #1f3f65);
}

.auth-brand-panel::before,
.auth-brand-panel::after {
  content: "";
  position: absolute;
  border: 1px solid rgba(255, 255, 255, 0.11);
  border-radius: 50%;
  pointer-events: none;
}

.auth-brand-panel::before {
  width: 420px;
  height: 420px;
  right: -210px;
  top: -130px;
}

.auth-brand-panel::after {
  width: 270px;
  height: 270px;
  left: -155px;
  bottom: -95px;
}

.auth-brand-inner {
  position: relative;
  z-index: 1;
  min-height: calc(100vh - clamp(68px, 10vw, 140px));
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.auth-brand-panel .brand-copy strong,
.auth-brand-panel .brand-copy small {
  color: #fff;
}

.auth-brand-panel .brand-copy small {
  opacity: 0.65;
}

.auth-brand-message {
  max-width: 590px;
  padding: 70px 0;
}

.auth-brand-message h1 {
  max-width: 600px;
  margin-bottom: 22px;
  font-family: var(--font-serif);
  font-size: clamp(46px, 5.2vw, 78px);
  font-weight: 400;
  letter-spacing: -0.035em;
  line-height: 0.98;
}

.auth-brand-message p {
  max-width: 520px;
  margin-bottom: 0;
  color: rgba(255, 255, 255, 0.72);
  font-size: 18px;
  line-height: 1.7;
}

.auth-proof {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: rgba(255, 255, 255, 0.72);
  font-size: 13px;
}

.auth-proof svg {
  color: var(--lime);
}

.auth-form-panel {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 46px;
  background:
    linear-gradient(rgba(255, 255, 255, 0.92), rgba(255, 255, 255, 0.92)),
    radial-gradient(circle at 70% 20%, var(--gold-soft), transparent 33%);
}

.auth-card {
  width: min(100%, 460px);
}

.mobile-brand {
  display: none;
  margin-bottom: 50px;
}

.auth-card h2 {
  margin-bottom: 12px;
  color: var(--navy-900);
  font-family: var(--font-serif);
  font-size: clamp(42px, 4vw, 56px);
  font-weight: 400;
  letter-spacing: -0.03em;
  line-height: 1.03;
}

.form-intro {
  margin-bottom: 28px;
  color: var(--muted);
}

.auth-footer {
  display: grid;
  gap: 6px;
  margin-top: 28px;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.auth-footer a,
.legal-contact a {
  color: var(--navy-900);
  font-weight: 700;
  text-decoration: underline;
  text-decoration-color: rgba(16, 40, 74, 0.25);
  text-underline-offset: 3px;
}

/* Legal acknowledgement and account */
.centered-shell,
.account-main,
.install-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 38px 20px;
  background:
    radial-gradient(circle at 15% 10%, rgba(198, 154, 61, 0.11), transparent 30%),
    radial-gradient(circle at 88% 85%, rgba(110, 87, 147, 0.09), transparent 34%),
    var(--canvas);
}

.centered-shell {
  align-content: center;
  gap: 24px;
}

.top-brand {
  width: min(100%, 660px);
}

.legal-card,
.account-card,
.install-card {
  width: min(100%, 660px);
  padding: clamp(28px, 5vw, 52px);
  border: 1px solid rgba(206, 211, 218, 0.8);
  border-radius: var(--radius-xl);
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--shadow-md);
}

.legal-card.compact {
  max-width: 540px;
  text-align: center;
}

.legal-icon,
.dialog-icon {
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  margin-bottom: 24px;
  border-radius: 16px;
  color: var(--navy-900);
  background: var(--gold-soft);
}

.legal-icon svg,
.dialog-icon svg {
  width: 25px;
  height: 25px;
}

.legal-card h1,
.account-heading h1,
.install-heading h1,
.install-success h1 {
  margin-bottom: 16px;
  color: var(--navy-900);
  font-family: var(--font-serif);
  font-size: clamp(38px, 5vw, 52px);
  font-weight: 400;
  letter-spacing: -0.03em;
  line-height: 1.06;
}

.legal-card > p,
.account-heading > p,
.install-heading > p,
.install-success > p {
  color: var(--muted);
  line-height: 1.75;
}

.legal-points {
  display: grid;
  gap: 12px;
  margin: 28px 0;
}

.legal-points > div {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 15px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fbfbfa;
}

.legal-points svg {
  width: 21px;
  height: 21px;
  flex: 0 0 auto;
  margin-top: 2px;
  color: var(--gold);
}

.legal-points span {
  display: grid;
  gap: 2px;
  color: var(--muted);
  font-size: 13px;
}

.legal-points strong {
  color: var(--ink);
  font-size: 14px;
}

.legal-form {
  display: grid;
  gap: 20px;
}

.check-row {
  display: grid;
  grid-template-columns: 22px 1fr;
  gap: 12px;
  align-items: flex-start;
  color: #445064;
  font-size: 14px;
  line-height: 1.65;
  cursor: pointer;
}

.check-row input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.custom-check {
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  margin-top: 1px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #fff;
  transition: background 150ms ease, border-color 150ms ease, box-shadow 150ms ease;
}

.custom-check svg {
  width: 14px;
  height: 14px;
  color: #fff;
  opacity: 0;
}

.check-row input:checked + .custom-check {
  border-color: var(--navy-900);
  background: var(--navy-900);
  box-shadow: 0 0 0 3px rgba(16, 40, 74, 0.12);
}

.check-row input:checked + .custom-check svg {
  opacity: 1;
}

.legal-contact {
  margin: 22px 0 0;
  font-size: 12px;
  text-align: center;
}

.account-main {
  min-height: calc(100vh - 80px);
  align-items: start;
  padding-top: 70px;
}

.account-card {
  max-width: 610px;
}

.profile-summary,
.user-card {
  display: flex;
  align-items: center;
  gap: 12px;
}

.profile-summary {
  margin: 26px 0;
  padding: 15px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface-soft);
}

.profile-summary > span:last-child,
.user-card > span:nth-child(2) {
  min-width: 0;
  display: grid;
  gap: 1px;
}

.profile-summary small,
.user-card small {
  color: var(--muted);
  font-size: 12px;
}

.user-avatar {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 10px;
  color: var(--navy-950);
  background: var(--lime);
  font-size: 13px;
  font-weight: 800;
}

.user-avatar.large {
  width: 46px;
  height: 46px;
  border-radius: 14px;
  font-size: 16px;
}

/* Portal header and selector */
.portal-page {
  min-height: 100vh;
}

.portal-header {
  position: sticky;
  top: 0;
  z-index: 20;
  border-bottom: 1px solid rgba(226, 228, 232, 0.9);
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(18px);
}

.portal-header-inner {
  width: min(100% - 40px, 1180px);
  min-height: 80px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  margin: 0 auto;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-actions form {
  display: contents;
}

.text-link {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 10px;
  color: var(--muted);
  background: transparent;
  font-size: 13px;
  font-weight: 600;
}

.text-link:hover {
  color: var(--navy-900);
  background: rgba(16, 40, 74, 0.06);
}

.text-link svg {
  width: 17px;
  height: 17px;
}

.selector-main {
  width: min(100% - 40px, 1120px);
  margin: 0 auto;
  padding: clamp(62px, 8vw, 100px) 0 70px;
}

.selector-heading {
  max-width: 760px;
  margin-bottom: 40px;
}

.selector-heading h1 {
  margin-bottom: 16px;
  color: var(--navy-900);
  font-family: var(--font-serif);
  font-size: clamp(46px, 6vw, 72px);
  font-weight: 400;
  letter-spacing: -0.04em;
  line-height: 1;
}

.selector-heading p {
  max-width: 680px;
  margin-bottom: 0;
  color: var(--muted);
  font-size: 17px;
  line-height: 1.7;
}

.companion-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 22px;
}

.companion-card {
  position: relative;
  overflow: hidden;
  min-height: 500px;
  display: flex;
  flex-direction: column;
  padding: clamp(26px, 4vw, 40px);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  transition: transform 220ms ease, border-color 220ms ease, box-shadow 220ms ease;
}

.companion-card::before {
  content: "";
  position: absolute;
  width: 240px;
  height: 240px;
  top: -150px;
  right: -100px;
  border-radius: 50%;
  opacity: 0.38;
}

.companion-card.theme-contract::before {
  background: var(--coral-soft);
}

.companion-card.theme-programme::before {
  background: var(--purple-soft);
}

.companion-card:hover {
  transform: translateY(-5px);
  border-color: #d5c79f;
  box-shadow: var(--shadow-md);
}

.companion-top {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 32px;
}

.companion-icon,
.active-companion-icon,
.welcome-icon {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 16px;
}

.companion-icon {
  width: 58px;
  height: 58px;
}

.theme-contract .companion-icon,
.welcome-icon.theme-contract {
  color: var(--coral);
  background: var(--coral-soft);
}

.theme-programme .companion-icon,
.welcome-icon.theme-programme {
  color: var(--purple);
  background: var(--purple-soft);
}

.companion-icon svg {
  width: 27px;
  height: 27px;
}

.companion-kicker {
  max-width: 250px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  line-height: 1.45;
  text-align: right;
  text-transform: uppercase;
}

.companion-card h2 {
  margin-bottom: 16px;
  color: var(--navy-900);
  font-family: var(--font-serif);
  font-size: clamp(36px, 4vw, 48px);
  font-weight: 400;
  letter-spacing: -0.03em;
  line-height: 1.05;
}

.companion-card > p {
  margin-bottom: 24px;
  color: var(--muted);
  line-height: 1.72;
}

.feature-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 30px;
}

.feature-pills span {
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: #586274;
  background: #fafafa;
  font-size: 11px;
  font-weight: 600;
}

.companion-cta {
  min-height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: auto;
  padding: 14px 16px;
  border-radius: 13px;
  color: #fff;
  background: var(--navy-900);
  font-weight: 700;
  transition: background 160ms ease, transform 160ms ease;
}

.companion-cta:hover {
  background: var(--navy-950);
  transform: translateY(-1px);
}

.disclaimer-strip {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  margin-top: 26px;
  padding: 18px 20px;
  border: 1px solid #e6dcc0;
  border-radius: 15px;
  background: #fffaf0;
}

.disclaimer-strip svg {
  width: 20px;
  height: 20px;
  flex: 0 0 auto;
  margin-top: 2px;
  color: var(--gold);
}

.disclaimer-strip p {
  margin: 0;
  color: #666052;
  font-size: 13px;
  line-height: 1.65;
}

/* Chat application */
.page-chat {
  overflow: hidden;
  background: var(--surface);
}

.chat-app {
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  overflow: hidden;
}

.chat-sidebar {
  position: relative;
  z-index: 40;
  min-width: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-right: 1px solid #dfe2e6;
  background: #f3f4f5;
  transition: margin-left 220ms ease, transform 220ms ease;
}

.sidebar-top {
  min-height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
}

.chat-sidebar .brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 11px;
}

.chat-sidebar .brand-copy strong {
  font-size: 16px;
}

.chat-sidebar .brand-copy small {
  font-size: 9px;
}

.mobile-sidebar-close,
.mobile-menu {
  display: none;
}

.new-chat-button {
  width: calc(100% - 28px);
  min-height: 44px;
  justify-content: flex-start;
  margin: 4px 14px 16px;
  padding: 10px 13px;
  border: 1px solid var(--line-strong);
  color: var(--navy-900);
  background: #fff;
  box-shadow: none;
}

.new-chat-button:hover {
  border-color: #aeb7c2;
  background: #fff;
}

.companion-switcher {
  display: grid;
  gap: 5px;
  padding: 0 10px 16px;
  border-bottom: 1px solid #dfe2e6;
}

.companion-switch {
  min-height: 55px;
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 10px;
  border-radius: 11px;
  color: #5b6676;
  transition: color 150ms ease, background 150ms ease;
}

.companion-switch:hover {
  color: var(--navy-900);
  background: rgba(255, 255, 255, 0.7);
}

.companion-switch.active {
  color: var(--navy-900);
  background: #fff;
  box-shadow: var(--shadow-sm);
}

.companion-switch > svg {
  width: 20px;
  height: 20px;
  flex: 0 0 auto;
  color: var(--gold);
}

.companion-switch > span {
  min-width: 0;
  display: grid;
}

.companion-switch strong {
  overflow: hidden;
  font-size: 12px;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.companion-switch small {
  overflow: hidden;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-scroll {
  min-height: 0;
  flex: 1;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 8px 8px 20px;
  scrollbar-width: thin;
  scrollbar-color: #cbd0d6 transparent;
}

.history-section + .history-section {
  margin-top: 18px;
}

.history-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 30px;
  padding: 6px 8px;
  color: #7b8491;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.history-list {
  display: grid;
  gap: 2px;
}

.history-empty {
  padding: 8px;
  color: #939aa4;
  font-size: 11px;
}

.history-item-wrap {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 32px;
  align-items: center;
  gap: 1px;
  border-radius: 9px;
}

.history-item-wrap:hover,
.history-item-wrap.active {
  background: rgba(255, 255, 255, 0.86);
}

.history-item {
  min-width: 0;
  height: 38px;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 0 5px 0 9px;
  color: #586274;
  background: transparent;
  text-align: left;
}

.history-item-wrap.active .history-item {
  color: var(--navy-900);
  font-weight: 600;
}

.history-item svg {
  width: 15px;
  height: 15px;
  flex: 0 0 auto;
  color: #8a929e;
}

.history-item span {
  overflow: hidden;
  font-size: 12px;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-menu-button {
  width: 30px;
  height: 30px;
  opacity: 0;
}

.history-item-wrap:hover .history-menu-button,
.history-item-wrap.menu-open .history-menu-button,
.history-item-wrap.active .history-menu-button {
  opacity: 1;
}

.history-menu {
  position: absolute;
  z-index: 60;
  top: 34px;
  right: 0;
  width: 150px;
  display: none;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: #fff;
  box-shadow: var(--shadow-md);
}

.history-item-wrap.menu-open .history-menu {
  display: grid;
}

.history-menu button {
  min-height: 36px;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 9px;
  border-radius: 8px;
  color: #4f5a6a;
  background: transparent;
  font-size: 12px;
  text-align: left;
}

.history-menu button:hover {
  color: var(--navy-900);
  background: var(--surface-soft);
}

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

.history-menu svg {
  width: 15px;
  height: 15px;
}

.history-loading {
  height: 34px;
  margin: 2px 7px;
  border-radius: 8px;
  background: linear-gradient(90deg, #e5e7e9 25%, #f3f4f5 50%, #e5e7e9 75%);
  background-size: 200% 100%;
  animation: shimmer 1.3s infinite linear;
}

.history-loading.short {
  width: 68%;
}

.sidebar-footer {
  padding: 10px;
  border-top: 1px solid #dfe2e6;
}

.user-card {
  min-height: 58px;
  padding: 8px;
  border-radius: 12px;
  color: var(--ink);
}

.user-card:hover {
  background: #fff;
}

.user-card > svg {
  width: 17px;
  height: 17px;
  margin-left: auto;
  color: var(--soft-muted);
}

.user-card strong {
  overflow: hidden;
  font-size: 12px;
  line-height: 1.3;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-main {
  min-width: 0;
  max-height: 100vh;
  height: 100%;
  display: grid;
  grid-template-rows: var(--header-height) minmax(0, 1fr) auto;
  background: #fff;
}

.chat-header {
  position: relative;
  z-index: 20;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 10px 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(16px);
}

.chat-header-left,
.chat-header-actions,
.active-companion {
  min-width: 0;
  display: flex;
  align-items: center;
}

.chat-header-left {
  gap: 8px;
}

.chat-header-actions {
  gap: 5px;
}

.chat-header-actions form {
  display: contents;
}

.active-companion {
  gap: 10px;
  margin-left: 4px;
}

.active-companion-icon {
  width: 38px;
  height: 38px;
  color: var(--navy-900);
  background: var(--gold-soft);
}

.active-companion-icon svg {
  width: 19px;
  height: 19px;
}

.active-companion > span:last-child {
  min-width: 0;
  display: grid;
}

.active-companion strong {
  overflow: hidden;
  color: var(--navy-900);
  font-size: 13px;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.active-companion small {
  overflow: hidden;
  max-width: min(50vw, 420px);
  color: var(--muted);
  font-size: 10px;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-stage {
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  scroll-behavior: smooth;
}

.welcome-state {
  width: min(100% - 40px, 810px);
  min-height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  margin: 0 auto;
  padding: 70px 0 110px;
  text-align: center;
}

.welcome-state[hidden] {
  display: none;
}

.welcome-icon {
  width: 68px;
  height: 68px;
  margin: 0 auto 24px;
}

.welcome-icon svg {
  width: 30px;
  height: 30px;
}

.welcome-state h1 {
  max-width: 700px;
  margin: 0 auto 16px;
  color: var(--navy-900);
  font-family: var(--font-serif);
  font-size: clamp(40px, 5.5vw, 62px);
  font-weight: 400;
  letter-spacing: -0.04em;
  line-height: 1.04;
}

.welcome-state > p {
  max-width: 650px;
  margin: 0 auto 32px;
  color: var(--muted);
  line-height: 1.72;
}

.suggestion-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  width: min(100%, 720px);
  margin: 0 auto;
}

.suggestion-pill {
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  color: #455166;
  background: #fff;
  font-size: 13px;
  font-weight: 600;
  text-align: left;
  box-shadow: 0 3px 12px rgba(9, 25, 47, 0.04);
  transition: color 160ms ease, border-color 160ms ease, transform 160ms ease, box-shadow 160ms ease;
}

.suggestion-pill:hover {
  color: var(--navy-900);
  border-color: #cfbd8d;
  transform: translateY(-2px);
  box-shadow: var(--shadow-sm);
}

.suggestion-pill svg {
  width: 17px;
  height: 17px;
  flex: 0 0 auto;
  color: var(--gold);
}

.messages {
  width: min(100% - 40px, 860px);
  display: none;
  margin: 0 auto;
  padding: 38px 0 120px;
}

.messages.visible {
  display: block;
}

.message-row {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 13px;
  align-items: flex-start;
  margin-bottom: 28px;
}

.message-avatar {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  color: #fff;
  background: var(--navy-900);
}

.message-row.user .message-avatar {
  color: var(--navy-950);
  background: var(--lime);
  font-size: 12px;
  font-weight: 800;
}

.message-avatar svg {
  width: 17px;
  height: 17px;
}

.message-body {
  min-width: 0;
  padding-top: 4px;
  color: #263347;
  font-size: 15px;
  line-height: 1.75;
}

.message-row.user .message-body {
  width: fit-content;
  max-width: min(100%, 690px);
  justify-self: end;
  padding: 11px 15px;
  border-radius: 16px 16px 4px 16px;
  color: #172337;
  background: #f0f2f4;
  white-space: pre-wrap;
}

.message-body > :first-child {
  margin-top: 0;
}

.message-body > :last-child {
  margin-bottom: 0;
}

.message-body p,
.message-body ul,
.message-body ol,
.message-body blockquote,
.message-body pre,
.message-body table {
  margin: 0 0 15px;
}

.message-body h1,
.message-body h2,
.message-body h3,
.message-body h4 {
  margin: 24px 0 10px;
  color: var(--navy-900);
  font-family: var(--font-sans);
  font-weight: 700;
  line-height: 1.3;
}

.message-body h1 {
  font-size: 22px;
}

.message-body h2 {
  font-size: 19px;
}

.message-body h3,
.message-body h4 {
  font-size: 16px;
}

.message-body ul,
.message-body ol {
  padding-left: 22px;
}

.message-body li + li {
  margin-top: 7px;
}

.message-body strong {
  color: var(--ink);
}

.message-body a {
  color: var(--navy-700);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.message-body blockquote {
  padding: 11px 15px;
  border-left: 3px solid var(--gold);
  color: #586274;
  background: #fbf7ed;
}

.message-body code {
  padding: 2px 5px;
  border-radius: 5px;
  color: #8d3d39;
  background: #f8eeed;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.9em;
}

.message-body pre {
  overflow-x: auto;
  padding: 15px;
  border-radius: 12px;
  color: #e7edf5;
  background: var(--navy-950);
}

.message-body pre code {
  padding: 0;
  color: inherit;
  background: transparent;
}

.message-body table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.message-body th,
.message-body td {
  padding: 9px 10px;
  border: 1px solid var(--line);
  text-align: left;
}

.message-body th {
  color: var(--navy-900);
  background: var(--surface-soft);
}

.typing-indicator {
  min-height: 34px;
  display: flex;
  align-items: center;
  gap: 5px;
}

.typing-indicator span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #9aa2ad;
  animation: typingBounce 1.25s infinite ease-in-out;
}

.typing-indicator span:nth-child(2) {
  animation-delay: 0.15s;
}

.typing-indicator span:nth-child(3) {
  animation-delay: 0.3s;
}

.message-error {
  padding: 12px 14px;
  border: 1px solid #f1c5c2;
  border-radius: 12px;
  color: #8f3030;
  background: var(--danger-soft);
  font-size: 13px;
}

.composer-area {
  position: relative;
  z-index: 15;
  padding: 12px 20px max(12px, env(safe-area-inset-bottom));
  background: linear-gradient(to top, #fff 78%, rgba(255, 255, 255, 0));
}

.composer-wrap {
  width: min(100%, 860px);
  margin: 0 auto;
}

.composer {
  min-height: 58px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 42px;
  align-items: end;
  gap: 8px;
  padding: 8px 8px 8px 17px;
  border: 1px solid var(--line-strong);
  border-radius: 19px;
  background: #fff;
  box-shadow: 0 8px 30px rgba(9, 25, 47, 0.11);
  transition: border-color 150ms ease, box-shadow 150ms ease;
}

.composer:focus-within {
  border-color: #c4ad70;
  box-shadow: 0 10px 34px rgba(9, 25, 47, 0.13), 0 0 0 4px rgba(198, 154, 61, 0.08);
}

.composer textarea {
  width: 100%;
  max-height: 180px;
  resize: none;
  overflow-y: auto;
  padding: 9px 0;
  border: 0;
  outline: 0;
  color: var(--ink);
  background: transparent;
  line-height: 1.5;
}

.send-button {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 13px;
  color: #fff;
  background: var(--navy-900);
  transition: background 150ms ease, transform 150ms ease, opacity 150ms ease;
}

.send-button:hover:not(:disabled) {
  background: var(--navy-950);
  transform: translateY(-1px);
}

.send-button:disabled {
  cursor: not-allowed;
  opacity: 0.35;
}

.send-button svg {
  width: 19px;
  height: 19px;
}

.composer-wrap > p {
  margin: 7px 0 0;
  color: #8a929e;
  font-size: 10px;
  line-height: 1.45;
  text-align: center;
}

body.sidebar-collapsed .chat-app {
  grid-template-columns: 0 minmax(0, 1fr);
}

body.sidebar-collapsed .chat-sidebar {
  margin-left: calc(var(--sidebar-width) * -1);
}

body.sidebar-collapsed .desktop-sidebar-toggle svg {
  transform: rotate(180deg);
}

.sidebar-scrim {
  display: none;
}

/* Dialogs and toasts */
.action-dialog {
  width: min(calc(100% - 32px), 450px);
  padding: 0;
  border: 0;
  border-radius: 22px;
  color: var(--ink);
  background: #fff;
  box-shadow: var(--shadow-lg);
}

.action-dialog::backdrop {
  background: rgba(7, 20, 38, 0.52);
  backdrop-filter: blur(3px);
}

.action-dialog form {
  padding: 28px;
}

.dialog-icon {
  width: 48px;
  height: 48px;
  margin-bottom: 18px;
}

.dialog-icon.danger {
  color: var(--danger);
  background: var(--danger-soft);
}

.action-dialog h2 {
  margin-bottom: 8px;
  color: var(--navy-900);
  font-family: var(--font-serif);
  font-size: 34px;
  font-weight: 400;
  line-height: 1.1;
}

.action-dialog p {
  margin-bottom: 20px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.65;
}

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

.dialog-actions .button {
  min-height: 43px;
  padding: 10px 14px;
  font-size: 13px;
}

.toast-region {
  position: fixed;
  z-index: 200;
  right: 18px;
  bottom: 18px;
  display: grid;
  gap: 8px;
  pointer-events: none;
}

.toast {
  min-width: 250px;
  max-width: 380px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 13px 15px;
  border: 1px solid rgba(206, 211, 218, 0.85);
  border-radius: 13px;
  color: var(--ink);
  background: #fff;
  box-shadow: var(--shadow-md);
  font-size: 13px;
  line-height: 1.5;
  pointer-events: auto;
  animation: toastIn 220ms ease both;
}

.toast.error {
  color: #8f3030;
  border-color: #f1c5c2;
  background: #fff7f6;
}

.toast svg {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  margin-top: 1px;
  color: var(--gold);
}

.toast.error svg {
  color: var(--danger);
}

/* Installer */
.install-shell {
  align-items: start;
  padding-top: 46px;
  padding-bottom: 70px;
}

.install-card {
  width: min(100%, 820px);
}

.install-brand {
  display: flex;
  align-items: center;
  gap: 13px;
  margin-bottom: 38px;
}

.install-brand img {
  border-radius: 13px;
}

.install-brand span {
  display: grid;
}

.install-brand strong {
  color: var(--navy-900);
  font-family: var(--font-serif);
  font-size: 20px;
  font-weight: 400;
}

.install-brand small {
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.requirement-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 24px 0 30px;
}

.requirement {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--muted);
  background: #fafafa;
  font-size: 12px;
}

.requirement span {
  width: 20px;
  height: 20px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  font-weight: 800;
}

.requirement.ok span {
  color: var(--success);
  background: var(--success-soft);
}

.requirement.fail span {
  color: var(--danger);
  background: var(--danger-soft);
}

.install-form {
  display: grid;
  gap: 25px;
}

.install-form fieldset {
  display: grid;
  gap: 16px;
  margin: 0;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 16px;
}

.install-form legend {
  padding: 0 7px;
  color: var(--navy-900);
  font-weight: 700;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.form-grid .full {
  grid-column: 1 / -1;
}

.install-success {
  padding: 25px 0 10px;
  text-align: center;
}

.install-success .legal-icon {
  margin-right: auto;
  margin-left: auto;
}

/* Motion */
@keyframes shimmer {
  to { background-position: -200% 0; }
}

@keyframes typingBounce {
  0%, 65%, 100% { transform: translateY(0); opacity: 0.45; }
  30% { transform: translateY(-5px); opacity: 1; }
}

@keyframes toastIn {
  from { transform: translateY(10px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

@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;
  }
}

@media (max-width: 980px) {
  .auth-shell {
    grid-template-columns: 1fr;
  }

  .auth-brand-panel {
    display: none;
  }

  .auth-form-panel {
    padding: 34px 22px;
    background: var(--canvas);
  }

  .auth-card {
    padding: 34px;
    border: 1px solid var(--line);
    border-radius: 24px;
    background: #fff;
    box-shadow: var(--shadow-md);
  }

  .mobile-brand {
    display: block;
  }

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

  .companion-card {
    min-height: 0;
  }

  .page-chat {
    overflow: hidden;
  }

  .chat-app {
    display: block;
  }

  .chat-sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(88vw, var(--sidebar-width));
    transform: translateX(-105%);
    box-shadow: var(--shadow-lg);
  }

  body.mobile-sidebar-open .chat-sidebar {
    transform: translateX(0);
  }

  body.sidebar-collapsed .chat-sidebar {
    margin-left: 0;
  }

  .sidebar-scrim {
    position: fixed;
    z-index: 35;
    inset: 0;
    display: block;
    border: 0;
    background: rgba(7, 20, 38, 0.45);
    backdrop-filter: blur(2px);
  }

  .sidebar-scrim[hidden] {
    display: none;
  }

  .mobile-sidebar-close,
  .mobile-menu {
    display: inline-flex;
  }

  .desktop-sidebar-toggle {
    display: none;
  }

  .chat-main {
    height: 100vh;
    height: 100dvh;
  }
}

@media (max-width: 700px) {
  :root {
    --header-height: 66px;
  }

  .portal-header-inner,
  .selector-main {
    width: min(100% - 28px, 1120px);
  }

  .portal-header-inner {
    min-height: 72px;
  }

  .portal-header .brand-copy small,
  .header-actions .text-link span {
    display: none;
  }

  .selector-main {
    padding-top: 52px;
  }

  .selector-heading h1 {
    font-size: 48px;
  }

  .selector-heading p {
    font-size: 15px;
  }

  .companion-card {
    padding: 25px;
  }

  .companion-top {
    display: grid;
  }

  .companion-kicker {
    max-width: none;
    text-align: left;
  }

  .disclaimer-strip {
    padding: 15px;
  }

  .centered-shell,
  .account-main,
  .install-shell {
    padding: 20px 14px;
  }

  .top-brand {
    padding: 10px 8px 0;
  }

  .legal-card,
  .account-card,
  .install-card {
    padding: 26px 20px;
    border-radius: 22px;
  }

  .requirement-grid,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .form-grid .full {
    grid-column: auto;
  }

  .chat-header {
    padding: 8px 10px;
  }

  .active-companion small {
    max-width: 45vw;
  }

  .chat-header-actions .icon-button:first-child {
    display: none;
  }

  .welcome-state {
    width: min(100% - 28px, 810px);
    justify-content: flex-start;
    padding: 55px 0 150px;
  }

  .welcome-state h1 {
    font-size: 40px;
  }

  .welcome-state > p {
    font-size: 14px;
  }

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

  .suggestion-pill {
    min-height: 52px;
  }

  .messages {
    width: min(100% - 24px, 860px);
    padding-top: 24px;
  }

  .message-row {
    grid-template-columns: 30px minmax(0, 1fr);
    gap: 9px;
  }

  .message-avatar {
    width: 30px;
    height: 30px;
    border-radius: 9px;
  }

  .message-body {
    font-size: 14px;
  }

  .composer-area {
    padding-right: 10px;
    padding-left: 10px;
  }

  .composer {
    border-radius: 17px;
  }

  .composer-wrap > p {
    padding: 0 18px;
  }

  .toast-region {
    right: 10px;
    bottom: 10px;
    left: 10px;
  }

  .toast {
    min-width: 0;
    max-width: none;
  }

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

@media (max-width: 460px) {
  .auth-form-panel {
    padding: 0;
  }

  .auth-card {
    min-height: 100vh;
    width: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 28px 20px;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .mobile-brand {
    margin-bottom: 40px;
  }

  .auth-card h2 {
    font-size: 43px;
  }

  .brand-copy strong {
    font-size: 17px;
  }

  .brand-copy small {
    font-size: 9px;
  }

  .active-companion-icon {
    display: none;
  }

  .active-companion small {
    max-width: 54vw;
  }

  .welcome-state h1 {
    font-size: 36px;
  }
}
