/* Village BC — layout + mobile-first responsive */

*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
}

body {
    background-color: #f4f6f8;
    font-family: "Segoe UI", Arial, sans-serif;
    color: #1f2937;
    overflow-x: hidden;
    min-height: 100vh;
}

.topbar {
    background-color: #1e3a5f;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
    z-index: 1030;
}

.brand-title {
    font-size: 1rem;
    font-weight: 700;
    color: #fff;
    line-height: 1.2;
}

.brand-subtitle {
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.75);
}

.user-chip {
    max-width: 42vw;
    font-size: 0.85rem;
}

.app-menu-btn {
    width: 2.5rem;
    height: 2.5rem;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.menu-bars,
.menu-bars::before,
.menu-bars::after {
    display: block;
    width: 1.1rem;
    height: 2px;
    background: currentColor;
    border-radius: 1px;
    position: relative;
}

.menu-bars::before,
.menu-bars::after {
    content: "";
    position: absolute;
    left: 0;
}

.menu-bars::before { top: -5px; }
.menu-bars::after { top: 5px; }

.sidebar {
    background: #fff;
    border-right: 1px solid #dde3ea;
    min-height: calc(100vh - 56px);
    position: sticky;
    top: 56px;
    align-self: flex-start;
    max-height: calc(100vh - 56px);
    overflow-y: auto;
}

.app-nav .nav-link {
    color: #374151;
    border-radius: 8px;
    margin-bottom: 2px;
    padding: 0.65rem 0.85rem;
    font-weight: 500;
}

.app-nav .nav-link:hover,
.app-nav .nav-link.active {
    background-color: #e8eef5;
    color: #1e3a5f;
}

#appSidebar {
    max-width: min(86vw, 320px);
}

#appSidebar .nav-link {
    font-size: 1rem;
}

.main-content {
    padding: 0.75rem;
    min-width: 0; /* allow flex/grid children to shrink */
}

.page-card {
    background: #fff;
    border: 1px solid #dde3ea;
    border-radius: 10px;
    padding: 0.9rem;
    overflow: hidden;
}

.stat-card {
    border: 1px solid #dde3ea;
    border-radius: 8px;
    padding: 0.9rem;
    background: #fff;
    height: 100%;
}

.stat-card .value {
    font-size: 1.5rem;
    font-weight: 700;
    color: #1e3a5f;
    word-break: break-word;
}

.login-card {
    max-width: 420px;
    margin: 2rem auto;
    padding: 1.25rem;
}

.form-label {
    font-weight: 600;
}

.alert-inline {
    margin-bottom: 1rem;
}

/* Forms / controls — touch friendly */
.form-control,
.form-select {
    min-height: 2.5rem;
    font-size: 1rem;
}

.btn {
    min-height: 2.4rem;
}

.btn-sm {
    min-height: 2rem;
}

/* Page headers that use flex — wrap on small screens */
.page-card > .d-flex.justify-content-between,
.page-card .d-flex.justify-content-between.align-items-center.mb-3 {
    flex-wrap: wrap;
    gap: 0.5rem;
}

/* Tables: always scroll horizontally on narrow screens */
.table-responsive {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-bottom: 0.5rem;
}

.table {
    margin-bottom: 0;
}

.table th,
.table td {
    vertical-align: middle;
}

/* Data grids: keep columns compact; key-value detail tables may wrap */
.table-responsive > .table th,
.table-responsive > .table td {
    white-space: nowrap;
}

.table-responsive > .table td.text-wrap,
.table-responsive > .table th.text-wrap {
    white-space: normal;
    word-break: break-word;
}

.table-detail th,
.table-detail td {
    white-space: normal;
    word-break: break-word;
}

.table-detail th {
    width: 38%;
    min-width: 7rem;
    color: #4b5563;
    font-weight: 600;
}

.table.table-sm th,
.table.table-sm td {
    padding: 0.45rem 0.55rem;
    font-size: 0.9rem;
}

/* Row action buttons (Disburse / Cancel / Request) */
.table-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    align-items: center;
}

/* Sticky first columns help wide reports on phone */
@media (max-width: 767.98px) {
    .table-sticky-first th:first-child,
    .table-sticky-first td:first-child {
        position: sticky;
        left: 0;
        background: #fff;
        z-index: 1;
        box-shadow: 1px 0 0 #dde3ea;
    }

    .table-sticky-first thead th:first-child {
        background: #f8f9fa;
        z-index: 2;
    }
}

/* Avoid nested form issues; keep inputs full width in cols */
.row.g-2 > [class*="col-"],
.row.g-3 > [class*="col-"] {
    min-width: 0;
}

/* Sticky action bars on long forms (collection / loan) */
@media (max-width: 767.98px) {
    .brand-title {
        font-size: 0.95rem;
    }

    .main-content {
        padding: 0.5rem;
    }

    .page-card {
        padding: 0.75rem;
        border-radius: 8px;
        border-left: none;
        border-right: none;
        border-radius: 0;
        margin: 0 -0.5rem;
        width: calc(100% + 1rem);
    }

    .stat-card .value {
        font-size: 1.35rem;
    }

    h4, .h4 {
        font-size: 1.15rem;
    }

    h5, .h5 {
        font-size: 1.05rem;
    }

    .login-card {
        margin: 1.25rem 0.75rem;
        max-width: none;
    }

    /* Stack filter rows / make filter button full width when alone */
    .row.g-2.mb-3 .btn,
    .row.g-3 > [class*="col-"] > .btn.btn-outline-secondary {
        width: 100%;
    }

    /* Full-width primary submit when it is the only control in a form footer */
    .form-actions > .btn-primary,
    .form-actions > .btn-danger {
        width: 100%;
    }

    .form-actions {
        display: flex;
        flex-direction: column;
        gap: 0.5rem;
    }

    .form-actions .btn-link {
        text-align: center;
    }

    /* Header / table small buttons stay auto width */
    .btn-primary.btn-sm,
    .btn-danger.btn-sm,
    .btn-outline-danger.btn-sm,
    .btn-outline-primary.btn-sm,
    .btn-outline-secondary.btn-sm {
        width: auto;
    }

    .table-actions {
        flex-direction: column;
        align-items: stretch;
    }

    .table-actions .btn {
        width: 100%;
    }

    .form-text {
        font-size: 0.8rem;
    }

    .alert {
        font-size: 0.9rem;
        padding: 0.65rem 0.75rem;
    }
}

@media (min-width: 768px) {
    .brand-title {
        font-size: 1.1rem;
    }

    .main-content {
        padding: 1.25rem;
    }

    .page-card {
        padding: 1.25rem;
    }

    .stat-card .value {
        font-size: 1.75rem;
    }

    .login-card {
        margin: 4rem auto;
    }

    .user-chip {
        max-width: none;
    }

    .form-actions {
        display: flex;
        flex-direction: row;
        flex-wrap: wrap;
        gap: 0.5rem;
        align-items: center;
    }

    .form-actions > .btn-primary,
    .form-actions > .btn-danger {
        width: auto;
    }

    .table-actions {
        flex-direction: row;
        align-items: center;
    }

    .table-actions .btn {
        width: auto;
    }
}

/* Safe area for notched phones */
@supports (padding: max(0px)) {
    .topbar {
        padding-left: max(0.5rem, env(safe-area-inset-left));
        padding-right: max(0.5rem, env(safe-area-inset-right));
    }

    body {
        padding-bottom: env(safe-area-inset-bottom);
    }
}
