:root {
  color-scheme: dark;  /* native tick boxes, file pickers and scrollbars match the dark page */
  accent-color: var(--accent);
  --bg: #14151a;
  --card: #1d1f26;
  --border: #2c2f3a;
  --text: #e8e9ed;
  --muted: #8b8f9c;
  --accent: #6c8cff;
  --error: #ff6b6b;
  --ok: #4cd28a;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }  /* hidden elements stay hidden even when a rule gives them a display */

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

body.centered {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.wrap {
  max-width: 640px;
  margin: 0 auto;
  /* env(): room for the iPhone's notch and home bar when opened from the home-screen icon */
  padding: calc(24px + env(safe-area-inset-top)) calc(16px + env(safe-area-inset-right))
           calc(60px + env(safe-area-inset-bottom)) calc(16px + env(safe-area-inset-left));
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

h1 { font-size: 1.4rem; margin: 0; }

nav { display: flex; gap: 16px; }
button.menu-btn { display: none; }
.navlink {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.9rem;
}
.navlink:hover { color: var(--text); }

a { color: var(--accent); }
a.home { color: var(--text); text-decoration: none; }

.page-title { font-size: 1.15rem; margin: 8px 0 4px; }

.profile-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
  padding: 10px 14px;
  border: 1px solid var(--accent);
  border-radius: 10px;
  background: var(--card);
}
label.inline { margin: 0; }
.profile-bar select { flex: 0 1 auto; min-width: 0; max-width: 320px; text-overflow: ellipsis; }
select {
  background: #101116;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 0.95rem;
  font-weight: 600;
}
.tabs { display: flex; flex-wrap: wrap; gap: 4px; margin-left: auto; }
@media (max-width: 560px) { .tabs { margin-left: 0; width: 100%; } }
.tab {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.9rem;
  padding: 6px 12px;
  border-radius: 6px;
}
.tab.active { background: var(--border); color: var(--text); }

.profile-card {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.profile-info { flex: 1; min-width: 180px; }

/* ---------- reordering ---------- */
.sortable > * { transition: box-shadow 0.15s; }
button.drag-handle {
  width: auto;
  margin: 0;
  padding: 4px 6px;
  background: transparent;
  color: var(--muted);
  border: none;
  font-size: 1.1rem;
  line-height: 1;
  cursor: grab;
  touch-action: none;  /* let pointer drags reorder instead of scrolling on touch screens */
  user-select: none;
}
button.drag-handle:hover, button.drag-handle:focus-visible { color: var(--text); }
button.drag-handle:focus-visible { outline: 2px solid var(--accent); border-radius: 4px; }
.sortable.is-sorting { cursor: grabbing; user-select: none; }
.sortable .dragging {
  border-color: var(--accent);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
  opacity: 0.95;
}

.list-tools {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin: 4px 0 10px;
}
.list-tools .small { margin: 0; }
button.link-btn {
  width: auto;
  margin: 0;
  padding: 0;
  background: none;
  border: none;
  color: var(--accent);
  font-size: 0.85rem;
  font-weight: normal;
}

/* ---------- collapsible platform sections ---------- */
details.platform { padding: 0 20px 20px; margin-bottom: 12px; }
details.platform:not([open]) { padding-bottom: 0; }
details.platform > summary {
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 -20px;
  padding: 14px 16px 14px 10px;
  cursor: pointer;
}
details.platform > summary::-webkit-details-marker { display: none; }
details.platform > summary h2 { flex: 1; }
details.platform > summary .chevron::before {
  content: "▸";
  display: inline-block;
  color: var(--muted);
  transition: transform 0.15s;
}
details.platform[open] > summary .chevron::before { transform: rotate(90deg); }
details.platform[open] > summary { border-bottom: 1px solid var(--border); }
details.platform > p.muted:first-of-type { margin-top: 14px; }
.profile-name { font-weight: 600; margin-bottom: 6px; }
.badges { display: flex; gap: 6px; flex-wrap: wrap; }
.profile-actions { display: flex; gap: 8px; }
.btn {
  display: inline-block;
  text-decoration: none;
  background: var(--accent);
  color: #0c0d10;
  border-radius: 8px;
  padding: 8px 16px;
  font-size: 0.9rem;
  font-weight: 600;
}
.btn.secondary { background: transparent; color: var(--text); border: 1px solid var(--border); }

form.card { margin-bottom: 16px; }
.danger { border-color: #5a2a2a; margin-top: 32px; }
button.danger-btn { background: var(--error); }

h2 { font-size: 1.05rem; margin: 0; }
.card h2 + label { margin-top: 12px; }
section.card { margin-bottom: 16px; }
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}
.badge {
  font-size: 0.75rem;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted);
}
.badge.ok { border-color: var(--ok); color: var(--ok); }

.flash {
  background: var(--card);
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 0.9rem;
}
.center { text-align: center; }
.small { font-size: 0.8rem; margin: 8px 0 0; }
code { background: #101116; padding: 1px 5px; border-radius: 4px; font-size: 0.85em; }
.sticky-save {
  position: sticky;
  bottom: 0;
  background: var(--bg);
  padding: 4px 0 8px;
  margin-bottom: 16px;
}
.sticky-save button { margin-top: 8px; }
.sticky-save p { margin: 6px 0 0; }

.test-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 14px;
}
button.secondary {
  width: auto;
  margin: 0;
  padding: 8px 14px;
  font-size: 0.85rem;
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}
/* ---------- compose ---------- */
input[type="url"], input[type="datetime-local"] {
  width: 100%;
  background: #101116;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 10px 12px;
  font-size: 0.95rem;
  font-family: inherit;
  color-scheme: dark;
}
.image-list { display: flex; flex-direction: column; gap: 10px; margin-top: 10px; }
.image-item {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
}
.image-item img { width: 88px; height: 88px; object-fit: cover; border-radius: 6px; flex: none; }
.image-body { flex: 1; min-width: 0; }
.image-body label { margin: 0 0 4px; }
.image-body textarea { font-size: 0.85rem; }

details.overrides { margin-top: 16px; border: 1px solid var(--border); border-radius: 8px; padding: 10px 14px; }
details.overrides > summary { cursor: pointer; color: var(--muted); font-size: 0.9rem; }
details.overrides label { margin-top: 10px; }

.preview-panel { margin-top: 16px; border-top: 1px solid var(--border); padding-top: 12px; }
.preview-panel h3 { font-size: 0.95rem; margin: 0 0 8px; }
details.preview-card { border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px; margin-bottom: 8px; }
details.preview-card.has-error { border-color: var(--error); }
details.preview-card > summary { cursor: pointer; font-size: 0.9rem; }
.preview-note, .preview-error { font-size: 0.8rem; margin-top: 4px; color: var(--muted); }
.preview-error { color: var(--error); }
pre.preview-part {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-family: inherit;
  font-size: 0.85rem;
  background: #101116;
  border-radius: 6px;
  padding: 8px 10px;
  margin: 2px 0 8px;
}

.actions { margin-top: 18px; }
.actions > button { margin-top: 0; }
.secondary-actions { display: flex; gap: 8px; margin-top: 8px; }
.secondary-actions button { flex: 1; margin: 0; padding: 10px; font-size: 0.9rem; }
.schedule-box { margin-top: 12px; padding: 12px; border: 1px solid var(--border); border-radius: 8px; }
.schedule-box label { margin-top: 0; }
.schedule-box button { margin-top: 10px; }

/* ---------- queue / history / status ---------- */
.post-card { margin-bottom: 12px; }
.post-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.post-text { white-space: pre-wrap; overflow-wrap: anywhere; margin: 8px 0; font-size: 0.95rem; }
.post-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 10px; }
.post-actions .btn, .post-actions button { padding: 6px 12px; font-size: 0.85rem; }
.history-results { display: flex; flex-direction: column; gap: 6px; }
.badge.warn { border-color: #e0a84a; color: #e0a84a; }
.badge.err, .err { color: var(--error); }
.badge.err { border-color: var(--error); }
button.danger-text { color: var(--error); }
.status-row { margin-top: 8px; }
.list-tools h2.page-title { margin: 0; }
.list-tools > button { width: auto; margin: 0; padding: 8px 14px; font-size: 0.9rem; }
.login-card .checkbox { font-size: 0.85rem; color: var(--muted); }

.helper {
  margin-top: 16px;
  padding: 12px 14px;
  border: 1px dashed var(--border);
  border-radius: 8px;
}
.helper h3 { font-size: 0.95rem; margin: 0 0 4px; }
.helper input { margin-top: 8px; }
.page-list { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.test-result { font-size: 0.85rem; color: var(--muted); }
.test-result.ok { color: var(--ok); }
.test-result.err { color: var(--error); }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
}

.login-card {
  width: 280px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

label {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
  margin: 14px 0 6px;
}
label:first-of-type { margin-top: 0; }

textarea, input[type="password"], input[type="text"], input[type="file"],
input[type="number"], input[type="email"], input[type="time"], input[type="search"] {
  width: 100%;
  background: #101116;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 10px 12px;
  font-size: 0.95rem;
  font-family: inherit;
  resize: vertical;
}
input[type="number"] { width: 8em; padding: 8px 10px; }

.char-count {
  text-align: right;
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 4px;
}

fieldset {
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-top: 16px;
  padding: 12px 14px;
}
legend { color: var(--muted); font-size: 0.85rem; padding: 0 6px; }

.checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.95rem;
  color: var(--text);
  margin: 6px 0;
}
.checkbox input { width: auto; }
.muted { color: var(--muted); font-size: 0.85rem; }

button {
  margin-top: 18px;
  width: 100%;
  background: var(--accent);
  color: #0c0d10;
  border: none;
  border-radius: 8px;
  padding: 12px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
}
button:hover { opacity: 0.9; }
button:disabled { opacity: 0.5; cursor: not-allowed; }

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

.preview {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}
.preview img {
  width: 72px;
  height: 72px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--border);
}

.results {
  margin-top: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.result-row {
  padding: 10px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 0.9rem;
  display: flex;
  justify-content: space-between;
  gap: 12px;
}
.result-row.ok { border-color: var(--ok); }
.result-row.err { border-color: var(--error); }
.result-row .status.ok { color: var(--ok); }
.result-row .status.err { color: var(--error); }

/* ---------- video page ---------- */
.video-box { margin-top: 10px; }
.video-box video { display: block; width: 100%; max-height: 420px; background: #000; border-radius: 8px; }
.field-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 0 16px; }
.field-row select { width: 100%; }
.upload-progress { display: flex; align-items: center; gap: 10px; margin-top: 12px; }
.upload-progress progress { flex: 1; min-width: 0; }
.result-row.busy { border-color: var(--border); }
.result-row .status.busy { color: var(--muted); }

/* ---------- autopost page ---------- */
#autopost-form h3 { margin: 22px 0 4px; }
.day-row { display: flex; flex-wrap: wrap; gap: 4px 14px; }
.day-row legend { width: 100%; }
.inline-check { display: inline-flex; margin: 0; }
.inline-checks { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 14px; margin: 6px 0 4px; }
.link-fill button { margin: 0; }
.share-page { display: flex; gap: 12px; align-items: flex-start; }
.share-page p { margin: 4px 0 0; overflow-wrap: anywhere; }
.bookmarklet { cursor: grab; margin: 6px 0; }
#bookmarklet-code, #shortcut-code { font-family: ui-monospace, monospace; font-size: 12px; }
.autopost-row { display: flex; gap: 12px; align-items: flex-start; padding: 12px 0; border-top: 1px solid var(--border); }
.autopost-row:first-of-type { border-top: 0; }
.autopost-mini { width: 96px; height: 64px; object-fit: cover; border-radius: 6px; flex: 0 0 auto; }
.autopost-body { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.autopost-body .post-actions { margin-top: 6px; }
#items-list .result-row { gap: 12px; }
#items-list .result-row a { overflow-wrap: anywhere; }

/* ---------- phones ---------- */
@media (max-width: 600px) {
  .wrap {
    padding: calc(12px + env(safe-area-inset-top)) calc(12px + env(safe-area-inset-right))
             calc(40px + env(safe-area-inset-bottom)) calc(12px + env(safe-area-inset-left));
  }
  body.centered { padding: 16px; }
  .login-card { width: 100%; max-width: 340px; }

  /* 16px text in fields stops iPhone Safari zooming in whenever one is tapped */
  textarea, input, select { font-size: 16px; }
  input[type="checkbox"], input[type="radio"] { width: 18px; height: 18px; flex: none; }

  /* top bar: name on the left, Menu on the right; the links drop down below */
  header { flex-wrap: wrap; margin-bottom: 12px; }
  h1 { font-size: 1.2rem; white-space: nowrap; }
  button.menu-btn {
    display: block;
    width: auto;
    margin: 0;
    padding: 8px 14px;
    font-size: 0.9rem;
    background: transparent;
    color: var(--text);
    border: 1px solid var(--border);
  }
  header.menu-open button.menu-btn { background: var(--border); }
  header nav { display: none; }
  header.menu-open nav {
    display: flex;
    flex-direction: column;
    gap: 0;
    width: 100%;
    margin-top: 10px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
  }
  header.menu-open .navlink {
    padding: 13px 16px;
    font-size: 1rem;
    color: var(--text);
    border-top: 1px solid var(--border);
  }
  header.menu-open .navlink:first-child { border-top: 0; }

  /* profile picker full width, tabs as an even 3 x 2 grid so none hide off-screen */
  .profile-bar { padding: 10px; gap: 8px; margin-bottom: 12px; }
  .profile-bar select { flex: 1 1 0; max-width: none; padding: 8px 10px; }
  .tabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }
  .tab { text-align: center; padding: 9px 4px; font-size: 0.95rem; }

  .card { padding: 14px; }
  details.platform { padding: 0 14px 14px; }
  details.platform > summary { margin: 0 -14px; padding: 12px 12px 12px 6px; }
  fieldset { padding: 8px 12px; }

  /* taller tick-box rows; a long note after a network's name wraps under the name, not the box */
  .checkbox:not(.inline-check) {
    display: block;
    position: relative;
    padding: 8px 0 8px 28px;
    margin: 0;
    line-height: 1.35;
  }
  .checkbox:not(.inline-check) > input { position: absolute; left: 0; top: 8px; margin: 0; }
  .inline-checks { gap: 0 14px; }
  .inline-checks .checkbox { min-height: 34px; }

  .image-item img { width: 64px; height: 64px; }

  /* Post, Video and Thread: the send buttons stay on screen while scrolling */
  #post-form .actions, #video-form .actions, #thread-form .actions {
    position: sticky;
    bottom: 0;
    z-index: 5;
    margin: 18px -14px -14px;
    padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
    background: var(--card);
    border-top: 1px solid var(--border);
    border-radius: 0 0 12px 12px;
  }
  /* ...except while typing, when the keyboard already takes half the screen */
  #post-form:has(textarea:focus, input[type="text"]:focus, input[type="url"]:focus) .actions,
  #video-form:has(textarea:focus, input[type="text"]:focus, input[type="url"]:focus) .actions,
  #thread-form:has(textarea:focus, input[type="text"]:focus, input[type="url"]:focus) .actions,
  #thread-form:not(.has-posts) .actions { position: static; }  /* nothing to send yet: keep Build clear */
  .actions > button { padding: 11px; }
  .secondary-actions button { padding: 9px 6px; }

  /* history: compact per-network rows; a long error drops under the network name */
  .result-row { flex-wrap: wrap; padding: 8px 12px; gap: 2px 12px; font-size: 0.85rem; }
  .history-results { gap: 4px; }
  .post-actions button, .post-actions .btn { padding: 9px 12px; }

  .autopost-row { gap: 10px; }
  .autopost-mini { width: 72px; height: 48px; }
  .sticky-save { padding-bottom: calc(8px + env(safe-area-inset-bottom)); }
}

/* ---------- Thread page: an article as a Bluesky thread ---------- */
.event-times { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 600px) { .event-times { grid-template-columns: 1fr; } }

.thread-posts { list-style: none; margin: 12px 0 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.thread-post { border: 1px solid var(--border); border-radius: 10px; padding: 10px; }
.thread-post .post-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 6px; }
.thread-post textarea { min-height: 3em; resize: vertical; overflow: hidden; }
.thread-post .count.over { color: var(--error); font-weight: 600; }
.thread-post .tools { display: flex; flex-wrap: wrap; gap: 6px; }
.thread-post .tools button { padding: 4px 8px; font-size: 0.85rem; }
.thread-images { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.thread-image { width: 120px; display: flex; flex-direction: column; gap: 4px; }
.thread-image img { width: 120px; height: 90px; object-fit: cover; border-radius: 6px; background: var(--border); }
.thread-image input { font-size: 0.8rem; padding: 4px 6px; }
.thread-image .tools button { padding: 2px 6px; font-size: 0.75rem; }
.thread-link-post { border-style: dashed; }

/* Event box: copy-each-detail helper for Facebook events */
.fb-event { margin-top: 10px; }
.fb-event-fields { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.fb-event-fields li { display: flex; align-items: center; gap: 10px; border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; }
.fb-event-fields .what { flex: 1; min-width: 0; }
.fb-event-fields .what small { display: block; color: var(--muted); }
.fb-event-fields .what span { display: block; overflow-wrap: anywhere; white-space: pre-line; max-height: 6em; overflow: hidden; }
.fb-event-fields button { flex: none; padding: 6px 12px; }

/* ---------- (i) help popups (templates/help/) ---------- */
.help-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px; padding: 0; margin: 0 0 0 6px; vertical-align: 2px;
  border-radius: 50%; border: 1px solid var(--muted); background: transparent;
  color: var(--muted); font: italic 600 13px/1 Georgia, "Times New Roman", serif; cursor: pointer;
}
.help-btn:hover, .help-btn:focus-visible { color: var(--accent); border-color: var(--accent); }
dialog.help {
  width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 48px); overflow: auto;
  padding: 20px 22px; border: 1px solid var(--border); border-radius: 12px;
  background: var(--card); color: var(--text); line-height: 1.5;
}
dialog.help::backdrop { background: rgba(0, 0, 0, 0.6); }
dialog.help h2 { font-size: 1.15rem; margin: 0 32px 10px 0; }
dialog.help h3 { font-size: 0.95rem; margin: 18px 0 4px; }
dialog.help ol, dialog.help ul { padding-left: 22px; }
dialog.help li { margin-bottom: 6px; }
dialog.help a { color: var(--accent); }
.help-close {
  position: sticky; top: 0; float: right; margin: -8px -10px 0 0;
  width: 32px; height: 32px; padding: 0; border: 0; border-radius: 50%;
  background: transparent; color: var(--muted); font-size: 22px; line-height: 1; cursor: pointer;
}
.help-close:hover { color: var(--text); background: var(--border); }
.help-note { border-left: 3px solid var(--accent); padding: 2px 12px; margin: 8px 0 12px; }
.help-note p { margin: 6px 0; }

/* ---------- Getting started checklist (Profiles page, until done) ---------- */
.getting-started .checklist { list-style: none; padding: 0; margin: 12px 0; }
.getting-started .checklist li { display: flex; gap: 10px; align-items: flex-start; margin-bottom: 10px; }
.getting-started .tick {
  flex: none; width: 20px; height: 20px; border-radius: 50%; border: 1px solid var(--muted);
  display: inline-flex; align-items: center; justify-content: center; font-size: 12px; margin-top: 1px;
}
.getting-started li.done .tick { background: var(--ok); border-color: var(--ok); color: var(--bg); }
.getting-started li.done { color: var(--muted); }
.getting-started a { color: var(--accent); }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
h2:has(> .help-btn) { display: flex; align-items: center; gap: 2px; }
h2 > .help-btn { vertical-align: 0; flex: none; }

/* ---------- Users page ---------- */
.user-card form { margin-top: 16px; }
.user-card form + form { border-top: 1px solid var(--border); padding-top: 14px; }
fieldset.profile-ticks { border: 1px solid var(--border); border-radius: 8px; padding: 6px 12px 10px; margin: 12px 0; }
fieldset.profile-ticks legend { color: var(--muted); font-size: 0.9rem; padding: 0 4px; }
