:root {
    --hubly-sidebar: #172033;
    --hubly-sidebar-light: #202b42;
    --hubly-primary: #2563eb;
    --hubly-bg: #f5f7fb;
    --hubly-border: #e5e7eb;
    --hubly-text: #172033;
    --hubly-muted: #6b7280;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: Inter, "Segoe UI", Arial, sans-serif;
    background: var(--hubly-bg);
    color: var(--hubly-text);
}

.hubly-app {
    min-height: 100vh;
    display: flex;
}

.hubly-sidebar {
    width: 265px;
    min-width: 265px;
    background: var(--hubly-sidebar);
    color: white;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 1000;
    overflow-y: auto;
}

.brand {
    height: 76px;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 22px;
    border-bottom: 1px solid rgba(255,255,255,.08);
}

.brand-mark {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    display: grid;
    place-items: center;
    background: var(--hubly-primary);
    font-size: 21px;
    font-weight: 800;
}

.brand-name {
    font-size: 20px;
    font-weight: 800;
    letter-spacing: 1px;
}

.brand-subtitle {
    font-size: 10px;
    color: #aeb9cb;
    letter-spacing: 1.5px;
}

.school-context {
    padding: 18px 22px;
    border-bottom: 1px solid rgba(255,255,255,.08);
}

.school-context-label {
    font-size: 10px;
    color: #94a3b8;
    letter-spacing: 1px;
    margin-bottom: 5px;
}

.school-context-name {
    font-size: 13px;
    line-height: 1.35;
    color: #e8edf5;
}

.sidebar-nav {
    padding: 12px 10px;
    flex: 1;
}

.nav-section {
    padding: 15px 12px 7px;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 1px;
    color: #7f8ba0;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 43px;
    padding: 9px 13px;
    margin: 2px 0;
    border-radius: 8px;
    color: #cbd5e1;
    text-decoration: none;
    font-size: 14px;
    transition: .15s ease;
}

.nav-item i {
    width: 20px;
    text-align: center;
    font-size: 16px;
}

.nav-item:hover,
.nav-item.active {
    background: var(--hubly-sidebar-light);
    color: white;
}

.sidebar-footer {
    padding: 16px 22px;
    border-top: 1px solid rgba(255,255,255,.08);
    font-size: 10px;
    color: #748096;
    line-height: 1.6;
}

.sidebar-footer .version {
    color: #aeb9cb;
}

.hubly-main {
    margin-left: 265px;
    min-width: 0;
    width: calc(100% - 265px);
}

.hubly-header {
    height: 76px;
    background: white;
    border-bottom: 1px solid var(--hubly-border);
    display: flex;
    align-items: center;
    padding: 0 28px;
    gap: 18px;
    position: sticky;
    top: 0;
    z-index: 900;
}

.sidebar-toggle {
    border: 0;
    background: transparent;
    font-size: 22px;
    color: #475569;
    display: none;
}

.header-title {
    flex: 1;
}

.page-heading {
    font-size: 20px;
    font-weight: 700;
}

.page-school {
    color: var(--hubly-muted);
    font-size: 12px;
    margin-top: 2px;
}

.header-user {
    display: flex;
    align-items: center;
    gap: 10px;
}

.user-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: #e8efff;
    color: var(--hubly-primary);
    display: grid;
    place-items: center;
    font-weight: 700;
}

.user-details {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
}

.user-details strong {
    font-size: 13px;
}

.user-details small {
    color: var(--hubly-muted);
    margin-top: 3px;
}

.logout-button {
    color: #64748b;
    font-size: 19px;
    margin-left: 10px;
}

.hubly-content {
    padding: 28px;
}

.dashboard-welcome {
    margin-bottom: 24px;
}

.dashboard-welcome h1 {
    font-size: 25px;
    margin-bottom: 5px;
}

.dashboard-welcome p {
    color: var(--hubly-muted);
    margin: 0;
}

.metric-card {
    background: white;
    border: 1px solid var(--hubly-border);
    border-radius: 12px;
    padding: 20px;
    height: 100%;
    box-shadow: 0 1px 2px rgba(0,0,0,.03);
}

.metric-label {
    color: var(--hubly-muted);
    font-size: 13px;
    margin-bottom: 10px;
}

.metric-value {
    font-size: 29px;
    font-weight: 750;
}

.metric-icon {
    width: 43px;
    height: 43px;
    display: grid;
    place-items: center;
    border-radius: 10px;
    background: #eef3ff;
    color: var(--hubly-primary);
    font-size: 20px;
}

.module-card {
    display: block;
    height: 100%;
    padding: 20px;
    background: white;
    border: 1px solid var(--hubly-border);
    border-radius: 12px;
    text-decoration: none;
    color: inherit;
    transition: .15s ease;
}

.module-card:hover {
    border-color: #cbd5e1;
    box-shadow: 0 6px 20px rgba(15,23,42,.07);
    transform: translateY(-1px);
}

.module-card i {
    font-size: 25px;
    color: var(--hubly-primary);
}

.module-card h3 {
    font-size: 16px;
    margin: 14px 0 5px;
}

.module-card p {
    color: var(--hubly-muted);
    font-size: 12px;
    margin: 0;
}

.section-title {
    font-size: 17px;
    font-weight: 700;
    margin: 30px 0 15px;
}

@media (max-width: 900px) {
    .hubly-sidebar {
        transform: translateX(-100%);
        transition: transform .2s ease;
    }

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

    .hubly-main {
        margin-left: 0;
        width: 100%;
    }

    .sidebar-toggle {
        display: block;
    }

    .hubly-content {
        padding: 18px;
    }

    .user-details {
        display: none;
    }
}

/* ==========================================================
   HUBLY MOBILE APP EXPERIENCE
   Desktop design remains unchanged above.
   ========================================================== */

.hubly-mobile-backdrop,
.hubly-mobile-nav {
    display: none;
}

@media (max-width: 900px) {

    html,
    body {
        width: 100%;
        max-width: 100%;
        overflow-x: hidden;
    }

    body {
        -webkit-text-size-adjust: 100%;
        padding-bottom: 72px;
    }

    .hubly-app {
        display: block;
        width: 100%;
        min-height: 100dvh;
    }

    /* ---------- MOBILE SIDEBAR ---------- */

    .hubly-sidebar {
        width: min(310px, 86vw);
        min-width: 0;
        height: 100dvh;
        min-height: 100dvh;
        transform: translateX(-105%);
        box-shadow: 12px 0 30px rgba(15, 23, 42, .25);
        transition: transform .22s ease;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

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

    .hubly-mobile-backdrop {
        position: fixed;
        inset: 0;
        z-index: 950;
        background: rgba(15, 23, 42, .48);
        backdrop-filter: blur(2px);
        -webkit-backdrop-filter: blur(2px);
        opacity: 0;
        pointer-events: none;
        transition: opacity .2s ease;
    }

    .hubly-mobile-backdrop.show {
        display: block;
        opacity: 1;
        pointer-events: auto;
    }

    body.sidebar-open {
        overflow: hidden;
    }

    /* ---------- HEADER ---------- */

    .hubly-main {
        width: 100%;
        min-width: 0;
        margin-left: 0;
        padding-bottom: 8px;
    }

    .hubly-header {
        height: 64px;
        min-height: 64px;
        padding: 0 12px;
        gap: 9px;
        position: sticky;
        top: 0;
        z-index: 900;
        box-shadow: 0 1px 6px rgba(15, 23, 42, .06);
    }

    .sidebar-toggle {
        display: grid;
        place-items: center;
        width: 42px;
        height: 42px;
        min-width: 42px;
        border-radius: 12px;
        background: #f1f5f9;
        color: #334155;
        font-size: 23px;
    }

    .header-title {
        min-width: 0;
        overflow: hidden;
    }

    .page-heading {
        font-size: 16px;
        line-height: 1.2;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .page-school {
        font-size: 10px;
        line-height: 1.25;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .header-user {
        gap: 4px;
        flex: 0 0 auto;
    }

    .user-avatar {
        width: 36px;
        height: 36px;
        min-width: 36px;
        font-size: 13px;
    }

    .user-details {
        display: none;
    }

    .logout-button {
        display: grid;
        place-items: center;
        width: 38px;
        height: 38px;
        margin-left: 2px;
        border-radius: 10px;
        font-size: 18px;
    }

    /* ---------- CONTENT ---------- */

    .hubly-content {
        width: 100%;
        max-width: 100%;
        padding: 16px 12px 26px;
        overflow-x: hidden;
    }

    .dashboard-welcome {
        margin-bottom: 18px;
    }

    .dashboard-welcome h1 {
        font-size: 22px;
        line-height: 1.25;
        margin-bottom: 5px;
    }

    .dashboard-welcome p {
        font-size: 13px;
        line-height: 1.45;
    }

    /* ---------- DASHBOARD CARDS ---------- */

    .metric-card {
        padding: 16px;
        border-radius: 14px;
        box-shadow: 0 2px 9px rgba(15, 23, 42, .05);
    }

    .metric-label {
        font-size: 12px;
        margin-bottom: 7px;
    }

    .metric-value {
        font-size: 25px;
    }

    .metric-icon {
        width: 40px;
        height: 40px;
        font-size: 18px;
    }

    .module-card {
        padding: 17px;
        border-radius: 14px;
        box-shadow: 0 2px 9px rgba(15, 23, 42, .05);
    }

    .module-card i {
        font-size: 23px;
    }

    .module-card h3 {
        font-size: 15px;
        margin: 11px 0 5px;
    }

    .module-card p {
        font-size: 12px;
        line-height: 1.45;
    }

    .section-title {
        font-size: 16px;
        margin: 24px 0 12px;
    }

    /* ---------- BOOTSTRAP GRIDS ---------- */

    .hubly-content .row {
        --bs-gutter-x: .75rem;
        --bs-gutter-y: .75rem;
    }

    /* ---------- CARDS ---------- */

    .hubly-content .card {
        width: 100%;
        max-width: 100%;
        border-radius: 14px;
    }

    .hubly-content .card-header {
        padding: 12px 14px;
    }

    .hubly-content .card-body {
        padding: 14px;
    }

    /* ---------- BUTTONS ---------- */

    .hubly-content .btn {
        min-height: 42px;
        border-radius: 9px;
    }

    /* ---------- FORMS ---------- */

    .hubly-content .form-control,
    .hubly-content .form-select {
        min-height: 42px;
        border-radius: 9px;
        font-size: 16px;
    }

    .hubly-content input[type="text"],
    .hubly-content input[type="number"],
    .hubly-content input[type="date"],
    .hubly-content input[type="search"] {
        font-size: 16px;
    }

    /* ---------- TABLES ---------- */

    .hubly-content .table-responsive {
        width: 100%;
        max-width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        border-radius: 10px;
    }

    .hubly-content .table {
        white-space: nowrap;
    }

    /* ---------- MOBILE BOTTOM NAV ---------- */

    .hubly-mobile-nav {
        position: fixed;
        display: flex;
        left: 0;
        right: 0;
        bottom: 0;
        height: 68px;
        padding: 6px 6px max(6px, env(safe-area-inset-bottom));
        background: rgba(255, 255, 255, .97);
        border-top: 1px solid var(--hubly-border);
        box-shadow: 0 -5px 18px rgba(15, 23, 42, .08);
        z-index: 1001;
        gap: 2px;
        backdrop-filter: blur(10px);
        -webkit-backdrop-filter: blur(10px);
    }

    .mobile-nav-item {
        min-width: 0;
        flex: 1 1 0;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 3px;
        padding: 4px 2px;
        border: 0;
        background: transparent;
        color: #64748b;
        text-decoration: none;
        font-family: inherit;
        font-size: 10px;
        font-weight: 600;
        line-height: 1.1;
        border-radius: 10px;
    }

    .mobile-nav-item i {
        font-size: 20px;
        line-height: 1;
    }

    .mobile-nav-item:active,
    .mobile-nav-item:hover {
        color: var(--hubly-primary);
        background: #f5f7fb;
    }

    .mobile-menu-button {
        cursor: pointer;
    }
}

/* ---------- SMALL PHONES ---------- */

@media (max-width: 420px) {

    .hubly-header {
        padding-left: 9px;
        padding-right: 9px;
    }

    .hubly-content {
        padding-left: 9px;
        padding-right: 9px;
    }

    .sidebar-toggle {
        width: 40px;
        height: 40px;
        min-width: 40px;
    }

    .user-avatar {
        width: 34px;
        height: 34px;
        min-width: 34px;
    }

    .logout-button {
        width: 34px;
        height: 34px;
    }

    .mobile-nav-item i {
        font-size: 19px;
    }
}

/* ---------- NEVER SHOW MOBILE NAV ON DESKTOP ---------- */

@media (min-width: 901px) {

    .hubly-mobile-backdrop,
    .hubly-mobile-nav {
        display: none !important;
    }
}

/* =========================================================
   HUBLY ANDROID / MOBILE UI
   ========================================================= */

.hubly-mobile-backdrop {
    display: none;
}

.hubly-mobile-nav {
    display: none;
}

@media (max-width: 900px) {

    html,
    body {
        width: 100%;
        max-width: 100%;
        overflow-x: hidden;
    }

    body {
        padding-bottom: 72px;
    }

    .hubly-app {
        width: 100%;
        min-height: 100dvh;
        display: block;
    }

    /* Mobile sidebar */
    .hubly-sidebar {
        width: min(310px, 86vw);
        min-width: 0;
        height: 100dvh;
        min-height: 100dvh;
        transform: translateX(-105%);
        transition: transform .25s ease;
        box-shadow: 8px 0 30px rgba(0,0,0,.25);
        z-index: 1100;
    }

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

    /* Dark overlay */
    .hubly-mobile-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,.48);
        opacity: 0;
        visibility: hidden;
        pointer-events: none;
        transition: opacity .2s ease;
        z-index: 1050;
    }

    .hubly-mobile-backdrop.show {
        opacity: 1;
        visibility: visible;
        pointer-events: auto;
    }

    /* Main area */
    .hubly-main {
        width: 100%;
        margin-left: 0;
        min-width: 0;
    }

    /* Header */
    .hubly-header {
        height: 64px;
        min-height: 64px;
        padding: 0 12px;
        gap: 10px;
        position: sticky;
        top: 0;
        z-index: 1000;
    }

    .sidebar-toggle {
        width: 42px;
        height: 42px;
        min-width: 42px;
        display: grid;
        place-items: center;
        border-radius: 10px;
        background: #f1f5f9;
        color: #172033;
        font-size: 22px;
    }

    .header-title {
        min-width: 0;
    }

    .page-heading {
        font-size: 16px;
        line-height: 1.2;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .page-school {
        max-width: 100%;
        font-size: 10px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .header-user {
        gap: 6px;
        margin-left: auto;
    }

    .user-avatar {
        width: 36px;
        height: 36px;
        min-width: 36px;
    }

    .user-details {
        display: none;
    }

    .logout-button {
        width: 38px;
        height: 38px;
        margin-left: 0;
        display: grid;
        place-items: center;
    }

    /* Content */
    .hubly-content {
        width: 100%;
        padding: 16px 12px 28px;
    }

    .dashboard-welcome {
        margin-bottom: 18px;
    }

    .dashboard-welcome h1 {
        font-size: 21px;
        line-height: 1.25;
    }

    .dashboard-welcome p {
        font-size: 13px;
    }

    /* Cards */
    .metric-card,
    .module-card {
        border-radius: 14px;
        padding: 16px;
        max-width: 100%;
    }

    .metric-value {
        font-size: 25px;
    }

    .module-card h3 {
        font-size: 15px;
    }

    /* Bootstrap rows */
    .hubly-content .row {
        --bs-gutter-x: .75rem;
        --bs-gutter-y: .75rem;
    }

    /* Tables */
    .table-responsive {
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .table-responsive table {
        min-width: 700px;
    }

    /* Forms */
    .hubly-content .form-control,
    .hubly-content .form-select,
    .hubly-content .btn {
        min-height: 42px;
    }

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

    .hubly-content .btn {
        padding-left: 14px;
        padding-right: 14px;
    }

    /* Modal */
    .modal-dialog {
        margin: .75rem;
    }

    /* Fixed Android bottom navigation */
    .hubly-mobile-nav {
        position: fixed;
        display: flex;
        left: 0;
        right: 0;
        bottom: 0;
        height: 68px;
        padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
        background: rgba(255,255,255,.98);
        border-top: 1px solid #e5e7eb;
        box-shadow: 0 -4px 18px rgba(15,23,42,.08);
        z-index: 1000;
    }

    .hubly-mobile-nav a,
    .hubly-mobile-nav button {
        flex: 1;
        min-width: 0;
        border: 0;
        background: transparent;
        color: #64748b;
        text-decoration: none;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 3px;
        font-size: 10px;
        font-weight: 600;
    }

    .hubly-mobile-nav i {
        font-size: 20px;
        line-height: 1;
    }

    .hubly-mobile-nav .mobile-nav-active {
        color: #2563eb;
    }
}

@media (max-width: 420px) {

    .hubly-header {
        padding-left: 8px;
        padding-right: 8px;
    }

    .hubly-content {
        padding-left: 10px;
        padding-right: 10px;
    }

    .metric-card,
    .module-card {
        padding: 14px;
    }
}

/* =========================================================
   HUBLY PWA APP LOADING SCREEN
   ========================================================= */

#hublyPwaSplash {
    position: fixed;
    inset: 0;
    z-index: 99999;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #172033;
    transition: opacity .25s ease, visibility .25s ease;
}

#hublyPwaSplash.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.hubly-pwa-splash-inner {
    text-align: center;
    color: #fff;
}

.hubly-pwa-splash-logo {
    width: 92px;
    height: 92px;
    object-fit: contain;
    border-radius: 20px;
    margin-bottom: 18px;
}

.hubly-pwa-splash-name {
    font-size: 26px;
    font-weight: 800;
    letter-spacing: 2px;
}

.hubly-pwa-splash-subtitle {
    margin-top: 5px;
    font-size: 12px;
    letter-spacing: 2px;
    opacity: .75;
}

.hubly-pwa-splash-loader {
    width: 32px;
    height: 32px;
    margin: 24px auto 0;
    border: 3px solid rgba(255,255,255,.25);
    border-top-color: #fff;
    border-radius: 50%;
    animation: hublySplashSpin .8s linear infinite;
}

@keyframes hublySplashSpin {
    to {
        transform: rotate(360deg);
    }
}
