:root {
    --pg-primary: #6366f1;
    --pg-primary-dark: #4f46e5;
    --pg-secondary: #0ea5e9;
    --pg-success: #22c55e;
    --pg-danger: #ef4444;
    --pg-warning: #f59e0b;
    --pg-sidebar-bg: #0f172a;
    --pg-sidebar-w: 260px;
    --pg-topbar-h: 64px;
}

*, body {
    font-family: 'Inter', sans-serif;
}

/* ── TOPBAR ─────────────────────────────────────── */
.pg-topbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--pg-topbar-h);
    background: #ffffff;
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    align-items: center;
    padding: 0 1.5rem;
    z-index: 1040;
    gap: 1rem;
}

.pg-brand {
    display: flex;
    align-items: center;
    gap: .5rem;
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--pg-primary);
    text-decoration: none;
    white-space: nowrap;
}

.pg-brand .brand-icon {
    width: 36px;
    height: 36px;
    background: linear-gradient(135deg, var(--pg-primary), var(--pg-secondary));
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: .9rem;
}

.pg-topbar .topbar-right {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: .75rem;
}

.pg-role-badge {
    font-size: .7rem;
    font-weight: 600;
    letter-spacing: .05em;
    text-transform: uppercase;
    padding: .25rem .6rem;
    border-radius: 20px;
}

.pg-user-btn {
    display: flex;
    align-items: center;
    gap: .5rem;
    background: #f1f5f9;
    border: none;
    border-radius: 10px;
    padding: .4rem .85rem;
    font-size: .875rem;
    font-weight: 500;
    color: #334155;
    cursor: pointer;
    transition: background .2s;
}

.pg-user-btn:hover {
    background: #e2e8f0;
}

.pg-user-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--pg-primary), var(--pg-secondary));
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: .7rem;
    font-weight: 700;
}

.hover-primary:hover {
    color: var(--pg-primary) !important;
    transition: color 0.2s;
}

.fw-500 {
    font-weight: 500;
}

.fw-600 {
    font-weight: 600;
}

/* ── SIDEBAR ────────────────────────────────────── */
.pg-sidebar {
    position: fixed;
    top: var(--pg-topbar-h);
    left: 0;
    bottom: 0;
    width: var(--pg-sidebar-w);
    background: var(--pg-sidebar-bg);
    padding-bottom: 2rem;
    overflow-y: auto;
    overflow-x: hidden;
    z-index: 1030;
    transition: transform .3s ease;
}

    .pg-sidebar::-webkit-scrollbar {
        width: 4px;
    }

    .pg-sidebar::-webkit-scrollbar-track {
        background: transparent;
    }

    .pg-sidebar::-webkit-scrollbar-thumb {
        background: #334155;
        border-radius: 4px;
    }

.sidebar-section {
    padding: .5rem 1rem .25rem;
    font-size: .65rem;
    font-weight: 600;
    letter-spacing: .1em;
    text-transform: uppercase;
    color: #64748b;
    margin-top: .5rem;
}

.sidebar-item {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .55rem 1.25rem;
    color: #94a3b8;
    font-size: .875rem;
    font-weight: 400;
    text-decoration: none;
    border-radius: 0;
    transition: background .15s, color .15s;
    position: relative;
}

.sidebar-item:hover {
    color: #e2e8f0;
    background: rgba(255,255,255,.05);
}

.sidebar-item.active {
    color: #ffffff;
    background: rgba(99,102,241,.2);
    font-weight: 500;
}

.sidebar-item.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: var(--pg-primary);
    border-radius: 0 2px 2px 0;
}

.sidebar-item i {
    width: 18px;
    text-align: center;
    font-size: .875rem;
}

.sidebar-item .badge {
    margin-left: auto;
    font-size: .65rem;
    padding: .2rem .45rem;
}

/* ── MAIN CONTENT ───────────────────────────────── */
.pg-main {
    margin-left: var(--pg-sidebar-w);
    margin-top: var(--pg-topbar-h);
    min-height: calc(100vh - var(--pg-topbar-h));
    background: #f8fafc;
    padding: 0.75rem;
}

.pg-footer-with-sidebar {
    margin-left: var(--pg-sidebar-w);
}

/* ── PAGE HEADER ─────────────────────────────────── */
.pg-page-header {
    margin-bottom: 1.5rem;
}

.pg-page-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: #0f172a;
    margin: 0;
}

.pg-breadcrumb {
    font-size: .8rem;
    color: #94a3b8;
    margin-top: .2rem;
}

.pg-breadcrumb a {
    color: #64748b;
    text-decoration: none;
}

.pg-breadcrumb a:hover {
    color: var(--pg-primary);
}

/* ── CARDS ──────────────────────────────────────── */
.card {
    border: 1px solid #e2e8f0;
    border-radius: 14px;
    box-shadow: 0 1px 3px rgba(0,0,0,.06);
}

.card-header {
    background: #fff;
    border-bottom: 1px solid #e2e8f0;
    border-radius: 14px 14px 0 0 !important;
    padding: 1rem 1.25rem;
    font-weight: 600;
    color: #1e293b;
}

/* ── STAT CARDS ─────────────────────────────────── */
.stat-card {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 14px;
    padding: 1.25rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    box-shadow: 0 1px 3px rgba(0,0,0,.06);
    transition: box-shadow .2s, transform .2s;
}

.stat-card:hover {
    box-shadow: 0 4px 12px rgba(0,0,0,.1);
    transform: translateY(-2px);
}

.stat-icon {
    width: 52px;
    height: 52px;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    flex-shrink: 0;
}

.stat-card .stat-label {
    font-size: .78rem;
    color: #94a3b8;
    font-weight: 500;
}

.stat-card .stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: #0f172a;
    line-height: 1.2;
}

/* ── BUTTONS ─────────────────────────────────────── */
.btn {
    border-radius: 8px;
    font-size: .875rem;
    font-weight: 500;
}

.btn-primary {
    background: var(--pg-primary);
    border-color: var(--pg-primary);
}

.btn-primary:hover {
    background: var(--pg-primary-dark);
    border-color: var(--pg-primary-dark);
}

/* ── BADGES ──────────────────────────────────────── */
.badge {
    border-radius: 6px;
    font-weight: 500;
}

/* ── TABLES ──────────────────────────────────────── */
.table {
    font-size: .875rem;
}

.table th {
    font-weight: 600;
    color: #64748b;
    font-size: .78rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    border-bottom: 2px solid #e2e8f0;
}

.table td {
    vertical-align: middle;
    color: #334155;
    border-color: #f1f5f9;
}

.table-hover > tbody > tr:hover > td {
    background: #f8fafc;
}

/* ── FORMS ──────────────────────────────────────── */
.form-control, .form-select {
    border-radius: 8px;
    border-color: #e2e8f0;
    font-size: .875rem;
}

.form-control:focus, .form-select:focus {
    border-color: var(--pg-primary);
    box-shadow: 0 0 0 3px rgba(99,102,241,.15);
}

.form-label {
    font-weight: 500;
    font-size: .875rem;
    color: #374151;
}

/* ── ALERTS ──────────────────────────────────────── */
.alert {
    border-radius: 10px;
    font-size: .875rem;
}

/* ── ALERTS TOAST ────────────────────────────────── */
.pg-toast-container {
    position: fixed;
    top: calc(var(--pg-topbar-h) + 1rem);
    right: 1.5rem;
    z-index: 9999;
}

/* ── NO SIDEBAR (public) ─────────────────────────── */
.pg-main-public {
    margin-top: var(--pg-topbar-h);
    min-height: calc(100vh - var(--pg-topbar-h));
    background: #f8fafc;
    padding: 0.5rem;
}

/* ── RESPONSIVE ──────────────────────────────────── */

/* Sidebar overlay backdrop */
.pg-sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.5);
    z-index: 1029;
    backdrop-filter: blur(2px);
}

.pg-sidebar-backdrop.show {
    display: block;
}

/* Mobile bottom navigation bar */
.pg-bottom-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 60px;
    background: #ffffff;
    border-top: 1px solid #e2e8f0;
    z-index: 1035;
    padding-bottom: env(safe-area-inset-bottom);
}

.pg-bottom-nav .nav-items {
    display: flex;
    height: 100%;
    margin-left: auto;
    margin-right: auto;
}

.pg-bottom-nav .nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #94a3b8;
    text-decoration: none;
    font-size: .62rem;
    font-weight: 500;
    gap: 3px;
    transition: color .15s;
    padding: 0 4px;
    width: 60px;
    border-right: 1px dashed var(--pg-primary);
}

.pg-bottom-nav .nav-item:last-child {
    border-right: 0;
}

.pg-bottom-nav .nav-item i {
    font-size: 1.15rem;
}

.pg-bottom-nav .nav-item.active {
    color: var(--pg-primary);
}

.pg-bottom-nav .nav-item .dot {
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: var(--pg-primary);
    opacity: 0;
}

.pg-bottom-nav .nav-item.active .dot {
    opacity: 1;
}

@media (max-width: 991.98px) {
    .pg-sidebar {
        transform: translateX(-100%);
        top: 0;
        z-index: 1030;
        height: 100vh;
        max-height: 100vh;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 80px;
    }

    .pg-sidebar.show {
        transform: translateX(0);
        box-shadow: 4px 0 24px rgba(0,0,0,.25);
    }

    .pg-main {
        margin-left: 0;
        padding: 1rem 0.875rem;
        padding-bottom: calc(60px + env(safe-area-inset-bottom) + 1rem);
    }

    .pg-footer-with-sidebar {
        margin-left: 0;
    }

    .pg-topbar {
        padding: 0 1rem;
    }
}

@media (max-width: 767.98px) {
    .pg-bottom-nav {
        display: flex;
    }

    .pg-main {
        padding: 0.75rem 0.75rem;
        padding-bottom: calc(68px + env(safe-area-inset-bottom) + 0.5rem);
    }

    .card-body {
        padding: 1rem;
    }

    .stat-card {
        padding: 1rem;
    }

    .stat-value {
        font-size: 1.25rem !important;
    }
    /* Bigger touch targets for table actions */
    .table td .btn {
        min-height: 36px;
        min-width: 36px;
    }
    /* Stack action buttons on mobile */
    .pg-page-header {
        flex-direction: column;
        align-items: flex-start !important;
        gap: .75rem;
    }
}

@media (max-width: 575.98px) {
    body {
        padding-bottom: 60px;
    }

    .pg-topbar {
        padding: 0 .75rem;
    }

    .pg-brand span {
        display: none;
    }

    .pg-sidebar {
        padding-top:4rem;
    }
    /* hide text on tiny screens */
}

/* Table responsive fix */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* Smooth scrolling */
html {
    scroll-behavior: smooth;
}

/* Touch-friendly form controls */
@media (max-width: 767.98px) {
    .form-control, .form-select {
        min-height: 44px;
        font-size: 16px !important; /* prevent iOS zoom */
    }

    .btn {
        min-height: 44px;
    }
}

@media (min-width: 992px) {
    html.sidebar-toggled .pg-sidebar {
        transform: translateX(-100%);
    }
    html.sidebar-toggled .pg-main,
    html.sidebar-toggled .pg-footer-with-sidebar {
        margin-left: 0;
    }
}

@media print {
    .pg-bottom-nav {
        display: none;
    }
}
