/* ============================================================================
   Cloud layer — login, entity dashboard, sharing, floating bar.
   Uses the BUILDER's own design tokens (:root vars from app.css, which loads
   first) so it matches the app exactly and follows the active theme.
   ========================================================================== */
#cloudRoot, #cloudRoot * { box-sizing: border-box; }

.cloud-screen {
  position: fixed; inset: 0; z-index: 4000;
  display: flex; align-items: flex-start; justify-content: center;
  padding: 44px 24px; overflow: auto;
  background:
    radial-gradient(120% 90% at 50% -10%, var(--accent-muted) 0%, rgba(0,0,0,0) 55%),
    var(--bg);
  font-family: var(--font-body);
  color: var(--text);
  letter-spacing: .01em;
}
.cloud-screen.center { align-items: center; }

.cloud-card {
  width: 100%; max-width: 416px;
  background: var(--paper2);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 30px 28px;
}
.cloud-card.wide { max-width: 860px; }

.cloud-brand { display: flex; align-items: center; gap: 11px; color: var(--text-strong); }
.cloud-brand.lg { flex-direction: column; gap: 13px; align-items: center; text-align: center; margin-bottom: 2px; }
.cloud-logo-mark { height: 26px; width: auto; flex: none; display: block; }
.cloud-brand.lg .cloud-logo-mark { height: 54px; width: auto; }
.cloud-wordmark { font-size: var(--fs-body-lg); color: var(--text-strong); letter-spacing: .02em; font-weight: 400; white-space: nowrap; }
.cloud-wordmark b { font-weight: 700; }
.cloud-brand.lg .cloud-wordmark { font-size: 23px; }

.cloud-sub { color: var(--muted); font-size: var(--fs-meta); margin: 10px 0 22px; line-height: 1.5; }
.cloud-sub.center { text-align: center; }

.cloud-field { margin-bottom: 14px; }
.cloud-field label { display: block; font-size: var(--fs-label-sm); color: var(--muted); margin-bottom: 6px; font-weight: var(--fw-control); }
.cloud-field input, .cloud-field select {
  width: 100%; padding: 12px 14px;
  border: 1px solid var(--line2); border-radius: var(--radius-sm);
  background: var(--paper3); color: var(--text);
  font-size: var(--fs-body); font-weight: var(--fw-body); font-family: inherit;
}
.cloud-field input::placeholder { color: var(--muted2); }
.cloud-field input:focus, .cloud-field select:focus { outline: none; border-color: var(--accent-strong); background: var(--surface-dark); box-shadow: 0 0 0 3px var(--accent-muted); }

/* buttons mirror the app's .btn */
.cloud-btn {
  padding: 9px 15px; min-height: 42px;
  border: 1px solid var(--primary); border-radius: var(--radius-sm);
  background: var(--primary); color: #fff;
  font-size: 14px; font-weight: var(--fw-control); font-family: inherit;
  letter-spacing: .02em; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  transition: background .15s ease, border-color .15s ease;
}
.cloud-btn.block { width: 100%; }
.cloud-btn:hover { background: var(--accent-strong); border-color: var(--accent-strong); }
.cloud-btn:active { transform: translateY(1px); }
.cloud-btn:disabled { opacity: .55; cursor: default; }
.cloud-btn.ghost { background: transparent; border-color: var(--line2); color: var(--text-soft); }
.cloud-btn.ghost:hover { background: rgba(255,255,255,.05); border-color: rgba(255,255,255,.38); color: #fff; }
.cloud-btn.sm { min-height: 32px; padding: 0 12px; font-size: var(--fs-label-sm); }
.cloud-btn.danger { background: transparent; border-color: rgba(180,35,24,.62); color: #F1C4C0; }
.cloud-btn.danger:hover { background: rgba(180,35,24,.16); border-color: rgba(180,35,24,.85); }
.cloud-btn.google { background: var(--paper3); color: var(--text-soft); border-color: var(--line2); }
.cloud-btn.google:hover { background: #262626; border-color: rgba(255,255,255,.38); }

.cloud-or { display: flex; align-items: center; gap: 12px; color: var(--muted2); font-size: var(--fs-label-sm); margin: 16px 0 8px; }
.cloud-or::before, .cloud-or::after { content: ''; flex: 1; height: 1px; background: var(--line); }

.cloud-toggle { margin-top: 18px; text-align: center; font-size: var(--fs-meta); color: var(--muted); }
.cloud-toggle button { background: none; border: none; color: var(--text-soft); cursor: pointer; font-size: var(--fs-meta); font-family: inherit; font-weight: var(--fw-control); padding: 0 2px; }
.cloud-toggle button:hover { text-decoration: underline; }

.cloud-msg { margin-top: 14px; font-size: var(--fs-meta); line-height: 1.5; padding: 10px 12px; border-radius: var(--radius-sm); }
.cloud-msg.err  { background: rgba(180,35,24,.14); border: 1px solid rgba(180,35,24,.5); color: #F1C4C0; }
.cloud-msg.ok   { background: rgba(70,185,138,.14); border: 1px solid rgba(70,185,138,.45); color: #A9E2C4; }
.cloud-msg.info { background: var(--accent-muted); border: 1px solid var(--accent); color: var(--text-soft); }

/* ---------- dashboard ---------- */
.cloud-dash-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.cloud-dash-head .who { font-size: var(--fs-meta); color: var(--muted); display: flex; align-items: center; gap: 10px; }
.cloud-dash-head .who button { background: transparent; border: 1px solid var(--line2); color: var(--text-soft); border-radius: var(--radius-sm); padding: 7px 12px; font-size: var(--fs-label-sm); font-weight: var(--fw-control); cursor: pointer; font-family: inherit; white-space: nowrap; display: inline-flex; align-items: center; }
.cloud-dash-head .who button:hover { border-color: rgba(255,255,255,.38); background: rgba(255,255,255,.05); color: #fff; }

.cloud-section-title { display: flex; align-items: center; justify-content: space-between; margin: 26px 0 12px; }
.cloud-section-title h2 { font-size: var(--fs-label-sm); font-weight: 600; color: var(--muted); letter-spacing: .09em; text-transform: uppercase; margin: 0; }

.cloud-entity { border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--paper2); margin-bottom: 12px; overflow: hidden; }
.cloud-entity-head { display: flex; align-items: center; gap: 12px; padding: 14px 16px; cursor: pointer; }
.cloud-entity-head:hover { background: var(--paper3); }
.cloud-entity-head .caret { color: var(--muted2); transition: transform .15s ease; flex: none; }
.cloud-entity.open .cloud-entity-head .caret { transform: rotate(90deg); }
.cloud-entity-head .ent-name { font-size: var(--fs-body); font-weight: 600; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text-strong); }
.cloud-entity-head .ent-count { font-size: var(--fs-label-sm); color: var(--muted2); flex: none; }
.cloud-badge { font-size: 11px; font-weight: 600; padding: 3px 9px; border-radius: var(--radius-full); flex: none; letter-spacing: .02em; }
.cloud-badge.owner  { background: var(--accent-muted); color: #9FB6E0; border: 1px solid var(--accent); }
.cloud-badge.editor { background: rgba(70,185,138,.16); color: #A9E2C4; }
.cloud-badge.viewer { background: rgba(156,163,175,.16); color: #C7CDD7; }

.cloud-entity-body { display: none; padding: 4px 12px 14px; }
.cloud-entity.open .cloud-entity-body { display: block; }
.cloud-entity-actions { display: flex; flex-wrap: wrap; gap: 8px; padding: 6px 4px 12px; }

.cloud-sop { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 11px 13px; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius-sm); margin-bottom: 7px; cursor: pointer; transition: border-color .15s ease, background .15s ease; }
.cloud-sop:hover { border-color: var(--accent-strong); background: var(--surface-dark); }
.cloud-sop .meta { min-width: 0; }
.cloud-sop .title { font-size: var(--fs-meta); font-weight: 600; color: var(--text-soft); display: flex; align-items: center; gap: 7px; min-width: 0; }
.cloud-sop .title .t-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
/* Content-version tag, right beside the SOP title — see which version each SOP is before opening it
   (there can be several SOPs per entity). flex:none so it never shrinks or clips when the title is long. */
.cloud-sop .cloud-sop-ver { flex: none; font-size: 10.5px; font-weight: 600; letter-spacing: .03em; padding: 2px 8px; border-radius: var(--radius-full); background: var(--surface-dark, rgba(255,255,255,.06)); color: var(--text-soft); border: 1px solid var(--line); white-space: nowrap; }
.cloud-sop .sub { font-size: 11.5px; color: var(--muted2); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cloud-sop .row-actions { display: flex; gap: 6px; flex: none; }
.cloud-sop .row-actions button { background: transparent; border: 1px solid var(--line2); color: var(--muted); border-radius: var(--radius-sm); padding: 5px 9px; font-size: 11.5px; cursor: pointer; font-family: inherit; }
.cloud-sop .row-actions button:hover { border-color: rgba(255,255,255,.38); color: #fff; }
.cloud-sop .row-actions button.del:hover { border-color: rgba(180,35,24,.85); color: #F1C4C0; }
.cloud-sop .meta { flex: 1; }

/* reorder controls — minimal up/down chevrons, revealed on hover */
.cloud-move-group { flex: none; display: inline-flex; gap: 1px; margin-left: 4px; opacity: 0; transition: opacity .14s ease; }
.cloud-entity-head:hover .cloud-move-group, .cloud-sop:hover .cloud-move-group,
.cloud-move-group:focus-within { opacity: 1; }
.cloud-move { width: 22px; height: 22px; display: inline-flex; align-items: center; justify-content: center; padding: 0; border: 0; background: transparent; color: var(--muted2); border-radius: var(--radius-sm); cursor: pointer; font-family: inherit; }
.cloud-move:hover:not(:disabled) { background: rgba(255,255,255,.08); color: var(--text); }
.cloud-move:disabled { opacity: .28; cursor: default; }
.cloud-move svg { display: block; }
/* touch devices have no hover — keep the controls visible but quiet */
@media (hover: none) { .cloud-move-group { opacity: .6; } }

.cloud-empty { color: var(--muted2); font-size: var(--fs-meta); padding: 10px 6px; line-height: 1.6; }
.cloud-empty.big { text-align: center; padding: 26px 10px; }

.cloud-spinner { width: 28px; height: 28px; margin: 30px auto; border-radius: 50%; border: 3px solid var(--line2); border-top-color: var(--text-soft); animation: cloudspin .8s linear infinite; }
@keyframes cloudspin { to { transform: rotate(360deg); } }

/* ---------- modal ---------- */
.cloud-modal-back { position: fixed; inset: 0; z-index: 4200; background: rgba(0,0,0,.62); display: flex; align-items: center; justify-content: center; padding: 24px; }
.cloud-modal { width: 100%; max-width: 460px; background: var(--paper2); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 24px; max-height: calc(100vh - 48px); max-height: calc(100dvh - 48px); overflow-y: auto; }
/* Many users: the admin modal is a flex column so the header + Done stay pinned and only the
   user list scrolls — keeps everything reachable even on short / mobile screens. */
.cloud-modal.wide { display: flex; flex-direction: column; }
.cloud-modal.wide > * { flex: none; }
#adminList { flex: 1 1 auto; min-height: 0; overflow-y: auto; margin-right: -6px; padding-right: 6px; }
.cloud-modal h3 { margin: 0 0 4px; font-size: var(--fs-body-lg); font-weight: 600; color: var(--text-strong); }
.cloud-modal .hint { color: var(--muted); font-size: var(--fs-meta); margin: 0 0 16px; line-height: 1.5; }
.cloud-modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

.cloud-share-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 9px 11px; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius-sm); margin-bottom: 7px; }
.cloud-share-row .em { font-size: var(--fs-meta); min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text-soft); }
.cloud-share-row .ctl { display: flex; gap: 7px; align-items: center; flex: none; }
.cloud-share-row select, .cloud-add-row select { background: var(--paper3); border: 1px solid var(--line2); color: var(--text); border-radius: var(--radius-sm); padding: 7px 8px; font-size: var(--fs-label-sm); font-family: inherit; }
.cloud-add-row { display: flex; gap: 8px; margin-top: 12px; }
.cloud-add-row input { flex: 1; padding: 10px 12px; border: 1px solid var(--line2); border-radius: var(--radius-sm); background: var(--paper3); color: var(--text); font-size: var(--fs-meta); font-family: inherit; }
.cloud-add-row input::placeholder { color: var(--muted2); }
.cloud-add-row input:focus { outline: none; border-color: var(--accent-strong); background: var(--surface-dark); }

/* ---------- approval / pending screen ---------- */
.cloud-pending { text-align: center; margin-top: 18px; }
.cloud-pending-icon { font-size: 40px; line-height: 1; margin-bottom: 12px; }
.cloud-pending h2 { font-size: var(--fs-body-lg); font-weight: 600; color: var(--text-strong); margin: 0 0 4px; }
.cloud-pending .cloud-sub { margin: 10px 0 16px; }
.cloud-pending-who { font-size: var(--fs-label-sm); color: var(--muted2); margin: 0 0 18px; }
.cloud-pending.rejected .cloud-pending-icon { filter: grayscale(.2); }

/* ---------- admin: manage users ---------- */
.cloud-dash-head .who button.admin-link { border-color: var(--accent); color: #9FB6E0; }
.cloud-dash-head .who button.admin-link:hover { background: var(--accent-muted); border-color: var(--accent-strong); color: #fff; }
.cloud-pill { display: inline-flex; align-items: center; justify-content: center; min-width: 18px; height: 18px; padding: 0 5px; margin-left: 5px; border-radius: var(--radius-full); background: #B42318; color: #fff; font-size: 11px; font-weight: 700; }

.cloud-modal.wide { max-width: 640px; }
/* Each user gets two tidy lines: the email on its own row (never truncated), then the status on the
   left and the role + action buttons grouped on the right — they wrap instead of crowding the email. */
.cloud-user-row { display: flex; flex-wrap: wrap; align-items: center; gap: 9px 10px; padding: 11px 13px; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius-sm); margin-bottom: 7px; }
.cloud-user-row .em { flex: 1 1 100%; min-width: 0; font-size: var(--fs-meta); color: var(--text-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; align-items: center; gap: 7px; }
.cloud-user-row .ctl { flex: 0 1 auto; display: flex; flex-wrap: wrap; gap: 7px; align-items: center; justify-content: flex-end; margin-left: auto; }
.cloud-user-row .ctl .cloud-role { flex: none; }
.cloud-self { font-size: var(--fs-label-sm); color: var(--muted2); padding: 0 4px; }
.cloud-tag { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; padding: 2px 6px; border-radius: var(--radius-full); background: var(--accent-muted); color: #9FB6E0; border: 1px solid var(--accent); }
.cloud-badge.pending { background: rgba(227,192,138,.16); color: #E3C08A; }
.cloud-badge.danger  { background: rgba(180,35,24,.16); color: #F1C4C0; }
/* Role picker: drop the cramped native dropdown caret for a clean role chip-button (still a select). */
/* No dropdown caret: the global select rule paints an !important SVG chevron + 42px right-pad;
   override both so the role reads as a clean centered chip-button (still a working <select>). */
.cloud-role { appearance: none; -webkit-appearance: none; width: auto; min-width: 78px; background: var(--paper3); background-image: none !important; border: 1px solid var(--line2); color: var(--text); border-radius: var(--radius-sm); padding: 7px 12px !important; font-size: var(--fs-label-sm); font-weight: var(--fw-control); font-family: inherit; cursor: pointer; text-align: center; }
.cloud-role:hover { border-color: var(--accent-strong); }
.cloud-role:focus { outline: none; border-color: var(--accent-strong); box-shadow: 0 0 0 3px var(--accent-muted); background-image: none !important; }
/* admin tools: sort + history */
.cloud-admin-tools { display: flex; align-items: center; gap: 10px; margin: 4px 0 12px; }
.cloud-sort { font-size: var(--fs-label-sm); color: var(--muted2); display: inline-flex; align-items: center; }
.cloud-sort select { background: var(--paper3); border: 1px solid var(--line2); color: var(--text); border-radius: var(--radius-sm); padding: 5px 8px; font-size: var(--fs-label-sm); font-family: inherit; cursor: pointer; }
.cloud-tools-spacer { flex: 1; }
.cloud-user-row .st { flex: none; display: flex; flex-direction: column; align-items: flex-start; gap: 3px; }
.cloud-seen { font-size: 10.5px; color: var(--muted2); white-space: nowrap; }
/* history log */
.cloud-hist { margin: 4px 0 8px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--paper); padding: 10px 12px; max-height: 300px; overflow: auto; }
.cloud-hist-h { font-size: var(--fs-label-sm); font-weight: 600; color: var(--text-soft); margin-bottom: 8px; }
.cloud-hist-row { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 9px; padding: 7px 0; border-top: 1px solid var(--line); font-size: var(--fs-label-sm); }
.cloud-hist-row:first-of-type { border-top: 0; }
.cloud-hist-row .ha { font-weight: 700; text-transform: capitalize; padding: 2px 7px; border-radius: var(--radius-full); background: var(--accent-muted); color: var(--text-soft); flex: none; }
.cloud-hist-row .ha.approved { background: rgba(70,185,138,.16); color: #A9E2C4; }
.cloud-hist-row .ha.rejected, .cloud-hist-row .ha.revoked, .cloud-hist-row .ha.deleted, .cloud-hist-row .ha.removed { background: rgba(180,35,24,.16); color: #F1C4C0; }
.cloud-hist-row .ht { color: var(--text); font-weight: 600; }
.cloud-hist-row .hd { color: var(--muted2); }
.cloud-hist-row .hby { color: var(--muted2); margin-left: auto; white-space: nowrap; }

@media (max-width: 560px) {
  .cloud-user-row { flex-wrap: wrap; row-gap: 9px; }
  .cloud-user-row .em { flex-basis: 100%; }
  .cloud-user-row .ctl { margin-left: auto; flex-wrap: wrap; justify-content: flex-end; }   /* badge left, role+actions right on line 2 */
  .cloud-user-row .ctl .cloud-btn.sm { min-height: 36px; }
}

/* ---------- floating account bar ---------- */
#cloudBar { position: fixed; right: 14px; bottom: 14px; z-index: 3500; display: flex; gap: 8px; align-items: center; font-family: var(--font-body); }
#cloudBar button { display: inline-flex; align-items: center; gap: 7px; padding: 8px 13px; background: var(--toolbar); border: 1px solid var(--line2); border-radius: var(--radius-full); color: var(--text-soft); font-size: var(--fs-label-sm); font-weight: var(--fw-control); font-family: inherit; cursor: pointer; }
#cloudBar button:hover { border-color: rgba(255,255,255,.38); background: var(--paper3); color: #fff; }
#cloudBar .cloud-status { font-size: 11.5px; color: var(--muted2); padding-right: 2px; }
#cloudBar .cloud-status.saving { color: #E3C08A; }
#cloudBar .cloud-status.saved  { color: #A9E2C4; }
/* Concurrent-edit conflict: a teammate saved since you opened the SOP. Stands out so it's not missed. */
#cloudBar .cloud-status.conflict { color: #F1C4C0; font-weight: var(--fw-control); cursor: help; }
#cloudBar .cloud-ro { font-size: 11.5px; color: #C7CDD7; background: rgba(156,163,175,.16); padding: 7px 12px; border-radius: var(--radius-full); }
/* Presence: stacked avatar initials of who else has this SOP open. Hidden when nobody else is here. */
#cloudBar .cloud-presence { display: none; }
#cloudBar .cloud-presence.has { display: inline-flex; align-items: center; padding: 3px 7px 3px 4px; background: var(--toolbar); border: 1px solid var(--line2); border-radius: var(--radius-full); }
#cloudBar .cloud-who { width: 22px; height: 22px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-size: 9.5px; font-weight: 700; color: #fff; border: 1.5px solid var(--toolbar); margin-left: -6px; }
#cloudBar .cloud-who:first-child { margin-left: 0; }
#cloudBar .cloud-who.editing { box-shadow: 0 0 0 1.5px var(--toolbar), 0 0 0 3px #E3C08A; }  /* amber ring = the active editor */
#cloudBar .cloud-who-more { font-size: 10.5px; color: var(--muted2); margin-left: 5px; }
/* Edit-lock banner: someone else holds the single-editor lock; you're read-only until they finish or you take over. */
#cloudBar .cloud-lock { display: none; }
#cloudBar .cloud-lock.has { display: inline-flex; align-items: center; gap: 8px; padding: 5px 6px 5px 12px; background: rgba(192,136,58,.16); border: 1px solid rgba(192,136,58,.45); border-radius: var(--radius-full); color: #E3C08A; font-size: 11.5px; }
#cloudBar .cloud-lock-msg { white-space: nowrap; }
#cloudBar .cloud-lock-take { padding: 4px 11px; background: var(--primary); border: 1px solid var(--primary); border-radius: var(--radius-full); color: #fff; font-size: 11px; font-weight: var(--fw-control); font-family: inherit; cursor: pointer; }
#cloudBar .cloud-lock-take:hover { background: var(--accent-strong); border-color: var(--accent-strong); }
:root[data-mode="light"] #cloudBar .cloud-lock.has { color: #8a5a16; }
/* The brand mark ships as a white PNG (for the dark theme); on the light-mode dashboard/entity
   screen it would wash out on the light background, so flip it to a dark mark to match the wordmark. */
:root[data-mode="light"] .cloud-logo-mark { filter: invert(1); }

/* view-only: hide editing affordances for viewers (refined per real markup at 2.0 integration) */
body.cloud-viewonly [data-action="toggle-edit"], body.cloud-viewonly #editToggle { display: none !important; }

@media (max-width: 560px) {
  #cloudBar { right: 10px; bottom: 10px; }
  #cloudBar .label-text { display: none; }
  .cloud-card { padding: 22px 18px; }

  /* dashboard header stacks: brand row, then email + actions below */
  .cloud-dash-head { flex-direction: column; align-items: stretch; gap: 14px; }
  .cloud-dash-head .cloud-brand { justify-content: flex-start; }
  .cloud-dash-head .who { flex-wrap: wrap; gap: 8px; }
  .cloud-dash-head .who > span { flex: 1 1 100%; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .cloud-dash-head .who button { flex: 1 1 auto; justify-content: center; min-height: 40px; }

  /* section title: keep heading + action on one tidy row */
  .cloud-section-title { gap: 10px; }
  .cloud-section-title .cloud-btn.sm { flex: none; }

  /* modals fill the small screen with comfortable padding */
  .cloud-modal-back { padding: 14px; }
  .cloud-modal, .cloud-modal.wide { max-width: 100%; padding: 20px 18px; }
  .cloud-modal-actions .cloud-btn { flex: 1 1 auto; }
}
