/* ===== Theme variables ===== */
:root {
    --bg: #ffffff;
    --text: #000000;
    --border: #cccccc;
    --th-bg: #f0f0f0;
    --th-hover: #e0e0e0;
    --text-secondary: #555555;
    --text-muted: #aaaaaa;
    --link: #1976d2;
    --active-tab-bg: #ffffff;
    --active-tab-text: #2c3e50;
    --input-bg: #ffffff;
    --card-bg: #ffffff;
    --chip-bg: #1976d2;
    --hover-bg: #e3f2fd;
    --hover-text: #0d0d0d;
}

html.dark {
    color-scheme: dark;
    --bg: #1e1e1e;
    --text: #e0e0e0;
    --border: #3a3a3a;
    --th-bg: #282828;
    --th-hover: #333333;
    --text-secondary: #9e9e9e;
    --text-muted: #555555;
    --link: #64b5f6;
    --active-tab-bg: #1e1e1e;
    --active-tab-text: #e0e0e0;
    --input-bg: #282828;
    --card-bg: #2a2a2a;
    --chip-bg: #1565c0;
    --hover-bg: #1a3a5c;
    --hover-text: #e0e0e0;
}

body {
    font-family: sans-serif;
    margin: 0;
    background-color: var(--bg);
    color: var(--text);
}

/* ===== Navbar ===== */

.navbar {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    background-color: #2c3e50;
    color: white;
    padding: 0.75rem 2rem 0;
    margin-bottom: 1.5rem;
}

.navbar-brand-link {
    text-decoration: none;
    color: inherit;
}

.navbar-brand {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 0.65rem;
    padding-bottom: 0.75rem;
}

.navbar-logo {
    height: 2.5rem;
    width: auto;
    flex-shrink: 0;
}

.navbar-brand-text {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.navbar-title {
    font-size: 1.1rem;
    font-weight: bold;
    letter-spacing: 0.03em;
}

.navbar-stats {
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.7);
    font-variant-caps: small-caps;
}

.navbar-actions {
    display: flex;
    gap: 0.5rem;
    padding-bottom: 0.75rem;
}

.navbar-btn {
    background-color: transparent;
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.4);
    border-radius: 4px;
    padding: 0.3rem 0.8rem;
    cursor: pointer;
    font-size: 0.9rem;
}

.navbar-btn:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

.navbar-tabs {
    display: flex;
    gap: 0.25rem;
}

.navbar-tab {
    color: rgba(255, 255, 255, 0.75);
    background-color: rgba(255, 255, 255, 0.1);
    text-decoration: none;
    padding: 0.3rem 0.9rem 0.6rem;
    border-radius: 4px 4px 0 0;
    font-size: 0.9rem;
}

.navbar-tab:hover {
    background-color: rgba(255, 255, 255, 0.2);
    color: white;
}

.navbar-tab--active {
    background-color: var(--active-tab-bg);
    color: var(--active-tab-text);
}

/* ===== Navbar three-dot menu ===== */

.navbar-menu {
    position: relative;
    padding-bottom: 0.75rem;
}

.navbar-menu-btn {
    padding: 0.2rem 0.5rem;
    line-height: 0;
}

.navbar-menu-icon {
    width: 20px;
    height: 20px;
    display: block;
}

.navbar-menu-dropdown {
    display: none;
    position: absolute;
    right: 0;
    top: calc(100% + 2px);
    background-color: #2c3e50;
    border: 1px solid rgba(255, 255, 255, 0.25);
    border-radius: 4px;
    min-width: 150px;
    z-index: 200;
    flex-direction: column;
    padding: 0.4rem;
    gap: 0.15rem;
}

.navbar-menu-dropdown.open {
    display: flex;
}

.navbar-menu-item {
    display: block;
    width: 100%;
    text-align: left;
    background: transparent;
    color: rgba(255, 255, 255, 0.85);
    border: none;
    border-radius: 3px;
    padding: 0.4rem 0.7rem;
    font-size: 0.9rem;
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
    box-sizing: border-box;
}

.navbar-menu-item:hover {
    background-color: rgba(255, 255, 255, 0.12);
    color: white;
}

.navbar-menu-divider {
    height: 1px;
    background-color: rgba(255, 255, 255, 0.2);
    margin: 0.25rem 0;
}

.navbar-menu-tabs {
    display: none;
}

@media (max-width: 768px) {
    .navbar-tabs {
        display: none;
    }

    .navbar-menu-tabs {
        display: flex;
        flex-direction: column;
    }
}

/* ===== Controls ===== */

.controls {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    padding: 0 2rem 1rem;
}

.controls-body {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex: 1;
}

.controls-left {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem 1rem;
}

.clear-filters-btn {
    background: transparent;
    border: none;
    color: var(--text);
    cursor: pointer;
    font-size: 1.1rem;
    margin-left: auto;
    padding: 0.2rem 0.4rem;
    opacity: 0.6;
    line-height: 1;
}

.clear-filters-btn:hover {
    opacity: 1;
}

.toggle-indicator {
    display: inline-block;
    width: 1.2em;
    text-align: center;
}

.filters-toggle {
    display: none;
    background: transparent;
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0.35rem 0.8rem;
    font-size: 0.9rem;
    cursor: pointer;
    margin-bottom: 0.5rem;
}

input[type=text],
input[type=number],
select {
    background-color: var(--input-bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 4px;
}

#titleFilter {
    padding: 0.35rem 0.7rem;
    font-size: 0.9rem;
    width: 240px;
}

/* ===== Tag filter ===== */

.tag-filter-wrap {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    min-width: 260px;
}

.tag-input-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

#tagFilterInput {
    flex: 1;
    padding: 0.35rem 0.7rem;
    font-size: 0.9rem;
}

.match-count {
    font-size: 0.8rem;
    color: var(--text-muted, #888);
    white-space: nowrap;
}

.active-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
    min-height: 0;
}

.tag-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    background: var(--chip-bg, #3a7bd5);
    color: #fff;
    border-radius: 12px;
    padding: 0.15rem 0.55rem;
    font-size: 0.8rem;
}

.tag-chip button {
    background: none;
    border: none;
    color: #fff;
    cursor: pointer;
    font-size: 1rem;
    line-height: 1;
    padding: 0;
    opacity: 0.75;
}

.tag-chip button:hover {
    opacity: 1;
}

.tag-suggestions {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--card-bg, #fff);
    border: 1px solid var(--border);
    border-radius: 4px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 100;
    max-height: 260px;
    overflow-y: auto;
}

.tag-suggestion-item {
    padding: 0.4rem 0.75rem;
    font-size: 0.9rem;
    cursor: pointer;
}

.tag-suggestion-item:hover,
.tag-suggestion-item.highlighted {
    background: var(--hover-bg, #e8f0fe);
    color: var(--hover-text, #1a1a1a);
}

.hidden {
    display: none !important;
}

/* ===== Table ===== */

.table-wrapper {
    padding: 0 2rem 2rem;
}

table {
    border-collapse: collapse;
    width: 100%;
    border: 1px solid var(--border);
}

th, td {
    padding: 0.5rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

td:first-child, th:first-child {
    width: 1px;
    padding: 0.25rem 0.5rem;
    white-space: nowrap;
}

th {
    background-color: var(--th-bg);
    font-variant-caps: small-caps;
    position: sticky;
    top: 0;
    z-index: 1;
}

th.sortable {
    cursor: pointer;
    user-select: none;
}

th.sortable:hover {
    background-color: var(--th-hover);
}

th[data-sort="asc"]::after {
    content: ' ▲';
    font-size: 0.75em;
}

th[data-sort="desc"]::after {
    content: ' ▼';
    font-size: 0.75em;
}

/* ===== Lists overview: inline create form ===== */

.new-list-form {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.new-list-form input[type="text"] {
    padding: 0.35rem 0.5rem;
}

/* ===== Misc ===== */

.button-bar {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.comment {
    max-width: 300px;
    font-size: 0.8em;
    cursor: help;
}

.comment-inner {
    display: -webkit-box;
    -webkit-line-clamp: 4;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.game-sub-info {
    font-size: 0.8em;
    color: var(--text-secondary);
}

/* ===== Expandable expansion / contained-game lists (title cell) ===== */

details.expansion-list {
    display: inline-block;
}

details.expansion-list summary {
    cursor: pointer;
    list-style: none;
    display: inline;
}

details.expansion-list summary::-webkit-details-marker {
    display: none;
}

details.expansion-list summary::before {
    content: '▶ ';
    font-size: 0.65em;
    vertical-align: middle;
}

details.expansion-list[open] summary::before {
    content: '▼ ';
}

details.expansion-list ul {
    margin: 0.15rem 0 0 0.8rem;
    padding: 0;
    list-style: disc;
    font-size: 0.8em;
    color: var(--text-secondary);
}

details.expansion-list ul li {
    margin: 0.1rem 0;
}

details.expansion-list ul li a {
    color: var(--text-secondary);
    text-decoration: none;
}

details.expansion-list ul li a:hover {
    text-decoration: underline;
}

/* ===== Collection-notes tags (title cell) ===== */

.game-tags {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    margin-top: 0.2rem;
}

.game-tag {
    display: inline-block;
    font-size: 0.7em;
    padding: 0.1em 0.5em;
    border-radius: 3px;
    white-space: nowrap;
    font-weight: 500;
    cursor: pointer;
}

.game-tag:hover {
    filter: brightness(0.92);
    text-decoration: underline;
}

html.dark .game-tag:hover {
    filter: brightness(1.25);
}

/* box size – neutral slate */
.game-tag-size {
    display: inline-flex;
    align-items: center;
    gap: 0.25em;
    background-color: #e2e8f0;
    color: #334155;
}

.game-tag-icon {
    flex-shrink: 0;
    vertical-align: middle;
}

/* segmentation – moss green */
.game-tag-seg {
    background-color: #dde8d0;
    color: #3a5228;
}

/* category – teal */
.game-tag-cat {
    background-color: #ccfbf1;
    color: #115e59;
}

/* mechanic – violet */
.game-tag-mech {
    background-color: #ede9fe;
    color: #4c1d95;
}

html.dark .game-tag-size {
    background-color: #334155;
    color: #cbd5e1;
}

html.dark .game-tag-seg {
    background-color: #1e2e14;
    color: #9dba7a;
}

html.dark .game-tag-cat {
    background-color: #042f2e;
    color: #5eead4;
}

html.dark .game-tag-mech {
    background-color: #2e1065;
    color: #c4b5fd;
}

.game-detail {
    padding: 1rem;
}

.play-winner {
    font-weight: bold;
}

.bgg-link {
    font-size: 0.5em;
    vertical-align: middle;
}

/* ===== Rating badges ===== */

.rating-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.4em;
    height: 2.4em;
    border-radius: 3px;
    color: white;
    font-weight: bold;
    font-size: 0.9em;
}

/* 10–8: dark → bright green */
.rating-10 {
    background-color: #1a5e20;
}

.rating-9 {
    background-color: #2e7d32;
}

.rating-8 {
    background-color: #4caf50;
}

/* 7–5: bright → dark blue */
.rating-7 {
    background-color: #42a5f5;
}

.rating-6 {
    background-color: #1976d2;
}

.rating-5 {
    background-color: #0d47a1;
}

/* below 5: muted orange */
.rating-low {
    background-color: #bf6c00;
}

/* ===== Filter bar sizing ===== */

.filter-icon {
    flex-shrink: 0;
    vertical-align: middle;
}

/* ===== Filter pills ===== */

.filter-pill-wrap {
    position: relative;
}

.filter-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    background: transparent;
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 0.25rem 0.65rem;
    font-size: 0.85rem;
    cursor: pointer;
    white-space: nowrap;
}

.filter-pill:hover {
    border-color: var(--text-muted, #888);
}

.filter-pill.active {
    background: var(--chip-bg, #3a7bd5);
    color: #fff;
    border-color: transparent;
}

.filter-popover {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    background: var(--card-bg, #fff);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
    padding: 0.75rem;
    z-index: 200;
    min-width: 140px;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.popover-row {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.filter-popover input[type=number] {
    width: 4.5rem;
    padding: 0.25rem 0.4rem;
    font-size: 0.85rem;
}

.filter-popover select {
    padding: 0.25rem 0.4rem;
    font-size: 0.85rem;
    width: 100%;
}

/* ===== Active filter chips row ===== */

.active-chips-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.3rem;
    flex-basis: 100%;
    padding: 0.4rem 0 0.75rem;
    min-height: 0;
}

#activeFilterTags {
    display: contents;
}

/* ===== Icon-only button (used for batch edit header icon) ===== */

.icon-btn {
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
    color: inherit;
}

.icon-btn:hover {
    opacity: 0.7;
}

/* ===== Checkbox selection column ===== */

.col-check {
    width: 2rem;
    text-align: center;
    padding: 0.2rem 0.3rem;
}

/* ===== Batch edit / add-to-list modals ===== */

#batchEditModal,
#addToListModal {
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1.5rem;
    max-width: 480px;
    width: 90%;
    background: var(--bg);
    color: var(--text);
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.35);
}

#batchEditModal::backdrop,
#addToListModal::backdrop {
    background: rgba(0, 0, 0, 0.5);
}

#batchEditModal h2,
#addToListModal h2 {
    margin: 0 0 1.2rem;
    font-size: 1.1rem;
}

.add-to-list-feedback {
    margin: 0.5rem 0 0;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.batch-field {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    margin-bottom: 0.9rem;
}

.batch-field label {
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.batch-field select,
.batch-field input[type="number"],
.batch-field input[type="text"] {
    padding: 0.4rem 0.5rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--bg);
    color: var(--text);
    font-size: 0.9rem;
}

.batch-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    margin-top: 1.2rem;
}

/* ===== Icon table headers ===== */

th.col-icon {
    text-align: center;
    padding: 0.4rem 0.5rem;
}

.col-weight {
    white-space: nowrap;
    text-align: right;
}

/* ===== Last-played two-line date ===== */

.last-played-date {
    display: flex;
    flex-direction: column;
    align-items: center;
    line-height: 1.2;
    white-space: nowrap;
}

.last-played-year {
    font-size: 1.2em;
    color: var(--text-muted);
}

.last-played-day {
    font-weight: bold;
    font-size: 0.85em;
}

/* ===== Thumbnails ===== */

.thumbnail-cell {
    width: 2.5rem;
    padding: 0.25rem 0.5rem;
}

.play-thumbnail {
    display: block;
    width: 2rem;
    height: 2rem;
    object-fit: contain;
}

/* ===== Pagination ===== */

.pagination {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem 0;
}

.page-link {
    font-size: 0.9rem;
    color: var(--link);
    text-decoration: none;
}

.page-link:hover {
    text-decoration: underline;
}

.page-link.disabled {
    color: var(--text-muted);
    pointer-events: none;
}

.page-indicator {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

/* ===== Error page ===== */

.error-content {
    padding: 2rem;
}

/* ===== Mobile layout (≤768px) ===== */

@media (max-width: 768px) {
    .table-wrapper {
        overflow-x: auto;
        padding: 0 0.5rem 1rem;
    }

    .col-players,
    .col-time,
    .col-acquired,
    .col-price,
    .comment-col {
        display: none;
    }

    .controls {
        flex-direction: column;
        align-items: stretch;
        padding: 0 0.5rem 1rem;
    }

    .controls-body {
        flex-direction: column;
        align-items: stretch;
        gap: 0.75rem;
    }

    .controls-body.hidden {
        display: none;
    }

    .controls-left {
        gap: 0.5rem;
    }

    .filter-popover {
        left: auto;
        right: 0;
    }

    .active-chips-row {
        padding: 0 0 0.75rem;
    }

    .pill-label {
        display: none;
    }

    .filters-toggle {
        display: block;
    }
}

/* Sync status banner (issue #237) — fixed toast, shown/hidden by sync-status.js */
.sync-status-banner {
    position: fixed;
    bottom: 1rem;
    right: 1rem;
    z-index: 1000;
    max-width: 22rem;
    padding: 0.6rem 1rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--card-bg);
    color: var(--text);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
    cursor: pointer;
    font-size: 0.9rem;
    overflow-wrap: break-word;
}

.sync-status-banner--running {
    border-left: 4px solid var(--link);
}

.sync-status-banner--success {
    border-left: 4px solid #2e7d32;
}

.sync-status-banner--error {
    border-left: 4px solid #c62828;
}

/* ===== List detail page (issue #202) ===== */

.list-detail-header {
    padding: 0 2rem 1rem;
}

.pre-line {
    white-space: pre-line;
}

.list-description {
    max-width: 60rem;
    margin: 0.5rem 0;
}

.list-detail-actions {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    margin-top: 0.75rem;
}

.numbered-toggle {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

/* Click-to-edit affordance: only elements the server marked editable get the hover hint. */
.editable {
    cursor: pointer;
    border-radius: 4px;
}

.editable:hover {
    outline: 1px dashed var(--border);
    outline-offset: 3px;
}

.edit-placeholder {
    color: var(--text-secondary);
    font-style: italic;
}

.inline-editor {
    width: 100%;
    max-width: 60rem;
    font: inherit;
    padding: 0.35rem 0.7rem;
    background-color: var(--input-bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 4px;
}

textarea.inline-editor {
    min-height: 5rem;
    resize: vertical;
}

/* Rank numbers only appear while the list's numbered flag is on. */
.list-detail:not(.numbered) .entry-rank {
    display: none;
}

.entry-comment-cell {
    width: 40%;
}

/* Same pill look as .game-tag, but static — status is informational, not clickable. */
.status-tag {
    display: inline-block;
    font-size: 0.7em;
    padding: 0.1em 0.5em;
    border-radius: 3px;
    white-space: nowrap;
    font-weight: 500;
    border: 1px solid var(--border);
    color: var(--text-secondary);
}

/* "on N lists" badge in the collection title cell (issue #202) – amber pill,
   tooltip carries the list names, links to the game detail page. */
.list-badge {
    display: inline-block;
    font-size: 0.7em;
    padding: 0.1em 0.5em;
    border-radius: 3px;
    white-space: nowrap;
    font-weight: 500;
    margin-left: 0.35em;
    text-decoration: none;
    background-color: #b2a4c3;
    color: #4b3d93;
}

.list-badge:hover {
    filter: brightness(0.94);
    text-decoration: underline;
}

html.dark .list-badge {
    background-color: #4b3d93;
    color: #b2a4c3;
}

html.dark .list-badge:hover {
    filter: brightness(1.25);
}

/* Drag-and-drop reordering on the list detail page (issue #202) */
.drag-handle-cell {
    width: 1.5rem;
}

.drag-handle {
    cursor: grab;
    color: var(--text-secondary);
    user-select: none;
}

/* SortableJS marks the drop placeholder row while dragging. */
.sortable-ghost {
    opacity: 0.4;
}
