:root {
    color-scheme: dark;

    --background: #090c12;
    --surface: #141923;
    --surface-raised: #1a202b;
    --surface-hover: #202735;
    --border: rgba(255, 255, 255, 0.09);
    --border-strong: rgba(255, 255, 255, 0.15);

    --text: #f4f7fb;
    --muted: #9ba6b6;
    --dim: #6f7a8b;

    --green: #48d487;
    --green-soft: rgba(72, 212, 135, 0.15);

    --blue: #5ca0ff;
    --blue-soft: rgba(92, 160, 255, 0.15);

    --orange: #ffad45;
    --orange-soft: rgba(255, 173, 69, 0.15);

    --purple: #a083ff;
    --purple-soft: rgba(160, 131, 255, 0.15);

    --red: #ff6575;
    --red-soft: rgba(255, 101, 117, 0.15);

    --shadow: 0 20px 55px rgba(0, 0, 0, 0.3);
}

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
    background: var(--background);
}

body {
    min-height: 100vh;
    margin: 0;
    background:
        radial-gradient(
            circle at 15% -10%,
            rgba(70, 120, 255, 0.14),
            transparent 34%
        ),
        radial-gradient(
            circle at 95% 5%,
            rgba(150, 90, 255, 0.12),
            transparent 33%
        ),
        var(--background);
    color: var(--text);
    font-family:
        Inter,
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        sans-serif;
}

button,
input {
    font: inherit;
}

button {
    color: inherit;
}

.app-shell {
    width: min(1380px, 100%);
    margin: 0 auto;
    padding: 20px 22px 44px;
}

.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    padding-bottom: 20px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 13px;
}

.brand-disc {
    width: 45px;
    height: 45px;
    border: 1px solid rgba(160, 131, 255, 0.45);
    border-radius: 50%;
    background:
        radial-gradient(
            circle,
            #090c12 0 13%,
            transparent 14%
        ),
        repeating-radial-gradient(
            circle,
            transparent 0 6px,
            rgba(255, 255, 255, 0.08) 7px 8px
        ),
        conic-gradient(
            #765cff,
            #4da2ff,
            #45d4b0,
            #a083ff,
            #765cff
        );
    box-shadow:
        0 0 25px rgba(120, 95, 255, 0.28),
        inset 0 0 16px rgba(255, 255, 255, 0.16);
}

.eyebrow {
    margin-bottom: 3px;
    color: var(--purple);
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 0.15em;
    text-transform: uppercase;
}

h1 {
    margin: 0;
    font-size: 30px;
    letter-spacing: -0.04em;
}

h2 {
    margin: 0;
    font-size: 20px;
    letter-spacing: -0.025em;
}

.header-status {
    display: flex;
    align-items: center;
    gap: 9px;
    color: var(--muted);
    font-size: 13px;
}

.live-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--green);
    box-shadow: 0 0 0 5px rgba(72, 212, 135, 0.1);
}

.main-tabs {
    display: inline-flex;
    gap: 5px;
    margin-bottom: 16px;
    padding: 5px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: rgba(16, 21, 30, 0.88);
}

.main-tab {
    min-height: 37px;
    padding: 8px 15px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    font-size: 13px;
    font-weight: 700;
}

.main-tab:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text);
}

.main-tab.active {
    background:
        linear-gradient(
            135deg,
            rgba(92, 160, 255, 0.23),
            rgba(160, 131, 255, 0.2)
        );
    color: #ffffff;
}

.tab-panel {
    display: none;
}

.tab-panel.active {
    display: block;
}

.stats {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
    margin-bottom: 14px;
}

.stat {
    position: relative;
    display: flex;
    align-items: center;
    gap: 14px;
    min-height: 104px;
    padding: 17px;
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: 14px;
    background:
        linear-gradient(
            145deg,
            rgba(255, 255, 255, 0.035),
            transparent
        ),
        rgba(20, 25, 35, 0.95);
    box-shadow: var(--shadow);
}

.stat-icon {
    display: grid;
    width: 40px;
    height: 40px;
    flex: 0 0 auto;
    place-items: center;
    border-radius: 11px;
    font-weight: 900;
}

.uploaded-stat .stat-icon {
    background: var(--green-soft);
    color: var(--green);
}

.owned-stat .stat-icon {
    background: var(--blue-soft);
    color: var(--blue);
}

.warning-stat .stat-icon {
    background: var(--orange-soft);
    color: var(--orange);
}

.number {
    display: block;
    margin-bottom: 2px;
    font-size: 34px;
    line-height: 1;
    letter-spacing: -0.04em;
}

.label {
    display: block;
    font-size: 13px;
    font-weight: 750;
}

.stat small {
    display: block;
    margin-top: 3px;
    color: var(--dim);
    font-size: 11px;
}

.overview-card,
.library-card {
    border: 1px solid var(--border);
    border-radius: 17px;
    background:
        linear-gradient(
            145deg,
            rgba(255, 255, 255, 0.025),
            transparent 55%
        ),
        rgba(20, 25, 35, 0.94);
    box-shadow: var(--shadow);
}

.overview-card {
    padding: 20px;
}

.card-heading {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 15px;
    margin-bottom: 17px;
}

.tracked-count {
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: 999px;
    color: var(--muted);
    font-size: 11px;
}

.chart-layout {
    display: grid;
    grid-template-columns: minmax(200px, 0.8fr) minmax(260px, 1fr);
    align-items: center;
    gap: 28px;
    max-width: 720px;
    margin: 0 auto;
}

.dvd-chart {
    position: relative;
    width: min(230px, 100%);
    aspect-ratio: 1;
    margin: auto;
}

.chart-svg {
    display: block;
    width: 100%;
    height: 100%;
    overflow: visible;
    transform: rotate(-90deg);
}

.chart-track,
.chart-segment {
    fill: none;
    stroke-width: 24;
}

.chart-track {
    stroke: rgba(255, 255, 255, 0.06);
}

.chart-segment {
    stroke-linecap: butt;
}

.chart-uploaded {
    stroke: var(--green);
}

.chart-owned {
    stroke: var(--blue);
}

.chart-missing {
    stroke: var(--orange);
}

.chart-center {
    position: absolute;
    top: 50%;
    left: 50%;
    display: grid;
    width: 126px;
    height: 126px;
    place-content: center;
    border: 1px solid var(--border);
    border-radius: 50%;
    background: #111620;
    text-align: center;
    transform: translate(-50%, -50%);
}

.chart-center strong {
    font-size: 30px;
    line-height: 1;
}

.chart-center span {
    margin-top: 5px;
    color: var(--muted);
    font-size: 10px;
}

.chart-legend {
    display: grid;
    gap: 9px;
}

.legend-row {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 10px;
    min-height: 48px;
    padding: 9px 11px;
    border: 1px solid transparent;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.027);
}

.legend-row:hover {
    border-color: var(--border);
    background: rgba(255, 255, 255, 0.045);
}

.legend-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

.legend-dot.green {
    background: var(--green);
}

.legend-dot.blue {
    background: var(--blue);
}

.legend-dot.orange {
    background: var(--orange);
}

.legend-name {
    overflow: hidden;
    color: var(--muted);
    font-size: 12px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.library-card {
    overflow: hidden;
}

.library-toolbar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 11px;
    border-bottom: 1px solid var(--border);
}

.search-wrapper {
    position: relative;
    min-width: 250px;
    flex: 1;
}

.search-icon {
    position: absolute;
    top: 50%;
    left: 12px;
    color: var(--dim);
    font-size: 19px;
    transform: translateY(-52%);
}

#search {
    width: 100%;
    height: 39px;
    padding: 0 38px;
    border: 1px solid var(--border);
    border-radius: 9px;
    outline: none;
    background: rgba(8, 11, 17, 0.65);
    color: var(--text);
    font-size: 13px;
}

#search:focus {
    border-color: rgba(92, 160, 255, 0.55);
    box-shadow: 0 0 0 3px rgba(92, 160, 255, 0.1);
}

#clearSearch {
    position: absolute;
    top: 50%;
    right: 8px;
    width: 25px;
    height: 25px;
    padding: 0;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--dim);
    cursor: pointer;
    font-size: 18px;
    transform: translateY(-50%);
}

.filters {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.filter {
    height: 34px;
    padding: 0 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.025);
    color: var(--muted);
    cursor: pointer;
    font-size: 11px;
    font-weight: 700;
}

.filter:hover {
    color: var(--text);
}

.filter.active {
    border-color: rgba(92, 160, 255, 0.35);
    background: var(--blue-soft);
    color: #dceaff;
}

.result-bar {
    min-height: 32px;
    padding: 8px 13px;
    border-bottom: 1px solid var(--border);
    color: var(--dim);
    font-size: 10px;
}

.result-bar strong {
    color: var(--muted);
}

.table-wrapper {
    max-height: calc(100vh - 230px);
    overflow: auto;
    scrollbar-color: #30394a transparent;
    scrollbar-width: thin;
}

table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
}

thead {
    position: sticky;
    z-index: 5;
    top: 0;
    background: rgba(20, 25, 35, 0.97);
}

th {
    height: 34px;
    padding: 0 13px;
    border-bottom: 1px solid var(--border-strong);
    color: var(--dim);
    font-size: 9px;
    font-weight: 800;
    letter-spacing: 0.12em;
    text-align: left;
    text-transform: uppercase;
}

th:first-child {
    width: 52%;
}

th:last-child {
    width: 48%;
}

td {
    height: 36px;
    padding: 4px 13px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.047);
    vertical-align: middle;
}

tbody tr:hover {
    background: rgba(255, 255, 255, 0.035);
}

.movie-title {
    display: flex;
    align-items: center;
    gap: 9px;
    min-width: 0;
    overflow: hidden;
    color: #e8edf5;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
}

.movie-title > span:last-child {
    overflow: hidden;
    text-overflow: ellipsis;
}

.movie-disc {
    width: 14px;
    height: 14px;
    flex: 0 0 auto;
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 50%;
    background:
        radial-gradient(
            circle,
            #0c1017 0 17%,
            transparent 18%
        ),
        conic-gradient(
            #5965a8,
            #61969f,
            #7265a8,
            #5965a8
        );
}

.status-cell {
    overflow: hidden;
    white-space: nowrap;
}

.badge {
    display: inline-flex;
    align-items: center;
    height: 23px;
    margin: 2px 4px 2px 0;
    padding: 0 7px;
    border: 1px solid transparent;
    border-radius: 999px;
    font-size: 9px;
    font-weight: 750;
    white-space: nowrap;
}

.uploaded-badge {
    border-color: rgba(72, 212, 135, 0.16);
    background: var(--green-soft);
    color: #74e7a6;
}

.owned-badge {
    border-color: rgba(92, 160, 255, 0.16);
    background: var(--blue-soft);
    color: #85b9ff;
}

.dvd-badge {
    border-color: rgba(160, 131, 255, 0.2);
    background: var(--purple-soft);
    color: #c9baff;
}

.bluray-badge {
    border-color: rgba(62, 174, 255, 0.2);
    background: rgba(62, 174, 255, 0.15);
    color: #82c9ff;
}

.unknown-badge {
    border-color: rgba(255, 255, 255, 0.12);
    background: rgba(255, 255, 255, 0.07);
    color: var(--muted);
}

.mismatch-badge {
    border-color: rgba(255, 101, 117, 0.24);
    background: var(--red-soft);
    color: #ff929d;
}

.missing-sheet-badge {
    border-color: rgba(255, 173, 69, 0.2);
    background: var(--orange-soft);
    color: #ffc374;
}

.empty-state {
    padding: 60px 20px;
    color: var(--muted);
    text-align: center;
}

@media (max-width: 850px) {
    .library-toolbar {
        align-items: stretch;
        flex-direction: column;
    }

    .filters {
        display: grid;
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }

    .filter {
        min-width: 0;
        padding: 0 5px;
    }
}

@media (max-width: 650px) {
    .app-shell {
        padding: 10px 8px 22px;
    }

    .app-header {
        padding-bottom: 13px;
    }

    .brand {
        gap: 9px;
    }

    .brand-disc {
        width: 36px;
        height: 36px;
    }

    h1 {
        font-size: 21px;
    }

    .eyebrow {
        font-size: 8px;
    }

    .header-status {
        display: none;
    }

    .main-tabs {
        display: grid;
        width: 100%;
        grid-template-columns: 1fr 1fr;
        margin-bottom: 9px;
    }

    .main-tab {
        min-height: 33px;
        padding: 5px;
        font-size: 11px;
    }

    .stats {
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 6px;
        margin-bottom: 8px;
    }

    .stat {
        display: block;
        min-height: 82px;
        padding: 9px 6px;
        text-align: center;
    }

    .stat-icon {
        width: 25px;
        height: 25px;
        margin: 0 auto 5px;
        border-radius: 7px;
        font-size: 11px;
    }

    .number {
        font-size: 22px;
    }

    .label {
        font-size: 9px;
    }

    .stat small {
        display: none;
    }

    .overview-card {
        padding: 12px;
        border-radius: 13px;
    }

    .chart-layout {
        grid-template-columns: 125px minmax(0, 1fr);
        gap: 9px;
    }

    .dvd-chart {
        width: 125px;
    }

    .chart-center {
        width: 70px;
        height: 70px;
    }

    .chart-center strong {
        font-size: 19px;
    }

    .chart-center span {
        font-size: 7px;
    }

    .legend-row {
        min-height: 36px;
        padding: 5px 7px;
    }

    .legend-name {
        font-size: 8px;
    }

    .legend-row strong {
        font-size: 11px;
    }

    .library-toolbar {
        gap: 6px;
        padding: 7px;
    }

    .search-wrapper {
        min-width: 0;
    }

    #search {
        height: 34px;
        font-size: 11px;
    }

    .filters {
        gap: 4px;
    }

    .filter {
        height: 29px;
        font-size: 8px;
    }

    .result-bar {
        min-height: 27px;
        padding: 6px 8px;
        font-size: 8px;
    }

    .table-wrapper {
        max-height: calc(100vh - 190px);
    }

    thead {
        display: none;
    }

    table,
    tbody,
    tr,
    td {
        display: block;
        width: 100%;
    }

    tbody tr {
        min-height: 47px;
        padding: 6px 8px;
        border-bottom: 1px solid rgba(255, 255, 255, 0.055);
    }

    td {
        height: auto;
        padding: 0;
        border: 0;
    }

    .movie-title {
        gap: 7px;
        font-size: 10.5px;
        line-height: 1.25;
    }

    .movie-disc {
        width: 12px;
        height: 12px;
    }

    .status-cell {
        margin-top: 4px;
        padding-left: 19px;
        overflow: visible;
        white-space: normal;
    }

    .badge {
        height: 18px;
        margin-right: 2px;
        padding: 0 5px;
        font-size: 7px;
    }
}


/* -------------------------------------------------
   Row color coding
-------------------------------------------------- */

#movieTable tbody tr {
    position: relative;
}

#movieTable tbody tr[data-status="uploaded"] {
    background:
        linear-gradient(
            90deg,
            rgba(72, 212, 135, 0.085),
            rgba(72, 212, 135, 0.015) 42%,
            transparent 75%
        );
}

#movieTable tbody tr[data-status="owned"] {
    background:
        linear-gradient(
            90deg,
            rgba(92, 160, 255, 0.1),
            rgba(92, 160, 255, 0.018) 42%,
            transparent 75%
        );
}

#movieTable tbody tr[data-missing-sheet="true"] {
    background:
        linear-gradient(
            90deg,
            rgba(255, 173, 69, 0.11),
            rgba(255, 173, 69, 0.02) 42%,
            transparent 75%
        );
}

#movieTable tbody tr[data-status="uploaded"]::before,
#movieTable tbody tr[data-status="owned"]::before {
    position: absolute;
    top: 4px;
    bottom: 4px;
    left: 0;
    width: 3px;
    border-radius: 0 999px 999px 0;
    content: "";
}

#movieTable tbody tr[data-status="uploaded"]::before {
    background: var(--green);
    box-shadow:
        0 0 10px rgba(72, 212, 135, 0.38);
}

#movieTable tbody tr[data-status="owned"]::before {
    background: var(--blue);
    box-shadow:
        0 0 10px rgba(92, 160, 255, 0.38);
}

#movieTable tbody tr[data-missing-sheet="true"]::before {
    background: var(--orange);
    box-shadow:
        0 0 10px rgba(255, 173, 69, 0.4);
}

#movieTable tbody tr[data-status="uploaded"]:hover {
    background:
        linear-gradient(
            90deg,
            rgba(72, 212, 135, 0.14),
            rgba(72, 212, 135, 0.035) 48%,
            rgba(255, 255, 255, 0.025)
        );
}

#movieTable tbody tr[data-status="owned"]:hover {
    background:
        linear-gradient(
            90deg,
            rgba(92, 160, 255, 0.15),
            rgba(92, 160, 255, 0.035) 48%,
            rgba(255, 255, 255, 0.025)
        );
}


/* -------------------------------------------------
   Mobile auto-hiding navigation
-------------------------------------------------- */

@media (max-width: 650px) {
    .main-tabs {
        position: sticky;
        z-index: 100;
        top: 6px;
        transition:
            transform 180ms ease,
            opacity 180ms ease,
            box-shadow 180ms ease,
            background 180ms ease;
        will-change: transform;
    }

    .main-tabs.menu-floating {
        background: rgba(12, 16, 24, 0.94);
        box-shadow:
            0 10px 28px rgba(0, 0, 0, 0.42),
            0 0 0 1px rgba(255, 255, 255, 0.05);
        backdrop-filter: blur(18px);
        -webkit-backdrop-filter: blur(18px);
    }

    .main-tabs.menu-hidden {
        opacity: 0;
        pointer-events: none;
        transform: translateY(
            calc(-100% - 16px)
        );
    }

    #movieTable tbody tr {
        min-height: 43px;
        padding: 5px 7px 5px 10px;
    }

    #movieTable tbody tr::before {
        top: 5px;
        bottom: 5px;
        width: 2px;
    }

    .movie-title {
        font-size: 10px;
    }

    .status-cell {
        margin-top: 3px;
    }

    .badge {
        height: 17px;
        padding: 0 4px;
        font-size: 6.8px;
    }
}


/* -------------------------------------------------
   Lazy-loading states
-------------------------------------------------- */

.overview-loading,
.table-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 11px;
    min-height: 220px;
    color: var(--muted);
    font-size: 12px;
}

.table-loading {
    min-height: 320px;
}

.loading-spinner {
    width: 22px;
    height: 22px;
    flex: 0 0 auto;
    border: 3px solid rgba(255, 255, 255, 0.1);
    border-top-color: var(--purple);
    border-radius: 50%;
    animation: loading-spin 750ms linear infinite;
}

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

.loading-dot {
    background: var(--blue);
    animation: loading-pulse 1.2s ease-in-out infinite;
}

.error-dot {
    background: var(--red);
    box-shadow: 0 0 0 5px rgba(255, 101, 117, 0.1);
}

@keyframes loading-pulse {
    0%,
    100% {
        opacity: 0.45;
        transform: scale(0.8);
    }

    50% {
        opacity: 1;
        transform: scale(1);
    }
}

.skeleton-number {
    color: transparent;
}

.skeleton-number::after {
    display: block;
    width: 52px;
    height: 27px;
    border-radius: 7px;
    background:
        linear-gradient(
            90deg,
            rgba(255, 255, 255, 0.05),
            rgba(255, 255, 255, 0.12),
            rgba(255, 255, 255, 0.05)
        );
    background-size: 200% 100%;
    content: "";
    animation: skeleton-shimmer 1.3s linear infinite;
}

@keyframes skeleton-shimmer {
    from {
        background-position: 200% 0;
    }

    to {
        background-position: -200% 0;
    }
}

.load-error {
    display: grid;
    min-height: 220px;
    padding: 30px;
    place-content: center;
    gap: 7px;
    color: var(--muted);
    text-align: center;
}

.load-error strong {
    color: var(--red);
    font-size: 16px;
}

.load-error span {
    max-width: 600px;
    font-size: 11px;
    line-height: 1.5;
}

.retry-button {
    width: fit-content;
    min-height: 34px;
    margin: 8px auto 0;
    padding: 0 15px;
    border: 1px solid rgba(92, 160, 255, 0.3);
    border-radius: 8px;
    background: var(--blue-soft);
    color: #cfe2ff;
    cursor: pointer;
    font-size: 11px;
    font-weight: 700;
}

.retry-button:hover {
    border-color: rgba(92, 160, 255, 0.55);
    background: rgba(92, 160, 255, 0.22);
}

.filter:disabled,
#search:disabled {
    cursor: wait;
    opacity: 0.52;
}

[hidden] {
    display: none !important;
}

@media (max-width: 650px) {
    .overview-loading {
        min-height: 150px;
    }

    .table-loading {
        min-height: 250px;
    }

    .loading-spinner {
        width: 18px;
        height: 18px;
    }
}
