:root {
  --bg: #f2efe8;
  --ink: #1f1b16;
  --card: #fffaf3;
  --accent: #b45309;
  --line: #dfd4c2;
  --muted: #7c6f60;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  color: var(--ink);
  font-family: "Trebuchet MS", Verdana, sans-serif;
  background: linear-gradient(160deg, #f8f3ea 0%, #ece5d8 55%, #f3eee4 100%);
}

.shell { min-height: 100vh; padding: 16px; }
.hidden { display: none !important; }

.auth-card {
  max-width: 420px;
  margin: 40px auto;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px;
}

.stack { display: grid; gap: 8px; margin: 10px 0; }
.stack.compact { margin: 8px; }
input, textarea, button {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  font: inherit;
}
button { background: var(--accent); color: #fff; cursor: pointer; }
textarea { min-height: 90px; resize: vertical; }

.dashboard {
  display: grid;
  grid-template-columns: 280px 1fr 320px;
  grid-template-rows: auto 1fr;
  gap: 12px;
  height: calc(100vh - 32px);
}

.tabs-row {
  grid-column: 1 / 4;
  grid-row: 1;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px;
}

.sidebar {
  grid-column: 1;
  grid-row: 2;
}

.chat-pane {
  grid-column: 2;
  grid-row: 2;
}

.admin {
  grid-column: 3;
  grid-row: 2;
}

.sidebar, .chat-pane, .admin {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
}

.sidebar-head, .chat-head {
  padding: 10px;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.contacts { overflow-y: auto; height: calc(100% - 52px); }
.tabs { display: flex; gap: 6px; padding: 8px; border-bottom: 1px solid var(--line); }
.tab { flex: 1; background: #efe5d3; color: #3d2d1f; }
.tab.active { background: var(--accent); color: #fff; }
.contact {
  padding: 10px;
  border-bottom: 1px solid #efe7da;
  cursor: pointer;
}
.contact.active { background: #f7e8cf; }
.contact small { color: var(--muted); display: block; }
.contact-row { display: flex; gap: 8px; align-items: flex-start; }
.avatar-btn {
  border: 0;
  background: transparent;
  padding: 0;
  cursor: zoom-in;
}
.avatar {
  width: 42px;
  height: 42px;
  border-radius: 999px;
  object-fit: cover;
  border: 1px solid #eadfcd;
  background: #f2efe8;
}

.messages { height: calc(100% - 108px); overflow-y: auto; padding: 10px; }
.msg { padding: 8px 10px; border-radius: 8px; margin-bottom: 8px; max-width: 78%; white-space: pre-wrap; }
.msg.me { background: #fde68a; margin-left: auto; }
.msg.them { background: #e7e5e4; }
.msg.error { background: #fecaca; }
.msg-content { margin-bottom: 6px; }

.tts-btn {
  border: 1px solid #cbd5e1;
  background: #fff;
  color: #1f1b16;
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 0.8rem;
}

.tts-actions {
  display: flex;
  gap: 6px;
}

.tts-stop-btn {
  background: #f8e5e5;
  border-color: #efc3c3;
}

.composer { border-top: 1px solid var(--line); padding: 10px; display: flex; gap: 8px; }
.composer input { flex: 1; }

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

.composer-topline {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  align-items: center;
}

.composer-inputline {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.composer-inputline input {
  flex: 1;
  min-width: 0;
}

.auto-mode-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.84rem;
  color: var(--muted);
  white-space: nowrap;
}

.super-auto-status {
  font-size: 0.8rem;
  color: var(--muted);
  white-space: nowrap;
}

.super-auto-status.active {
  color: #0f766e;
  font-weight: 700;
}

#mic-btn {
  white-space: nowrap;
  background: #fff;
  color: #3d2d1f;
  border: 1px solid #c8b79f;
}

#mic-btn.active {
  background: #b42318;
  color: #fff;
  border-color: #b42318;
}

#mic-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.admin { padding: 10px; overflow-y: auto; }
.bot-item { border: 1px solid #eadfcd; border-radius: 8px; padding: 8px; margin-top: 8px; }

.hint { color: var(--muted); font-size: 0.9rem; }

.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(10, 10, 10, 0.88);
  z-index: 9999;
  display: grid;
  grid-template-rows: 1fr auto;
  grid-template-columns: 72px 1fr 72px;
  align-items: center;
}

.lightbox-figure {
  grid-column: 2;
  grid-row: 1;
  margin: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.lightbox-counter {
  align-self: flex-end;
  margin-bottom: 4px;
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(20, 20, 20, 0.58);
  color: #fff;
  font-size: 0.84rem;
}

.lightbox-image {
  max-width: min(90vw, 1100px);
  max-height: 74vh;
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: 10px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.45);
  cursor: zoom-in;
  transition: transform 180ms ease;
  transform-origin: center center;
  touch-action: pan-y;
}

.lightbox-image.zoomed {
  transform: scale(1.8);
  cursor: zoom-out;
}

.lightbox-caption {
  color: #f8f8f8;
  font-size: 0.95rem;
}

.lightbox-close,
.lightbox-nav,
.thumb-btn {
  cursor: pointer;
}

.lightbox-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 42px;
  height: 42px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  background: rgba(20, 20, 20, 0.7);
  color: #fff;
  font-size: 1.2rem;
}

.lightbox-nav {
  width: 48px;
  height: 64px;
  border: 0;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  font-size: 2rem;
}

.lightbox-nav.prev { grid-column: 1; justify-self: center; }
.lightbox-nav.next { grid-column: 3; justify-self: center; }

.lightbox-thumbs {
  grid-column: 1 / 4;
  grid-row: 2;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 10px 16px 16px;
  justify-content: center;
}

.thumb-btn {
  border: 2px solid transparent;
  background: transparent;
  padding: 0;
  border-radius: 8px;
}

.thumb-btn img {
  width: 72px;
  height: 72px;
  object-fit: cover;
  border-radius: 6px;
}

.thumb-btn.active {
  border-color: #f5d08b;
}

@media (max-width: 980px) {
  .dashboard { grid-template-columns: 1fr; grid-template-rows: auto; height: auto; }
  .tabs-row, .sidebar, .chat-pane, .admin { grid-column: auto; grid-row: auto; }
  .sidebar, .chat-pane { min-height: 260px; }
  .admin { display: none !important; }
  .messages { height: calc(100dvh - 360px); min-height: 260px; }
  .lightbox { grid-template-columns: 56px 1fr 56px; }
  .lightbox-image { max-height: 66vh; }
  .thumb-btn img { width: 60px; height: 60px; }
  .composer {
    position: sticky;
    bottom: 0;
    background: var(--card);
    z-index: 8;
  }
  .composer-topline {
    gap: 6px;
  }
  .auto-mode-toggle,
  .super-auto-status {
    font-size: 0.74rem;
  }
  #mic-btn,
  .composer-inputline button,
  .composer-inputline input {
    padding: 8px;
  }
}
