@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

:root {
    --orange: #ec6925;
    --orange-dark: #d6591a;
    --orange-light: #fdf0e6;
    --navy: #1a2141;
    --navy-soft: #2a3363;
    --dark: #1a2141;
    --gray: #667085;
    --gray-light: #98a2b3;
    --border: #e4e6ec;
    --bg: #f4f5f9;
    --surface: #ffffff;
    --warn-bg: #fff4e5;
    --warn-border: #f0ad4e;
    --success: #1f9d55;
    --success-bg: #e6f4ea;
    --danger: #c0392b;
    --danger-bg: #fdecea;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.05);
    --shadow-md: 0 6px 16px rgba(16, 24, 40, 0.07), 0 1px 2px rgba(16, 24, 40, 0.05);
    --shadow-lg: 0 16px 32px rgba(16, 24, 40, 0.12);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--dark);
    -webkit-font-smoothing: antialiased;
    font-size: 15px;
    line-height: 1.45;
}

h1, h2, h3 {
    font-family: inherit;
    letter-spacing: -0.01em;
}

/* Champs de saisie : base commune (couleurs, radius, focus), pour un langage visuel
   cohérent sur tout le site. Les tailles/largeurs restent définies par contexte. */
input[type="text"],
input[type="password"],
input[type="number"],
input[type="date"],
input[type="tel"],
input[type="datetime-local"],
select,
textarea {
    font-family: inherit;
    color: var(--dark);
    background: #fff;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--orange);
    box-shadow: 0 0 0 3px rgba(236, 105, 37, 0.15);
}

header.site-header {
    background: linear-gradient(135deg, var(--navy), var(--navy-soft));
    color: #fff;
    padding: 1rem 1.25rem;
    border-bottom: 3px solid var(--orange);
    box-shadow: var(--shadow-md);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
    position: sticky;
    top: 0;
    z-index: 10;
}

header.site-header h1 {
    margin: 0;
    font-size: 1.2rem;
    font-weight: 800;
}

header.site-header .inline-form {
    width: auto;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.current-user {
    font-size: 0.82rem;
    opacity: 0.85;
}

main {
    max-width: 960px;
    margin: 0 auto;
    padding: 1.25rem 0.9rem 2.5rem;
}

.toolbar {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    padding: 1.1rem 1.2rem;
    margin-bottom: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
}

.filters {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 0.75rem 1rem;
    align-items: end;
}

.filters.filters-center {
    justify-content: center;
}

.filters label {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--gray);
    min-width: 0;
}

.filters input[type="date"],
.filters input[type="number"],
.filters select {
    width: 100%;
    padding: 0.5rem 0.65rem;
    font-size: 0.88rem;
    font-weight: 400;
    text-transform: none;
    letter-spacing: normal;
    line-height: 1.2;
    height: 2.5rem;
}

.filters button[type="submit"] {
    width: 100%;
    height: 2.5rem;
}

.sync-info {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.6rem 1rem;
    flex-wrap: wrap;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border);
    font-size: 0.82rem;
    color: var(--gray);
}

.alert {
    background: var(--warn-bg);
    border: 1px solid var(--warn-border);
    border-radius: var(--radius-sm);
    padding: 0.7rem 0.9rem;
    margin-bottom: 1rem;
    font-size: 0.9rem;
    box-shadow: var(--shadow-sm);
}

.alert-success {
    background: var(--success-bg);
    border-color: #4a9d5f;
    color: #205531;
}

.user-actions {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-top: 0.5rem;
    padding: 0.7rem;
    background: var(--bg);
    border-radius: var(--radius-sm);
}

.user-actions .inline-form {
    display: flex;
    gap: 0.4rem;
    align-items: center;
}

.user-actions input[type="password"] {
    padding: 0.4rem 0.6rem;
    font-size: 0.85rem;
}

details summary {
    cursor: pointer;
}

.pagination {
    display: flex;
    gap: 0.4rem;
    margin-top: 0.75rem;
    flex-wrap: wrap;
}

.pagination-active {
    font-weight: 700;
    text-decoration: underline;
}

.kpi-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 0.85rem;
    margin-bottom: 1.25rem;
}

.kpi-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    padding: 1rem 1.1rem;
    transition: box-shadow 0.15s ease, transform 0.15s ease;
}

.kpi-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}

.kpi-label {
    color: var(--gray);
    font-size: 0.74rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.kpi-value {
    font-size: 1.5rem;
    font-weight: 800;
    margin-top: 0.25rem;
    color: var(--navy);
    font-variant-numeric: tabular-nums;
}

.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    padding: 1.1rem 1.2rem;
    margin-bottom: 1.1rem;
}

.panel h2 {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin: 0 0 1rem;
    font-size: 1.02rem;
    font-weight: 700;
    color: var(--navy);
    padding-bottom: 0.7rem;
    border-bottom: 1px solid var(--border);
}

.panel h2::before {
    content: "";
    width: 4px;
    height: 1.1rem;
    border-radius: 2px;
    background: var(--orange);
    flex-shrink: 0;
}

.bar-chart {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.bar-row {
    display: grid;
    grid-template-columns: 5.5rem 1fr auto;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
}

.bar-track {
    background: var(--bg);
    border-radius: 999px;
    overflow: hidden;
    height: 0.9rem;
}

.bar-fill {
    background: linear-gradient(90deg, var(--orange), var(--orange-dark));
    height: 100%;
    border-radius: 999px;
}

.bar-value {
    white-space: nowrap;
    text-align: right;
    font-variant-numeric: tabular-nums;
}

table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 0.88rem;
}

th, td {
    text-align: left;
    padding: 0.6rem 0.5rem;
    border-bottom: 1px solid var(--border);
}

th {
    color: var(--gray);
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

td:not(:first-child), th:not(:first-child) {
    text-align: right;
}

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

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

button, .btn {
    display: inline-block;
    width: auto;
    background: var(--orange);
    background-image: linear-gradient(135deg, var(--orange), var(--orange-dark));
    color: #fff;
    border: none;
    border-radius: var(--radius-sm);
    padding: 0.6rem 1.1rem;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    box-shadow: var(--shadow-sm);
    transition: transform 0.12s ease, box-shadow 0.12s ease, filter 0.12s ease;
}

button:hover, .btn:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
    filter: brightness(1.03);
}

button:active, .btn:active {
    transform: translateY(0);
    box-shadow: var(--shadow-sm);
    filter: brightness(0.98);
}

button:focus-visible, .btn:focus-visible {
    outline: 2px solid var(--orange-dark);
    outline-offset: 2px;
}

button.secondary {
    background: #fff;
    background-image: none;
    color: var(--navy);
    border: 1px solid var(--border);
    box-shadow: none;
}

button.secondary:hover {
    background: var(--bg);
    box-shadow: var(--shadow-sm);
    filter: none;
}

.login-page {
    max-width: 380px;
    margin: 0 auto;
    padding: 0.75rem;
    min-height: 100vh;
    display: flex;
    align-items: center;
}

.login-box {
    width: 100%;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 1.75rem 1.5rem;
}

.login-box h1 {
    margin: 0 0 1.25rem;
    font-size: 1.3rem;
    font-weight: 800;
    color: var(--navy);
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: 0.7rem;
}

.login-form input[type="password"],
.login-form input[type="text"] {
    padding: 0.65rem 0.8rem;
    font-size: 1rem;
}

.empty-state {
    color: var(--gray);
    font-style: italic;
}

.site-nav {
    display: flex;
    gap: 0.4rem;
    flex-wrap: wrap;
}

.nav-link {
    color: rgba(255, 255, 255, 0.85);
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 600;
    padding: 0.45rem 0.8rem;
    border-radius: var(--radius-sm);
    background: rgba(255, 255, 255, 0.08);
    transition: background 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

.nav-link:hover {
    background: rgba(255, 255, 255, 0.16);
    color: #fff;
}

.nav-link.active {
    background: var(--orange);
    color: #fff;
    box-shadow: var(--shadow-sm);
}

.home-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 0.9rem;
    margin-bottom: 1rem;
}

.home-card {
    display: block;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    padding: 1.2rem 1.25rem;
    text-decoration: none;
    color: var(--dark);
    border-top: 3px solid var(--orange);
    transition: box-shadow 0.18s ease, transform 0.18s ease;
}

.home-card:hover {
    box-shadow: var(--shadow-lg);
    transform: translateY(-3px);
}

.home-card h2 {
    margin: 0 0 0.4rem;
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--navy);
}

.home-card p {
    margin: 0;
    color: var(--gray);
    font-size: 0.88rem;
}

.filters-center {
    justify-content: center;
    margin-bottom: 0.5rem;
}

.caisse-date {
    text-align: center;
    font-size: 1.1rem;
    font-weight: 700;
    margin: 0.5rem 0 1.25rem;
    color: var(--navy);
}

.caisse-empty {
    text-align: center;
    font-size: 1.1rem;
    margin: 2rem 0;
    color: var(--gray);
}

.kpi-row-big .kpi-value-big {
    font-size: 2.1rem;
}

.caisse-table td {
    font-size: 1.1rem;
    padding: 0.65rem 0.4rem;
}

.caisse-amount {
    font-weight: 700;
    color: var(--navy);
}

.caisse-calc {
    margin-top: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.caisse-calc[hidden] {
    display: none;
}

.caisse-calc label {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    font-size: 0.85rem;
    color: var(--gray);
}

.caisse-calc input[type="number"] {
    padding: 0.6rem 0.75rem;
    font-size: 1.1rem;
    max-width: 220px;
}

.caisse-calc-result {
    background: var(--bg);
    border-radius: var(--radius-sm);
    padding: 0.75rem 0.9rem;
    font-size: 1rem;
    line-height: 1.5;
}

.insights-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 0.9rem;
    margin-bottom: 1rem;
}

.insight-panel ul {
    margin: 0;
    padding-left: 1.1rem;
    font-size: 0.9rem;
    line-height: 1.5;
}

.insight-panel li {
    margin-bottom: 0.4rem;
}

.insight-good {
    border-top: 3px solid var(--success);
}

.insight-improve {
    border-top: 3px solid var(--warn-border);
}

.charts-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 0.9rem;
    margin-bottom: 1rem;
}

.line-chart {
    width: 100%;
    height: auto;
}

.chart-grid {
    stroke: var(--border);
    stroke-width: 1;
}

.chart-area {
    fill: rgba(236, 105, 37, 0.12);
    stroke: none;
}

.chart-line {
    fill: none;
    stroke: var(--orange);
    stroke-width: 2.5;
}

.chart-dot {
    fill: var(--orange);
}

.chart-axis-label {
    fill: var(--gray);
    font-size: 10px;
}

.donut-wrap {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.donut-chart {
    width: 140px;
    height: 140px;
    flex-shrink: 0;
}

.donut-legend {
    list-style: none;
    margin: 0;
    padding: 0;
    font-size: 0.85rem;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.swatch {
    display: inline-block;
    width: 0.7rem;
    height: 0.7rem;
    border-radius: 50%;
    margin-right: 0.4rem;
}

.btn-link {
    color: var(--orange);
    text-decoration: none;
    font-weight: 600;
    font-size: 0.88rem;
    transition: color 0.12s ease;
}

.btn-link:hover {
    color: var(--orange-dark);
    text-decoration: underline;
}

.badge-done,
.badge-todo {
    display: inline-block;
    font-size: 0.72rem;
    font-weight: 700;
    padding: 0.25rem 0.6rem;
    border-radius: 999px;
    letter-spacing: 0.01em;
}

.badge-done {
    background: var(--success-bg);
    color: var(--success);
}

.badge-todo {
    background: var(--warn-bg);
    color: #a15c00;
}

.closure-form h3 {
    margin: 1.1rem 0 0.2rem;
    font-size: 0.92rem;
    font-weight: 700;
    color: var(--navy);
}

.form-hint {
    margin: 0 0 0.6rem;
    color: var(--gray);
    font-size: 0.8rem;
}

.closure-form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 0.75rem;
    margin-top: 0.75rem;
}

.closure-form > label {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--gray);
    margin-top: 0.75rem;
}

.closure-form > label:first-child {
    margin-top: 0;
}

.closure-form .closure-form-grid > label {
    margin-top: 0;
}

.closure-form-grid label {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--gray);
}

.closure-form input[type="number"],
.closure-form input[type="text"],
.closure-form input[type="tel"],
.closure-form input[type="date"],
.closure-form input[type="datetime-local"],
.closure-form textarea,
.closure-form select {
    padding: 0.6rem 0.75rem;
    font-size: 0.95rem;
    resize: vertical;
}

.checkbox-label {
    display: flex !important;
    flex-direction: row !important;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.88rem !important;
    font-weight: 400 !important;
    color: var(--dark) !important;
}

.checkbox-label input[type="checkbox"] {
    width: auto;
    accent-color: var(--orange);
}

.movement-row {
    display: grid;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
    align-items: center;
}

.movement-row-aide {
    grid-template-columns: 1.3fr 0.9fr 1.6fr 1fr auto;
}

.movement-row-sortie {
    grid-template-columns: 0.9fr 2fr auto;
}

.movement-row-option {
    grid-template-columns: 2fr 1.2fr auto;
}

.movement-row-registration {
    grid-template-columns: 1fr 6rem;
    align-items: center;
}

.movement-row-registration input[type="number"] {
    padding: 0.5rem 0.65rem;
    font-size: 0.95rem;
}

.hp-field {
    position: absolute;
    left: -9999px;
}

.remove-row {
    padding: 0.5rem 0.65rem;
    font-size: 0.8rem;
}

.closure-form-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-top: 1rem;
}

tr.ecart-ok td {
    color: var(--success);
    font-weight: 700;
}

tr.ecart-off td {
    color: var(--danger);
    font-weight: 700;
}

@media (max-width: 640px) {
    .movement-row-aide,
    .movement-row-sortie,
    .movement-row-option,
    .movement-row-registration {
        grid-template-columns: 1fr;
    }
}

.table-scroll {
    overflow-x: auto;
}

.closure-list th,
.closure-list td {
    white-space: nowrap;
}

.denom-columns {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.25rem;
    margin-top: 0.5rem;
}

.denom-group-title {
    margin: 0 0 0.4rem;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--gray);
}

.denom-row {
    display: grid;
    grid-template-columns: 1fr 1rem 5rem;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.4rem;
}

.denom-label {
    font-size: 0.9rem;
}

.denom-x {
    color: var(--gray-light);
    text-align: center;
}

.denom-qty {
    padding: 0.45rem 0.6rem;
    font-size: 0.9rem;
    width: 100%;
}

.denom-total {
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px dashed var(--border);
    font-size: 1rem;
    font-weight: 600;
    color: var(--navy);
}

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

.split-columns h3 {
    margin: 0 0 0.5rem;
    font-size: 0.92rem;
    font-weight: 700;
    color: var(--navy);
}

/* Tableaux à colonnes multiples (Mes caisses, Utilisateurs, Journal, Inscrits) :
   passent d'un tableau classique à une liste de cartes empilées sous 700px, pour
   ne jamais couper une info (badge de statut, bouton d'action) hors écran. */
@media (max-width: 700px) {
    table.table-stack thead {
        display: none;
    }

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

    table.table-stack {
        border: none;
    }

    table.table-stack tr {
        background: var(--surface);
        border: 1px solid var(--border);
        border-radius: var(--radius-md);
        box-shadow: var(--shadow-sm);
        padding: 0.7rem 0.9rem;
        margin-bottom: 0.65rem;
    }

    table.table-stack td {
        display: block;
        padding: 0.35rem 0;
        border-bottom: 1px dashed var(--border);
        text-align: left;
        font-size: 0.92rem;
    }

    table.table-stack td:last-child {
        border-bottom: none;
    }

    table.table-stack td::before {
        content: attr(data-label);
        display: block;
        font-size: 0.7rem;
        font-weight: 700;
        text-transform: uppercase;
        letter-spacing: 0.03em;
        color: var(--gray);
        margin-bottom: 0.15rem;
    }

    table.table-stack td:first-child {
        font-weight: 700;
        font-size: 1rem;
        text-align: left;
        color: var(--navy);
    }

    table.table-stack td:first-child::before {
        content: none;
    }

    table.table-stack td:not([data-label]) {
        display: block;
        text-align: left;
        border-bottom: none;
        padding-top: 0.5rem;
    }

    table.table-stack td:not([data-label])::before {
        content: none;
    }
}

/* Bannière + mode d'emploi pour installer l'app (PWA) sur l'écran d'accueil. */
.install-banner {
    position: fixed;
    left: 0.75rem;
    right: 0.75rem;
    bottom: 0.75rem;
    z-index: 50;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    padding: 0.9rem 1rem;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    max-width: 640px;
    margin: 0 auto;
}

.install-banner-text {
    font-size: 0.88rem;
    color: var(--dark);
}

.install-banner-actions {
    display: flex;
    align-items: center;
    gap: 0.9rem;
    flex-wrap: wrap;
}

.install-dismiss {
    color: var(--gray);
}

.install-dismiss:hover {
    color: var(--dark);
}

.install-modal {
    position: fixed;
    inset: 0;
    z-index: 60;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

/* L'attribut hidden doit toujours l'emporter, même sur des éléments dont une règle
   plus loin dans la cascade fixe déjà un display (boutons, bannière/modale flex...). */
[hidden] {
    display: none !important;
}

.install-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(26, 33, 65, 0.55);
}

.install-modal-box {
    position: relative;
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 1.5rem;
    max-width: 380px;
    width: 100%;
}

.install-modal-box h2 {
    margin: 0 0 1rem;
    font-size: 1.1rem;
    font-weight: 800;
    color: var(--navy);
}

.install-steps {
    margin: 0 0 1.25rem;
    padding-left: 1.2rem;
    font-size: 0.92rem;
    line-height: 1.6;
    color: var(--dark);
}

.install-steps li {
    margin-bottom: 0.5rem;
}

@media (max-width: 500px) {
    .install-banner {
        flex-direction: column;
        align-items: stretch;
        text-align: left;
    }

    .install-banner-actions {
        justify-content: space-between;
    }
}

/* Zones tactiles et saisie confortables au doigt : cible min. ~44px, et jamais
   moins de 16px sur les champs pour éviter le zoom automatique de Safari iOS. */
@media (max-width: 700px) {
    input,
    select,
    textarea,
    button,
    .btn {
        font-size: 16px;
    }

    button,
    .btn {
        min-height: 44px;
        padding: 0.6rem 1rem;
    }

    .remove-row {
        min-height: 36px;
        padding: 0.4rem 0.65rem;
    }

    .nav-link {
        padding: 0.6rem 0.85rem;
        font-size: 0.88rem;
    }

    .btn-link {
        display: inline-block;
        padding: 0.3rem 0;
    }
}
