/*
 * Agribank Đoàn UI foundation
 * Shared visual language for all user/admin screens.
 */
:root {
    --ui-brand: #006b45;
    --ui-brand-strong: #005238;
    --ui-brand-soft: #e8f5ef;
    --ui-navy: #12304a;
    --ui-blue: #0b6fb3;
    --ui-blue-soft: #eaf4fb;
    --ui-ink: #17212b;
    --ui-muted: #667482;
    --ui-border: #e3e9ee;
    --ui-surface: #ffffff;
    --ui-bg: #f4f7f8;
    --ui-success: #15803d;
    --ui-warning: #b45309;
    --ui-danger: #b42318;
    --ui-info: #0369a1;
    --ui-radius-sm: 10px;
    --ui-radius-md: 16px;
    --ui-radius-lg: 22px;
    --ui-shadow-sm: 0 2px 8px rgba(17, 36, 52, .06);
    --ui-shadow-md: 0 12px 30px rgba(17, 36, 52, .09);
    --ui-sidebar-width: 284px;
    --ui-content-gutter: clamp(16px, 2.4vw, 36px);
}

html { scroll-behavior: smooth; }
body.ui-app-body {
    background:
        radial-gradient(circle at 0 0, rgba(11, 111, 179, .055), transparent 28rem),
        var(--ui-bg);
    color: var(--ui-ink);
    font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 15px;
    line-height: 1.55;
    text-rendering: optimizeLegibility;
}
body.ui-app-body::selection { color: #fff; background: var(--ui-brand); }
a { color: var(--ui-blue); text-underline-offset: 3px; }
a:hover { color: var(--ui-brand-strong); }

/* App shell: the existing pages share Bootstrap's two-column layout. */
.row.g-0 > .col-auto.bg-dark {
    width: var(--ui-sidebar-width) !important;
    min-width: var(--ui-sidebar-width) !important;
    background: transparent !important;
    padding: 0 !important;
}
.row.g-0 > .col.py-3.offset-md-3.offset-xl-2 {
    width: calc(100% - var(--ui-sidebar-width));
    min-height: 100vh;
    margin-left: var(--ui-sidebar-width);
    padding: var(--ui-content-gutter) var(--ui-content-gutter) 44px !important;
}
.row.g-0 > .col.py-3.offset-md-3.offset-xl-2 > .d-flex.justify-content-between.align-items-center.mb-4.bg-white {
    min-height: 64px;
    border: 1px solid var(--ui-border);
    border-radius: var(--ui-radius-md) !important;
    box-shadow: var(--ui-shadow-sm) !important;
}

/* Typography and page hierarchy */
h1, h2, h3, h4, h5, h6 { color: var(--ui-ink); letter-spacing: -.018em; }
h5 { font-size: 1.12rem; }
.text-muted { color: var(--ui-muted) !important; }
.text-primary { color: var(--ui-blue) !important; }
.text-success { color: var(--ui-success) !important; }
.text-warning { color: var(--ui-warning) !important; }
.text-danger { color: var(--ui-danger) !important; }

/* Cards, panels and data surfaces */
.card, .glass-card {
    border: 1px solid var(--ui-border) !important;
    border-radius: var(--ui-radius-md) !important;
    background: var(--ui-surface) !important;
    box-shadow: var(--ui-shadow-sm) !important;
}
.card:hover { box-shadow: var(--ui-shadow-md) !important; }
.card-header {
    color: var(--ui-ink);
    border-bottom: 1px solid var(--ui-border) !important;
    background: transparent !important;
}
.card-footer { border-top: 1px solid var(--ui-border) !important; background: #fbfcfd !important; }
.shadow, .shadow-sm, .shadow-lg { box-shadow: var(--ui-shadow-sm) !important; }
.rounded-4 { border-radius: var(--ui-radius-md) !important; }
.rounded-5 { border-radius: var(--ui-radius-lg) !important; }

/* Buttons: clear hierarchy and comfortable touch targets */
.btn {
    min-height: 40px;
    border-radius: var(--ui-radius-sm);
    padding: .58rem .95rem;
    font-weight: 650;
    letter-spacing: -.005em;
    transition: transform .18s ease, box-shadow .18s ease, background-color .18s ease, border-color .18s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn-primary, .btn-primary-custom {
    color: #fff !important;
    border-color: var(--ui-brand) !important;
    background: linear-gradient(135deg, var(--ui-brand), var(--ui-blue)) !important;
    box-shadow: 0 5px 14px rgba(0, 107, 69, .16);
}
.btn-primary:hover, .btn-primary-custom:hover { box-shadow: 0 9px 20px rgba(0, 107, 69, .22); }
.btn-outline-primary { color: var(--ui-brand) !important; border-color: #8dc8ae !important; }
.btn-outline-primary:hover { color: #fff !important; background: var(--ui-brand) !important; }
.btn-light { border-color: var(--ui-border) !important; background: #fff !important; }
.btn-danger { background: var(--ui-danger) !important; border-color: var(--ui-danger) !important; }
.btn-sm { min-height: 34px; padding: .38rem .72rem; font-size: .82rem; }
.btn-lg { min-height: 48px; }

/* Inputs and filters */
.form-label { margin-bottom: .42rem; color: #43515d; font-size: .82rem; font-weight: 750; }
.form-control, .form-select {
    min-height: 42px;
    border: 1px solid #d6e0e7;
    border-radius: var(--ui-radius-sm);
    color: var(--ui-ink);
    background-color: #fff;
    box-shadow: none;
}
.form-control::placeholder { color: #9aa8b4; }
.form-control:focus, .form-select:focus {
    border-color: #5ab795;
    box-shadow: 0 0 0 .2rem rgba(0, 107, 69, .12);
}
.input-group-text { border-color: #d6e0e7; color: var(--ui-muted); background: #f8fafb; }
.form-check-input:checked { border-color: var(--ui-brand); background-color: var(--ui-brand); }

/* Tables: readable on desktop, scrollable without layout break on mobile */
.table-responsive { border-radius: var(--ui-radius-md); }
.table { margin-bottom: 0; color: var(--ui-ink); vertical-align: middle; }
.table > :not(caption) > * > * { border-bottom-color: var(--ui-border); padding: .82rem .75rem; }
.table thead th { color: #596875; background: #f7fafb; font-size: .72rem; letter-spacing: .055em; text-transform: uppercase; white-space: nowrap; }
.table tbody tr { transition: background-color .16s ease; }
.table tbody tr:hover { background: #f7fbf9; }
.table-rounded, .table-custom-rounded { overflow: hidden; border: 1px solid var(--ui-border); border-radius: var(--ui-radius-md); }

/* Status and feedback */
.badge { border-radius: 999px; padding: .42em .7em; font-weight: 700; letter-spacing: .01em; }
.alert { border: 1px solid transparent; border-radius: var(--ui-radius-sm); box-shadow: none; }
.alert-success { color: #166534; border-color: #bbf7d0; background: #f0fdf4; }
.alert-warning { color: #92400e; border-color: #fed7aa; background: #fff7ed; }
.alert-danger { color: #991b1b; border-color: #fecaca; background: #fef2f2; }
.alert-info { color: #075985; border-color: #bae6fd; background: #f0f9ff; }
.progress { height: 9px; overflow: hidden; border-radius: 999px; background: #e8eef2; }
.progress-bar { border-radius: inherit; background: linear-gradient(90deg, var(--ui-brand), #34a77b) !important; }

/* Dashboard activity metadata: Bootstrap badges default to nowrap, which can overflow on phones. */
#stats_container .small.text-dark.mb-2 > .badge.text-dark {
    max-width: 100%;
    white-space: normal;
    overflow-wrap: anywhere;
    word-break: break-word;
    text-align: left;
    line-height: 1.35;
    vertical-align: top;
}

/* Dashboard Hub: long unit names must wrap instead of overflowing on narrow screens. */
.dtn-hub-unit-badge {
    display: inline-block;
    max-width: 100%;
    white-space: normal;
    overflow-wrap: anywhere;
    word-break: break-word;
    text-align: left;
    line-height: 1.35;
    vertical-align: top;
}

/* Navigation and role sidebars */
.sidebar-admin, .sidebar-user {
    width: var(--ui-sidebar-width) !important;
    height: 100vh !important;
    min-height: 100vh !important;
    overflow-y: auto;
    background: linear-gradient(180deg, #102f47 0%, #071d2c 100%) !important;
    border-right: 1px solid rgba(255,255,255,.08);
}
.sidebar-admin .nav-link, .sidebar-user .nav-link {
    min-height: 44px;
    margin: 3px 14px !important;
    padding: 10px 14px !important;
    border: 1px solid transparent;
    border-radius: 12px !important;
    color: rgba(255,255,255,.74) !important;
    font-size: .88rem;
    font-weight: 650;
}
.sidebar-admin .nav-link i, .sidebar-user .nav-link i { width: 28px; color: #9bc4d7; }
.sidebar-admin .nav-link:hover, .sidebar-user .nav-link:hover {
    color: #fff !important;
    border-color: rgba(255,255,255,.08);
    background: rgba(255,255,255,.08) !important;
    transform: translateX(3px);
}
.sidebar-admin .nav-link.active, .sidebar-user .nav-link.active {
    color: #fff !important;
    border-color: rgba(167,243,208,.2);
    background: linear-gradient(135deg, #08764f, #0b6fb3) !important;
    box-shadow: 0 8px 18px rgba(0,0,0,.16) !important;
}
.sidebar-admin .nav-link.active i, .sidebar-user .nav-link.active i { color: #fff; }
.sidebar-admin small, .sidebar-user small { color: rgba(226,232,240,.6) !important; }

/* Existing pages use a few generic fixed columns. Make them behave consistently. */
.mobile-header-bar { border-bottom: 1px solid var(--ui-border) !important; }
.dropdown-menu { border: 1px solid var(--ui-border); border-radius: 12px; box-shadow: var(--ui-shadow-md); padding: .4rem; }
.dropdown-item { border-radius: 8px; padding: .52rem .68rem; }
.dropdown-item:hover { background: var(--ui-brand-soft); }
.modal-content { border: 1px solid var(--ui-border) !important; border-radius: var(--ui-radius-lg) !important; box-shadow: 0 24px 70px rgba(7, 29, 44, .2) !important; }
.modal-header, .modal-footer { border-color: var(--ui-border) !important; }
.toast { border: 1px solid var(--ui-border); border-radius: 12px; box-shadow: var(--ui-shadow-md); }
.accordion-item { border-color: var(--ui-border); }
.accordion-button { color: var(--ui-ink); font-weight: 650; }
.accordion-button:not(.collapsed) { color: var(--ui-brand-strong); background: var(--ui-brand-soft); box-shadow: none; }
.list-group-item { border-color: var(--ui-border); }
.timeline { border-color: #cbd8df !important; }

/* Criterion tree editor: keep actions visible while long forms scroll inside the viewport. */
#modalThemTieuChi .modal-dialog {
    height: calc(100dvh - 2rem);
    max-height: calc(100dvh - 2rem);
    margin-top: 1rem;
    margin-bottom: 1rem;
}
#modalThemTieuChi .modal-content {
    height: 100%;
    max-height: 100%;
    overflow: hidden;
}
#modalThemTieuChi form {
    display: flex;
    flex: 1 1 auto;
    min-height: 0;
    flex-direction: column;
    overflow: hidden;
}
#modalThemTieuChi .modal-header,
#modalThemTieuChi .modal-footer {
    flex: 0 0 auto;
}
#modalThemTieuChi .modal-body {
    min-height: 0;
    overflow-y: auto !important;
    overscroll-behavior: contain;
    scrollbar-gutter: stable;
    -webkit-overflow-scrolling: touch;
}
#modalThemTieuChi .modal-footer {
    position: relative;
    z-index: 2;
    box-shadow: 0 -8px 20px rgba(17, 36, 52, .08);
}

/* Keyboard and reduced-motion accessibility */
:focus-visible { outline: 3px solid rgba(14, 165, 233, .42); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; }
}

@media (max-width: 900px) {
    :root { --ui-sidebar-width: 280px; }
    .row.g-0 > .col-auto.bg-dark {
        position: fixed !important;
        z-index: 10000 !important;
        top: 0 !important;
        bottom: 0 !important;
        left: calc(var(--ui-sidebar-width) * -1) !important;
        width: var(--ui-sidebar-width) !important;
        min-width: 0 !important;
        transition: left .24s ease !important;
    }
    .row.g-0 > .col-auto.bg-dark.show-mobile { left: 0 !important; }
    .row.g-0 > .col.py-3.offset-md-3.offset-xl-2 { width: 100%; margin-left: 0; padding-top: 84px !important; }
    .mobile-header-bar { display: flex !important; }
    .table-responsive { margin-right: -4px; }
}

@media (max-width: 576px) {
    .dtn-hub-unit-badge {
        width: 100%;
        margin-right: 0 !important;
        margin-bottom: .25rem;
    }

    body { font-size: 14px; }
    .row.g-0 > .col.py-3.offset-md-3.offset-xl-2 { padding-right: 14px !important; padding-left: 14px !important; }
    .card-body { padding: 1rem !important; }
    .d-flex.justify-content-between.align-items-center { gap: 10px; flex-wrap: wrap; }
    .btn { min-height: 42px; }
    .table > :not(caption) > * > * { padding: .68rem .56rem; }

    #modalThemTieuChi .modal-dialog {
        width: calc(100% - 1rem);
        height: calc(100dvh - 1rem);
        max-height: calc(100dvh - 1rem);
        margin: .5rem;
    }
    #modalThemTieuChi .modal-header { padding: .9rem 1rem; }
    #modalThemTieuChi .modal-body { padding: 1rem !important; }
    #modalThemTieuChi .modal-footer {
        padding: .75rem 1rem;
        gap: .5rem;
    }
    #modalThemTieuChi .modal-footer .btn { flex: 1 1 0; }

    #stats_container .small.text-dark.mb-2 {
        display: flex;
        flex-wrap: wrap;
        align-items: flex-start;
        gap: .35rem;
    }
    #stats_container .small.text-dark.mb-2 > .badge.text-dark {
        display: block;
        width: 100%;
        margin-right: 0 !important;
        margin-bottom: 0;
        padding: .52em .72em;
        border-radius: 10px;
    }
    #stats_container .small.text-dark.mb-2 > .badge.text-primary {
        max-width: 100%;
        white-space: normal;
        overflow-wrap: anywhere;
        line-height: 1.3;
    }
}

/* Printing authenticated app pages must never repeat fixed/sticky application chrome. */
@media print {
    html body .mobile-header-bar,
    html body .staging-environment-banner,
    html body .overlay-mobile,
    html body .row.g-0 > .col-auto.bg-dark,
    html body .sidebar-admin,
    html body .sidebar-user,
    html body .dtn-nav-skeleton {
        display: none !important;
        visibility: hidden !important;
    }
}

