/* Kiaalap Dashboard - Main Stylesheet */

/* CSS Variables */
:root {
    --sidebar-width: 260px;
    --header-height: 60px;
    --brand-primary: #266210;
    --brand-primary-dark: #063b00;
    --brand-secondary: #90b800;
    --brand-accent: #e1e100;
    --sidebar-bg: var(--brand-primary-dark, #063b00);
    --sidebar-text: #ffffff;
    --sidebar-text-muted: rgba(255, 255, 255, 0.7);
    --sidebar-border: rgba(255, 255, 255, 0.1);
    --sidebar-active-bg: var(--brand-primary, #266210);
    --sidebar-active-text: #ffffff;
    --body-bg: #f5f7fa;
    --border-color: #e5e7eb;
    --text-muted: #6b7280;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.1);
    --shadow-lg: 0 10px 25px rgba(0,0,0,0.1);
    --transition-speed: 0.3s;
    --border-radius: 8px;
}

/* Base Styles */
body {
    background: var(--body-bg);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

/* ========================================
   SIDEBAR STYLES
======================================== */

.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--sidebar-bg);
    z-index: 1040;
    transition: width var(--transition-speed) ease, transform var(--transition-speed) ease;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar.collapsed {
    width: 70px !important;
}

/* Hide text and submenus when collapsed */
.sidebar.collapsed .sidebar-nav .nav-link span,
.sidebar.collapsed .menu-section-title,
.sidebar.collapsed .submenu {
    display: none !important;
}

.sidebar.collapsed .sidebar-brand h5 {
    justify-content: center !important;
    font-size: 0 !important; /* Hide text */
}

.sidebar.collapsed .sidebar-brand h5 i {
    font-size: 1.5rem !important; /* Restore icon size */
}

.sidebar.collapsed .sidebar-brand span,
.sidebar.collapsed .brand-text {
    display: none !important;
}

/* Center the logo in the header when collapsed */
.sidebar.collapsed .sidebar-header {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.75rem 0.5rem !important;
}

.sidebar.collapsed .sidebar-brand {
    justify-content: center !important;
    flex-grow: 0 !important;
}

.sidebar.collapsed .brand-logo {
    max-width: 36px !important;
    max-height: 36px !important;
    margin-right: 0 !important;
}

.sidebar.collapsed .nav-link {
    justify-content: center !important;
    padding: 0.625rem !important;
}

.sidebar.collapsed .nav-link i {
    margin-right: 0 !important;
    font-size: 1.15rem;
}

/* Hide dropdown arrows when collapsed */
.sidebar.collapsed .nav-link.has-submenu::after {
    display: none !important;
}

/* ── Collapsed sidebar: Bootstrap tooltips appear to the right ─────────── */
/* Make tooltip appear instantly with no flicker lag */
.sidebar.collapsed .sidebar-nav .nav-link[data-bs-toggle="tooltip"] {
    position: relative;
}

.sidebar-header {
    padding: 1rem;
    border-bottom: 1px solid var(--sidebar-border);
}

.sidebar-brand {
    display: flex;
    align-items: center;
    justify-content: space-between;
    color: var(--sidebar-text);
    text-decoration: none;
}

.sidebar-brand h5 {
    margin: 0;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.sidebar-close {
    background: none;
    border: none;
    color: var(--sidebar-text);
    cursor: pointer;
    padding: 0;
    font-size: 1.25rem;
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
}

.sidebar-nav::-webkit-scrollbar {
    width: 6px;
}

.sidebar-nav::-webkit-scrollbar-track {
    background: rgba(255,255,255,0.05);
}

.sidebar-nav::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.2);
    border-radius: 3px;
}

.sidebar-nav .nav-link {
    color: var(--sidebar-text-muted);
    padding: 0.625rem 0.75rem;
    border-radius: var(--border-radius);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.25rem;
    transition: all 0.2s ease;
    position: relative;
}

.sidebar-nav .nav-link:hover {
    background: rgba(255,255,255,0.08);
    color: var(--sidebar-text);
}

.sidebar-nav .nav-link.active {
    background: var(--sidebar-active-bg);
    color: var(--sidebar-active-text);
}

/* Submenu Toggle Arrow */
.sidebar-nav .nav-link.has-submenu::after {
    content: '\F282';
    font-family: 'bootstrap-icons';
    position: absolute;
    right: 1rem;
    transition: transform 0.3s ease;
    font-size: 0.75rem;
    transform: rotate(-90deg);
}

.sidebar-nav .nav-link.has-submenu[aria-expanded="true"]::after {
    transform: rotate(0);
}

/* Submenu Styles */
.submenu {
    padding-left: 0;
    margin-top: 0.25rem;
}

.submenu.collapsing {
    transition: height 0.3s ease;
}

.submenu .nav-link {
    padding-left: 3rem;
    font-size: 0.875rem;
    color: var(--sidebar-text-muted);
}

.submenu .nav-link:hover {
    color: var(--sidebar-text);
    background: rgba(255,255,255,0.05);
}

.submenu .nav-link.active {
    color: var(--sidebar-active-text);
    background: rgba(255,255,255,0.15);
}

.submenu .nav-link::before {
    content: '';
    position: absolute;
    left: 2rem;
    top: 50%;
    transform: translateY(-50%);
    width: 4px;
    height: 4px;
    background: rgba(255,255,255,0.3);
    border-radius: 50%;
}

.menu-section {
    margin-bottom: 1.5rem;
}

.menu-section-title {
    color: rgba(255,255,255,0.4);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 0 0.75rem;
    margin-bottom: 0.5rem;
}

/* Sidebar Overlay */
.sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 1039;
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--transition-speed) ease;
}

.sidebar-overlay.active {
    opacity: 1;
    visibility: visible;
}

/* ========================================
   MAIN WRAPPER
======================================== */

.main-wrapper {
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    transition: margin-left var(--transition-speed) ease;
    display: flex;
    flex-direction: column;
}

.main-wrapper.full-width {
    margin-left: 70px;
}

@media (max-width: 768px) {
    .main-wrapper.full-width {
        margin-left: 0;
    }
}

/* ========================================
   HEADER STYLES
======================================== */

.top-navbar {
    background: white;
    border-bottom: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    height: var(--header-height);
    padding: 0 1rem;
    display: flex;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 1030;
}

.hamburger-menu {
    background: none;
    border: none;
    font-size: 1.25rem;
    color: #495057;
    cursor: pointer;
    padding: 0.375rem 0.625rem;
    border-radius: 6px;
    margin-right: 1rem;
}

.hamburger-menu:hover {
    background: #f8f9fa;
}

/* ========================================
   SEARCH STYLES
======================================== */

.search-container {
    position: relative;
}

.search-form {
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 0;
    overflow: hidden;
    transition: width var(--transition-speed) ease;
    display: flex;
    align-items: center;
}

.search-form.active {
    width: 300px;
}

.search-form input {
    width: 100%;
    border-radius: var(--border-radius);
    border: 1px solid var(--border-color);
    padding: 0.375rem 2.25rem;
    height: 36px;
    opacity: 0;
    transition: opacity var(--transition-speed) ease;
}

.search-form.active input {
    opacity: 1;
}

.search-icon {
    position: absolute;
    left: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: 0.875rem;
}

.close-search {
    position: absolute;
    right: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.875rem;
    opacity: 0;
    transition: opacity var(--transition-speed) ease;
}

.search-form.active .close-search {
    opacity: 1;
}

.search-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.3);
    backdrop-filter: blur(2px);
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--transition-speed) ease;
    z-index: 999;
}

.search-backdrop.active {
    opacity: 1;
    visibility: visible;
}

/* ========================================
   BUTTON STYLES
======================================== */

.btn-icon {
    padding: 0.375rem 0.625rem;
    font-size: 1.125rem;
    border-radius: 6px;
}

/* ========================================
   USER & AVATAR STYLES
======================================== */

.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
}

/* ========================================
   NOTIFICATION STYLES
======================================== */

.notification-dot {
    width: 6px;
    height: 6px;
    background: #ef4444;
    border-radius: 50%;
    position: absolute;
    top: 6px;
    right: 6px;
    border: 2px solid white;
}

.notification-item {
    display: flex;
    gap: 0.625rem;
    padding: 0.625rem;
    border-radius: 8px;
    transition: background 0.2s ease;
    text-decoration: none;
    color: inherit;
}

.notification-item:hover {
    background: #f8f9fa;
}

.notification-icon {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    display: grid;
    place-items: center;
    flex-shrink: 0;
    font-size: 0.875rem;
}

/* ========================================
   DROPDOWN STYLES
======================================== */

.dropdown-menu {
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border-color);
    padding: 0.5rem;
    min-width: 280px;
}

.dropdown-item {
    border-radius: 8px;
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
}

.dropdown-item:hover {
    background: #f3f4f6;
}

/* ========================================
   MOBILE RESPONSIVE
======================================== */

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.active {
        transform: translateX(0);
    }

    .main-wrapper {
        margin-left: 0;
    }

    .search-form.active {
        width: 200px;
    }

    .hide-mobile {
        display: none !important;
    }

    .sidebar-close {
        display: block !important;
    }
}

@media (min-width: 769px) {
    .sidebar-close {
        display: none;
    }

    /* Desktop-only collapsed sidebar behavior */
    .sidebar.collapsed {
        width: 70px;
    }

    .main-wrapper.full-width {
        margin-left: 70px;
    }
}

/* ========================================
   DASHBOARD LAYOUT & COMPONENTS
======================================== */

/* Dashboard Content Area */
.dashboard-content {
    padding: 24px;
    flex: 1; /* Grow to fill available space */
}

/* Section Spacing */
.dashboard-row {
    margin-bottom: 24px;
}

/* Dashboard Cards */
.dashboard-card {
    background: white;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.06);
    transition: box-shadow 0.3s ease;
}

/* Direct content in dashboard-card without body wrapper */
.dashboard-card > *:not(.dashboard-card-header):not(.dashboard-card-body) {
    padding: 1.25rem;
}

.dashboard-card:hover {
    box-shadow: 0 4px 6px rgba(0,0,0,0.12), 0 2px 4px rgba(0,0,0,0.06);
}

.dashboard-card-header {
    padding: 1.25rem 1.25rem 1rem;
    border-bottom: 1px solid #e5e7eb;
}

.dashboard-card-body {
    padding: 1.25rem;
}

.dashboard-card-title {
    font-size: 16px;
    font-weight: 600;
    color: #1f2937;
    margin: 0;
}

/* Stats Cards */
.stats-card {
    background: white;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.12);
    padding: 20px;
}

.stats-card-label {
    font-size: 12px;
    color: #6b7280;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 8px;
}

.stats-card-value {
    font-size: 28px;
    font-weight: 700;
    color: #1f2937;
    margin-bottom: 8px;
}

.stats-card-change {
    font-size: 12px;
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 12px;
}

.stats-card-change.positive {
    background: #d1fae5;
    color: #065f46;
}

.stats-card-change.negative {
    background: #fee2e2;
    color: #991b1b;
}

/* Progress Bars */
.progress-custom {
    height: 6px;
    background: #e5e7eb;
    border-radius: 3px;
    overflow: hidden;
    margin-top: 8px;
}

.progress-bar-custom {
    height: 100%;
    transition: width 0.6s ease;
}

/* Chart Containers */
.chart-wrapper {
    position: relative;
    background: white;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.12);
    padding: 20px;
}

.chart-container-main {
    position: relative;
    height: 350px;
    width: 100%;
}

.chart-container-small {
    position: relative;
    height: 60px;
    width: 100%;
}

/* Social Cards */
.social-stats-card {
    background: white;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.12);
    padding: 20px;
    display: flex;
    align-items: center;
}

.social-icon-box {
    width: 48px;
    height: 48px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    margin-right: 16px;
}

.social-icon-box.facebook {
    background: rgba(24, 119, 242, 0.1);
    color: #1877f2;
}

.social-icon-box.twitter,
.social-icon-box.x {
    background: rgba(0, 0, 0, 0.1);
    color: #000000;
}

.social-icon-box.linkedin {
    background: rgba(0, 119, 181, 0.1);
    color: #0077b5;
}

.social-icon-box.youtube {
    background: rgba(255, 0, 0, 0.1);
    color: #ff0000;
}

/* Table Styles */
.simple-table {
    width: 100%;
}

.simple-table-row {
    padding: 12px 0;
    border-bottom: 1px solid #e5e7eb;
}

.simple-table-row:last-child {
    border-bottom: none;
}

/* Responsive Grid System */
.dashboard-grid {
    display: grid;
    gap: 20px;  /* Consistent spacing both vertical and horizontal */
}

.grid-cols-1 {
    grid-template-columns: repeat(1, 1fr);
}

.grid-cols-2 {
    grid-template-columns: repeat(2, 1fr);
}

.grid-cols-3 {
    grid-template-columns: repeat(3, 1fr);
}

.grid-cols-4 {
    grid-template-columns: repeat(4, 1fr);
}

@media (max-width: 1024px) {
    .grid-cols-4 {
        grid-template-columns: repeat(2, 1fr);
    }

    .grid-cols-3 {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {
    .dashboard-content {
        padding: 16px;
    }

    .dashboard-row {
        margin-bottom: 16px;
    }

    .grid-cols-4,
    .grid-cols-3,
    .grid-cols-2 {
        grid-template-columns: repeat(1, 1fr);
    }

    .stats-card {
        padding: 16px;
    }

    .stats-card-value {
        font-size: 24px;
    }
}

/* Remove Bootstrap Conflicts - but allow gutters to work */
.row {
    margin: 0;
}

/* Removed column padding override to allow Bootstrap gutters to work */

.card-body {
    padding: 0;
}

.card {
    border: none;
    margin-bottom: 0;
}

/* Footer */
.dashboard-footer {
    background: white;
    border-top: 1px solid #e5e7eb;
    padding: 20px 0;
    margin-top: auto;
    font-size: 14px;
    color: #6b7280;
}

/* ========================================
   UTILITY CLASSES
======================================== */

.hide-mobile {
    display: none;
}

@media (min-width: 769px) {
    .hide-mobile {
        display: initial;
    }
}

/* Margin Utilities */
.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.mb-3 { margin-bottom: 24px; }

/* Text Color Utilities */
.text-muted { color: #6b7280; }
.text-success { color: #10b981; }
.text-danger { color: #ef4444; }
.text-info { color: #3b82f6; }
.text-warning { color: #f59e0b; }

/* Text Size Utilities */
.text-sm { font-size: 14px; }
.text-xs { font-size: 12px; }

/* Font Weight Utilities */
.font-medium { font-weight: 500; }
.font-semibold { font-weight: 600; }
.font-bold { font-weight: 700; }

/* Flexbox Utilities */
.d-flex { display: flex; }
.align-items-center { align-items: center; }
.justify-content-between { justify-content: space-between; }

/* ========================================
   GLOBAL PRELOADER & TOAST STYLES
======================================== */

.page-loader-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(4px);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
}

.page-loader-content {
    background: white;
    padding: 30px 40px;
    border-radius: 16px;
    box-shadow: 0 20px 40px rgba(15, 23, 42, 0.15);
    border: 1px solid rgba(0, 0, 0, 0.05);
}

.section-loader-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.75);
    backdrop-filter: blur(2px);
    z-index: 100;
    border-radius: inherit;
}

.toast {
    min-width: 300px;
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15) !important;
}

.toast-header {
    padding: 0.625rem 1rem;
}

.toast-body {
    font-size: 0.9rem;
    line-height: 1.4;
}

/* =============================================================================
   GLOBAL PRINT STYLES — Document Isolation
   Hides the entire Kiaalap dashboard chrome when printing.
   Only .doc-print-target is shown on the printed page.
   ============================================================================= */
@media print {

    /* 1. Kill the entire layout chrome ─────────────────────────────────── */
    .sidebar-wrapper,
    .header-top-area,
    .breadcrumb-area,
    .main-header,
    nav,
    .navbar,
    .topbar,
    .dashboard-header,
    .d-print-none,
    .no-print,
    .btn-group,
    .btn:not(.d-print-block),
    .action-bar,
    .doc-actions,
    .alert,
    .pagination,
    .page-item,
    .tab-content > .tab-pane:not(.active),
    .nav-tabs,
    .dropdown-menu,
    [class*="toast"],
    [class*="modal"],
    .floating-btn,
    .fixed-bottom,
    .fixed-top { display: none !important; }

    /* 2. Reset all layout wrappers ────────────────────────────────────── */
    html, body,
    .main-wrapper,
    .dashboard-content,
    .all-content-wrapper,
    .container-fluid,
    .container {
        margin: 0 !important;
        padding: 0 !important;
        background: #ffffff !important;
        color: #000000 !important;
        width: 100% !important;
        max-width: 100% !important;
        min-height: auto !important;
        float: none !important;
        overflow: visible !important;
    }

    /* 3. Make the document the only visible element ───────────────────── */
    .doc-print-target {
        display: block !important;
        visibility: visible !important;
        position: static !important;
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
        box-shadow: none !important;
        border: none !important;
        border-radius: 0 !important;
        background: #ffffff !important;
    }

    /* 4. All elements inside doc-print-target are fully visible ────────── */
    .doc-print-target * {
        visibility: visible !important;
        -webkit-print-color-adjust: exact !important;
        color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    /* 5. A4 page setup ───────────────────────────────────────────────── */
    @page {
        size: A4 portrait;
        margin: 14mm 15mm 20mm 15mm;
    }

    /* 6. Table page-break rules ──────────────────────────────────────── */
    table  { page-break-inside: auto !important; }
    tr     { page-break-inside: avoid !important; }
    thead  { display: table-header-group !important; }
    tfoot  { display: table-footer-group !important; }

    /* 7. Avoid orphaned headings and section titles ─────────────────── */
    h1, h2, h3, h4, h5, h6                     { page-break-after: avoid !important; }
    .section-header, .card-header,
    .doc-section-header, .section-title         { page-break-after: avoid !important; }

    /* 8. Images print correctly ─────────────────────────────────────── */
    img {
        max-width: 100% !important;
        page-break-inside: avoid !important;
    }

    /* 9. Remove link underlines ─────────────────────────────────────── */
    a { text-decoration: none !important; color: inherit !important; }

    /* 10. Preserve badge, divider and header colours in browser print ── */
    .doc-header-divider-primary,
    .badge-success, .badge-primary, .badge-warning, .badge-danger,
    .badge-pill, .badge,
    .doc-title-badge,
    th { -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; }
}
