:root {
    --brand-primary: #0d4d8c;
    --brand-accent:  #f0a93b;
    --sidebar-bg:    #1b2238;
    --sidebar-text:  #c8cee0;
    --sidebar-hover: #2a3457;
    --sidebar-width: 240px;
}

* { -webkit-tap-highlight-color: transparent; }

body {
    background: #f4f6fb;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    margin: 0;
}

/* ====== App shell ====== */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    width: var(--sidebar-width);
    flex-shrink: 0;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    z-index: 1040;
    transition: transform 0.25s ease;
}

.sidebar-brand {
    padding: 20px 22px 18px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.sidebar-brand .brand-name {
    color: #fff;
    font-size: 22px;
    font-weight: 700;
    letter-spacing: 0.5px;
}
.sidebar-brand .brand-tag {
    color: var(--brand-accent);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    display: block;
    margin-top: 2px;
}
.sidebar-close {
    background: none; border: none; color: #fff;
    font-size: 22px; line-height: 1; padding: 4px 8px;
    display: none;
}

.sidebar nav { padding: 8px 0 24px; }
.sidebar nav a {
    display: block;
    padding: 12px 22px;
    color: var(--sidebar-text);
    text-decoration: none;
    border-left: 3px solid transparent;
    font-size: 15px;
}
.sidebar nav a:hover, .sidebar nav a:active { background: var(--sidebar-hover); color: #fff; }
.sidebar nav a.active {
    background: var(--sidebar-hover);
    color: #fff;
    border-left-color: var(--brand-accent);
}
.sidebar nav .nav-section {
    color: #8893b3;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    padding: 16px 22px 6px;
}

.sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1039;
    display: none;
}

.main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.topbar {
    background: #fff;
    border-bottom: 1px solid #e5e9f2;
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    position: sticky;
    top: 0;
    z-index: 1030;
}
.topbar .page-title {
    font-size: 16px;
    font-weight: 600;
    margin: 0;
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.topbar .user-info { font-size: 12px; color: #6b7793; white-space: nowrap; }

.menu-toggle {
    background: none;
    border: 1px solid #d3d8e6;
    border-radius: 6px;
    padding: 6px 10px;
    color: #1b2238;
    font-size: 18px;
    line-height: 1;
    display: none;
}
.menu-toggle:active { background: #eef1f8; }

.content {
    padding: 16px;
}

/* ====== Cards ====== */
.stat-card {
    background: #fff;
    border-radius: 10px;
    padding: 14px 16px;
    box-shadow: 0 1px 3px rgba(20,30,60,0.06);
    border: 1px solid #eef1f8;
}
.stat-card .label {
    color: #6b7793;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.stat-card .value {
    font-size: 20px;
    font-weight: 700;
    color: #1b2238;
    margin-top: 4px;
    word-break: break-word;
}
.stat-card .sub { font-size: 11px; color: #8893b3; margin-top: 2px; }

.card { border: 1px solid #eef1f8; box-shadow: 0 1px 3px rgba(20,30,60,0.04); }

.btn-brand { background: var(--brand-primary); color: #fff; border-color: var(--brand-primary); }
.btn-brand:hover { background: #0a3d70; color: #fff; border-color: #0a3d70; }

/* ====== Tables ====== */
.table-responsive { -webkit-overflow-scrolling: touch; }
.table thead th {
    background: #f7f9fd;
    color: #4a556e;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    font-weight: 600;
    border-bottom: 1px solid #e5e9f2;
    white-space: nowrap;
}
.table td { vertical-align: middle; }
.table .btn-sm { white-space: nowrap; }

/* ====== Status pills ====== */
.pill {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    white-space: nowrap;
}
.pill-success  { background: #d8f5e0; color: #1a7a3b; }
.pill-warn     { background: #fff1d6; color: #9a6b00; }
.pill-danger   { background: #fde0e0; color: #b3261e; }
.pill-muted    { background: #e9ecf4; color: #4a556e; }
.pill-info     { background: #d6e8fa; color: #0a4a82; }

/* ====== Login page ====== */
.login-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #1b2238 0%, #0d4d8c 100%);
    padding: 16px;
}
.login-card {
    background: #fff;
    border-radius: 12px;
    padding: 32px 24px;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 12px 30px rgba(0,0,0,0.2);
}
.login-card .brand { text-align: center; margin-bottom: 24px; }
.login-card .brand-name { font-size: 26px; font-weight: 700; color: var(--brand-primary); }
.login-card .brand-tag {
    display: block; color: #8893b3; font-size: 12px;
    text-transform: uppercase; letter-spacing: 1.5px; margin-top: 4px;
}
.login-card .form-control { font-size: 16px; padding: 10px 12px; }
.login-card .btn { padding: 10px 16px; font-size: 16px; }

/* ====== Section header ====== */
.section-header {
    display: flex; justify-content: space-between; align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 14px;
}
.section-header h2 { margin: 0; font-size: 20px; font-weight: 600; }

/* ====== Misc ====== */
.text-muted-sm { color: #8893b3; font-size: 12px; }

/* ===========================================================
   Mobile / tablet (≤ 991.98px) — sidebar becomes a drawer
   =========================================================== */
@media (max-width: 991.98px) {
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100vh;
        transform: translateX(-100%);
        box-shadow: 4px 0 24px rgba(0,0,0,0.25);
    }
    body.sidebar-open .sidebar { transform: translateX(0); }
    body.sidebar-open .sidebar-backdrop { display: block; }
    body.sidebar-open { overflow: hidden; }

    .sidebar-close { display: inline-block; }

    .menu-toggle { display: inline-block; }

    .main { width: 100%; }

    .topbar { padding: 10px 12px; }
    .topbar .page-title { font-size: 15px; }
    .topbar .user-info { display: none; }

    .content { padding: 12px; }

    .section-header h2 { font-size: 18px; }
    .section-header .btn { font-size: 14px; padding: 6px 12px; }

    .table { font-size: 14px; }
    .table thead th { font-size: 10px; padding: 8px; }
    .table td { padding: 8px; }

    /* On mobile, table action buttons stack vertically and full-width */
    .table .text-end .btn-sm + .btn-sm { margin-top: 4px; }

    .stat-card { padding: 12px; }
    .stat-card .value { font-size: 18px; }

    .form-control, .form-select { font-size: 16px; }  /* prevent iOS auto-zoom */

    /* Filter/search forms — stack inputs */
    .card-body.d-flex { flex-direction: column; align-items: stretch !important; }
    .card-body.d-flex > * { width: 100%; }
    .card-body.d-flex .btn { align-self: flex-start; }
}

/* ===========================================================
   Phones (≤ 575.98px) — extra-tight
   =========================================================== */
@media (max-width: 575.98px) {
    .sidebar { width: 80vw; max-width: 320px; }

    .topbar .user-info-mobile {
        display: inline-block;
        font-size: 11px;
    }

    .stat-card { padding: 10px 12px; }
    .stat-card .label { font-size: 10px; }
    .stat-card .value { font-size: 16px; }

    .section-header { margin-bottom: 10px; }

    /* Compact action buttons in long tables */
    .table .btn-sm { font-size: 12px; padding: 4px 8px; }

    /* Make modals full-screen-ish on tiny phones */
    .modal-dialog { margin: 8px; }

    /* Forms: column-12 padding */
    .card-body { padding: 14px; }

    /* Buttons in forms full-width when stacked */
    form .btn-brand { min-width: 120px; }
}

/* ===== Bottom tabs (mobile only) ===== */
.bottom-tabs {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: #fff;
    border-top: 1px solid #e5e9f2;
    padding-bottom: env(safe-area-inset-bottom, 0);
    z-index: 1025;
    box-shadow: 0 -2px 10px rgba(20,30,60,0.05);
}
.bottom-tabs a {
    flex: 1;
    text-align: center;
    padding: 8px 4px 10px;
    color: #6b7793;
    text-decoration: none;
    font-size: 11px;
    line-height: 1.1;
    border-top: 2px solid transparent;
    transition: color 0.15s ease, border-color 0.15s ease;
}
.bottom-tabs a:active { background: #f4f6fb; }
.bottom-tabs a.active {
    color: var(--brand-primary);
    border-top-color: var(--brand-accent);
}
.bottom-tabs .tab-icon {
    font-size: 22px;
    display: block;
    margin-bottom: 2px;
    line-height: 1;
}
.bottom-tabs .tab-label {
    font-weight: 600;
    letter-spacing: 0.2px;
}

@media (max-width: 991.98px) {
    .bottom-tabs { display: flex; }
    .content { padding-bottom: 80px; }
}

/* Apartment tile grid */
.apt-tiles {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 10px;
}
.apt-tile {
    background: #fff;
    border: 1px solid #eef1f8;
    border-radius: 10px;
    padding: 12px 14px;
    box-shadow: 0 1px 3px rgba(20,30,60,0.05);
    transition: transform 0.1s ease, box-shadow 0.1s ease, border-color 0.15s ease;
    user-select: none;
}
.apt-tile[role="button"] { cursor: pointer; }
.apt-tile[role="button"]:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(20,30,60,0.12);
}
.apt-tile[role="button"]:active { transform: translateY(0); }

.apt-tile .apt-num {
    font-size: 20px;
    font-weight: 700;
    color: #1b2238;
    letter-spacing: 0.3px;
}
.apt-tile .apt-tenant {
    font-size: 13px;
    color: #4a556e;
    margin-top: 2px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.apt-tile .apt-dues {
    font-size: 13px;
    color: #b3261e;
    margin-top: 6px;
}
.apt-tile .apt-cta {
    font-size: 11px;
    color: #0d4d8c;
    margin-top: 4px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.4px;
}

/* Color states */
.apt-tile-vacant {
    background: #f7f9fd;
    border-style: dashed;
}
.apt-tile-paid {
    border-left: 3px solid #1a7a3b;
}
.apt-tile-due {
    border-left: 3px solid #b3261e;
    background: linear-gradient(90deg, #fff5f5 0%, #fff 30%);
}

@media (max-width: 575.98px) {
    .apt-tiles {
        grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
        gap: 8px;
    }
    .apt-tile { padding: 10px 12px; }
    .apt-tile .apt-num { font-size: 18px; }
}

/* Building switcher in topbar */
.building-switcher { margin: 0; }
.building-switcher select {
    background: #f4f6fb;
    border-color: #d3d8e6;
    font-weight: 500;
    min-width: 160px;
    max-width: 220px;
}
.building-only {
    align-self: center;
    font-size: 12px;
}

@media (max-width: 575.98px) {
    .building-switcher select { min-width: 110px; max-width: 140px; font-size: 13px; }
}

/* Right-slide offcanvas — comfortable widths */
.offcanvas-end {
    width: 420px;
    max-width: 100%;
}
@media (max-width: 575.98px) {
    .offcanvas-end { width: 100%; }
}
.offcanvas-body { padding-bottom: 24px; }

/* User info inside the sidebar (only shown on mobile) */
.sidebar-user {
    display: none;
    padding: 16px 22px;
    border-top: 1px solid rgba(255,255,255,0.08);
    color: var(--sidebar-text);
    font-size: 13px;
}
.sidebar-user .username { color: #fff; font-weight: 600; }
.sidebar-user a { color: var(--brand-accent); text-decoration: none; }
@media (max-width: 991.98px) { .sidebar-user { display: block; } }
