/* ── Kalpurush font-weight fix ────────────────────────────────
   The CDN declares font-weight: 100 900 on a single-weight font,
   preventing browsers from synthesizing bold. Re-declare with
   font-weight: normal so faux-bold kicks in for fw-bold etc.
   ──────────────────────────────────────────────────────────────── */
@font-face {
    font-family: 'Kalpurush';
    font-weight: normal;
    font-style: normal;
    font-display: swap;
    src: url('https://fonts.maateen.me/kalpurush/Kalpurush-v0.258.woff2') format('woff2'),
         url('https://fonts.maateen.me/kalpurush/Kalpurush-v0.258.ttf') format('truetype');
}

/* ================================================================
   layout.css
   Place at:  src/main/resources/static/css/layout.css
   ================================================================ */

/* ── Variables ─────────────────────────────────────────────────── */
:root {
    --topbar-h: 64px;
    --sidebar-w: 240px;
    --sidebar-w-col: 64px;

    --bg-base: #0f1117;
    --bg-surface: #181c24;
    --bg-hover: #1e2330;
    --bg-active: rgba(99, 102, 241, 0.15);
    --border: rgba(255, 255, 255, 0.07);
    --overlay: rgba(0, 0, 0, 0.55);

    --accent: #6366f1;
    --accent-soft: #818cf8;
    --accent-glow: rgba(99, 102, 241, 0.30);

    --tx-primary: #e2e8f0;
    --tx-secondary: #94a3b8;
    --tx-muted: #475569;

    --radius: 8px;
    --transition: 250ms cubic-bezier(.4, 0, .2, 1);

    /* Bootstrap variable bridges (dark) */
    --bs-body-bg: #0f1117;
    --bs-body-color: #e2e8f0;
    --bs-border-color: rgba(255, 255, 255, 0.07);
    --bs-card-bg: #181c24;
    --bs-card-color: #e2e8f0;
    --bs-card-border-color: rgba(255, 255, 255, 0.07);
}

[data-theme="light"] {
    --bg-base: #f8fafc;
    --bg-surface: #ffffff;
    --bg-hover: #f1f5f9;
    --bg-active: rgba(99, 102, 241, 0.10);
    --border: rgba(0, 0, 0, 0.08);
    --overlay: rgba(0, 0, 0, 0.30);

    --accent: #4f46e5;
    --accent-soft: #4338ca;
    --accent-glow: rgba(79, 70, 229, 0.15);

    --tx-primary: #020617;
    --tx-secondary: #1e293b;
    --tx-muted: #475569;

    /* Bootstrap variable bridges (light) */
    --bs-body-bg: #f8fafc;
    --bs-body-color: #020617;
    --bs-border-color: rgba(0, 0, 0, 0.08);
    --bs-card-bg: #ffffff;
    --bs-card-color: #020617;
    --bs-card-border-color: rgba(0, 0, 0, 0.08);
}

/* ── Reset ─────────────────────────────────────────────────────── */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    min-height: 100vh;
    background: var(--bg-base);
    color: var(--tx-primary);
    font-family: 'Sora', system-ui, sans-serif;
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
}

:lang(bn):not(i):not(.fa):not(.fas):not(.far):not(.fal):not(.fab) {
    font-family: 'Kalpurush', 'Sora', system-ui, sans-serif;
}

i, .fa, .fas, .far, .fal, .fab {
    font-family: 'Font Awesome 6 Free', 'Font Awesome 6 Brands', system-ui, sans-serif !important;
}

a {
    text-decoration: none;
    color: inherit;
}

/* ================================================================
   TOPBAR
   ================================================================ */
.topbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
    height: var(--topbar-h);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
    /* Indigo top accent line */
    box-shadow: inset 0 1px 0 var(--accent),
    0 2px 8px rgba(0, 0, 0, 0.06);
}

/* Brand */
.topbar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
}

.brand-logo {
    --logo-h: 42px;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    flex-shrink: 0;
}

.brand-logo img {
    height: var(--logo-h);
    width: auto;
}

/* The tagline arcs under আঙ্গিক, centred on the wordmark and clear of the butterfly's
   wing; all sizes follow --logo-h. The colours are the wordmark's per-theme oranges. */
.brand-logo__tagline {
    display: block;
    width: calc(var(--logo-h) * 3.1);
    height: auto;
    margin-left: calc(var(--logo-h) * 1.2);
    margin-top: calc(var(--logo-h) * -0.12);
    overflow: visible;
    fill: #F2993A;
}

.brand-logo__tagline text {
    font-family: 'Kalpurush', system-ui, sans-serif;
    font-size: 11.5px;
}

[data-theme="light"] .brand-logo__tagline {
    fill: #D4650A;
}

/* Theme swap. The pre-paint script in every layout sets <html data-theme="light">
   for the light theme and leaves the attribute off for dark, so the variant is
   chosen in CSS with no JavaScript and no flash of the wrong logo. */
.brand-logo__lockup--on-light {
    display: none;
}

[data-theme="light"] .brand-logo__lockup--on-dark {
    display: none;
}

[data-theme="light"] .brand-logo__lockup--on-light {
    display: block;
}

/* The stacked lockup only shows on mobile (see the 768px breakpoint). */
.brand-logo__stacked {
    display: none;
}

/* Hamburger */
.topbar-toggle {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--tx-secondary);
    width: 36px;
    height: 36px;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    transition: background var(--transition), color var(--transition);
    margin-right: 6px;
}

/* Search */
.topbar-search {
    flex: 1;
    max-width: 340px;
    margin: 0 24px;
    position: relative;
}

.topbar-search i {
    position: absolute;
    left: 11px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--tx-muted);
    font-size: 16px;
    pointer-events: none;
}

.topbar-search input {
    width: 100%;
    padding: 8px 12px 8px 32px;
    background: var(--bg-hover);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--tx-primary);
    font-size: 16px;
    outline: none;
    transition: border-color var(--transition), box-shadow var(--transition);
}

.topbar-search input::placeholder {
    color: var(--tx-muted);
}

.topbar-search input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

/* Right side actions */
.topbar-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

.topbar-icon-btn {
    position: relative;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--tx-secondary);
    width: 36px;
    height: 36px;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    transition: background var(--transition), color var(--transition);
}

.topbar-icon-btn:hover,
.topbar-toggle:hover {
    background: var(--bg-hover);
    color: var(--tx-primary);
}

.topbar-nav-link {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    border-radius: var(--radius);
    color: var(--tx-secondary);
    font-size: 14px;
    font-weight: 500;
    text-decoration: none;
    transition: background var(--transition), color var(--transition);
}

.topbar-nav-link i {
    font-size: 14px;
}

.topbar-nav-link.active {
    color: var(--accent-soft);
    font-weight: 700;
}

/* Guest topbar nav (unlogged users, desktop only) */
.topbar-guest-nav {
    display: flex;
    align-items: center;
    gap: 4px;
}

.topbar-divider {
    width: 1px;
    height: 24px;
    background: var(--border);
    margin: 0 4px;
}

/* User dropdown */
.user-dropdown {
    position: relative;
}

.user-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--tx-primary);
    padding: 4px 8px 4px 4px;
    border-radius: var(--radius);
    transition: background var(--transition);
}

.user-btn:hover {
    background: var(--bg-hover);
}

.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    overflow: hidden;
    background: var(--bg-active);
    border: 1px solid rgba(99, 102, 241, 0.35);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 15px;
    font-weight: 700;
    color: var(--accent-soft);
    flex-shrink: 0;
}

.user-info {
    text-align: left;
    line-height: 1.25;
}

.user-name {
    font-size: 16px;
    font-weight: 600;
    color: var(--tx-primary);
}

.user-role {
    font-size: 14px;
    color: var(--tx-secondary);
}

.user-chevron {
    font-size: 14px;
    color: var(--tx-muted);
    transition: transform var(--transition);
    margin-left: 2px;
}

.user-chevron.open {
    transform: rotate(180deg);
}

.dropdown-panel {
    display: none;
    position: absolute;
    right: 0;
    top: calc(100% + 8px);
    width: 210px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
    z-index: 200;
    animation: fadeDown .15s ease forwards;
}

.dropdown-panel.open {
    display: block;
}

@keyframes fadeDown {
    from {
        opacity: 0;
        transform: translateY(-6px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.dp-header {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
}

.dp-header .dp-label {
    font-size: 13px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--tx-muted);
}

.dp-header .dp-val {
    font-size: 16px;
    font-weight: 600;
    color: var(--tx-primary);
    margin-top: 2px;
}

.dp-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    font-size: 16px;
    color: var(--tx-secondary);
    cursor: pointer;
    transition: background var(--transition), color var(--transition);
}

.dp-item:hover,
.topbar-nav-link:hover {
    background: var(--bg-hover);
    color: var(--tx-primary);
}

.dp-item i {
    width: 14px;
    text-align: center;
}

.dp-item.logout:hover {
    background: rgba(239, 68, 68, .12);
    color: #f87171;
}

.dp-divider {
    height: 1px;
    background: var(--border);
}

/* ================================================================
   SIDEBAR
   ================================================================ */
.sidebar {
    position: fixed;
    top: var(--topbar-h);
    left: 0;
    bottom: 0;
    z-index: 90;
    width: var(--sidebar-w);
    background: var(--bg-surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: width var(--transition);
    box-shadow: 2px 0 8px rgba(0, 0, 0, 0.06);
}

.sidebar.collapsed {
    width: var(--sidebar-w-col);
}

/* Pre-paint collapsed state (no transition to prevent flicker on load) */
html.sb-collapsed .sidebar {
    width: var(--sidebar-w-col);
    transition: none;
}

html.sb-collapsed .main-wrapper {
    margin-left: var(--sidebar-w-col);
    transition: none;
}

/* Nav scroll area */
.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 16px 10px;
}

.sidebar-nav::-webkit-scrollbar {
    width: 3px;
}

.sidebar-nav::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 2px;
}

/* Section label */
.nav-section-label {
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .1em;
    color: var(--tx-muted);
    padding: 0 10px;
    margin: 4px 0 6px;
    white-space: nowrap;
    overflow: hidden;
    transition: opacity var(--transition);
}

.sidebar.collapsed .nav-section-label {
    opacity: 0;
}

/* Divider */
.nav-divider {
    height: 1px;
    background: var(--border);
    margin: 10px 10px;
}

/* Nav link */
.nav-link {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 9px 10px;
    border-radius: var(--radius);
    margin-bottom: 2px;
    color: var(--tx-secondary);
    white-space: nowrap;
    position: relative;
    overflow: hidden;
    transition: background var(--transition), color var(--transition);
    cursor: pointer;
}

.nav-link:hover {
    background: var(--bg-hover);
    color: var(--tx-primary);
}

.nav-link:hover .nav-icon {
    color: var(--accent-soft);
    transform: scale(1.1);
}

.nav-link.active {
    background: var(--bg-active);
    color: var(--accent-soft);
}

.nav-link.active .nav-label {
    font-weight: 700;
}

.nav-link.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 18%;
    bottom: 18%;
    width: 3px;
    border-radius: 0 3px 3px 0;
    background: var(--accent);
    box-shadow: 0 0 10px var(--accent-glow);
}

.nav-link.active .nav-icon {
    color: var(--accent);
}

.nav-icon {
    width: 20px;
    text-align: center;
    font-size: 15px;
    flex-shrink: 0;
    transition: color var(--transition), transform var(--transition);
}

.nav-label {
    font-size: 16px;
    font-weight: 500;
    overflow: hidden;
    transition: opacity var(--transition), width var(--transition);
}

.sidebar.collapsed .nav-label,
.sidebar.collapsed .footer-btn-label {
    opacity: 0;
    width: 0;
}

/* Tooltip when collapsed */
.sidebar.collapsed .nav-link:hover::after {
    content: attr(data-tip);
    position: absolute;
    left: calc(var(--sidebar-w-col) + 8px);
    top: 50%;
    transform: translateY(-50%);
    background: var(--bg-surface);
    border: 1px solid var(--border);
    color: var(--tx-primary);
    font-size: 16px;
    white-space: nowrap;
    padding: 5px 10px;
    border-radius: 6px;
    z-index: 999;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    pointer-events: none;
}

.lang-switch {
    position: relative;
    display: inline-block;
}

.lang-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--tx-primary);
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.lang-btn:hover {
    background-color: var(--bg-hover);
    border-color: var(--border);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08);
}

.lang-btn .fa-globe {
    color: var(--tx-muted);
    font-size: 15px;
}

.lang-btn::after {
    content: '';
    display: inline-block;
    width: 0;
    height: 0;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-top: 4px solid var(--tx-muted);
    margin-left: 2px;
    transition: transform 0.2s ease;
}

.lang-btn.active::after {
    transform: rotate(180deg);
}

.lang-panel {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 6px;
    min-width: 140px;
    background: var(--bg-surface);
    border-radius: 10px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.12), 0 2px 6px rgba(0, 0, 0, 0.06);
    border: 1px solid var(--border);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1000;
    overflow: hidden;
}

.lang-switch:hover .lang-panel,
.lang-panel.show {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.lang-option {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    color: var(--tx-secondary);
    text-decoration: none;
    font-size: 15px;
    transition: background-color 0.15s ease, color 0.15s ease, border-left-color 0.15s ease;
    border-left: 3px solid transparent;
}

.lang-option:hover {
    background-color: var(--bg-hover);
    color: var(--tx-primary);
}

.lang-option.active {
    background-color: var(--accent-subtle, rgba(99,102,241,0.1));
    color: var(--accent);
    border-left-color: var(--accent);
    font-weight: 600;
}

.lang-option .flag {
    font-size: 16px;
}

/* Sidebar footer buttons */
.sidebar-footer {
    padding: 10px;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
    display: flex;
    gap: 6px;
}

.sidebar-footer-btn {
    display: flex;
    align-items: center;
    gap: 11px;
    flex: 1;
    padding: 9px 10px;
    border-radius: var(--radius);
    border: none;
    cursor: pointer;
    background: none;
    color: var(--tx-muted);
    white-space: nowrap;
    font-size: 16px;
    transition: background var(--transition), color var(--transition);
}

.sidebar-footer-btn:hover {
    background: var(--bg-hover);
    color: var(--tx-primary);
}

.sidebar-footer-btn .nav-icon {
    flex-shrink: 0;
}

.footer-btn-label {
    transition: opacity var(--transition);
    overflow: hidden;
}

/* ================================================================
   MAIN WRAPPER
   ================================================================ */
.main-wrapper {
    margin-top: var(--topbar-h);
    margin-left: var(--sidebar-w);
    min-height: calc(100vh - var(--topbar-h));
    display: flex;
    flex-direction: column;
    transition: margin-left var(--transition);
}

.main-wrapper.collapsed {
    margin-left: var(--sidebar-w-col);
}

.page-content {
    flex: 1;
    padding: 28px;
}

.main-footer {
    padding: 14px 28px;
    border-top: 1px solid var(--border);
    font-size: 15px;
    color: var(--tx-muted);
    text-align: center;
}

/* ================================================================
   PAGE LOADER
   ================================================================ */
.page-loader {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--overlay);
    transition: opacity 400ms cubic-bezier(.4, 0, .2, 1);
}

.page-loader.fade-out {
    opacity: 0;
    pointer-events: none;
}

.page-loader .spinner-border {
    width: 3rem;
    height: 3rem;
    color: var(--accent) !important;
}

/* ================================================================
   MOBILE
   ================================================================ */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        width: var(--sidebar-w) !important;
        transition: transform var(--transition);
    }

    .sidebar.mobile-open {
        transform: translateX(0);
    }

    .main-wrapper {
        margin-left: 0 !important;
    }

    .topbar-search {
        display: none;
    }

    /* ── Compact topbar elements on mobile ── */
    .topbar {
        padding: 0 10px;
    }

    .topbar-brand {
        margin-left: 4px;
    }

    .brand-logo {
        --logo-h: 48px;
    }

    /* Narrow headers get the stacked lockup (butterfly over আঙ্গিক), as on the brand card,
       with no tagline. These selectors have to outrank the desktop rules above. */
    .brand-logo .brand-logo__tagline,
    .brand-logo .brand-logo__lockup,
    [data-theme="light"] .brand-logo .brand-logo__lockup,
    [data-theme="light"] .brand-logo .brand-logo__stacked--on-dark {
        display: none;
    }

    .brand-logo .brand-logo__stacked--on-dark,
    [data-theme="light"] .brand-logo .brand-logo__stacked--on-light {
        display: block;
    }

    .topbar-toggle {
        width: 28px;
        height: 28px;
        font-size: 13px;
        margin-right: 2px;
    }

    .user-btn {
        gap: 5px;
        padding: 3px 5px 3px 3px;
    }

    .user-avatar {
        width: 26px;
        height: 26px;
        font-size: 12px;
    }

    .user-chevron {
        font-size: 11px;
    }

    .user-dropdown {
        margin-right: -6px;
    }

    .dropdown-panel {
        right: 0;
        width: min(210px, calc(100vw - 20px));
    }

    .dp-item {
        padding: 8px 14px;
        font-size: 13px;
    }

    .lang-btn {
        gap: 4px;
        padding: 3px 8px;
        font-size: 12px;
        border-radius: 20px;
    }

    .lang-btn .fa-globe {
        font-size: 12px;
    }

    .btn.btn-sm.d-flex {
        font-size: 12px;
        padding: 4px 10px;
        border-radius: 20px;
    }

    .topbar-guest-nav {
        display: none;
    }

    html.is-guest .topbar-toggle {
        display: flex;
    }

    .page-content {
        padding: 12px;
    }
}

/* ── Sidebar backdrop (mobile + guest) ────────────────────────── */
.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .3);
    z-index: 89;
    backdrop-filter: blur(2px);
}

.sidebar-backdrop.active {
    display: block;
}

/* ================================================================
   GUEST (unlogged) — mobile-like sidebar on desktop
   ================================================================ */
html.is-guest .sidebar {
    transform: translateX(-100%);
    width: var(--sidebar-w) !important;
    transition: transform var(--transition);
}
html.is-guest .sidebar.mobile-open {
    transform: translateX(0);
}
html.is-guest .main-wrapper {
    margin-left: auto !important;
    margin-right: auto;
    max-width: 1440px;
    width: 100%;
}

/* Hide sidebar toggle for guests on desktop */
@media (min-width: 769px) {
    html.is-guest .topbar-toggle {
        display: none;
    }
}

