:root {
  color-scheme: light;
  font-family: "Segoe UI", "Trebuchet MS", sans-serif;
  --body-font: "Segoe UI", "Trebuchet MS", sans-serif;
  --tech-font: "Consolas", "Courier New", monospace;
  --label-font: "Trebuchet MS", "Segoe UI", sans-serif;
  --bg-base: #d9f5e7;
  --bg-overlay: rgba(255, 255, 255, 0.52);
  --surface: rgba(251, 255, 252, 0.84);
  --surface-strong: rgba(255, 255, 255, 0.95);
  --surface-deep: rgba(255, 255, 255, 0.78);
  --line: rgba(12, 71, 38, 0.12);
  --text: #0c2316;
  --muted: #4f7863;
  --header: linear-gradient(135deg, #12aa63, #42d98b 56%, #8de2b7);
  --header-shadow: 0 18px 40px rgba(8, 41, 24, 0.18);
  --bubble-ia: rgba(255, 255, 255, 0.9);
  --bubble-user: linear-gradient(135deg, #0fad60, #23c46f 60%, #69e59f);
  --bubble-user-text: #f6fff9;
  --accent: #10b968;
  --accent-strong: #0f9354;
  --accent-soft: rgba(16, 185, 104, 0.16);
  --backdrop: rgba(4, 21, 12, 0.52);
  --kpi-bg: rgba(255, 255, 255, 0.18);
  --kpi-text: #f4fff8;
  --promo-bg: linear-gradient(135deg, rgba(255, 255, 255, 0.66), rgba(236, 255, 244, 0.82));
  --send-shadow: 0 18px 30px rgba(8, 46, 23, 0.22);
  --send-clip: none;
}

body[data-theme="sky"] {
  --bg-base: #dcecff;
  --bg-overlay: rgba(255, 255, 255, 0.68);
  --surface: rgba(252, 254, 255, 0.92);
  --surface-strong: rgba(255, 255, 255, 0.98);
  --surface-deep: rgba(241, 248, 255, 0.92);
  --line: rgba(53, 102, 159, 0.22);
  --text: #1b2d47;
  --muted: #617794;
  --header: linear-gradient(135deg, #7cbaf0, #b2d6ff 58%, #f1c7cc);
  --header-shadow: 0 18px 42px rgba(31, 72, 126, 0.16);
  --bubble-ia: rgba(255, 255, 255, 0.96);
  --bubble-user: linear-gradient(135deg, #7ba8ff, #98bcff 55%, #d7b7ff);
  --bubble-user-text: #f8fbff;
  --accent: #5e8df6;
  --accent-strong: #4471d2;
  --accent-soft: rgba(94, 141, 246, 0.18);
  --backdrop: rgba(17, 40, 74, 0.48);
  --kpi-bg: rgba(255, 255, 255, 0.34);
  --kpi-text: #1f3454;
  --promo-bg: linear-gradient(135deg, rgba(255, 255, 255, 0.78), rgba(235, 244, 255, 0.92));
  --send-shadow: 0 16px 28px rgba(43, 79, 145, 0.22);
}

body[data-theme="nerd"] {
  color-scheme: dark;
  --body-font: "Consolas", "Courier New", monospace;
  --bg-base: #020607;
  --bg-overlay: rgba(0, 0, 0, 0.12);
  --surface: rgba(3, 15, 10, 0.86);
  --surface-strong: rgba(3, 12, 8, 0.96);
  --surface-deep: rgba(2, 18, 11, 0.9);
  --line: rgba(77, 255, 172, 0.2);
  --text: #abffd0;
  --muted: #67d79a;
  --header: linear-gradient(135deg, rgba(1, 10, 7, 0.9), rgba(5, 47, 23, 0.9) 56%, rgba(0, 16, 9, 0.95));
  --header-shadow: 0 18px 42px rgba(0, 0, 0, 0.48);
  --bubble-ia: linear-gradient(135deg, rgba(4, 17, 12, 0.94), rgba(2, 10, 7, 0.98));
  --bubble-user: linear-gradient(135deg, #05351a, #0e6d36 60%, #13ae55);
  --bubble-user-text: #e9fff3;
  --accent: #39ff8a;
  --accent-strong: #14cf69;
  --accent-soft: rgba(57, 255, 138, 0.14);
  --backdrop: rgba(0, 0, 0, 0.72);
  --kpi-bg: rgba(0, 0, 0, 0.38);
  --kpi-text: #90ffbc;
  --promo-bg: linear-gradient(135deg, rgba(1, 12, 7, 0.9), rgba(3, 27, 15, 0.96));
  --send-shadow: 0 16px 34px rgba(0, 0, 0, 0.42);
  --send-clip: polygon(18% 0, 100% 0, 100% 82%, 82% 100%, 0 100%, 0 18%);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: var(--body-font);
  background:
    radial-gradient(circle at top left, rgba(255, 255, 255, 0.34), transparent 24%),
    radial-gradient(circle at 90% 10%, rgba(255, 255, 255, 0.18), transparent 18%),
    linear-gradient(180deg, var(--bg-base), color-mix(in srgb, var(--bg-base) 60%, #ffffff 40%));
  color: var(--text);
}

body[data-theme="nerd"] {
  background:
    radial-gradient(circle at 10% 0%, rgba(57, 255, 138, 0.08), transparent 18%),
    linear-gradient(180deg, rgba(2, 7, 5, 0.9), rgba(1, 5, 4, 1)),
    repeating-linear-gradient(90deg, rgba(57, 255, 138, 0.06) 0 1px, transparent 1px 24px),
    repeating-linear-gradient(180deg, rgba(57, 255, 138, 0.035) 0 1px, transparent 1px 24px);
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

.app-shell {
  position: relative;
  max-width: 520px;
  min-height: 100dvh;
  margin: 0 auto;
  background: linear-gradient(180deg, var(--bg-overlay), transparent 30%);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 12;
  padding: calc(14px + env(safe-area-inset-top, 0px)) 16px 14px;
  background: var(--header);
  box-shadow: var(--header-shadow);
}

.topbar-row {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: space-between;
}

.menu-button,
.modal-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border-radius: 0;
  background: transparent;
  color: #fff;
}

.topbar-actions {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  flex: 0 0 auto;
}

.theme-cycle-button {
  --theme-cycle-color: #6b9bff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.14);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.14);
  backdrop-filter: blur(10px);
}

.theme-cycle-dot {
  width: 15px;
  height: 15px;
  border-radius: 999px;
  background: var(--theme-cycle-color);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.22), 0 0 16px color-mix(in srgb, var(--theme-cycle-color) 56%, transparent);
  transition: transform 180ms ease, background 180ms ease, box-shadow 180ms ease;
}

.theme-cycle-button:hover .theme-cycle-dot,
.theme-cycle-button:focus-visible .theme-cycle-dot {
  transform: scale(1.08);
}

.menu-button {
  flex: 0 0 auto;
  padding: 0;
  position: relative;
  z-index: 13;
  flex-direction: column;
  gap: 5px;
}

.menu-button span {
  display: block;
  width: 24px;
  height: 2.5px;
  border-radius: 999px;
  background: currentColor;
  transform-origin: center;
  transition: transform 180ms ease, opacity 180ms ease;
}

body.drawer-open .menu-button span:nth-child(1) {
  transform: translateY(7.5px) rotate(45deg);
}

body.drawer-open .menu-button span:nth-child(2) {
  opacity: 0;
}

body.drawer-open .menu-button span:nth-child(3) {
  transform: translateY(-7.5px) rotate(-45deg);
}

.topbar-main {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.kpi-row {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex: 1;
}

.kpi-pill {
  min-width: 72px;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  background: var(--kpi-bg);
  color: var(--kpi-text);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(10px);
}

.kpi-pill span {
  font-size: 0.95rem;
  font-weight: 800;
  letter-spacing: 0.03em;
}

.kpi-gold {
  background: linear-gradient(135deg, rgba(255, 181, 54, 0.24), rgba(255, 237, 175, 0.18));
}

.kpi-cyan {
  background: linear-gradient(135deg, rgba(89, 216, 255, 0.22), rgba(169, 236, 255, 0.18));
}

.kpi-lime {
  background: linear-gradient(135deg, rgba(104, 255, 122, 0.2), rgba(200, 255, 167, 0.16));
}

.chat-panel {
  padding: 18px 14px 118px;
}

.pitch-banner {
  padding: 16px 16px 18px;
  margin-bottom: 16px;
  border: 1px solid var(--line);
  border-radius: 26px;
  background: var(--promo-bg);
  box-shadow: 0 18px 34px rgba(0, 0, 0, 0.08);
  backdrop-filter: blur(12px);
}

body[data-theme="sky"] .pitch-banner,
body[data-theme="sky"] .message-bubble,
body[data-theme="sky"] .composer-input input,
body[data-theme="sky"] .drawer,
body[data-theme="sky"] .kpi-modal {
  border-width: 2px;
}

body[data-theme="nerd"] .pitch-banner {
  border-radius: 10px;
  box-shadow: 0 0 0 1px rgba(57, 255, 138, 0.18), 0 0 34px rgba(19, 151, 77, 0.16);
}

.pitch-label {
  margin: 0 0 8px;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--accent-strong);
}

.pitch-banner h1 {
  margin: 0 0 10px;
  font-size: 1.45rem;
  line-height: 1.1;
}

.pitch-copy {
  margin: 0;
  font-size: 0.92rem;
  line-height: 1.5;
  color: var(--muted);
}

.message-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.message-row {
  display: flex;
  width: 100%;
  animation: message-rise 220ms ease-out;
}

.message-row.user {
  justify-content: flex-end;
}

.message-row.ia {
  justify-content: flex-start;
}

.message-bubble {
  position: relative;
  min-width: 50%;
  max-width: 90%;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: var(--bubble-ia);
  color: var(--text);
  box-shadow: 0 18px 32px rgba(0, 0, 0, 0.08);
  backdrop-filter: blur(12px);
}

.message-row.user .message-bubble {
  background: var(--bubble-user);
  color: var(--bubble-user-text);
  border-color: transparent;
  border-bottom-right-radius: 8px;
}

.message-row.ia .message-bubble {
  border-bottom-left-radius: 8px;
}

body[data-theme="eco"] .message-bubble::after {
  content: "";
  position: absolute;
  bottom: 3px;
  width: 14px;
  height: 15px;
}

body[data-theme="eco"] .message-row.user .message-bubble::after {
  right: -7px;
  bottom: 5px;
  width: 12px;
  height: 13px;
  background: #54de90;
  clip-path: polygon(0 0, 100% 50%, 0 100%);
}

body[data-theme="eco"] .message-row.ia .message-bubble::after {
  left: -8px;
  bottom: 4px;
  width: 14px;
  height: 15px;
  background: rgba(255, 255, 255, 0.94);
  border-left: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  clip-path: polygon(100% 0, 100% 100%, 0 62%);
}

body[data-theme="sky"] .message-bubble {
  border-radius: 22px 22px 22px 10px;
}

body[data-theme="sky"] .message-row.user .message-bubble {
  border-radius: 22px 22px 10px 22px;
}

body[data-theme="sky"] .message-row.user .message-bubble {
  border-color: rgba(255, 255, 255, 0.28);
}

body[data-theme="nerd"] .message-bubble,
body[data-theme="nerd"] .composer-input input,
body[data-theme="nerd"] .drawer,
body[data-theme="nerd"] .kpi-modal {
  border-radius: 10px;
  box-shadow: 0 0 0 1px rgba(57, 255, 138, 0.14), 0 0 28px rgba(0, 0, 0, 0.22);
}

body[data-theme="nerd"] .message-row.user .message-bubble {
  border-radius: 2px;
}

body[data-theme="nerd"] .message-row.ia .message-bubble {
  border-radius: 2px;
}

.typing-indicator-row {
  padding: 6px 4px 2px;
}

.typing-indicator-row .typing-dots {
  min-height: 20px;
}

.message-author {
  display: block;
  margin-bottom: 6px;
  font-family: var(--label-font);
  font-size: 0.69rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  opacity: 0.76;
}

.message-row.user .message-author {
  color: var(--bubble-user-text);
  opacity: 0.66;
}

.message-text {
  margin: 0;
  font-size: 0.98rem;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}

.message-meta {
  display: block;
  margin-top: 8px;
  font-size: 0.72rem;
  text-align: right;
  opacity: 0.74;
}

.typing-dots {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.typing-dots span {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: var(--accent);
  animation: typing-bounce 1s infinite ease-in-out;
}

.typing-dots span:nth-child(2) {
  animation-delay: 120ms;
}

.typing-dots span:nth-child(3) {
  animation-delay: 240ms;
}

.composer {
  position: fixed;
  left: 50%;
  bottom: 0;
  z-index: 7;
  display: flex;
  gap: 10px;
  width: min(520px, 100%);
  padding: 12px 14px calc(14px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.03), transparent 12%), var(--surface-strong);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(18px);
  overflow: hidden;
}

.composer-input {
  flex: 1;
}

.composer-input input {
  width: 100%;
  min-height: 52px;
  padding: 0 18px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  color: var(--text);
  outline: none;
}

.composer-input input::placeholder {
  color: var(--muted);
  opacity: 0.56;
}

.composer-input input:focus,
.field input:focus,
.field select:focus,
.theme-option-button:focus-visible,
.theme-cycle-button:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}

.send-button {
  width: 54px;
  height: 54px;
  flex: 0 0 auto;
  border-radius: 18px;
  background: var(--bubble-user);
  color: var(--bubble-user-text);
  box-shadow: var(--send-shadow);
  clip-path: var(--send-clip);
}

body[data-theme="sky"] .send-button {
  border: 2px solid rgba(255, 255, 255, 0.28);
}

.send-button svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

.drawer-backdrop,
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 10;
  background: var(--backdrop);
}

.drawer-backdrop {
  border: 0;
  padding: 0;
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease;
}

.drawer {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 11;
  display: flex;
  flex-direction: column;
  gap: 18px;
  width: min(84vw, 360px);
  height: 100dvh;
  padding: calc(78px + env(safe-area-inset-top, 0px)) 18px 24px;
  background: var(--surface-strong);
  border-right: 1px solid var(--line);
  box-shadow: 22px 0 44px rgba(0, 0, 0, 0.16);
  transform: translateX(-104%);
  transition: transform 220ms ease;
  backdrop-filter: blur(16px);
}

.drawer-open .drawer {
  transform: translateX(0);
}

.drawer-open .drawer-backdrop {
  opacity: 1;
  pointer-events: auto;
}

.drawer-header {
  display: grid;
  gap: 8px;
}

.eyebrow {
  margin: 0 0 6px;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
}

.drawer-header h2 {
  margin: 0;
  font-size: 1.28rem;
  line-height: 1.25;
}

.drawer-section {
  margin: 0;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.settings-form {
  display: grid;
  gap: 16px;
}

.field {
  display: grid;
  gap: 8px;
}

.field span {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--muted);
}

.field input,
.field select {
  width: 100%;
  min-height: 48px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  color: var(--text);
  outline: none;
}

.theme-option-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.theme-option-button {
  min-height: 46px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  color: var(--text);
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  opacity: 0.48;
  transition: opacity 160ms ease, transform 160ms ease, border-color 160ms ease, background 160ms ease, box-shadow 160ms ease;
}

.theme-option-button:hover {
  opacity: 0.78;
}

.theme-option-button[data-active="true"] {
  opacity: 1;
  border-color: color-mix(in srgb, var(--accent) 72%, white 28%);
  background: color-mix(in srgb, var(--accent-soft) 78%, var(--surface) 22%);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 32%, transparent);
  transform: translateY(-1px);
}

body[data-theme="nerd"] .theme-cycle-button {
  background: rgba(0, 0, 0, 0.32);
  box-shadow: inset 0 0 0 1px rgba(57, 255, 138, 0.16);
}

body[data-theme="nerd"] .composer {
  background:
    linear-gradient(180deg, rgba(1, 8, 5, 0.32), rgba(1, 10, 6, 0.96) 18%, rgba(1, 8, 5, 0.98)),
    repeating-linear-gradient(90deg, rgba(57, 255, 138, 0.045) 0 1px, transparent 1px 26px);
  border-top: 1px solid rgba(57, 255, 138, 0.22);
  box-shadow:
    0 -18px 34px rgba(0, 0, 0, 0.34),
    inset 0 1px 0 rgba(57, 255, 138, 0.12),
    inset 0 0 0 1px rgba(57, 255, 138, 0.08);
  clip-path: polygon(0 14px, 14px 0, calc(100% - 14px) 0, 100% 14px, 100% 100%, 0 100%);
}

body[data-theme="nerd"] .composer::before {
  content: "";
  position: absolute;
  top: 8px;
  left: 18px;
  right: 18px;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(57, 255, 138, 0.42), transparent);
  pointer-events: none;
}

body[data-theme="nerd"] .composer-input input {
  border-color: rgba(57, 255, 138, 0.18);
  background: linear-gradient(180deg, rgba(1, 10, 6, 0.94), rgba(4, 21, 13, 0.98));
}

body[data-theme="nerd"] .send-button {
  border: 1px solid rgba(57, 255, 138, 0.22);
  box-shadow: 0 0 0 1px rgba(57, 255, 138, 0.14), 0 0 26px rgba(0, 0, 0, 0.34);
}

body[data-theme="nerd"] .theme-option-button {
  border-radius: 4px;
  text-transform: uppercase;
}

body[data-theme="sky"] .theme-option-button {
  border-radius: 18px;
}

.save-button {
  min-height: 48px;
  border-radius: 16px;
  background: var(--bubble-user);
  color: var(--bubble-user-text);
  font-weight: 800;
  box-shadow: 0 18px 28px rgba(0, 0, 0, 0.12);
}

.drawer-cta {
  margin: 0;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface-deep);
  font-size: 0.88rem;
  line-height: 1.5;
  color: var(--text);
}

.modal-backdrop {
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 24px;
}

.modal-backdrop[hidden] {
  display: none;
}

.kpi-modal {
  position: relative;
  display: grid;
  align-content: center;
  gap: 12px;
  width: min(82vw, 380px);
  min-height: min(48vh, 340px);
  padding: 28px 24px;
  border: 1px solid var(--line);
  border-radius: 28px;
  background: var(--surface-strong);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.28);
  text-align: center;
}

.modal-close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 40px;
  height: 40px;
  color: var(--text);
  background: var(--surface-deep);
}

.modal-kpi-value {
  display: block;
  font-size: clamp(2.6rem, 12vw, 4.4rem);
  font-weight: 900;
  line-height: 1;
  color: var(--accent-strong);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.kpi-modal h2 {
  margin: 0;
  font-size: 1.35rem;
}

.kpi-modal p {
  margin: 0;
  font-size: 0.96rem;
  line-height: 1.55;
  color: var(--muted);
}

@keyframes typing-bounce {
  0%,
  80%,
  100% {
    transform: translateY(0);
    opacity: 0.36;
  }
  40% {
    transform: translateY(-4px);
    opacity: 1;
  }
}

@keyframes message-rise {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (min-width: 720px) {
  .app-shell {
    box-shadow: 0 28px 60px rgba(0, 0, 0, 0.16);
  }

  .chat-panel {
    padding-left: 18px;
    padding-right: 18px;
  }

  .composer {
    border-radius: 20px 20px 0 0;
  }
}
