:root {
    --primary: #0d6efd;
    --primary-dark: #0b5ed7;
    --sidebar-bg: #1e293b;
    --sidebar-text: #cbd5e1;
    --body-bg: #f4f6f9;
    --card-bg: #ffffff;
    --text-color: #212529;
    --border-color: #e2e8f0;
}

[data-theme-mode="dark"] {
    --body-bg: #0f172a;
    --card-bg: #1e293b;
    --text-color: #e2e8f0;
    --border-color: #334155;
}

* { box-sizing: border-box; }
body {
    background: var(--body-bg);
    color: var(--text-color);
    font-family: 'Segoe UI', Roboto, Arial, sans-serif;
    transition: background .2s ease, color .2s ease;
}

/* ---------- Layout ---------- */
.app-wrapper { display: flex; min-height: 100vh; }

.sidebar {
    width: 250px;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    flex-shrink: 0;
    position: fixed;
    top: 0; bottom: 0; left: 0;
    overflow-y: auto;
    z-index: 1030;
    transition: transform .25s ease;
}
.sidebar .brand { padding: 18px 16px; display: flex; align-items: center; gap: 10px; border-bottom: 1px solid rgba(255,255,255,.08); }
.sidebar .brand img { height: 34px; width: 34px; object-fit: contain; border-radius: 6px; background:#fff; padding:2px;}
.sidebar .brand span { font-weight: 700; font-size: 15px; color: #fff; line-height:1.2; }
.sidebar-nav { padding: 10px 0; }
.sidebar-nav .nav-section { padding: 10px 18px 4px; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: #64748b; }
.sidebar-nav a {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 18px; color: var(--sidebar-text); text-decoration: none; font-size: 14.5px;
    border-left: 3px solid transparent;
}
.sidebar-nav a:hover, .sidebar-nav a.active {
    background: rgba(255,255,255,.06);
    color: #fff;
    border-left-color: var(--primary);
}
.sidebar-nav a i { width: 18px; text-align: center; }

.main-content { margin-left: 250px; flex: 1; min-height: 100vh; display:flex; flex-direction:column; }
@media (max-width: 991px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.show { transform: translateX(0); }
    .main-content { margin-left: 0; }
}

/* ---------- Topbar ---------- */
.topbar {
    background: var(--card-bg);
    border-bottom: 1px solid var(--border-color);
    padding: 10px 20px;
    display: flex; align-items: center; justify-content: space-between;
    position: sticky; top: 0; z-index: 1020;
}
.topbar .icon-btn { background: none; border: none; font-size: 18px; color: var(--text-color); position: relative; padding: 6px 10px; }
.topbar .badge-dot { position:absolute; top:2px; right:2px; background:#dc3545; color:#fff; border-radius:50%; font-size:10px; padding:1px 5px; }

.content-area { padding: 22px; flex: 1; }

/* ---------- Cards ---------- */
.card { background: var(--card-bg); border: 1px solid var(--border-color); border-radius: 10px; }
.stat-card { border-radius: 12px; padding: 18px 20px; color: #fff; position: relative; overflow: hidden; }
.stat-card h3 { font-size: 26px; font-weight: 700; margin: 4px 0 0; }
.stat-card .icon-circle { width: 42px; height: 42px; border-radius: 50%; background: rgba(255,255,255,.2); display:flex; align-items:center; justify-content:center; font-size:18px; }
.bg-grad-1 { background: linear-gradient(135deg,#0d6efd,#0b3d91); }
.bg-grad-2 { background: linear-gradient(135deg,#20c997,#0d7a53); }
.bg-grad-3 { background: linear-gradient(135deg,#fd7e14,#c05600); }
.bg-grad-4 { background: linear-gradient(135deg,#dc3545,#8c1c28); }

table.data-table th { background: var(--sidebar-bg); color: #fff; font-size: 13px; text-transform: uppercase; letter-spacing: .03em; }
table.data-table td, table.data-table th { vertical-align: middle; }
.btn-excel { background:#1d6f42; color:#fff; border:none; }
.btn-excel:hover { background:#155a34; color:#fff; }

.status-pill { padding: 3px 10px; border-radius: 20px; font-size: 12px; font-weight:600; }
.status-active { background:#dcfce7; color:#166534; }
.status-disabled { background:#fee2e2; color:#991b1b; }

/* ---------- Page loader (min. 3s on every navigation) ---------- */
#page-loader {
    position: fixed; inset: 0; background: var(--body-bg);
    z-index: 3000; display:flex; flex-direction:column; align-items:center; justify-content:center; gap:16px;
}
.loader-spinner {
    width: 54px; height: 54px; border-radius: 50%;
    border: 5px solid var(--border-color); border-top-color: var(--primary);
    animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
#page-loader p { color: var(--text-color); font-size: 14px; opacity: .8; }

/* ---------- Auth / Login page ---------- */
.auth-wrapper { min-height: 100vh; display:flex; align-items:center; justify-content:center; background-size: cover; background-position:center; position:relative; }
.auth-wrapper::before { content:""; position:absolute; inset:0; background: rgba(15,23,42,.55); }
.auth-card { position:relative; z-index:2; width: 380px; background: rgba(255,255,255,.97); border-radius:14px; padding: 32px 28px; box-shadow: 0 20px 50px rgba(0,0,0,.35); }
.auth-card img.logo { height:56px; display:block; margin: 0 auto 14px; }

.slider-wrapper { position:absolute; inset:0; z-index:0; }
.slider-wrapper img { width:100%; height:100%; object-fit:cover; position:absolute; inset:0; opacity:0; transition: opacity 1.2s ease; }
.slider-wrapper img.active { opacity:1; }

/* Theme color swatches on settings page */
.color-swatch { width:34px; height:34px; border-radius:50%; cursor:pointer; border:3px solid transparent; display:inline-block; transition: transform .15s ease, border-color .15s ease; }
.color-swatch:hover { transform: scale(1.15); }
.color-swatch.selected { border-color:#000; transform: scale(1.1); }

/* =========================================================
   SYSTEM-WIDE ANIMATIONS
   ========================================================= */

/* Page content fade + rise on every load */
@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(14px); }
    to   { opacity: 1; transform: translateY(0); }
}
.fade-in { animation: fadeInUp .45s ease both; }
.content-area > *:not(.fade-in) { animation: fadeInUp .45s ease both; }

/* Staggered table row entrance (row-anim + inline animation-delay set per row) */
@keyframes rowSlideIn {
    from { opacity: 0; transform: translateX(-8px); }
    to   { opacity: 1; transform: translateX(0); }
}
.row-anim { animation: rowSlideIn .35s ease both; }

/* Sidebar links: smooth slide + highlight on hover */
.sidebar-nav a { transition: background-color .18s ease, border-left-color .18s ease, padding-left .18s ease, color .18s ease; }
.sidebar-nav a:hover { padding-left: 22px; }

/* Sidebar brand logo gentle pulse on load */
@keyframes logoPop {
    0% { transform: scale(.8); opacity: 0; }
    70% { transform: scale(1.05); opacity: 1; }
    100% { transform: scale(1); }
}
.sidebar .brand img { animation: logoPop .5s ease both; }

/* Cards lift on hover */
.card { transition: box-shadow .2s ease, transform .2s ease; }
.card:hover { box-shadow: 0 10px 28px rgba(0,0,0,.08); }

/* Stat cards: lift + shine sweep on hover */
.stat-card { transition: transform .25s ease, box-shadow .25s ease; }
.stat-card:hover { transform: translateY(-4px); box-shadow: 0 14px 30px rgba(0,0,0,.18); }
.stat-card::after {
    content: "";
    position: absolute; top: 0; left: -60%; width: 40%; height: 100%;
    background: linear-gradient(120deg, transparent, rgba(255,255,255,.25), transparent);
    transform: skewX(-20deg);
    transition: left .6s ease;
}
.stat-card:hover::after { left: 130%; }
.stat-card h3 { transition: color .2s ease; }

/* Buttons: subtle press + hover lift */
.btn { transition: transform .12s ease, box-shadow .12s ease, background-color .15s ease, filter .15s ease; }
.btn:hover { transform: translateY(-1px); filter: brightness(1.03); }
.btn:active { transform: translateY(0) scale(.97); }

/* Table rows: hover highlight sweep */
table.data-table tbody tr { transition: background-color .15s ease; }
table.data-table tbody tr:hover { background-color: rgba(13,110,253,.06); }

/* Icon buttons (bell, avatar) subtle bounce on hover */
.icon-btn { transition: transform .15s ease, color .15s ease; }
.icon-btn:hover { transform: scale(1.12); color: var(--primary); }
.badge-dot { animation: pulseDot 1.6s ease-in-out infinite; }
@keyframes pulseDot { 0%,100% { transform: scale(1); } 50% { transform: scale(1.25); } }

/* Dropdown / modal entrance */
.dropdown-menu.show { animation: fadeInUp .18s ease both; }
.modal.fade .modal-dialog { transition: transform .3s ease, opacity .3s ease; transform: translateY(-20px) scale(.98); opacity: 0; }
.modal.show .modal-dialog { transform: translateY(0) scale(1); opacity: 1; }

/* Alerts slide in */
@keyframes alertSlide { from { opacity:0; transform: translateY(-10px);} to { opacity:1; transform:translateY(0);} }
.alert { animation: alertSlide .3s ease both; }

/* Status pill gentle pop */
@keyframes pillPop { 0% { transform: scale(.85); opacity:0;} 100% { transform: scale(1); opacity:1;} }
.status-pill { animation: pillPop .25s ease both; display:inline-block; }

/* Login card entrance + slider crossfade already handled via .active opacity transition */
.auth-card { animation: fadeInUp .55s cubic-bezier(.22,1,.36,1) both; }

/* Loader spinner: add a soft breathing scale on top of the spin */
@keyframes breathe { 0%,100% { transform: scale(1); } 50% { transform: scale(1.08); } }
.loader-spinner { animation: spin .9s linear infinite, breathe 1.8s ease-in-out infinite; }
#page-loader p { animation: alertSlide .4s ease both; }

/* Reduce motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
}

/* =========================================================
   RESPONSIVE / MOBILE
   ========================================================= */

/* Never let an oversized element cause page-level horizontal scroll */
html, body { max-width: 100%; overflow-x: hidden; }
img { max-width: 100%; height: auto; }
.card, table.data-table { max-width: 100%; }

/* Sidebar backdrop shown behind the off-canvas sidebar on mobile/tablet */
.sidebar-backdrop {
    display: none;
    position: fixed; inset: 0;
    background: rgba(15, 23, 42, .5);
    z-index: 1025;
}
.sidebar-backdrop.show { display: block; }
@media (min-width: 992px) {
    .sidebar-backdrop { display: none !important; }
}

/* Page-header rows (title + action buttons) wrap instead of overflowing */
.content-area .d-flex.justify-content-between,
.content-area .d-flex.justify-content-end {
    flex-wrap: wrap;
    row-gap: 10px;
}

/* Notification / user dropdowns never exceed the viewport width */
.dropdown-menu { max-width: calc(100vw - 24px); }

@media (max-width: 991px) {
    .content-area { padding: 18px; }
}

@media (max-width: 767px) {
    .content-area { padding: 16px 14px; }
    .topbar { padding: 10px 14px; }
    table.data-table { font-size: 13px; }
    table.data-table .btn-sm { padding: .2rem .45rem; font-size: 12px; }
    .stat-card h3 { font-size: 22px; }
    .stat-card { padding: 14px 16px; }
    .auth-card { width: 100%; margin: 0 16px; }
}

@media (max-width: 575px) {
    .content-area { padding: 14px 10px; }
    h5, h6 { font-size: 15px; }
    .btn-sm { font-size: 12.5px; }
    .card.p-4 { padding: 1rem !important; }
    .card.p-3 { padding: .85rem !important; }
    table.data-table th, table.data-table td { padding: .5rem .5rem; }

    /* Topbar: keep title, bell, and avatar from crowding/overlapping */
    .topbar { padding: 8px 10px; gap: 6px; }
    .topbar h5 { font-size: 16px; max-width: 45vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .topbar .btn.dropdown-toggle { padding: 4px 8px; }

    /* Notification / account dropdowns: full-width-ish and never clipped */
    .dropdown-menu { width: calc(100vw - 24px); }

    /* Sidebar: full width off-canvas drawer instead of a narrow 250px sliver */
    .sidebar { width: min(84vw, 280px); }

    /* Stat cards: stack to 1-per-row below ~400px so numbers/icons don't squeeze */
    .stat-card h3 { font-size: 20px; }
    .stat-card .icon-circle { width: 36px; height: 36px; font-size: 16px; }

    /* Auth/login card: fill the screen with comfortable side margins */
    .auth-card { padding: 24px 18px; }

    /* Buttons grouped in a row wrap cleanly instead of overflowing */
    .btn-toolbar, .d-flex.gap-2, .d-flex.gap-3 { flex-wrap: wrap; }
}

@media (max-width: 400px) {
    .stat-card { padding: 12px 14px; }
    .topbar h5 { max-width: 38vw; }
}
