/* App-only styles: sign-in gate, edit buttons, the edit form, toasts. Uses the viewer's colour tokens. */
#gate { display: none; }
body.gated > header, body.gated > nav, body.gated > main { display: none; }
body.gated #gate { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.gate-card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 28px; max-width: 380px; text-align: center; }
.gate-card h1 { margin: 0 0 8px; font-size: 22px; }
.gate-card p { color: var(--muted); margin: 0 0 18px; }
.gate-card button, dialog .primary { background: var(--accent); color: #fff; border: 0; border-radius: 8px; padding: 9px 16px; cursor: pointer; font-weight: 600; }
.who { margin-left: auto; color: var(--muted); font-size: 13px; display: flex; gap: 8px; align-items: center; }
button.link { background: none; border: 0; color: var(--accent); cursor: pointer; padding: 0; font-size: 13px; white-space: nowrap; }
.edit-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--border); }
.edit-actions button { border: 1px solid var(--border); background: var(--surface); border-radius: 8px; padding: 6px 10px; cursor: pointer; font-size: 13px; }
.edit-actions button:hover { border-color: var(--accent); }
.edit-actions .danger { color: #b3261e; }
dialog { border: 1px solid var(--border); border-radius: 14px; padding: 0; background: var(--surface); color: var(--text); width: min(720px, calc(100vw - 32px)); max-height: calc(100vh - 32px); }
dialog::backdrop { background: rgba(0, 0, 0, .35); }
dialog form { display: flex; flex-direction: column; max-height: calc(100vh - 34px); }
dialog h2 { margin: 0; padding: 16px 20px; font-size: 18px; border-bottom: 1px solid var(--border); }
dialog .body { padding: 8px 20px; overflow: auto; }
dialog fieldset { border: 0; padding: 0; margin: 12px 0; }
dialog legend { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; margin-bottom: 6px; }
dialog .grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 8px 12px; }
dialog label { display: flex; flex-direction: column; gap: 3px; font-size: 13px; }
dialog label span { color: var(--muted); }
dialog label.wide { grid-column: 1 / -1; }
dialog label.check { flex-direction: row; align-items: center; gap: 6px; }
dialog input, dialog select, dialog textarea { padding: 7px 9px; border: 1px solid var(--border); border-radius: 7px; background: var(--bg); font: inherit; color: inherit; }
dialog details.more { margin: 12px 0; border: 1px solid var(--border); border-radius: 10px; padding: 0 12px; }
dialog details.more[open] { padding-bottom: 4px; }
dialog details.more summary { cursor: pointer; padding: 10px 0; font-weight: 600; font-size: 14px; }
dialog details.more summary span { font-weight: 400; color: var(--muted); font-size: 13px; margin-left: 8px; }
dialog .marriage { margin-bottom: 8px; align-items: end; }
dialog .errors { padding: 0 20px; color: #b3261e; font-size: 14px; }
dialog .errors:empty { display: none; }
dialog .buttons { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px; border-top: 1px solid var(--border); }
dialog .buttons button:not(.primary) { border: 1px solid var(--border); background: var(--surface); border-radius: 8px; padding: 9px 16px; cursor: pointer; }
#toast { position: fixed; inset: auto auto 24px 50%; margin: 0; border: 0; transform: translateX(-50%) translateY(20px); opacity: 0; background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; transition: .2s; pointer-events: none; max-width: calc(100vw - 32px); display: flex; gap: 14px; align-items: center; overflow: visible; }
#toast:not(:popover-open):not(.show) { visibility: hidden; }
#toast.has-action { pointer-events: auto; }
#toast button { background: none; border: 0; color: inherit; font: inherit; font-weight: 700; text-decoration: underline; cursor: pointer; padding: 0; }
#history ol { list-style: none; margin: 0; padding: 0; }
#history li { display: grid; grid-template-columns: 110px 1fr auto; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 14px; align-items: baseline; }
#history li .t { color: var(--muted); font-size: 13px; }
#history li.undone .s { text-decoration: line-through; color: var(--muted); }
#history li.is-undo .s { font-style: italic; }
#history .tag { font-size: 12px; padding: 1px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
#history .tag.next { background: var(--accent-soft); color: var(--accent); }
@media (max-width: 520px) { #history li { grid-template-columns: 1fr auto; } #history li .t { grid-column: 1 / -1; } }
#toast.show { opacity: 1; transform: translateX(-50%); }
#toast.error { background: #b3261e; color: #fff; }
/* Comments in the details panel */
.comments { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--border); }
.comments h3 { margin: 0 0 8px; font-size: 14px; }
.comment { padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.comment .meta { color: var(--muted); font-size: 12px; margin-bottom: 3px; }
.comment .text { white-space: pre-wrap; overflow-wrap: anywhere; }
.comment-add { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
.comment-add textarea { padding: 7px 9px; border: 1px solid var(--border); border-radius: 7px; background: var(--bg); font: inherit; color: inherit; resize: vertical; }
.comment-add button { align-self: flex-start; border: 1px solid var(--border); background: var(--surface); border-radius: 8px; padding: 6px 10px; cursor: pointer; font-size: 13px; }
.comment-add button:hover { border-color: var(--accent); }
/* Photos in the details panel */
.photos { margin: 0 0 14px; }
.photos h3 { margin: 0 0 8px; font-size: 14px; }
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); gap: 6px; }
.photo-tile { position: relative; aspect-ratio: 1; padding: 0; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--surface-2); cursor: pointer; }
.photo-tile img { width: 100%; height: 100%; object-fit: cover; display: block; opacity: 0; transition: opacity .2s; }
.photo-tile img.loaded { opacity: 1; }
.photo-tile .tag, .photo-tile .yr { position: absolute; left: 4px; bottom: 4px; font-size: 10px; padding: 0 5px; border-radius: 999px; background: rgba(0, 0, 0, .6); color: #fff; }
.photo-tile .tag { left: auto; right: 4px; top: 4px; bottom: auto; background: var(--accent); }
.photo-tile.add { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; color: var(--accent); font-size: 12px; font-weight: 600; border-style: dashed; background: var(--surface); }
.photo-tile.add span { font-size: 22px; line-height: 1; }
.photo-tile:hover { border-color: var(--accent); }
/* Photo dialogs */
.photo-full, .photo-preview { margin: 8px 0; display: grid; place-items: center; }
.photo-full img, .photo-preview img { max-width: 100%; max-height: 60vh; border-radius: 8px; opacity: 0; transition: opacity .2s; }
.photo-full img.loaded, .photo-preview img.loaded { opacity: 1; }
.photo-preview:empty { display: none; }
.photo-preview { gap: 6px; }
.photo-preview figcaption { font-size: 13px; text-align: center; }
.photo-warn { color: var(--warn); background: var(--warn-soft); border-radius: 8px; padding: 6px 10px; }
.photo-caption { font-size: 16px; font-weight: 600; margin: 4px 0; }
.photo-people a { color: var(--accent); cursor: pointer; }
.photo-dialog .buttons { flex-wrap: wrap; }
.photo-dialog .buttons button:not(.primary) { border: 1px solid var(--border); background: var(--surface); border-radius: 8px; padding: 9px 16px; cursor: pointer; }
.photo-dialog .danger { color: #b3261e; }
.photo-pick input { padding: 10px; }
#photo-form .hint { color: var(--muted); font-size: 13px; margin: 4px 0 0; }
.photo-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.photo-chip { display: inline-flex; align-items: center; gap: 4px; background: var(--surface-2); border-radius: 999px; padding: 3px 4px 3px 10px; font-size: 13px; }
.photo-chip button { border: 0; background: none; cursor: pointer; color: var(--muted); width: 22px; height: 22px; border-radius: 50%; }
.photo-chip button:hover { background: var(--border); }
.profile-check { margin: 4px 0 8px; }
.profile-check[hidden] { display: none; }
/* Access screen */
#access .hint { color: var(--muted); font-size: 13px; }
#access table { width: 100%; border-collapse: collapse; font-size: 14px; }
#access td { padding: 6px 8px 6px 0; border-bottom: 1px solid var(--border); overflow-wrap: anywhere; }
#access td.muted { color: var(--muted); }
/* Fill in screen */
#fill .hint { color: var(--muted); font-size: 13px; margin: 4px 0; }
#fill .fill-controls { align-items: end; }
#fill .fill-same { display: flex; gap: 8px; margin: 10px 0; }
#fill .fill-same input { flex: 1; min-width: 0; }
#fill .fill-same button { border: 1px solid var(--border); background: var(--surface); border-radius: 8px; padding: 6px 10px; cursor: pointer; font-size: 13px; white-space: nowrap; }
#fill .fill-row { display: grid; grid-template-columns: 1fr minmax(160px, 40%); gap: 10px; align-items: center; padding: 6px 0; border-top: 1px solid var(--border); }
#fill .fill-row[hidden] { display: none; }
#fill .fill-who { min-width: 0; font-size: 14px; overflow-wrap: anywhere; }
#fill .fill-who b { font-weight: 500; }
#fill .fill-who small { display: block; color: var(--muted); font-size: 12px; }
#fill input:invalid { border-color: #b3261e; }
#fill .fill-count { margin-right: auto; align-self: center; color: var(--muted); font-size: 13px; }
#fill .buttons .primary:disabled { opacity: .5; cursor: default; }
@media (max-width: 520px) { #fill .fill-row { grid-template-columns: 1fr; gap: 4px; } }
/* Phones: forms fill the screen, with the buttons kept at the bottom; account links behind the ⋯ button. */
@media (max-width: 640px) {
  dialog { width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh; margin: 0; border: 0; border-radius: 0; }
  dialog form { height: 100%; max-height: 100dvh; }
  dialog h2 { padding: 14px 16px; position: sticky; top: 0; background: var(--surface); }
  dialog .body { flex: 1; padding: 8px 16px; }
  dialog .grid { grid-template-columns: 1fr; }
  dialog .buttons { padding: 10px 16px max(10px, env(safe-area-inset-bottom)); background: var(--surface); }
  dialog .buttons button, .gate-card button { min-height: 48px; flex: 1; }
  dialog input, dialog select, dialog textarea { min-height: 44px; }
  dialog label.check { min-height: 44px; }
  dialog label.check input { min-height: 0; width: 22px; height: 22px; }
  #history li { padding: 12px 0; }
  .photo-tile { min-height: 72px; }
  .photo-chip button { width: 36px; height: 36px; }
  .comment .link { padding: 10px 4px; }
  .more-btn { order: 3; }
  .who { display: none; position: fixed; top: 60px; right: 8px; z-index: 40; flex-direction: column; align-items: stretch; gap: 0; margin: 0; min-width: 220px;
    background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: 0 8px 24px rgba(0, 0, 0, .16); padding: 6px; font-size: 15px; }
  header.menu-open .who { display: flex; }
  .who > * { padding: 12px 10px; text-align: left; }
  .who button.link { font-size: 15px; min-height: 44px; }
  .who span { color: var(--muted); font-size: 13px; order: -1; border-bottom: 1px solid var(--border); overflow-wrap: anywhere; }
}
@media (min-width: 641px) { .more-btn { display: none !important; } }
@media print { .edit-actions, .comment-add, .who, #toast, .photo-tile.add { display: none !important; } }
