/* Recherche torrents — Design system
   Style : Soft UI Evolution (sombre par défaut, clair pris en charge)
   Typo   : Fira Sans (texte) / Fira Code (données tabulaires : tailles, dates, seed/leech) */

@import url('https://fonts.googleapis.com/css2?family=Fira+Code:wght@400;500;600;700&family=Fira+Sans:wght@300;400;500;600;700&display=swap');

:root {
    color-scheme: light dark;

    /* Échelle d'espacement (4/8pt) */
    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-5: 1.5rem;
    --space-6: 2rem;
    --space-7: 3rem;

    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --radius-pill: 999px;

    --font-sans: 'Fira Sans', system-ui, -apple-system, sans-serif;
    --font-mono: 'Fira Code', ui-monospace, SFMono-Regular, Menlo, monospace;

    --duration: 180ms;
    --ease: cubic-bezier(0.4, 0, 0.2, 1);

    /* Palette — clair */
    --background: #f1f5f9;
    --surface: #ffffff;
    --surface-hover: #f8fafc;
    --border: #e2e8f0;
    --muted: #475569;
    --text: #0f172a;
    --accent: #15803d;
    --accent-strong: #166534;
    --accent-soft: #15803d1a;
    --destructive: #b91c1c;
    --destructive-soft: #b91c1c14;
    --ring: #15803d;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
    --shadow-md: 0 6px 20px rgba(15, 23, 42, 0.08);
    --shadow-lg: 0 16px 40px rgba(15, 23, 42, 0.14);
    --scrim: rgba(15, 23, 42, 0.45);
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --background: #020617;
        --surface: #0f172a;
        --surface-hover: #16213a;
        --border: #263449;
        --muted: #94a3b8;
        --text: #f8fafc;
        --accent: #22c55e;
        --accent-strong: #16a34a;
        --accent-soft: #22c55e26;
        --destructive: #f87171;
        --destructive-soft: #f8717126;
        --ring: #22c55e;
        --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
        --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.45);
        --shadow-lg: 0 20px 48px rgba(0, 0, 0, 0.55);
        --scrim: rgba(0, 0, 0, 0.6);
    }
}

/* Bascule de thème manuelle (voir assets/theme.js) : prime sur la préférence système */
:root[data-theme="dark"] {
    --background: #020617;
    --surface: #0f172a;
    --surface-hover: #16213a;
    --border: #263449;
    --muted: #94a3b8;
    --text: #f8fafc;
    --accent: #22c55e;
    --accent-strong: #16a34a;
    --accent-soft: #22c55e26;
    --destructive: #f87171;
    --destructive-soft: #f8717126;
    --ring: #22c55e;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.45);
    --shadow-lg: 0 20px 48px rgba(0, 0, 0, 0.55);
    --scrim: rgba(0, 0, 0, 0.6);
}

* {
    box-sizing: border-box;
}

html {
    scrollbar-color: var(--border) transparent;
}

::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: var(--radius-pill);
}

::-webkit-scrollbar-track {
    background: transparent;
}

body {
    font-family: var(--font-sans);
    background: var(--background);
    color: var(--text);
    max-width: 1100px;
    margin: 2rem auto;
    padding: 0 1rem;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

a {
    color: var(--accent);
}

h1 {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.01em;
    margin: 0;
}

.section-title {
    margin-top: var(--space-6);
    font-size: 1.15rem;
    font-weight: 600;
}

/* ─── Barre supérieure ──────────────────────────────────────────────────── */

.topbar {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--space-4);
    padding-bottom: var(--space-4);
    margin-bottom: var(--space-5);
    border-bottom: 1px solid var(--border);
}

.logout {
    color: var(--muted);
    font-size: 0.85rem;
    margin-left: var(--space-4);
    text-decoration: none;
    transition: color var(--duration) var(--ease);
}

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

.logout:first-child {
    margin-left: 0;
}

.theme-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.1rem;
    height: 2.1rem;
    margin-left: var(--space-4);
    padding: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--muted);
    cursor: pointer;
    transition: color var(--duration) var(--ease), border-color var(--duration) var(--ease);
}

.theme-toggle:hover {
    color: var(--text);
    border-color: var(--muted);
}

.theme-toggle .icon {
    width: 1.1rem;
    height: 1.1rem;
    margin: 0;
}

/* Icône affichée par défaut selon le thème effectif — en CSS pur, sans dépendre du
   JS (assets/theme.js ne fait plus que basculer l'attribut data-theme au clic). */
.theme-toggle .icon-moon {
    display: none;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .theme-toggle .icon-sun {
        display: none;
    }
    :root:not([data-theme="light"]) .theme-toggle .icon-moon {
        display: inline-block;
    }
}

:root[data-theme="dark"] .theme-toggle .icon-sun {
    display: none;
}

:root[data-theme="dark"] .theme-toggle .icon-moon {
    display: inline-block;
}

:root[data-theme="light"] .theme-toggle .icon-sun {
    display: inline-block;
}

:root[data-theme="light"] .theme-toggle .icon-moon {
    display: none;
}

/* ─── Formulaires ───────────────────────────────────────────────────────── */

.search-form {
    display: flex;
    gap: var(--space-2);
    margin-bottom: var(--space-5);
}

.search-form input[type="text"] {
    flex: 1;
}

input[type="text"],
input[type="password"],
input[type="url"],
select {
    font: inherit;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.55rem 0.7rem;
    transition: border-color var(--duration) var(--ease), box-shadow var(--duration) var(--ease);
}

input[type="text"]:hover,
input[type="password"]:hover,
select:hover {
    border-color: var(--muted);
}

input[type="text"]:focus,
input[type="password"]:focus,
input[type="url"]:focus,
select:focus {
    outline: none;
    border-color: var(--ring);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

select,
button,
.btn,
.btn-send,
.logout,
.badge-plex-check {
    cursor: pointer;
}

.meta {
    color: var(--muted);
    font-size: 0.85rem;
}

.topbar .meta {
    margin-left: var(--space-2);
}

.error {
    color: var(--destructive);
    background: var(--destructive-soft);
    border: 1px solid color-mix(in srgb, var(--destructive) 45%, transparent);
    border-radius: var(--radius-sm);
    padding: var(--space-2) var(--space-3);
    font-size: 0.85rem;
    margin: 0 0 var(--space-4);
}

.error:empty {
    display: none;
}

/* ─── Tableau de résultats ──────────────────────────────────────────────── */

table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
}

th, td {
    border-bottom: 1px solid var(--border);
    padding: var(--space-3) var(--space-4);
    text-align: left;
    font-size: 0.9rem;
}

th {
    color: var(--muted);
    font-weight: 600;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    background: var(--surface-hover);
    position: sticky;
    top: 0;
    z-index: 5;
}

/* Coins arrondis posés directement sur les cellules d'angle plutôt que sur un
   "overflow: hidden" au niveau du tableau : ce dernier clipperait aussi le menu
   d'actions déroulant (voir .actions-menu-list) dès qu'il dépasse du tableau. */
thead th:first-child {
    border-top-left-radius: var(--radius-lg);
}

thead th:last-child {
    border-top-right-radius: var(--radius-lg);
}

tbody tr:last-child td:first-child {
    border-bottom-left-radius: var(--radius-lg);
}

tbody tr:last-child td:last-child {
    border-bottom-right-radius: var(--radius-lg);
}

.icon {
    display: inline-block;
    width: 0.95em;
    height: 0.95em;
    vertical-align: -0.15em;
    margin-right: 0.3em;
    flex-shrink: 0;
}

.stat-group {
    display: inline-flex;
    flex-wrap: wrap;
    gap: var(--space-1);
}

.stat {
    display: inline-flex;
    align-items: center;
    padding: 0.15rem 0.5rem;
    border-radius: var(--radius-pill);
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
    font-size: 0.78rem;
    font-weight: 600;
    white-space: nowrap;
}

.stat .icon {
    margin-right: 0.25em;
}

.stat-seed {
    background: var(--accent-soft);
    color: var(--accent);
}

.stat-leech {
    background: var(--destructive-soft);
    color: var(--destructive);
}

.stat-completed {
    background: var(--border);
    color: var(--muted);
}

tbody tr {
    transition: background-color var(--duration) var(--ease);
}

tbody tr:hover {
    background: var(--surface-hover);
}

tbody tr:last-child td {
    border-bottom: none;
}

td[data-label="Taille"],
td[data-label="Ajouté"] {
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
}

.title-main {
    font-weight: 600;
}

.title-raw {
    color: var(--muted);
    font-size: 0.78rem;
    font-family: var(--font-mono);
    word-break: break-word;
    margin-top: var(--space-1);
}

.title-tags {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-1);
    margin: var(--space-1) 0;
}

.tag {
    display: inline-block;
    background: var(--border);
    color: var(--text);
    border-radius: var(--radius-pill);
    padding: 0.1rem 0.55rem;
    font-size: 0.7rem;
    font-weight: 600;
    white-space: nowrap;
}

.tag-freeleech {
    background: var(--accent-soft);
    color: var(--accent);
}

.tag-double {
    background: #a78bfa26;
    color: #a78bfa;
}

.tag-featured {
    background: #f59e0b26;
    color: #f59e0b;
}

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-7) var(--space-4);
    color: var(--muted);
    text-align: center;
}

.empty-state svg {
    width: 2.5rem;
    height: 2.5rem;
    opacity: 0.6;
}

.empty-state-title {
    font-weight: 600;
    color: var(--text);
    font-size: 1rem;
}

.empty-state-hint {
    font-size: 0.85rem;
    max-width: 32ch;
}

.no-mapping {
    display: inline-block;
    color: var(--muted);
    font-size: 0.78rem;
    font-style: italic;
}

/* ─── Badges Plex ───────────────────────────────────────────────────────── */

.badge-plex {
    display: inline-block;
    background: var(--accent-soft);
    border: 1px solid color-mix(in srgb, var(--accent) 55%, transparent);
    color: var(--accent);
    border-radius: var(--radius-pill);
    padding: 0.1rem 0.5rem;
    font-size: 0.72rem;
    font-weight: 600;
    margin-left: var(--space-2);
    white-space: nowrap;
    vertical-align: middle;
}

.stats-bar {
    display: inline-flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2);
    margin-left: var(--space-2);
    vertical-align: middle;
}

.badge-ratio {
    display: inline-block;
    background: var(--surface-hover);
    border: 1px solid var(--border);
    color: var(--accent);
    border-radius: var(--radius-pill);
    padding: 0.15rem 0.6rem;
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
    font-size: 0.78rem;
    font-weight: 600;
    white-space: nowrap;
    vertical-align: middle;
    cursor: help;
}

.stat-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.5em;
    background: var(--surface-hover);
    border: 1px solid var(--border);
    color: var(--muted);
    border-radius: var(--radius-pill);
    padding: 0.15rem 0.6rem;
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
    font-size: 0.78rem;
    font-weight: 600;
    white-space: nowrap;
    vertical-align: middle;
    cursor: help;
}

.stat-chip .icon {
    margin-right: 0;
}

.badge-plex-check {
    display: inline-block;
    width: 0.65rem;
    height: 0.65rem;
    margin-left: var(--space-2);
    border: 2px solid color-mix(in srgb, var(--muted) 30%, transparent);
    border-top-color: var(--muted);
    border-radius: 50%;
    vertical-align: middle;
    animation: plex-check-spin 0.7s linear infinite;
}

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

/* ─── Boutons ───────────────────────────────────────────────────────────── */

.btn {
    display: inline-block;
    padding: 0.45rem 0.9rem;
    background: var(--accent-strong);
    color: #fff;
    text-decoration: none;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 0.85rem;
    white-space: nowrap;
    border: none;
    box-shadow: var(--shadow-sm);
    transition: background-color var(--duration) var(--ease), transform var(--duration) var(--ease), box-shadow var(--duration) var(--ease), opacity var(--duration) var(--ease);
}

.btn:hover {
    background: var(--accent);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn:active {
    transform: translateY(0);
    box-shadow: var(--shadow-sm);
}

.btn-send {
    font: inherit;
}

.btn-send:disabled {
    opacity: 0.55;
    cursor: default;
    transform: none;
    box-shadow: none;
}

.btn-secondary {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text);
    box-shadow: none;
}

.btn-secondary:hover {
    background: var(--surface-hover);
    border-color: var(--muted);
}

/* ─── Pagination ────────────────────────────────────────────────────────── */

.pagination {
    display: flex;
    justify-content: space-between;
    margin-top: var(--space-5);
}

/* ─── Écran de connexion / formulaires étroits ─────────────────────────── */

.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 80vh;
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
    width: 100%;
    max-width: 340px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: var(--space-6);
    box-shadow: var(--shadow-lg);
}

.login-form h1 {
    margin-bottom: var(--space-2);
}

.login-form label {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    font-size: 0.85rem;
    color: var(--muted);
}

.login-form input {
    font-size: 0.95rem;
}

.login-form button {
    padding: 0.6rem;
    background: var(--accent-strong);
    color: #fff;
    border: none;
    border-radius: var(--radius-sm);
    font-weight: 600;
    cursor: pointer;
    box-shadow: var(--shadow-sm);
    transition: background-color var(--duration) var(--ease), transform var(--duration) var(--ease), box-shadow var(--duration) var(--ease);
}

.login-form button:hover {
    background: var(--accent);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.login-form .checkbox-label {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: var(--space-2);
    font-size: 0.9rem;
    color: var(--text);
}

.checkbox-label input {
    width: auto;
}

.form-narrow {
    max-width: 360px;
}

.form-wide {
    max-width: 640px;
}

.alert-matrix th,
.alert-matrix td {
    padding: var(--space-2) var(--space-3);
}

.alert-matrix th:not(:first-child),
.alert-matrix td:not(:first-child) {
    text-align: center;
    width: 5rem;
}

.alert-matrix input[type="checkbox"] {
    width: auto;
}

.form-actions {
    display: flex;
    gap: var(--space-2);
}

/* ─── Gestion utilisateurs / webhooks ──────────────────────────────────── */

.user-actions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
}

.user-actions form {
    display: inline-block;
}

.alert-fieldset {
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: var(--space-3);
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.alert-fieldset legend {
    padding: 0 var(--space-2);
    color: var(--muted);
    font-size: 0.85rem;
}

/* ─── Menu d'actions (dropdown, tableaux) ───────────────────────────────── */

.actions-menu {
    position: relative;
    display: inline-block;
}

.actions-menu-list {
    position: absolute;
    right: 0;
    top: calc(100% + var(--space-1));
    z-index: 10;
    min-width: 170px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    padding: var(--space-1);
    display: flex;
    flex-direction: column;
    gap: 2px;
}

/* Sans ça, l'attribut HTML "hidden" n'a aucun effet : cette règle a la même spécificité
   que [hidden] { display: none } du navigateur, et une règle auteur l'emporte toujours
   sur la règle user-agent par défaut à spécificité égale. */
.actions-menu-list[hidden] {
    display: none;
}

.actions-menu-list form {
    display: block;
}

.actions-menu-item {
    display: block;
    width: 100%;
    padding: 0.45rem 0.7rem;
    background: none;
    border: none;
    border-radius: var(--radius-sm);
    color: var(--text);
    text-decoration: none;
    font-size: 0.85rem;
    text-align: left;
    cursor: pointer;
    font: inherit;
}

.actions-menu-item:hover {
    background: var(--surface-hover);
}

.actions-menu-item-danger {
    color: var(--destructive);
}

/* ─── Popup de confirmation ─────────────────────────────────────────────── */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: var(--scrim);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-4);
    z-index: 100;
}

.modal-overlay[hidden] {
    display: none;
}

.modal-box {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: var(--space-6);
    width: 100%;
    max-width: 420px;
    box-shadow: var(--shadow-lg);
    animation: modal-pop 0.18s var(--ease);
}

@keyframes modal-pop {
    from { transform: scale(0.96); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

.modal-box h2 {
    margin: 0 0 var(--space-3);
    font-size: 1.1rem;
}

.modal-film {
    font-size: 1.05rem;
    font-weight: 600;
    margin: 0 0 var(--space-3);
}

.modal-warning {
    background: #f59e0b1f;
    border: 1px solid #f59e0b;
    color: #f59e0b;
    border-radius: var(--radius-sm);
    padding: var(--space-2) var(--space-3);
    font-size: 0.85rem;
    margin: 0 0 var(--space-4);
}

.modal-meta {
    list-style: none;
    padding: 0;
    margin: 0 0 var(--space-5);
    color: var(--muted);
    font-size: 0.9rem;
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
}

.modal-meta strong {
    color: var(--text);
    font-family: var(--font-mono);
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: var(--space-2);
}

.modal-actions .btn,
.modal-actions .btn-secondary {
    padding: 0.55rem 1.1rem;
}

/* ─── Accessibilité ─────────────────────────────────────────────────────── */

a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
[tabindex]:focus-visible {
    outline: 2px solid var(--ring);
    outline-offset: 2px;
    border-radius: var(--radius-sm);
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.001ms !important;
        scroll-behavior: auto !important;
    }
}

/* ─── Responsive ────────────────────────────────────────────────────────── */

@media (min-width: 1440px) {
    body {
        max-width: 1280px;
    }
}

@media (max-width: 640px) {
    body {
        margin: 1rem auto;
    }

    .search-form {
        flex-direction: column;
    }

    .search-form input[type="text"],
    .search-form select,
    .search-form button {
        width: 100%;
    }

    table, thead, tbody, th, td, tr {
        display: block;
    }

    table {
        border-radius: var(--radius-md);
        box-shadow: var(--shadow-sm);
    }

    thead {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip: rect(0 0 0 0);
    }

    tbody tr {
        border-bottom: 1px solid var(--border);
        padding: var(--space-3) var(--space-4);
    }

    tbody tr:last-child {
        border-bottom: none;
    }

    tbody td {
        border: none;
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: var(--space-3);
        padding: var(--space-1) 0;
        text-align: right;
    }

    tbody td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--muted);
        text-align: left;
        flex-shrink: 0;
    }

    tbody td:first-child {
        font-weight: 600;
        text-align: left;
        white-space: normal;
        word-break: break-word;
    }

    .pagination {
        flex-wrap: wrap;
        gap: var(--space-2);
    }
}
