/* ============================================================
   MediaVault — Stylesheet
   ============================================================ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg: #141414;
    --surface: #1f1f1f;
    --surface2: #2a2a2a;
    --border: #333;
    --text: #e5e5e5;
    --text-muted: #888;
    --accent: #e5a00d;
    --accent-hover: #f0b429;
    --success: #22c55e;
    --error: #ef4444;
    --warning: #f59e0b;
    --plex: #e5a00d;
    --radius: 6px;
    --shadow: 0 2px 8px rgba(0,0,0,0.4);
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 15px;
    line-height: 1.5;
    min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

/* ---- Header ---- */
.site-header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}
.header-inner {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0.75rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}
.site-title {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--accent);
    flex-shrink: 0;
}
.site-nav {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}
.nav-link {
    color: var(--text-muted);
    font-size: 0.9rem;
}
.nav-link:hover { color: var(--text); }
.nav-link-active { color: var(--accent); font-weight: 600; }
.nav-divider {
    width: 1px;
    height: 1.2rem;
    background: var(--border);
    display: inline-block;
}
.nav-user {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
}
.avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    object-fit: cover;
}
.avatar-sm {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    object-fit: cover;
    vertical-align: middle;
}

/* ---- Tier Badges ---- */
.tier-badge {
    font-size: 0.7rem;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 3px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.tier-viewer   { background: #374151; color: #9ca3af; }
.tier-basic    { background: #1e3a5f; color: #60a5fa; }
.tier-trusted  { background: #1a3a2a; color: #4ade80; }
.tier-admin    { background: #3b1f1f; color: #f87171; }

/* ---- Main ---- */
.site-main {
    max-width: 1400px;
    margin: 0 auto;
    padding: 2rem 1.5rem;
}
.page-container { max-width: 1100px; }
.page-container-wide { width: 100%; }

/* ---- Login ---- */
.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--bg);
}
.login-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2.5rem 2rem;
    width: 100%;
    max-width: 400px;
    text-align: center;
    box-shadow: var(--shadow);
}
.login-title {
    font-size: 2rem;
    font-weight: 700;
    color: var(--accent);
    margin-bottom: 0.5rem;
}
.login-subtitle {
    color: var(--text-muted);
    margin-bottom: 1.5rem;
}

/* ---- Alerts ---- */
.alert {
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    font-size: 0.9rem;
}
.alert-error  { background: #3b1f1f; border: 1px solid #7f1d1d; color: #fca5a5; }
.alert-success { background: #1a3a2a; border: 1px solid #14532d; color: #86efac; }

/* ---- Buttons ---- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem 1.25rem;
    border-radius: var(--radius);
    border: none;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    transition: background 0.15s, opacity 0.15s;
    text-decoration: none;
    white-space: nowrap;
}
.btn:disabled, .btn-disabled { opacity: 0.5; cursor: not-allowed; }
.btn-plex {
    background: var(--plex);
    color: #000;
    font-weight: 600;
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
    margin-top: 0.5rem;
}
.btn-plex:hover { background: var(--accent-hover); color: #000; }
.btn-primary { background: var(--accent); color: #000; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); }
.btn-danger { background: #7f1d1d; color: #fca5a5; }
.btn-danger:hover { background: #991b1b; }
.btn-sm { padding: 0.3rem 0.75rem; font-size: 0.8rem; }
.btn-request { background: #1e3a5f; color: #93c5fd; }
.btn-request:hover { background: #1e40af; }
.btn-search { background: #1a3a2a; color: #86efac; }
.btn-search:hover { background: #166534; }
.btn-download { background: #1e3a5f; color: #93c5fd; }
.btn-download:hover { background: #1e40af; }
.btn-download-warned { background: #451a03; color: #fcd34d; border: 1px solid #78350f; }
.btn-download-warned:hover { background: #78350f; }

/* ---- Search ---- */
.search-container { max-width: 900px; }
.search-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
}
.search-header h2 { font-size: 1.5rem; }
.search-box-wrap {
    position: relative;
    margin-bottom: 1.5rem;
}
.search-input {
    width: 100%;
    padding: 0.75rem 1rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 1rem;
    outline: none;
    transition: border-color 0.15s;
}
.search-input:focus { border-color: var(--accent); }
.spinner {
    position: absolute;
    right: 1rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--accent);
    font-size: 1.2rem;
    display: none;
}
.htmx-request .spinner { display: inline; }
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator { display: inline; }

.interactive-loading {
    display: none;
    font-size: 0.8rem;
    color: var(--accent);
    font-style: italic;
    margin-left: 0.25rem;
}
.htmx-request .interactive-loading { display: inline; }

/* ---- Movie Cards ---- */
.search-results { display: flex; flex-direction: column; gap: 1rem; }
.movie-grid    { display: flex; flex-direction: column; gap: 1rem; }

.movie-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    transition: border-color 0.15s;
}
.movie-card:hover { border-color: var(--accent); }
.movie-card-inner {
    display: flex;
    gap: 1rem;
    padding: 1rem;
}
.movie-poster { flex-shrink: 0; width: 70px; }
.movie-poster img {
    width: 70px;
    height: 105px;
    object-fit: cover;
    border-radius: 4px;
}
.no-poster {
    width: 70px;
    height: 105px;
    background: var(--surface2);
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    color: var(--text-muted);
    text-align: center;
}
.movie-info { flex: 1; min-width: 0; }
.movie-title { font-size: 1rem; font-weight: 600; margin-bottom: 0.25rem; }
.movie-year { color: var(--text-muted); font-weight: 400; }
.genre-tags { display: flex; flex-wrap: wrap; gap: 0.25rem; margin-bottom: 0.5rem; }
.genre-tag {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 3px;
    padding: 1px 6px;
    font-size: 0.75rem;
    color: var(--text-muted);
}
.instance-badges { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.5rem; }
.instance-badge {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.3rem 0.6rem;
    font-size: 0.8rem;
}
.inst-label { font-weight: 600; color: var(--accent); }
.inst-status { color: var(--text-muted); }

.status-downloaded .inst-status  { color: var(--success); }
.status-downloading .inst-status { color: var(--warning); }
.status-missing .inst-status     { color: var(--error); }
.status-unavailable .inst-status { color: var(--text-muted); }
.status-not-in-library .inst-status { color: var(--text-muted); }
.status-unmonitored .inst-status { color: var(--text-muted); }

/* ---- Rate Info ---- */
.rate-info { font-size: 0.85rem; }
.rate-remaining { color: var(--success); }
.rate-exhausted { color: var(--error); }
.rate-limited   { color: var(--error); font-size: 0.85rem; }

/* ---- Detail Panel ---- */
.movie-detail-panel {
    border-top: 1px solid var(--border);
    padding: 1rem;
    background: var(--surface2);
}
.detail-view h4 { margin-bottom: 0.75rem; font-size: 0.95rem; color: var(--text-muted); }
.detail-instance {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.75rem;
    margin-bottom: 0.5rem;
}
.detail-instance-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.4rem;
}
.status-pill {
    font-size: 0.75rem;
    padding: 2px 8px;
    border-radius: 99px;
    font-weight: 600;
}
.status-pill.status-downloaded    { background: #14532d; color: #86efac; }
.status-pill.status-downloading   { background: #451a03; color: #fcd34d; }
.status-pill.status-missing       { background: #3b1f1f; color: #fca5a5; }
.status-pill.status-not-in-library { background: var(--surface2); color: var(--text-muted); }
.status-pill.status-unavailable   { background: var(--surface2); color: var(--text-muted); }
.status-pill.status-unmonitored   { background: var(--surface2); color: var(--text-muted); }
.detail-meta  { font-size: 0.85rem; color: var(--text-muted); display: flex; gap: 1rem; flex-wrap: wrap; }
.detail-error { font-size: 0.85rem; color: var(--error); }

/* ================================================================
   RELEASE CARDS  (interactive search results)
   ================================================================ */

.interactive-results { padding: 0.25rem 0; }

.interactive-header { margin-bottom: 1rem; }
.interactive-header h4 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 0.4rem;
}
.interactive-explainer {
    font-size: 0.85rem;
    color: var(--text-muted);
    background: var(--surface2);
    border: 1px solid var(--border);
    border-left: 3px solid var(--accent);
    border-radius: var(--radius);
    padding: 0.6rem 0.9rem;
}

/* Container — vertical stack with visible gap */
.release-cards {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-top: 0.5rem;
}

/* ---- Individual release card ---- */
.rc {
    /* Boxed card with its own background, border, padding */
    background: var(--surface2);
    border: 1px solid var(--border);
    border-left: 4px solid transparent;   /* coloured by modifier below */
    border-radius: var(--radius);
    padding: 0.75rem 1rem;
    width: 100%;
    /* Ensure nothing bleeds outside */
    overflow: hidden;
}

/* Green left border — approved */
.rc-approved {
    border-left-color: #16a34a;
    background: #0d1f0d;
}

/* Orange left border — rejected */
.rc-rejected {
    border-left-color: #c2410c;
    background: #1c1208;
}

/* ---- TOP ROW ---- */
.rc-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    flex-wrap: nowrap;          /* keep button pinned right on desktop */
    margin-bottom: 0.5rem;
}

.rc-top-left {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;            /* badges wrap on narrow screens */
    flex: 1;
    min-width: 0;
}

.rc-top-right {
    flex-shrink: 0;             /* button never shrinks */
    margin-left: auto;
}

/* Quality badge */
.rc-quality {
    display: inline-block;
    background: #14532d;
    border: 1px solid #16a34a;
    color: #86efac;
    font-size: 0.75rem;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 3px;
    white-space: nowrap;
}

/* Size badge */
.rc-size {
    display: inline-block;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 0.75rem;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 3px;
    white-space: nowrap;
}

/* Indexer badge */
.rc-indexer {
    display: inline-block;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 0.75rem;
    padding: 2px 8px;
    border-radius: 3px;
    white-space: nowrap;
    max-width: 140px;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Seeds / Leeches */
.rc-peers {
    display: inline-flex;
    align-items: center;
    gap: 0.2rem;
    font-size: 0.78rem;
    white-space: nowrap;
}
.rc-seeds   { color: var(--success); font-weight: 700; }
.rc-sep     { color: var(--text-muted); }
.rc-leeches { color: var(--error); font-weight: 700; }

/* ---- MIDDLE ROW — release title ---- */
.rc-title {
    font-size: 0.8rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.4;
    /* sits below the top row */
    margin-bottom: 0;
}

/* ---- BOTTOM ROW — rejection section ---- */
.rc-rejection-section {
    margin-top: 0.6rem;
    padding-top: 0.5rem;
    border-top: 1px solid #3b2200;
}

.rc-rejection-toggle {
    background: none;
    border: none;
    cursor: pointer;
    color: #fbbf24;
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0;
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    opacity: 0.9;
    transition: opacity 0.15s;
}
.rc-rejection-toggle:hover { opacity: 1; }

.rc-toggle-icon {
    font-size: 0.55rem;
    line-height: 1;
}

.rc-rejection-body {
    margin-top: 0.4rem;
    padding-left: 0.5rem;
}

.rc-rejection-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}
.rc-rejection-list li {
    font-size: 0.77rem;
    color: #fbbf24;
    padding-left: 1rem;
    position: relative;
    opacity: 0.9;
}
.rc-rejection-list li::before {
    content: "•";
    position: absolute;
    left: 0.25rem;
    color: #92400e;
}

/* Download result feedback */
.download-result { margin-top: 0.75rem; }

/* ---- Library Header ---- */
.library-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 1rem;
    margin-bottom: 1.5rem;
}
.library-header h2 { font-size: 1.5rem; }
.library-count { color: var(--text-muted); font-size: 1rem; font-weight: 400; }
.library-filters {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
    font-size: 0.875rem;
}
.library-filters label {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    color: var(--text-muted);
}

/* ---- Coming Soon ---- */
.coming-soon {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 5rem 2rem;
    text-align: center;
}
.coming-soon-icon { font-size: 4rem; margin-bottom: 1rem; }
.coming-soon h2   { font-size: 2rem; margin-bottom: 0.5rem; }
.coming-soon-text {
    font-size: 1.25rem;
    color: var(--accent);
    font-weight: 600;
    margin-bottom: 0.5rem;
}
.coming-soon-sub { color: var(--text-muted); max-width: 400px; }

/* ---- Data Tables ---- */
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}
.data-table th {
    text-align: left;
    padding: 0.6rem 0.75rem;
    background: var(--surface2);
    border-bottom: 2px solid var(--border);
    color: var(--text-muted);
    font-weight: 600;
}
.data-table td {
    padding: 0.6rem 0.75rem;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}
.data-table tr:hover td { background: var(--surface2); }
.detail-cell { max-width: 200px; font-size: 0.8rem; color: var(--text-muted); word-break: break-word; }

/* ---- Result Badges ---- */
.result-badge {
    font-size: 0.75rem;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 99px;
}
.result-success { background: #14532d; color: #86efac; }
.result-failure { background: #3b1f1f; color: #fca5a5; }

/* ---- Admin ---- */
.admin-section {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}
.admin-section h3 {
    font-size: 1.1rem;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border);
}
.admin-form { display: flex; flex-direction: column; gap: 0.75rem; max-width: 600px; }
.form-row   { display: flex; flex-direction: column; gap: 0.25rem; }
.form-row label { font-size: 0.85rem; color: var(--text-muted); }
.form-hint  { font-size: 0.78rem; color: var(--text-muted); margin-top: 0.15rem; }
.text-muted { color: var(--text-muted); }
.form-input {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    padding: 0.5rem 0.75rem;
    font-size: 0.9rem;
    outline: none;
    transition: border-color 0.15s;
}
.form-input:focus { border-color: var(--accent); }
.form-input-sm {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    padding: 0.25rem 0.5rem;
    font-size: 0.85rem;
    outline: none;
}
.form-select-sm {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    padding: 0.25rem 0.5rem;
    font-size: 0.85rem;
    outline: none;
}
.inline-form { display: flex; align-items: center; gap: 0.5rem; }

/* ---- Plex Test Section ---- */
.plex-test-section {
    margin-top: 1.5rem;
    padding-top: 1.25rem;
    border-top: 1px solid var(--border);
}
.plex-test-section h4 { font-size: 0.95rem; margin-bottom: 0.4rem; }
.plex-test-prompt    { font-size: 0.9rem; }
.plex-servers-result { font-size: 0.9rem; }
.machine-id-code {
    font-family: monospace;
    font-size: 0.82rem;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 3px;
    padding: 2px 6px;
    word-break: break-all;
}

/* ---- Instance Cards ---- */
.instance-card {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    margin-bottom: 1rem;
}
.instance-card-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
    flex-wrap: wrap;
}
.inst-url { font-size: 0.8rem; color: var(--text-muted); }
.quality-label {
    font-size: 0.75rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 3px;
    padding: 1px 6px;
    color: var(--accent);
}
.enabled-badge {
    font-size: 0.75rem;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 99px;
}
.enabled-badge.enabled  { background: #14532d; color: #86efac; }
.enabled-badge.disabled { background: #3b1f1f; color: #fca5a5; }
.instance-edit-form { display: flex; flex-direction: column; gap: 0.5rem; max-width: 500px; }
.add-instance-form {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
}
.add-instance-form h4 { margin-bottom: 0.75rem; font-size: 0.95rem; }

/* ---- Filter Form ---- */
.filter-form {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
    padding: 0.75rem 1rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.875rem;
}
.filter-form label { display: flex; align-items: center; gap: 0.4rem; }

/* ---- Misc ---- */
.no-results { color: var(--text-muted); padding: 1rem 0; }
.error   { color: var(--error);   font-size: 0.875rem; }
.success { color: var(--success); font-size: 0.875rem; }
.spinner { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: translateY(-50%) rotate(360deg); } }

/* ================================================================
   RESPONSIVE
   ================================================================ */
@media (max-width: 600px) {
    .header-inner {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }
    .site-nav { gap: 0.6rem; font-size: 0.85rem; }

    .movie-card-inner { gap: 0.75rem; }
    .movie-poster { width: 55px; }
    .movie-poster img { width: 55px; height: 82px; }
    .no-poster        { width: 55px; height: 82px; }
    .instance-badges  { flex-direction: column; align-items: flex-start; }

    /* Release cards on mobile: allow top-row to wrap so button
       drops below the badges but stays right-aligned */
    .rc-top {
        flex-wrap: wrap;
        align-items: flex-start;
    }
    .rc-top-left  { width: 100%; }
    .rc-top-right {
        width: 100%;
        display: flex;
        justify-content: flex-end;
        margin-top: 0.4rem;
    }
    .rc-title { white-space: normal; }   /* allow wrapping on very small screens */

    .library-header   { flex-direction: column; align-items: flex-start; }
    .library-filters  { width: 100%; }
    .admin-form       { max-width: 100%; }
    .instance-edit-form { max-width: 100%; }
    .filter-form      { flex-direction: column; align-items: flex-start; }
}
