/*
 * TutoHisab theme — "You teach, we keep the accounts" (আপনি পড়ান, হিসাব আমরা রাখি)
 * Built for Bootstrap 5.3 + AdminLTE v4. No build step: loaded after AdminLTE.
 *
 * Contrast (WCAG AA, 4.5:1 for body text) checked for every text/background pair below.
 * Accent gold is NEVER used for text on white (2.0:1) — only as a fill with dark text.
 */

:root {
    /* Brand */
    --th-primary: #0E7C6B;        /* Teal green: trust + money. White text 5.1:1 */
    --th-primary-hover: #0A6357;  /* Pressed/hover. White text 7.2:1 */
    --th-primary-rgb: 14, 124, 107;
    --th-primary-50: #E8F5F2;     /* Tinted backgrounds, selected rows */
    --th-primary-100: #CDEBE4;
    --th-accent: #F2A900;         /* Gold "taka": highlights, badges with dark text */
    --th-accent-50: #FEF3C7;
    --th-accent-text: #7A5600;    /* Text on accent-50: 6.0:1 */

    /* Money semantics — use these consistently for fee states */
    --th-paid: #15803D;           /* Collected / paid. White 5.0:1 */
    --th-due: #DC2626;            /* Due / overdue. White 4.8:1 */
    --th-partial: #B45309;        /* Partial payment. White 5.0:1 */
    --th-info: #0369A1;           /* Neutral info. White 5.9:1 */

    /* Neutrals */
    --th-bg: #F5F7F7;
    --th-surface: #FFFFFF;
    --th-border: #E2E8E7;
    --th-text: #1E293B;           /* On bg 13.6:1 */
    --th-muted: #64748B;          /* On white 4.8:1 */

    /* Sidebar */
    --th-sidebar-bg: #102A2B;
    --th-sidebar-text: #CFE3E0;   /* 11.3:1 */
    --th-sidebar-muted: #8FB3AE;  /* 6.7:1 */

    --th-radius: 0.5rem;
    --th-font: "Hind Siliguri", "Source Sans 3", system-ui, -apple-system, "Segoe UI", sans-serif;
}

/* ---------- Bootstrap 5 variable overrides ---------- */
:root,
[data-bs-theme="light"] {
    --bs-primary: var(--th-primary);
    --bs-primary-rgb: var(--th-primary-rgb);
    --bs-primary-bg-subtle: var(--th-primary-50);
    --bs-primary-border-subtle: var(--th-primary-100);
    --bs-primary-text-emphasis: var(--th-primary-hover);
    --bs-success: var(--th-paid);
    --bs-success-rgb: 21, 128, 61;
    --bs-danger: var(--th-due);
    --bs-danger-rgb: 220, 38, 38;
    --bs-warning: var(--th-accent);
    --bs-warning-rgb: 242, 169, 0;
    --bs-info: var(--th-info);
    --bs-info-rgb: 3, 105, 161;
    --bs-body-bg: var(--th-bg);
    --bs-body-color: var(--th-text);
    --bs-secondary-color: var(--th-muted);
    --bs-border-color: var(--th-border);
    --bs-link-color: var(--th-primary);
    --bs-link-color-rgb: var(--th-primary-rgb);
    --bs-link-hover-color: var(--th-primary-hover);
    --bs-link-hover-color-rgb: 10, 99, 87;
    --bs-focus-ring-color: rgba(var(--th-primary-rgb), 0.25);
    --bs-border-radius: var(--th-radius);
    --bs-body-font-family: var(--th-font);
}

body {
    font-family: var(--th-font);
    background-color: var(--th-bg);
    color: var(--th-text);
}

/* ---------- Buttons ---------- */
.btn-primary {
    --bs-btn-bg: var(--th-primary);
    --bs-btn-border-color: var(--th-primary);
    --bs-btn-hover-bg: var(--th-primary-hover);
    --bs-btn-hover-border-color: var(--th-primary-hover);
    --bs-btn-active-bg: var(--th-primary-hover);
    --bs-btn-active-border-color: var(--th-primary-hover);
    --bs-btn-disabled-bg: var(--th-primary);
    --bs-btn-disabled-border-color: var(--th-primary);
    --bs-btn-focus-shadow-rgb: var(--th-primary-rgb);
}
.btn-outline-primary {
    --bs-btn-color: var(--th-primary);
    --bs-btn-border-color: var(--th-primary);
    --bs-btn-hover-bg: var(--th-primary);
    --bs-btn-hover-border-color: var(--th-primary);
    --bs-btn-active-bg: var(--th-primary-hover);
    --bs-btn-active-border-color: var(--th-primary-hover);
}
.btn-success { --bs-btn-bg: var(--th-paid); --bs-btn-border-color: var(--th-paid); --bs-btn-hover-bg: #166534; --bs-btn-hover-border-color: #166534; }
.btn-danger  { --bs-btn-bg: var(--th-due);  --bs-btn-border-color: var(--th-due);  --bs-btn-hover-bg: #B91C1C; --bs-btn-hover-border-color: #B91C1C; }
.btn-info    { --bs-btn-color: #fff; --bs-btn-bg: var(--th-info); --bs-btn-border-color: var(--th-info); --bs-btn-hover-color: #fff; --bs-btn-hover-bg: #075985; --bs-btn-hover-border-color: #075985; }
.btn-warning { --bs-btn-color: var(--th-text); --bs-btn-bg: var(--th-accent); --bs-btn-border-color: var(--th-accent); --bs-btn-hover-bg: #D99700; --bs-btn-hover-border-color: #D99700; }
.btn { font-weight: 500; }

/* ---------- Cards, forms, tables ---------- */
.card {
    border: 1px solid var(--th-border);
    border-radius: var(--th-radius);
    box-shadow: 0 1px 2px rgba(16, 42, 43, 0.06);
}
.card-header { background: var(--th-surface); border-bottom-color: var(--th-border); font-weight: 600; }

.form-control:focus,
.form-select:focus {
    border-color: var(--th-primary);
    box-shadow: 0 0 0 0.2rem rgba(var(--th-primary-rgb), 0.2);
}
.form-check-input:checked { background-color: var(--th-primary); border-color: var(--th-primary); }

.table > thead th { color: var(--th-muted); font-weight: 600; text-transform: uppercase; font-size: 0.75rem; letter-spacing: 0.02em; }
.table-hover > tbody > tr:hover > * { --bs-table-hover-bg: var(--th-primary-50); }
.page-item.active .page-link,
.dt-paging .page-item.active .page-link { background-color: var(--th-primary); border-color: var(--th-primary); }

/* ---------- Fee status badges (use everywhere money state is shown) ---------- */
.badge-paid    { background: #DCFCE7; color: #14532D; }  /* 8.3:1 */
.badge-due     { background: #FEE2E2; color: #7F1D1D; }  /* 8.2:1 */
.badge-partial { background: var(--th-accent-50); color: var(--th-accent-text); }
.badge-waived  { background: var(--th-primary-50); color: var(--th-primary-hover); }
.badge-paid, .badge-due, .badge-partial, .badge-waived { font-weight: 600; }

.text-paid { color: var(--th-paid) !important; }
.text-due { color: var(--th-due) !important; }
.amount { font-variant-numeric: tabular-nums; }

/* ---------- Sidebar (AdminLTE v4) ---------- */
.app-sidebar,
.app-sidebar.bg-dark {
    background-color: var(--th-sidebar-bg) !important;
}
.app-sidebar .sidebar-brand { border-bottom: 1px solid rgba(255, 255, 255, 0.08); }
.app-sidebar .brand-link .brand-text { color: #fff; font-weight: 600; letter-spacing: 0.01em; }
.app-sidebar .brand-text .brand-accent { color: var(--th-accent); }
.app-sidebar .nav-link { color: var(--th-sidebar-text); border-radius: 0.375rem; margin-bottom: 0.15rem; }
.app-sidebar .nav-link .nav-icon { color: var(--th-sidebar-muted); }
.app-sidebar .nav-link:hover,
.app-sidebar .nav-link.active {
    color: #fff !important;
    background-color: rgba(var(--th-primary-rgb), 0.35);
    box-shadow: inset 3px 0 0 var(--th-accent);
}
.app-sidebar .nav-link:hover .nav-icon,
.app-sidebar .nav-link.active .nav-icon { color: #fff; }
body.sidebar-collapse .sidebar-user-panel { display: none !important; }

/* Initials avatar (no stock photos) */
.avatar-initials {
    width: 2.1rem; height: 2.1rem; border-radius: 50%;
    display: inline-flex; align-items: center; justify-content: center;
    background: var(--th-primary); color: #fff; font-weight: 600; font-size: 0.85rem;
}

/* ---------- Header ---------- */
.app-header { border-bottom: 1px solid var(--th-border); }

/* ---------- Auth pages ---------- */
.login-page { background: linear-gradient(180deg, var(--th-primary-50) 0%, var(--th-bg) 60%); }
.login-logo img { height: 44px; }

/* ---------- Mobile ---------- */
@media (max-width: 768px) {
    body { font-size: 14px; }
    .app-header .nav-link { padding: 0.5rem 0.25rem !important; }
    .table { font-size: 0.875rem; }
}
@media (max-width: 576px) {
    .app-content { padding: 0.5rem !important; }
    .card-body { padding: 1rem 0.75rem; }
    .container-fluid { padding-left: 0.5rem; padding-right: 0.5rem; }
    .card-header { padding: 0.625rem 0.75rem; }
    .table > :not(caption) > * > * { padding: 0.5rem 0.4rem; }
    h1.h4 { font-size: 1.15rem; }
    .btn-group-sm > .btn, .btn-sm { padding: 0.3rem 0.6rem; }
}

/* Phones: 16px inputs stop iOS from zooming the page on focus; bigger tap targets. */
@media (max-width: 768px) {
    .form-control, .form-select, .form-control-sm, .form-select-sm { font-size: 16px; }
    .card-header.d-flex { flex-wrap: wrap; gap: 0.5rem; }
    .list-group-item-action, .dropdown-item { padding-top: 0.6rem; padding-bottom: 0.6rem; }
    .notice-snippet { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
}
@media (min-width: 769px) {
    .notice-snippet { max-width: 28rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
}

/* Filter bars above lists: full-width search, selects share the row. */
@media (max-width: 576px) {
    .filter-bar { width: 100%; }
    .filter-bar > input[name=q] { flex: 1 1 100%; width: 100% !important; }
    .filter-bar > input[type=date] { flex: 1 1 40%; width: auto !important; min-width: 0; }
    .filter-bar > select { flex: 1 1 0; width: auto !important; min-width: 0; }
}

/* ---------- Tables on phones: one line per cell, swipe sideways ---------- */
@media (max-width: 768px) {
    .table-responsive { -webkit-overflow-scrolling: touch; overscroll-behavior-x: contain; }
    .table-responsive > .table { --bs-table-bg: transparent; margin-bottom: 0; }
    .table-responsive > .table > :not(caption) > * > * { white-space: nowrap; vertical-align: middle; }
    /* Long free text (notes, notice text, school) wraps inside a readable width instead. */
    .table-responsive > .table .cell-wrap,
    .table-responsive > .table td[colspan] { white-space: normal; min-width: 13rem; }
    .manual-body .table-responsive > .table > :not(caption) > * > * { white-space: normal; min-width: 6rem; }
    /* Shadows at the edges show that the table scrolls. */
    .table-responsive {
        background:
            linear-gradient(to right, var(--bs-body-bg) 30%, transparent) 0 0 / 2.5rem 100% no-repeat local,
            linear-gradient(to left, var(--bs-body-bg) 30%, transparent) 100% 0 / 2.5rem 100% no-repeat local,
            radial-gradient(farthest-side at 0 50%, rgba(0, 0, 0, .16), transparent) 0 0 / .9rem 100% no-repeat scroll,
            radial-gradient(farthest-side at 100% 50%, rgba(0, 0, 0, .16), transparent) 100% 0 / .9rem 100% no-repeat scroll;
        background-color: var(--bs-body-bg);
    }
}

/* ---------- Buttons on phones: a button's words stay together; the row wraps instead ---------- */
@media (max-width: 768px) {
    .btn { white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
    .btn.w-100, .d-grid > .btn { white-space: normal; text-wrap: balance; }
    .card-header .d-flex, .card-header.d-flex, .card-footer.d-flex, .d-flex.gap-1, .d-flex.gap-2, .d-flex.gap-3 { flex-wrap: wrap; }
    .card-footer.d-flex > span { flex: 1 1 100%; }
    .list-group-item.d-flex { flex-wrap: wrap; row-gap: .4rem; }
    .btn-group { flex-wrap: nowrap; }
    .btn-group > .btn { overflow: visible; }
}

/* Wide tables (attendance register): keep the name column in view while scrolling sideways. */
.table-sticky-first th:first-child, .table-sticky-first td:first-child {
    position: sticky; left: 0; z-index: 1; background: var(--bs-body-bg); box-shadow: 1px 0 0 var(--bs-border-color);
}

/* ---------- Bottom bar (phones, institute panel) ---------- */
.mobile-tabbar { display: none; }
@media (max-width: 991.98px) {
    .mobile-tabbar {
        display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 1030;
        background: var(--bs-body-bg); border-top: 1px solid var(--th-border);
        padding-bottom: env(safe-area-inset-bottom);
    }
    .mobile-tabbar a, .mobile-tabbar button {
        flex: 1 1 0; display: flex; flex-direction: column; align-items: center; gap: 2px;
        padding: 0.45rem 0.25rem 0.4rem; font-size: 0.72rem; line-height: 1.1; color: var(--bs-secondary-color);
        text-decoration: none; background: none; border: 0; min-height: 52px; justify-content: center;
    }
    .mobile-tabbar i { font-size: 1.15rem; }
    .mobile-tabbar .active { color: var(--th-primary); font-weight: 600; }
    body.has-tabbar .app-footer { padding-bottom: calc(64px + env(safe-area-inset-bottom)); }
    body.has-tabbar .app-main { padding-bottom: 8px; }
}

@media (prefers-reduced-motion: reduce) {
    * { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}
