/* Visual no espírito do shadcn/ui (paleta zinc, escuro), em CSS puro, sem build.
   Pensado para tablet e celular na horizontal: alvos de toque ≥ 44px,
   nada de zoom por toque duplo, altura real da tela (dvh). */
:root {
  --bg: #09090b; --card: #18181b; --muted-bg: #27272a; --border: #27272a;
  --fg: #fafafa; --muted: #a1a1aa; --ring: #71717a;
  --live: #22c55e; --live-bg: #14532d; --preview: #f59e0b; --danger: #ef4444;
  --radius: 12px; --note-size: 22px;
  --pad: max(12px, env(safe-area-inset-left));
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; scrollbar-width: thin; scrollbar-color: #3f3f46 transparent; }
html, body { margin: 0; height: 100%; }
body { font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--fg); touch-action: manipulation; overscroll-behavior: none; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.spacer { flex: 1; }
.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.error { color: var(--danger); min-height: 1.2em; margin: 0; }

/* ---------- componentes ---------- */
.btn { font: inherit; font-weight: 500; display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  min-height: 44px; padding: 0 16px; border-radius: 10px; border: 1px solid transparent; background: var(--muted-bg); color: var(--fg);
  cursor: pointer; user-select: none; -webkit-user-select: none; transition: background .15s, opacity .15s; white-space: nowrap; }
.btn:hover { background: #3f3f46; }
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .35; pointer-events: none; }
.btn.on-air { pointer-events: none; background: transparent; border-color: #166534; color: #86efac; }
.btn:focus-visible, .input:focus-visible, .list button:focus-visible, .segmented button:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }
.btn.primary { background: var(--fg); color: var(--bg); }
.btn.primary:hover { background: #e4e4e7; }
.btn.go-live { background: var(--live); color: #052e16; }
.btn.go-live:hover { background: #4ade80; }
.btn.go-preview { background: var(--preview); color: #1c1003; }
.btn.go-preview:hover { background: #fbbf24; }
.btn.ghost { background: transparent; }
.btn.ghost:hover { background: var(--muted-bg); }
.btn.icon { width: 44px; padding: 0; font-size: 20px; }
.btn.sm { min-height: 36px; padding: 0 10px; font-size: 14px; }
.btn.big { min-height: 64px; font-size: 18px; flex: 1; }
.input { font: inherit; width: 100%; min-height: 48px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--border); background: var(--card); color: var(--fg); }
.pill { display: inline-flex; align-items: center; gap: 4px; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--muted-bg); color: var(--muted); white-space: nowrap; }
.pill.live { background: var(--live-bg); color: #86efac; }
.pill.preview { background: #451a03; color: #fcd34d; }
.segmented { display: inline-flex; background: var(--muted-bg); border-radius: 10px; padding: 3px; }
.segmented button { font: inherit; min-height: 38px; min-width: 48px; padding: 0 10px; border: 0; border-radius: 8px; background: transparent; color: var(--muted); cursor: pointer; white-space: nowrap; }
.segmented button[aria-checked="true"] { background: var(--bg); color: var(--fg); }

/* ---------- estrutura ---------- */
.view { height: 100dvh; display: flex; flex-direction: column; }
.bar { display: flex; align-items: center; gap: 8px; padding: 8px var(--pad); border-bottom: 1px solid var(--border); min-height: 60px; }
.title { font-size: 18px; margin: 0; }
.title-wrap { display: flex; align-items: center; gap: 10px; min-width: 0; }

/* lista de pregações */
.pick-body { flex: 1; overflow: auto; padding: 16px var(--pad); display: flex; flex-direction: column; gap: 12px; max-width: 1000px; width: 100%; margin: 0 auto; }
.live-card { font: inherit; color: inherit; text-align: left; display: flex; flex-direction: column; align-items: flex-start; gap: 4px; padding: 16px; border-radius: var(--radius);
  border: 1px solid #166534; background: linear-gradient(180deg, #052e16, var(--card)); cursor: pointer; }
.live-card strong { font-size: 20px; }
.list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 8px; }
.list button { font: inherit; color: inherit; width: 100%; min-height: 56px; text-align: left; padding: 10px 14px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--card); cursor: pointer; display: flex; align-items: center; gap: 8px; }
.list button:hover { border-color: var(--ring); }
.list button.is-live { border-color: #166534; }
.list button span:first-child { flex: 1; min-width: 0; overflow-wrap: anywhere; }

/* púlpito */
.stage { flex: 1; min-height: 0; display: grid; gap: 12px; padding: 12px var(--pad); grid-template-columns: minmax(0, 2fr) minmax(0, 3fr); }
.stage[data-mode="slides"] { grid-template-columns: 1fr; }
.stage[data-mode="slides"] .notes { display: none; }
.stage[data-mode="notes"] { grid-template-columns: minmax(0, 1fr) minmax(0, 4fr); }
.stage[data-mode="notes"] .nxt { display: none; }

.slides { min-height: 0; display: flex; flex-direction: column; gap: 10px; overflow: hidden; }
.stage[data-mode="slides"] .slides { flex-direction: row; align-items: flex-start; }
.stage[data-mode="slides"] .cur { flex: 3; }
.stage[data-mode="slides"] .nxt { flex: 1; }
figure { margin: 0; min-height: 0; min-width: 0; }
figure img { display: block; width: 100%; max-height: 100%; object-fit: contain; background: #000; border-radius: var(--radius); border: 3px solid var(--border); }
img:not([src]), img[src=""] { visibility: hidden; }
.cur.is-live img { border-color: var(--live); }
.cur.is-preview img { border-color: var(--preview); }
.nxt { opacity: .75; }
.stage[data-mode="both"] .nxt { width: 55%; }
.nxt img { border-width: 1px; }
figcaption { display: flex; align-items: center; gap: 8px; font-size: 14px; margin-top: 6px; }
.badge { font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 6px; background: var(--muted-bg); }
.cur.is-live .badge { background: var(--live); color: #052e16; }
.cur.is-preview .badge { background: var(--preview); color: #1c1003; }

.notes { min-height: 0; display: flex; flex-direction: column; gap: 8px; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; }
.notes-head { display: flex; align-items: center; gap: 6px; }
.pp-notes { white-space: pre-wrap; font-size: calc(var(--note-size) * .75); color: var(--muted); border-left: 3px solid var(--ring); padding: 2px 10px; max-height: 30%; overflow: auto; }
.my-notes { flex: 1; min-height: 0; overflow: auto; white-space: pre-wrap; font: inherit; font-size: var(--note-size); line-height: 1.45; color: var(--fg); }
textarea.my-notes { width: 100%; resize: none; padding: 8px; margin: -8px 0 0 -8px; width: calc(100% + 16px); border-radius: 10px; border: 1px solid transparent; background: transparent; outline: none; }
textarea.my-notes:focus { border-color: var(--ring); background: var(--bg); }
textarea.my-notes::placeholder { color: var(--muted); font-size: 16px; }

.controls { display: flex; gap: 10px; padding: 10px var(--pad) max(10px, env(safe-area-inset-bottom)); border-top: 1px solid var(--border); }
.controls #go { flex: 1.4; }

/* lista de slides à esquerda (liga/desliga no ☷) */
.side-list { display: none; min-height: 0; overflow-y: auto; flex-direction: column; gap: 8px; padding: 8px;
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  scrollbar-width: none; overscroll-behavior: contain; /* sem barra do navegador: o esmaecimento indica que rola */
  /* esmaece as bordas para indicar que tem mais slides acima/abaixo */
  -webkit-mask-image: linear-gradient(transparent, #000 10px, #000 calc(100% - 10px), transparent);
          mask-image: linear-gradient(transparent, #000 10px, #000 calc(100% - 10px), transparent); }
.side-list::-webkit-scrollbar { display: none; }
.stage[data-list="true"] .side-list { display: flex; }
.stage[data-list="true"][data-mode="both"] { grid-template-columns: 128px minmax(0, 2fr) minmax(0, 3fr); }
.stage[data-list="true"][data-mode="slides"] { grid-template-columns: 128px minmax(0, 1fr); }
.stage[data-list="true"][data-mode="notes"] { grid-template-columns: 128px minmax(0, 1fr) minmax(0, 4fr); }

.side-list button { flex: none; position: relative; padding: 0; border: 2px solid transparent; border-radius: 9px; background: none; cursor: pointer; opacity: .6; transition: opacity .15s, border-color .15s; }
.side-list button:hover { opacity: .9; }
.side-list button.live, .side-list button.sel { opacity: 1; }
.side-list button.live { border-color: var(--live); }
.side-list button.sel { border-color: var(--preview); }
.side-list img { display: block; width: 100%; background: #000; border-radius: 7px; }
.side-list .num { position: absolute; top: 4px; left: 4px; min-width: 20px; height: 20px; padding: 0 5px; border-radius: 6px;
  display: grid; place-items: center; font-size: 11px; font-weight: 700; color: var(--fg); background: rgba(9, 9, 11, .75); }
.side-list .live .num { background: var(--live); color: #052e16; }
.side-list .sel .num { background: var(--preview); color: #1c1003; }
.side-list .has-note::after { content: "✎"; position: absolute; top: 4px; right: 4px; width: 20px; height: 20px; border-radius: 6px;
  display: grid; place-items: center; font-size: 11px; color: #1c1003; background: #fcd34d; }
#listBtn[aria-pressed="true"] { background: var(--muted-bg); }

.toast { position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%); z-index: 10; margin: 0; padding: 10px 16px; border-radius: 10px; background: #450a0a; color: #fecaca; border: 1px solid #7f1d1d; max-width: 90vw; }

/* ---------- celular na horizontal (pouca altura) ---------- */
@media (orientation: landscape) and (max-height: 520px) {
  .bar { min-height: 48px; padding-top: 2px; padding-bottom: 2px; }
  .stage[data-list="true"][data-mode="both"] { grid-template-columns: 96px minmax(0, 2fr) minmax(0, 3fr); }
  .stage[data-list="true"][data-mode="slides"] { grid-template-columns: 96px minmax(0, 1fr); }
  .stage[data-list="true"][data-mode="notes"] { grid-template-columns: 96px minmax(0, 1fr) minmax(0, 4fr); }
  .side-list { padding: 6px; gap: 6px; }
  .title { font-size: 16px; }
  .stage { padding-top: 8px; padding-bottom: 8px; gap: 8px; }
  .stage[data-mode="both"] .nxt { display: none; } /* sem altura: mostra só o atual */
  .btn.big { min-height: 52px; }
  .btn.big .lbl { display: none; }
  .controls { padding-top: 6px; padding-bottom: max(6px, env(safe-area-inset-bottom)); }
  .notes { padding: 8px; }
  .toast { bottom: 70px; }
}

/* ---------- em pé: empilha ---------- */
@media (orientation: portrait) {
  .stage, .stage[data-mode="notes"] { grid-template-columns: 1fr; grid-template-rows: auto minmax(0, 1fr); }
  .stage[data-mode="both"] .nxt, .stage[data-mode="notes"] .slides { display: none; }
  .stage[data-mode="notes"] { grid-template-rows: minmax(0, 1fr); }
  /* em pé ou tela dividida do tablet: atual e próximo empilhados, largura toda */
  .stage[data-mode="slides"] { grid-template-rows: minmax(0, 1fr); }
  .stage[data-mode="slides"] .slides { flex-direction: column; align-items: stretch; overflow: auto; }
  .stage[data-mode="slides"] .cur, .stage[data-mode="slides"] .nxt { flex: none; }
  .btn.big .lbl, #fsBtn { display: none; }
  .stage[data-list="true"][data-mode] { grid-template-columns: 92px minmax(0, 1fr); }
  .side-list { grid-row: 1 / -1; padding: 6px; gap: 6px; }
}
@media (max-width: 640px) { #who, .title-wrap .pill { display: none; } }

/* ---------- login ---------- */
body.center { display: flex; min-height: 100dvh; }
.login { margin: auto; width: min(380px, 92vw); display: grid; gap: 14px; padding: 24px; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); }
.login h1 { margin: 0; }
.login label { display: grid; gap: 6px; font-size: 14px; font-weight: 500; }

/* ---------- receptor ---------- */
body.receptor { background: #000; }
body.receptor video { width: 100vw; height: 100vh; object-fit: contain; }
body.receptor #msg { position: fixed; inset: auto 0 1rem; text-align: center; }
.login .muted { margin: 0; }
.pw-wrap { position: relative; display: block; }
.pw-wrap .input { padding-right: 96px; }
.pw-wrap .btn { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); }
.bar { overflow: hidden; }
@media (max-width: 480px) {
  .segmented button { min-width: 0; padding: 0 8px; }
  .bar { gap: 4px; }
}
