:root {
  --bg: #f6f3ee;
  --panel: #fffdf9;
  --ink: #1f2328;
  --muted: #697077;
  --line: #ded7cc;
  --accent: #b64b3a;
  --accent-dark: #813123;
  --green: #2d6a4f;
  --blue: #315c8f;
  --shadow: 0 20px 60px rgba(38, 31, 24, 0.12);
  --visual-viewport-height: 100vh;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

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

button {
  cursor: pointer;
}

.topbar {
  align-items: center;
  background: rgba(246, 243, 238, 0.86);
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 16px;
  height: 68px;
  justify-content: space-between;
  padding: 0 28px;
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: blur(14px);
}

.brand,
.nav button,
.footer button,
.footer a {
  align-items: center;
  background: transparent;
  border: 0;
  color: var(--ink);
  display: inline-flex;
  gap: 10px;
  padding: 0;
}

.brand {
  font-weight: 800;
}

.brand-mark {
  align-items: center;
  background: var(--ink);
  color: var(--panel);
  display: inline-flex;
  font-size: 12px;
  height: 32px;
  justify-content: center;
  width: 32px;
}

.nav {
  align-items: center;
  display: flex;
  gap: 18px;
  justify-content: flex-end;
}

.nav button,
.footer button,
.footer a {
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
}

.account-nav {
  flex-direction: column;
  line-height: 1.1;
}

.account-badge {
  color: var(--rust);
  display: block;
  font-size: 11px;
  font-weight: 700;
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.view {
  display: none;
  min-height: calc(100vh - 126px);
  padding: 28px;
}

.view-active {
  display: block;
}

.hero {
  display: grid;
  gap: 28px;
  grid-template-columns: minmax(0, 0.95fr) minmax(360px, 1.05fr);
  min-height: calc(100vh - 170px);
  overflow: hidden;
}

.hero-copy {
  align-self: center;
  max-width: 720px;
  padding: 48px 0 72px 4vw;
  z-index: 1;
}

.eyebrow {
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  margin: 0 0 12px;
  text-transform: uppercase;
}

h1 {
  font-size: 60px;
  letter-spacing: 0;
  line-height: 0.98;
  margin: 0 0 18px;
}

.hero-subtitle {
  color: #3d4247;
  font-size: 22px;
  line-height: 1.42;
  margin: 0 0 28px;
  max-width: 620px;
}

.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.primary,
.secondary,
.pill {
  border: 1px solid transparent;
  border-radius: 8px;
  font-weight: 800;
  min-height: 44px;
  padding: 0 18px;
}

.primary {
  background: var(--accent);
  color: white;
}

.primary:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.secondary {
  background: var(--panel);
  border-color: var(--line);
  color: var(--ink);
}

.pill {
  background: #17191d;
  color: #fff;
  min-height: 34px;
  padding: 0 12px;
}

.full {
  width: 100%;
}

.hero-visual {
  align-self: stretch;
  min-height: 520px;
  position: relative;
}

.hero-visual img {
  border-radius: 8px;
  box-shadow: var(--shadow);
  height: 100%;
  inset: 0;
  object-fit: cover;
  position: absolute;
  width: 100%;
}

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

.feel-grid article,
.price-card,
.account-card,
.memory-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 22px;
}

.feel-grid span {
  color: var(--accent);
  font-weight: 800;
}

.feel-grid h2,
.setup-block h2,
.chat-side h2,
.price-card h2,
.account-card h2,
.memory-card h2 {
  font-size: 19px;
  line-height: 1.2;
  margin: 8px 0;
}

.feel-grid p,
.side-note,
.fineprint,
.readable p {
  color: var(--muted);
  line-height: 1.55;
  margin: 0;
}

.panel {
  margin: 0 auto;
  max-width: 1040px;
  padding: 30px 0 48px;
}

.panel.narrow {
  max-width: 760px;
}

.panel.readable {
  max-width: 760px;
}

.setup-block {
  margin: 26px 0;
}

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

.option-card,
.segment-btn {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  min-height: 86px;
  padding: 16px;
  text-align: left;
}

.option-card.active,
.segment-btn.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(182, 75, 58, 0.14);
}

.option-card strong {
  display: block;
  margin-bottom: 6px;
}

.option-card span {
  color: var(--muted);
  font-size: 14px;
}

.segmented {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.chat-shell {
  display: grid;
  gap: 18px;
  grid-template-columns: 300px minmax(0, 1fr);
  margin: 0 auto;
  max-width: 1180px;
}

.chat-side,
.chat-main {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.chat-side {
  align-self: start;
  padding: 20px;
}

.field {
  margin: 18px 0;
}

.field label {
  color: var(--muted);
  display: block;
  font-size: 12px;
  font-weight: 800;
  margin-bottom: 7px;
  text-transform: uppercase;
}

select,
input,
textarea {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  min-height: 44px;
  padding: 0 12px;
  width: 100%;
}

textarea {
  min-height: 96px;
  padding: 12px;
  resize: vertical;
}

.quota {
  margin: 22px 0;
}

.quota span {
  color: var(--muted);
  display: block;
  font-size: 13px;
  margin-bottom: 8px;
}

.quota-bar {
  background: #ebe5dc;
  border-radius: 999px;
  height: 8px;
  overflow: hidden;
}

.quota-bar span {
  background: var(--green);
  display: block;
  height: 100%;
  margin: 0;
  width: 100%;
}

.chat-main {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 126px);
  min-height: 640px;
}

.chat-header {
  align-items: center;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  padding: 18px 20px;
}

.chat-header h1 {
  font-size: 24px;
  line-height: 1.15;
  margin: 2px 0 0;
}

.chat-header p {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  margin: 0;
}

.messages {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
  padding: 20px;
}

.message {
  border-radius: 8px;
  line-height: 1.45;
  max-width: min(680px, 88%);
  padding: 12px 14px;
}

.message.user {
  align-self: flex-end;
  background: #1f2328;
  color: #fff;
}

.message.assistant {
  align-self: flex-start;
  background: #eee8df;
}

.message.system {
  align-self: center;
  background: #f7edd6;
  border: 1px solid #e1c98f;
  color: #604819;
  max-width: 92%;
}

.message.typing {
  align-items: center;
  display: inline-flex;
  gap: 5px;
  min-height: 42px;
  width: auto;
}

.message.typing span {
  animation: typing-dot 1.2s infinite ease-in-out;
  background: #687078;
  border-radius: 999px;
  display: block;
  height: 7px;
  opacity: 0.35;
  width: 7px;
}

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

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

@keyframes typing-dot {
  0%,
  80%,
  100% {
    transform: translateY(0);
    opacity: 0.32;
  }
  40% {
    transform: translateY(-4px);
    opacity: 0.9;
  }
}

.composer {
  border-top: 1px solid var(--line);
  display: grid;
  gap: 10px;
  grid-template-columns: minmax(0, 1fr) auto;
  padding: 14px;
}

.repair-banner,
.crisis {
  border-bottom: 1px solid var(--line);
  padding: 12px 20px;
}

.repair-banner {
  align-items: center;
  background: #f7edd6;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.repair-banner button {
  background: white;
  border: 1px solid #e1c98f;
  border-radius: 8px;
  min-height: 34px;
  padding: 0 10px;
}

.crisis {
  background: #fff0ed;
}

.crisis h2 {
  margin: 0 0 6px;
}

.crisis p {
  line-height: 1.5;
  margin: 0 0 12px;
}

.price-card.featured {
  border-color: var(--accent);
  box-shadow: var(--shadow);
}

.price {
  font-size: 42px;
  font-weight: 800;
  margin: 4px 0 16px;
}

.price span {
  color: var(--muted);
  font-size: 15px;
}

.price-card ul {
  line-height: 1.55;
  padding-left: 20px;
}

.price-card li {
  margin: 12px 0;
}

.price-card li strong {
  font-weight: 800;
}

.plan-note {
  color: var(--muted);
  font-size: 15px;
  line-height: 1.55;
  margin: 16px 0 8px;
  max-width: 760px;
}

.history-note {
  background: #f4efe8;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  display: grid;
  gap: 4px;
  margin: 0 0 14px;
  padding: 12px 14px;
}

.history-note span {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.history-item,
.memory-item {
  align-items: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: flex;
  gap: 14px;
  justify-content: space-between;
  margin: 10px 0;
  padding: 14px;
}

.history-item h2 {
  font-size: 16px;
  margin: 0 0 4px;
}

.history-item p,
.memory-item p {
  color: var(--muted);
  font-size: 13px;
  margin: 0;
}

.memory-empty {
  color: var(--muted);
  line-height: 1.5;
  margin: 0;
}

.admin-toolbar {
  align-items: center;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  margin: 0 0 18px;
  padding: 0 0 16px;
}

.admin-toolbar h2 {
  font-size: 18px;
  margin: 0 0 4px;
}

.admin-toolbar p {
  color: var(--muted);
  margin: 0;
}

.metric-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin: 0 0 18px;
}

.metric-card {
  background: #f4efe8;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}

.metric-card span {
  color: var(--muted);
  display: block;
  font-size: 12px;
  font-weight: 700;
  margin: 0 0 8px;
  text-transform: uppercase;
}

.metric-card strong {
  font-size: 28px;
}

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

.admin-grid section {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}

.admin-grid h2 {
  font-size: 18px;
  margin: 0 0 12px;
}

.admin-row {
  align-items: center;
  border-top: 1px solid var(--line);
  display: flex;
  gap: 12px;
  justify-content: space-between;
  padding: 10px 0;
}

.admin-row:first-child {
  border-top: 0;
}

.admin-row span {
  color: var(--muted);
  text-transform: capitalize;
}

.dialog {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  color: var(--ink);
  max-width: 520px;
  width: calc(100% - 28px);
}

.dialog::backdrop {
  background: rgba(31, 35, 40, 0.42);
}

.dialog h2 {
  margin-top: 0;
}

.dialog label {
  line-height: 1.4;
}

.check-row {
  align-items: flex-start;
  display: flex;
  gap: 12px;
  margin: 14px 0;
}

.check-row input {
  appearance: auto;
  flex: 0 0 auto;
  height: 18px;
  margin: 2px 0 0;
  min-height: 0;
  padding: 0;
  width: 18px;
}

.check-row span {
  flex: 1;
  min-width: 0;
}

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

.feedback-options {
  display: grid;
  gap: 6px;
}

.google-button {
  align-items: center;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  display: flex;
  font-weight: 800;
  gap: 12px;
  justify-content: center;
  min-height: 52px;
  padding: 0 16px;
  width: 100%;
}

.google-mark {
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  display: inline-flex;
  font-weight: 800;
  height: 28px;
  justify-content: center;
  width: 28px;
}

.toast {
  background: #17191d;
  border-radius: 8px;
  bottom: 22px;
  color: #fff;
  left: 50%;
  padding: 12px 16px;
  position: fixed;
  transform: translateX(-50%);
  z-index: 40;
}

.footer {
  align-items: center;
  border-top: 1px solid var(--line);
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  justify-content: center;
  min-height: 58px;
  padding: 12px 28px;
}

.hidden {
  display: none !important;
}

@media (max-width: 860px) {
  .topbar {
    height: auto;
    padding: 14px 16px;
  }

  .brand span:last-child {
    display: none;
  }

  .nav {
    gap: 12px;
  }

  .account-badge {
    max-width: 84px;
  }

  .view {
    padding: 16px;
  }

  .hero,
  .chat-shell {
    grid-template-columns: 1fr;
  }

  .metric-grid,
  .admin-grid {
    grid-template-columns: 1fr;
  }

  .hero {
    min-height: auto;
  }

  .hero-copy {
    padding: 28px 0 0;
  }

  h1 {
    font-size: 44px;
  }

  .hero-subtitle {
    font-size: 18px;
  }

  .hero-visual {
    min-height: 280px;
  }

  .feel-grid,
  .pricing-grid,
  .option-grid,
  .segmented {
    grid-template-columns: 1fr;
  }

  .chat-side {
    order: 2;
  }

  .chat-main {
    height: 72vh;
    min-height: 560px;
  }

  .message {
    max-width: 94%;
  }

  body.chat-keyboard-open {
    overflow: hidden;
  }

  body.chat-keyboard-open .topbar,
  body.chat-keyboard-open .footer,
  body.chat-keyboard-open .chat-side {
    display: none;
  }

  body.chat-keyboard-open .view {
    padding: 0;
  }

  body.chat-keyboard-open .chat-shell {
    gap: 0;
    max-width: none;
  }

  body.chat-keyboard-open .chat-main {
    border-left: 0;
    border-radius: 0;
    border-right: 0;
    height: var(--visual-viewport-height);
    min-height: 0;
  }

  body.chat-keyboard-open .chat-header {
    padding: 12px 16px;
  }

  body.chat-keyboard-open .chat-header h1 {
    font-size: 18px;
  }

  body.chat-keyboard-open .messages {
    padding: 14px 14px 10px;
  }

  body.chat-keyboard-open .composer {
    background: var(--panel);
    padding: 10px 12px max(10px, env(safe-area-inset-bottom));
  }
}
