/* Shared Portal UI components — docs/design/PORTAL_UI_STANDARD.md.
 *
 * ModalShell (and ConfirmDialog / HelpModal on it), SidePanel, HelpTip, FormField and Tip. The look is
 * lifted from the approved mockups (plan §U6, portal-ux-mockups: M3, M5, M8, M10). Phones are below
 * 768px, one breakpoint for all of it: @media (max-width: 767.98px). There, a modal is a bottom sheet
 * with full-width 44px buttons, a side panel is a full-screen sheet with a sticky footer, and an ⓘ
 * popover is a bottom sheet. Tooltips do not show on phones at all — they never hold information that
 * is not somewhere else. PortalUiStylesheetTests reads this file. */

/* ── One z-index scale ──────────────────────────────────────────────────────────────────────────────
 * Bootstrap's own modal (1055), popover (1070) and tooltip (1080) sit inside this scale, so a legacy
 * Bootstrap modal and a new one never fight. A confirmation opened from a side panel is above it; an ⓘ
 * popover inside either is above both; toasts stay on top of everything. */
:root {
    --z-dropdown:  1000;
    --z-panel:     1045;
    --z-modal:     1060;
    --z-popover:   1070;
    --z-tooltip:   1075;
    --z-toast:     1080;

    /* Colours the shared components need that the house palette (app.css) does not name. Every colour
       in this file is a token: raw values live here and nowhere below (PortalUiStylesheetTests). */
    --cc-scrim:          rgba(17, 26, 20, .5);
    --cc-shadow-modal:   0 24px 60px rgba(17, 26, 20, .3);
    --cc-shadow-panel:   -16px 0 40px rgba(17, 26, 20, .22);
    --cc-shadow-footer:  0 -6px 16px rgba(17, 26, 20, .05);
    --cc-shadow-pop:     0 12px 32px rgba(17, 26, 20, .16), 0 2px 6px rgba(17, 26, 20, .06);
    --cc-shadow-sheet:   0 -12px 36px rgba(17, 26, 20, .25);
    --cc-ring-invalid:   0 0 0 3px rgba(198, 40, 40, .13);
    --cc-help-tint:      #e4eee7;
    --cc-grab-handle:    #d7d0c4;
    --cc-tip-bg:         var(--text-primary);
    --cc-tip-fg:         var(--text-inverse);
    --cc-dg-struck:      #a9b5ac;
    --cc-dg-on-green:    var(--text-inverse);
    --cc-dg-on-green-2:  #cfe3d5;

    /* The space Bootstrap's .form-select chevron takes at the right of a select. TODO(ux-nav-pickers):
       that stream owns the global select padding fix (plan U2 item 3); when it lands, point this at its
       value so an invalid select's error icon keeps clear of the chevron. */
    --cc-select-chevron-space: 2.25rem;
    --cc-panel-width:  640px;
    --cc-sheet-radius: 14px;
    --cc-tap:          44px;
}

/* ── Things outside the scale ──────────────────────────────────────────────────────────────────────
 * The Blazor reconnect overlay (App.razor, 20000) is meant to cover everything, overlays included.
 * The floating chat bubble (ChatPanel.razor, 9999) is not: it would sit on a side panel's Save button,
 * cover a bottom sheet's buttons, and be a clickable way out of a modal's focus trap. So it is hidden
 * while any overlay holds the page lock — js/modal-scroll.js puts .cc-overlay-open on <html>. */
:root.cc-overlay-open .cc-chat-root { visibility: hidden; }

/* ── Focus guards (the focus trap's two ends) ──────────────────────────────────────────────────── */
.cc-focus-guard { position: fixed; width: 1px; height: 1px; overflow: hidden; outline: 0; opacity: 0; }

/* ── Close button (✕) shared by modal, panel and popover headers ───────────────────────────────── */
.cc-x {
    margin-left: auto; flex: 0 0 auto;
    width: 36px; height: 36px; display: grid; place-items: center;
    border: 0; background: none; border-radius: var(--radius-md);
    color: var(--text-muted); font-size: 18px; line-height: 1;
}
.cc-x:hover { background: var(--content-bg); color: var(--text-primary); }
.cc-x:focus-visible { outline: 0; box-shadow: var(--shadow-focus); }

/* ── ModalShell: centred modal ≥768px, bottom sheet below ──────────────────────────────────────── */
.cc-modal-wrap {
    position: fixed; inset: 0; z-index: var(--z-modal);
    display: flex; align-items: center; justify-content: center;
    padding: 16px; background: var(--cc-scrim);
    overflow-y: auto;
}
.cc-modal {
    width: min(540px, 100%);
    max-height: calc(100vh - 32px);
    display: flex; flex-direction: column;
    background: var(--card-bg); color: var(--text-primary);
    border-radius: var(--radius-lg);
    box-shadow: var(--cc-shadow-modal);
    outline: 0;
}
.cc-modal--lg { width: min(640px, 100%); }
.cc-modal-h { display: flex; gap: 14px; align-items: flex-start; padding: 20px 22px 10px; }
.cc-modal-h .cc-x { margin: -6px -8px 0 auto; }
.cc-modal-htext { min-width: 0; }
.cc-modal-title { font-size: 17px; font-weight: 700; margin: 1px 0 3px; line-height: 1.3; }
.cc-modal-sub { font-size: 12.5px; color: var(--text-secondary); }
.cc-modal-ic {
    width: 40px; height: 40px; border-radius: 50%; flex: 0 0 auto;
    display: grid; place-items: center; font-size: 18px;
    background: var(--warning-light); color: var(--warning-text);
}
.cc-modal-ic.cc-tone-danger  { background: var(--danger-light); color: var(--danger-text); }
.cc-modal-ic.cc-tone-help    { background: var(--cc-help-tint); color: var(--cc-green); }
.cc-modal-ic.cc-tone-neutral { background: var(--content-bg); color: var(--text-secondary); }
.cc-modal-b { padding: 4px 22px 14px; overflow-y: auto; font-size: 13.5px; line-height: 1.55; }
.cc-modal-b > p:last-child { margin-bottom: 0; }
.cc-modal-f {
    display: flex; justify-content: flex-end; align-items: center; gap: 8px;
    padding: 14px 22px; background: var(--content-bg);
    border-top: 1px solid var(--border);
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}
.cc-modal-f .btn { min-height: 38px; padding-left: 18px; padding-right: 18px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.cc-modal-f .cc-modal-f-note { margin-right: auto; font-size: 12.5px; color: var(--text-muted); }
/* The dismissing button is white on the tinted footer (mockups M3, M4), not transparent. */
.cc-modal-f .btn-secondary, .cc-panel-f .btn-secondary { background: var(--card-bg); }
.cc-modal-f .btn-secondary:hover, .cc-panel-f .btn-secondary:hover { background: var(--border); }

/* ConfirmDialog: the consequence list (money / the box / the member / undo). */
.cc-confirm-msg { margin: 0; }
.cc-fx { display: grid; grid-template-columns: 30px 1fr; gap: 8px; padding: 10px 0; border-top: 1px solid var(--border); }
.cc-fx-ic {
    width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center;
    background: var(--content-bg); border: 1px solid var(--border); color: var(--cc-green-md); font-size: 14px;
}
.cc-fx-k { display: block; font-size: 10.5px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--text-muted); margin-bottom: 1px; }
.cc-fx-v { font-size: 13.5px; color: var(--text-primary); line-height: 1.45; }

/* ── SidePanel: 640px from the right ≥768px, full-screen sheet below ───────────────────────────── */
.cc-panel-wrap { position: fixed; inset: 0; z-index: var(--z-panel); background: var(--cc-scrim); }
.cc-panel {
    position: absolute; top: 0; right: 0; bottom: 0;
    width: min(var(--cc-panel-width), 100%);
    display: flex; flex-direction: column;
    background: var(--card-bg); color: var(--text-primary);
    box-shadow: var(--cc-shadow-panel);
    outline: 0;
}
.cc-panel-h { display: flex; align-items: flex-start; gap: 12px; padding: 18px 24px 16px; border-bottom: 1px solid var(--border); flex: 0 0 auto; }
.cc-panel-eb { font-size: 10.5px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--text-muted); margin-bottom: 2px; }
.cc-panel-title { margin: 0; font-size: 19px; font-weight: 700; line-height: 1.3; }
.cc-panel-sub { font-size: 13px; color: var(--text-secondary); margin-top: 3px; }
.cc-panel-b { flex: 1 1 auto; overflow-y: auto; padding: 20px 24px 8px; overscroll-behavior: contain; }
.cc-panel-sum { flex: 0 0 auto; margin: 0 24px 16px; }
.cc-panel-f {
    flex: 0 0 auto; display: flex; align-items: center; gap: 8px;
    padding: 14px 24px; border-top: 1px solid var(--border);
    background: var(--card-bg); box-shadow: var(--cc-shadow-footer);
}
.cc-panel-f .cc-panel-hint { margin-right: auto; font-size: 12.5px; color: var(--text-muted); }
.cc-panel-f .cc-panel-cancel { margin-left: auto; }
.cc-panel-f .cc-panel-hint + .cc-panel-cancel { margin-left: 0; }
.cc-panel-f .btn { min-height: 38px; padding-left: 18px; padding-right: 18px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }

/* A section inside a panel: small caps heading with a rule under it (mockup M5 "THE SHARE"). */
.cc-sec { margin: 0 0 22px; }
.cc-sec-t {
    display: flex; align-items: center; gap: 2px;
    font-size: 10.5px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--text-secondary);
    padding-bottom: 8px; margin: 0 0 14px; border-bottom: 1px solid var(--border);
}

/* ── FormField ─────────────────────────────────────────────────────────────────────────────────── */
.cc-ff { margin-bottom: 16px; }
.cc-ff-lbl { display: flex; align-items: center; gap: 2px; min-height: 22px; margin-bottom: 6px; }
.cc-ff-lbl > label { font-size: 13px; font-weight: 600; color: var(--text-primary); margin: 0; }
.cc-ff-req { color: var(--danger); margin-left: 2px; }
.cc-ff-opt { font-weight: 400; color: var(--text-muted); margin-left: 4px; }
.cc-ff-ctl { position: relative; }
.cc-ff .form-control, .cc-ff .form-select { min-height: 38px; }
.cc-ff-hint { font-size: 12px; color: var(--text-muted); margin-top: 5px; }
.cc-ff-bad-ic { display: none; }
.cc-ff.is-invalid .cc-ff-lbl > label { color: var(--danger-text); }
.cc-ff.is-invalid .form-control,
.cc-ff.is-invalid .form-select {
    border-color: var(--danger);
    box-shadow: var(--cc-ring-invalid);
    padding-right: 36px;
}
.cc-ff.is-invalid .form-select { padding-right: calc(var(--cc-select-chevron-space) + 1.5rem); }
.cc-ff.is-invalid .cc-ff-bad-ic {
    display: block; position: absolute; right: 11px; top: 50%; transform: translateY(-50%);
    color: var(--danger); font-size: 15px; pointer-events: none;
}
.cc-ff.is-invalid .cc-ff-ctl:has(.form-select) .cc-ff-bad-ic { right: calc(var(--cc-select-chevron-space) + .15rem); }
.cc-ff-err {
    display: flex; gap: 6px; align-items: flex-start; margin-top: 6px;
    font-size: 12.5px; font-weight: 600; line-height: 1.4; color: var(--danger-text);
}
.cc-ff-err i { margin-top: 1px; }
.cc-ff-err a { color: var(--danger-text); text-decoration: underline; }

/* ── HelpTip (ⓘ): popover ≥768px, bottom sheet below ───────────────────────────────────────────── */
.cc-help { position: relative; display: inline-flex; align-items: center; vertical-align: middle; }
.cc-hi {
    display: inline-grid; place-items: center; flex: 0 0 auto;
    position: relative;
    width: 24px; height: 24px; padding: 0; margin: 0 0 0 2px;   /* WCAG 2.5.8: never below 24px */
    border: 0; border-radius: 50%; background: none;
    color: var(--text-muted); font-size: 14px; line-height: 1; cursor: pointer;
}
.cc-hi:hover, .cc-hi.is-open { color: var(--accent-strong); background: var(--accent-light); }
.cc-hi:focus-visible { outline: 0; box-shadow: var(--shadow-focus); }
/* The hit area can be larger than the drawn circle; on a phone it is (see the phone block). */
.cc-hi::after { content: ''; position: absolute; inset: 0; border-radius: 50%; }
/* A transparent layer that catches the click outside an open popover (and dims the page on a phone). */
.cc-help-scrim { position: fixed; inset: 0; z-index: var(--z-popover); background: transparent; }
.cc-pop {
    position: absolute; z-index: var(--z-popover);
    top: calc(100% + 10px); left: -16px;
    width: 300px; max-width: calc(100vw - 24px);
    display: block; padding: 12px 14px;
    background: var(--card-bg); color: var(--text-primary);
    border: 1px solid var(--border); border-radius: var(--radius-lg);
    box-shadow: var(--cc-shadow-pop);
    font: 400 13px/1.5 var(--font-sans);
    text-align: left; text-transform: none; letter-spacing: normal; white-space: normal;
    outline: 0;
}
.cc-pop::before {
    content: ''; position: absolute; top: -6px; left: var(--cc-arrow-x, 20px);
    width: 11px; height: 11px; background: var(--card-bg);
    border-left: 1px solid var(--border); border-top: 1px solid var(--border);
    transform: rotate(45deg);
}
.cc-pop.cc-pop--end { left: auto; right: -16px; }
.cc-pop.cc-pop--end::before { left: auto; right: 20px; }
.cc-pop.cc-pop--up { top: auto; bottom: calc(100% + 10px); }
.cc-pop.cc-pop--up::before { top: auto; bottom: -6px; transform: rotate(225deg); }
.cc-pop-t { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; font-weight: 700; font-size: 13.5px; margin-bottom: 3px; }
.cc-pop-x {
    display: inline-grid; place-items: center; min-width: 24px; min-height: 24px;
    border: 0; background: none; color: var(--text-muted); font-size: 17px; line-height: 1; padding: 0; margin: -4px -6px 0 0;
}
.cc-pop-b { display: block; }
.cc-pop-b .cc-p { display: block; margin: 0 0 6px; }
.cc-pop-b .cc-p:last-child { margin-bottom: 0; }
.cc-pop-more {
    display: inline-flex; align-items: center; gap: 4px; margin-top: 8px; padding: 0;
    border: 0; background: none; font-weight: 600; font-size: 13px; color: var(--accent-strong);
}
.cc-pop-more:hover { text-decoration: underline; }

/* HelpModal body */
.cc-help-fig { margin: 0 0 14px; padding: 12px 10px 8px; background: var(--content-bg); border: 1px solid var(--border); border-radius: var(--radius-md); }
.cc-help-fig svg { display: block; width: 100%; height: auto; }
.cc-help-fig figcaption { text-align: center; font-size: 12px; color: var(--text-muted); margin-top: 6px; }
.cc-help-body p { margin: 0 0 10px; }
.cc-help-body ul { padding-left: 18px; margin: 0 0 8px; }
.cc-help-body li { margin-bottom: 4px; }

/* Diagram classes (inline SVG in HelpModal) — house tokens, so the diagram follows the theme. */
.cc-dg-t  { font: 600 13px var(--font-sans); fill: var(--text-secondary); }
.cc-dg-n  { font: 700 22px var(--font-sans); fill: var(--text-primary); }
.cc-dg-s  { font: 500 11.5px var(--font-sans); fill: var(--text-muted); }
.cc-dg-op { font: 700 26px var(--font-sans); fill: var(--text-muted); }
.cc-dg-box    { fill: var(--card-bg); stroke: var(--border); }
.cc-dg-add    { fill: var(--accent-light); stroke: var(--accent); }
.cc-dg-own    { fill: var(--card-bg); stroke: var(--cc-green-md); }
.cc-dg-gone   { fill: var(--card-bg); stroke: var(--border); stroke-dasharray: 4 3; }
.cc-dg-gone-n { font: 700 22px var(--font-sans); fill: var(--cc-dg-struck); text-decoration: line-through; }
.cc-dg-res    { fill: var(--cc-green); }
.cc-dg-res-n  { font: 700 22px var(--font-sans); fill: var(--cc-dg-on-green); }
.cc-dg-res-s  { font: 500 11.5px var(--font-sans); fill: var(--cc-dg-on-green-2); }

/* ── Tip: hover/focus tooltip on icon-only and state-changing buttons (desktop only) ───────────── */
.cc-tip-host { position: relative; display: inline-flex; }
.cc-tip {
    position: absolute; z-index: var(--z-tooltip);
    bottom: calc(100% + 9px); left: 50%; transform: translateX(-50%);
    width: max-content; max-width: 250px; padding: 7px 10px;
    background: var(--cc-tip-bg); color: var(--cc-tip-fg); border-radius: var(--radius-md); box-shadow: var(--shadow-md);
    font: 500 12px/1.45 var(--font-sans); text-align: left; white-space: normal;
    text-transform: none; letter-spacing: normal;
    visibility: hidden; opacity: 0; transition: opacity .12s ease;
    pointer-events: none;
}
.cc-tip::after {
    content: ''; position: absolute; bottom: -5px; left: 50%; margin-left: -5px;
    border: 5px solid transparent; border-bottom: 0; border-top-color: var(--cc-tip-bg);
}
.cc-tip--start { left: 0; transform: none; }
.cc-tip--start::after { left: 16px; }
.cc-tip--end { left: auto; right: 0; transform: none; }
.cc-tip--end::after { left: auto; right: 11px; }
.cc-tip-host:hover > .cc-tip,
.cc-tip-host:has(:focus-visible) > .cc-tip { visibility: visible; opacity: 1; transition-delay: .35s; }
.cc-tip-host:has(:focus-visible) > .cc-tip { transition-delay: 0s; }
:root.cc-tips-off .cc-tip { visibility: hidden !important; opacity: 0 !important; }
@media (hover: none) { .cc-tip { display: none; } }

/* ── Phones: below 768px ───────────────────────────────────────────────────────────────────────── */
@media (max-width: 767.98px) {
    /* A modal is a bottom sheet: full width, grab handle, buttons stacked full width at 44px with the
       confirming verb on top. The consequence text is never cut. */
    .cc-modal-wrap { align-items: flex-end; padding: 0; }
    .cc-modal, .cc-modal--lg {
        width: 100%; max-height: 94vh;
        border-radius: var(--cc-sheet-radius) var(--cc-sheet-radius) 0 0;
    }
    .cc-modal::before {
        content: ''; display: block; flex: 0 0 auto;
        width: 40px; height: 4px; border-radius: 2px; background: var(--cc-grab-handle); margin: 8px auto 0;
    }
    .cc-modal-h { padding: 16px 16px 8px; }
    .cc-modal-b { padding: 4px 16px 12px; font-size: 14px; }
    .cc-fx-v { font-size: 14px; }
    .cc-modal-f {
        flex-direction: column-reverse; align-items: stretch;
        padding: 12px 16px 16px; border-radius: 0;
    }
    .cc-modal-f .btn { width: 100%; min-height: var(--cc-tap); font-size: 14px; }
    .cc-modal-f .cc-modal-f-note { margin: 0; text-align: center; }

    /* A side panel is a full-screen sheet with the page hidden behind it and a sticky footer. */
    .cc-panel-wrap { background: transparent; }
    .cc-panel { width: 100%; box-shadow: none; }
    .cc-panel-h { padding: 14px 16px 12px; }
    .cc-panel-b { padding: 16px 16px 4px; }
    .cc-panel-sum { margin: 0 16px 14px; }
    .cc-panel-f { padding: 12px 16px; }
    .cc-panel-f .cc-panel-hint { display: none; }
    .cc-panel-f .btn { flex: 1 1 0; min-height: var(--cc-tap); font-size: 14px; }

    /* An ⓘ popover is a bottom sheet, so it never covers the field it explains. */
    .cc-help-scrim { background: var(--cc-scrim); }
    .cc-pop, .cc-pop.cc-pop--end, .cc-pop.cc-pop--up {
        position: fixed; top: auto; left: 0; right: 0; bottom: 0;
        width: auto; max-width: none; max-height: 80vh; overflow-y: auto;
        border: 0; border-radius: var(--cc-sheet-radius) var(--cc-sheet-radius) 0 0;
        box-shadow: var(--cc-shadow-sheet);
        padding: 8px 18px 20px; font-size: 14.5px; line-height: 1.55;
    }
    .cc-pop::before, .cc-pop.cc-pop--end::before, .cc-pop.cc-pop--up::before {
        position: static; display: block; width: 40px; height: 4px; margin: 0 auto 12px;
        border: 0; border-radius: 2px; background: var(--cc-grab-handle); transform: none;
    }
    .cc-pop-t { font-size: 17px; margin-bottom: 6px; }
    .cc-pop-x { font-size: 24px; min-width: var(--cc-tap); min-height: var(--cc-tap); margin: -10px -12px 0 0; }

    /* 44px targets (plan U7 rule 8). The ⓘ keeps its small drawn circle and gets an invisible 44px hit
       area; the ✕ on every modal, panel and sheet is 44px outright. */
    .cc-hi::after { inset: -10px; }
    .cc-x { width: var(--cc-tap); height: var(--cc-tap); }
    .cc-pop-more {
        display: flex; width: 100%; justify-content: center; min-height: var(--cc-tap);
        margin-top: 16px; border: 1px solid var(--border); border-radius: var(--radius-md); font-size: 14px;
    }

    /* Tooltips never show on a phone. */
    .cc-tip { display: none; }
}
