:root {
  color-scheme: light;
  --ink: #101414;
  --muted: #67706d;
  --line: #dbe2dd;
  --paper: #fffdf4;
  --panel: #ffffff;
  --wash: #f3f7f2;
  --green: #18a884;
  --green-dark: #06745d;
  --mint: #d8fff1;
  --yellow: #ffe94a;
  --yellow-soft: #fff6ba;
  --coral: #ff6b57;
  --shadow: 0 20px 60px rgba(16, 20, 20, 0.12);
  --radius: 8px;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(120deg, rgba(255, 233, 74, 0.42), rgba(216, 255, 241, 0.66) 48%, #f7f7f2 48%),
    var(--wash);
  letter-spacing: 0;
}

button,
input {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

button,
summary {
  touch-action: manipulation;
}

button:focus-visible,
summary:focus-visible,
.media-preview:focus-visible {
  outline: 3px solid rgba(255, 233, 74, 0.78);
  outline-offset: 2px;
}

input {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 13px;
  color: var(--ink);
  background: #fff;
  outline: none;
}

input:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(24, 168, 132, 0.16);
}

.hidden {
  display: none !important;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--green-dark);
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.auth-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(280px, 0.9fr) minmax(320px, 430px);
  gap: 18px;
  align-items: stretch;
  padding: 22px;
}

.brand-panel,
.auth-card,
.sidebar,
.chat-pane {
  border: 1px solid rgba(16, 20, 20, 0.08);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.86);
  box-shadow: var(--shadow);
}

.brand-panel {
  min-height: 520px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: clamp(24px, 5vw, 56px);
  background:
    linear-gradient(180deg, rgba(255, 253, 244, 0.66), rgba(255, 253, 244, 0.96)),
    repeating-linear-gradient(135deg, rgba(24, 168, 132, 0.16) 0 12px, transparent 12px 28px),
    var(--yellow-soft);
}

.brand-mark {
  width: 72px;
  height: 72px;
  display: grid;
  place-items: center;
  margin-bottom: auto;
  border: 3px solid var(--ink);
  border-radius: 22px;
  background: var(--yellow);
  box-shadow: 8px 8px 0 var(--green);
  font-size: 2.3rem;
  font-weight: 950;
}

.brand-panel h1 {
  margin: 0;
  font-size: clamp(3.2rem, 10vw, 7rem);
  line-height: 0.9;
  letter-spacing: 0;
}

.brand-copy {
  max-width: 580px;
  margin: 18px 0 0;
  color: #26312e;
  font-size: clamp(1.05rem, 2vw, 1.42rem);
  line-height: 1.35;
}

.security-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 28px;
}

.security-row span,
.security-pill {
  border: 1px solid rgba(6, 116, 93, 0.25);
  border-radius: 999px;
  padding: 7px 10px;
  color: var(--green-dark);
  background: rgba(216, 255, 241, 0.84);
  font-size: 0.82rem;
  font-weight: 800;
}

.auth-card {
  align-self: center;
  display: grid;
  gap: 15px;
  padding: 18px;
  background: rgba(255, 255, 255, 0.94);
}

.auth-card label {
  display: grid;
  gap: 7px;
  color: #303936;
  font-size: 0.88rem;
  font-weight: 800;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  border-radius: var(--radius);
  background: #eef4ef;
}

.segmented button {
  min-height: 42px;
  border-radius: 6px;
  color: var(--muted);
  background: transparent;
  font-weight: 900;
}

.segmented .selected {
  color: var(--ink);
  background: var(--yellow);
}

.primary-button,
.send-button,
.new-chat button {
  min-height: 44px;
  border-radius: var(--radius);
  color: #fff;
  background: var(--green);
  font-weight: 950;
}

.primary-button:hover,
.send-button:hover,
.new-chat button:hover {
  background: var(--green-dark);
}

.form-error,
.composer-status {
  min-height: 20px;
  margin: 0;
  color: #b92c1c;
  font-size: 0.9rem;
}

.app-shell {
  height: 100vh;
  display: grid;
  grid-template-columns: minmax(280px, 360px) 1fr;
  gap: 12px;
  padding: 12px;
}

.sidebar,
.chat-pane {
  min-height: 0;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.92);
}

.sidebar {
  display: grid;
  grid-template-rows: auto auto 1fr;
}

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

.sidebar-header h2,
.chat-header h2 {
  margin: 0;
  font-size: 1.08rem;
  letter-spacing: 0;
}

.sidebar-header > div,
.chat-header > div {
  min-width: 0;
}

.sidebar-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}

.chat-header h2,
.sidebar-header h2,
.chat-header .eyebrow,
.sidebar-header .eyebrow {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.icon-button,
.file-button,
.quality-toggle {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0 11px;
  color: var(--ink);
  background: #fff;
  font-size: 0.84rem;
  font-weight: 900;
}

.icon-button:hover,
.file-button:hover {
  border-color: var(--green);
}

.new-chat {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
}

.conversation-list {
  min-height: 0;
  overflow: auto;
  padding: 8px;
}

.conversation-button {
  width: 100%;
  display: grid;
  grid-template-columns: 42px 1fr;
  gap: 10px;
  align-items: center;
  margin-bottom: 6px;
  border-radius: var(--radius);
  padding: 10px;
  color: var(--ink);
  background: transparent;
  text-align: left;
}

.conversation-button:hover,
.conversation-button.selected {
  background: #effaf5;
}

.avatar {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: #fff;
  background: var(--green);
  font-weight: 950;
}

.conversation-meta {
  min-width: 0;
}

.conversation-meta strong,
.conversation-meta span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-meta strong {
  font-size: 0.95rem;
}

.conversation-meta span {
  color: var(--muted);
  font-size: 0.82rem;
}

.device-dot {
  display: inline-flex;
  width: max-content;
  max-width: 100%;
  margin-top: 4px;
  border-radius: 999px;
  padding: 3px 7px;
  color: #372f00;
  background: var(--yellow);
  font-size: 0.72rem;
  font-weight: 900;
}

.chat-pane {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto auto auto auto;
}

.device-banner {
  margin: 10px 14px 0;
  border: 1px solid rgba(255, 107, 87, 0.28);
  border-radius: var(--radius);
  padding: 10px 12px;
  color: #5b1b12;
  background: #fff0ec;
  font-size: 0.9rem;
  font-weight: 800;
}

.messages {
  min-height: 0;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 16px 14px;
  background:
    linear-gradient(rgba(255, 253, 244, 0.88), rgba(255, 253, 244, 0.88)),
    repeating-linear-gradient(45deg, rgba(24, 168, 132, 0.08) 0 1px, transparent 1px 18px);
}

.load-more {
  align-self: center;
  min-height: 40px;
  border: 1px solid rgba(6, 116, 93, 0.22);
  border-radius: var(--radius);
  padding: 0 14px;
  color: var(--green-dark);
  background: rgba(216, 255, 241, 0.88);
  font-size: 0.86rem;
  font-weight: 950;
}

.empty-state {
  max-width: 360px;
  margin: auto;
  padding: 18px;
  border: 1px dashed rgba(6, 116, 93, 0.32);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.74);
  text-align: center;
}

.empty-state h3 {
  margin: 0 0 5px;
  font-size: 1.25rem;
}

.empty-state p {
  margin: 0;
  color: var(--muted);
}

.message-row {
  display: flex;
  width: 100%;
}

.message-row.own {
  justify-content: flex-end;
}

.message-bubble {
  position: relative;
  max-width: min(680px, 78%);
  border-radius: var(--radius);
  padding: 9px 38px 9px 11px;
  color: var(--ink);
  background: #fff;
  box-shadow: 0 2px 10px rgba(16, 20, 20, 0.08);
}

.message-row.own .message-bubble {
  background: #dcffe8;
}

.unsent-bubble,
.message-row.own .unsent-bubble {
  padding-right: 11px;
  color: var(--muted);
  background: #f1f5f0;
}

.unsent-bubble p {
  font-style: italic;
}

.message-bubble p {
  margin: 0;
  overflow-wrap: anywhere;
  line-height: 1.38;
}

.message-actions {
  position: absolute;
  top: 4px;
  right: 5px;
  z-index: 5;
}

.message-actions summary {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  color: var(--muted);
  font-size: 1rem;
  font-weight: 950;
  line-height: 1;
  list-style: none;
  cursor: pointer;
}

.message-actions summary::-webkit-details-marker {
  display: none;
}

.message-actions summary:hover,
.message-actions[open] summary {
  color: var(--ink);
  background: rgba(16, 20, 20, 0.07);
}

.message-menu {
  position: absolute;
  top: 34px;
  right: 0;
  min-width: 148px;
  overflow: hidden;
  border: 1px solid rgba(16, 20, 20, 0.12);
  border-radius: var(--radius);
  background: #fff;
  box-shadow: 0 16px 34px rgba(16, 20, 20, 0.18);
}

.message-menu button {
  width: 100%;
  min-height: 40px;
  padding: 0 12px;
  color: var(--ink);
  background: #fff;
  font-size: 0.88rem;
  font-weight: 900;
  text-align: left;
}

.message-menu button:hover,
.message-menu button:focus-visible {
  background: #effaf5;
  outline-offset: -3px;
}

.reply-quote,
.reply-preview {
  border-left: 4px solid var(--green);
  border-radius: 6px;
  color: #283330;
  background: rgba(255, 255, 255, 0.58);
}

.reply-quote {
  display: grid;
  gap: 2px;
  margin: 0 0 8px;
  padding: 7px 9px;
}

.reply-quote span,
.reply-preview span {
  color: var(--green-dark);
  font-size: 0.72rem;
  font-weight: 950;
}

.reply-quote strong,
.reply-preview strong {
  overflow: hidden;
  color: var(--ink);
  font-size: 0.84rem;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.message-time {
  display: block;
  margin-top: 5px;
  color: #6d7a75;
  font-size: 0.72rem;
  text-align: right;
}

.system-event {
  align-self: center;
  max-width: min(560px, 92%);
  border-radius: 999px;
  padding: 7px 11px;
  color: #4a4004;
  background: rgba(255, 233, 74, 0.86);
  font-size: 0.8rem;
  font-weight: 900;
  text-align: center;
}

.media-shell {
  display: grid;
  gap: 8px;
  min-width: min(320px, 70vw);
}

.media-tap {
  min-height: 56px;
  display: grid;
  grid-template-columns: 24px 1fr;
  gap: 10px;
  align-items: center;
  border: 1px solid rgba(16, 20, 20, 0.08);
  border-radius: var(--radius);
  padding: 9px 10px;
  color: var(--ink);
  background:
    linear-gradient(90deg, rgba(255, 233, 74, 0.34), rgba(216, 255, 241, 0.46)),
    #fff;
  text-align: left;
}

.media-tap:hover,
.media-tap:focus-visible {
  border-color: rgba(6, 116, 93, 0.42);
  box-shadow: 0 0 0 3px rgba(24, 168, 132, 0.14);
  outline: none;
}

.media-tap:disabled {
  cursor: wait;
  opacity: 0.78;
}

.media-tap-icon {
  width: 20px;
  height: 20px;
  border-radius: 5px;
  background: var(--coral);
  box-shadow: 4px 4px 0 var(--yellow);
}

.media-tap-icon.video {
  background: var(--green);
}

.media-tap-copy {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.media-tap-copy strong,
.media-tap-copy span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.media-tap-copy strong {
  font-size: 1rem;
  font-weight: 950;
}

.media-tap-copy span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

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

.expired-media {
  border: 1px dashed rgba(103, 112, 109, 0.45);
  border-radius: var(--radius);
  padding: 9px 10px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.72);
  font-size: 0.84rem;
  font-weight: 800;
}

.media-preview {
  max-width: min(520px, 72vw);
  max-height: 420px;
  border-radius: var(--radius);
  background: #111;
  object-fit: contain;
  cursor: zoom-in;
}

video.media-preview {
  cursor: default;
}

.typing-indicator {
  min-height: 32px;
  padding: 6px 16px;
  color: var(--green-dark);
  background: #fff;
  font-size: 0.86rem;
  font-weight: 900;
}

.reply-preview {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  margin: 8px 14px 0;
  padding: 8px 9px;
  background: #f5fff9;
}

.reply-preview > div {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.reply-preview button {
  min-height: 34px;
  border-radius: var(--radius);
  padding: 0 10px;
  color: var(--green-dark);
  background: rgba(216, 255, 241, 0.88);
  font-size: 0.82rem;
  font-weight: 950;
}

.composer {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  gap: 8px;
  align-items: center;
  padding: 12px 14px 8px;
  border-top: 1px solid var(--line);
  background: #fff;
}

.file-button input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  opacity: 0;
}

.quality-toggle input {
  width: 16px;
  height: 16px;
  accent-color: var(--green);
}

.send-button {
  min-width: 76px;
}

.composer-status {
  padding: 0 14px 10px;
  color: var(--muted);
}

.toast-region {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 20;
  display: grid;
  gap: 8px;
  width: min(360px, calc(100vw - 36px));
}

.toast {
  border: 1px solid rgba(16, 20, 20, 0.08);
  border-radius: var(--radius);
  padding: 12px;
  color: var(--ink);
  background: #fff;
  box-shadow: var(--shadow);
  font-weight: 800;
}

.media-lightbox {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 10px;
  padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right))
    max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  background: rgba(12, 15, 14, 0.92);
}

.lightbox-close {
  justify-self: end;
  min-height: 44px;
  border-radius: var(--radius);
  padding: 0 14px;
  color: #111;
  background: var(--yellow);
  font-weight: 950;
}

.lightbox-content {
  min-height: 0;
  display: grid;
  place-items: center;
}

.lightbox-content img {
  max-width: 100%;
  max-height: 100%;
  border-radius: var(--radius);
  object-fit: contain;
}

.show-chats {
  display: none;
}

@media (max-width: 860px) {
  html,
  body {
    height: 100%;
  }

  .auth-shell {
    grid-template-columns: 1fr;
    padding: 10px;
  }

  .brand-panel {
    min-height: 320px;
  }

  .app-shell {
    height: 100dvh;
    min-height: 100dvh;
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
    gap: 8px;
    overflow: hidden;
    padding: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right))
      max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
  }

  .sidebar,
  .chat-pane {
    height: calc(100dvh - 16px);
    max-height: none;
    min-height: 0;
  }

  body.chat-focused .sidebar {
    display: none;
  }

  body:not(.chat-focused) .chat-pane {
    display: none;
  }

  input {
    min-height: 44px;
    font-size: 16px;
  }

  .conversation-button {
    min-height: 58px;
    padding: 12px 10px;
  }

  .show-chats {
    display: inline-flex;
  }

  .message-bubble {
    max-width: 90%;
  }
}

@media (max-width: 560px) {
  .auth-shell {
    min-height: auto;
  }

  .brand-panel {
    padding: 22px;
  }

  .brand-mark {
    width: 58px;
    height: 58px;
    border-radius: 18px;
    font-size: 1.8rem;
  }

  .app-shell {
    height: 100dvh;
    min-height: 100dvh;
  }

  .sidebar-header,
  .chat-header {
    min-height: 68px;
    padding: 10px;
  }

  .new-chat {
    grid-template-columns: 1fr;
  }

  .composer {
    grid-template-columns: auto minmax(0, 1fr) auto;
    padding: 10px;
  }

  #message-input {
    grid-column: 2 / -1;
  }

  .file-button {
    justify-content: flex-start;
  }

  .quality-toggle {
    grid-column: 1 / 3;
    justify-content: flex-start;
  }

  .send-button {
    grid-row: 2;
    grid-column: 3;
    align-self: stretch;
  }

  .icon-button,
  .file-button,
  .quality-toggle,
  .send-button,
  .new-chat button,
  .media-tap {
    min-height: 44px;
  }

  .message-bubble {
    max-width: 92%;
  }

  .messages {
    padding: 12px 10px;
  }

  .media-preview {
    max-width: 82vw;
    max-height: 320px;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    scroll-behavior: auto !important;
  }
}
