/* Mobile-First Responsive CSS for Personal Tune Management */

/* ============================================
   BASE STYLES (Mobile & Desktop)
   ============================================ */

/* Prevent page bounce/overscroll and pull-to-refresh on mobile only */
@media (max-width: 768px) {
    html, body {
        overscroll-behavior-y: none; /* Prevent pull-to-refresh */
        overscroll-behavior-x: none; /* Prevent horizontal bounce */
        /* Use `clip` rather than `hidden`: `overflow-x: hidden` forces overflow-y
           to compute to `auto`, turning <body> into a scroll container sized to its
           content. Combined with `overscroll-behavior-y: none`, that traps wheel/touch
           scrolling and the page becomes unscrollable. `clip` prevents horizontal
           scroll without creating a scroll container, so vertical page scroll works. */
        overflow-x: clip; /* Prevent horizontal scroll when swiping cards */
    }
}

/* Ensure header and hamburger menu stay fixed during swipe gestures */
/* Using z-index: 2000 from the z-index scale in theme.css (--z-header) */
.header.fixed-top {
    position: fixed;
    width: 100%;
    z-index: 2000 !important;
    /* Isolate from transforms applied to page content */
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
    will-change: transform;
}

/* Full width on desktop, the same as /sessions and /tunes. .docs-content is already
   the page's content box — 40px in from each edge — so a second 1200px cap centred
   inside it just made Tunes a visibly narrower page than Sessions, with nothing on
   screen to explain why. Horizontal padding goes for the same reason: it would inset
   these rows 20px further than the rows on either of those pages. */
.my-tunes-container {
    padding: 20px 0;
}

.btn {
    padding: 4px 12px;
    background-color: var(--primary-fill);
    color: white !important;
    text-decoration: none;
    border-radius: 4px;
    border: none;
    cursor: pointer;
    font-size: 13px;
    transition: background-color 0.2s;
    white-space: nowrap;
    line-height: 1.2;
}

.btn:hover {
    background-color: var(--primary-fill-hover, #437342);
    color: white !important;
    text-decoration: none;
}

.btn-secondary {
    background-color: var(--secondary, #6c757d);
    color: white !important;
}

.btn-secondary:hover {
    background-color: var(--secondary-dark, #5a6268);
    color: white !important;
}

.filters-container {
    margin-bottom: 20px;
}

/* New top row layout: search + filter icon */
.filter-top-row {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-bottom: 0;
}

/* The kit SearchField wrapper takes the input's old flex slot in the row */
.filter-top-row .kit-search {
    flex: 1;
    min-width: 0;
}

.filter-search-input {
    flex: 1;
    padding: 8px 10px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 14px;
    background-color: var(--bg-color);
    color: var(--text-color);
    min-width: 0;
}

/* The session People box used to carry its own skin, and a focus border was the
   one thing that skin had which this one did not. Kept, and given to every
   search box that wears this class rather than to one of them. */
.filter-search-input:focus {
    outline: none;
    border-color: var(--primary);
}

.filter-panel-toggle {
    padding: 8px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background-color: var(--bg-color);
    color: var(--text-color);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
    width: 40px;
    height: 40px;
}

.filter-panel-toggle:hover {
    background-color: var(--hover-bg);
}

.filter-panel-toggle.active {
    background-color: var(--primary-fill);
    color: white;
    border-color: var(--primary-fill);
}

.filter-panel-toggle svg {
    display: block;
}

/* Filter panel - slides down when opened */
.filter-panel {
    margin-top: 12px;
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background-color: var(--bg-color);
    /* overflow:visible so the custom instrument dropdown can overlay rows below it; the
       slide animation clips via overflow:hidden on .opening/.closing (only for 0.3s). */
    transition: all 0.3s ease-out;
}

.filter-panel.opening {
    animation: slideDown 0.3s ease-out;
    overflow: hidden;
}

.filter-panel.closing {
    animation: slideUp 0.3s ease-out;
    overflow: hidden;
}

/* Custom instrument-filter dropdown (native <select> popup can't be themed / scaled). */
.inst-select { position: relative; flex: 1; }
.inst-select-trigger {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 10px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 14px;
    background-color: var(--bg-color);
    color: var(--text-color);
    cursor: pointer;
}
#instrument-filter-label {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-align: left;
}
/* Drawn (lib/Chevron.svelte), already pointing down, so opening flips it to up
   rather than rotating a 10px `▾` by 180 degrees. */
.inst-select-caret { opacity: 0.7; }
.inst-select.open .inst-select-caret { transform: rotate(-90deg); }
.inst-select-menu {
    display: none;
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    z-index: 100;
    max-height: 240px;
    overflow-y: auto;
    background-color: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
}
.inst-select.open .inst-select-menu { display: block; }
.inst-select-option {
    display: block;
    width: 100%;
    text-align: left;
    padding: 9px 12px;
    border: none;
    background: transparent;
    color: var(--text-color);
    font-size: 14px;
    cursor: pointer;
}
.inst-select-option:hover { background-color: var(--hover-bg); }
.inst-select-option.active { background-color: var(--primary-fill); color: #fff; }

/* The status filter lives OUTSIDE the drawer (it's the one you reach for every visit),
   so it needs the row spacing the drawer used to give it. */
.filter-status-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 8px;
}

/* It's on screen at all times, so it runs tighter than the drawer's controls — enough
   less height to buy back a row of tunes, still a comfortable thumb target. Specific
   enough to beat the shared .filter-status-btn/.filter-sort-btn padding in the mobile
   block below, so it holds at every width. */
.filter-status-row .filter-status-btn {
    padding-top: 4px;
    padding-bottom: 4px;
}

.filter-panel-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
}

.filter-panel-row:last-of-type {
    margin-bottom: 0;
}

/* The relationship-chip row can hold three pills — let them wrap on phones. */
#rel-filter-row {
    flex-wrap: wrap;
}

.filter-panel-select {
    flex: 1;
    padding: 8px 10px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 14px;
    background-color: var(--bg-color);
    color: var(--text-color);
    cursor: pointer;
}

/* Button groups for status and sort filters */
.filter-button-group {
    display: flex;
    gap: 0;
    flex: 1;
}

.filter-status-btn,
.filter-sort-btn {
    flex: 1;
    padding: 8px 10px;
    border: 1px solid var(--border-color);
    background-color: var(--bg-color);
    color: var(--text-color);
    cursor: pointer;
    font-size: 14px; /* match the type/instrument selects */
    transition: all 0.2s;
    white-space: nowrap;
}

.filter-status-btn:first-child,
.filter-sort-btn:first-child {
    border-radius: 4px 0 0 4px;
}

.filter-status-btn:last-child,
.filter-sort-btn:last-child {
    border-radius: 0 4px 4px 0;
}

/* Every button keeps its full 1px border; adjacent borders overlap so each divider is a
   single line, and the active button (raised via z-index) owns BOTH of its edges — no
   mismatched divider colors next to it. */
.filter-status-btn:not(:first-child),
.filter-sort-btn:not(:first-child) {
    margin-left: -1px;
}

.filter-status-btn:hover,
.filter-sort-btn:hover {
    background-color: var(--hover-bg);
}

.filter-status-btn.active,
.filter-sort-btn.active {
    background-color: var(--primary-fill);
    color: white;
    border-color: var(--primary-fill);
    position: relative;
    z-index: 1;
}

.filter-sort-btn.active-secondary {
    background-color: transparent;
    color: var(--primary);
    border-color: var(--primary);
    position: relative;
    z-index: 1;
}

.filter-sort-direction-btn {
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background-color: var(--bg-color);
    color: var(--text-color);
    cursor: pointer;
    font-size: 16px;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 40px;
    flex-shrink: 0;
}

.filter-sort-direction-btn:hover {
    background-color: var(--hover-bg);
}

/* :has() so the divider only exists when something is under it — without this the
   row is a border-top and nothing else whenever no filters are set, which reads as
   a stray rule across the foot of the panel. */
.filter-panel-actions:has(> *) {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: center;
}

.filter-panel-clear-btn {
    padding: 6px 16px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background-color: var(--bg-color);
    color: var(--text-color);
    cursor: pointer;
    font-size: 13px;
    transition: all 0.2s;
}

.filter-panel-clear-btn:hover {
    background-color: var(--hover-bg);
}

.tunes-grid {
    display: block;
    margin-bottom: 30px;
}

.tune-card {
    background-color: var(--bg-color);
    border-bottom: 1px solid var(--border-color);
    padding: 15px 8px;
    transition: background-color 0.1s;
    cursor: pointer;
    display: grid;
    grid-template-columns: var(--tune-row-columns);
    gap: 12px;
    align-items: center;
}

/* The desktop row: learn status | name | type | tunebooks | my plays | heard. The
   status column fits "Learning"; the type column is wide enough for "Strathspey";
   the counts are fixed-width so they line up under their headings. The phone
   layout (below, max-width 768px) replaces this with its own three columns. */
.tunes-grid {
    --tune-row-columns: 5.75rem minmax(0, 1fr) 6.25rem repeat(3, 4.75rem);
}

/* Desktop column headings, on the rows' own grid (App.svelte renders them only
   above 768px). They name the three counts, which are otherwise bare numbers. */
.tune-list-columns {
    display: grid;
    grid-template-columns: var(--tune-row-columns);
    gap: 12px;
    padding: 0 8px 6px;
    border-bottom: 1px solid var(--border-color);
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted, #6c757d);
}

.tune-list-col-type {
    grid-column: 3;
}

.tune-list-col-num {
    text-align: right;
}

.tune-list-col-num.sorted {
    color: var(--text-color);
}

.tune-count {
    grid-row: 1;
    text-align: right;
    font-size: 14px;
    font-variant-numeric: tabular-nums;
    color: var(--text-muted, #6c757d);
}

.tune-count-tunebooks { grid-column: 4; }
.tune-count-plays { grid-column: 5; }
.tune-count-heard { grid-column: 6; }

/* The count the list is sorted by, so the order reads at a glance. */
.tune-count.sorted {
    color: var(--text-color);
    font-weight: 600;
}

.tune-card:first-child {
    border-top: 1px solid var(--border-color);
}

.tune-card:hover {
    background-color: var(--hover-bg);
}

/* Instrument filter: tunes not on the selected instrument stay visible but dimmed */
.tune-card.tune-card-dimmed {
    opacity: 0.45;
}

/* Instrument filter: heading separating on-instrument tunes from the dimmed rest */
.tune-group-heading {
    grid-column: 1 / -1;
    padding: 20px 8px 6px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted, #6c757d);
}

.tune-type-cell {
    grid-column: 3;
    grid-row: 1;
    display: flex;
    justify-content: flex-start;
    min-width: 0;
}

.tune-card-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 0;
    grid-column: 2;
    grid-row: 1;
    min-width: 0;
}

.tune-name {
    font-size: 17px;
    font-weight: 500;
    color: var(--text-color);
    margin: 0;
    flex: 0 0 auto;
}

/* This card is in the results because its NOTATION matched the search, not its name.
   Without the mark, a search by notes reads as a list of unrelated tunes. */
.abc-only-badge {
    font-size: 15px;
    line-height: 1;
    color: #e8d28a;
    flex: 0 0 auto;
    margin-left: -6px; /* sits with the name, not spaced like the chips beside it */
}

.tune-type {
    font-size: 13px;
    padding: 3px 6px;
    background-color: var(--primary-fill);
    color: white;
    border-radius: 3px;
    text-transform: capitalize;
    white-space: nowrap;
    margin-left: 0;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tune-meta {
    display: flex;
    flex-direction: row;
    gap: 12px;
    margin-bottom: 0;
    font-size: 13px;
    color: var(--text-muted, #6c757d);
    align-items: center;
    grid-column: 1;
    grid-row: 1;
}

.tune-meta-item {
    display: flex;
    align-items: center;
    gap: 8px;
}

.status-badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
    text-transform: capitalize;
}

/* Status colors match the tune detail modal (tunebook-status-*): want to learn = blue,
   learning = yellow, learned = green */
.status-want-to-learn {
    background-color: #1f3a4a;
    color: #cce5ff;
}

.status-learning {
    background-color: #4a3f1f;
    color: #ffeaa7;
}

.status-learned {
    background-color: #1f4a2f;
    color: #c3e6cb;
}

.tune-actions {
    display: none;
}

.tune-action-btn {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    background-color: var(--bg-color);
    color: var(--text-color);
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    transition: background-color 0.2s;
    text-align: center;
    text-decoration: none;
}

.tune-action-btn:hover {
    background-color: var(--hover-bg);
    text-decoration: none;
    color: var(--text-color);
}

.heard-count-container {
    display: none;
}

.heard-count {
    font-weight: 600;
    color: var(--primary);
}

.increment-heard-btn {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    border: 1px solid var(--primary);
    background-color: var(--bg-color);
    color: var(--primary);
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.increment-heard-btn:hover {
    background-color: var(--primary-fill);
    color: white;
}

.no-results {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted, #6c757d);
}

.no-results h3 {
    margin-bottom: 10px;
}

.loading {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted, #6c757d);
}

.loading-more {
    text-align: center;
    padding: 20px;
    color: var(--text-muted, #6c757d);
    font-size: 14px;
    display: none;
}

.loading-more.visible {
    display: block;
}

.loading-spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-right: 8px;
    vertical-align: middle;
}

/* @keyframes spin lives in theme.css */

/* Active-filter pills, shown while the filter panel is collapsed */
.active-filter-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 10px;
}

/* Relationship filter chips in the filter panel (spec 033): single-select
   toggle-off pills — outlined when idle, filled like the active sort when on. */
.filter-rel-chip {
    display: inline-flex;
    align-items: center;
    padding: 4px 12px;
    border: 1px solid var(--border-color);
    border-radius: 999px;
    font-size: 13px;
    color: var(--text-color);
    background-color: var(--bg-color);
    cursor: pointer;
    transition: all 0.2s;
}

.filter-rel-chip:hover {
    border-color: var(--primary);
}

.filter-rel-chip.active {
    border-color: var(--primary-fill);
    background-color: var(--primary-fill);
    color: white;
}

.filter-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    border: 1px solid var(--primary-fill);
    border-radius: 999px;
    font-size: 13px;
    color: white;
    background-color: var(--primary-fill); /* same blue as the active filter buttons */
}

.filter-pill-x {
    background: none;
    border: none;
    padding: 0;
    font-size: 15px;
    line-height: 1;
    color: inherit;
    opacity: 0.7;
    cursor: pointer;
}

.filter-pill-x:hover { opacity: 1; }

.results-count {
    margin-bottom: 15px;
    color: var(--text-muted, #6c757d);
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.sort-toggle {
    padding: 4px 8px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background-color: var(--bg-color);
    color: var(--text-color);
    cursor: pointer;
    font-size: 13px;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 4px;
    white-space: nowrap;
    user-select: none;
}

.sort-toggle:hover {
    background-color: var(--hover-bg);
}

.sort-toggle.active {
    background-color: var(--primary-fill);
    color: white;
    border-color: var(--primary-fill);
}

/* Loading dots animation */
.loading-dots {
    font-weight: bold;
    display: inline-block;
    animation: pulse-dots 1.5s ease-in-out infinite;
}

@keyframes pulse-dots {
    0%, 100% {
        opacity: 0.3;
    }
    50% {
        opacity: 1;
    }
}

/* ============================================
   TUNE DETAIL MODAL STYLES
   ============================================ */

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 1900;
    display: none;
    align-items: center;
    justify-content: center;
    pointer-events: auto;
}

.modal-dialog {
    background: var(--bg-color, white);
    border-radius: 8px;
    padding: 0;
    max-width: 600px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 8px 24px rgba(0,0,0,0.3);
    color: var(--text-color);
    position: relative;
    pointer-events: auto;
    z-index: 1;
}

#tune-detail-content {
    padding: 20px;
}

.modal-close-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    background: none;
    border: none;
    font-size: 28px;
    color: var(--text-muted, #999);
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1;
}

.modal-close-btn:hover {
    color: var(--text-color);
}

.modal-tune-title {
    margin: 0 32px 12px 0;
    color: var(--text-color);
    font-size: 23px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}

.thesession-link-icon {
    font-size: 18px;
    text-decoration: none;
    color: var(--primary);
    opacity: 0.8;
}

.thesession-link-icon:hover {
    opacity: 1;
}

.modal-header-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
    width: 100%;
}

.modal-status-select {
    padding: 6px 10px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 15px;
    background-color: var(--bg-color);
    color: var(--text-color);
    cursor: pointer;
    flex: 1;
    min-width: 0;
}

.modal-save-btn {
    padding: 6px 16px;
    background-color: var(--primary-fill);
    color: white;
    border: none;
    border-radius: 4px;
    font-size: 15px;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
    flex: 1;
    max-width: 120px;
}

.modal-save-btn:hover:not(:disabled) {
    background-color: var(--primary-fill-hover, #437342);
}

.modal-save-btn:disabled {
    background-color: #555;
    cursor: not-allowed;
    opacity: 0.5;
}

.modal-info-line {
    color: var(--text-muted, #6c757d);
    font-size: 15px;
    margin-bottom: 8px;
}

.modal-session-play-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 8px;
}

.modal-view-btn {
    padding: 4px 12px;
    background-color: var(--primary-fill);
    color: white !important;
    text-decoration: none;
    border-radius: 4px;
    font-size: 14px;
    white-space: nowrap;
    flex-shrink: 0;
}

.modal-view-btn:hover {
    background-color: var(--primary-fill-hover, #437342);
    color: white !important;
    text-decoration: none;
}

.modal-notes-section {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border-color);
}

.modal-notes-label {
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text-color);
}

.modal-notes-section p {
    margin: 0;
    color: var(--text-color);
    font-size: 15px;
    line-height: 1.5;
}

.modal-notes-textarea {
    width: 100%;
    min-height: 80px;
    padding: 10px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 15px;
    font-family: inherit;
    background-color: var(--bg-color);
    color: var(--text-color);
    resize: vertical;
    box-sizing: border-box;
}

.modal-notes-textarea:focus {
    outline: none;
    border-color: var(--primary);
}

.modal-notes-textarea:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    background-color: #2a2a2a;
}

/* Setting ID and Name Alias field styles */
.modal-field-section {
    margin-bottom: 12px;
}

.modal-field-label {
    font-size: 14px;
    color: var(--text-muted, #6c757d);
    margin-bottom: 4px;
    display: block;
}

.modal-field-input {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 15px;
    background-color: var(--bg-color);
    color: var(--text-color);
    box-sizing: border-box;
}

.modal-field-input:focus {
    outline: none;
    border-color: var(--primary);
}

.modal-field-input:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    background-color: #2a2a2a;
}

.modal-tune-title-editable {
    cursor: pointer;
    transition: opacity 0.2s;
}

.modal-tune-title-editable:hover {
    opacity: 0.7;
}

.name-alias-hint {
    font-size: 12px;
    color: var(--text-muted, #999);
    font-style: italic;
    margin-top: 2px;
}

.modal-field-error {
    font-size: 13px;
    color: #dc3545;
    margin-top: 4px;
    font-weight: 500;
}

/* Heard count controls */
.heard-count-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
    padding: 12px;
    background-color: #2a2a2a;
    border-radius: 4px;
}

.heard-count-label {
    font-size: 15px;
    color: var(--text-color);
    flex: 1;
    transition: opacity 0.2s;
}

/* Dim the label when increment button is disabled (data not loaded) */
.heard-count-btn-increment:disabled ~ .heard-count-label,
.heard-count-controls:has(.heard-count-btn-increment:disabled) ~ .heard-count-label {
    opacity: 0.4;
}

/* Alternative approach using parent container */
.heard-count-row:has(.heard-count-btn-increment:disabled) .heard-count-label {
    opacity: 0.4;
}

.heard-count-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}

.heard-count-btn {
    width: 32px;
    height: 32px;
    border-radius: 4px;
    border: none;
    color: white;
    font-size: 18px;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.2s;
}

.heard-count-btn:hover:not(:disabled) {
    opacity: 0.8;
}

.heard-count-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.heard-count-btn-decrement {
    background-color: #dc3545;
}

.heard-count-btn-increment {
    background-color: #28a745;
}

.heard-count-value {
    font-size: 19px;
    font-weight: 600;
    color: var(--text-color);
    min-width: 30px;
    text-align: center;
}

/* ============================================
   MOBILE OPTIMIZATIONS (< 768px)
   ============================================ */

@media (max-width: 768px) {
    /* Override parent container padding */
    .docs-content {
        padding: 0 !important;
        margin-left: 0 !important;
        margin-right: 0 !important;
    }

    .my-tunes-container {
        padding: 0;
        max-width: 100%;
        margin-top: 0;
        margin-left: 0;
        margin-right: 0;
    }

    /* Override safe area insets for tune list container */
    .my-tunes-container {
        padding-left: 0 !important;
        padding-right: 0 !important;
    }

    .my-tunes-header-section {
        padding-top: 14px;
        padding-left: 8px;
        padding-right: 8px;
    }

    .btn {
        padding: 4px 10px;
        font-size: 12px;
    }

    .filters-container {
        margin-bottom: 6px;
        padding: 0;
    }

    .filter-top-row {
        gap: 6px;
    }

    .filter-search-input {
        font-size: 16px; /* Prevents zoom on iOS */
        padding: 8px 10px;
        height: 40px;
        box-sizing: border-box;
    }

    .filter-panel-toggle {
        width: 40px;
        height: 40px;
        padding: 8px;
    }

    .filter-panel {
        margin-top: 8px;
        padding: 10px;
    }

    .filter-status-row {
        margin-top: 6px;
    }

    .filter-panel-row {
        flex-wrap: wrap;
        gap: 8px;
        margin-bottom: 12px;
    }

    .filter-panel-select {
        font-size: 16px; /* Prevents zoom on iOS */
        width: 100%;
    }

    .filter-button-group {
        width: 100%;
    }

    .filter-status-btn,
    .filter-sort-btn {
        font-size: 14px;
        padding: 8px 6px;
    }

    .filter-sort-direction-btn {
        font-size: 18px;
        min-width: 44px;
        padding: 8px;
    }

    .filter-panel-actions {
        margin-top: 8px;
        padding-top: 8px;
    }

    .filter-panel-clear-btn {
        font-size: 14px;
        width: 100%;
    }

    .results-count {
        margin-bottom: 4px;
        font-size: 12px;
        padding: 0;
        gap: 6px;
        flex-wrap: wrap;
    }

    .sort-toggle {
        font-size: 11px;
        padding: 3px 6px;
    }

    /* Mobile compact tune list */
    .tunes-grid {
        display: flex;
        flex-direction: column;
        gap: 1px;
        margin-bottom: 10px;
        grid-template-columns: 1fr;
        gap: 0; /* No gap between rows in mobile */
    }

    .tune-card {
        border-radius: 0;
        border-left: none;
        border-right: none;
        border-top: none;
        padding: 8px 8px;
        margin: 0;
        display: grid;
        /* status icon | name | type (or the sorted-by count), right-aligned */
        grid-template-columns: 20px minmax(0, 1fr) auto;
        grid-template-rows: auto;
        grid-auto-rows: 0;
        align-items: center;
        gap: 6px;
        max-width: 100%;
        overflow: hidden;
        min-height: 0;
    }

    .tune-card:first-child {
        border-top: 1px solid var(--border-color);
    }

    /* Force all direct children to be on row 1 or hidden */
    .tune-card > * {
        grid-row: 1;
    }

    .tune-card:hover {
        box-shadow: none;
        transform: none;
        background-color: transparent;
    }

    .tune-type-cell {
        grid-column: 3;
        justify-content: flex-end;
    }

    .tune-card-header {
        grid-column: 2;
        grid-row: 1;
        margin-bottom: 0;
        min-width: 0;
        overflow: hidden;
        display: flex;
        align-items: center;
        gap: 6px;
    }

    .tune-name {
        font-size: 18px;
        font-weight: 500;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        min-width: 0;
        flex: 0 1 auto;
    }

    .tune-type {
        font-size: 12px;
        padding: 2px 6px;
        white-space: nowrap;
    }

    .tune-meta {
        display: contents;
    }

    .tune-meta-item {
        display: contents;
    }

    /* Hide the "Key: X" meta item on mobile */
    .tune-meta-item:not(:first-child) {
        display: none !important;
    }

    /* Ensure only the first meta-item participates */
    .tune-meta-item:first-child {
        display: contents;
    }

    .status-badge {
        /* Grid column 1: fixed 20px column */
        grid-column: 1;
        grid-row: 1;
        padding: 0;
        border-radius: 0;
        font-size: 0;
        background-color: transparent !important;
        width: 20px;
        height: 20px;
        min-width: 20px;
        display: flex;
        align-items: center;
        justify-content: center;
        flex-shrink: 0;
    }

    .status-badge::before {
        font-size: 16px;
    }

    .status-want-to-learn::before {
        content: '●';
        color: #5bc0de;
    }

    .status-learning::before {
        content: '⋯';
        color: #f0ad4e;
    }

    .status-learned::before {
        content: '✓';
        color: #5cb85c;
    }

    .tune-actions {
        display: none !important;
    }

    .heard-count-container {
        display: none !important;
    }

    /* Touch-friendly button sizes */
    .tune-action-btn,
    .increment-heard-btn {
        min-height: 44px;
        min-width: 44px;
    }

    /* Modal adjustments - full page slide-in */
    .modal-overlay {
        background-color: transparent;
        align-items: flex-start;
        justify-content: flex-end;
        pointer-events: none;
    }

    .modal-dialog {
        width: 100%;
        max-width: 100%;
        height: calc(100vh - 40px);
        max-height: calc(100vh - 40px);
        margin: 0;
        margin-top: 40px;
        border-radius: 0;
        position: fixed;
        right: 0;
        top: 0;
        transform: translateX(100%);
        transition: transform 0.3s ease-out;
        overflow-y: auto;
        box-shadow: -4px 0 12px rgba(0,0,0,0.2);
        pointer-events: auto;
        padding-left: 16px;
        padding-right: 16px;
        box-sizing: border-box;
    }

    .modal-overlay.show .modal-dialog {
        transform: translateX(0);
    }

    #tune-detail-content {
        padding: 16px 0;
        box-sizing: border-box;
    }

    .modal-tune-title {
        font-size: 18px;
        margin-right: 48px;
        margin-top: 0;
        margin-left: 0;
    }

    .modal-close-btn {
        position: fixed;
        top: 8px;
        right: 8px;
        left: auto;
        font-size: 0;
        width: 40px;
        height: 40px;
        background-color: var(--bg-color);
        border: 1px solid var(--border-color);
        border-radius: 4px;
        z-index: 1920;
        color: var(--text-color);
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .modal-close-btn::before {
        content: '>';
        font-size: 24px;
        font-weight: bold;
        color: var(--text-color);
    }

    .modal-close-btn:hover {
        background-color: var(--hover-bg);
    }

    .modal-header-row {
        flex-wrap: wrap;
    }

    .modal-status-select {
        max-width: none;
    }

    .modal-info-line {
        font-size: 13px;
    }

    .modal-session-play-row {
        flex-direction: row;
        align-items: center;
    }

    .loading,
    .no-results {
        padding: 40px 20px;
        font-size: 14px;
    }

    .loading::after {
        content: '';
        display: block;
        width: 40px;
        height: 40px;
        margin: 20px auto 0;
        border: 4px solid var(--border-color);
        border-top-color: var(--primary);
        border-radius: 50%;
        animation: spin 1s linear infinite;
    }

    /* Swipe-to-reveal styles */
    .tune-card-swipe-container {
        position: relative;
        overflow: hidden; /* Prevent expansion beyond container */
        width: 100%;
        height: 100%;
    }

    .tune-card-swipe-action {
        position: absolute;
        left: 0;
        top: 0;
        bottom: 0;
        width: 0;
        height: 100%;
        display: flex;
        align-items: center;
        justify-content: center;
        background-color: #28a745;
        z-index: 0;
        overflow: hidden;
    }

    .swipe-action-btn {
        width: 100%;
        height: 100%;
        border: none;
        background: transparent;
        color: white;
        font-size: 32px;
        font-weight: bold;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 0;
        transition: background-color 0.2s;
    }

    .swipe-action-btn:active {
        background-color: #218838;
    }

    .swipe-action-icon {
        display: block;
        line-height: 1;
    }

    .tune-card-swipeable {
        position: relative;
        z-index: 1;
        background-color: var(--bg-color);
        transition: transform 0.3s ease-out;
        transform: translateX(0);
        width: 100%;
    }

    .tune-card-swipeable.swiping {
        transition: none;
    }

    .tune-card-swipeable.revealed {
        transform: translateX(80px);
    }

    /* Enable smooth scrolling for swipe gestures */
    .tunes-grid {
        scroll-behavior: smooth;
    }

    /* Add visual feedback for swipeable cards */
    .tune-card {
        touch-action: pan-y;
        user-select: none;
        -webkit-user-select: none;
        transition: transform 0.2s ease-out, box-shadow 0.2s;
    }

    .tune-card:active {
        transform: scale(0.98);
    }

    /* Pull-to-refresh indicator */
    .pull-to-refresh {
        position: fixed;
        top: 0;
        left: 50%;
        transform: translateX(-50%) translateY(-100%);
        background: var(--primary-fill);
        color: white;
        padding: 10px 20px;
        border-radius: 20px;
        font-size: 14px;
        z-index: 2850;
        transition: transform 0.3s ease-out;
        pointer-events: none;
        opacity: 0;
    }

    .pull-to-refresh.active {
        transform: translateX(-50%) translateY(20px);
        opacity: 1;
    }
}

/* ============================================
   ACCESSIBILITY ENHANCEMENTS
   ============================================ */

@media (max-width: 768px) {
    /* Focus indicators for keyboard navigation — :focus-visible, not :focus.
       The comment always said keyboard; the selector said "and also every mouse
       click", which is where the ring-on-tap came from. */
    .btn:focus-visible,
    .filter-input:focus-visible,
    .filter-select:focus-visible,
    .tune-action-btn:focus-visible,
    .increment-heard-btn:focus-visible {
        outline: 3px solid var(--primary);
        outline-offset: 2px;
    }

    /* High contrast mode support */
    @media (prefers-contrast: high) {
        .tune-card {
            border-width: 2px;
        }

        .btn {
            border: 2px solid currentColor;
        }
    }

}

/* ============================================
   PERFORMANCE OPTIMIZATIONS
   ============================================ */

@media (max-width: 768px) {
    /* Reduce animations on mobile for better performance */
    @media (prefers-reduced-motion: reduce) {
        * {
            animation-duration: 0.01ms !important;
            animation-iteration-count: 1 !important;
            transition-duration: 0.01ms !important;
        }
    }

    /* Optimize rendering */
    .tune-card,
    .autocomplete-results {
        will-change: transform;
        transform: translateZ(0);
        -webkit-transform: translateZ(0);
    }

    /* Optimize scrolling */
    .tunes-grid,
    .autocomplete-results,
    .modal-dialog {
        -webkit-overflow-scrolling: touch;
        overflow-scrolling: touch;
    }
}

/* ============================================
   ANIMATIONS
   ============================================ */

@keyframes slideDown {
    from {
        opacity: 0;
        max-height: 0;
        margin-top: 0;
    }
    to {
        opacity: 1;
        max-height: 500px;
        margin-top: 12px;
    }
}

@keyframes slideUp {
    from {
        opacity: 1;
        max-height: 500px;
        margin-top: 12px;
    }
    to {
        opacity: 0;
        max-height: 0;
        margin-top: 0;
    }
}

/* ============================================
   SMALL MOBILE DEVICES (< 375px)
   ============================================ */

@media (max-width: 374px) {
    .my-tunes-container,
    .add-tune-container,
    .sync-container {
        padding: 10px;
    }

    .tune-name {
        font-size: 15px;
    }

    .tune-card {
        padding: 12px;
    }

    .filters-container {
        padding: 12px;
    }

    .stat-value {
        font-size: 24px;
    }
}

/* ============================================
   LANDSCAPE ORIENTATION
   ============================================ */

@media (max-width: 768px) and (orientation: landscape) {
    /* Adjust modal height for landscape */
    .modal-dialog {
        max-height: 85vh;
    }

    /* The tune list is always a single column (even in landscape) */
    .tunes-grid {
        grid-template-columns: 1fr;
    }

    .filters-container {
        padding: 12px;
    }
}

/* ============================================
   TABLET DEVICES (768px - 1024px)
   ============================================ */

@media (min-width: 769px) and (max-width: 1024px) {
    .tunes-grid {
        grid-template-columns: 1fr;
    }

    /* Vertical only, like the base rule — horizontal padding here would put this
       page's rows 20px further in than /sessions' at exactly these widths, which is
       the inconsistency the base rule was changed to remove. */
    .my-tunes-container {
        padding: 20px 0;
    }

    /* Touch-friendly buttons on tablets too */
    .btn,
    .tune-action-btn,
    .increment-heard-btn {
        min-height: 40px;
        min-width: 40px;
    }
}

/* ============================================
   SAFE AREA INSETS (for notched devices)
   ============================================ */

@supports (padding: max(0px)) {
    @media (max-width: 768px) {
        .add-tune-container,
        .sync-container {
            padding-left: max(15px, env(safe-area-inset-left));
            padding-right: max(15px, env(safe-area-inset-right));
            padding-bottom: max(15px, env(safe-area-inset-bottom));
        }

        .my-tunes-container {
            /* No horizontal padding - let borders go edge-to-edge */
            padding-bottom: max(15px, env(safe-area-inset-bottom));
        }

        .modal-dialog {
            margin-left: 0;
            margin-right: 0;
        }
    }
}

/* ============================================
   MODAL BUTTONS AND REMOVE LINK
   ============================================ */

.modal-button-group {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-bottom: 12px;
}

.modal-cancel-btn {
    padding: 6px 16px;
    background-color: #1e3a5f;
    color: white;
    border: none;
    border-radius: 4px;
    font-size: 15px;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
    flex: 1;
    max-width: 120px;
}

.modal-cancel-btn:hover {
    background-color: #152b47;
}

.modal-remove-link-container {
    text-align: center;
    margin-bottom: 16px;
}

.modal-remove-link {
    font-size: 14px;
    color: #ff6b6b;
    text-decoration: none;
    transition: opacity 0.2s;
}

.modal-remove-link:hover {
    text-decoration: underline;
    opacity: 0.8;
}

/* Added-date range in the filter panel (spec 052 §B1). The profile's Tunebook
   section filtered the same collection by the same field; it is a filter here now. */
.filter-date-row {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.filter-date-input {
    flex: 0 1 auto;
    min-width: 0;
    padding: 6px 8px;
    font: inherit;
    font-size: 0.85rem;
    color: var(--text-color);
    background-color: var(--input-bg);
    border: 1px solid var(--border-color);
    border-radius: 4px;
}

.filter-date-input:focus {
    outline: none;
    border-color: var(--primary);
}

/* Sort row: droplist + direction button on one line (spec 052 §B1). Five modes in a
   segmented control took the panel's full width and still truncated. */
.filter-sort-row {
    display: flex;
    align-items: stretch;
    gap: 8px;
}

.filter-sort-row .sort-select {
    flex: 1;
    min-width: 0;
}

.filter-sort-row .filter-sort-direction-btn {
    flex: 0 0 auto;
}

/* "Added [After|Before] [date]" — one date and a direction, not a range. */
.filter-date-row .added-dir-select {
    flex: 0 0 auto;
    min-width: 96px;
}

.filter-played-row {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.filter-date-row .filter-date-input {
    /* A date is a date's width, not the panel's. */
    flex: 0 1 auto;
    width: 11rem;
    min-width: 0;
}

/* The three labelled rows (Sort / Added / Played) share one label style, and one
   width, so their controls start at the same x rather than stepping in and out. */
.filter-row-label {
    flex: 0 0 auto;
    min-width: 44px;
    font-size: 0.85rem;
    opacity: 0.75;
    white-space: nowrap;
}

/* The trigger inside .inst-select is the visible box, so stretching the wrapper is
   not enough: without this the droplist keeps its natural height inside a taller
   row and the direction button beside it looks a size too big. */
.filter-sort-row .inst-select,
.filter-sort-row .inst-select-trigger,
.filter-sort-row .filter-sort-direction-btn {
    height: 100%;
}

.filter-sort-row .filter-sort-direction-btn {
    padding: 8px 10px;
    font-size: 14px;
}
