/* =============================================================
   GLOBAL STYLES - styles.css
   Bootstrap-based with custom design system
   ============================================================= */

/* -------------------------------------------------------
   CSS Variables / Design Tokens
------------------------------------------------------- */
:root {
    --primary:        #4f46e5;
    --primary-dark:   #3730a3;
    --primary-light:  #818cf8;
    --secondary:      #64748b;
    --success:        #10b981;
    --danger:         #ef4444;
    --warning:        #f59e0b;
    --info:           #3b82f6;
    --light:          #f8fafc;
    --dark:           #0f172a;

    --sidebar-width:  260px;
    --sidebar-bg:     #0f172a;
    --sidebar-text:   #94a3b8;
    --sidebar-active: #4f46e5;
    --topbar-height:  64px;
    --topbar-bg:      #ffffff;

    --font-sans:      'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
    --radius-sm:      0.375rem;
    --radius-md:      0.5rem;
    --radius-lg:      0.75rem;
    --radius-xl:      1rem;

    --shadow-sm:      0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md:      0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg:      0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --shadow-xl:      0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);

    --transition:     all 0.2s ease;
}

/* -------------------------------------------------------
   Base Reset & Typography
------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
    font-family: var(--font-sans);
    font-size: 0.9rem;
    background-color: #f1f5f9;
    color: #334155;
    line-height: 1.6;
    min-height: 100vh;
}

a { text-decoration: none; transition: var(--transition); }
a:hover { text-decoration: none; }

img { max-width: 100%; height: auto; }

/* -------------------------------------------------------
   Layout - Sidebar + Wrapper
------------------------------------------------------- */
.layout-wrapper {
    display: flex;
    min-height: 100vh;
}

/* -------------------------------------------------------
   Sidebar
------------------------------------------------------- */
.sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    height: 100vh;
    position: fixed;
    top: 0;
    left: 0;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease, width 0.3s ease;
    overflow: hidden;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid rgba(255,255,255,0.07);
    min-height: var(--topbar-height);
    text-decoration: none;
}

.sidebar-brand-icon {
    width: 36px;
    height: 36px;
    background: var(--primary);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 1.1rem;
    flex-shrink: 0;
}

.sidebar-brand-text {
    font-size: 1rem;
    font-weight: 700;
    color: #f1f5f9;
    letter-spacing: -0.02em;
    white-space: nowrap;
}

.sidebar-nav {
    flex: 1;
    min-height: 0;
    padding: 1rem 0;
    overflow-y: auto;
}

.sidebar-section-title {
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: #475569;
    padding: 0.75rem 1.5rem 0.375rem;
    margin-top: 0.5rem;
}

.sidebar-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.625rem 1.5rem;
    color: var(--sidebar-text);
    font-size: 0.875rem;
    font-weight: 500;
    border-radius: 0;
    transition: var(--transition);
    position: relative;
    cursor: pointer;
    text-decoration: none;
}

.sidebar-item:hover {
    color: #e2e8f0;
    background: rgba(255,255,255,0.05);
}

.sidebar-item.active {
    color: #ffffff;
    background: rgba(79, 70, 229, 0.2);
}

.sidebar-item.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 60%;
    background: var(--primary);
    border-radius: 0 2px 2px 0;
}

.sidebar-item .sidebar-icon {
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 1rem;
    opacity: 0.8;
}

.sidebar-item.active .sidebar-icon { opacity: 1; }

/* Submenu */
.sidebar-submenu {
    display: none;
    background: rgba(0,0,0,0.15);
}

.sidebar-submenu.show { display: block; }

.sidebar-submenu .sidebar-item {
    padding-left: 3.25rem;
    font-size: 0.825rem;
}

.sidebar-submenu .sidebar-item::before { display: none; }

.sidebar-collapse-toggle {
    margin-left: auto;
    transition: transform 0.2s;
    font-size: 0.75rem;
    opacity: 0.6;
}

.sidebar-item[aria-expanded="true"] .sidebar-collapse-toggle {
    transform: rotate(180deg);
}

.sidebar-dropdown-menu {
    display: none;
    padding-left: 0.5rem;
}
.sidebar-dropdown-menu.show {
    display: block;
}
.sidebar-child {
    font-size: 0.85rem;
    padding-left: 2.5rem !important;
}
.sidebar-chevron {
    transition: transform 0.2s;
    font-size: 0.7rem;
}
.sidebar-dropdown.open .sidebar-chevron {
    transform: rotate(180deg);
}

/* -------------------------------------------------------
   Main Content Area
------------------------------------------------------- */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    transition: margin-left 0.3s ease;
}

/* -------------------------------------------------------
   Topbar
------------------------------------------------------- */
.topbar {
    height: var(--topbar-height);
    background: var(--topbar-bg);
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    align-items: center;
    padding: 0 1.5rem;
    gap: 1rem;
    position: sticky;
    top: 0;
    z-index: 999;
    box-shadow: var(--shadow-sm);
}

.topbar-toggle {
    background: none;
    border: none;
    color: #64748b;
    font-size: 1.25rem;
    cursor: pointer;
    padding: 0.375rem;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    transition: var(--transition);
}

.topbar-toggle:hover { background: #f1f5f9; color: #334155; }

.topbar-spacer { flex: 1; }

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.topbar-btn {
    background: none;
    border: none;
    color: #64748b;
    font-size: 1.1rem;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    transition: var(--transition);
    position: relative;
}

.topbar-btn:hover { background: #f1f5f9; color: #334155; }

.topbar-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.875rem;
    cursor: pointer;
    border: none;
    transition: var(--transition);
}

.topbar-avatar:hover { box-shadow: 0 0 0 3px rgba(79,70,229,0.2); }

/* -------------------------------------------------------
   Page Content
------------------------------------------------------- */
.page-content {
    flex: 1;
    padding: 1.75rem;
}

.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 1rem;
    margin-bottom: 1.75rem;
}

.page-title {
    font-size: 1.4rem;
    font-weight: 700;
    color: #0f172a;
    margin: 0;
    letter-spacing: -0.02em;
}

.page-subtitle {
    font-size: 0.875rem;
    color: #64748b;
    margin: 0.25rem 0 0;
}

.breadcrumb {
    margin-bottom: 0;
    font-size: 0.8125rem;
}

.breadcrumb-item + .breadcrumb-item::before { color: #94a3b8; }

/* -------------------------------------------------------
   Cards
------------------------------------------------------- */
.card {
    border: 1px solid #e2e8f0;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    background: #ffffff;
    transition: var(--transition);
}

.card-header {
    background: #ffffff;
    border-bottom: 1px solid #f1f5f9;
    padding: 1rem 1.5rem;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
}

.card-title {
    font-size: 0.9375rem;
    font-weight: 600;
    color: #0f172a;
    margin: 0;
}

.card-body { padding: 1.5rem; }

.card-footer {
    background: #f8fafc;
    border-top: 1px solid #f1f5f9;
    padding: 1rem 1.5rem;
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

/* Stat Cards */
.stat-card {
    padding: 1.5rem;
    border-radius: var(--radius-lg);
    background: #ffffff;
    border: 1px solid #e2e8f0;
    box-shadow: var(--shadow-sm);
    transition: var(--transition);
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.stat-card-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.375rem;
    margin-bottom: 1rem;
}

.stat-card-value {
    font-size: 1.875rem;
    font-weight: 700;
    color: #0f172a;
    letter-spacing: -0.03em;
    line-height: 1;
}

.stat-card-label {
    font-size: 0.8125rem;
    color: #64748b;
    margin-top: 0.375rem;
    font-weight: 500;
}

.stat-card-change {
    font-size: 0.75rem;
    font-weight: 600;
    margin-top: 0.5rem;
}

/* -------------------------------------------------------
   Tables
------------------------------------------------------- */
.table {
    font-size: 0.875rem;
}

.table thead th {
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: #64748b;
    border-bottom: 1px solid #e2e8f0;
    padding: 0.875rem 1rem;
    background: #f8fafc;
    white-space: nowrap;
}

.table tbody td {
    padding: 0.875rem 1rem;
    vertical-align: middle;
    border-bottom: 1px solid #f1f5f9;
    color: #334155;
}

.table tbody tr:last-child td { border-bottom: 0; }

.table tbody tr:hover td { background: #f8fafc; }

.table-card .table { margin-bottom: 0; }
.table-card .card-body { padding: 0; }
.table-card .table thead th:first-child { border-radius: 0; }

/* -------------------------------------------------------
   Badges
------------------------------------------------------- */
.badge {
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    padding: 0.3em 0.65em;
    border-radius: 50rem;
}

/* -------------------------------------------------------
   Forms
------------------------------------------------------- */
.form-label {
    font-size: 0.8125rem;
    font-weight: 600;
    color: #374151;
    margin-bottom: 0.375rem;
}

.form-control,
.form-select {
    border: 1px solid #d1d5db;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    padding: 0.5625rem 0.875rem;
    color: #111827;
    transition: border-color 0.15s, box-shadow 0.15s;
    background-color: #ffffff;
}

.form-control:focus,
.form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.12);
    outline: none;
}

.form-control.is-invalid,
.form-select.is-invalid {
    border-color: var(--danger);
    box-shadow: none;
}

.form-control.is-invalid:focus,
.form-select.is-invalid:focus {
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.12);
}

.invalid-feedback { font-size: 0.8rem; }

.input-group-text {
    background: #f8fafc;
    border-color: #d1d5db;
    color: #6b7280;
    font-size: 0.875rem;
}

/* -------------------------------------------------------
   Buttons
------------------------------------------------------- */
.btn {
    font-size: 0.875rem;
    font-weight: 500;
    padding: 0.5625rem 1.125rem;
    border-radius: var(--radius-sm);
    transition: var(--transition);
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
}

.btn-sm {
    padding: 0.375rem 0.75rem;
    font-size: 0.8125rem;
}

.btn-lg {
    padding: 0.75rem 1.5rem;
    font-size: 0.9375rem;
}

.btn-primary {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

.btn-primary:hover {
    background: var(--primary-dark);
    border-color: var(--primary-dark);
    color: #fff;
}

.btn-outline-primary {
    color: var(--primary);
    border-color: var(--primary);
}

.btn-outline-primary:hover {
    background: var(--primary);
    color: #fff;
}

/* Icon-only button */
.btn-icon {
    width: 36px;
    height: 36px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
}

/* -------------------------------------------------------
   Alerts
------------------------------------------------------- */
.alert {
    border: none;
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    border-left: 4px solid transparent;
}

.alert-success {
    background: #f0fdf4;
    color: #166534;
    border-left-color: var(--success);
}

.alert-danger {
    background: #fef2f2;
    color: #991b1b;
    border-left-color: var(--danger);
}

.alert-warning {
    background: #fffbeb;
    color: #92400e;
    border-left-color: var(--warning);
}

.alert-info {
    background: #eff6ff;
    color: #1e40af;
    border-left-color: var(--info);
}

/* -------------------------------------------------------
   Dropdowns
------------------------------------------------------- */
.dropdown-menu {
    border: 1px solid #e2e8f0;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    font-size: 0.875rem;
    padding: 0.375rem;
}

.dropdown-item {
    border-radius: var(--radius-sm);
    padding: 0.5rem 0.75rem;
    color: #374151;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: var(--transition);
}

.dropdown-item:hover { background: #f1f5f9; color: #111827; }
.dropdown-item.text-danger:hover { background: #fef2f2; }
.dropdown-divider { border-color: #f1f5f9; margin: 0.25rem 0; }

/* -------------------------------------------------------
   Modals
------------------------------------------------------- */
.modal-content {
    border: none;
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl);
}

.modal-header {
    border-bottom: 1px solid #f1f5f9;
    padding: 1.25rem 1.5rem;
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
}

.modal-footer {
    border-top: 1px solid #f1f5f9;
    padding: 1rem 1.5rem;
    border-radius: 0 0 var(--radius-xl) var(--radius-xl);
}

/* -------------------------------------------------------
   Pagination
------------------------------------------------------- */
.pagination {
    gap: 0.25rem;
}

.page-link {
    border-radius: var(--radius-sm) !important;
    border: 1px solid #e2e8f0;
    color: #374151;
    font-size: 0.8125rem;
    padding: 0.4375rem 0.75rem;
    transition: var(--transition);
}

.page-link:hover { background: #f1f5f9; border-color: #d1d5db; color: #111827; }
.page-item.active .page-link { background: var(--primary); border-color: var(--primary); }

/* -------------------------------------------------------
   Auth Pages (Login, Register, etc.)
------------------------------------------------------- */
.auth-wrapper {
    min-height: 100vh;
    background: linear-gradient(135deg, #0f172a 0%, #1e1b4b 50%, #0f172a 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    position: relative;
    overflow: hidden;
}

.auth-wrapper::before {
    content: '';
    position: absolute;
    width: 600px;
    height: 600px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(79,70,229,0.15) 0%, transparent 70%);
    top: -200px;
    right: -200px;
    pointer-events: none;
}

.auth-wrapper::after {
    content: '';
    position: absolute;
    width: 400px;
    height: 400px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(79,70,229,0.1) 0%, transparent 70%);
    bottom: -150px;
    left: -150px;
    pointer-events: none;
}

.auth-card {
    width: 100%;
    max-width: 440px;
    background: #ffffff;
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl);
    padding: 2.5rem;
    position: relative;
    z-index: 1;
}

.auth-logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    margin-bottom: 2rem;
    text-decoration: none;
}

.auth-logo-icon {
    width: 44px;
    height: 44px;
    background: var(--primary);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 1.25rem;
}

.auth-logo-text {
    font-size: 1.375rem;
    font-weight: 800;
    color: #0f172a;
    letter-spacing: -0.04em;
}

.auth-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: #0f172a;
    letter-spacing: -0.03em;
    margin-bottom: 0.375rem;
}

.auth-subtitle {
    font-size: 0.875rem;
    color: #64748b;
    margin-bottom: 2rem;
}

.auth-divider {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin: 1.5rem 0;
    color: #94a3b8;
    font-size: 0.8125rem;
}

.auth-divider::before,
.auth-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: #e2e8f0;
}

.auth-footer {
    text-align: center;
    margin-top: 1.5rem;
    font-size: 0.875rem;
    color: #64748b;
}

.auth-footer a { color: var(--primary); font-weight: 600; }
.auth-footer a:hover { color: var(--primary-dark); }

/* -------------------------------------------------------
   Utilities
------------------------------------------------------- */
.text-muted { color: #94a3b8 !important; }
.text-xs    { font-size: 0.75rem; }
.text-sm    { font-size: 0.875rem; }
.fw-medium  { font-weight: 500; }
.fw-semibold { font-weight: 600; }

.rounded-pill-sm { border-radius: 50rem !important; }

.cursor-pointer { cursor: pointer; }

.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: #94a3b8;
}

.empty-state-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.4;
}

/* -------------------------------------------------------
   Responsive - Tablet
------------------------------------------------------- */
@media (max-width: 1024px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.show { transform: translateX(0); }
    .main-content { margin-left: 0; }
    .sidebar-backdrop {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.5);
        z-index: 999;
    }
    .sidebar-backdrop.show { display: block; }
}

/* -------------------------------------------------------
   Responsive - Mobile
------------------------------------------------------- */
@media (max-width: 640px) {
    .auth-card { padding: 1.75rem 1.25rem; }
    .page-content { padding: 1rem; }
    .page-header { flex-direction: column; }
    .card-body { padding: 1.25rem; }
    .topbar { padding: 0 1rem; }
    .stat-card-value { font-size: 1.5rem; }
}

/* -------------------------------------------------------
   Scrollbar Custom
------------------------------------------------------- */
.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 4px; }

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: #f1f5f9; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* -------------------------------------------------------
   Animations
------------------------------------------------------- */
@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(16px); }
    to   { opacity: 1; transform: translateY(0); }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.fade-in-up { animation: fadeInUp 0.35s ease both; }
.fade-in    { animation: fadeIn 0.25s ease both; }

/* Staggered children */
.stagger > *:nth-child(1) { animation-delay: 0.05s; }
.stagger > *:nth-child(2) { animation-delay: 0.10s; }
.stagger > *:nth-child(3) { animation-delay: 0.15s; }
.stagger > *:nth-child(4) { animation-delay: 0.20s; }

/* -------------------------------------------------------
   NProgress bar (loading indicator)
------------------------------------------------------- */
#nprogress .bar {
    background: var(--primary) !important;
    height: 3px !important;
}

#nprogress .peg {
    box-shadow: 0 0 10px var(--primary), 0 0 5px var(--primary) !important;
}

/* -------------------------------------------------------
   Toast Notifications
------------------------------------------------------- */
.toast-container { z-index: 9999; }

.toast {
    border: none;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    font-size: 0.875rem;
    min-width: 300px;
}

/* -------------------------------------------------------
   Permission Checkboxes Grid
------------------------------------------------------- */
.permission-group {
    border: 1px solid #e2e8f0;
    border-radius: var(--radius-md);
    overflow: hidden;
    margin-bottom: 1rem;
}

.permission-group-header {
    background: #f8fafc;
    padding: 0.75rem 1rem;
    font-weight: 600;
    font-size: 0.8125rem;
    color: #374151;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    border-bottom: 1px solid #e2e8f0;
}

.permission-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 0;
}

.permission-check-item {
    padding: 0.625rem 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    border-right: 1px solid #f1f5f9;
    border-bottom: 1px solid #f1f5f9;
    font-size: 0.8125rem;
}

.permission-check-item:hover { background: #f8fafc; }
