/* ══════════════════════════════════════════════════════════════
   UNI-ISM Admin — Unified blue theme matching mobile apps
   Primary: #1565C0  Secondary: #4CAF50  Accent: #F57F17
   ══════════════════════════════════════════════════════════════ */

:root {
    --primary: #1565C0;
    --primary-dark: #0D47A1;
    --primary-light: #D1E4FF;
    --secondary: #4CAF50;
    --secondary-light: #E8F5E9;
    --accent: #F57F17;
    --accent-light: #FFF8E1;
    --danger: #D32F2F;
    --danger-light: #FFEBEE;
    --text-primary: #1A1C1E;
    --text-secondary: #44474F;
    --bg: #F5F7FA;
    --surface: #FFFFFF;
    --sidebar-width: 260px;
}

* { box-sizing: border-box; }

body {
    font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text-primary);
    margin: 0;
    min-height: 100vh;
}

/* ── Sidebar ─────────────────────────────────────────────────── */
.sidebar {
    position: fixed;
    top: 0; left: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--primary-dark);
    color: white;
    z-index: 1000;
    overflow-y: auto;
    transition: transform .3s;
}

.sidebar-brand {
    padding: 20px 24px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid rgba(255,255,255,.12);
}

.sidebar-brand .brand-icon {
    width: 40px; height: 40px;
    background: rgba(255,255,255,.15);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
}

.sidebar-brand h5 { margin: 0; font-weight: 700; font-size: 1.1rem; }
.sidebar-brand small { opacity: .7; font-size: .75rem; }

.sidebar-nav { padding: 16px 0; }

.sidebar-nav .nav-section {
    padding: 8px 24px 4px;
    font-size: .7rem;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    opacity: .5;
    font-weight: 600;
}

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 24px;
    color: rgba(255,255,255,.75);
    text-decoration: none;
    font-size: .9rem;
    border-radius: 0;
    transition: all .15s;
}

.sidebar-nav a:hover { background: rgba(255,255,255,.08); color: white; }
.sidebar-nav a.active { background: rgba(255,255,255,.15); color: white; font-weight: 600; }
.sidebar-nav a .nav-icon { font-size: 1.1rem; width: 24px; text-align: center; }

/* ── Main content area ───────────────────────────────────────── */
.main-content {
    margin-left: var(--sidebar-width);
    width: calc(100% - var(--sidebar-width));
    max-width: calc(100vw - var(--sidebar-width));
    min-height: 100vh;
    overflow-x: hidden;
}

/* ── Top bar ─────────────────────────────────────────────────── */
.topbar {
    background: var(--surface);
    border-bottom: 1px solid #e0e0e0;
    padding: 0 32px;
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
}

.topbar h4 { margin: 0; font-weight: 600; color: var(--text-primary); }

.topbar .user-menu {
    display: flex;
    align-items: center;
    gap: 12px;
}

.topbar .user-avatar {
    width: 36px; height: 36px;
    background: var(--primary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 700;
    font-size: .85rem;
}

/* ── Content padding ──────────────────────────────────────────── */
.page-content { padding: 32px; min-width: 0; max-width: 100%; overflow-x: hidden; box-sizing: border-box; }
.page-content .row { max-width: 100%; margin-left: 0; margin-right: 0; }

/* ── Stat cards ───────────────────────────────────────────────── */
.stat-card {
    background: var(--surface);
    border-radius: 16px;
    padding: 24px;
    border: 1px solid #e8ecf0;
    transition: box-shadow .2s;
}
.stat-card:hover { box-shadow: 0 4px 20px rgba(0,0,0,.08); }

.stat-card .stat-icon {
    width: 48px; height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    margin-bottom: 16px;
}

.stat-card .stat-value {
    font-size: 2rem;
    font-weight: 700;
    line-height: 1.1;
}

.stat-card .stat-label {
    font-size: .85rem;
    color: var(--text-secondary);
    margin-top: 4px;
}

.stat-card .stat-change {
    font-size: .78rem;
    margin-top: 8px;
}

.icon-blue { background: var(--primary-light); color: var(--primary); }
.icon-green { background: var(--secondary-light); color: var(--secondary); }
.icon-amber { background: var(--accent-light); color: var(--accent); }
.icon-red { background: var(--danger-light); color: var(--danger); }

/* ── Charts ──────────────────────────────────────────────────── */
.chart-card {
    background: var(--surface);
    border-radius: 16px;
    padding: 24px;
    border: 1px solid #e8ecf0;
    max-width: 100%;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.chart-card h6 {
    font-weight: 600;
    margin-bottom: 16px;
    color: var(--text-primary);
    flex: 0 0 auto;
}

/*
 * Canonical Chart.js responsive container.
 * Chart.js with maintainAspectRatio:false fills its parent; the parent MUST
 * have a bounded height, otherwise the canvas grows indefinitely and pushes
 * the card height on every resize (infinite-stretch bug).
 */
.chart-container {
    position: relative;
    width: 100%;
    height: 320px;
    flex: 0 0 auto;
}

.chart-container.chart-sm { height: 220px; }
.chart-container.chart-lg { height: 420px; }

.chart-container canvas {
    max-width: 100% !important;
    max-height: 100% !important;
}

/* Safety net: lone canvases inside chart-card (non-wrapped legacy markup). */
.chart-card > canvas {
    max-width: 100% !important;
    max-height: 360px !important;
}

/* ── Tables ──────────────────────────────────────────────────── */
.data-table {
    background: var(--surface);
    border-radius: 16px;
    border: 1px solid #e8ecf0;
    overflow-x: auto;
    max-width: 100%;
}

.data-table .table {
    margin: 0;
    width: 100%;
    max-width: 100%;
    table-layout: fixed;
}

.data-table .table th {
    background: #f8f9fc;
    border-top: none;
    font-weight: 600;
    font-size: .82rem;
    text-transform: uppercase;
    letter-spacing: .5px;
    color: var(--text-secondary);
    padding: 12px 16px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.data-table .table td {
    padding: 12px 16px;
    vertical-align: middle;
    font-size: .9rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 250px;
}

.data-table .table td.wrap-cell {
    white-space: normal;
    word-wrap: break-word;
}

/* ── Badges / Status ──────────────────────────────────────────── */
.badge-status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: .78rem;
    font-weight: 600;
}

.badge-active { background: var(--secondary-light); color: #2E7D32; }
.badge-inactive { background: #f5f5f5; color: #757575; }
.badge-treatment { background: var(--primary-light); color: var(--primary); }
.badge-census { background: var(--accent-light); color: #E65100; }
.badge-planned { background: #f3e5f5; color: #7B1FA2; }
.badge-completed { background: var(--secondary-light); color: #1B5E20; }

/* ── Buttons ──────────────────────────────────────────────────── */
.btn-primary-custom {
    background: var(--primary);
    border: none;
    color: white;
    border-radius: 12px;
    padding: 10px 24px;
    font-weight: 600;
    transition: all .15s;
}
.btn-primary-custom:hover { background: var(--primary-dark); color: white; }

.btn-outline-custom {
    border: 2px solid var(--primary);
    color: var(--primary);
    border-radius: 12px;
    padding: 8px 22px;
    font-weight: 600;
    background: transparent;
}
.btn-outline-custom:hover { background: var(--primary); color: white; }

/* ── Login page ──────────────────────────────────────────────── */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 100%);
}

.login-card {
    background: white;
    border-radius: 24px;
    padding: 48px;
    width: 420px;
    max-width: 90vw;
    box-shadow: 0 20px 60px rgba(0,0,0,.3);
}

.login-card .login-icon {
    width: 80px; height: 80px;
    background: var(--primary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 20px;
    font-size: 2rem;
    color: white;
}

.login-card h3 { text-align: center; font-weight: 700; color: var(--primary); }
.login-card .subtitle { text-align: center; color: var(--text-secondary); margin-bottom: 8px; }
.login-card .warning { text-align: center; color: var(--accent); font-size: .85rem; font-weight: 600; margin-bottom: 32px; }

.login-card .form-control {
    border-radius: 12px;
    padding: 12px 16px;
    border: 2px solid #e0e0e0;
}
.login-card .form-control:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(21,101,192,.15); }

.login-card .btn-login {
    width: 100%;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 12px;
    padding: 14px;
    font-size: 1rem;
    font-weight: 600;
    margin-top: 16px;
}
.login-card .btn-login:hover { background: var(--primary-dark); }

/* ── Responsive ──────────────────────────────────────────────── */
@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.show { transform: translateX(0); }
    .main-content { margin-left: 0; width: 100%; max-width: 100vw; }
    .page-content { padding: 16px; }
}

/* ── KPI row ─────────────────────────────────────────────────── */
.kpi-row { margin-bottom: 32px; }

/* ── Coverage map placeholder ─────────────────────────────────── */
.map-placeholder {
    background: #e3f2fd;
    border-radius: 16px;
    height: 300px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--primary);
    font-weight: 600;
}

/* ── Modal ────────────────────────────────────────────────────── */
.modal-content { border-radius: 16px; border: none; }
.modal-header { background: var(--primary); color: white; border-radius: 16px 16px 0 0; }
.modal-header .btn-close { filter: brightness(0) invert(1); }

/*
 * Mobile fix: prevent the modal-footer (Enregistrer/Annuler buttons) from
 * being hidden behind the Android navigation bar when the form is longer
 * than the viewport. We cap the modal height and let the body scroll.
 */
.modal-dialog {
    max-height: calc(100vh - env(safe-area-inset-bottom, 0) - 24px);
}
.modal-content {
    max-height: calc(100vh - env(safe-area-inset-bottom, 0) - 24px);
}
.modal-dialog-scrollable .modal-content {
    max-height: calc(100vh - env(safe-area-inset-bottom, 0) - 24px);
}
.modal-footer {
    position: sticky;
    bottom: 0;
    background: var(--surface);
    border-top: 1px solid #e8ecf0;
    border-radius: 0 0 16px 16px;
    padding-bottom: calc(0.75rem + env(safe-area-inset-bottom, 0));
    z-index: 2;
}
@media (max-width: 576px) {
    .modal-dialog { margin: 8px; }
    .modal-body { max-height: calc(100vh - 200px); overflow-y: auto; }
}

/* ── Action row ──────────────────────────────────────────────── */
.action-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
}

.search-box {
    position: relative;
    width: 300px;
}
.search-box input {
    padding-left: 40px;
    border-radius: 12px;
    border: 2px solid #e0e0e0;
}
.search-box .search-icon {
    position: absolute;
    left: 12px; top: 50%;
    transform: translateY(-50%);
    color: #9e9e9e;
}

/* ── Alert cards ─────────────────────────────────────────────── */
.alert-card {
    border-radius: 12px;
    border: none;
    padding: 16px 20px;
}
