/* nosMedia CMS: only what Carson sees while signed in, plus the gear.
   Black and white like the site. Tap targets are at least 44px because he
   edits from his iPhone. */

/* Until Firestore answers (max 3s, see the inline guard in each <head>), hide
   what it might overwrite so visitors never see the old words flash. */
html.cms-pending [data-cms-id],
html.cms-pending [data-cms-list] { visibility: hidden; }

.cms-gear {
  width: 44px; height: 44px; margin: -12px -12px -12px 0; padding: 12px;
  border: 0; background: none; color: inherit; cursor: pointer; opacity: .55;
}
.cms-gear:hover, .cms-gear.is-admin { opacity: 1; }
.cms-gear svg { width: 20px; height: 20px; display: block; }
.cms-gear-fixed { position: fixed; right: 16px; bottom: 16px; margin: 0; color: var(--graphite, #5c5c5c); z-index: 60; }

.cms-backdrop {
  position: fixed; inset: 0; z-index: 1000; display: none;
  align-items: center; justify-content: center; padding: 16px;
  background: rgba(0, 0, 0, .55);
}
.cms-backdrop.open { display: flex; }
.cms-modal {
  width: min(420px, 100%); max-height: calc(100vh - 32px); max-height: calc(100dvh - 32px); overflow: auto;
  background: #fff; color: #000; border-radius: 18px; padding: 28px;
  display: grid; gap: 14px; font: 400 16px/1.5 var(--text, system-ui, sans-serif);
}
.cms-modal h2 { margin: 0 0 4px; font: 400 2rem/1 var(--display, Impact, sans-serif); text-transform: uppercase; }
.cms-modal label { display: grid; gap: 6px; font-size: .9rem; font-weight: 600; }
.cms-modal input, .cms-modal textarea {
  /* 16px, not the label's smaller size: iPhone Safari zooms the page into any box under 16px. */
  font: inherit; font-size: 16px; font-weight: 400; min-height: 44px; padding: 10px 12px;
  border: 1px solid #c9c9c7; border-radius: 10px; background: #fff; color: #000;
}
.cms-modal .cms-hint { margin: -6px 0 0; color: #5c5c5c; font-size: .85rem; font-weight: 400; }
.cms-error { margin: 0; color: #b00020; font-size: .9rem; min-height: 1.2em; }
.cms-row { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }
/* Save / Cancel stay in view at the bottom of a long box (Settings on a phone). */
.cms-modal > .cms-row:last-child { position: sticky; bottom: -28px; margin: 0 -28px -28px; padding: 12px 28px 28px; background: #fff; }

.cms-btn {
  min-height: 44px; padding: 0 18px; border-radius: 999px; border: 1px solid #000;
  background: #000; color: #fff; font: 600 .95rem var(--text, system-ui, sans-serif); cursor: pointer;
}
.cms-btn:disabled { opacity: .5; cursor: default; }
.cms-btn-ghost { background: #fff; color: #000; }

.cms-badge {
  position: fixed; left: 50%; bottom: max(16px, env(safe-area-inset-bottom)); transform: translate(-50%, 160%);
  z-index: 900; display: flex; align-items: center; gap: 8px; padding: 8px 8px 8px 18px;
  max-width: calc(100vw - 32px); flex-wrap: wrap; justify-content: center;
  background: #fff; color: #000; border: 1px solid #000; border-radius: 999px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .18); transition: transform .3s;
  font: 600 .95rem var(--text, system-ui, sans-serif);
}
.cms-badge.open { transform: translate(-50%, 0); }
.cms-badge-label::before { content: ""; display: inline-block; width: 8px; height: 8px; margin-right: 8px; border-radius: 50%; background: #000; }
#cmsBadgeExtra { display: contents; }

/* Editable text: a dashed outline Carson can see on both white and black. */
.cms-editable { outline: 1px dashed rgba(127, 127, 127, .9); outline-offset: 4px; cursor: text; border-radius: 2px; }
.cms-editable:hover { outline-style: solid; }
.cms-editable.cms-linked:not(.cms-editing) { cursor: pointer; }

/* Pencil beside each page link: tap the link to go there, tap this to reword it. */
.cms-pencil {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  width: 44px; height: 44px; margin-left: 8px; padding: 0; vertical-align: middle;
  border: 1px solid #000; border-radius: 50%; background: #fff; color: #000; cursor: pointer;
}
.cms-pencil:hover { background: #000; color: #fff; }
.cms-pencil svg { width: 18px; height: 18px; display: block; }
/* The full-screen menu stacks one link per row; keep each pencil on its link's row. */
html.cms-editing-on .menu nav { grid-template-columns: auto auto; justify-content: start; align-items: center; column-gap: 12px; }
html.cms-editing-on .menu nav .cms-pencil { margin-left: 0; }
/* The header has no room beside its button on a phone; hang the pencil just below it. */
html.cms-editing-on .header-right { position: relative; }
.header-right .cms-pencil { position: absolute; top: calc(100% + 8px); right: 0; margin: 0; }
.cms-editing { outline: 2px solid #3b82f6; outline-offset: 4px; background: rgba(59, 130, 246, .06); }
/* The hero text fades out on scroll; keep it visible while editing. */
html.cms-editing-on .hero-inner { opacity: 1 !important; transform: none !important; }

.cms-toast {
  position: fixed; left: 50%; top: 20px; transform: translate(-50%, -150%); z-index: 1100;
  max-width: calc(100vw - 32px); padding: 12px 18px; border-radius: 12px;
  background: #000; color: #fff; font: 600 .95rem/1.4 var(--text, system-ui, sans-serif);
  transition: transform .25s; text-align: center;
}
.cms-toast.show { transform: translate(-50%, 0); }

/* ---------- media replace buttons and the upload overlay ---------- */
.cms-media-host { position: relative; }
.cms-media-btn { position: absolute; top: 12px; right: 12px; z-index: 20; box-shadow: 0 4px 16px rgba(0, 0, 0, .25); }
.hero .cms-media-btn { top: calc(var(--header, 76px) + 12px); }
/* ...and below the header button's pencil, which hangs under the header while editing. */
html.cms-editing-on .hero .cms-media-btn { top: calc(var(--header, 76px) + 64px); }
.cms-slot-img { width: 100%; height: 100%; object-fit: cover; }
.cms-upload { z-index: 1050; }
.cms-progress { height: 8px; border-radius: 999px; background: #e2e2e0; overflow: hidden; }
.cms-progress i { display: block; height: 100%; width: 0; background: #000; transition: width .2s; }

/* ---------- list item tools (services, slides, films) ---------- */
.cms-item-tools { display: none; }
html.cms-editing-on [data-cms-item-id] { position: relative; }
html.cms-editing-on .cms-item-tools {
  position: absolute; top: 8px; left: 8px; right: 8px; z-index: 25;
  display: flex; flex-wrap: wrap; gap: 6px; pointer-events: none;
}
.cms-tool {
  pointer-events: auto; min-width: 44px; min-height: 44px; padding: 0 12px; border-radius: 999px;
  border: 1px solid #000; background: #fff; color: #000; cursor: pointer;
  font: 600 .85rem var(--text, system-ui, sans-serif); box-shadow: 0 4px 14px rgba(0, 0, 0, .2);
}
.cms-tool:disabled { opacity: .35; cursor: default; }
.cms-tool[aria-label^="Delete"] { margin-left: auto; }
.cms-add { display: block; margin: 16px auto 0; }

/* ---------- iPhone ---------- */
@media (max-width: 600px) {
  /* The editing bar becomes a full-width strip instead of wrapping into a tall pill. */
  .cms-badge {
    left: 12px; right: 12px; max-width: none; transform: translateY(160%);
    flex-wrap: nowrap; gap: 6px; padding: 6px; border-radius: 18px;
  }
  .cms-badge.open { transform: translateY(0); }
  .cms-badge-label { display: none; }
  .cms-badge .cms-btn { flex: 1 1 0; min-width: 0; padding: 0 8px; }
  /* Room under the last section so the strip never covers it. */
  html.cms-editing-on body { padding-bottom: 84px; }

  /* Card tools fit on one row: ← → Replace video, label, ×. */
  html.cms-editing-on .cms-item-tools { gap: 4px; }
  .cms-tool { padding: 0 10px; font-size: .8rem; }

  .cms-modal { padding: 22px 18px; border-radius: 16px; }
  .cms-modal > .cms-row:last-child { bottom: -22px; margin: 0 -18px -22px; padding: 12px 18px 22px; }
}

/* Slide titles run down the top-left corner, so the slide tools sit at the
   bottom instead of covering the words Carson needs to tap. */
html.cms-editing-on [data-cms-list="slides"] .cms-item-tools { top: auto; bottom: 8px; }
