/* =============================================================================
   Plateforme Intrants Agricoles — Design system
   ============================================================================= */

:root {
    --sidebar-width: 240px;
    --color-primary: #15803d;
    --color-primary-dark: #14532d;
    --color-primary-light: #22c55e;
    --color-accent: #eab308;
    --color-surface: #ffffff;
    --color-bg: #edf7f2;
    --color-bg-soft: #f5fbf8;
    --color-border: #e2e8f0;
    --color-text: #0f172a;
    --color-text-muted: #64748b;
    --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.06);
    --shadow-md: 0 4px 20px rgba(15, 23, 42, 0.08);
    --shadow-lg: 0 12px 40px rgba(15, 23, 42, 0.12);
    --radius-sm: 0.5rem;
    --radius-md: 0.875rem;
    --radius-lg: 1.25rem;
    --font-sans: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;
    --transition: 0.2s ease;
    --bs-primary: #15803d;
    --bs-primary-rgb: 21, 128, 61;
    --bs-success: #15803d;
    --bs-success-rgb: 21, 128, 61;
    --bs-link-color: #15803d;
    --bs-link-hover-color: #14532d;
}

/* --- Base --- */
body {
    font-family: var(--font-sans);
    color: var(--color-text);
    background: var(--color-bg);
    -webkit-font-smoothing: antialiased;
}

body.app-page {
    background:
        radial-gradient(ellipse 80% 50% at 100% -10%, rgba(34, 197, 94, 0.12), transparent),
        radial-gradient(ellipse 60% 40% at 0% 100%, rgba(21, 128, 61, 0.1), transparent),
        var(--color-bg);
    margin: 0;
    overflow-x: hidden;
}

/* --- App shell (sidebar + contenu) --- */
.app-shell {
    display: grid;
    grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
    min-height: 100vh;
    width: 100%;
}

h1, h2, h3, h4, h5, h6 {
    font-weight: 700;
    letter-spacing: -0.02em;
}

h2 {
    font-size: 1.65rem;
    color: var(--color-text);
}

.text-primary {
    color: var(--color-primary) !important;
}

/* --- Sidebar --- */
.sidebar {
    width: var(--sidebar-width);
    height: 100vh;
    background: linear-gradient(165deg, #0f3d24 0%, #14532d 45%, #166534 100%);
    color: #fff;
    position: sticky;
    top: 0;
    align-self: start;
    z-index: 1040;
    box-shadow: 4px 0 24px rgba(15, 61, 36, 0.25);
    border-right: 1px solid rgba(255, 255, 255, 0.06);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar-nav-scroll {
    flex: 1 1 auto;
    overflow-y: auto;
    overflow-x: hidden;
    min-height: 0;
}

.sidebar-nav-scroll .nav {
    padding-bottom: 0.35rem;
}

.sidebar-brand {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem 1rem 0.9rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    margin-bottom: 0.35rem;
}

.sidebar-brand-icon {
    flex-shrink: 0;
    width: 2.35rem;
    height: 1.55rem;
    border-radius: 0.2rem;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 0;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.senegal-flag {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.senegal-flag-sidebar {
    width: 2.35rem;
    height: 1.55rem;
}

.sidebar-brand-text {
    min-width: 0;
    line-height: 1.25;
}

.sidebar-brand h5 {
    font-weight: 700;
    font-size: 0.95rem;
    margin-bottom: 0.1rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-brand small {
    font-size: 0.7rem;
    display: block;
    line-height: 1.2;
}

.sidebar-nav-label {
    font-size: 0.62rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: rgba(255, 255, 255, 0.42);
    padding: 0.55rem 1rem 0.25rem;
}

.sidebar-nav-label + .nav {
    padding-top: 0.15rem;
}

.sidebar .nav-item {
    line-height: 1.2;
}

.sidebar .nav-link {
    color: rgba(255, 255, 255, 0.82);
    border-radius: var(--radius-sm);
    margin: 0.08rem 0.55rem;
    padding: 0.48rem 0.75rem;
    font-size: 0.875rem;
    font-weight: 500;
    transition: background var(--transition), color var(--transition), transform var(--transition);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    white-space: nowrap;
}

.sidebar .nav-link i {
    font-size: 1.05rem;
    opacity: 0.9;
    width: 1.25rem;
    text-align: center;
    flex-shrink: 0;
}

.sidebar .nav-link:hover {
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    transform: translateX(2px);
}

.sidebar .nav-link.active {
    background: rgba(255, 255, 255, 0.18);
    color: #fff;
    box-shadow: inset 3px 0 0 var(--color-accent);
}

.sidebar-user {
    flex-shrink: 0;
    padding: 0.85rem 1rem;
    border-top: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(0, 0, 0, 0.12);
}

.sidebar-user-name {
    font-weight: 600;
    font-size: 0.85rem;
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 0.15rem;
}

.sidebar-user-role {
    font-size: 0.72rem;
    color: rgba(255, 255, 255, 0.55);
    margin-bottom: 0.55rem !important;
}

.sidebar-user .btn {
    font-size: 0.78rem;
    padding: 0.32rem 0.65rem;
}

/* --- Main content --- */
.main-content {
    min-width: 0;
    padding: 1.75rem 2rem 2.5rem;
    min-height: 100vh;
}

body.app-page .main-content {
    margin-left: 0;
}

.sidebar-toggle {
    display: none;
    position: fixed;
    bottom: 1.25rem;
    left: 1.25rem;
    z-index: 1050;
    width: 2.75rem;
    height: 2.75rem;
    border-radius: 50%;
    border: none;
    background: var(--color-primary);
    color: #fff;
    box-shadow: var(--shadow-md);
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
}

.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    z-index: 1035;
}

/* --- Cards --- */
.card {
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    background: var(--color-surface);
    overflow: hidden;
}

.stat-card,
.card.stat-card {
    transition: box-shadow var(--transition), transform var(--transition);
}

a.stat-card:hover,
a.card.stat-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
    border-color: rgba(21, 128, 61, 0.25);
}

.stat-card .card-header {
    background: var(--color-bg-soft) !important;
    border-bottom: 1px solid var(--color-border);
    padding: 1rem 1.25rem;
    font-weight: 600;
}

.stat-card .card-header h5,
.stat-card .card-header h6 {
    font-weight: 700;
    color: var(--color-text);
}

.stat-card .card-body {
    padding: 1.25rem;
}

.stat-card .icon {
    font-size: 2.25rem;
    opacity: 0.85;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.08));
}

/* KPI cards on dashboard */
.stat-card .card-body h3 {
    font-weight: 800;
    font-size: 1.75rem;
    letter-spacing: -0.03em;
}

.stat-card .card-body p.text-muted {
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

/* --- Tables --- */
.table {
    --bs-table-hover-bg: rgba(21, 128, 61, 0.04);
    font-size: 0.925rem;
}

.table > thead.table-light {
    background: var(--color-bg-soft) !important;
    border-bottom: 2px solid var(--color-border);
}

.table > thead th {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-text-muted);
    padding: 0.85rem 1rem;
    white-space: nowrap;
}

.table > tbody td {
    padding: 0.75rem 1rem;
    vertical-align: middle;
}

.table-hover > tbody > tr:hover {
    background-color: rgba(21, 128, 61, 0.04);
}

/* --- Buttons --- */
.btn {
    font-weight: 600;
    border-radius: var(--radius-sm);
    padding: 0.45rem 1rem;
    transition: transform var(--transition), box-shadow var(--transition);
}

.btn:active {
    transform: scale(0.98);
}

.btn-success,
.btn-primary {
    background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-primary-dark) 100%);
    border: none;
    box-shadow: 0 2px 8px rgba(21, 128, 61, 0.3);
}

.btn-success:hover,
.btn-primary:hover {
    background: linear-gradient(135deg, var(--color-primary-light) 0%, var(--color-primary) 100%);
    box-shadow: 0 4px 12px rgba(21, 128, 61, 0.35);
}

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

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

.btn-sm {
    font-size: 0.8rem;
    padding: 0.3rem 0.65rem;
}

/* --- Forms --- */
.form-control,
.form-select {
    border-radius: var(--radius-sm);
    border-color: var(--color-border);
    padding: 0.55rem 0.85rem;
    font-size: 0.925rem;
    transition: border-color var(--transition), box-shadow var(--transition);
}

.form-control:focus,
.form-select:focus {
    border-color: var(--color-primary-light);
    box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.15);
}

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

/* --- Badges --- */
.badge {
    font-weight: 600;
    font-size: 0.72rem;
    padding: 0.4em 0.65em;
    border-radius: 2rem;
    letter-spacing: 0.02em;
}

/* --- Alerts --- */
.alert {
    border: none;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    font-weight: 500;
}

.alert-success { background: #ecfdf5; color: #065f46; }
.alert-danger { background: #fef2f2; color: #991b1b; }
.alert-warning { background: #fffbeb; color: #92400e; }
.alert-info { background: #eff6ff; color: #1e40af; }

/* --- Progress bars --- */
.progress {
    border-radius: 2rem;
    background: var(--color-bg);
    overflow: hidden;
}

.progress-bar {
    font-size: 0.7rem;
    font-weight: 700;
}

/* --- Page headers --- */
.page-header {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.75rem;
    padding-bottom: 1.25rem;
    border-bottom: 1px solid var(--color-border);
}

.page-header h2 {
    margin-bottom: 0.25rem;
}

.page-header .page-subtitle,
.page-header .text-muted {
    font-size: 0.925rem;
}

.page-header .page-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.page-header-simple {
    margin-bottom: 1.75rem;
}

.page-header-simple h2 {
    margin-bottom: 0.35rem;
}

.back-link {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--color-text-muted);
    text-decoration: none;
    margin-bottom: 0.75rem;
    transition: color var(--transition);
}

.back-link:hover {
    color: var(--color-primary);
}

/* --- Filter / toolbar --- */
.filter-bar {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 1rem 1.25rem;
    margin-bottom: 1.25rem;
    box-shadow: var(--shadow-sm);
}

.filter-bar .form-label {
    margin-bottom: 0.25rem;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--color-text-muted);
    white-space: nowrap;
}

.filter-bar .form-select,
.filter-bar .form-control {
    min-width: 0;
}

.filter-bar--inline {
    padding: 0.75rem 1rem;
}

.filter-bar--inline .filter-bar-row {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: flex-end;
    gap: 0.5rem;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
}

.filter-bar--inline .filter-field {
    flex: 1 1 0;
    min-width: 6.5rem;
    max-width: 12rem;
}

.filter-bar--inline .filter-field--narrow {
    flex: 0 0 4.5rem;
    min-width: 4.5rem;
    max-width: 4.5rem;
}

.filter-bar--inline .filter-field--search {
    flex: 1.2 1 0;
    min-width: 8rem;
    max-width: 14rem;
}

.filter-bar--inline .form-select,
.filter-bar--inline .form-control {
    font-size: 0.875rem;
    padding-top: 0.35rem;
    padding-bottom: 0.35rem;
}

.filter-bar--inline .filter-actions {
    flex: 0 0 auto;
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: 0.5rem;
    white-space: nowrap;
    margin-left: auto;
    padding-bottom: 0.125rem;
}

.filter-bar--inline .filter-actions .btn {
    white-space: nowrap;
}

.list-pagination {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    width: 100%;
}

.list-pagination-meta {
    line-height: 1.4;
}

.list-pagination-page {
    white-space: nowrap;
}

.list-pagination .pagination .page-link {
    min-width: 2rem;
    text-align: center;
}

/* --- Nav grid cards (référentiels, paramètres) --- */
a.nav-card {
    text-decoration: none;
    color: var(--color-text);
}

a.nav-card .card-body {
    padding: 1.5rem;
}

a.nav-card:hover {
    color: var(--color-text);
}

a.nav-card .nav-card-icon {
    width: 3rem;
    height: 3rem;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.35rem;
    margin-bottom: 0.75rem;
}

a.nav-card .nav-card-icon.icon-green { background: #ecfdf5; color: var(--color-primary); }
a.nav-card .nav-card-icon.icon-blue { background: #eff6ff; color: #2563eb; }
a.nav-card .nav-card-icon.icon-amber { background: #fffbeb; color: #d97706; }
a.nav-card .nav-card-icon.icon-red { background: #fef2f2; color: #dc2626; }
a.nav-card .nav-card-icon.icon-purple { background: #f5f3ff; color: #7c3aed; }

a.nav-card h5 {
    font-weight: 700;
    font-size: 1.05rem;
    margin-bottom: 0.25rem;
}

a.nav-card .nav-card-meta {
    font-size: 0.8rem;
    color: var(--color-text-muted);
}

/* --- KPI row --- */
.kpi-row .stat-card .card-body h4,
.kpi-row .stat-card .card-body h3 {
    font-weight: 800;
    letter-spacing: -0.02em;
    margin-bottom: 0;
}

.kpi-row .stat-card .card-body small.text-muted {
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-size: 0.72rem;
}

/* --- Progress bars --- */
.progress-mep {
    height: 1.25rem;
    min-width: 5.5rem;
}

.table .col-chevron {
    width: 2rem;
    padding-left: 0.5rem !important;
    padding-right: 0 !important;
}

/* --- Input groups --- */
.input-group-text {
    background: var(--color-bg-soft);
    border-color: var(--color-border);
    color: var(--color-text-muted);
}

.input-group .form-control.border-start-0:focus {
    box-shadow: none;
}

.input-group:focus-within {
    box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.15);
    border-radius: var(--radius-sm);
}

.input-group:focus-within .input-group-text,
.input-group:focus-within .form-control {
    border-color: var(--color-primary-light);
}

/* --- Outline buttons --- */
.btn-outline-danger {
    border-color: #fca5a5;
    color: #dc2626;
}

.btn-outline-danger:hover {
    background: #dc2626;
    border-color: #dc2626;
}

.btn-outline-success {
    border-color: #86efac;
    color: var(--color-primary);
}

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

.btn-outline-secondary {
    border-color: var(--color-border);
    color: var(--color-text-muted);
}

.btn-outline-secondary:hover {
    background: var(--color-bg-soft);
    border-color: #cbd5e1;
    color: var(--color-text);
}

/* --- Form pages --- */
.form-card {
    max-width: 42rem;
}

.form-card .card-body {
    padding: 1.75rem;
}

/* --- Summary banner --- */
.summary-banner {
    background: linear-gradient(135deg, #ecfdf5 0%, #f0fdf4 100%);
    border: 1px solid #bbf7d0;
    border-radius: var(--radius-md);
    padding: 1rem 1.25rem;
    margin-bottom: 1.25rem;
}

.summary-banner .summary-item {
    text-align: center;
}

.summary-banner .summary-item small {
    display: block;
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--color-text-muted);
    margin-bottom: 0.15rem;
}

.summary-banner .summary-item strong {
    font-size: 1.25rem;
    font-weight: 800;
    color: var(--color-primary-dark);
}

/* --- Status badges in tables --- */
.table .badge {
    min-width: 4.5rem;
}

/* --- Empty success state --- */
.table td.text-center.text-success {
    padding: 2.5rem 1rem !important;
    font-weight: 500;
}

/* --- Pagination --- */
.pagination .page-link {
    border-radius: var(--radius-sm);
    margin: 0 0.15rem;
    border-color: var(--color-border);
    color: var(--color-text);
    font-weight: 600;
    font-size: 0.875rem;
}

.pagination .page-item.active .page-link {
    background: var(--color-primary);
    border-color: var(--color-primary);
}

/* --- Page headers (legacy block kept for compat) --- */
.page-header-legacy {
    margin-bottom: 1.75rem;
}

.page-header-legacy h2 {
    margin-bottom: 0.25rem;
}

.page-header-legacy .page-subtitle {
    color: var(--color-text-muted);
    font-size: 0.95rem;
}

/* --- Auth / Login --- */
body.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    background:
        linear-gradient(135deg, rgba(15, 61, 36, 0.92) 0%, rgba(20, 83, 45, 0.88) 100%),
        url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23ffffff' fill-opacity='0.04'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
}

body.auth-page .main-content {
    margin-left: 0;
    width: 100%;
    max-width: 100%;
    padding: 2rem;
}

.auth-card {
    border: none !important;
    border-radius: var(--radius-lg) !important;
    box-shadow: var(--shadow-lg) !important;
    overflow: hidden;
}

.auth-card .auth-logo {
    width: 4.5rem;
    height: 3rem;
    margin: 0 auto 1rem;
    border-radius: var(--radius-sm);
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--color-border);
}

.senegal-flag-auth {
    width: 4.5rem;
    height: 3rem;
}

/* --- Map --- */
#map {
    height: 400px;
    border-radius: var(--radius-md);
    border: 1px solid var(--color-border);
}

/* --- Quotas expandable rows --- */
.quota-summary-row { cursor: pointer; }
.quota-summary-row .quota-chevron { transition: transform var(--transition); }
.quota-summary-row[aria-expanded="true"] .quota-chevron { transform: rotate(90deg); }
.quota-detail-table { background: var(--color-bg-soft); }
.quota-detail-table thead th { font-size: 0.75rem; }

/* --- Pluviométrie --- */
.pluvio-table input {
    min-width: 4rem;
    text-align: center;
    border-radius: var(--radius-sm);
}

.pluvio-table th {
    font-size: 0.75rem;
    white-space: nowrap;
    background: var(--color-bg-soft);
}

.pluvio-region-row { cursor: pointer; }
.pluvio-region-row .pluvio-chevron { transition: transform var(--transition); }
.pluvio-region-row[aria-expanded="true"] .pluvio-chevron { transform: rotate(90deg); }

/* --- Empty states --- */
.table td.text-center.text-muted {
    padding: 2.5rem 1rem !important;
    font-style: italic;
    color: var(--color-text-muted) !important;
}

/* --- Scrollbar (webkit) --- */
.sidebar-nav-scroll::-webkit-scrollbar,
.sidebar::-webkit-scrollbar,
.table-responsive::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

.sidebar-nav-scroll::-webkit-scrollbar-thumb,
.sidebar::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
}

/* --- Responsive --- */
@media (max-width: 992px) {
    .app-shell {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        transform: translateX(-100%);
        transition: transform var(--transition);
        height: 100vh;
        width: min(var(--sidebar-width), 85vw);
    }

    body.sidebar-open .sidebar {
        transform: translateX(0);
    }

    body.sidebar-open .sidebar-backdrop {
        display: block;
    }

    body.sidebar-open {
        overflow: hidden;
    }

    .sidebar-toggle {
        display: flex;
    }

    .main-content {
        padding: 1.25rem 1rem 2rem;
    }

    h2 {
        font-size: 1.35rem;
    }
}
