:root {
  color-scheme: dark;
  --bg: #010403;
  --bg-2: #030807;
  --panel: #07110e;
  --panel-2: #0a1813;
  --line: rgba(203, 255, 225, 0.1);
  --text: #e9fff1;
  --muted: #789887;
  --accent: #34d77e;
  --accent-2: #94e85d;
  --warning: #f0c36d;
  --danger: #ff7a7a;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.42);
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  height: 100%;
  overflow-x: hidden;
  scrollbar-width: none;
}

body {
  margin: 0;
  min-width: 320px;
  height: 100%;
  overflow-x: hidden;
  scrollbar-width: none;
  background:
    linear-gradient(rgba(52, 215, 126, 0.024) 1px, transparent 1px),
    linear-gradient(90deg, rgba(52, 215, 126, 0.018) 1px, transparent 1px),
    linear-gradient(135deg, rgba(52, 215, 126, 0.035), transparent 34%),
    var(--bg);
  background-size:
    30px 30px,
    30px 30px,
    auto;
  color: var(--text);
}

html::-webkit-scrollbar,
body::-webkit-scrollbar,
.sidebar::-webkit-scrollbar,
.messages::-webkit-scrollbar {
  display: none;
}

.hidden {
  display: none !important;
}

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

button {
  min-height: 38px;
  border: 1px solid rgba(52, 215, 126, 0.23);
  border-radius: 8px;
  background: linear-gradient(180deg, #113524, #0a1f17);
  color: var(--text);
  cursor: pointer;
  font-family: var(--mono);
  font-size: 13px;
  transition:
    border-color 160ms ease,
    background 160ms ease,
    opacity 160ms ease,
    transform 160ms ease;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

button:hover:not(:disabled) {
  border-color: rgba(184, 243, 108, 0.55);
  transform: translateY(-1px);
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #020605;
  color: var(--text);
  font-family: var(--mono);
  outline: none;
}

input,
select {
  height: 38px;
  padding: 0 10px;
}

textarea {
  min-height: 46px;
  max-height: 170px;
  resize: none;
  padding: 12px 14px;
  line-height: 1.45;
}

input:focus,
select:focus,
textarea:focus {
  border-color: rgba(52, 215, 126, 0.72);
  box-shadow: 0 0 0 3px rgba(52, 215, 126, 0.11);
}

.auth-view {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 22px;
  background:
    linear-gradient(180deg, rgba(1, 4, 3, 0), rgba(1, 4, 3, 0.68)),
    transparent;
}

.auth-box {
  display: grid;
  gap: 16px;
  width: min(460px, 100%);
  border: 1px solid rgba(52, 215, 126, 0.24);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(52, 215, 126, 0.055), rgba(1, 4, 3, 0.96)),
    #010403;
  padding: 14px 18px 18px;
  box-shadow:
    0 0 0 1px rgba(52, 215, 126, 0.05),
    var(--shadow);
  animation: softIn 260ms ease both;
}

.terminal-bar {
  display: flex;
  align-items: center;
  gap: 7px;
  min-height: 28px;
  border-bottom: 1px solid rgba(203, 255, 225, 0.08);
  padding-bottom: 10px;
}

.terminal-bar span {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: rgba(52, 215, 126, 0.72);
}

.terminal-bar span:nth-child(2) {
  background: rgba(240, 195, 109, 0.8);
}

.terminal-bar span:nth-child(3) {
  background: rgba(255, 122, 122, 0.78);
}

.terminal-bar code {
  margin-left: 5px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 12px;
}

.intro-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 22px;
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(10px);
}

.intro-dialog {
  display: grid;
  gap: 14px;
  width: min(560px, 100%);
  border: 1px solid rgba(52, 215, 126, 0.24);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(52, 215, 126, 0.07), rgba(1, 4, 3, 0.94)),
    #010403;
  padding: 22px;
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.5);
  animation: softIn 220ms ease both;
}

.intro-kicker {
  color: var(--accent-2);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  text-transform: uppercase;
}

.intro-dialog h2 {
  margin: 0;
  font-size: 22px;
}

.intro-dialog p {
  margin: 0;
  color: #b8d7c5;
  font-size: 14px;
  line-height: 1.58;
}

.intro-dialog button {
  margin-top: 4px;
}

#introStatus {
  min-height: 20px;
  color: var(--muted);
  font-size: 13px;
}

.auth-brand {
  min-height: 50px;
}

.auth-form {
  display: grid;
  gap: 9px;
}

.auth-form label {
  color: #c9efda;
  font-family: var(--mono);
  font-size: 12px;
}

.auth-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 4px;
}

#authStatus {
  min-height: 20px;
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.app-shell {
  --sidebar-width: 300px;
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  height: 100dvh;
  max-width: 100vw;
  overflow: hidden;
  overflow-x: hidden;
  transition: grid-template-columns 220ms ease;
}

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

.sidebar-backdrop {
  position: fixed;
  inset: 0;
  z-index: 55;
  background: rgba(0, 0, 0, 0.46);
  backdrop-filter: blur(2px);
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 14px;
  height: 100dvh;
  min-width: 0;
  border-right: 1px solid var(--line);
  background:
    linear-gradient(180deg, rgba(52, 215, 126, 0.025), transparent 42%),
    rgba(1, 5, 4, 0.94);
  padding: 18px;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: none;
  transition:
    opacity 180ms ease,
    padding 180ms ease,
    transform 220ms ease;
}

.app-shell.sidebar-collapsed .sidebar {
  padding-right: 0;
  padding-left: 0;
  border-right: 0;
  opacity: 0;
  pointer-events: none;
  transform: translateX(-100%);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 52px;
}

.brand img {
  width: 42px;
  height: 42px;
  border: 1px solid rgba(148, 232, 93, 0.36);
  border-radius: 50%;
  object-fit: cover;
  box-shadow: 0 0 0 3px rgba(52, 215, 126, 0.07);
}

.brand strong {
  display: block;
  font-family: var(--mono);
  font-size: 16px;
}

.brand span,
.panel p,
.chat-header p {
  color: var(--muted);
  font-size: 13px;
}

.panel {
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(5, 12, 10, 0.82);
  padding: 12px;
  animation: softIn 220ms ease both;
}

.panel label {
  color: #c9efda;
  font-family: var(--mono);
  font-size: 12px;
}

.panel strong {
  overflow-wrap: anywhere;
}

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

.panel-heading span,
.chat-meta,
.chat-empty {
  color: var(--muted);
  font-size: 12px;
}

.chats-panel {
  gap: 10px;
}

.chats-panel > #newChat {
  width: 100%;
}

.danger-button {
  border-color: rgba(255, 122, 122, 0.34);
  background: linear-gradient(180deg, #4a1f24, #2d1418);
}

.danger-button:hover:not(:disabled) {
  border-color: rgba(255, 122, 122, 0.68);
}

.subscription-panel {
  gap: 10px;
}

.subscription-button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  min-height: 44px;
  padding: 0 12px;
  border-color: rgba(52, 215, 126, 0.3);
  background:
    linear-gradient(180deg, rgba(52, 215, 126, 0.2), rgba(4, 14, 10, 0.96)),
    #04100b;
}

.subscription-button.compact {
  width: auto;
  min-width: 118px;
  min-height: 38px;
}

.subscription-button span {
  color: #c8f6d9;
  font-size: 13px;
}

.subscription-button strong {
  color: var(--accent-2);
  font-size: 15px;
}

.subscription-button.featured {
  border-color: rgba(148, 232, 93, 0.62);
  background:
    linear-gradient(180deg, rgba(148, 232, 93, 0.24), rgba(8, 28, 17, 0.98)),
    #06140d;
  box-shadow: 0 0 0 1px rgba(148, 232, 93, 0.08);
}

.chat-list {
  display: grid;
  gap: 7px;
}

.chat-row {
  position: relative;
  min-width: 0;
}

.chat-row.active .chat-item {
  border-color: rgba(148, 232, 93, 0.68);
  background: linear-gradient(180deg, #0f2a1d, #07150f);
}

.chat-item {
  display: grid;
  gap: 2px;
  min-height: 48px;
  width: 100%;
  padding: 8px 74px 8px 10px;
  text-align: left;
  background: #020605;
}

.chat-title {
  min-width: 0;
  overflow: hidden;
  color: var(--text);
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-empty {
  padding: 4px 2px;
}

.chat-actions {
  position: absolute;
  top: 50%;
  right: 6px;
  display: flex;
  gap: 5px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(-50%);
  transition: opacity 160ms ease;
}

.chat-row:hover .chat-actions,
.chat-row:focus-within .chat-actions {
  opacity: 1;
  pointer-events: auto;
}

.chat-action {
  display: grid;
  place-items: center;
  width: 29px;
  min-height: 29px;
  padding: 0;
  border-color: rgba(203, 255, 225, 0.14);
  background: rgba(2, 8, 6, 0.92);
  font-size: 13px;
  line-height: 1;
}

.chat-action.danger {
  border-color: rgba(255, 122, 122, 0.34);
  color: #ffd2d2;
}

.row {
  display: grid;
  grid-template-columns: 1fr 72px;
  gap: 8px;
}

#sideStatus {
  min-height: 20px;
  margin: 0;
  overflow-wrap: anywhere;
}

.chat-area {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  height: 100dvh;
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
  background:
    linear-gradient(rgba(52, 215, 126, 0.018) 1px, transparent 1px),
    linear-gradient(90deg, rgba(52, 215, 126, 0.014) 1px, transparent 1px),
    var(--bg-2);
  background-size: 30px 30px;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  min-height: 84px;
  border-bottom: 1px solid var(--line);
  padding: 14px 22px;
  background:
    linear-gradient(180deg, rgba(52, 215, 126, 0.05), rgba(2, 7, 6, 0.92)),
    rgba(2, 7, 6, 0.94);
}

.chat-header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  width: min(1080px, 100%);
  min-width: 0;
}

.chat-title-block {
  min-width: 0;
}

.sidebar-toggle {
  flex: 0 0 auto;
}

.chat-header h1 {
  margin: 0;
  font-family: var(--mono);
  font-size: 18px;
  font-weight: 650;
}

.chat-header p {
  margin: 4px 0 0;
}

.plan-badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  margin-top: 8px;
  padding: 0 9px;
  border: 1px solid rgba(203, 255, 225, 0.12);
  border-radius: 999px;
  background: rgba(2, 8, 6, 0.72);
  color: #9ecfac;
  font-family: var(--mono);
  font-size: 12px;
}

.plan-badge.premium {
  border-color: rgba(184, 255, 108, 0.74);
  background:
    linear-gradient(135deg, rgba(148, 232, 93, 0.2), rgba(52, 215, 126, 0.08)),
    #06110b;
  color: #dfffbc;
  box-shadow: 0 0 18px rgba(52, 215, 126, 0.2);
}

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

.top-action {
  min-height: 38px;
  padding: 0 12px;
  border-color: rgba(203, 255, 225, 0.14);
  background: rgba(2, 8, 6, 0.76);
}

.plan-control {
  position: relative;
}

.plan-toggle {
  min-width: 132px;
  border-color: rgba(184, 255, 108, 0.82);
  background:
    radial-gradient(circle at 20% 18%, rgba(255, 255, 255, 0.24), transparent 24%),
    linear-gradient(135deg, #94e85d, #34d77e 48%, #0b6b43);
  color: #011008;
  font-weight: 800;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.26);
  box-shadow:
    0 0 0 1px rgba(148, 232, 93, 0.18),
    0 0 22px rgba(52, 215, 126, 0.36),
    inset 0 1px 0 rgba(255, 255, 255, 0.22);
  animation: planPulse 2.2s ease-in-out infinite;
}

.plan-toggle::after {
  content: "";
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-left: 8px;
  border-right: 1px solid currentColor;
  border-bottom: 1px solid currentColor;
  transform: translateY(-2px) rotate(45deg);
}

.plan-toggle:hover:not(:disabled) {
  border-color: rgba(225, 255, 158, 0.95);
  background:
    radial-gradient(circle at 20% 18%, rgba(255, 255, 255, 0.32), transparent 24%),
    linear-gradient(135deg, #b8ff6c, #41f28f 48%, #0f7b4e);
}

.plan-menu {
  position: fixed;
  top: 76px;
  right: 22px;
  z-index: 80;
  display: grid;
  gap: 12px;
  width: min(360px, calc(100vw - 28px));
  padding: 16px;
  border: 1px solid rgba(148, 232, 93, 0.34);
  border-radius: 8px;
  background:
    linear-gradient(rgba(52, 215, 126, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(52, 215, 126, 0.026) 1px, transparent 1px),
    linear-gradient(180deg, rgba(8, 28, 18, 0.98), rgba(1, 6, 4, 0.98));
  background-size: 18px 18px, 18px 18px, auto;
  box-shadow: 0 22px 60px rgba(0, 0, 0, 0.52), 0 0 0 1px rgba(52, 215, 126, 0.08);
  animation: menuIn 150ms ease both;
}

.plan-emblem {
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  margin: 2px auto 0;
  border: 1px solid rgba(148, 232, 93, 0.48);
  border-radius: 50%;
  background:
    radial-gradient(circle at 35% 28%, rgba(148, 232, 93, 0.38), transparent 42%),
    #06120c;
  color: var(--accent-2);
  font-family: var(--mono);
  font-size: 21px;
  font-weight: 800;
  box-shadow: 0 0 24px rgba(52, 215, 126, 0.16);
}

.plan-copy {
  display: grid;
  gap: 6px;
  text-align: center;
}

.plan-copy strong {
  color: #e7ffef;
  font-family: var(--mono);
  font-size: 15px;
}

.plan-copy p {
  margin: 0;
  color: #9ecfac;
  font-size: 13px;
  line-height: 1.5;
}

.plan-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 16px;
  width: min(980px, 100%);
  min-width: 0;
  margin: 0 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  scrollbar-width: none;
  padding: 28px 22px;
  scroll-behavior: smooth;
}

.message {
  display: grid;
  gap: 7px;
  width: min(82%, 100%);
  min-width: 0;
  animation: messageIn 220ms ease both;
}

.message.user {
  align-self: flex-end;
}

.message.assistant,
.message.system {
  align-self: flex-start;
}

.message .role {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 12px;
}

.bubble {
  max-width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
  line-height: 1.55;
  overflow: hidden;
  overflow-wrap: anywhere;
  word-break: break-word;
  box-shadow: var(--shadow);
}

.bubble * {
  max-width: 100%;
}

.message-text {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.message-text + .message-text,
.message-text + .code-block,
.code-block + .message-text,
.code-block + .code-block {
  margin-top: 10px;
}

.code-block {
  max-width: 100%;
  min-width: 0;
  overflow: hidden;
  border: 1px solid rgba(52, 215, 126, 0.18);
  border-radius: 8px;
  background: #010302;
}

.code-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 36px;
  border-bottom: 1px solid rgba(203, 255, 225, 0.1);
  padding: 6px 8px 6px 12px;
  color: var(--muted);
  font-size: 12px;
}

.copy-code {
  min-height: 28px;
  padding: 0 10px;
  font-size: 12px;
}

.code-block pre {
  margin: 0;
  max-width: 100%;
  overflow-x: hidden;
  padding: 12px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.code-block code {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 13px;
  line-height: 1.5;
}

.user .bubble {
  background: #0d2c1f;
  border-color: rgba(52, 215, 126, 0.26);
}

.assistant .bubble {
  background: #030a08;
}

.system .bubble {
  background: rgba(240, 195, 109, 0.1);
  border-color: rgba(240, 195, 109, 0.28);
  color: #ffe8b7;
}

.subscription-message {
  width: min(520px, 100%);
}

.subscription-bubble {
  display: grid;
  gap: 12px;
  border-color: rgba(52, 215, 126, 0.28);
  background:
    linear-gradient(180deg, rgba(52, 215, 126, 0.08), rgba(1, 4, 3, 0.92)),
    #010403;
  color: var(--text);
}

.subscription-actions {
  display: grid;
  gap: 8px;
}

.chat-plan-button {
  width: 100%;
  min-height: 46px;
  border-color: rgba(184, 255, 108, 0.82);
  background:
    radial-gradient(circle at 18% 20%, rgba(255, 255, 255, 0.22), transparent 24%),
    linear-gradient(135deg, #94e85d, #34d77e 52%, #0b6b43);
  color: #011008;
  font-weight: 850;
  letter-spacing: 0;
  box-shadow: 0 14px 34px rgba(52, 215, 126, 0.22), inset 0 1px 0 rgba(255, 255, 255, 0.22);
}

.chat-plan-button:hover:not(:disabled) {
  border-color: rgba(225, 255, 158, 0.95);
  background:
    radial-gradient(circle at 18% 20%, rgba(255, 255, 255, 0.3), transparent 24%),
    linear-gradient(135deg, #b8ff6c, #41f28f 52%, #0f7b4e);
}

.message.welcome {
  width: min(620px, 100%);
  align-self: center;
}

.message.welcome .role {
  display: none;
}

.message.welcome .bubble {
  border-color: rgba(52, 215, 126, 0.36);
  background:
    linear-gradient(180deg, rgba(52, 215, 126, 0.08), rgba(1, 4, 3, 0.92)),
    #010403;
  color: #b9ffd4;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  text-shadow: 0 0 16px rgba(52, 215, 126, 0.22);
  box-shadow:
    0 0 0 1px rgba(52, 215, 126, 0.08),
    0 22px 60px rgba(0, 0, 0, 0.36);
}

.message.welcome .message-text::after {
  content: "_";
  display: inline-block;
  margin-left: 2px;
  animation: caretBlink 1s steps(2, start) infinite;
}

.composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 92px;
  gap: 10px;
  width: min(920px, calc(100% - 44px));
  min-width: 0;
  margin: 0 auto;
  border-top: 1px solid var(--line);
  padding: 16px 0 20px;
  background: var(--bg-2);
}

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

@keyframes menuIn {
  from {
    opacity: 0;
    transform: translateY(-6px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes planPulse {
  0%,
  100% {
    box-shadow:
      0 0 0 1px rgba(148, 232, 93, 0.18),
      0 0 18px rgba(52, 215, 126, 0.28),
      inset 0 1px 0 rgba(255, 255, 255, 0.22);
  }
  50% {
    box-shadow:
      0 0 0 1px rgba(184, 255, 108, 0.28),
      0 0 30px rgba(52, 215, 126, 0.5),
      inset 0 1px 0 rgba(255, 255, 255, 0.28);
  }
}

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

@keyframes caretBlink {
  50% {
    opacity: 0;
  }
}

.composer button {
  height: 46px;
}

@media (max-width: 800px) {
  .app-shell {
    grid-template-columns: 1fr;
    height: 100dvh;
    min-height: 100dvh;
    overflow: hidden;
  }

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

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 65;
    width: min(320px, 86vw);
    height: 100dvh;
    max-height: none;
    border-right: 1px solid var(--line);
    border-bottom: 0;
    box-shadow: 20px 0 60px rgba(0, 0, 0, 0.42);
  }

  .chat-area {
    height: 100dvh;
    min-height: 0;
  }

  .chat-header {
    padding: 12px 14px;
  }

  .chat-header-inner {
    align-items: flex-start;
    flex-direction: column;
  }

  .top-console {
    display: grid;
    grid-template-columns: 1fr 1fr;
    width: 100%;
  }

  .top-action,
  .plan-control,
  .plan-toggle {
    width: 100%;
  }

  .plan-menu {
    width: auto;
  }

  .plan-options {
    grid-template-columns: 1fr;
  }

  .message {
    width: min(94%, 100%);
  }

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