/* list.css -- shared chrome for full-height list pages (events, organizations).
 *
 * The page itself does not scroll: the header/toolbar stay put and only
 * .table-wrap scrolls, so the sticky <thead> is always visible. Load this
 * after components.css and keep page-specific bits in the page's own
 * {% block extra_css %}.
 */

/* Full-height layout: table scrolls, not the page */
body { height: 100vh; overflow: hidden; }
.site-footer { display: none; }
.page-content { display: flex; flex-direction: column; overflow: hidden; min-height: 0; padding: 0; }

.list-layout {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    max-width: 1400px;
    margin: 0 auto;
    padding: 1.5rem;
    width: 100%;
    gap: 1rem;
}

/* ── Header ─────────────────────────────── */
.list-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-shrink: 0;
    flex-wrap: wrap;
    min-height: 2.4375rem;
}
.list-title {
    display: flex;
    align-items: center;
    gap: 0.625rem;
}
.list-title h1 {
    font-size: 1.375rem;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0;
    line-height: 1.2;
}
/* Create button: the "+" is an SVG, not a text/icon-font glyph — a glyph sits on
   the label's baseline and is pushed down by the font's own ascent/descent, which
   no amount of nudging fixes reliably. An SVG box centres exactly. */
.btn-create {
    gap: 0.4375rem;
    padding: 0.5rem 0.9375rem 0.5rem 0.8125rem;
    box-shadow: var(--shadow-sm);
}
.btn-create:hover { box-shadow: var(--shadow-md); }
.btn-create-plus {
    display: block;
    width: 0.9375rem;
    height: 0.9375rem;
    flex-shrink: 0;
}

.count-pill {
    padding: 0.125rem 0.5rem;
    border-radius: 100px;
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    font-size: 0.75rem;
    font-weight: 600;
}

/* ── Toolbar: search + segmented filter ─── */
.toolbar {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
    flex-shrink: 0;
}

.search-box {
    position: relative;
    flex: 1;
    min-width: 220px;
    max-width: 420px;
    display: flex;
    align-items: center;
}
.search-box .bi-search {
    position: absolute;
    left: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    display: block;
    font-size: 0.875rem;
    line-height: 1;
    color: var(--text-muted);
    pointer-events: none;
}
.search-box .bi-search::before { vertical-align: 0; display: block; }
.search-clear i { display: block; line-height: 1; }
.search-clear i::before { vertical-align: 0; display: block; }
.search-box input {
    width: 100%;
    padding: 0.5rem 2.25rem 0.5rem 2.125rem;
    font-size: 0.875rem;
    color: var(--text-primary);
    background: var(--bg-secondary);
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
}
.search-box input:focus {
    outline: none;
    background: var(--bg-primary);
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px var(--focus-ring);
}
.search-box input::-webkit-search-cancel-button,
.search-box input::-webkit-search-decoration { -webkit-appearance: none; appearance: none; }
.search-clear {
    position: absolute;
    right: 0.375rem;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 1.5rem;
    height: 1.5rem;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: var(--text-muted);
    font-size: 0.875rem;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}
.search-clear:hover { background: var(--bg-tertiary); color: var(--text-primary); }

.seg {
    display: flex;
    gap: 2px;
    padding: 3px;
    border-radius: var(--radius-md);
    background: var(--bg-secondary);
}
.seg a {
    padding: 0.3125rem 0.75rem;
    border-radius: 4px;
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-decoration: none;
    transition: background 0.15s, color 0.15s;
    white-space: nowrap;
}
.seg a:hover { color: var(--text-primary); }
.seg a.active {
    background: var(--bg-primary);
    color: var(--text-primary);
    box-shadow: var(--shadow-sm);
}

.active-search {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    font-size: 0.8125rem;
    color: var(--text-muted);
}
.active-search a { color: var(--accent-color); text-decoration: none; font-weight: 600; }
.active-search a:hover { text-decoration: underline; }

/* ── Table ──────────────────────────────── */
.table-wrap {
    flex: 1;
    overflow: auto;
    min-height: 0;
    border-radius: var(--radius-lg);
    background: var(--bg-secondary);
    box-shadow: var(--shadow-sm);
}

.list-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    table-layout: fixed;
}
.list-table thead th {
    padding: 0.625rem 0.875rem;
    font-size: 0.6875rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-secondary);
    background: var(--bg-tertiary);
    border-bottom: none;
    text-align: left;
    white-space: nowrap;
    position: sticky;
    top: 0;
    z-index: 10;
}
.list-table th:first-child, .list-table td:first-child { padding-left: 1.125rem; }
.list-table th:last-child, .list-table td:last-child { padding-right: 1.125rem; text-align: right; }

.list-table tbody tr { transition: background 0.1s; }
.list-table tbody tr:hover { background: var(--bg-tertiary); }
.list-table tbody tr:hover td { background: transparent; }
.list-table tbody tr:not(:last-child) td { border-bottom: 1px solid var(--bg-tertiary); }
.list-table td {
    padding: 0.75rem 0.875rem;
    font-size: 0.875rem;
    vertical-align: middle;
    border-bottom: none;
}
.list-table td[data-label="Domain"] { overflow: hidden; }

/* Cell primitives */
.cell-title {
    display: block;
    font-weight: 600;
    font-size: 0.9375rem;
    color: var(--text-primary);
    text-decoration: none;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.cell-title:hover { color: var(--accent-color); text-decoration: underline; }
.cell-sub {
    display: block;
    font-size: 0.8125rem;
    color: var(--text-muted);
    margin-top: 0.125rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.cell-strong {
    color: var(--text-primary);
    font-size: 0.8125rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display: block;
}
.cell-text {
    font-size: 0.8125rem;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display: block;
}
.cell-date {
    display: block;
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}
.cell-empty { color: var(--text-muted); }
.cell-more {
    font-size: 0.6875rem;
    font-weight: 600;
    color: var(--text-muted);
}
.cell-link {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    width: 100%;
    max-width: 100%;
    overflow: hidden;
    font-size: 0.8125rem;
    color: var(--accent-color);
    text-decoration: none;
}
.cell-link span {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.cell-link:hover { text-decoration: underline; }
.cell-link i { font-size: 0.75rem; flex-shrink: 0; opacity: 0.7; }
.status-stack { display: flex; flex-direction: column; align-items: flex-start; gap: 0.25rem; }

/* Row actions */
.row-actions {
    display: flex;
    gap: 0.375rem;
    justify-content: flex-end;
}
.row-actions .btn {
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
    white-space: nowrap;
}

/* Base .ic geometry lives in components.css (shared with the form icons) */
.cell-link .ic { width: 13px; height: 13px; stroke-width: 1.5; opacity: 0.75; }

/* ── Empty state: a quiet row inside the table ── */
.list-table tbody tr.empty-row:hover { background: transparent; }
.list-table tbody tr.empty-row > td {
    padding: 2.5rem 1rem;
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.875rem;
}
.empty-row .empty-msg { color: var(--text-secondary); }
.empty-row .empty-action {
    margin-left: 0.375rem;
    color: var(--accent-color);
    font-weight: 600;
    text-decoration: none;
    background: none;
    border: none;
    padding: 0;
    font-size: inherit;
    font-family: inherit;
    cursor: pointer;
}
.empty-row .empty-action:hover { text-decoration: underline; }

/* ── Responsive: rows become cards ──────── */
@media (max-width: 900px) {
    /* The full-height app shell is a desktop affordance: on a phone the nav +
       header + toolbar leave almost nothing for the list, and 100vh fights the
       browser chrome. Hand scrolling back to the page. */
    body { height: auto; overflow: visible; }
    .page-content { overflow: visible; }
    .list-layout {
        padding: 1rem;
        padding-left: max(1rem, env(safe-area-inset-left));
        padding-right: max(1rem, env(safe-area-inset-right));
        padding-bottom: max(1.5rem, env(safe-area-inset-bottom));
        gap: 0.875rem;
    }

    .table-wrap {
        flex: none;
        overflow: visible;
        background: transparent;
        box-shadow: none;
        border-radius: 0;
    }

    .list-table { table-layout: auto; }
    .list-table col { width: auto !important; }
    .list-table thead { display: none; }
    .list-table, .list-table tr, .list-table td { display: block; width: 100%; }

    .list-table tbody {
        display: flex;
        flex-direction: column;
        gap: 0.625rem;
    }

    .list-table tbody tr {
        padding: 0.875rem 1rem;
        background: var(--bg-secondary);
        border-radius: var(--radius-lg);
        box-shadow: var(--shadow-sm);
    }
    .list-table tbody tr:hover,
    .list-table tbody tr:not(:last-child) { background: var(--bg-secondary); border-bottom: none; }
    .list-table tbody tr:not(:last-child) td { border-bottom: none; }

    .list-table td,
    .list-table th:first-child, .list-table td:first-child,
    .list-table th:last-child, .list-table td:last-child {
        padding: 0.1875rem 0;
        text-align: left;
    }

    /* Label + value as an aligned key/value list rather than a run-on line */
    .list-table td[data-label]:not(:first-child) {
        display: flex;
        align-items: baseline;
        gap: 0.5rem;
    }
    .list-table { --label-w: 4.75rem; }
    .list-table td[data-label]:not(:first-child)::before {
        content: attr(data-label);
        flex: 0 0 var(--label-w);
        font-size: 0.6875rem;
        font-weight: 700;
        text-transform: uppercase;
        letter-spacing: 0.05em;
        color: var(--text-muted);
    }
    /* Flex items default to min-width:auto, which defeats the ellipsis and lets a
       long org name or domain push past the card edge. */
    .list-table td[data-label]:not(:first-child) > * { min-width: 0; }

    /* In a card there is no column to protect, so wrap rather than truncate --
       "Osvaldo Osorio" should not read "Osvaldo ...". Items keep their content
       width, so a pair like "$0.00  1 ticket" stays on one line and only a long
       value such as an email address drops to the next one. */
    .list-table td[data-label]:not(:first-child) { flex-wrap: wrap; }
    .list-table td[data-label]:not(:first-child) > * {
        white-space: normal;
        overflow: visible;
        overflow-wrap: anywhere;
    }
    .list-table td[data-label]:not(:first-child) > .cell-sub { margin-top: 0; }
    .list-table td.cell-hide-sm { display: none; }

    /* Card title gets to breathe and wrap instead of being clipped */
    .list-table td:first-child { padding-bottom: 0.5rem; }
    .list-table td:first-child .cell-title {
        white-space: normal;
        overflow: visible;
        font-size: 1rem;
        line-height: 1.3;
    }
    .list-table td:first-child .cell-sub {
        white-space: normal;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
        margin-top: 0.25rem;
    }

    .status-stack { flex-direction: row; flex-wrap: wrap; }

    /* Actions share the row in equal parts. With four or more the first one is
       the primary and gets a full row to itself, the rest split the next one.
       flex-basis 0 rather than auto so widths do not follow label length. */
    .row-actions {
        display: flex;
        flex-wrap: wrap;
        gap: 0.5rem;
        padding-top: 0.875rem;
    }
    .row-actions .btn {
        flex: 1 1 0;
        min-width: 0;
        min-height: 2.5rem;
        justify-content: center;
        padding: 0.5rem 0.75rem;
        font-size: 0.8125rem;
    }
    .row-actions .btn:first-child:nth-last-child(n+4) { flex-basis: 100%; }
    .row-actions .btn:first-child {
        background: var(--accent-color);
        color: #fff;
        border-color: transparent;
    }
    .row-actions .btn:first-child:hover {
        background: var(--accent-hover);
        border-color: transparent;
    }
    .row-actions .btn-ghost {
        background: var(--bg-tertiary);
        color: var(--text-primary);
    }
    .row-actions .btn-ghost:hover { background: var(--border-color); }

    /* 16px keeps iOS Safari from zooming the viewport on focus */
    .search-box { max-width: none; min-width: 0; flex-basis: 100%; }
    .search-box input {
        font-size: 1rem;
        padding-top: 0.625rem;
        padding-bottom: 0.625rem;
    }
    .search-clear { width: 1.75rem; height: 1.75rem; }

    /* Grow to fill the row when the segments fit (3 filters), scroll instead of
       squeezing when they do not (Orders has 5 and "Cancelled" ran off-screen). */
    .seg {
        flex: 1 1 100%;
        padding: 4px;
        overflow-x: auto;
        scrollbar-width: none;
    }
    .seg::-webkit-scrollbar { display: none; }
    .seg a {
        flex: 1 0 auto;
        text-align: center;
        padding: 0.4375rem 0.75rem;
        font-size: 0.875rem;
        line-height: 1.35;
    }
    .seg a.active {
        background: var(--accent-color);
        color: #fff;
        box-shadow: none;
    }

    /* Form modal becomes a bottom sheet */
    .list-layout .modal-overlay { padding: 0; align-items: flex-end; }
    .list-layout .modal-shell {
        width: 100% !important;
        max-width: 100% !important;
        max-height: 92dvh !important;
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    }
}

@media (max-width: 560px) {
    .list-head { gap: 0.75rem; }
    .list-title h1 { font-size: 1.25rem; }
    .list-table { --label-w: 4.25rem; }
}
