/*
 * Issue #402 Community S1-U3 (design 6, R3; mockups w01 to w28) - the signed-in Community pages:
 * the R3 resets under the Community view's story wrapper, then the Community components.
 *
 * R3. The Community view renders the SAME story as /j (PublicJourneyStory) inside
 * <div class="pj pj-theme cm-story">, but in the Web app, where Bootstrap's Reboot, MudBlazor and
 * app.css also style bare elements (p, list and figure margins, heading sizes and weights, image
 * alignment, letter spacing). /j has none of them. So, under .cm-story only, each element the story
 * uses is put back to the browser's own value with `revert`, at ZERO added specificity
 * (:where(.cm-story) x is (0,0,1), as the bare rules it undoes). This sheet is linked BEFORE
 * journey-story.css (App.razor): it wins its ties against Bootstrap and app.css, which come
 * earlier, and loses them to the story's own (0,0,1) rules (:where(.pj-theme) a, the headings),
 * which come later, exactly as on /j. Never a rule /j reads: /j never links this sheet.
 *
 * Colours are the --cailo-* tokens (tokens.css); no hex.
 */

/* ================================================================== R3: the story as /j renders it */
.cm-story { letter-spacing: normal; }

:where(.cm-story) :is(p, h1, h2, h3, h4, h5, h6, ol, ul, li, dl, dt, dd, figure, figcaption, details, summary, b, strong, small) {
    margin: revert;
    padding: revert;
    font-family: revert;
    font-size: revert;
    font-weight: revert;
    line-height: revert;
    color: revert;
}

:where(.cm-story) :is(img, svg) { vertical-align: revert; }
:where(.cm-story) a { text-decoration: revert; }

/* The full-screen map is /j's :target. Blazor's in-page navigation moves the hash with pushState,
   which never updates :target, so the Community view cannot open it: its open-map links are hidden
   (design 6, 10.4). The overview SVG, the day maps and the battery chart stay. */
.cm-story .pj-map-open, .cm-story .pj-daymap-open { display: none; }

/* The view's own footer, holding the not-advice notice as /j's footer does. */
.cm-story-footer { max-width: 760px; margin: 0 auto; padding: 8px 16px 40px; display: flex; justify-content: center; text-align: center; }

/* ================================================================== the pages */
.cm-page { padding-top: 16px; }
.cm-head { margin: 4px 0 16px; }
.cm-title.mud-typography { font-family: var(--cailo-font-family-headings); font-weight: 700; color: var(--cailo-primary-dark); }
.cm-sentence.mud-typography { color: var(--cailo-text-secondary); }
.cm-back { display: inline-flex; margin-bottom: 8px; font-weight: 600; }

.cm-card { background: var(--cailo-surface); border-radius: 16px; box-shadow: 0 4px 14px var(--cailo-shadow-color); padding: 20px 24px; }
.cm-mid { max-width: 880px; }
.cm-card-skeleton { border-radius: 16px; }
.cm-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.cm-col { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.cm-sp { flex: 1; }
.cm-h2 { font: 700 20px/1.3 var(--cailo-font-family-headings); color: var(--cailo-primary-dark); margin: 0; }
.cm-h3 { font: 700 15px/1.3 var(--cailo-font-family-headings); color: var(--cailo-text-primary); margin: 18px 0 6px; }
.cm-body { font: 400 14px/1.55 var(--cailo-font-family-body); color: var(--cailo-text-primary); margin: 0; }
.cm-small { font: 400 12px/1.45 var(--cailo-font-family-body); color: var(--cailo-text-secondary); margin: 0; }
.cm-strong { font-weight: 700; color: var(--cailo-text-primary); }
.cm-strong-link { font-weight: 700; }
.cm-list { padding-left: 20px; margin: 0; }
.cm-list li + li { margin-top: 4px; }
.cm-state-icon { color: var(--cailo-text-secondary); }

.cm-intro { display: flex; gap: 20px; align-items: flex-start; }
.cm-intro-icon.mud-icon-root { font-size: 48px; width: 48px; height: 48px; color: var(--cailo-primary); flex: none; }
.cm-fixed-line {
    display: flex; gap: 10px; align-items: center; padding: 12px 14px; border-radius: 10px;
    background: var(--cailo-primary-05); font: 600 14px/1.45 var(--cailo-font-family-body); color: var(--cailo-text-primary);
}
.cm-fixed-line .mud-icon-root { color: var(--cailo-primary-hover); }

.cm-steps { font: 700 12px var(--cailo-font-family-body); letter-spacing: .4px; text-transform: uppercase; color: var(--cailo-primary-hover); margin: 0 0 10px; }
.cm-rules { border: 1px solid var(--cailo-border-color); border-radius: 10px; padding: 14px 16px; }
.cm-rules ul { margin: 6px 0 8px; padding-left: 20px; font: 400 13px/1.55 var(--cailo-font-family-body); color: var(--cailo-text-primary); }
.cm-rules-page .cm-h2 { margin-bottom: 8px; }
.cm-setting { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 16px; align-items: center; padding: 16px 0 0; border-top: 1px solid var(--cailo-border-color); }

.cm-people { list-style: none; margin: 0; padding: 4px 24px; }
.cm-person { display: grid; grid-template-columns: 40px minmax(0, 1fr) auto; gap: 14px; align-items: center; padding: 14px 0; }
.cm-person + .cm-person { border-top: 1px solid var(--cailo-border-color); }
.cm-name { font: 700 14px/1.3 var(--cailo-font-family-body); color: var(--cailo-text-primary); }

/* ================================================================== the journey view */
.cm-journey-top { display: flex; flex-wrap: wrap; align-items: center; gap: 0 12px; max-width: 1440px; margin: 0 auto; padding: 12px 16px 0; }
.cm-owner-band {
    display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px;
    max-width: 1180px; margin: 12px auto 0; padding: 12px 16px; border-radius: 10px;
    background: var(--cailo-tertiary-10); border-left: 4px solid var(--cailo-tertiary-dark);
    font: 400 14px/1.45 var(--cailo-font-family-body); color: var(--cailo-text-primary);
}

/* One item's actions, in the story's slot: a white bar, so it reads the same on a light day and on the dark closing chapter. */
.cm-item { margin: 12px 0 0; }
.cm-item--open { background: var(--cailo-surface); border-radius: 14px; box-shadow: 0 2px 10px var(--cailo-shadow-color); padding: 4px 0 8px; color: var(--cailo-text-primary); }
.pj-moment-card > .cm-item { margin: 8px 16px 12px; }
.pj-closing .cm-item { margin-top: 20px; }
.pj-gallery .cm-item { margin-top: 6px; }

.cm-bar {
    display: flex; align-items: center; flex-wrap: wrap; gap: 8px 12px;
    padding: 6px 10px; border-radius: 14px; background: var(--cailo-surface); width: fit-content; max-width: 100%;
    border: 1px solid var(--cailo-border-color); color: var(--cailo-text-primary);
}
.cm-item--open > .cm-bar { border: 0; border-radius: 14px 14px 0 0; width: auto; }
.cm-bar .cm-err-text { flex-basis: 100%; }

.cm-link-icon svg { display: block; width: 16px; height: 16px; fill: currentColor; }
.cm-sum { display: inline-flex; align-items: center; gap: 6px; font: 600 13px/1 var(--cailo-font-family-body); color: var(--cailo-text-primary); }
.cm-sum-top { letter-spacing: -2px; font-size: 15px; }
.cm-link {
    display: inline-flex; align-items: center; gap: 5px; min-height: 32px; padding: 0; margin: 0; border: 0; background: none; cursor: pointer;
    font: 700 13px var(--cailo-font-family-body); color: var(--cailo-primary-hover);
}
.cm-link:hover { text-decoration: underline; }
.cm-greyed { color: var(--cailo-text-secondary); opacity: .75; }
.cm-err-text { font: 400 12px/1.4 var(--cailo-font-family-body); color: var(--cailo-danger-dark); margin: 4px 0 0; }
.cm-warn-text { font: 600 12px/1.4 var(--cailo-font-family-body); color: var(--cailo-text-primary); margin: 4px 0 0; padding: 6px 10px; border-radius: 6px; background: var(--cailo-warning-light); }

/* The conversation (w08 to w10c). */
.cm-thread { padding: 4px 16px 8px; }
.cm-thread--off .cm-greyed { opacity: .6; }
.cm-c { display: grid; grid-template-columns: 32px minmax(0, 1fr) auto; gap: 2px 10px; padding: 10px 0; align-items: start; }
.cm-c + .cm-c { border-top: 1px solid var(--cailo-border-color); }
.cm-c.cm-reply { margin-left: 42px; border-top: 0; padding-top: 2px; }
.cm-c-main { min-width: 0; }
.cm-meta { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.cm-when { font: 400 12px var(--cailo-font-family-body); color: var(--cailo-text-secondary); }
.cm-text { font: 400 14px/1.5 var(--cailo-font-family-body); color: var(--cailo-text-primary); margin: 2px 0 4px; white-space: pre-line; overflow-wrap: anywhere; }
.cm-acts { display: flex; gap: 16px; }
.cm-acts .cm-link { font-size: 12px; min-height: 28px; }
.cm-reply-composer { margin-left: 42px; }
.cm-composer { margin-top: 10px; }
.cm-composer-foot { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 12px; margin-top: 6px; }
.cm-visible { display: inline-flex; align-items: center; gap: 4px; }
.cm-hl-preview { margin: 6px 0 0; padding: 8px 10px; border-radius: 6px; border: 1px solid var(--cailo-border-color); white-space: pre-line; font: 400 14px/1.5 var(--cailo-font-family-body); color: var(--cailo-text-primary); }
.cm-hl { background: var(--cailo-danger-light); color: var(--cailo-danger-dark); border-radius: 3px; padding: 0 2px; text-decoration: underline wavy var(--cailo-danger); }

/* The photo viewer (w07c): component state, over the page. */
.cm-viewer { position: fixed; inset: 0; z-index: 1500; display: flex; flex-direction: column; background: var(--cailo-primary-dark); background: color-mix(in srgb, var(--cailo-primary-dark) 22%, black); color: var(--cailo-white); outline: none; }
.cm-viewer-bar { display: flex; align-items: center; gap: 8px; padding: 8px 12px; }
.cm-viewer-count { font: 600 13px/1 var(--cailo-font-family-headings); color: var(--cailo-white-80); }
.cm-viewer-btn { display: grid; place-items: center; width: 44px; height: 44px; border: 0; border-radius: 50%; background: var(--cailo-white-15); color: var(--cailo-white); cursor: pointer; }
.cm-viewer-btn:disabled { opacity: .35; cursor: default; }
.cm-viewer-btn:focus-visible { outline: 3px solid var(--cailo-white); outline-offset: 2px; }
.cm-viewer-body { flex: 1; min-height: 0; overflow: auto; display: flex; flex-direction: column; gap: 16px; padding: 0 16px 24px; }
.cm-viewer-figure { margin: 0 auto; width: min(1100px, 100%); display: flex; flex-direction: column; gap: 10px; }
.cm-viewer-stack { display: grid; }
.cm-viewer-stack > img { grid-area: 1 / 1; display: block; width: 100%; height: auto; max-height: 64vh; object-fit: contain; }
.cm-viewer-figure figcaption { display: flex; flex-direction: column; gap: 2px; }
.cm-viewer-caption { font: 700 1.05rem/1.35 var(--cailo-font-family-headings); white-space: pre-line; }
.cm-viewer-detail { font-size: 14px; color: var(--cailo-white-80); }
.cm-viewer-side { width: min(1100px, 100%); margin: 0 auto; }
.cm-viewer-side .cm-item { margin: 0; }

@media (min-width: 1024px) {
    .cm-viewer-body { flex-direction: row; align-items: flex-start; }
    .cm-viewer-figure { flex: 1; }
    .cm-viewer-side { flex: 0 0 380px; width: 380px; }
}

/* ================================================================== the owner's journey page (design 6, w09) */
.cm-chip-row { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.cm-chip-row--card { display: flex; padding: 0 16px 12px; }
.cm-chip-row--dark { display: flex; margin-top: 8px; }
.cm-chip {
    display: inline-flex; align-items: center; gap: 6px; min-height: 30px; padding: 2px 12px; border-radius: 999px;
    background: var(--cailo-surface); border: 1px solid var(--cailo-border-color);
    font: 600 13px/1 var(--cailo-font-family-body); color: var(--cailo-text-primary); text-decoration: none;
}
.cm-chip-link { color: var(--cailo-primary-hover); }
.cm-chip-link:hover { text-decoration: underline; }

/* ================================================================== slice 3: the feed (w04 to w06), post (w09 to w09d), who reacted (w11) */
.cm-feed-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-end; gap: 12px 16px; margin: 4px 0 12px; }
.cm-feed-head .cm-head { margin: 0; }
.cm-tabs-row { display: flex; align-items: center; flex-wrap: wrap; gap: 12px; margin: 4px 0 16px; }
.cm-by { display: flex; align-items: center; gap: 8px; margin: 0 0 8px; font: 600 13px/1.3 var(--cailo-font-family-body); color: var(--cailo-text-primary); }
.cm-by .mud-avatar { width: 28px; height: 28px; font-size: 12px; }
.cm-card-foot { display: flex; align-items: center; gap: 12px; margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--cailo-border-color); font: 600 13px/1.3 var(--cailo-font-family-body); color: var(--cailo-text-secondary); }
.cm-card-foot .cm-link-icon svg { display: inline-block; vertical-align: -3px; }
.cm-end { margin: 24px 0 8px; text-align: center; font: 600 14px/1.4 var(--cailo-font-family-body); color: var(--cailo-text-secondary); }
.cm-feed-section { margin-top: 24px; }
.cm-skel-card { border-radius: 16px; overflow: hidden; background: var(--cailo-surface); box-shadow: 0 4px 14px var(--cailo-shadow-color); }
.cm-empty-icon.mud-icon-root { font-size: 40px; width: 40px; height: 40px; color: var(--cailo-primary); }
.cm-badge { display: inline-flex; align-items: center; padding: 3px 10px; border-radius: 999px; background: var(--cailo-primary-10); color: var(--cailo-primary-dark); font: 700 12px/1.3 var(--cailo-font-family-body); margin-bottom: 8px; }
.cm-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 4px; }
.cm-people--dialog { padding: 0; }
.cm-person-who { min-width: 0; overflow-wrap: anywhere; }
.cm-person-face { font-size: 22px; line-height: 1; }
.cm-sum-button { padding: 4px 6px; margin: 0; border: 0; border-radius: 8px; background: none; cursor: pointer; }
.cm-sum-button:hover { background: var(--cailo-primary-05); }
.cm-sum-button:focus-visible { outline: 3px solid var(--cailo-primary); outline-offset: 2px; }
.cm-post-block { padding: 14px 0; border-top: 1px solid var(--cailo-border-color); }
.cm-post-block:first-child { border-top: 0; padding-top: 0; }
/* UI review M1: the Community owner dialog's key catcher (Escape goes through Done); focusable, never outlined. */
.cm-keys:focus { outline: none; }
.cm-refused { margin-top: 12px; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--cailo-danger-light); }
.cm-refused-row { margin-top: 8px; }
.cm-refused-text { margin: 0; white-space: pre-line; overflow-wrap: anywhere; font: 400 14px/1.5 var(--cailo-font-family-body); color: var(--cailo-text-primary); }
.cm-refused-text mark { padding: 0 2px; border-radius: 3px; background: var(--cailo-danger-light); color: var(--cailo-danger-dark); }

/* ================================================================== staff (AdminJourney comments) */
.admin-comment-words { white-space: pre-line; overflow-wrap: anywhere; max-width: 520px; }
/* The comment a report email links to (?comment={ref}): marked by colour AND the Reported label. */
.admin-comment-reported > td { background: var(--cailo-warning-light); }
.admin-comment-ref { font-family: monospace; font-size: 12px; overflow-wrap: anywhere; }

@media (max-width: 599.98px) {
    .cm-card { padding: 16px; }
    .cm-intro { flex-direction: column; }
    .cm-people { padding: 4px 16px; }
}

/* Slice 4: people and follows (w12 to w19b). */
.cm-profile { display: flex; gap: 20px; align-items: flex-start; }
.cm-profile-avatar.mud-avatar { width: 88px; height: 88px; font-size: 28px; flex: none; }
.cm-h1 { font: 700 24px/1.25 var(--cailo-font-family-headings); color: var(--cailo-primary-dark); margin: 0; }
.cm-counts { font: 600 14px/1.4 var(--cailo-font-family-body); color: var(--cailo-text-primary); }
.cm-person-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.cm-one-line { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cm-person-actions { justify-content: flex-end; gap: 8px; }
.cm-picture-field { display: flex; gap: 14px; align-items: flex-start; }
.cm-byline-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; max-width: 960px; margin: 8px auto 0; padding: 0 16px; font: 400 14px/1.4 var(--cailo-font-family-body); color: var(--cailo-text-primary); }
.cm-links { display: flex; flex-direction: column; gap: 12px; }
.mud-avatar img { width: 100%; height: 100%; object-fit: cover; }

@media (max-width: 599.98px) {
    .cm-profile { flex-direction: column; }
    .cm-person { grid-template-columns: 40px minmax(0, 1fr); }
    .cm-person-actions { grid-column: 1 / -1; justify-content: flex-start; }
}
