/* ── SB Dashboard — Main Stylesheet ───────────────────────────────────────── */
/* Font loaded via <link> in layout_header.php for faster delivery */

/* ── Custom Properties ───────────────────────────────────────────────────── */
:root {
    --color-primary:       #0D2240;
    --color-primary-light: #1A3A6B;
    --color-accent:        #C8102E;
    --color-accent-hover:  #A50D26;
    --color-bg:            #F0F2F5;
    --color-bg-white:      #FFFFFF;
    --color-border:        #E2E6ED;
    --color-text:          #0F1923;
    --color-text-muted:    #64748B;
    --color-success:       #16A34A;
    --color-error:         #DC2626;
    --color-warning:       #D97706;
    --color-info:          #2563EB;

    --font-family: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;

    --radius-sm:  6px;
    --radius-md:  10px;
    --radius-lg:  16px;
    --radius-xl:  20px;

    --shadow-xs:  0 1px 2px rgba(0,0,0,.06);
    --shadow-sm:  0 1px 4px rgba(0,0,0,.08), 0 0 0 1px rgba(0,0,0,.04);
    --shadow-md:  0 4px 16px rgba(0,0,0,.10), 0 0 0 1px rgba(0,0,0,.04);
    --shadow-lg:  0 12px 32px rgba(0,0,0,.14);

    --nav-height:  62px;
    --content-max: 1440px;
    --transition:  160ms cubic-bezier(.4,0,.2,1);
}

/* ── Reset ───────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-font-smoothing: antialiased; }
body {
    font-family: var(--font-family);
    background: var(--color-bg);
    color: var(--color-text);
    line-height: 1.55;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}
a { color: var(--color-primary-light); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; display: block; }
button, input, select, textarea { font-family: inherit; font-size: inherit; }

/* ── Top Navigation ──────────────────────────────────────────────────────── */
.topnav {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--color-primary);
    height: var(--nav-height);
    border-bottom: 1px solid rgba(255,255,255,.08);
    backdrop-filter: blur(8px);
}
.topnav-inner {
    display: flex;
    align-items: center;
    gap: 0;
    max-width: var(--content-max);
    margin: 0 auto;
    padding: 0 1.75rem;
    height: 100%;
}
.topnav-brand {
    display: flex;
    align-items: center;
    gap: .6rem;
    text-decoration: none;
    flex-shrink: 0;
    margin-right: 2rem;
}
.topnav-logo { height: 34px; }
.topnav-title {
    font-size: 1rem;
    font-weight: 700;
    color: #fff;
    letter-spacing: -.01em;
}
.topnav-links {
    display: flex;
    align-items: center;
    gap: .15rem;
    flex: 1;
    height: 100%;
}
.nav-link {
    color: rgba(255,255,255,.65);
    padding: .45rem .9rem;
    border-radius: var(--radius-sm);
    font-size: .85rem;
    font-weight: 500;
    text-decoration: none;
    transition: background var(--transition), color var(--transition);
    letter-spacing: .01em;
    height: 34px;
    display: flex;
    align-items: center;
}
.nav-link:hover { background: rgba(255,255,255,.1); color: #fff; text-decoration: none; }
.nav-link.active {
    background: rgba(255,255,255,.14);
    color: #fff;
    font-weight: 600;
}

/* ── Nav Dropdown ────────────────────────────────────────────────────────── */
.nav-dropdown {
    position: relative;
    height: 100%;
    display: flex;
    align-items: center;
}
.nav-dropdown-toggle {
    background: none;
    border: none;
    cursor: pointer;
    font-family: inherit;
    white-space: nowrap;
}
.nav-dropdown-menu {
    display: none;
    position: absolute;
    top: calc(100% - 4px);
    left: 0;
    min-width: 180px;
    background: var(--color-bg-white);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    z-index: 200;
    padding: .3rem 0;
}
.nav-dropdown:hover .nav-dropdown-menu,
.nav-dropdown:focus-within .nav-dropdown-menu {
    display: block;
}
.nav-dropdown-item {
    display: block;
    padding: .5rem 1rem;
    font-size: .84rem;
    font-weight: 500;
    color: var(--color-text);
    text-decoration: none;
    transition: background var(--transition), color var(--transition);
}
.nav-dropdown-item:hover {
    background: #EEF3FB;
    color: var(--color-primary);
    text-decoration: none;
}

.topnav-user {
    position: relative;
    margin-left: auto;
    flex-shrink: 0;
}
.user-chip {
    display: flex;
    align-items: center;
    gap: .6rem;
    cursor: pointer;
    padding: .3rem .5rem .3rem .4rem;
    border-radius: var(--radius-md);
    transition: background var(--transition);
}
.user-chip:hover { background: rgba(255,255,255,.1); }
.user-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--color-accent);
    color: #fff;
    font-size: .7rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    letter-spacing: .02em;
}
.user-info { display: flex; flex-direction: column; line-height: 1.2; }
.user-name { color: #fff; font-size: .82rem; font-weight: 600; }
.user-role-label { color: rgba(255,255,255,.5); font-size: .7rem; }
.user-caret { color: rgba(255,255,255,.4); font-size: .6rem; margin-left: .2rem; }
.user-menu {
    display: none;
    position: absolute;
    right: 0;
    top: calc(100% + 6px);
    background: var(--color-bg-white);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    min-width: 190px;
    padding: .4rem 0;
    z-index: 200;
}
.topnav-user:hover .user-menu { display: block; }
.user-menu-divider { height: 1px; background: var(--color-border); margin: .3rem 0; }
.user-menu-item {
    display: flex;
    align-items: center;
    gap: .5rem;
    width: 100%;
    padding: .55rem 1rem;
    font-size: .82rem;
    color: var(--color-text);
    background: none;
    border: none;
    text-align: left;
    cursor: pointer;
    text-decoration: none;
    transition: background var(--transition);
    font-family: inherit;
}
.user-menu-item:hover { background: var(--color-bg); text-decoration: none; }
.user-menu-logout { color: var(--color-error); }

/* ── Badges ──────────────────────────────────────────────────────────────── */
.badge {
    display: inline-flex;
    align-items: center;
    padding: .2em .6em;
    border-radius: 999px;
    font-size: .67rem;
    font-weight: 700;
    letter-spacing: .04em;
    text-transform: uppercase;
}
.badge-super_admin { background: #FEE2E2; color: #991B1B; }
.badge-admin       { background: #DBEAFE; color: #1E40AF; }
.badge-manager     { background: #CFFAFE; color: #155E75; }
.badge-associate   { background: #F1F5F9; color: #475569; }

/* ── Page Wrapper ────────────────────────────────────────────────────────── */
.page-wrapper {
    flex: 1;
    max-width: var(--content-max);
    width: 100%;
    margin: 0 auto;
    padding: 2rem 1.75rem;
}

/* ── Page Header ─────────────────────────────────────────────────────────── */
.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 1rem;
    margin-bottom: 1.75rem;
}
.page-header h2 {
    font-size: 1.45rem;
    font-weight: 800;
    color: var(--color-primary);
    letter-spacing: -.02em;
    line-height: 1.2;
}
.page-header-actions { display: flex; gap: .5rem; align-items: center; }

/* ── Cards ───────────────────────────────────────────────────────────────── */
.card {
    background: var(--color-bg-white);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 1.5rem;
    box-shadow: var(--shadow-xs);
}
.card-header {
    font-size: .9rem;
    font-weight: 700;
    color: var(--color-primary);
    margin-bottom: 1.1rem;
    padding-bottom: .85rem;
    border-bottom: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

/* ── Stat Cards ──────────────────────────────────────────────────────────── */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: .85rem;
    margin-bottom: 1.5rem;
}
.stat-card {
    background: var(--color-bg-white);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 1.25rem 1.4rem 1.1rem;
    box-shadow: var(--shadow-xs);
    position: relative;
    overflow: hidden;
}
.stat-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 3px;
    background: var(--stat-color, var(--color-primary));
    border-radius: var(--radius-md) var(--radius-md) 0 0;
}
.stat-card:nth-child(1) { --stat-color: var(--color-primary); }
.stat-card:nth-child(2) { --stat-color: #0891B2; }
.stat-card:nth-child(3) { --stat-color: #7C3AED; }
.stat-card:nth-child(4) { --stat-color: var(--color-accent); }
.stat-label {
    font-size: .7rem;
    font-weight: 700;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: .07em;
    margin-bottom: .5rem;
}
.stat-value {
    font-size: 1.65rem;
    font-weight: 800;
    color: var(--color-primary);
    line-height: 1.1;
    letter-spacing: -.02em;
}
.stat-sub {
    font-size: .75rem;
    color: var(--color-text-muted);
    margin-top: .3rem;
    font-weight: 500;
}

/* ── Alerts ──────────────────────────────────────────────────────────────── */
.alert {
    display: flex;
    align-items: flex-start;
    gap: .75rem;
    padding: .9rem 1.1rem;
    border-radius: var(--radius-md);
    margin-bottom: 1.1rem;
    font-size: .875rem;
    border-left: 3px solid transparent;
}
.alert-success { background: #F0FDF4; border-color: var(--color-success); color: #14532D; }
.alert-error   { background: #FEF2F2; border-color: var(--color-error);   color: #7F1D1D; }
.alert-warning { background: #FFFBEB; border-color: var(--color-warning); color: #78350F; }
.alert-info    { background: #EFF6FF; border-color: var(--color-info);    color: #1E3A5F; }

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .4rem;
    padding: .5rem 1.1rem;
    border-radius: var(--radius-sm);
    font-size: .82rem;
    font-weight: 600;
    border: 1px solid transparent;
    cursor: pointer;
    text-decoration: none;
    transition: background var(--transition), border-color var(--transition),
                color var(--transition), box-shadow var(--transition), transform var(--transition);
    white-space: nowrap;
    line-height: 1.4;
    letter-spacing: .01em;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--color-accent); color: #fff; border-color: var(--color-accent); }
.btn-primary:hover { background: var(--color-accent-hover); border-color: var(--color-accent-hover); text-decoration: none; color: #fff; box-shadow: 0 4px 12px rgba(200,16,46,.3); }
.btn-secondary { background: var(--color-bg-white); color: var(--color-text); border-color: var(--color-border); }
.btn-secondary:hover { background: var(--color-bg); text-decoration: none; box-shadow: var(--shadow-xs); }
.btn-navy { background: var(--color-primary); color: #fff; border-color: var(--color-primary); }
.btn-navy:hover { background: var(--color-primary-light); text-decoration: none; color: #fff; }
.btn-danger { background: var(--color-error); color: #fff; border-color: var(--color-error); }
.btn-danger:hover { background: #B91C1C; text-decoration: none; color: #fff; }
.btn-sm { padding: .3rem .7rem; font-size: .77rem; }
.btn-full { width: 100%; }
.btn-outline { background: transparent; border-color: var(--color-border); color: var(--color-text); }
.btn-outline:hover { background: var(--color-bg); text-decoration: none; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--color-text-muted); }
.btn-ghost:hover { background: var(--color-bg); color: var(--color-text); text-decoration: none; }

/* ── Forms ───────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 1.15rem; }
.form-group label {
    display: block;
    font-size: .82rem;
    font-weight: 600;
    color: var(--color-text);
    margin-bottom: .4rem;
}
.form-group input[type="text"],
.form-group input[type="email"],
.form-group input[type="password"],
.form-group input[type="date"],
.form-group input[type="number"],
.form-group select,
.form-group textarea {
    display: block;
    width: 100%;
    padding: .55rem .85rem;
    border: 1.5px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: var(--color-bg-white);
    color: var(--color-text);
    transition: border-color var(--transition), box-shadow var(--transition);
    outline: none;
    font-size: .875rem;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    border-color: var(--color-primary-light);
    box-shadow: 0 0 0 3px rgba(26,58,107,.12);
}
.form-group .form-help {
    font-size: .75rem;
    color: var(--color-text-muted);
    margin-top: .35rem;
    line-height: 1.4;
}
.form-actions {
    display: flex;
    gap: .75rem;
    align-items: center;
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid var(--color-border);
}
.form-check {
    display: flex;
    align-items: center;
    gap: .5rem;
    font-size: .875rem;
    cursor: pointer;
}
.form-check input[type="checkbox"] { width: 16px; height: 16px; cursor: pointer; accent-color: var(--color-primary); }

/* ── Tables ──────────────────────────────────────────────────────────────── */
.table-wrapper {
    width: 100%;
    overflow-x: auto;
    border-radius: var(--radius-md);
    border: 1px solid var(--color-border);
    box-shadow: var(--shadow-xs);
}
table {
    width: 100%;
    border-collapse: collapse;
    background: var(--color-bg-white);
    font-size: .85rem;
}
thead th {
    background: var(--color-primary);
    color: rgba(255,255,255,.9);
    font-weight: 600;
    font-size: .72rem;
    text-transform: uppercase;
    letter-spacing: .07em;
    padding: .85rem 1rem;
    text-align: left;
    white-space: nowrap;
}
thead th:first-child { border-radius: var(--radius-md) 0 0 0; }
thead th:last-child  { border-radius: 0 var(--radius-md) 0 0; }
thead th.sortable { cursor: pointer; user-select: none; }
thead th.sortable:hover { background: var(--color-primary-light); }
thead th .sort-icon { opacity: .35; margin-left: .25rem; font-size: .65rem; }
thead th.sort-asc  .sort-icon::after { content: '↑'; opacity: 1; }
thead th.sort-desc .sort-icon::after { content: '↓'; opacity: 1; }
thead th.text-right, td.text-right { text-align: right; }
thead th.text-center, td.text-center { text-align: center; }
tbody tr { border-bottom: 1px solid var(--color-border); transition: background var(--transition); }
tbody tr:last-child { border-bottom: none; }
tbody td { padding: .7rem 1rem; color: var(--color-text); vertical-align: middle; }
tbody tr.row-associate { background: #fff; cursor: pointer; }
tbody tr.row-associate:hover { background: #F5F7FF; }
tbody tr.row-dept td { padding-left: 1rem; }
tbody tr.row-dept { display: none; }
tbody tr.row-dept.expanded { display: table-row; }

/* ── Footer ──────────────────────────────────────────────────────────────── */
.site-footer {
    background: var(--color-primary);
    padding: .85rem 1.75rem;
    margin-top: auto;
}
.site-footer-inner {
    max-width: var(--content-max);
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.footer-copy, .footer-version { font-size: .72rem; color: rgba(255,255,255,.4); }

/* ── Data-source strip (per-report footer chip row) ──────────────────────── */
/* Set by reports via `$data_sources = ['sbsdb', ...]` then rendered in
   layout_footer.php. Sits at the bottom of the page-wrapper, just above
   the global site-footer. */
.data-source-strip {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: .55rem;
    margin: 2rem 0 .5rem;
    padding: .55rem .8rem;
    background: rgba(248, 250, 252, 0.7);
    border: 1px solid rgba(229, 231, 235, 1);
    border-radius: .45rem;
    font-family: "Inter", sans-serif;
    font-size: .72rem;
    color: rgba(107, 114, 128, 1);
}
.data-source-strip svg { color: rgba(107, 114, 128, 1); flex-shrink: 0; }
.data-source-label { font-weight: 600; color: rgba(75, 85, 99, 1); }
.data-source-chip {
    background: #fff;
    border: 1px solid rgba(229, 231, 235, 1);
    border-radius: 9999px;
    padding: .15rem .65rem;
    font-weight: 500;
    color: rgba(48, 48, 48, 1);
    font-size: .7rem;
    cursor: help;
}
.data-source-clickhouse {
    border-color: rgba(252, 211, 77, 0.55);
    background: rgba(255, 251, 235, 1);
    color: rgba(120, 53, 15, 1);
}
.data-source-mssql {
    border-color: rgba(96, 165, 250, 0.55);
    background: rgba(239, 246, 255, 1);
    color: rgba(30, 64, 175, 1);
}
.data-source-via {
    margin-left: auto;
    color: rgba(150, 150, 150, 1);
    font-size: .68rem;
}
.data-source-via code {
    background: rgba(243, 244, 246, 1);
    padding: .05rem .35rem;
    border-radius: .25rem;
    font-size: .68rem;
    color: rgba(75, 85, 99, 1);
}

@media print {
    .data-source-strip { display: none; }
}

/* ── Login Page ──────────────────────────────────────────────────────────── */
body.login-page {
    background: linear-gradient(135deg, var(--color-primary) 0%, #1A3A6B 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
}
.login-container {
    background: var(--color-bg-white);
    border-radius: var(--radius-xl);
    padding: 2.75rem 2.25rem;
    width: 100%;
    max-width: 420px;
    box-shadow: var(--shadow-lg);
}
.login-logo { text-align: center; margin-bottom: 2rem; }
.login-brand {
    font-size: 1.8rem;
    font-weight: 800;
    color: var(--color-primary);
    margin-bottom: .25rem;
    letter-spacing: -.03em;
}
.login-subtitle {
    font-size: .75rem;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: .1em;
    font-weight: 500;
}
.login-form .btn { margin-top: .5rem; }
.login-footer { text-align: center; margin-top: 1.5rem; font-size: .8rem; color: var(--color-text-muted); }

.login-divider {
    display: flex; align-items: center; gap: .75rem;
    margin: 1.25rem 0; color: var(--color-text-muted); font-size: .8rem;
    text-align: center;
}
.login-divider::before,
.login-divider::after { content: ''; flex: 1; height: 1px; background: var(--color-border); }
.login-divider span { flex-shrink: 0; }

.btn-google {
    display: flex; align-items: center; justify-content: center; gap: .6rem;
    width: 100%; box-sizing: border-box; padding: .65rem 1rem;
    background: #fff; color: #3c4043;
    border: 1px solid #dadce0; border-radius: 6px;
    font-size: .9rem; font-weight: 500; text-decoration: none;
    transition: background .15s, box-shadow .15s;
}
.btn-google:hover {
    background: #f8f9fa;
    box-shadow: 0 1px 3px rgba(0,0,0,.12);
}

/* ── Error Pages ─────────────────────────────────────────────────────────── */
body.error-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.error-container { text-align: center; padding: 3rem; }
.error-container h1 { font-size: 5rem; font-weight: 800; color: var(--color-primary); line-height: 1; letter-spacing: -.05em; }
.error-container p { font-size: 1.1rem; color: var(--color-text-muted); margin: 1rem 0 2rem; }

/* ── Utility ─────────────────────────────────────────────────────────────── */
.text-right   { text-align: right; }
.text-center  { text-align: center; }
.text-muted   { color: var(--color-text-muted); }
.text-success { color: var(--color-success); }
.text-danger  { color: var(--color-error); }
.text-sm      { font-size: .78rem; }
.fw-bold      { font-weight: 700; }
.fw-semibold  { font-weight: 600; }
.mt-1 { margin-top: .5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: .5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }
.d-flex { display: flex; }
.gap-1  { gap: .5rem; }
.gap-2  { gap: 1rem; }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }
.flex-wrap { flex-wrap: wrap; }

/* ── Loading / Spinner ───────────────────────────────────────────────────── */
.loading-overlay {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 3rem;
    font-size: .875rem;
    color: var(--color-text-muted);
    gap: .75rem;
}
.spinner {
    width: 18px;
    height: 18px;
    border: 2px solid var(--color-border);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Page fade-in ────────────────────────────────────────────────────────── */
.page-wrapper { animation: pageFade .2s ease; }
@keyframes pageFade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
    .page-wrapper { padding: 1rem; }
    .topnav-links { display: none; }
    .stat-grid { grid-template-columns: 1fr 1fr; }
    .user-info { display: none; }
}

/* ── Print ───────────────────────────────────────────────────────────────── */
@media print {
    .topnav, .site-footer, .report-controls, .export-bar, .btn,
    .user-chip, .user-menu, .page-header-actions { display: none !important; }
    body { background: #fff; }
    .page-wrapper { padding: 0; max-width: none; animation: none; }
    table { font-size: .72rem; }
    thead th { background: #0D2240 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; position: static; }
    .stat-card { border: 1px solid #ccc; box-shadow: none; }
    tbody tr.row-dept { display: table-row !important; }
}
