/* narratory-spa.css — shared chrome for Narratory product SPAs.
 * Served at https://narratory.com/static/narratory-spa.css.
 * Product-specific overrides live in each product's own /static/css/style.css,
 * which should be linked AFTER this file so overrides take effect.
 * Canonical standard: Narratory/SPA_dashboard_standards.md */

/* ---- Base alert (pre-placed [role=alert] inline alerts) ---- */
[role="alert"] {
    padding: 1rem;
    border-radius: var(--pico-border-radius);
    background: var(--pico-card-background-color);
    margin-top: 1rem;
}

/* ---- Header nav: two-line user block (email above, links below) ---- */
.nav-user {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.1rem;
}
.nav-user-email {
    font-size: 0.8rem;
    color: var(--pico-muted-color);
}
.nav-user-links {
    font-size: 0.8rem;
}
.nav-user-links a {
    color: var(--pico-primary);
}
.nav-sep {
    color: var(--pico-muted-color);
    margin: 0 0.2rem;
}

/* ---- Product switcher — pill overlays a ghost placeholder ---- */
.product-switcher-wrap {
    position: relative;
    display: inline-block;
}
.product-switcher-ghost {
    display: inline-block;
    visibility: hidden;
    border: 1px solid transparent;
    border-radius: var(--pico-border-radius);
    padding: 0.15rem 0.5rem;
    white-space: nowrap;
}
.product-switcher {
    position: absolute;
    top: 0;
    left: 0;
    border: 1px solid var(--pico-muted-border-color);
    border-radius: var(--pico-border-radius);
    padding: 0.15rem 0.5rem;
    cursor: pointer;
    background: var(--pico-background-color, #fff);
    z-index: 10;
}
.product-switcher:hover,
.product-switcher.open {
    border-color: var(--pico-primary);
    z-index: 100;
}
.product-switcher-current {
    display: block;
    white-space: nowrap;
}
.product-switcher-link {
    display: none;
    text-decoration: none;
    font-size: inherit;
    color: var(--pico-color);
    white-space: nowrap;
}
.product-switcher-link:hover {
    color: var(--pico-primary);
}
.product-switcher.open .product-switcher-link {
    display: block;
    margin-top: 0.25rem;
    padding-top: 0.25rem;
    border-top: 1px solid var(--pico-muted-border-color);
}

/* ---- Mobile: stack header nav vertically, left-aligned ---- */
@media (max-width: 576px) {
    body > header {
        padding-block: 0.75rem;
    }
    header nav {
        flex-direction: column;
        align-items: flex-start;
    }
    header nav ul,
    header nav ul:first-of-type,
    header nav ul:last-of-type {
        padding: 0;
        margin: 0;
    }
    header nav li {
        padding: 0.25rem 0;
    }
    .nav-user {
        align-items: flex-start;
    }
}

/* ---- Admin dashboard layout (sidebar + panels) ---- */
.admin-layout {
    display: flex;
    gap: 2rem;
    align-items: flex-start;
}

.admin-sidebar {
    width: 180px;
    flex-shrink: 0;
    position: sticky;
    top: 1rem;
}

.admin-sidebar nav a {
    display: block;
    padding: 0.5rem 0.75rem;
    text-decoration: none;
    border-radius: var(--pico-border-radius);
    margin-bottom: 0.25rem;
    color: var(--pico-color);
}

.admin-sidebar nav a:hover {
    background: var(--pico-card-background-color);
}

.admin-sidebar-header {
    display: block;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #999;
    padding: 0.6rem 0.75rem 0.2rem;
    margin-top: 0.25rem;
}

.admin-sidebar nav a.active {
    background: var(--pico-primary-background);
    color: var(--pico-primary-inverse);
}

.admin-content {
    flex: 1;
    min-width: 0;
}

.admin-content > .admin-panel {
    display: none !important;
}

.admin-content > .admin-panel.active {
    display: block !important;
}

/* ---- Responsive: stack sidebar above content on narrow screens ---- */
@media (max-width: 768px) {
    .admin-layout {
        flex-direction: column;
    }
    .admin-sidebar {
        width: 100%;
        position: static;
    }
    .admin-sidebar nav {
        display: grid !important;
        grid-template-columns: repeat(3, 1fr);
        gap: 0.35rem;
    }
    .admin-sidebar nav a {
        text-align: center;
        white-space: nowrap;
        padding: 0.4rem 0.65rem;
        font-size: 0.85rem;
        border: 1px solid var(--pico-muted-border-color);
    }
    .admin-sidebar nav a.active {
        border-color: var(--pico-primary-background);
    }
    .admin-sidebar-header {
        display: none;
    }
}

/* ---- Landing page cards (three-hero grid) ---- */
.landing-card {
    border: 1px solid var(--pico-muted-border-color);
    border-radius: var(--pico-border-radius);
    padding: 1.5rem;
    text-align: center;
}

.landing-card svg {
    display: block;
    margin: 0 auto 0.75rem;
}

.landing-card strong {
    display: block;
    font-size: 1.1rem;
    margin-bottom: 0.5rem;
}

.landing-card p {
    font-size: 0.95rem;
    color: var(--pico-muted-color);
    margin: 0;
}

.landing-section-heading {
    text-align: center;
    font-size: 1.2rem;
    font-weight: 600;
    margin: 2.5rem 0 1.5rem;
    color: var(--pico-muted-color);
}

.landing-tagline {
    text-align: center;
    font-size: 1.15rem;
    color: var(--pico-muted-color);
    margin: 0.5rem 0 2rem;
}

/* ---- Entity switcher (`<select>` + adjacent action buttons at panel top) ----
 * Pattern: panels that manage one of many instances of an entity
 * (newsletters, events, groups) lead with a dropdown to pick which one
 * is being configured, optionally followed by "New X" / "Delete" buttons.
 * Used by Convene's events-panel and Collate's newsletter switcher.
 * Documented in SPA_dashboard_standards.md §21.
 */
.entity-switcher-bar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1rem;
}
.entity-switcher {
    flex: 1;
    min-width: 0;
    margin: 0;
    padding: 0.2rem 0.4rem;
    font-weight: bold;
}
.entity-switcher-actions {
    display: flex;
    gap: 0.4rem;
    flex-shrink: 0;
}
/* Buttons inside the actions slot auto-size to match .btn-sm (see
 * design_standards.md §2). Applying this via the parent instead of
 * requiring products to add .btn-sm keeps the switcher visually
 * balanced against the compact .entity-switcher <select> and
 * prevents per-product drift.
 *
 * margin: 0 strips Pico's default [type=button] margin-bottom, which
 * otherwise enlarges the button's flex margin box and vertically
 * misaligns it against the .entity-switcher <select> under the row's
 * align-items: center. */
.entity-switcher-actions button,
.entity-switcher-actions a[role="button"] {
    margin: 0;
    padding: 0.3rem 0.75rem;
    font-size: 0.8rem;
}

/* ---- Sub-navigation within a panel ----
 * Tile-style horizontal bar that hosts either:
 *   - sub-tabs: links carrying data-sub-panel="..." that toggle .sub-panel
 *     siblings (wired by narratory.subNavInit)
 *   - action buttons: <button> elements that perform side-effecting actions
 *     (no data-sub-panel; click handlers stay product-local)
 *
 * Visual language is identical to the collapsed-mobile main menu (see
 * @media block below) — bordered tile buttons in a responsive grid.
 * Documented in SPA_dashboard_standards.md §20.
 */
.sub-nav {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
    gap: 0.35rem;
    margin: 1rem 0;
}
.sub-nav a,
.sub-nav button {
    display: block;
    width: 100%;
    text-align: center;
    white-space: nowrap;
    padding: 0.4rem 0.65rem;
    font-size: 0.85rem;
    text-decoration: none;
    color: var(--pico-muted-color);
    background: transparent;
    border: 1px solid var(--pico-muted-border-color);
    border-radius: var(--pico-border-radius);
    cursor: pointer;
    transition: color 0.15s, border-color 0.15s;
    /* Pico's <button> defaults shove margin-bottom; reset for grid layout */
    margin: 0;
}
.sub-nav a:hover,
.sub-nav button:hover:not(:disabled),
.sub-nav button:focus:not(:disabled) {
    color: var(--pico-color);
    background: transparent;
    border-color: var(--pico-color);
    box-shadow: none;
}
.sub-nav a.active,
.sub-nav button.active {
    border-color: var(--pico-primary);
    color: var(--pico-primary);
    font-weight: 600;
}
.sub-nav button:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.sub-panel {
    display: none !important;
}
.sub-panel.active {
    display: block !important;
}

/* Sub-nav narrows to fixed 3 columns on small screens — matches the
 * collapsed-mobile main menu so the visual rhythm is consistent.
 */
@media (max-width: 768px) {
    .sub-nav {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* =========================================================
 * Design-system primitives — see Narratory/design_standards.md
 * ========================================================= */

/* ---- Status-color tokens (semantic variants) ----
 * Five semantic buckets every product's status vocabulary maps into.
 * Use via <span class="badge" data-variant="success">Delivered</span>,
 * or via a product-local status→variant CSS table for legacy
 * domain-specific data-status names. See design_standards.md §11.
 */
:root {
    --status-success:  #059669;
    --status-info:     #2563eb;
    --status-warning:  #d97706;
    --status-danger:   #dc2626;
    --status-neutral:  #6b7280;
}

/* ---- Badge (status pill) ---- */
.badge {
    display: inline-block;
    padding: 0.15em 0.5em;
    font-size: 0.75rem;
    font-weight: 600;
    border-radius: 3px;
    background: var(--status-neutral);
    color: #fff;
}
.badge[data-variant="success"]  { background: var(--status-success); }
.badge[data-variant="info"]     { background: var(--status-info); }
.badge[data-variant="warning"]  { background: var(--status-warning); }
.badge[data-variant="danger"]   { background: var(--status-danger); }
.badge[data-variant="neutral"]  { background: var(--status-neutral); }


/* ---- Buttons — 3 sizes (default via Pico, .btn-sm, .btn-xs) ----
 * See design_standards.md §2. Applies to both <button> and <a role="button">.
 * Does not touch color/variant — combine with Pico's `outline`,
 * `outline secondary`, `contrast` classes as needed.
 */
.btn-sm {
    padding: 0.3rem 0.75rem;
    font-size: 0.8rem;
}
.btn-xs {
    padding: 0.15rem 0.5rem;
    font-size: 0.75rem;
    /* Pico applies a default margin-bottom to <button> that disrupts
     * inline table-row actions; reset it at the xs size where rows
     * routinely need tight vertical rhythm. */
    margin: 0;
}
a.btn-sm,
a.btn-xs {
    /* Links-as-buttons need text-decoration off and Pico's outline
     * border to match native buttons at these sizes. */
    text-decoration: none;
}

/* ---- Help text (muted captions, hints below form fields) ----
 * Sets font-size AND color. For inline muted text inside <small>, <span>,
 * or a line of body copy where you just want the color de-emphasis and
 * NOT a font-size change, use the .muted utility below instead.
 */
.help-text {
    font-size: 0.8rem;
    color: var(--pico-muted-color);
    line-height: 1.4;
}

/* ---- Muted color only (no font-size change) ---- */
.muted {
    color: var(--pico-muted-color);
}

/* ---- Empty state (list panels with no items yet) ---- */
.empty-state {
    padding: 2rem 0;
    text-align: center;
    color: var(--pico-muted-color);
}
.empty-state > p:first-child {
    margin-bottom: 1rem;
}

/* ---- Table default spacing (tighter than Pico default) ----
 * Global — applies to every <table> on every product. Compact variant
 * below for high-row-count auxiliary tables.
 */
table td,
table th {
    padding: 0.5rem 0.75rem;
}
.table-compact td,
.table-compact th {
    padding: 0.25rem 0.5rem;
    font-size: 0.85rem;
}

/* ---- Dialog default + wide variant ---- */
dialog article {
    max-width: 500px;
}
dialog.dialog-wide article {
    max-width: 800px;
}

/* ---- SortableJS ghost placeholder (drag-and-drop lists) ---- */
.sortable-ghost {
    opacity: 0.4;
}

/* ---- Sort card shell — horizontal card for SortableJS lists ----
 * Three-zone row: drag handle + body + actions. The canonical simple
 * pattern — products extend with their own body content (titles, tags,
 * metadata). For expandable/collapsible cards (Collate's work-card
 * uses <details>), design a product-local extension; this shell is for
 * the single-row case.
 * See design_standards.md §13.
 */
.sort-card {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    background: var(--pico-card-background-color);
    padding: 0.75rem;
    border-radius: var(--pico-border-radius);
    margin-bottom: 0.5rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}
.sort-card:last-child {
    margin-bottom: 0;
}

.sort-card-handle {
    cursor: grab;
    color: var(--pico-muted-color);
    font-size: 1.2rem;
    line-height: 1;
    user-select: none;
    flex-shrink: 0;
}
.sort-card-handle:hover {
    color: var(--pico-color);
}

.sort-card-body {
    flex: 1;
    min-width: 0;
}

.sort-card-actions {
    display: flex;
    gap: 0.25rem;
    flex-shrink: 0;
}

/* ---- Inline row — flex container for aligned controls ----
 * Horizontal strip of <input>/<select>/<button>/<label>/<span> aligned on
 * a baseline, with no margin-bottom cascading from Pico's form element
 * defaults. Replaces the brittle attribute-selector hack in Convene's
 * local style.css. See design_standards.md §12.
 *
 * Variants: add .inline-row--end (align-items: flex-end) for rows whose
 * controls have labels above them, or .inline-row--stretch (stretch)
 * for fill-height rows.
 */
.inline-row {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    flex-wrap: wrap;
}
.inline-row--end {
    align-items: flex-end;
}
.inline-row--stretch {
    align-items: stretch;
}
.inline-row > input,
.inline-row > select,
.inline-row > button,
.inline-row > label,
.inline-row > [role="button"] {
    margin-bottom: 0;
}

/* ---- Toast container + toast (narratory.showAlert) ---- */
.narratory-toast-stack {
    position: fixed;
    bottom: 1.25rem;
    right: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    z-index: 10000;
    pointer-events: none;
    max-width: min(420px, calc(100vw - 2.5rem));
}
.narratory-toast {
    pointer-events: auto;
    padding: 0.75rem 1rem;
    border-radius: var(--pico-border-radius);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
    font-size: 0.9rem;
    line-height: 1.35;
    background: #333;
    color: #fff;
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 180ms ease-out, transform 180ms ease-out;
}
.narratory-toast.visible {
    opacity: 1;
    transform: translateY(0);
}
.narratory-toast.success {
    background: #1f7a3a;
}
.narratory-toast.error {
    background: #9a2a2a;
}
.narratory-toast.info {
    background: #2a5a9a;
}
