:root {
  --bg: #faf7f2;
  --surface: #ffffff;
  --text: #1d1a17;
  --muted: #6f675f;
  --line: #e7e0d6;
  --line-strong: #d5ccbf;
  --red: #d33a2c;
  --red-bg: #fbe3df;
  --yellow: #c98a00;
  --yellow-bg: #fdf0c7;
  --green: #2f8a4a;
  --green-bg: #dcf1e1;
  --shadow: 0 10px 40px rgb(0 0 0 / 0.18);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14110f;
    --surface: #1e1a17;
    --text: #f3ede6;
    --muted: #a59b90;
    --line: #2d2723;
    --line-strong: #3d3530;
    --red: #ff6b5c;
    --red-bg: #4a1f1a;
    --yellow: #f2bf3a;
    --yellow-bg: #463712;
    --green: #5fcf7e;
    --green-bg: #173a22;
    --shadow: 0 10px 40px rgb(0 0 0 / 0.5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #14110f; --surface: #1e1a17; --text: #f3ede6; --muted: #a59b90;
  --line: #2d2723; --line-strong: #3d3530;
  --red: #ff6b5c; --red-bg: #4a1f1a; --yellow: #f2bf3a; --yellow-bg: #463712;
  --green: #5fcf7e; --green-bg: #173a22; --shadow: 0 10px 40px rgb(0 0 0 / 0.5);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
button { font: inherit; color: inherit; cursor: pointer; }

.s-ideia { --c: var(--red); --cbg: var(--red-bg); }
.s-contacto { --c: var(--yellow); --cbg: var(--yellow-bg); }
.s-confirmado { --c: var(--green); --cbg: var(--green-bg); }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--c); flex: none; }

.top {
  position: sticky; top: 0; z-index: 5;
  background: var(--bg);
  padding: max(12px, env(safe-area-inset-top)) 16px 10px;
  border-bottom: 1px solid var(--line);
  display: grid; grid-template-columns: 1fr auto; gap: 10px 12px; align-items: center;
}
.title h1 { margin: 0; font-size: 20px; letter-spacing: -0.01em; }
.title p { margin: 0; color: var(--muted); font-size: 13px; }

.tabs { display: flex; background: var(--line); border-radius: 10px; padding: 3px; }
.tabs button { border: 0; background: none; padding: 6px 12px; border-radius: 8px; font-size: 14px; color: var(--muted); }
.tabs button[aria-selected="true"] { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: 0 1px 2px rgb(0 0 0 / 0.1); }

.legend { grid-column: 1 / -1; display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--line-strong); background: var(--surface);
  border-radius: 999px; padding: 4px 10px; font-size: 13px;
}
.chip b { font-weight: 600; color: var(--muted); }
.chip[aria-pressed="false"] { opacity: 0.45; }
.chip[aria-pressed="false"] .dot { background: transparent; box-shadow: inset 0 0 0 2px var(--c); }

main { padding: 0 0 40px; }

/* Grelha */
.grid-wrap { padding: 0 8px 0 0; }
.grid-head, .grid-body { display: grid; grid-template-columns: 38px repeat(4, minmax(0, 1fr)); }
.grid-head {
  position: sticky; top: var(--head-h, 108px); z-index: 4;
  background: var(--bg); border-bottom: 1px solid var(--line);
}
.dh { padding: 8px 4px; text-align: center; font-size: 13px; color: var(--muted); }
.dh b { color: var(--text); }
.grid-body { position: relative; }
.hours { position: absolute; inset: 0; pointer-events: none; }
.hour { position: absolute; left: 0; right: 0; border-top: 1px solid var(--line); }
.hour span { position: absolute; left: 4px; top: -8px; font-size: 11px; color: var(--muted); background: var(--bg); padding: 0 2px; }
.hour:first-child span { top: 2px; }
.col { position: relative; grid-row: 1; border-left: 1px solid var(--line); }

.block {
  position: absolute; overflow: hidden;
  display: flex; flex-direction: column; justify-content: flex-start; gap: 1px;
  text-align: left; padding: 4px 5px;
  border: 0; border-left: 3px solid var(--c); border-radius: 6px;
  background: var(--cbg);
  font-size: 12px; line-height: 1.2;
}
.block img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
/* Bloco com foto: a imagem ocupa tudo e o texto fica por cima, em baixo. */
.block.photo { justify-content: flex-end; color: #fff; border-left-width: 5px; }
.block.photo::after { content: ""; position: absolute; inset: 0; background: linear-gradient(to top, rgb(0 0 0 / 0.75), rgb(0 0 0 / 0) 60%); }
.block.photo .b-title, .block.photo .b-time { position: relative; z-index: 1; text-shadow: 0 1px 2px rgb(0 0 0 / 0.6); }
.block.photo .b-time { color: rgb(255 255 255 / 0.85); }
.b-title { font-weight: 600; overflow-wrap: break-word; hyphens: auto; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; overflow: hidden; }
.b-time { color: var(--muted); font-size: 11px; }
.block.tiny { padding: 1px 4px; justify-content: center; }
.block.tiny .b-time { display: none; }
.block.tiny .b-title { -webkit-line-clamp: 1; }
.block.cont { border-top: 2px dashed var(--c); border-radius: 0 0 6px 6px; }
.block.narrow { padding: 3px 3px; font-size: 11px; }
.block.narrow .b-time { display: none; }

/* Lista */
.list { padding: 0 16px; max-width: 640px; margin: 0 auto; }
.list h2 { font-size: 17px; margin: 22px 0 8px; }
.list h2 span { color: var(--muted); font-weight: 400; font-size: 14px; }
.item {
  width: 100%; display: flex; align-items: center; gap: 12px; text-align: left;
  background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--c);
  border-radius: 10px; padding: 8px 12px 8px 8px; margin-bottom: 8px;
}
.item img, .item .ph { width: 48px; height: 48px; border-radius: 6px; object-fit: cover; flex: none; background: var(--cbg); }
.i-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.i-time { font-size: 13px; color: var(--muted); }
.i-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.none { color: var(--muted); margin: 0 0 8px; font-size: 14px; }

.empty { text-align: center; color: var(--muted); padding: 24px 16px; }

/* Detalhe */
.sheet {
  border: 0; padding: 0; width: min(520px, 100%); max-width: 100%;
  margin: auto auto 0; border-radius: 18px 18px 0 0;
  background: var(--surface); color: var(--text); box-shadow: var(--shadow);
  max-height: 90dvh;
}
@media (min-width: 640px) { .sheet { margin: auto; border-radius: 18px; } }
.sheet::backdrop { background: rgb(0 0 0 / 0.45); }
.sheet #detail-body { padding: 16px 20px max(20px, env(safe-area-inset-bottom)); }
.close {
  position: absolute; top: 10px; right: 10px; z-index: 1;
  width: 34px; height: 34px; border-radius: 50%; border: 0;
  background: rgb(0 0 0 / 0.5); color: #fff; font-size: 22px; line-height: 1;
}
.d-img { display: block; width: calc(100% + 40px); margin: -16px -20px 14px; max-height: 50dvh; object-fit: cover; }
.badge { display: inline-flex; align-items: center; gap: 6px; background: var(--cbg); color: var(--text); border-radius: 999px; padding: 3px 10px; font-size: 13px; font-weight: 600; }
.sheet h2 { margin: 10px 0 4px; font-size: 22px; }
.d-when { margin: 0; color: var(--muted); }
.d-desc { white-space: pre-wrap; margin: 14px 0 0; overflow-wrap: anywhere; }
.d-desc a { color: inherit; text-decoration-color: var(--muted); }
.d-meta { margin: 16px 0 0; font-size: 12px; color: var(--muted); }
