/* Grok Chat — UI premium (dark default + light opcional) */

:root {
  color-scheme: dark;
  --bg: #07080d;
  --bg-elevated: #0e1018;
  --surface: rgba(22, 26, 38, 0.72);
  --surface-solid: #141824;
  --surface-2: #1a1f2e;
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.14);
  --text: #f2f4f8;
  --text-secondary: #c4cad8;
  --muted: #8b93a7;
  --accent: #8b5cf6;
  --accent-2: #3b82f6;
  --accent-soft: rgba(139, 92, 246, 0.14);
  --user: linear-gradient(135deg, #6366f1 0%, #3b82f6 100%);
  --user-solid: #4f46e5;
  --danger: #f87171;
  --danger-bg: rgba(248, 113, 113, 0.1);
  --danger-border: rgba(248, 113, 113, 0.28);
  --ok: #34d399;
  --ok-bg: rgba(52, 211, 153, 0.1);
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.45);
  --shadow-sm: 0 2px 12px rgba(0, 0, 0, 0.28);
  --radius: 16px;
  --radius-sm: 12px;
  --radius-xs: 8px;
  --sidebar-w: 280px;
  --composer-max: 820px;
  --topbar-h: 60px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --ease: 180ms ease;
  --ring: 0 0 0 3px rgba(139, 92, 246, 0.35);
  --glass: blur(16px) saturate(1.2);
  --scrollbar: rgba(255, 255, 255, 0.12);
  --scrollbar-hover: rgba(255, 255, 255, 0.22);
  --code-bg: #0a0c12;
  --avatar-g: linear-gradient(135deg, #a78bfa, #60a5fa);
}

html[data-theme="light"] {
  color-scheme: light;
  --bg: #f4f5f9;
  --bg-elevated: #ffffff;
  --surface: rgba(255, 255, 255, 0.78);
  --surface-solid: #ffffff;
  --surface-2: #eef0f6;
  --border: rgba(15, 23, 42, 0.08);
  --border-strong: rgba(15, 23, 42, 0.14);
  --text: #0f172a;
  --text-secondary: #334155;
  --muted: #64748b;
  --accent-soft: rgba(99, 102, 241, 0.1);
  --shadow: 0 8px 28px rgba(15, 23, 42, 0.08);
  --shadow-sm: 0 2px 10px rgba(15, 23, 42, 0.06);
  --ring: 0 0 0 3px rgba(99, 102, 241, 0.28);
  --scrollbar: rgba(15, 23, 42, 0.15);
  --scrollbar-hover: rgba(15, 23, 42, 0.28);
  --code-bg: #f1f5f9;
  --danger-bg: rgba(239, 68, 68, 0.08);
  --danger-border: rgba(239, 68, 68, 0.25);
}

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* Ambient background */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background:
    radial-gradient(900px 500px at 10% -10%, rgba(139, 92, 246, 0.18), transparent 55%),
    radial-gradient(700px 420px at 100% 0%, rgba(59, 130, 246, 0.12), transparent 50%),
    radial-gradient(600px 400px at 50% 100%, rgba(99, 102, 241, 0.08), transparent 55%);
}

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

button {
  cursor: pointer;
  border: none;
  background: none;
}

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

:focus-visible {
  outline: none;
  box-shadow: var(--ring);
}

/* Shell */
.shell {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  height: 100dvh;
  max-height: 100dvh;
}

/* Sidebar */
.sidebar {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 16px 14px;
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  min-height: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 8px 16px;
}

.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 12px;
  background: var(--avatar-g);
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 700;
  font-size: 0.95rem;
  box-shadow: 0 4px 16px rgba(99, 102, 241, 0.35);
  flex-shrink: 0;
}

.brand-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.brand-text strong {
  font-size: 0.98rem;
  letter-spacing: -0.02em;
}

.brand-text span {
  font-size: 0.72rem;
  color: var(--muted);
}

.btn-new {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, #7c3aed 0%, #4f46e5 50%, #2563eb 100%);
  color: #fff;
  font-weight: 600;
  font-size: 0.9rem;
  box-shadow: 0 6px 20px rgba(79, 70, 229, 0.35);
  transition: transform var(--ease), filter var(--ease), box-shadow var(--ease);
}

.btn-new:hover:not(:disabled) {
  filter: brightness(1.06);
  transform: translateY(-1px);
}

.btn-new:active:not(:disabled) {
  transform: translateY(0);
}

.btn-new svg {
  width: 16px;
  height: 16px;
}

.nav-section {
  margin-top: 8px;
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 0 4px;
}

.nav-label {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 8px 10px 6px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  border-radius: var(--radius-xs);
  color: var(--text-secondary);
  font-size: 0.88rem;
  transition: background var(--ease), color var(--ease);
}

.nav-item:hover {
  background: var(--accent-soft);
  color: var(--text);
}

.nav-item.active {
  background: var(--accent-soft);
  color: var(--text);
  font-weight: 600;
}

.nav-item svg {
  width: 16px;
  height: 16px;
  opacity: 0.85;
  flex-shrink: 0;
}

.sidebar-footer {
  margin-top: auto;
  padding: 12px 10px 4px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.secure-badge {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 0.72rem;
  color: var(--muted);
  line-height: 1.4;
  padding: 10px;
  border-radius: var(--radius-xs);
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.secure-badge svg {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  margin-top: 1px;
  color: var(--ok);
}

.theme-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border-radius: var(--radius-xs);
  border: 1px solid var(--border);
  background: var(--surface-solid);
  color: var(--text-secondary);
  font-size: 0.8rem;
  transition: border-color var(--ease), color var(--ease);
}

.theme-toggle:hover {
  border-color: var(--border-strong);
  color: var(--text);
}

/* Main */
.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: transparent;
}

.topbar {
  height: var(--topbar-h);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg-elevated) 80%, transparent);
  backdrop-filter: var(--glass);
  -webkit-backdrop-filter: var(--glass);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.menu-btn {
  display: none;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-xs);
  border: 1px solid var(--border);
  background: var(--surface-solid);
  align-items: center;
  justify-content: center;
  color: var(--text);
  transition: background var(--ease);
}

.menu-btn:hover {
  background: var(--surface-2);
}

.menu-btn svg {
  width: 18px;
  height: 18px;
}

.topbar-title {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar-title h1 {
  font-size: 0.98rem;
  font-weight: 650;
  letter-spacing: -0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.68rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--muted);
}

.badge.accent {
  color: #c4b5fd;
  border-color: rgba(139, 92, 246, 0.35);
  background: var(--accent-soft);
}

html[data-theme="light"] .badge.accent {
  color: #5b21b6;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 0 3px rgba(52, 211, 153, 0.2);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-xs);
  border: 1px solid var(--border);
  background: var(--surface-solid);
  display: grid;
  place-items: center;
  color: var(--text-secondary);
  transition: color var(--ease), border-color var(--ease), background var(--ease), transform var(--ease);
}

.icon-btn:hover:not(:disabled) {
  color: var(--text);
  border-color: var(--border-strong);
  background: var(--surface-2);
}

.icon-btn:active:not(:disabled) {
  transform: scale(0.97);
}

.icon-btn svg {
  width: 18px;
  height: 18px;
}

.icon-btn.active {
  color: #c4b5fd;
  border-color: rgba(139, 92, 246, 0.4);
  background: var(--accent-soft);
}

/* Chat area */
.chat-area {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  position: relative;
}

.messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 20px 16px 12px;
  scroll-behavior: smooth;
}

.messages::-webkit-scrollbar {
  width: 8px;
}
.messages::-webkit-scrollbar-track {
  background: transparent;
}
.messages::-webkit-scrollbar-thumb {
  background: var(--scrollbar);
  border-radius: 999px;
}
.messages::-webkit-scrollbar-thumb:hover {
  background: var(--scrollbar-hover);
}

.messages-inner {
  max-width: var(--composer-max);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: 100%;
}

/* Empty state */
.empty {
  margin: auto;
  max-width: 560px;
  text-align: center;
  padding: 32px 12px 48px;
  animation: fadeUp 0.35s ease both;
}

.empty-icon {
  width: 72px;
  height: 72px;
  margin: 0 auto 18px;
  border-radius: 22px;
  background: var(--avatar-g);
  display: grid;
  place-items: center;
  color: #fff;
  box-shadow: 0 12px 40px rgba(99, 102, 241, 0.35);
}

.empty-icon svg {
  width: 34px;
  height: 34px;
}

.empty h2 {
  font-size: 1.45rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  margin-bottom: 8px;
}

.empty p {
  color: var(--muted);
  font-size: 0.9rem;
  margin-bottom: 22px;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.chip {
  padding: 10px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-solid);
  color: var(--text-secondary);
  font-size: 0.82rem;
  transition: border-color var(--ease), background var(--ease), color var(--ease), transform var(--ease);
  box-shadow: var(--shadow-sm);
}

.chip:hover {
  border-color: rgba(139, 92, 246, 0.45);
  background: var(--accent-soft);
  color: var(--text);
  transform: translateY(-1px);
}

.empty-privacy {
  margin-top: 22px;
  font-size: 0.75rem;
  color: var(--muted);
}

/* Messages */
.msg-row {
  display: flex;
  gap: 12px;
  animation: fadeUp 0.28s ease both;
  max-width: 100%;
}

.msg-row.user {
  flex-direction: row-reverse;
}

.avatar {
  width: 34px;
  height: 34px;
  border-radius: 11px;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  font-size: 0.78rem;
  font-weight: 700;
  color: #fff;
  margin-top: 2px;
}

.avatar.grok {
  background: var(--avatar-g);
  box-shadow: 0 4px 14px rgba(99, 102, 241, 0.3);
}

.avatar.user {
  background: linear-gradient(135deg, #64748b, #475569);
}

.msg-col {
  min-width: 0;
  max-width: min(100%, 720px);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.msg-row.user .msg-col {
  align-items: flex-end;
  max-width: min(100%, 560px);
}

.msg-row.assistant .msg-col {
  max-width: min(100%, 760px);
  width: 100%;
}

.msg-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.72rem;
  color: var(--muted);
  padding: 0 4px;
}

.msg-row.user .msg-meta {
  flex-direction: row-reverse;
}

.bubble {
  position: relative;
  padding: 12px 14px;
  border-radius: 16px;
  font-size: 0.95rem;
  line-height: 1.6;
  overflow-wrap: anywhere;
  word-break: break-word;
  box-shadow: var(--shadow-sm);
}

.msg-row.assistant .bubble {
  background: var(--surface-solid);
  border: 1px solid var(--border);
  border-bottom-left-radius: 6px;
  padding: 14px 16px 16px;
}

.msg-row.user .bubble {
  background: var(--user);
  color: #fff;
  border-bottom-right-radius: 6px;
}

/* Texto plano (user / fallback) */
.bubble .body.plain {
  white-space: pre-wrap;
}

.bubble .body p + p {
  margin-top: 0.65em;
}

/* ——— Markdown prose (assistant, estilo grok/docs) ——— */
.md {
  font-size: 0.95rem;
  line-height: 1.65;
  color: var(--text);
  overflow-wrap: anywhere;
}

.md > *:first-child {
  margin-top: 0 !important;
}

.md > *:last-child {
  margin-bottom: 0 !important;
}

.md h1,
.md h2,
.md h3,
.md h4 {
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.3;
  color: var(--text);
  margin: 1.15em 0 0.45em;
}

.md h1 { font-size: 1.28rem; }
.md h2 { font-size: 1.12rem; margin-top: 1.25em; }
.md h3 { font-size: 1.02rem; font-weight: 650; }

.md p {
  margin: 0.55em 0;
  line-height: 1.65;
  color: var(--text-secondary);
}

.md strong {
  color: var(--text);
  font-weight: 650;
}

.md em {
  font-style: italic;
}

.md del {
  opacity: 0.75;
}

.md ul,
.md ol {
  margin: 0.55em 0;
  padding-left: 1.35em;
  color: var(--text-secondary);
}

.md li {
  margin: 0.28em 0;
  padding-left: 0.15em;
}

.md li > ul,
.md li > ol {
  margin: 0.25em 0;
}

.md blockquote {
  margin: 0.75em 0;
  padding: 0.55em 0.9em;
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
  border-radius: 0 10px 10px 0;
  color: var(--text-secondary);
}

.md blockquote p {
  margin: 0.3em 0;
}

.md hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 1.1em 0;
}

.md a {
  color: #a78bfa;
  text-decoration: underline;
  text-underline-offset: 2px;
}

html[data-theme="light"] .md a {
  color: #5b21b6;
}

.md a:hover {
  color: var(--accent-2);
}

/* Tablas */
.md .table-wrap {
  width: 100%;
  overflow-x: auto;
  margin: 0.85em 0;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  -webkit-overflow-scrolling: touch;
}

.md table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.86rem;
  min-width: 420px;
}

.md thead th {
  text-align: left;
  font-weight: 650;
  color: var(--text);
  background: color-mix(in srgb, var(--surface-solid) 70%, var(--accent-soft));
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-strong);
  white-space: nowrap;
  position: sticky;
  top: 0;
}

.md tbody td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text-secondary);
  vertical-align: top;
}

.md tbody tr:nth-child(even) td {
  background: rgba(127, 127, 160, 0.06);
}

.md tbody tr:last-child td {
  border-bottom: none;
}

/* Código */
.md :not(pre) > code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.86em;
  padding: 0.12em 0.4em;
  border-radius: 6px;
  background: rgba(127, 127, 160, 0.16);
  color: var(--text);
}

.md .code-block {
  position: relative;
  margin: 0.85em 0;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--code-bg);
  overflow: hidden;
}

.md .code-block .code-lang {
  position: absolute;
  top: 8px;
  left: 12px;
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  pointer-events: none;
}

.md .code-block .code-copy {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 2;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 9px;
  border-radius: 8px;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--muted);
  background: color-mix(in srgb, var(--surface-solid) 80%, transparent);
  border: 1px solid var(--border);
  transition: color var(--ease), background var(--ease), border-color var(--ease);
}

.md .code-block .code-copy:hover {
  color: var(--text);
  border-color: var(--border-strong);
}

.md .code-block pre {
  margin: 0;
  padding: 36px 14px 14px;
  overflow-x: auto;
  font-size: 0.82rem;
  line-height: 1.55;
  white-space: pre;
  background: transparent;
  border: none;
}

.md .code-block code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: inherit;
  background: none;
  padding: 0;
  color: var(--text);
}

/* Chips de opciones al final de la respuesta */
.choice-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
  padding-top: 4px;
}

.choice-chip {
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid rgba(139, 92, 246, 0.35);
  background: var(--accent-soft);
  color: var(--text);
  font-size: 0.82rem;
  font-weight: 550;
  text-align: left;
  transition: transform var(--ease), border-color var(--ease), filter var(--ease);
  max-width: 100%;
}

.choice-chip:hover:not(:disabled) {
  border-color: rgba(139, 92, 246, 0.65);
  transform: translateY(-1px);
  filter: brightness(1.05);
}

.choice-chip:disabled {
  opacity: 0.5;
}

/* User bubble code (simple) */
.msg-row.user .bubble pre {
  margin: 10px 0;
  padding: 12px 14px;
  border-radius: var(--radius-xs);
  background: rgba(0, 0, 0, 0.22);
  border: 1px solid rgba(255, 255, 255, 0.12);
  overflow-x: auto;
  font-size: 0.82rem;
  white-space: pre;
}

.msg-row.user .bubble code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.88em;
}

.msg-row.user .bubble :not(pre) > code {
  padding: 1px 5px;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.2);
}

.attach-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.attach-preview img.thumb {
  max-width: 160px;
  max-height: 120px;
  border-radius: 10px;
  object-fit: cover;
  border: 1px solid rgba(255, 255, 255, 0.15);
  cursor: zoom-in;
  transition: transform var(--ease);
}

.attach-preview img.thumb:hover {
  transform: scale(1.02);
}

.attach-chip {
  font-size: 0.78rem;
  padding: 6px 10px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.18);
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.msg-row.assistant .attach-chip {
  background: var(--surface-2);
  border-color: var(--border);
}

.msg-actions {
  display: flex;
  gap: 4px;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--ease);
  padding: 0 2px;
}

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

.msg-action {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 0.72rem;
  color: var(--muted);
  border: 1px solid transparent;
  transition: background var(--ease), color var(--ease), border-color var(--ease);
}

.msg-action:hover {
  color: var(--text);
  background: var(--surface-2);
  border-color: var(--border);
}

.msg-action svg {
  width: 13px;
  height: 13px;
}

/* Error / system cards */
.card-error {
  max-width: var(--composer-max);
  margin: 0 auto;
  width: 100%;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: var(--danger-bg);
  border: 1px solid var(--danger-border);
  color: var(--danger);
  font-size: 0.88rem;
  line-height: 1.45;
  animation: fadeUp 0.28s ease both;
  display: flex;
  gap: 10px;
  align-items: flex-start;
}

.card-error svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  margin-top: 1px;
}

.card-image {
  max-width: var(--composer-max);
  margin: 0 auto;
  width: 100%;
  padding: 14px;
  border-radius: var(--radius);
  background: var(--surface-solid);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  animation: fadeUp 0.28s ease both;
}

.card-image h3 {
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 10px;
  color: var(--text-secondary);
}

.card-image img {
  max-width: 100%;
  max-height: 360px;
  border-radius: 12px;
  display: block;
  cursor: zoom-in;
  border: 1px solid var(--border);
}

.card-image .note {
  margin-top: 8px;
  font-size: 0.75rem;
  color: var(--muted);
}

/* Typing indicator */
.typing {
  display: flex;
  align-items: center;
  gap: 12px;
  animation: fadeUp 0.2s ease both;
}

.typing .bubble {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 0.85rem;
  min-width: 120px;
}

.dots {
  display: inline-flex;
  gap: 4px;
}

.dots i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
  display: block;
  animation: bounce 1.2s infinite ease-in-out;
}

.dots i:nth-child(2) { animation-delay: 0.15s; }
.dots i:nth-child(3) { animation-delay: 0.3s; }

/* Composer */
.composer-wrap {
  flex-shrink: 0;
  padding: 0 16px calc(14px + env(safe-area-inset-bottom, 0px));
}

.composer {
  max-width: var(--composer-max);
  margin: 0 auto;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: color-mix(in srgb, var(--surface-solid) 88%, transparent);
  backdrop-filter: var(--glass);
  -webkit-backdrop-filter: var(--glass);
  box-shadow: var(--shadow);
  padding: 10px 12px 8px;
  transition: border-color var(--ease), box-shadow var(--ease);
}

.composer:focus-within {
  border-color: rgba(139, 92, 246, 0.45);
  box-shadow: var(--shadow), 0 0 0 3px rgba(139, 92, 246, 0.12);
}

.pending {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}

.pending:empty {
  display: none;
}

.pending-item {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px 8px;
  font-size: 0.78rem;
  max-width: 100%;
}

.pending-item img {
  width: 36px;
  height: 36px;
  object-fit: cover;
  border-radius: 6px;
}

.pending-item .meta {
  min-width: 0;
  color: var(--muted);
}

.pending-item .name {
  color: var(--text);
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pending-item .rm {
  color: var(--muted);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 1rem;
  line-height: 1;
}

.pending-item .rm:hover {
  color: var(--danger);
  background: var(--danger-bg);
}

.composer-row {
  display: flex;
  align-items: flex-end;
  gap: 6px;
}

#input {
  flex: 1;
  resize: none;
  border: none;
  background: transparent;
  color: var(--text);
  padding: 10px 8px;
  min-height: 44px;
  max-height: 160px;
  line-height: 1.45;
  outline: none;
  box-shadow: none !important;
}

#input::placeholder {
  color: var(--muted);
}

.composer-tools {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
  padding-bottom: 4px;
}

.tool-btn {
  width: 38px;
  height: 38px;
  border-radius: 11px;
  display: grid;
  place-items: center;
  color: var(--muted);
  transition: background var(--ease), color var(--ease);
}

.tool-btn:hover:not(:disabled) {
  background: var(--surface-2);
  color: var(--text);
}

.tool-btn.active {
  background: var(--accent-soft);
  color: #c4b5fd;
}

.tool-btn svg {
  width: 18px;
  height: 18px;
}

.send-btn {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  color: #fff;
  background: linear-gradient(135deg, #7c3aed, #4f46e5 50%, #2563eb);
  box-shadow: 0 4px 14px rgba(79, 70, 229, 0.4);
  transition: filter var(--ease), transform var(--ease), opacity var(--ease);
}

.send-btn:hover:not(:disabled) {
  filter: brightness(1.08);
  transform: translateY(-1px);
}

.send-btn:disabled {
  opacity: 0.45;
  filter: grayscale(0.3);
}

.send-btn svg {
  width: 18px;
  height: 18px;
}

.composer-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 4px 6px 2px;
  font-size: 0.7rem;
  color: var(--muted);
}

.file-count {
  color: var(--muted);
}

#fileInput {
  display: none;
}

/* Image drawer */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s ease;
}

.overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 50;
  width: min(420px, 100%);
  height: 100dvh;
  background: var(--bg-elevated);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  transform: translateX(105%);
  transition: transform 0.28s cubic-bezier(0.22, 1, 0.36, 1);
}

.drawer.open {
  transform: translateX(0);
}

.drawer-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 18px 12px;
  border-bottom: 1px solid var(--border);
}

.drawer-header h2 {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.drawer-header p {
  margin-top: 4px;
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.4;
}

.drawer-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 16px 18px 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.field label {
  display: block;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 6px;
}

.field textarea,
.field select {
  width: 100%;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-solid);
  color: var(--text);
  padding: 12px 14px;
  transition: border-color var(--ease);
}

.field textarea {
  min-height: 110px;
  resize: vertical;
  line-height: 1.45;
}

.field textarea:focus,
.field select:focus {
  border-color: rgba(139, 92, 246, 0.5);
}

.btn-cta {
  width: 100%;
  padding: 13px 16px;
  border-radius: var(--radius-sm);
  font-weight: 650;
  font-size: 0.92rem;
  color: #fff;
  background: linear-gradient(135deg, #7c3aed, #4f46e5 50%, #2563eb);
  box-shadow: 0 6px 18px rgba(79, 70, 229, 0.35);
  transition: filter var(--ease), transform var(--ease);
}

.btn-cta:hover:not(:disabled) {
  filter: brightness(1.06);
  transform: translateY(-1px);
}

.img-status {
  font-size: 0.84rem;
  color: var(--muted);
  min-height: 1.25em;
  line-height: 1.4;
}

.img-status.error { color: var(--danger); }
.img-status.ok { color: var(--ok); }

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

.gallery-item {
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--surface-2);
  display: flex;
  flex-direction: column;
}

.gallery-item img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  cursor: zoom-in;
  background: #000;
}

.gallery-item .actions {
  padding: 8px;
}

.gallery-item a {
  display: block;
  text-align: center;
  text-decoration: none;
  color: var(--text-secondary);
  font-size: 0.78rem;
  font-weight: 600;
  padding: 8px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-solid);
  transition: color var(--ease), border-color var(--ease);
}

.gallery-item a:hover {
  color: var(--text);
  border-color: var(--border-strong);
}

/* Lightbox */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(0, 0, 0, 0.88);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.lightbox.open {
  opacity: 1;
  pointer-events: auto;
}

.lightbox img {
  max-width: min(96vw, 1100px);
  max-height: 90dvh;
  border-radius: 12px;
  box-shadow: var(--shadow);
  object-fit: contain;
}

.lightbox-close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.15);
}

.lightbox-close svg {
  width: 20px;
  height: 20px;
}

/* Sidebar overlay mobile */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgba(0, 0, 0, 0.45);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

/* Animations */
@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.45; }
  40% { transform: translateY(-4px); opacity: 1; }
}

/* Responsive */
@media (max-width: 900px) {
  .shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 35;
    width: min(var(--sidebar-w), 88vw);
    height: 100dvh;
    transform: translateX(-105%);
    transition: transform 0.28s cubic-bezier(0.22, 1, 0.36, 1);
    box-shadow: var(--shadow);
  }

  .shell.sidebar-open .sidebar {
    transform: translateX(0);
  }

  .sidebar-backdrop {
    display: block;
  }

  .shell.sidebar-open .sidebar-backdrop {
    opacity: 1;
    pointer-events: auto;
  }

  .menu-btn {
    display: inline-flex;
  }

  .messages {
    padding: 14px 12px 8px;
  }

  .composer-wrap {
    padding-left: 12px;
    padding-right: 12px;
  }

  .msg-actions {
    opacity: 1;
    pointer-events: auto;
  }

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

@media (max-width: 420px) {
  .empty h2 {
    font-size: 1.25rem;
  }

  .chip {
    font-size: 0.78rem;
    padding: 9px 12px;
  }

  .topbar-title h1 {
    font-size: 0.9rem;
  }
}
