/* ── Hide scrollbars on mobile only ────────────────────────────── */
@media (max-width: 767px) {
    * { scrollbar-width: none; -ms-overflow-style: none; }
    *::-webkit-scrollbar { display: none; }
}
@media (min-width: 768px) {
    * { scrollbar-width: auto; -ms-overflow-style: auto; }
    *::-webkit-scrollbar { display: unset; }
}

:root {
    --primary: #6366f1;
    --primary-dark: #4338ca;
    --secondary: #64748b;
    --success: #10b981;
    --danger: #ef4444;
    --bg-main: #f8fafc;
    --sidebar-bg: #0f172a;
    --sidebar-text: #94a3b8;
    --sidebar-active: #ffffff;
    --card-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --text-main: #1e293b;
    --text-muted: #64748b;
    /* Clickable text (links) — deeper blue */
    --link-color: #2b7ec8;
    --link-hover-color: #1f5f9a;
    /* Align Bootstrap link utilities with app links */
    --bs-link-color: var(--link-color);
    --bs-link-hover-color: var(--link-hover-color);
    --bs-link-color-rgb: 43, 126, 200;
}

html,
body {
    font-family: 'Sitka Small', Sitka, serif;
    background-color: var(--bg-main);
    color: var(--text-main);
    height: 100%;
    overflow: hidden;
}

h1, h2, h3, h4, h5, h6, .card-title, .fw-bold, .nav-link {
    font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif !important;
}

a,
.btn-link {
    color: var(--link-color);
    text-decoration: none;
    transition: color 0.2s ease;
}

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

/* Utility classes on <a> (e.g. text-dark) win in Bootstrap — force link tint for clickable text */
main a.text-dark,
main a.text-secondary,
main a.text-body,
.modal a.text-dark,
.modal a.text-secondary,
.modal a.text-body,
#blazor-error-ui a {
    color: var(--link-color) !important;
}

main a.text-dark:hover,
main a.text-secondary:hover,
main a.text-body:hover,
.modal a.text-dark:hover,
.modal a.text-secondary:hover,
.modal a.text-body:hover,
#blazor-error-ui a:hover {
    color: var(--link-hover-color) !important;
}

/* Keep semantic link colors when explicitly set */
a.text-danger,
.btn-link.text-danger,
main a.text-danger,
.modal a.text-danger {
    color: var(--bs-danger) !important;
}

a.text-danger:hover,
.btn-link.text-danger:hover {
    filter: brightness(0.92);
}

.btn-primary {
    background-color: var(--primary);
    border-color: var(--primary);
}

.btn-primary:hover {
    background-color: var(--primary-dark);
    border-color: var(--primary-dark);
}

.btn:focus,
.btn:active:focus,
.btn-link.nav-link:focus,
.form-control:focus,
.form-check-input:focus {
    box-shadow: 0 0 0 0.1rem white, 0 0 0 0.25rem #258cfb;
}

.content {
    padding-top: 0.5rem;
}

.valid.modified:not([type=checkbox]) {
    outline: 1px solid #26b050;
}

.invalid {
    outline: 1px solid red;
}

.validation-message {
    color: red;
}

#blazor-error-ui {
    color-scheme: light only;
    background: lightyellow;
    bottom: 0;
    box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
    box-sizing: border-box;
    display: none;
    left: 0;
    padding: 0.6rem 1.25rem 0.7rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
}

#blazor-error-ui .dismiss {
    cursor: pointer;
    position: absolute;
    right: 0.75rem;
    top: 0.5rem;
}

.blazor-error-boundary {
    background: url(data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNTYiIGhlaWdodD0iNDkiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIG92ZXJmbG93PSJoaWRkZW4iPjxkZWZzPjxjbGlwUGF0aCBpZD0iY2xpcDAiPjxyZWN0IHg9IjIzNSIgeT0iNTEiIHdpZHRoPSI1NiIgaGVpZ2h0PSI0OSIvPjwvY2xpcFBhdGg+PC9kZWZzPjxnIGNsaXAtcGF0aD0idXJsKCNjbGlwMCkiIHRyYW5zZm9ybT0idHJhbnNsYXRlKC0yMzUgLTUxKSI+PHBhdGggZD0iTTI2My41MDYgNTFDMjY0LjcxNyA1MSAyNjUuODEzIDUxLjQ4MzcgMjY2LjYwNiA1Mi4yNjU4TDI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LjMwMDUgMjY2LjExNiA4Ni4wNTQ3IDI2My41NzYgODYuMDU0N1oiIGZpbGw9IiNGRkU1MDAiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPjwvZz48L3N2Zz4=) no-repeat 1rem/1.8rem, #b32121;
    padding: 1rem 1rem 1rem 3.7rem;
    color: white;
}

.blazor-error-boundary::after {
    content: "An error has occurred."
}

::-webkit-scrollbar {
    width: 16px;
}
::-webkit-scrollbar-track {
    background: #f1f1f1;
}
::-webkit-scrollbar-thumb {
    background: #bbb;
    border-radius: 8px;
    border: 3px solid #f1f1f1;
}

.loading-progress {
    position: absolute;
    display: block;
    width: 8rem;
    height: 8rem;
    inset: 20vh 0 auto 0;
    margin: 0 auto 0 auto;
}

.loading-progress circle {
    fill: none;
    stroke: #e0e0e0;
    stroke-width: 0.6rem;
    transform-origin: 50% 50%;
    transform: rotate(-90deg);
}

.loading-progress circle:last-child {
    stroke: #1b6ec2;
    stroke-dasharray: calc(3.141 * var(--blazor-load-percentage, 0%) * 0.8), 500%;
    transition: stroke-dasharray 0.05s ease-in-out;
}

.loading-progress-text {
    position: absolute;
    text-align: center;
    font-weight: bold;
    inset: calc(20vh + 3.25rem) 0 auto 0.2rem;
}

.loading-progress-text:after {
    content: var(--blazor-load-percentage-text, "Loading");
}

code {
    color: #c02d76;
}

.form-floating>.form-control-plaintext::placeholder,
.form-floating>.form-control::placeholder {
    color: var(--bs-secondary-color);
    text-align: end;
}

.form-floating>.form-control-plaintext:focus::placeholder,
.form-floating>.form-control:focus::placeholder {
    text-align: start;
}

/* --- Sidebar Overrides --- */
.sidebar.d-none.d-sm-flex, .sidebar:not(.mobile-bottom-nav) {
    background-color: var(--sidebar-bg) !important;
}

.sidebar .nav-item a {
    color: var(--sidebar-text) !important;
    border-radius: 0.5rem;
    margin: 0.25rem 0.75rem;
}

.sidebar .nav-item a.active {
    background-color: rgba(255, 255, 255, 0.1) !important;
    color: var(--sidebar-active) !important;
}

.sidebar .nav-item a:hover:not(.active) {
    background-color: rgba(255, 255, 255, 0.05) !important;
    color: var(--sidebar-active) !important;
}

/* --- Table & Card Refinements --- */
.card {
    border: none !important;
    box-shadow: var(--card-shadow);
}

.table-hover tbody tr:hover {
    background-color: #f1f5f9 !important; /* Slate 100 */
}

.table thead th {
    background-color: #f8fafc !important; /* Slate 50 */
    color: var(--secondary) !important;
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.05em;
    border-bottom: 2px solid #e2e8f0 !important;
}

/* --- Badges --- */
.badge.bg-secondary {
    background-color: var(--secondary) !important;
}

.badge.bg-dark {
    background-color: var(--sidebar-bg) !important;
}

/* --- Hover Actions --- */
.show-on-row-hover {
    opacity: 0;
}

tr:hover .show-on-row-hover {
    opacity: 1;
}

/* --- Row Striping --- */
.table tbody tr:nth-child(even) > td {
    background-color: rgba(0, 0, 0, 0.05) !important;
}

.show-on-row-hover:focus {
    opacity: 1;
}
/* --- Tracking Pill Hover (+/- buttons) --- */
.show-on-pill-hover {
    opacity: 0;
}

.tracking-pill:hover .show-on-pill-hover {
    opacity: 1;
}

.show-on-pill-hover:focus {
    opacity: 1;
}

/* ── MobileNav overrides — ensure no global rules bleed in ── */
.mob-item,
.mob-item:hover,
.mob-item:focus,
.mob-item.active {
    color: rgba(255,255,255,0.65) !important;
    background-image: none !important;
    border: none !important;
    margin: 0 !important;
}
.mob-item.active,
.mob-item:hover {
    color: #fff !important;
    background-color: rgba(255,255,255,0.15) !important;
}
.mob-item i {
    font-size: 1.3rem !important;
    margin: 0 !important;
    top: 0 !important;
    width: auto !important;
    height: auto !important;
    background-image: none !important;
}
.mob-item span {
    font-size: 0.55rem !important;
    color: inherit !important;
    margin: 0 !important;
}

/* ══════════════════════════════════════════════════════════════
   PAGE SHELL — sticky toolbar + scrollable content
   Used by: Watched, Watching, Watchlist, Search pages
   ══════════════════════════════════════════════════════════════ */

/* Strip the article padding for pages that use page-shell */
article.content:has(.page-shell) {
    padding: 0 !important;
    margin: 0 !important;
}

.page-shell {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 67px); /* 67px = search bar height */
    overflow: hidden;
}

/* ── Toolbar base ───────────────────────────────────────────── */
.toolbar-primary,
.toolbar-actions {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 2px;
    padding: 0 10px;
    background: #fff;
    border-bottom: 1px solid #e8eaed;
    min-height: 44px;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    position: relative;
    z-index: 10;
}
.toolbar-primary::-webkit-scrollbar,
.toolbar-actions::-webkit-scrollbar { display: none; }

.toolbar-primary {
    box-shadow: 0 1px 0 #e8eaed;
}

/* ── Action bar (edit/selection) ────────────────────────────── */
.toolbar-actions {
    background: #f8faff;
    border-bottom: 1px solid #d0d9ff;
    min-height: 40px;
    transition: background 0.2s, border-color 0.2s;
    gap: 4px;
}
.toolbar-actions.has-selection {
    background: #eef2ff;
    border-bottom-color: #818cf8;
}

/* ── Toolbar buttons ────────────────────────────────────────── */
.tb-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 5px 10px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: #555;
    font-size: 0.82rem;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.13s, color 0.13s, box-shadow 0.13s;
    flex-shrink: 0;
    line-height: 1.3;
}
.tb-btn:hover {
    background: #f1f3f4;
    color: #111;
}
.tb-btn:active { background: #e8eaed; }

.tb-btn.active {
    background: #1a1a2e;
    color: #fff;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.tb-btn.active:hover { background: #2d2d4a; }

/* Sort buttons — lighter active state */
.tb-btn.tb-btn-sort.sorted {
    background: #e8eaed;
    color: #111;
    font-weight: 600;
}
.tb-btn.tb-btn-sort.sorted:hover { background: #dde1e7; }

/* Action buttons */
.tb-btn.tb-btn-success { color: #15803d; }
.tb-btn.tb-btn-success:hover { background: #dcfce7; }
.tb-btn.tb-btn-primary { color: #1d4ed8; }
.tb-btn.tb-btn-primary:hover { background: #dbeafe; }
.tb-btn.tb-btn-danger  { color: #dc2626; }
.tb-btn.tb-btn-danger:hover  { background: #fee2e2; }

/* Live = has selection — add subtle fill */
.tb-btn.live.tb-btn-success { background: #f0fdf4; }
.tb-btn.live.tb-btn-primary { background: #eff6ff; }
.tb-btn.live.tb-btn-danger  { background: #fff1f2; }

/* Selection badge */
.sel-badge {
    font-size: 0.75rem;
    font-weight: 700;
    color: #4338ca;
    background: #e0e7ff;
    border-radius: 999px;
    padding: 2px 10px;
    white-space: nowrap;
    margin-right: 4px;
    flex-shrink: 0;
}
.sel-hint {
    font-size: 0.78rem;
    color: #888;
    font-style: italic;
    white-space: nowrap;
    flex-shrink: 0;
}

/* Divider and spacer */
.tb-divider {
    width: 1px;
    height: 22px;
    background: #e2e8f0;
    flex-shrink: 0;
    margin: 0 4px;
}
.tb-spacer { flex: 1; }
.toolbar-primary .tb-spacer { display: none; }

/* Icon only on small screens */
.tb-label {
    display: inline;
}

/* ── Scrollable content area ────────────────────────────────── */
.page-content {
    flex: 1;
    overflow: hidden;
    display: flex;
    min-height: 0;
}

/* When just a scrollable column (no sidebar) */
.page-content.scroll-y {
    overflow-y: auto;
    display: block;
}

/* ── Sticky thead inside page-content scroll ────────────────── */
.sticky-thead thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    background: #f8fafc !important;
}

/* ── Selected row highlight ─────────────────────────────────── */
tr.row-selected td {
    background-color: rgba(99, 102, 241, 0.07) !important;
}

/* ══════════════════════════════════════════════════════════════
   MOBILE  (< 768px)
   ══════════════════════════════════════════════════════════════ */
@media (max-width: 767px) {

    /* Shell height accounts for fixed bottom nav */
    .page-shell {
        height: calc(100vh - 67px - 56px);
    }

    /* ── Toolbar: wrap into two rows ───────────────────────── */
    .toolbar-primary,
    .toolbar-actions {
        justify-content: flex-start;
        flex-wrap: nowrap;
        overflow-x: auto;
        overflow-y: hidden;
        min-height: unset;
        padding: 5px 10px;
        gap: 4px;
        scroll-padding-left: 10px;
        scroll-padding-right: 10px;
    }

    /* Row 1: primary controls (Filters, Edit, Done, view-toggle, spacer, count) */
    .tb-row-primary {
        display: flex;
        align-items: center;
        width: 100%;
        min-height: 40px;
        gap: 2px;
    }

    /* Row 2: sort buttons */
    .tb-row-sort {
        display: flex;
        align-items: center;
        width: 100%;
        min-height: 36px;
        gap: 2px;
        border-top: 1px solid #f0f0f0;
        padding-top: 2px;
        padding-bottom: 2px;
        overflow-x: auto;
        scrollbar-width: none;
    }
    .tb-row-sort::-webkit-scrollbar { display: none; }

    /* Buttons in row 2 are a little smaller */
    .tb-row-sort .tb-btn {
        font-size: 0.76rem;
        padding: 3px 8px;
    }

    /* Always show labels on mobile (rows give enough room) */
    .tb-label { display: inline; }

    /* ── Action bar: wrap freely ───────────────────────────── */
    .toolbar-primary .tb-spacer,
    .toolbar-actions .tb-spacer {
        display: none;
    }

    /* ── Filter panel: stacks above content on mobile ──────── */
    .page-content {
        flex-direction: column;
    }

    .filter-sidebar {
        width: 100% !important;
        border-right: none !important;
        border-bottom: 1px solid rgba(0,0,0,0.08) !important;
        border-bottom-left-radius: 16px;
        border-bottom-right-radius: 16px;
        box-shadow: 0 4px 12px rgba(0,0,0,0.05);
        max-height: 45vh;
        overflow-y: auto;
        flex-shrink: 0;
        z-index: 10;
        position: relative;
    }

    /* Swipe-to-close drag handle */
    .filter-drag-handle {
        display: flex;
        justify-content: flex-end;
        padding: 4px 8px 0 0;
        margin-bottom: 4px;
        cursor: grab;
    }
    .filter-drag-handle span {
        display: block;
        width: 4px;
        height: 36px;
        border-radius: 2px;
        background: rgba(0,0,0,0.18);
    }

    /* Table/card area fills remaining height below the filter panel */
    .content-scroll {
        flex: 1;
        min-height: 0;
        overflow-y: auto;
        overflow-x: hidden;
    }
}

/* ── Tracking pill: shrink dynamically if title cell is narrow ─ */
@container (max-width: 210px) { .tracking-pill { transform: scale(0.85); } }
@container (max-width: 170px) { .tracking-pill { transform: scale(0.70); } }
@container (max-width: 130px) { .tracking-pill { transform: scale(0.55); } }

/* ── Toolbar desktop: max-width + wrap if needed ───────────── */
@media (min-width: 768px) {
    .toolbar-primary {
        max-width: 900px;
        margin-left: auto;
        margin-right: auto;
        margin-top: 8px;
        margin-bottom: 8px;
        border-radius: 12px;
        border: 1px solid #e8eaed;
        box-shadow: 0 2px 6px rgba(0,0,0,0.03);
        overflow-x: visible;
        flex-wrap: wrap;
        row-gap: 4px;
        padding-top: 6px;
        padding-bottom: 6px;
    }

    .toolbar-actions {
        max-width: 900px;
        margin-left: auto;
        margin-right: auto;
        margin-bottom: 12px;
        border-radius: 12px;
        border: 1px solid #d0d9ff;
        box-shadow: 0 2px 6px rgba(0,0,0,0.03);
        overflow-x: visible;
        flex-wrap: wrap;
        row-gap: 4px;
        padding-top: 6px;
        padding-bottom: 6px;
    }

    .toolbar-actions.has-selection {
        border-color: #818cf8;
    }

    .filter-sidebar {
        margin: 16px 0 16px 16px !important;
        border-radius: 12px;
        border: 1px solid #e8eaed !important;
        box-shadow: 0 4px 12px rgba(0,0,0,0.04);
    }
}

/* ── Table max-width ────────────────────────────────────────── */
.content-scroll {
    max-width: unset; /* reset any page-local override */
}
.content-scroll > table {
    max-width: 1200px;
    margin-left: auto;
    margin-right: auto;
}
.page-content.scroll-y > table {
    max-width: 1200px;
    margin-left: auto;
    margin-right: auto;
}

/* ── Table max-width wrapper ────────────────────────────────── */
.table-wrap {
    max-width: 1080px;
    margin: 0 auto;
    width: 100%;
}
.table-wrap--wide {
    max-width: 960px;
}

/* Remove the two-tone stripe on even rows inside table-wrap
   since we no longer have a header to anchor the eye */
.table-wrap .table tbody tr:nth-child(even) > td {
    background-color: transparent !important;
}

/* ── Row meta line (year · date added, shown below title) ───── */
.row-meta {
    display: block;
    font-size: 0.71rem;
    color: #999;
    margin-top: 2px;
    line-height: 1.3;
}
