/*
 * Markdown theme — a self-contained stylesheet (no @imports, no dependency on
 * base/components/responsive-theme/enhancements/rectilinear).
 *
 * The page should read like a rendered Markdown document: one heading, a date
 * heading per day, a plain table of shows, links for actions. Anything that is
 * not information is left out. Palette: warm paper and ink with a single pine-green accent; dark mode is the
 * same document on warm charcoal.
 */

:root {
    --bg: #fbfaf6;
    --fg: #1d1b18;
    --muted: #6a645b;
    --border: #ddd8cd;
    --subtle: #f2efe8;
    --link: #0f6b5c;
    --mark: #fde68a;
    --star: #b7791f;
    --warn: #8a5a00;
    --danger: #b42318;
    --shadow: 0 8px 24px rgba(29, 27, 24, 0.14);

    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans", Helvetica, Arial, sans-serif;
    --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;

    --page: 1080px;
    --gutter: 24px;
    --control-h: 36px;

    /* Shared by the column header and every show row so they line up as a table */
    --col-time: 92px;
    --col-venue: 170px;
    --col-price: 48px;
    --col-action: 112px;
    --col-gap: 16px;
}

body.dark-mode {
    --bg: #161513;
    --fg: #ece8e1;
    --muted: #a39d92;
    --border: #37342f;
    --subtle: #1f1d1a;
    --link: #5cc8ae;
    --mark: rgba(234, 179, 8, 0.3);
    --star: #e3b341;
    --warn: #e0a93b;
    --danger: #f47067;
    --shadow: 0 8px 24px rgba(0, 0, 0, 0.55);
    color-scheme: dark;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
    scroll-padding-top: 16px;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--fg);
    font-family: var(--font);
    font-size: 16px;
    line-height: 1.5;
    color-scheme: light;
}

[hidden],
.hidden {
    display: none !important;
}

a {
    color: var(--link);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

button,
input,
select {
    font: inherit;
    color: inherit;
}

button {
    cursor: pointer;
}

:focus-visible {
    outline: 2px solid var(--link);
    outline-offset: 2px;
}

/* Kept in the DOM for assistive tech and tests, not shown */
.site-kicker,
.filter-label,
.schedule-intro {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
}

/* ---------- Page frame ---------- */

.header-inner,
main,
.footer,
#error {
    width: 100%;
    max-width: var(--page);
    margin-left: auto;
    margin-right: auto;
    padding-left: max(var(--gutter), env(safe-area-inset-left));
    padding-right: max(var(--gutter), env(safe-area-inset-right));
}

.header-inner {
    position: relative;
    padding-top: max(24px, env(safe-area-inset-top));
}

main {
    position: relative;
    /* flex only so the favorites banner (inserted just before the list) can sit above the table header */
    display: flex;
    flex-direction: column;
}

/* ---------- Title (# heading) ---------- */

.header-title-group {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
}

.title-stack {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    column-gap: 12px;
    min-width: 0;
}

h1 {
    margin: 0;
    font-size: 2rem;
    font-weight: 600;
    line-height: 1.25;
}

h1 span {
    color: var(--muted);
    font-weight: 400;
}

.show-count {
    color: var(--muted);
    font-size: 0.875rem;
}

.header-icons {
    display: flex;
    flex: none;
    gap: 2px;
}

.header-icons button {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    padding: 0;
    background: none;
    border: 1px solid transparent;
    border-radius: 6px;
    color: var(--muted);
}

.header-icons button:hover {
    background: var(--subtle);
    color: var(--fg);
}

.header-icons button.active,
.header-icons button[aria-pressed="true"] {
    color: var(--link);
    border-color: var(--border);
    background: var(--subtle);
}

.fav-count {
    position: absolute;
    top: 2px;
    right: 2px;
    min-width: 16px;
    padding: 0 4px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 2em;
    color: var(--fg);
    font-size: 10px;
    font-weight: 600;
    line-height: 14px;
    text-align: center;
}

/* ---------- Filters ---------- */

.header-controls {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    padding: 12px 0 0;
}

.header-controls.collapsed {
    display: none;
}

/* A real flex container, not display: contents — Safari positions a <select>'s
   native popup relative to the wrong box when its parent has display: contents. */
.header-controls .row {
    display: flex;
    flex: 1 1 0;
    flex-wrap: wrap;
    gap: 8px;
    min-width: 0;
}

.quick-chips {
    display: flex;
    gap: 8px;
}

.filter-field {
    display: block;
    min-width: 0;
}

.filter-field-search {
    flex: 1 1 160px;
    position: relative;
}

.header-controls select,
.header-controls input[type="search"],
#filter-date-btn,
#calendar-toggle,
.chip {
    height: var(--control-h);
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.875rem;
}

.header-controls select {
    max-width: 190px;
    padding: 0 28px 0 10px;
}

.header-controls input[type="search"] {
    width: 100%;
    padding: 0 32px 0 10px;
    -webkit-appearance: none;
    appearance: none;
}

.header-controls input[type="search"]::placeholder {
    color: var(--muted);
}

.header-controls input[type="search"]::-webkit-search-cancel-button {
    display: none;
}

.search-clear-btn {
    position: absolute;
    top: 50%;
    right: 4px;
    width: 28px;
    height: 28px;
    padding: 0;
    transform: translateY(-50%);
    background: none;
    border: 0;
    color: var(--muted);
}

.date-filter-wrapper {
    display: inline-flex;
}

#filter-date-btn {
    padding: 0 10px;
    border-radius: 6px 0 0 6px;
    white-space: nowrap;
}

#calendar-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: var(--control-h);
    margin-left: -1px;
    padding: 0;
    border-radius: 0 6px 6px 0;
    color: var(--muted);
}

.chip {
    padding: 0 12px;
    color: var(--muted);
    white-space: nowrap;
}

.header-controls select:hover,
#filter-date-btn:hover,
#calendar-toggle:hover,
.chip:hover {
    background: var(--subtle);
}

.chip.active,
#filter-date-btn.active {
    border-color: var(--link);
    color: var(--link);
    font-weight: 600;
}

/* ---------- Calendar popup ---------- */

.calendar-backdrop {
    position: fixed;
    inset: 0;
    z-index: 997;
}

.calendar-popup {
    position: absolute;
    top: 100%;
    left: max(var(--gutter), env(safe-area-inset-left));
    z-index: 999;
    width: 300px;
    max-width: calc(100% - 2 * var(--gutter));
    margin-top: 6px;
    padding: 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    box-shadow: var(--shadow);
}

.calendar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}

.calendar-header button {
    width: 36px;
    height: 36px;
    padding: 0;
    background: none;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 1.125rem;
    line-height: 1;
}

.calendar-month-year {
    font-weight: 600;
}

.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 2px;
}

.calendar-day-label {
    padding: 4px 0;
    color: var(--muted);
    font-size: 0.75rem;
    text-align: center;
}

.calendar-day {
    height: 36px;
    padding: 0;
    background: none;
    border: 1px solid transparent;
    border-radius: 6px;
    font-size: 0.875rem;
    font-variant-numeric: tabular-nums;
}

button.calendar-day:hover {
    background: var(--subtle);
}

.calendar-day.today {
    border-color: var(--border);
    font-weight: 600;
}

.calendar-day.selected {
    background: var(--link);
    border-color: var(--link);
    color: var(--bg);
    font-weight: 600;
}

.calendar-day.disabled {
    color: var(--muted);
    opacity: 0.45;
    cursor: default;
}

.calendar-day.disabled:hover {
    background: none;
}

.calendar-footer {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--border);
}

.calendar-footer button,
.tba-toggle,
.fav-banner-btn,
.btn-clear-filters {
    padding: 0;
    background: none;
    border: 0;
    color: var(--link);
    font-size: 0.875rem;
}

.calendar-footer button:hover,
.tba-toggle:hover,
.fav-banner-btn:hover,
.btn-clear-filters:hover {
    text-decoration: underline;
}

/* ---------- Error, banner (blockquote-style callouts) ---------- */

#error {
    margin-top: 16px;
}

#error .msg {
    display: block;
    padding: 8px 12px;
    border-left: 4px solid var(--danger);
    color: var(--danger);
}

.fav-banner {
    order: -1;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px 14px;
    margin: 16px 0 0;
    padding: 8px 12px;
    border-left: 4px solid var(--link);
    background: var(--subtle);
    font-size: 0.875rem;
}

.fav-banner-text {
    flex: 1 1 200px;
}

.fav-banner-btn {
    min-height: 32px;
}

.fav-banner-dismiss {
    width: 32px;
    height: 32px;
    padding: 0;
    background: none;
    border: 0;
    color: var(--muted);
}

/* ---------- Schedule table ---------- */

.schedule-columns,
.show {
    display: grid;
    grid-template-columns:
        var(--col-time)
        minmax(0, 1fr)
        calc(var(--col-price) + var(--col-action) + 10px);
    column-gap: var(--col-gap);
}

/* Five labels over three row cells: split the middle and last cells to match */
.schedule-columns {
    grid-template-columns:
        var(--col-time)
        var(--col-venue)
        minmax(0, 1fr)
        var(--col-price)
        calc(var(--col-action) - var(--col-gap) + 10px);
    margin-top: 20px;
    padding: 6px 0;
    border-bottom: 2px solid var(--border);
    color: var(--muted);
    font-size: 0.75rem;
    font-weight: 600;
}

.list {
    margin: 0;
    padding: 0;
    list-style: none;
}

/* Date heading (## heading) */
.date-break {
    margin: 0;
}

.date-divider {
    margin: 28px 0 0;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border);
    font-size: 1.25rem;
    font-weight: 600;
    line-height: 1.25;
}

.date-break:first-child .date-divider {
    margin-top: 16px;
}

.date-divider .wd {
    margin-right: 0.35em;
}

.show {
    align-items: start;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
    font-size: 0.9375rem;
}

.show.flash-highlight {
    animation: flash 1.6s ease-out;
}

@keyframes flash {
    from { background: var(--mark); }
    to { background: transparent; }
}

/* Time cell */
.show-time {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
    min-width: 0;
}

.show-time .t {
    font-family: var(--mono);
    font-size: 0.875rem;
    font-weight: 600;
    white-space: nowrap;
}

.show-time .d,
.next-up-badge {
    color: var(--muted);
    font-size: 0.75rem;
}

/* The date heading already says the day; keep the per-row date only when there is none */
.date-break ~ .show .show-time .d {
    display: none;
}

.next-up-badge {
    color: var(--link);
    font-weight: 600;
}

/* Venue + lineup cell */
.show-main {
    display: grid;
    grid-template-columns: var(--col-venue) minmax(0, 1fr);
    column-gap: var(--col-gap);
    min-width: 0;
}

.show-venue-row {
    grid-column: 1;
    grid-row: 1 / span 6;
    min-width: 0;
}

.show-main > :not(.show-venue-row) {
    grid-column: 2;
    min-width: 0;
}

.show-venue {
    font-weight: 600;
}

.room-badge {
    color: var(--muted);
    font-size: 0.8125rem;
}

.badge {
    display: inline-block;
    margin-left: 6px;
    padding: 0 7px;
    border: 1px solid var(--border);
    border-radius: 2em;
    color: var(--muted);
    font-size: 0.75rem;
    font-weight: 500;
    line-height: 18px;
    white-space: nowrap;
    vertical-align: 1px;
}

.show-time .badge {
    margin-left: 0;
}

.badge.sold-out {
    border-color: var(--danger);
    color: var(--danger);
}

.badge.almost {
    border-color: var(--warn);
    color: var(--warn);
}

.show-title {
    font-weight: 600;
}

.show-series {
    color: var(--muted);
    font-size: 0.875rem;
}

/* Show note (> blockquote) */
.show-note {
    margin: 2px 0 4px;
    padding: 0 0 0 10px;
    border-left: 3px solid var(--border);
    color: var(--muted);
    font-size: 0.875rem;
}

.show-note.important {
    border-left-color: var(--warn);
}

/* Lineup: comma-separated names */
.show-comedians {
    display: flex;
    flex-wrap: wrap;
    column-gap: 0.5em;
}

.comedian-wrapper {
    display: inline-flex;
    align-items: center;
    white-space: nowrap;
}

.comedian-wrapper:not(:last-child)::after {
    content: ",";
}

.fav-star {
    align-self: stretch;
    min-width: 22px;
    padding: 0 3px 0 0;
    background: none;
    border: 0;
    color: var(--border);
    font-size: 0.8125rem;
    line-height: 1;
}

.fav-star:hover,
.fav-star.favorited {
    color: var(--star);
}

.comedian {
    color: inherit;
}

.comedian[data-bio] {
    cursor: help;
}

a.comedian:hover {
    color: var(--link);
}

.comedian-wrapper.favorited .comedian {
    padding: 0 2px;
    background: var(--mark);
    border-radius: 3px;
    font-weight: 600;
}

.celebrity-pseudonym {
    font-style: italic;
}

.no-lineup {
    color: var(--muted);
}

/* Price + actions cell */
.show-ctas {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 2px 10px;
}

.primary-ctas,
.secondary-ctas {
    display: contents;
}

.price {
    flex: none;
    width: var(--col-price);
    font-family: var(--mono);
    font-size: 0.875rem;
}

.show-ctas .btn {
    padding: 0;
    background: none;
    border: 0;
    color: var(--link);
    font-weight: 600;
    white-space: nowrap;
}

.show-ctas .btn:hover {
    text-decoration: underline;
}

.show-ctas .btn-secondary {
    color: var(--muted);
    font-size: 0.8125rem;
    font-weight: 400;
}

.seats-left {
    order: 9;
    flex-basis: 100%;
    color: var(--warn);
    font-size: 0.75rem;
}

/* "+ N more shows · lineup TBA" row */
.tba-group {
    padding: 4px 0;
    border-bottom: 1px solid var(--border);
}

.tba-toggle {
    min-height: 32px;
    color: var(--muted);
}

/* scoped: calendar padding cells are also .empty */
.list > .empty {
    padding: 32px 0;
    color: var(--muted);
}

/* Bordered buttons that are not in a show row (load more) */
.load-more-container {
    padding: 20px 0;
    text-align: center;
}

.load-more-btn {
    padding: 6px 16px;
    background: var(--subtle);
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.875rem;
    font-weight: 500;
}

.load-more-btn:hover {
    border-color: var(--muted);
}

/* Loading skeleton: grey bars in the same grid */
.skeleton-time,
.skeleton-line,
.skeleton-chip,
.skeleton-pill,
.skeleton-btn {
    display: block;
    height: 12px;
    margin: 5px 0;
    background: var(--subtle);
    border-radius: 3px;
}

.skeleton-time { width: 56px; }
.skeleton-line.w-60 { width: 40%; }
.skeleton-line.w-90 { width: 70%; }
.skeleton-chip-row,
.skeleton-ctas { display: flex; gap: 8px; }
.skeleton-chip,
.skeleton-btn { width: 72px; }
.skeleton-pill { width: 36px; }

/* ---------- Footer ---------- */

.footer {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 8px 16px;
    margin-top: 32px;
    padding-top: 16px;
    padding-bottom: max(24px, env(safe-area-inset-bottom));
    border-top: 1px solid var(--border);
    color: var(--muted);
    font-size: 0.8125rem;
}

/* Inset by margin rather than padding so the top rule lines up with the content */
.footer {
    width: calc(100% - 2 * var(--gutter));
    max-width: calc(var(--page) - 2 * var(--gutter));
    padding-left: 0;
    padding-right: 0;
}

.bmc-btn {
    color: var(--muted);
}

/* ---------- Floating pieces ---------- */

.fav-manager {
    position: fixed;
    z-index: 1100;
    padding: 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    box-shadow: var(--shadow);
    font-size: 0.875rem;
}

.fav-manager-title {
    margin-bottom: 6px;
    font-weight: 600;
}

.fav-manager-list {
    max-height: 50vh;
    margin: 0 0 8px;
    padding: 0;
    overflow-y: auto;
    list-style: none;
}

.fav-manager-list li {
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border);
}

.fav-manager-remove {
    width: 32px;
    height: 32px;
    padding: 0;
    background: none;
    border: 0;
    color: var(--muted);
}

.fav-manager-remove:hover {
    color: var(--danger);
}

.fav-manager-push,
.tooltip-btn,
.tooltip-fav-btn {
    display: inline-block;
    padding: 4px 10px;
    background: var(--subtle);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--fg);
    font-size: 0.8125rem;
}

.fav-manager-push {
    width: 100%;
}

.tooltip {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 1200;
    max-width: min(320px, calc(100vw - 24px));
    padding: 8px 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    box-shadow: var(--shadow);
    font-size: 0.8125rem;
    white-space: pre-line;
}

.tooltip-btn-row {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}

.tooltip-btn:hover {
    text-decoration: none;
    border-color: var(--muted);
}

.tooltip-fav-btn.favorited {
    color: var(--star);
}

.autocomplete-dropdown {
    z-index: 1300;
    overflow-y: auto;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    box-shadow: var(--shadow);
    font-size: 0.875rem;
}

.category-header {
    padding: 6px 10px 2px;
    color: var(--muted);
    font-size: 0.75rem;
    font-weight: 600;
}

.autocomplete-item {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    padding: 8px 10px;
    cursor: pointer;
}

.autocomplete-item:hover,
.autocomplete-item.selected {
    background: var(--subtle);
}

.suggestion-meta {
    flex: none;
    color: var(--muted);
    font-size: 0.75rem;
}

.app-toast {
    position: fixed;
    left: 50%;
    bottom: max(20px, env(safe-area-inset-bottom));
    z-index: 1400;
    max-width: calc(100vw - 32px);
    padding: 8px 14px;
    transform: translateX(-50%);
    background: var(--fg);
    border-radius: 6px;
    color: var(--bg);
    font-size: 0.875rem;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s;
}

.app-toast.visible {
    opacity: 1;
}

.scroll-to-top {
    position: fixed;
    right: max(16px, env(safe-area-inset-right));
    bottom: max(16px, env(safe-area-inset-bottom));
    z-index: 900;
    width: 40px;
    height: 40px;
    padding: 0;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--muted);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s;
}

.scroll-to-top.visible {
    display: block !important;
    opacity: 1;
    pointer-events: auto;
}

.pull-refresh {
    position: absolute;
    top: -60px;
    left: 0;
    right: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    height: 60px;
    color: var(--muted);
    font-size: 0.875rem;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s, transform 0.2s;
}

.pull-refresh.visible {
    opacity: 1;
}

.pull-refresh.refreshing .pull-refresh-text {
    display: none;
}

.pull-refresh-spinner {
    width: 18px;
    height: 18px;
    border: 2px solid var(--border);
    border-top-color: var(--link);
    border-radius: 50%;
}

.pull-refresh.refreshing .pull-refresh-spinner {
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ---------- Narrow screens: rows stack, table header goes away ---------- */

@media (max-width: 820px) {
    :root {
        --gutter: 16px;
        --col-time: 70px;
        --col-gap: 10px;
    }

    .schedule-columns {
        display: none;
    }

    .show {
        grid-template-columns: var(--col-time) minmax(0, 1fr);
        row-gap: 4px;
    }

    .show-main {
        display: block;
    }

    .show-venue-row {
        display: flex;
        flex-wrap: wrap;
        align-items: baseline;
        column-gap: 8px;
    }

    .show-ctas {
        grid-column: 2;
        gap: 2px 14px;
    }

    .price {
        width: auto;
    }

    .seats-left {
        order: 0;
        flex-basis: auto;
    }
}

@media (max-width: 640px) {
    :root {
        --control-h: 40px;
    }

    .header-inner {
        padding-top: max(12px, env(safe-area-inset-top));
    }

    h1 {
        font-size: 1.375rem;
    }

    h1 span {
        display: none;
    }

    .title-stack {
        flex-direction: column;
    }

    /* 16px keeps iOS from zooming the page when a control takes focus */
    .header-controls select,
    .header-controls input[type="search"] {
        font-size: 1rem;
    }

    .filter-field-date,
    .filter-field-location,
    .filter-field-lineup {
        flex: 1 1 calc(50% - 4px);
    }

    .filter-field select,
    .date-filter-wrapper {
        width: 100%;
        max-width: none;
    }

    .header-controls .row,
    .quick-chips {
        flex-basis: 100%;
    }

    #filter-date-btn {
        flex: 1;
        text-align: left;
    }

    .filter-field-search {
        flex-basis: 100%;
    }

    .chip {
        flex: 1;
    }

    .date-divider {
        margin-top: 24px;
        font-size: 1.125rem;
    }

    /* Bigger hit areas for touch: stars and row actions */
    .show-comedians {
        column-gap: 0.25em;
    }

    .fav-star {
        min-width: 26px;
        min-height: 30px;
        padding-right: 2px;
        text-align: right;
    }

    .show-ctas .btn {
        min-height: 36px;
        display: inline-flex;
        align-items: center;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation: none !important;
        transition: none !important;
    }
}
