/* ================================================================
   UISB App — Responsive / Mobile Stylesheet
   Supplements Bootstrap 5. Linked from layouts/main.php
   ================================================================ */

/* ── CSS Variables ─────────────────────────────────────────────── */
:root {
    --sidebar-width: 250px;
    --topbar-height: 60px;
    --color-bg-main:    #dddddd;
    --color-bg-sidebar: #B2BEB5;
    --color-border:     #000000;
}

/* ── Base ──────────────────────────────────────────────────────── */
body,
body * {
    color: #000000 !important;
}

body {
    min-height: 100vh;
    background: var(--color-bg-main);
    overflow-x: hidden;
}

/* ── Sidebar ───────────────────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-width);
    height: 100vh;
    position: fixed;
    top: 0;
    left: 0;
    z-index: 1045;
    background: var(--color-bg-sidebar);
    display: flex;
    flex-direction: column;
    transition: transform 0.28s ease-in-out;
    overflow: hidden;
}

.sidebar-brand {
    padding: 1rem;
    border-bottom: 1px solid var(--color-border);
    flex-shrink: 0;
}

.sidebar-brand h5 {
    margin: 0;
    font-size: 0.9rem;
    font-weight: 600;
}

.sidebar-brand small {
    font-size: 0.72rem;
}

.sidebar-nav-wrap {
    flex: 1 1 auto;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 0.5rem;
}

/* Sidebar section labels — was 20px, now readable */
.sidebar .nav-section-label {
    font-size: 0.65rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    font-weight: 700;
    padding: 0.75rem 1rem 0.25rem;
    display: block;
    opacity: 0.7;
}

.sidebar .nav-link {
    padding: 0.6rem 1rem;
    border-radius: 0.375rem;
    margin: 0.1rem 0.5rem;
    font-weight: 500;
    font-size: 0.875rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar .nav-link:hover,
.sidebar .nav-link.active {
    background: rgba(0, 0, 0, 0.12);
}

.sidebar .nav-link i {
    flex-shrink: 0;
    width: 20px;
    text-align: center;
    font-size: 1rem;
}

.sidebar-footer {
    flex-shrink: 0;
    padding: 0.75rem 1rem;
    border-top: 1px solid rgba(0, 0, 0, 0.15);
    font-size: 0.75rem;
}

/* ── Sidebar overlay (mobile backdrop) ─────────────────────────── */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 1044;
    cursor: pointer;
}

.sidebar-overlay.show {
    display: block;
}

/* ── Topbar ─────────────────────────────────────────────────────── */
.topbar {
    height: var(--topbar-height);
    background: var(--color-bg-sidebar);
    border-bottom: 2px solid var(--color-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1rem;
    position: sticky;
    top: 0;
    z-index: 1040;
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-width: 0; /* allow truncation */
}

.topbar-title {
    font-size: 0.9rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 40vw;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-shrink: 0;
}

/* Notification dropdown — responsive width */
.notif-dropdown {
    width: min(340px, 92vw) !important;
    max-height: 400px;
    overflow-y: auto;
}

/* User dropdown — truncate long names */
.topbar .user-label {
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display: inline-block;
    vertical-align: middle;
}

/* ── Main content ───────────────────────────────────────────────── */
.main-content {
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    background: var(--color-bg-main);
}

.page-body {
    padding: 1.25rem;
}

/* ── Cards ──────────────────────────────────────────────────────── */
.card {
    border-radius: 0.5rem;
}

/* ── Tables: make them mobile-friendly ─────────────────────────── */
.table-responsive {
    -webkit-overflow-scrolling: touch;
    border-radius: 0.375rem;
}

/* On narrow screens, stack key table data */
@media (max-width: 575.98px) {
    /* Hide low-priority columns tagged with .d-mobile-none */
    .d-mobile-none {
        display: none !important;
    }
}

/* ── Buttons / action rows ──────────────────────────────────────── */
.page-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
    margin-bottom: 1rem;
}

.page-actions .btn {
    white-space: nowrap;
}

/* ── Stat cards: always show in a responsive grid ───────────────── */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 0.75rem;
    margin-bottom: 1rem;
}

/* ── Auth layout ────────────────────────────────────────────────── */
.auth-wrapper {
    min-height: 100vh;
    background: var(--color-bg-sidebar);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.auth-card {
    width: 100%;
    max-width: 420px;
    border-radius: 0.75rem;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.15);
}

/* ── Touch targets — minimum 44px tap area ─────────────────────── */
.btn,
.nav-link,
.dropdown-item {
    min-height: 38px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.sidebar .nav-link {
    min-height: 42px;
    justify-content: flex-start;
}

.dropdown-item {
    justify-content: flex-start;
}

/* ── Form controls ──────────────────────────────────────────────── */
.form-control,
.form-select {
    font-size: 1rem; /* prevent iOS zoom-in on focus */
}

/* ── Alerts ─────────────────────────────────────────────────────── */
.alert {
    border-radius: 0.5rem;
}

/* ================================================================
   MOBILE  (max-width: 767px)
   ================================================================ */
@media (max-width: 767.98px) {

    /* Sidebar hidden off-screen; shown via .show class */
    .sidebar {
        transform: translateX(-100%);
        box-shadow: 4px 0 16px rgba(0, 0, 0, 0.18);
    }

    .sidebar.show {
        transform: translateX(0);
    }

    /* Main content fills full width */
    .main-content {
        margin-left: 0;
    }

    /* Smaller page padding */
    .page-body {
        padding: 0.875rem 0.75rem;
    }

    /* Topbar title: shorter max-width on small screens */
    .topbar-title {
        max-width: 30vw;
    }

    /* Cards: slightly less padding */
    .card-body {
        padding: 0.875rem;
    }

    /* Stack flex rows that would overflow */
    .flex-mobile-wrap {
        flex-wrap: wrap !important;
    }

    /* Full-width buttons on mobile when inside .d-grid-mobile */
    .d-grid-mobile > .btn,
    .d-grid-mobile > .btn-group {
        width: 100%;
    }

    /* Table font: slightly smaller to fit more columns */
    .table {
        font-size: 0.82rem;
    }

    /* Reduce badge padding */
    .badge {
        font-size: 0.68rem;
        padding: 0.28em 0.5em;
    }

    /* Row stat cards: 2 per row on mobile */
    .row-stats > [class*="col-"] {
        flex: 0 0 50%;
        max-width: 50%;
    }

    /* Heading sizes */
    h5.page-title { font-size: 1rem; }

    /* Notification dropdown */
    .notif-dropdown {
        right: -60px !important; /* keep it on screen */
    }
}

/* ================================================================
   SMALL PHONES  (max-width: 374px)
   ================================================================ */
@media (max-width: 374px) {
    .topbar-title {
        display: none; /* hide page title, keep icons visible */
    }

    .page-body {
        padding: 0.625rem 0.5rem;
    }

    .stat-grid {
        grid-template-columns: 1fr 1fr;
    }
}

/* ================================================================
   TABLET  (768px – 991px)
   ================================================================ */
@media (min-width: 768px) and (max-width: 991.98px) {
    :root {
        --sidebar-width: 220px;
    }

    .topbar-title {
        max-width: 35vw;
    }

    .page-body {
        padding: 1rem;
    }
}

/* ================================================================
   PRINT
   ================================================================ */
@media print {
    .sidebar, .topbar, .no-print { display: none !important; }
    .main-content { margin-left: 0 !important; }
    .page-body { padding: 0 !important; }
}
