/* ── Reset & Base ──────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --cafe-dark:    #1a0f0a;
  --cafe-brown:   #3d2314;
  --cafe-mid:     #6b3a1f;
  --cafe-light:   #c87941;
  --cafe-cream:   #f5e6d3;
  --cafe-pale:    #fdf6ef;
  --text:         #1a0f0a;
  --text-sub:     #6b4a32;
  --text-inv:     #fdf6ef;
  --bg:           #fdf6ef;
  --bg-card:      #ffffff;
  --bg-muted:     #f5e6d3;
  --border:       #e8d5c0;
  --shadow:       0 2px 8px rgba(61,35,20,.12);
  --radius:       12px;
  --radius-sm:    8px;
  --tap:          44px;
  --header-h:     56px;
  --tab-h:        48px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:       #1a0f0a;
    --bg-card:  #2a1a10;
    --bg-muted: #3d2314;
    --border:   #5a3520;
    --text:     #f5e6d3;
    --text-sub: #c4956a;
    --shadow:   0 2px 8px rgba(0,0,0,.4);
    --cafe-pale:#2a1a10;
  }
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

button { cursor: pointer; font-family: inherit; }
input, textarea {
  font-family: inherit;
  font-size: 1rem;
  background: var(--bg);
  color: var(--text);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: .6rem .85rem;
  outline: none;
  transition: border-color .15s;
  width: 100%;
}
input:focus, textarea:focus { border-color: var(--cafe-light); }
textarea { resize: none; }
img { max-width: 100%; display: block; }

/* ── Layout ────────────────────────────────────────────────── */
#app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  max-width: 540px;
  margin: 0 auto;
}

main {
  flex: 1;
  overflow-y: auto;
  padding-bottom: 80px;
}

/* ── Header ────────────────────────────────────────────────── */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--cafe-brown);
  height: var(--header-h);
  box-shadow: 0 2px 8px rgba(0,0,0,.25);
}
.header-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 100%;
  padding: 0 16px;
}
.header-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--cafe-cream);
  letter-spacing: -.3px;
}
.header-title small {
  font-size: .75rem;
  font-weight: 400;
  opacity: .75;
}
.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}
.btn-nome {
  background: rgba(255,255,255,.15);
  border: none;
  border-radius: 20px;
  color: var(--cafe-cream);
  font-size: .8rem;
  padding: 6px 12px;
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: var(--tap);
  max-width: 130px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.btn-nome:hover { background: rgba(255,255,255,.25); }
.ws-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.ws-dot.ws-on  { background: #4ade80; box-shadow: 0 0 6px #4ade80; }
.ws-dot.ws-off { background: #9ca3af; }

/* ── Tabs ──────────────────────────────────────────────────── */
.tabs {
  display: flex;
  background: var(--cafe-dark);
  height: var(--tab-h);
  position: sticky;
  top: var(--header-h);
  z-index: 99;
}
.tab {
  flex: 1;
  background: none;
  border: none;
  color: rgba(245,230,211,.55);
  font-size: .9rem;
  font-weight: 600;
  border-bottom: 3px solid transparent;
  transition: color .15s, border-color .15s;
}
.tab.active {
  color: var(--cafe-cream);
  border-bottom-color: var(--cafe-light);
}

/* ── Tab sections ──────────────────────────────────────────── */
.tab-content { display: none; }
.tab-content.active { display: block; }

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 10px;
}
.section-header h2 {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-sub);
  text-transform: uppercase;
  letter-spacing: .5px;
  font-size: .8rem;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.section-header .btn-sm {
  flex-shrink: 0;
  white-space: nowrap;
}

/* ── Buttons ───────────────────────────────────────────────── */
.btn-primary {
  background: var(--cafe-mid);
  color: #fff;
  border: none;
  border-radius: 20px;
  padding: 8px 18px;
  font-size: .9rem;
  font-weight: 600;
  min-height: var(--tap);
  transition: background .15s, transform .1s;
}
.btn-primary:hover  { background: var(--cafe-light); }
.btn-primary:active { transform: scale(.97); }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; }
.btn-sm { padding: 6px 14px; font-size: .85rem; min-height: 36px; }

.btn-ghost {
  background: none;
  border: 1.5px solid var(--border);
  color: var(--text-sub);
  border-radius: 20px;
  padding: 8px 18px;
  font-size: .9rem;
  font-weight: 600;
  min-height: var(--tap);
}
.btn-ghost:hover { border-color: var(--cafe-light); color: var(--cafe-light); }

.btn-icon {
  background: none;
  border: none;
  font-size: 1.4rem;
  cursor: pointer;
  min-width: var(--tap);
  min-height: var(--tap);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: background .15s;
}
.btn-icon:hover { background: var(--bg-muted); }

/* ── Participantes ─────────────────────────────────────────── */
.lista-participantes {
  padding: 4px 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.participante-card {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg-card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  cursor: pointer;
  transition: border-color .15s, transform .1s, box-shadow .15s;
  user-select: none;
}
.participante-card:hover  {
  border-color: var(--cafe-light);
  box-shadow: var(--shadow);
}
.participante-card:active { transform: scale(.98); }
.participante-avatar {
  width: 44px; height: 44px;
  border-radius: 50%;
  background: var(--cafe-mid);
  color: #fff;
  font-size: 1.1rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.participante-info { flex: 1; min-width: 0; }
.participante-nome {
  font-weight: 600;
  font-size: .95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.participante-contador {
  font-size: .8rem;
  color: var(--text-sub);
  margin-top: 2px;
}
.participante-badge {
  font-size: 1.3rem;
  flex-shrink: 0;
}
.btn-del-participante {
  background: none;
  border: none;
  color: #ef4444;
  font-size: 1.1rem;
  padding: 4px 8px;
  border-radius: 6px;
  cursor: pointer;
  display: none;
}
.admin-mode .btn-del-participante { display: flex; }
.btn-hist-cafe {
  background: none;
  border: none;
  font-size: 1.1rem;
  padding: 4px 6px;
  border-radius: 6px;
  cursor: pointer;
  flex-shrink: 0;
  opacity: .65;
  transition: opacity .15s, transform .1s;
}
.btn-hist-cafe:hover { opacity: 1; transform: scale(1.1); }

.btn-dec-cafe {
  background: none;
  border: 1.5px solid var(--border);
  color: var(--text-sub);
  font-size: 1.2rem;
  line-height: 1;
  font-weight: 700;
  width: 30px; height: 30px;
  border-radius: 50%;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color .15s, color .15s, background .15s;
}
.btn-dec-cafe:hover {
  border-color: #ef4444;
  color: #ef4444;
  background: rgba(239, 68, 68, .08);
}

/* ── Próximo a trazer café ─────────────────────────────────── */
.proximo-cafe {
  margin: 4px 12px 0;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: var(--radius);
  background: linear-gradient(135deg, var(--cafe-mid), var(--cafe-light));
  color: #fff;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform .1s;
}
.proximo-cafe:active { transform: scale(.98); }
.proximo-avatar {
  width: 44px; height: 44px;
  border-radius: 50%;
  background: rgba(255, 255, 255, .25);
  color: #fff;
  font-size: 1.1rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.proximo-info { flex: 1; min-width: 0; }
.proximo-label {
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  opacity: .9;
}
.proximo-nome {
  font-weight: 700;
  font-size: 1.05rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.proximo-cta { font-size: 1.5rem; flex-shrink: 0; }

/* ── Histórico de cafés (modal) ────────────────────────────── */
.hist-lista {
  max-height: 55vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 8px 0;
}
.hist-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.hist-icone { font-size: 1.3rem; flex-shrink: 0; }
.hist-body { flex: 1; min-width: 0; }
.hist-data { font-weight: 600; font-size: .9rem; }
.hist-por { font-size: .75rem; color: var(--text-sub); margin-top: 2px; }
.hist-foto {
  width: 44px; height: 44px;
  object-fit: cover;
  border-radius: 8px;
  cursor: pointer;
  flex-shrink: 0;
}
.hist-sep {
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-sub);
  margin: 10px 2px 2px;
  font-weight: 700;
}
.hist-item-log {
  border-style: dashed;
  opacity: .85;
}

/* ── Composer ──────────────────────────────────────────────── */
.composer {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding: 12px;
}
.composer-top {
  display: flex;
  gap: 10px;
  align-items: flex-start;
}
.avatar-placeholder {
  width: 38px; height: 38px;
  border-radius: 50%;
  background: var(--cafe-mid);
  font-size: 1.2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.composer-input {
  border-radius: 20px;
  padding: .6rem 1rem;
  background: var(--bg-muted);
  border-color: transparent;
  flex: 1;
}
.composer-input:focus { border-color: var(--cafe-light); background: var(--bg); }
.composer-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  padding-left: 48px;
}
.toggle-anon {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: .82rem;
  color: var(--text-sub);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
.toggle-anon input { width: auto; }
.composer-actions .btn-primary { margin-left: auto; }

/* ── Preview de imagem ─────────────────────────────────────── */
.img-preview {
  position: relative;
  margin: 8px 0 4px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  max-height: 200px;
}
.img-preview img {
  width: 100%;
  max-height: 200px;
  object-fit: cover;
  border-radius: var(--radius-sm);
}
.btn-remove-img {
  position: absolute;
  top: 6px; right: 6px;
  background: rgba(0,0,0,.55);
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 28px; height: 28px;
  font-size: .9rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ── Feed ──────────────────────────────────────────────────── */
.feed { padding: 8px 0; }

.post-card {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding: 14px 16px;
  animation: fadeIn .25s ease;
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.post-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}
.post-avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-weight: 700;
  color: #fff;
}
.post-avatar.tipo-cafe    { background: var(--cafe-mid); }
.post-avatar.tipo-mensagem{ background: var(--cafe-dark); }

.post-meta { flex: 1; min-width: 0; }
.post-autor {
  font-weight: 600;
  font-size: .9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.post-time {
  font-size: .75rem;
  color: var(--text-sub);
}
.post-badge-cafe {
  background: var(--cafe-light);
  color: #fff;
  font-size: .7rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 20px;
  white-space: nowrap;
}
.btn-del-post {
  background: none;
  border: none;
  color: #ef4444;
  font-size: .85rem;
  padding: 4px 8px;
  border-radius: 6px;
  cursor: pointer;
  display: none;
}
.admin-mode .btn-del-post { display: inline-flex; align-items: center; gap: 3px; }

.post-texto {
  font-size: .95rem;
  line-height: 1.5;
  word-break: break-word;
  margin-bottom: 8px;
  white-space: pre-wrap;
}
.post-foto {
  width: 100%;
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  max-height: 360px;
  object-fit: cover;
  cursor: pointer;
}

/* ── Comentários ───────────────────────────────────────────── */
.post-footer {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-top: 4px;
  border-top: 1px solid var(--border);
}
.btn-comentar {
  background: none;
  border: none;
  color: var(--text-sub);
  font-size: .82rem;
  padding: 6px 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: var(--tap);
}
.btn-comentar:hover { color: var(--cafe-light); }

.comentarios-section { margin-top: 8px; }
.comentario-item {
  display: flex;
  gap: 8px;
  padding: 6px 0;
  border-top: 1px solid var(--border);
  animation: fadeIn .2s ease;
}
.comentario-avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--bg-muted);
  border: 1px solid var(--border);
  font-size: .75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-weight: 700;
}
.comentario-body { flex: 1; min-width: 0; }
.comentario-autor {
  font-weight: 600;
  font-size: .8rem;
  color: var(--text-sub);
}
.comentario-texto {
  font-size: .88rem;
  line-height: 1.4;
  word-break: break-word;
  white-space: pre-wrap;
}
.btn-del-comentario {
  background: none;
  border: none;
  color: #ef4444;
  font-size: .75rem;
  padding: 2px 6px;
  border-radius: 4px;
  cursor: pointer;
  display: none;
}
.admin-mode .btn-del-comentario { display: inline-block; }

.form-comentario {
  display: flex;
  gap: 8px;
  padding-top: 8px;
  margin-top: 4px;
  border-top: 1px solid var(--border);
}
.form-comentario input {
  flex: 1;
  font-size: .88rem;
  padding: .5rem .75rem;
}
.btn-enviar-comentario {
  background: var(--cafe-mid);
  color: #fff;
  border: none;
  border-radius: 20px;
  padding: 6px 14px;
  font-size: .82rem;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  min-height: var(--tap);
}
.btn-enviar-comentario:hover { background: var(--cafe-light); }

/* ── Load more ─────────────────────────────────────────────── */
.btn-load-more {
  display: block;
  width: calc(100% - 32px);
  margin: 16px;
  background: none;
  border: 1.5px solid var(--border);
  color: var(--text-sub);
  border-radius: 20px;
  padding: 10px;
  font-size: .9rem;
  cursor: pointer;
  min-height: var(--tap);
}
.btn-load-more:hover { border-color: var(--cafe-light); color: var(--cafe-light); }

/* ── Modais ────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.55);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 200;
  animation: fadeIn .15s ease;
  padding: 0 0 env(safe-area-inset-bottom);
}
@media (min-width: 480px) {
  .modal-overlay { align-items: center; }
}
.modal-card {
  background: var(--bg-card);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 24px 20px;
  width: 100%;
  max-width: 480px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  animation: slideUp .2s ease;
}
@media (min-width: 480px) {
  .modal-card { border-radius: var(--radius); }
}
@keyframes slideUp {
  from { transform: translateY(20px); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}
.modal-card h3 {
  font-size: 1.1rem;
  font-weight: 700;
  text-align: center;
}
.modal-btns {
  display: flex;
  gap: 10px;
  margin-top: 4px;
}
.modal-btns .btn-primary,
.modal-btns .btn-ghost {
  flex: 1;
  text-align: center;
}
.error-msg {
  color: #ef4444;
  font-size: .85rem;
  text-align: center;
  background: #fef2f2;
  border-radius: 6px;
  padding: 8px;
}
.btn-upload-label {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-muted);
  border: 2px dashed var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
  cursor: pointer;
  font-size: .9rem;
  color: var(--text-sub);
  text-align: center;
  justify-content: center;
}
.btn-upload-label:hover { border-color: var(--cafe-light); }
.btn-upload-label small { font-size: .75rem; }

/* ── Modal imagem fullscreen ───────────────────────────────── */
.modal-fullimg {
  background: rgba(0,0,0,.9);
  align-items: center;
  justify-content: center;
}
.modal-fullimg img {
  max-width: 100%;
  max-height: 90vh;
  object-fit: contain;
  border-radius: var(--radius-sm);
}
.btn-fechar-img {
  position: fixed;
  top: 16px; right: 16px;
  background: rgba(255,255,255,.15);
  border: none;
  color: #fff;
  font-size: 1.2rem;
  width: 40px; height: 40px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ── Toasts ────────────────────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  pointer-events: none;
}
.toast {
  background: var(--cafe-dark);
  color: var(--cafe-cream);
  padding: 10px 18px;
  border-radius: 20px;
  font-size: .88rem;
  box-shadow: 0 4px 12px rgba(0,0,0,.3);
  animation: toastIn .2s ease;
  pointer-events: all;
  max-width: 300px;
  text-align: center;
}
.toast.error { background: #7f1d1d; }
.toast.success { background: #14532d; }
@keyframes toastIn {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Admin toggle ──────────────────────────────────────────── */
.btn-admin-toggle {
  position: fixed;
  bottom: 20px;
  right: 16px;
  background: var(--bg-card);
  border: 1.5px solid var(--border);
  border-radius: 50%;
  width: 40px; height: 40px;
  font-size: 1rem;
  color: var(--text-sub);
  box-shadow: var(--shadow);
  z-index: 90;
}
.btn-admin-toggle:hover { border-color: var(--cafe-light); }
.btn-admin-toggle.active { background: var(--cafe-mid); color: #fff; border-color: var(--cafe-mid); }

/* ── Loading / Empty states ────────────────────────────────── */
.loading-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-sub);
  font-size: .9rem;
}
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-sub);
}
.empty-state .emoji { font-size: 2.5rem; margin-bottom: 8px; }
.empty-state p { font-size: .9rem; }


/* ── Visualização x gestão ───────────────────────────────── */
.tab-admin { display: none; }
.admin-mode .tab-admin { display: inline-flex; justify-content: center; align-items: center; }
.btn-hist-cafe { display: flex; }
.gestao-add { display: flex; gap: 8px; margin-bottom: 12px; }
.gestao-add input { flex: 1; min-width: 0; }
.gestao-card { cursor: default; flex-wrap: wrap; }
.gestao-acoes { display: flex; gap: 6px; margin-left: auto; }
.gestao-acoes button {
  border: 1px solid var(--cafe-light, #c9a27a); background: transparent; border-radius: 8px;
  min-width: 34px; height: 34px; padding: 0 8px; font-size: .9rem; cursor: pointer;
}
.gestao-acoes button:disabled { opacity: .35; cursor: default; }
.campo-data { display: flex; flex-direction: column; gap: 4px; font-size: .85rem; margin: 10px 0; }
.hist-admin { display: none; gap: 4px; }
.admin-mode .hist-admin { display: flex; }
.hist-admin button { border: none; background: transparent; cursor: pointer; font-size: 1rem; }

.tab { font-size: .8rem; padding-left: 4px; padding-right: 4px; }
