:root {
  color-scheme: dark;
  --bg: #101010;
  --sidebar: #171717;
  --surface: #212121;
  --surface-2: #2a2a2a;
  --line: #333333;
  --text: #f4f4f4;
  --muted: #b4b4b4;
  --soft: #8f8f8f;
  --accent: #10a37f;
  --accent-2: #d6a84f;
  --danger: #f07272;
  --shadow: rgba(0, 0, 0, 0.28);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

body {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100dvh;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

.auth-screen {
  display: grid;
  min-height: 100dvh;
  padding: 24px;
  place-items: center;
  background: var(--bg);
}

.auth-card {
  display: grid;
  gap: 22px;
  width: min(860px, 100%);
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #151515;
  box-shadow: 0 18px 70px var(--shadow);
}

.auth-brand,
.auth-grid {
  display: grid;
  gap: 18px;
}

.auth-brand {
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
}

.auth-brand strong {
  display: block;
  font-size: 1.35rem;
}

.auth-brand span,
.auth-form p {
  color: var(--muted);
}

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

.auth-form {
  display: grid;
  gap: 13px;
  min-width: 0;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.auth-form h1 {
  margin: 0 0 4px;
  font-size: 1.15rem;
  letter-spacing: 0;
}

.auth-form label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.9rem;
}

.auth-form input,
.activation-form input,
.admin-user input,
.admin-user select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: #101010;
  color: var(--text);
  outline: none;
}

.auth-form input:focus,
.activation-form input:focus,
.admin-user input:focus,
.admin-user select:focus {
  border-color: rgba(16, 163, 127, 0.62);
  box-shadow: 0 0 0 3px rgba(16, 163, 127, 0.13);
}

.auth-form p,
.auth-error,
.activation-message {
  margin: 0;
  font-size: 0.86rem;
}

.auth-error,
.activation-message {
  min-height: 1.2em;
  color: var(--danger);
}

.activation-message.is-success {
  color: var(--accent);
}

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

button {
  cursor: pointer;
}

svg {
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.9;
}

.app-shell {
  display: grid;
  grid-template-columns: 292px minmax(0, 1fr);
  height: 100dvh;
  max-height: 100dvh;
  min-height: 0;
  overflow: hidden;
}

.sidebar {
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr) auto auto auto;
  gap: 12px;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
  padding: 14px;
  background: var(--sidebar);
  border-right: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
  padding: 4px 2px 8px;
}

.brand img {
  flex: 0 0 auto;
}

.brand strong,
.brand span {
  display: block;
}

.brand strong {
  line-height: 1.15;
}

.brand span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.82rem;
}

.primary-action,
.secondary-action,
.conversation-button,
.icon-button,
.send-button {
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
}

.primary-action,
.secondary-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  padding: 0 13px;
  text-decoration: none;
}

.primary-action {
  width: 100%;
  background: var(--text);
  color: #111111;
  border-color: transparent;
}

.secondary-action {
  background: var(--surface);
}

.primary-action.compact,
.secondary-action.compact {
  min-height: 34px;
  padding: 0 10px;
  font-size: 0.86rem;
}

.secondary-action:hover,
.conversation-button:hover,
.icon-button:hover {
  background: var(--surface-2);
}

.conversation-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 0;
  overflow-y: auto;
  padding-right: 2px;
}

.conversation-button {
  display: grid;
  width: 100%;
  min-height: 44px;
  padding: 8px 10px;
  background: transparent;
  text-align: left;
}

.conversation-button.is-active {
  background: var(--surface);
  border-color: #464646;
}

.conversation-button strong {
  overflow: hidden;
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-button span {
  margin-top: 2px;
  overflow: hidden;
  color: var(--soft);
  font-size: 0.76rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.side-card {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #141414;
}

.side-card span {
  color: var(--muted);
  font-size: 0.8rem;
}

.side-card strong {
  font-size: 0.92rem;
}

.user-card {
  gap: 12px;
}

.user-card small {
  display: block;
  margin-top: 4px;
  overflow: hidden;
  color: var(--soft);
  font-size: 0.76rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

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

.reminders-list {
  display: grid;
  gap: 7px;
  max-height: 180px;
  overflow-y: auto;
}

.reminder-item {
  display: grid;
  gap: 4px;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.reminder-item strong {
  overflow-wrap: anywhere;
  font-size: 0.84rem;
}

.reminder-item span,
.reminder-empty {
  color: var(--muted);
  font-size: 0.78rem;
}

.chat-main {
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr) auto auto;
  min-width: 0;
  min-height: 0;
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
  background: var(--bg);
}

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

.chat-header h1 {
  margin: 0;
  font-size: 1.05rem;
  line-height: 1.25;
  letter-spacing: 0;
}

.chat-header p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.82rem;
}

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

.segmented {
  display: grid;
  grid-auto-flow: column;
  min-height: 38px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #161616;
}

.mode-segment {
  grid-template-columns: repeat(3, minmax(68px, 1fr));
}

.mode-button {
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  padding: 0 10px;
  white-space: nowrap;
}

.mode-button.is-active {
  background: var(--surface-2);
  color: var(--text);
}

.icon-button,
.send-button {
  display: inline-grid;
  place-items: center;
  background: transparent;
}

.icon-button {
  width: 40px;
  height: 40px;
}

.icon-button.small {
  width: 30px;
  height: 30px;
}

.icon-button.small svg {
  width: 16px;
  height: 16px;
}

.icon-button.is-active {
  border-color: rgba(16, 163, 127, 0.58);
  color: var(--accent);
}

.icon-button.is-hidden,
.web-only,
.app-only {
  display: none;
}

html:not(.app-surface) .web-only {
  display: inline-flex;
}

.app-surface .app-only {
  display: grid;
}

.update-banner {
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin: 14px auto 0;
  width: min(820px, calc(100% - 32px));
  padding: 12px;
  border: 1px solid rgba(214, 168, 79, 0.42);
  border-radius: 8px;
  background: rgba(214, 168, 79, 0.1);
}

.update-banner[hidden] {
  display: none;
}

.update-banner strong,
.update-banner span {
  display: block;
}

.update-banner span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.84rem;
}

.limit-panel {
  display: grid;
  gap: 12px;
  width: min(820px, calc(100% - 32px));
  margin: 14px auto 0;
  padding: 14px;
  border: 1px solid rgba(240, 114, 114, 0.46);
  border-radius: 8px;
  background: rgba(240, 114, 114, 0.08);
}

.limit-panel strong {
  display: block;
  margin-bottom: 4px;
}

.limit-panel p {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.limit-actions,
.activation-form {
  display: grid;
  gap: 10px;
}

.limit-actions {
  grid-template-columns: minmax(0, 0.75fr) minmax(0, 1.25fr);
}

.activation-form {
  grid-template-columns: minmax(0, 1fr) auto;
}

.messages {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 24px 0;
}

.quick-actions {
  display: none;
}

.message {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  gap: 14px;
  width: min(820px, calc(100% - 32px));
  margin: 0 auto;
  padding: 18px 0;
}

.avatar {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 0.82rem;
  font-weight: 700;
}

.assistant .avatar {
  background: var(--accent);
  color: #07130f;
}

.message-body {
  display: grid;
  gap: 9px;
  min-width: 0;
  line-height: 1.58;
}

.message-meta {
  color: var(--muted);
  font-size: 0.78rem;
}

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

.message-text.error {
  color: var(--danger);
}

.message-text a {
  color: #8ab4ff;
  text-decoration: underline;
  text-underline-offset: 3px;
  overflow-wrap: anywhere;
}

.message-text a:hover {
  color: #b7ccff;
}

.generated-image {
  display: grid;
  gap: 10px;
  width: min(520px, 100%);
}

.generated-image img {
  display: block;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.image-download {
  justify-self: start;
  color: var(--text);
  font-size: 0.86rem;
}

.typing {
  display: inline-flex;
  gap: 5px;
  align-items: center;
}

.typing span {
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: var(--accent);
  animation: pulse 1s ease-in-out infinite;
}

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

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

.composer {
  position: sticky;
  bottom: 0;
  z-index: 3;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 46px;
  align-items: end;
  gap: 10px;
  width: min(820px, calc(100% - 32px));
  margin: 0 auto;
  padding: 12px 0;
  background: linear-gradient(180deg, rgba(16, 16, 16, 0), var(--bg) 24%);
}

.composer textarea {
  width: 100%;
  max-height: 132px;
  min-height: 48px;
  resize: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 13px 14px;
  background: var(--surface);
  color: var(--text);
  line-height: 1.35;
  outline: none;
}

.composer textarea:focus {
  border-color: rgba(16, 163, 127, 0.62);
  box-shadow: 0 0 0 3px rgba(16, 163, 127, 0.13);
}

.send-button {
  width: 46px;
  height: 46px;
  background: var(--text);
  color: #111111;
}

.send-button:disabled {
  cursor: progress;
  opacity: 0.62;
}

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

.admin-panel {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  padding: 18px;
  place-items: center;
  background: rgba(0, 0, 0, 0.72);
}

.admin-shell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  width: min(1120px, 100%);
  max-height: min(760px, calc(100dvh - 36px));
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #151515;
  box-shadow: 0 18px 70px var(--shadow);
}

.admin-header,
.admin-section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.admin-header {
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.admin-header strong {
  display: block;
  font-size: 1.05rem;
}

.admin-header span,
.admin-log span,
.admin-user-meta {
  color: var(--muted);
  font-size: 0.82rem;
}

.admin-content {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(260px, 0.65fr);
  gap: 14px;
  min-height: 0;
  overflow: auto;
  padding: 16px;
}

.admin-section {
  display: grid;
  align-content: start;
  gap: 12px;
  min-width: 0;
}

.admin-section h2 {
  margin: 0;
  font-size: 1rem;
  letter-spacing: 0;
}

.admin-users,
.admin-logs {
  display: grid;
  gap: 10px;
}

.admin-user,
.admin-log {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.admin-user-main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: start;
}

.admin-user-main strong {
  display: block;
  overflow-wrap: anywhere;
}

.admin-badge {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 8px;
  color: var(--muted);
  font-size: 0.74rem;
}

.admin-badge.is-blocked {
  border-color: rgba(240, 114, 114, 0.48);
  color: var(--danger);
}

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

.admin-controls label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 0.76rem;
}

.admin-key-result {
  color: var(--accent);
  font-size: 0.86rem;
  overflow-wrap: anywhere;
}

@keyframes pulse {
  0%,
  80%,
  100% {
    opacity: 0.35;
    transform: translateY(0);
  }

  40% {
    opacity: 1;
    transform: translateY(-4px);
  }
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 240px minmax(0, 1fr);
  }

  .mode-segment {
    display: none;
  }

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

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

@media (max-width: 760px) {
  .auth-screen {
    align-items: start;
    padding: 12px;
  }

  .auth-card {
    padding: 16px;
  }

  .auth-grid,
  .limit-actions,
  .activation-form {
    grid-template-columns: 1fr;
  }

  body {
    overflow: hidden;
  }

  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr);
    height: 100dvh;
    min-height: 0;
  }

  .sidebar {
    grid-template-rows: auto auto auto minmax(0, 1fr) auto auto auto;
    height: auto;
    max-height: 34dvh;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .conversation-list {
    max-height: 170px;
  }

  .chat-main {
    height: auto;
    min-height: 0;
    max-height: none;
  }

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

  .header-actions {
    width: 100%;
    flex-wrap: wrap;
  }

  .segmented {
    flex: 1 1 auto;
  }

  .message {
    grid-template-columns: 34px minmax(0, 1fr);
    gap: 10px;
    width: min(100% - 22px, 820px);
  }

  .composer {
    width: min(100% - 22px, 820px);
  }

  .admin-panel {
    padding: 8px;
  }

  .admin-shell {
    max-height: calc(100dvh - 16px);
  }

  .admin-content {
    padding: 12px;
  }
}

@media (max-width: 460px) {
  .mode-button {
    padding: 0 8px;
    font-size: 0.86rem;
  }

  .message {
    padding: 14px 0;
  }
}

@media (max-width: 760px) {
  .app-surface body {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100dvh;
    background: #0d0d0d;
  }

  .app-surface .app-shell {
    display: block;
    height: 100dvh;
    max-height: 100dvh;
    overflow: hidden;
  }

  .app-surface .sidebar {
    display: none;
  }

  .app-surface .chat-main {
    display: grid;
    grid-template-rows: auto auto minmax(0, 1fr);
    height: 100dvh;
    max-height: 100dvh;
    overflow: hidden;
  }

  .app-surface .chat-header {
    min-height: 108px;
    padding: 24px 22px 12px;
    border-bottom: 0;
    background: #0d0d0d;
  }

  .app-surface .chat-header > div:first-child {
    min-width: 0;
  }

  .app-surface .chat-header h1 {
    font-size: 1.25rem;
    line-height: 1.15;
  }

  .app-surface .chat-header p {
    display: none;
  }

  .app-surface .header-actions {
    margin-top: 12px;
    width: 100%;
    gap: 8px;
  }

  .app-surface .segmented {
    flex: 1 1 auto;
    min-height: 50px;
    border-radius: 14px;
    background: transparent;
  }

  .app-surface .mode-segment,
  .app-surface #installButton {
    display: none;
  }

  .app-surface .icon-button {
    width: 52px;
    height: 52px;
    border-radius: 14px;
    background: transparent;
  }

  .app-surface #voiceButton {
    order: 2;
  }

  .app-surface #clearButton {
    order: 3;
  }

  .app-surface .update-banner {
    display: none;
  }

  .app-surface .messages {
    padding: 16px 0 156px;
  }

  .app-surface.empty-chat .messages {
    display: none;
  }

  .app-surface .message {
    grid-template-columns: 48px minmax(0, 1fr);
    gap: 14px;
    width: calc(100% - 40px);
    padding: 18px 0;
  }

  .app-surface .avatar {
    width: 44px;
    height: 44px;
    border-radius: 13px;
  }

  .app-surface .message-body {
    font-size: 1.05rem;
    line-height: 1.62;
  }

  .app-surface .message-meta {
    font-size: 0.86rem;
  }

  .app-surface .quick-actions {
    position: fixed;
    left: 46px;
    right: 46px;
    bottom: 166px;
    display: grid;
    gap: 24px;
    z-index: 2;
  }

  .app-surface:not(.empty-chat) .quick-actions {
    display: none;
  }

  .quick-action {
    display: grid;
    grid-template-columns: 34px minmax(0, 1fr);
    align-items: center;
    gap: 18px;
    border: 0;
    background: transparent;
    color: var(--text);
    font-size: 1.45rem;
    line-height: 1.2;
    text-align: left;
  }

  .quick-action svg {
    width: 28px;
    height: 28px;
  }

  .app-surface .composer {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 72px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 54px;
    gap: 8px;
    width: calc(100% - 56px);
    margin: 0 auto;
    padding: 0;
    background: transparent;
  }

  .app-surface .composer textarea {
    min-height: 58px;
    max-height: 116px;
    border-radius: 29px;
    padding: 17px 18px;
    background: #242424;
    font-size: 1.12rem;
  }

  .app-surface .send-button {
    width: 54px;
    height: 54px;
    border-radius: 18px;
  }
}
