/* ============================================
   Ma Tribu - Styles
   Design: Chaleureux, moderne, mobile-first
   ============================================ */

/* --- Variables --- */
:root {
    --primary: #4A90A4;
    --primary-dark: #3A7A8E;
    --primary-light: #E8F4F8;
    --accent: #E8845C;
    --accent-light: #FFF0EB;
    --success: #7BC67E;
    --success-light: #EDF9EE;
    --warning: #F2C94C;
    --danger: #FF7E7E;
    --danger-light: #FFF0F0;

    --text: #2D3436;
    --text-light: #636E72;
    --text-muted: #B2BEC3;
    --bg: #F8F9FA;
    --white: #FFFFFF;
    --border: #E9ECEF;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.12);
    --radius: 12px;
    --radius-sm: 8px;
    --nav-height: 64px;
    --header-height: 56px;
}

/* --- Reset --- */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 16px;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
    min-height: 100dvh;
    overflow-x: hidden;
}

a {
    color: var(--primary);
    text-decoration: none;
}

img {
    max-width: 100%;
    display: block;
}

/* --- Auth Pages --- */
.auth-page {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100dvh;
    padding: 1rem;
}

.auth-page main {
    width: 100%;
    max-width: 400px;
}

.auth-container {
    background: var(--white);
    border-radius: var(--radius);
    padding: 2rem;
    box-shadow: var(--shadow-lg);
}

.auth-logo {
    text-align: center;
    margin-bottom: 2rem;
}

.auth-logo h1 {
    font-size: 2rem;
    font-weight: 800;
    color: var(--primary);
    letter-spacing: -0.5px;
}

.auth-subtitle {
    color: var(--text-light);
    font-size: 0.95rem;
    margin-top: 0.25rem;
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.auth-link {
    text-align: center;
    margin-top: 1.5rem;
    font-size: 0.9rem;
    color: var(--text-light);
}

/* --- Formulaires --- */
.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.form-group label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text);
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="date"],
input[type="time"],
input[type="number"],
input[type="search"],
select,
textarea {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 1rem;
    font-family: inherit;
    color: var(--text);
    background: var(--white);
    transition: border-color 0.2s;
    -webkit-appearance: none;
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
}

input::placeholder {
    color: var(--text-muted);
}

/* --- Boutons --- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 1rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s;
    -webkit-appearance: none;
}

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

.btn-primary:hover, .btn-primary:active {
    background: var(--primary-dark);
}

.btn-accent {
    background: var(--accent);
    color: var(--white);
}

.btn-outline {
    background: transparent;
    border: 2px solid var(--border);
    color: var(--text);
}

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

.btn-sm {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
}

.btn-full {
    width: 100%;
}

.btn-icon {
    width: 40px;
    height: 40px;
    padding: 0;
    border-radius: 50%;
}

.btn-fab {
    position: fixed;
    bottom: calc(var(--nav-height) + 1rem);
    right: 1rem;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--accent);
    color: var(--white);
    box-shadow: var(--shadow-lg);
    z-index: 50;
    font-size: 1.5rem;
}

/* --- Alertes --- */
.alert {
    padding: 0.75rem 1rem;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    margin-bottom: 1rem;
}

.alert-error {
    background: var(--danger-light);
    color: #C0392B;
    border: 1px solid var(--danger);
}

.alert-success {
    background: var(--success-light);
    color: #27AE60;
    border: 1px solid var(--success);
}

/* --- App Layout --- */
.app-page main {
    padding: 0;
}

main.has-nav {
    padding-bottom: var(--nav-height);
}

/* Conteneur centré pour desktop */
.page-header,
.stats-grid,
.list-section,
.setup-container {
    max-width: 800px;
    margin-left: auto;
    margin-right: auto;
}

/* --- Page Header --- */
.page-header {
    background: var(--white);
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 40;
}

.page-header h1 {
    font-size: 1.25rem;
    font-weight: 700;
}

.page-header-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

/* --- Bottom Navigation --- */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--nav-height);
    background: var(--white);
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-around;
    z-index: 100;
    padding-bottom: env(safe-area-inset-bottom, 0);
}

.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.2rem;
    color: var(--text-muted);
    font-size: 0.7rem;
    font-weight: 500;
    text-decoration: none;
    padding: 0.5rem;
    transition: color 0.2s;
    -webkit-tap-highlight-color: transparent;
}

.nav-item svg {
    width: 22px;
    height: 22px;
}

.nav-item.active {
    color: var(--primary);
}

/* --- Cards --- */
.card {
    background: var(--white);
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: var(--shadow);
}

.card + .card {
    margin-top: 1rem;
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
}

.card-header h2 {
    font-size: 1.1rem;
    font-weight: 700;
}

.card-stat {
    font-size: 0.85rem;
    color: var(--text-light);
}

/* --- Avatar --- */
.avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    color: var(--white);
    font-weight: 700;
    font-size: 0.9rem;
    flex-shrink: 0;
}

.avatar-sm {
    width: 28px;
    height: 28px;
    font-size: 0.75rem;
}

.avatar-lg {
    width: 48px;
    height: 48px;
    font-size: 1.2rem;
}

/* --- Lists --- */
.list-section {
    padding: 1rem 1.25rem;
}

.list-section-title {
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    margin-bottom: 0.75rem;
}

.list-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.875rem 0;
    border-bottom: 1px solid var(--border);
}

.list-item:last-child {
    border-bottom: none;
}

.list-item-content {
    flex: 1;
    min-width: 0;
}

.list-item-title {
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.list-item-subtitle {
    font-size: 0.85rem;
    color: var(--text-light);
}

/* --- Checkbox custom --- */
.checkbox {
    position: relative;
    width: 24px;
    height: 24px;
    flex-shrink: 0;
}

.checkbox input {
    position: absolute;
    opacity: 0;
    width: 100%;
    height: 100%;
    cursor: pointer;
    z-index: 1;
}

.checkbox .checkmark {
    width: 24px;
    height: 24px;
    border: 2px solid var(--border);
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.checkbox input:checked + .checkmark {
    background: var(--success);
    border-color: var(--success);
}

.checkbox input:checked + .checkmark::after {
    content: '';
    width: 6px;
    height: 10px;
    border: solid var(--white);
    border-width: 0 2.5px 2.5px 0;
    transform: rotate(45deg);
    margin-top: -2px;
}

.checked-item .list-item-title {
    text-decoration: line-through;
    color: var(--text-muted);
}

/* --- Priority badges --- */
.priority {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 100px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
}

.priority-high { background: var(--danger-light); color: #E74C3C; }
.priority-medium { background: #FFF8E1; color: #F39C12; }
.priority-low { background: var(--primary-light); color: var(--primary); }

/* --- Stats grid (dashboard) --- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
    padding: 1rem 1.25rem;
}

.stat-card {
    background: var(--white);
    border-radius: var(--radius);
    padding: 1rem;
    text-align: center;
    box-shadow: var(--shadow);
}

.stat-value {
    font-size: 1.75rem;
    font-weight: 800;
    color: var(--primary);
}

.stat-label {
    font-size: 0.8rem;
    color: var(--text-light);
    margin-top: 0.25rem;
}

/* --- Modal / Bottom Sheet --- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 200;
    display: none;
    align-items: flex-end;
    justify-content: center;
}

.modal-overlay.active {
    display: flex;
}

.modal {
    background: var(--white);
    border-radius: var(--radius) var(--radius) 0 0;
    width: 100%;
    max-width: 500px;
    max-height: 90dvh;
    overflow-y: auto;
    padding: 1.5rem;
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.25rem;
}

.modal-header h2 {
    font-size: 1.15rem;
    font-weight: 700;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.25rem;
}

/* --- Invite code --- */
.invite-code {
    background: var(--primary-light);
    border-radius: var(--radius-sm);
    padding: 1rem;
    text-align: center;
    font-size: 1.5rem;
    font-weight: 800;
    letter-spacing: 3px;
    color: var(--primary);
    cursor: pointer;
    transition: background 0.2s;
}

.invite-code:active {
    background: #D0E8F0;
}

/* --- Empty state --- */
.empty-state {
    text-align: center;
    padding: 3rem 2rem;
    color: var(--text-light);
}

.empty-state-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}

.empty-state p {
    margin-bottom: 1.5rem;
}

/* --- Household setup --- */
.setup-container {
    max-width: 500px;
    margin: 0 auto;
    padding: 2rem 1.25rem;
}

.setup-container h1 {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
}

.setup-container p {
    color: var(--text-light);
    margin-bottom: 2rem;
}

.setup-options {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.setup-option {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1.25rem;
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    text-decoration: none;
    color: var(--text);
    transition: box-shadow 0.2s;
}

.setup-option:active {
    box-shadow: var(--shadow-lg);
}

.setup-option-icon {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    flex-shrink: 0;
}

.setup-option-text h3 {
    font-size: 1rem;
    margin-bottom: 0.15rem;
}

.setup-option-text p {
    font-size: 0.85rem;
    color: var(--text-light);
    margin: 0;
}

/* --- Members list --- */
.members-row {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

/* --- Delete button inline --- */
.btn-delete-item {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.25rem;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    opacity: 0;
    transition: opacity 0.2s, color 0.2s;
}

.list-item:hover .btn-delete-item {
    opacity: 1;
}

.btn-delete-item:hover {
    color: var(--danger);
}

@media (hover: none) {
    .btn-delete-item {
        opacity: 0.5;
    }
}

/* --- Photo grid --- */
.photo-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 2px;
    padding: 2px;
}

@media (min-width: 768px) {
    .photo-grid {
        grid-template-columns: repeat(4, 1fr);
        gap: 4px;
        padding: 1rem;
        max-width: 900px;
        margin: 0 auto;
    }
}

@media (min-width: 1200px) {
    .photo-grid {
        grid-template-columns: repeat(5, 1fr);
    }
}

.photo-grid-item {
    aspect-ratio: 1;
    position: relative;
    cursor: pointer;
    overflow: hidden;
    border-radius: 2px;
}

.photo-grid-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.2s;
}

.photo-grid-item:hover img {
    transform: scale(1.05);
}

/* --- Lightbox --- */
.lightbox {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.95);
    z-index: 300;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.lightbox.active {
    display: flex;
}

.lightbox-header {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem;
    background: linear-gradient(to bottom, rgba(0,0,0,0.6), transparent);
    z-index: 2;
}

.lightbox-info {
    color: var(--white);
    font-size: 0.85rem;
}

.lightbox-btn {
    background: none;
    border: none;
    color: var(--white);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.5rem;
    opacity: 0.8;
}

.lightbox-btn:hover {
    opacity: 1;
}

.lightbox img {
    max-width: 95%;
    max-height: 85vh;
    object-fit: contain;
}

.lightbox-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: var(--white);
    font-size: 2rem;
    cursor: pointer;
    padding: 1rem;
    opacity: 0.6;
    z-index: 2;
}

.lightbox-nav:hover {
    opacity: 1;
}

.lightbox-prev { left: 0; }
.lightbox-next { right: 0; }

/* --- Upload progress --- */
.upload-progress {
    position: fixed;
    bottom: calc(var(--nav-height) + 0.75rem);
    left: 1rem;
    right: 1rem;
    background: var(--white);
    border-radius: var(--radius-sm);
    padding: 0.75rem 1rem;
    box-shadow: var(--shadow-lg);
    z-index: 150;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.upload-progress-bar {
    height: 4px;
    background: var(--primary);
    border-radius: 2px;
    width: 0%;
    transition: width 0.3s;
    position: absolute;
    bottom: 0;
    left: 0;
}

/* --- Calendar day active --- */
.cal-day.selected {
    background: var(--primary-light) !important;
    color: var(--primary) !important;
    font-weight: 700 !important;
}

/* --- Utilities --- */
.text-center { text-align: center; }
.text-muted { color: var(--text-light); }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.px { padding-left: 1.25rem; padding-right: 1.25rem; }
.gap-1 { gap: 0.5rem; }
.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.hidden { display: none !important; }

/* --- Responsive tablet+ --- */
@media (min-width: 768px) {
    .bottom-nav {
        top: 0;
        bottom: auto;
        border-top: none;
        border-bottom: 1px solid var(--border);
        justify-content: center;
        gap: 2rem;
        height: var(--header-height);
        padding-bottom: 0;
    }

    .nav-item {
        flex-direction: row;
        gap: 0.5rem;
        font-size: 0.85rem;
    }

    main.has-nav {
        padding-bottom: 0;
        padding-top: var(--header-height);
    }

    .btn-fab {
        bottom: 2rem;
        right: 2rem;
    }

    .modal {
        border-radius: var(--radius);
        margin-bottom: auto;
        margin-top: 10vh;
        max-width: 480px;
    }

    .modal-overlay {
        align-items: flex-start;
    }
}
