/* =====================================================================
   Responsive rules (mobile-first adjustments for 360px → desktop)
   ===================================================================== */

/* Tablets & below: sidebar becomes an off-canvas drawer */
@media (max-width: 991.98px) {
    .app-main, body.sidebar-collapsed .app-main { margin-left: 0; }
    .sidebar, body.sidebar-collapsed .sidebar { width: min(86vw, 300px); transform: translateX(-100%); box-shadow: none; }
    body.sidebar-open .sidebar { transform: translateX(0); box-shadow: 0 0 40px rgba(7,26,45,.4); }
    body.sidebar-collapsed .brand-text, body.sidebar-collapsed .nav-link-main span, body.sidebar-collapsed .nav-caret, body.sidebar-collapsed .sidebar-footer { display: revert !important; }
    body.sidebar-collapsed .nav-group.open .nav-sub { display: block !important; }
    body.sidebar-collapsed .nav-link-main { justify-content: flex-start; padding: 10px 12px; }
    body.sidebar-collapsed .sidebar-brand { justify-content: space-between; padding: 0 16px; }
    .sidebar-backdrop { position: fixed; inset: 0; background: rgba(7, 26, 45, .52); z-index: 1035; opacity: 0; pointer-events: none; transition: opacity .2s; }
    body.sidebar-open .sidebar-backdrop { opacity: 1; pointer-events: auto; }
    body.sidebar-open { overflow: hidden; }
    .app-content { padding: 18px 16px 28px; }
    .app-footer { padding: 12px 16px; }
    .topbar { padding: 0 12px; gap: 8px; }
    .topbar-search { width: 260px; }
}

/* Phones */
@media (max-width: 767.98px) {
    :root { --ss-topbar-h: 58px; }
    body { font-size: .95rem; }
    .topbar-title { font-size: .95rem; flex: 1; }
    .topbar-search { display: none; position: absolute; left: 8px; right: 8px; top: calc(var(--ss-topbar-h) - 2px); width: auto; max-width: none; margin: 0; background: var(--ss-surface); padding: 8px; border-radius: 12px; box-shadow: var(--ss-shadow-lg); }
    body.search-open .topbar-search { display: block; }
    .topbar-search > .bi-search { left: 20px; }
    .topbar-actions { margin-left: auto; gap: 2px; }
    .page-header { align-items: stretch; flex-direction: column; margin-bottom: 14px; }
    .page-title { font-size: 1.25rem; }
    .page-actions { width: 100%; }
    .page-actions > .btn, .page-actions > a.btn, .page-actions > form { flex: 1 1 auto; }
    .page-actions > form > .btn { width: 100%; }
    .card-body { padding: 14px; }
    .card-header { padding: 12px 14px; }
    .kpi-card { padding: 12px; gap: 10px; }
    .kpi-icon { width: 38px; height: 38px; font-size: 1.05rem; border-radius: 10px; }
    .kpi-value { font-size: 1.15rem; }
    .kpi-label { font-size: .7rem; }
    .chart-box { height: 230px; }
    .detail-list { grid-template-columns: 1fr; gap: 2px; }
    .detail-list dd { margin-bottom: 8px; }
    .form-actions { position: sticky; bottom: 0; background: rgba(255,253,248,.97); margin: 0 -14px -14px; padding: 12px 14px; border-top: 1px solid var(--ss-border); z-index: 5; }
    .form-actions .btn { flex: 1 1 auto; }
    .btn { min-height: 42px; }
    .btn-sm { min-height: 34px; }
    .form-control, .form-select { font-size: 16px; } /* prevents iOS zoom */
    .profile-photo { width: 84px; height: 84px; }
    .profile-tag { font-size: 1.25rem; }
    .notif-menu { position: fixed !important; left: 8px !important; right: 8px !important; top: var(--ss-topbar-h) !important; transform: none !important; width: auto; }

    /* Stack wide tables into cards */
    .table-mobile-cards thead { display: none; }
    .table-mobile-cards, .table-mobile-cards tbody, .table-mobile-cards tr, .table-mobile-cards td { display: block; width: 100%; }
    .table-mobile-cards tr { border: 1px solid var(--ss-border); border-radius: var(--ss-radius-sm); margin: 0 0 10px; background: var(--ss-surface); padding: 6px 4px; }
    .table-mobile-cards > :not(caption) > * > * { border-bottom: 0; padding: .35rem .75rem; }
    .table-mobile-cards td[data-label] { display: flex; justify-content: space-between; gap: 12px; text-align: right; }
    .table-mobile-cards td[data-label]::before { content: attr(data-label); font-weight: 600; color: var(--ss-text-muted); font-size: .76rem; text-transform: uppercase; letter-spacing: .03em; text-align: left; flex-shrink: 0; }
    .table-mobile-cards td.actions-cell { justify-content: flex-end; text-align: right; display: flex; flex-wrap: wrap; gap: 6px; border-top: 1px dashed var(--ss-border); margin-top: 4px; padding-top: 8px; }
    .table-mobile-cards td.actions-cell::before { display: none; }
    .table-mobile-cards td.cell-primary { text-align: left; justify-content: flex-start; }
    .table-mobile-cards td.cell-primary::before { display: none; }
    .table-mobile-cards tfoot { display: block; }
    .table-mobile-cards tfoot tr { background: var(--ss-primary-50); }
    .table-card .table-mobile-cards { padding: 10px; }
    .tree-node { min-width: 120px; font-size: .78rem; }
}

@media (max-width: 400px) {
    .app-content { padding: 14px 12px 24px; }
    .kpi-value { font-size: 1.05rem; }
    .user-chip { padding: 2px; border: 0; }
}

/* Large screens: a bit more breathing room */
@media (min-width: 1400px) {
    .app-content { padding: 28px 36px 40px; }
}
