/**
 * ApiWeb — Responsive tablette & smartphone uniquement.
 * Aucune règle hors media query : le rendu PC (≥992px) reste inchangé.
 */

/* ============================================================
   TABLETTE — 768px à 991px
   ============================================================ */
@media (min-width: 768px) and (max-width: 991.98px) {

    .content {
        padding: 22px;
    }

    .dashboard-card {
        padding: 20px;
        gap: 16px;
    }

    .dashboard-card .icon {
        width: 60px;
        height: 60px;
        font-size: 26px;
    }

    .dashboard-section {
        padding: 16px;
    }

    .map-container {
        padding: 16px;
    }

    #map {
        height: 480px;
    }

    #graphContainer {
        height: 65vh;
    }

    .graphContainer {
        height: 150px;
    }

    .card-mini .card-title {
        font-size: 0.9rem;
    }

    .topbar {
        flex-wrap: wrap;
        gap: 12px;
    }

    .topbar h2 {
        font-size: 1.45rem;
    }

    /* Tableaux plus compacts */
    .content table.table,
    .container table.table {
        font-size: 0.9rem;
    }

    .content table.table th,
    .content table.table td,
    .container table.table th,
    .container table.table td {
        padding: 0.45rem 0.55rem;
    }

    .container.py-4 {
        padding-left: 22px;
        padding-right: 22px;
    }

    /* Boutons légèrement agrandis (touch) */
    .content .btn-sm,
    .container .btn-sm {
        padding: 0.35rem 0.7rem;
        font-size: 0.875rem;
    }

    .content .btn:not(.btn-sm):not(.btn-lg),
    .container .btn:not(.btn-sm):not(.btn-lg) {
        padding: 0.5rem 1.1rem;
    }

    .rucher-map {
        height: 280px;
    }

    .alerte-summary {
        padding: 18px;
        gap: 16px;
    }

    .alerte-summary h3 {
        font-size: 1.65rem;
    }
}

/* ============================================================
   SMARTPHONE — ≤767px
   ============================================================ */
@media (max-width: 767.98px) {

    body {
        overflow-x: hidden;
    }

    /* --- Menu hamburger (sidebar off-canvas) --- */
    .mobile-menu-toggle {
        position: fixed;
        top: 10px;
        left: 10px;
        z-index: 1050;
        width: 44px;
        height: 44px;
        border: none;
        border-radius: 10px;
        background: var(--perso-menu-bg, #2f3542);
        color: var(--perso-primary, #ffc107);
        font-size: 1.5rem;
        display: flex;
        align-items: center;
        justify-content: center;
        box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
        cursor: pointer;
    }

    .mobile-menu-toggle:active {
        transform: scale(0.96);
    }

    .sidebar-overlay {
        position: fixed;
        inset: 0;
        z-index: 1040;
        background: rgba(0, 0, 0, 0.45);
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.25s ease, visibility 0.25s ease;
    }

    body.sidebar-open .sidebar-overlay {
        opacity: 1;
        visibility: visible;
    }

    .wrapper {
        display: block;
    }

    .sidebar {
        position: fixed !important;
        left: 0;
        top: 0;
        bottom: 0;
        width: var(--perso-sidebar-width);
        height: auto !important;
        z-index: 1045;
        transform: translateX(-100%);
        transition: transform 0.28s ease;
    }

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

    .content {
        margin-left: 0 !important;
        padding: 14px;
        padding-top: 58px;
        max-width: 100vw;
    }

    /* --- Topbar --- */
    .topbar,
    .topbar-cover {
        flex-direction: column;
        align-items: stretch !important;
        gap: 12px;
        margin-bottom: 20px;
    }

    .topbar h2,
    .topbar-cover h2 {
        font-size: 1.35rem;
    }

    .topbar .date,
    .topbar > .d-flex {
        width: 100%;
    }

    .topbar .d-flex.gap-2,
    .topbar .d-flex.align-items-center {
        flex-direction: column;
        align-items: stretch !important;
    }

    .graphs-header {
        flex-direction: column;
        align-items: stretch !important;
    }

    /* --- Cartes dashboard --- */
    .dashboard-card {
        padding: 16px;
        gap: 14px;
    }

    .dashboard-card .icon {
        width: 54px;
        height: 54px;
        font-size: 22px;
        flex-shrink: 0;
    }

    .dashboard-card h2 {
        font-size: 1.5rem;
    }

    .dashboard-section {
        padding: 14px;
        margin-top: 1rem;
    }

    .map-container {
        padding: 14px;
    }

    .map-header {
        font-size: 1.15rem;
    }

    #map {
        height: 300px;
    }

    .rucher-map {
        height: 240px;
    }

    /* --- Graphiques --- */
    .graphContainer {
        height: auto;
        min-height: 130px;
        width: 100%;
    }

    .graphContainer canvas,
    .content canvas {
        max-width: 100% !important;
        height: auto !important;
    }

    .card-mini {
        width: 100%;
    }

    /* --- Boutons --- */
    .content .btn {
        min-height: 42px;
    }

    .content .btn-sm {
        min-height: 38px;
    }

    .content .d-grid .btn,
    .content form .btn-primary,
    .content form .btn-success,
    .content form .btn-danger,
    .content .modal-footer .btn {
        width: 100%;
    }

    .content .topbar .btn,
    .content .graphs-header .btn,
    .content .dashboard-section > .d-flex .btn {
        width: 100%;
    }

    .content .btn-group,
    .content .btn-group .btn {
        width: auto;
    }

    /* --- Formulaires une colonne --- */
    .content .row.g-2 > [class*="col-"],
    .content .row.g-3 > [class*="col-"],
    .content .row.g-4 > [class*="col-"],
    .content form .row > [class*="col-"] {
        flex: 0 0 100%;
        max-width: 100%;
    }

    .content .form-select,
    .content .form-control {
        font-size: 16px; /* évite zoom iOS */
    }

    /* --- Cartes ruchers / balances --- */
    .card-balance .valeur {
        font-size: 24px;
    }

    .rucher-card-photo {
        height: 140px;
    }

    .alerte-summary {
        padding: 14px;
        gap: 12px;
    }

    .alerte-summary h3 {
        font-size: 1.4rem;
    }

    .alerte-card .d-flex.flex-wrap.gap-1 .btn {
        flex: 1 1 calc(50% - 4px);
        min-width: 0;
    }

    /* --- Tableaux → cartes (JS ajoute .is-mobile-cards) --- */
    .table-mobile-wrap.is-mobile-cards > table.table {
        display: none;
    }

    .mobile-table-cards {
        display: block;
    }

    .mobile-table-card {
        border-radius: 12px;
    }

    .mobile-table-card .card-body {
        padding: 0.75rem 1rem !important;
    }

    .mobile-table-row {
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
        gap: 10px;
        padding: 7px 0;
        border-bottom: 1px solid rgba(0, 0, 0, 0.06);
    }

    .mobile-table-row:last-child {
        border-bottom: none;
    }

    .mobile-table-label {
        font-size: 0.72rem;
        text-transform: uppercase;
        letter-spacing: 0.03em;
        color: #888;
        flex: 0 0 38%;
    }

    .mobile-table-value {
        flex: 1;
        text-align: right;
        font-size: 0.9rem;
        word-break: break-word;
    }

    .mobile-table-value .btn {
        width: auto;
        min-height: 34px;
    }

    /* --- Paramètres --- */
    .param-tabs {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 4px;
    }

    .param-tabs .nav-link {
        padding: 8px 12px;
        font-size: 0.85rem;
        white-space: nowrap;
    }

    /* --- Login --- */
    .login-card {
        margin-left: 12px;
        margin-right: 12px;
    }

    /* --- Footer --- */
    .site-footer {
        font-size: 0.8rem;
        text-align: center;
    }

    /* --- Pages graphique standalone --- */
    #graphContainer {
        height: 55vh !important;
        min-height: 260px;
        width: 100%;
    }

    .card-header.d-flex.justify-content-between {
        flex-direction: column;
        align-items: stretch !important;
        gap: 10px;
    }

    .card-header.d-flex .btn,
    .card-header.d-flex > div .btn {
        width: 100%;
        margin-bottom: 4px;
    }

    .container-fluid {
        padding-left: 12px;
        padding-right: 12px;
    }

    /* --- Pages standalone (balance, etc.) --- */
    .container.py-4 {
        padding: 14px 12px;
        max-width: 100%;
    }

    .container .d-flex.justify-content-between.align-items-center {
        flex-direction: column;
        align-items: stretch !important;
        gap: 12px;
    }

    .container .d-flex.justify-content-between .btn {
        width: 100%;
    }

    .container .value {
        font-size: 28px;
    }

    .container .row.g-4 > [class*="col-"] {
        flex: 0 0 100%;
        max-width: 100%;
    }

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

    .container .form-select,
    .container .form-control {
        font-size: 16px;
    }

    .content .dashboard-section .d-flex.gap-2,
    .content .dashboard-section .d-flex.gap-2 .form-select {
        flex-direction: column;
        max-width: 100% !important;
        width: 100%;
    }

    .content .dashboard-section .d-flex.gap-2 .btn {
        width: 100%;
    }
}

/* Masquer les cartes mobiles sur tablette et PC */
@media (min-width: 768px) {
    .mobile-table-cards {
        display: none !important;
    }
}
