:root {
    color-scheme: light dark;
    --color-bg: #f4f5f7;
    --color-surface: #ffffff;
    --color-text: #1a1a1a;
    --color-muted: #6b7280;
    --color-border: #d1d5db;
    --color-primary: #2563eb;
    --color-primary-hover: #1d4ed8;
    --color-error: #dc2626;
    --color-success: #16a34a;
}

@media (prefers-color-scheme: dark) {
    :root {
        --color-bg: #111318;
        --color-surface: #1b1e26;
        --color-text: #f3f4f6;
        --color-muted: #9ca3af;
        --color-border: #333844;
    }
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    min-height: 100vh;
}

body {
    background: var(--color-bg);
    color: var(--color-text);
    font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}

#app {
    min-height: 100vh;
}

/* --- Login --- */

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

.login-card {
    width: 100%;
    max-width: 360px;
    padding: 2rem;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.08);
}

.login-card h1 {
    margin: 0 0 1.5rem;
    font-size: 1.25rem;
    text-align: center;
}

/* --- Formulaires --- */

.field {
    margin-bottom: 1rem;
}

.field label {
    display: block;
    margin-bottom: 0.375rem;
    font-size: 0.875rem;
    color: var(--color-muted);
}

.field input,
.field textarea {
    width: 100%;
    padding: 0.625rem 0.75rem;
    border: 1px solid var(--color-border);
    border-radius: 8px;
    font-size: 1rem;
    font-family: inherit;
    background: transparent;
    color: inherit;
    resize: vertical;
}

.field input:focus,
.field textarea:focus {
    outline: 2px solid var(--color-primary);
    outline-offset: 1px;
}

.field input[aria-invalid="true"],
.field textarea[aria-invalid="true"] {
    border-color: var(--color-error);
}

.field-error {
    display: block;
    min-height: 1.1em;
    margin-top: 0.25rem;
    font-size: 0.8125rem;
    color: var(--color-error);
}

.global-error {
    margin-bottom: 1rem;
    padding: 0.625rem 0.75rem;
    border-radius: 8px;
    background: color-mix(in srgb, var(--color-error) 12%, transparent);
    color: var(--color-error);
    font-size: 0.875rem;
}

button {
    font-family: inherit;
}

button[type="submit"],
.admin-content button:not(.danger):not(#cancel-edit-button) {
    padding: 0.6rem 1.25rem;
    border: none;
    border-radius: 8px;
    background: var(--color-primary);
    color: #fff;
    font-size: 0.9375rem;
    font-weight: 600;
    cursor: pointer;
}

.login-card button[type="submit"] {
    width: 100%;
    padding: 0.7rem;
    font-size: 1rem;
}

button:hover:not(:disabled) {
    filter: brightness(1.1);
}

button:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}

button.danger {
    padding: 0.5rem 1rem;
    border: 1px solid var(--color-error);
    border-radius: 8px;
    background: transparent;
    color: var(--color-error);
    cursor: pointer;
}

#cancel-edit-button {
    padding: 0.5rem 1rem;
    border: 1px solid var(--color-border);
    border-radius: 8px;
    background: transparent;
    color: inherit;
    cursor: pointer;
}

[hidden] {
    display: none !important;
}

/* --- Coque admin --- */

.admin-shell {
    display: flex;
    min-height: 100vh;
}

.admin-nav {
    width: 220px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    padding: 1.5rem 1rem;
    background: var(--color-surface);
    border-right: 1px solid var(--color-border);
}

.admin-nav-brand {
    font-weight: 700;
    margin-bottom: 1rem;
}

.admin-nav-links {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    flex: 1;
}

.admin-nav a {
    padding: 0.5rem 0.75rem;
    border-radius: 8px;
    color: inherit;
    text-decoration: none;
    font-size: 0.9375rem;
}

.admin-nav a:hover {
    background: var(--color-bg);
}

.admin-nav a.active {
    background: var(--color-primary);
    color: #fff;
}

.admin-nav-logout {
    background: transparent;
    border: 1px solid var(--color-border);
    color: inherit;
    padding: 0.5rem 0.75rem;
    border-radius: 8px;
    cursor: pointer;
}

.admin-content {
    flex: 1;
    padding: 2rem;
    max-width: 960px;
}

.admin-content h1 {
    margin-top: 0;
}

/* --- Formulaires d'entité (create/edit) --- */

.entity-form {
    padding: 1.25rem;
    margin-bottom: 2rem;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 12px;
}

.entity-form h2 {
    margin-top: 0;
    font-size: 1.05rem;
}

.form-actions {
    display: flex;
    gap: 0.75rem;
}

.image-field {
    padding: 0.75rem;
    border: 1px dashed var(--color-border);
    border-radius: 8px;
}

.image-preview {
    display: block;
    max-width: 160px;
    max-height: 160px;
    object-fit: cover;
    border-radius: 8px;
    border: 1px solid var(--color-border);
    margin-bottom: 0.5rem;
}

.image-upload-row {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.image-upload-row input[type="file"] {
    flex: 1;
    font-size: 0.8125rem;
}

.thumb {
    width: 48px;
    height: 48px;
    object-fit: cover;
    border-radius: 6px;
    display: block;
}

.checkbox-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 1.25rem;
    max-height: 160px;
    overflow-y: auto;
    padding: 0.75rem;
    border: 1px solid var(--color-border);
    border-radius: 8px;
}

.checkbox-option {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    font-size: 0.875rem;
    font-weight: 400;
    color: inherit;
}

.checkbox-option input {
    width: auto;
}

/* --- Tableaux --- */

.entity-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 12px;
    overflow: hidden;
}

.entity-table th,
.entity-table td {
    padding: 0.7rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--color-border);
    font-size: 0.9rem;
}

.entity-table th {
    color: var(--color-muted);
    font-weight: 600;
    font-size: 0.8125rem;
    text-transform: uppercase;
}

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

.row-actions {
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
}

/* --- Tableau de bord --- */

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 1rem;
}

.stat-card {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    padding: 1.5rem;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 12px;
    text-decoration: none;
    color: inherit;
}

.stat-card:hover {
    border-color: var(--color-primary);
}

.stat-value {
    font-size: 2rem;
    font-weight: 700;
}

.stat-label {
    color: var(--color-muted);
    font-size: 0.875rem;
}
