/**
 * MagStack 2.0 Unified SaaS Design System
 * Enterprise Cloud Hosting & E-Commerce Platform
 * Benchmarks: Cloudflare, DigitalOcean, Vercel, Stripe
 */

:root {
    /* Brand Foundation */
    --mag-primary:          #6366f1; /* Modern Indigo */
    --mag-primary-hover:    #4f46e5;
    --mag-primary-dark:     #4338ca;
    --mag-primary-light:    #e0e7ff;
    --mag-primary-subtle:   #f5f3ff;

    --mag-accent:           #7c3aed; /* Electric Purple */
    --mag-accent-hover:     #6d28d9;

    /* Neutral Scale (Slate) */
    --mag-bg:               #f8fafc; /* Page Background */
    --mag-surface:          #ffffff; /* Card Background */
    --mag-surface-subtle:   #f1f5f9; /* Table Headers / Inner Well */
    --mag-border:           #e2e8f0; /* Default Borders */
    --mag-border-hover:     #cbd5e1;
    --mag-text-main:        #0f172a; /* Slate 900 */
    --mag-text-heading:     #1e293b; /* Slate 800 */
    --mag-text-body:        #334155; /* Slate 700 */
    --mag-text-muted:       #475569; /* Slate 600 - High Contrast AA */
    --mag-text-subtle:      #64748b; /* Slate 500 */
    --mag-text-disabled:    #94a3b8; /* Slate 400 */

    /* Semantic Status Scale */
    --mag-success-bg:       #ecfdf5;
    --mag-success-border:   #a7f3d0;
    --mag-success-text:     #065f46;
    --mag-success:          #10b981;

    --mag-warning-bg:       #fffbeb;
    --mag-warning-border:   #fde68a;
    --mag-warning-text:     #92400e;
    --mag-warning:          #f59e0b;

    --mag-danger-bg:        #fef2f2;
    --mag-danger-border:    #fecaca;
    --mag-danger-text:      #991b1b;
    --mag-danger:           #ef4444;

    --mag-info-bg:          #eff6ff;
    --mag-info-border:      #bfdbfe;
    --mag-info-text:        #1e40af;
    --mag-info:             #3b82f6;

    /* Elevations & Shadows */
    --mag-shadow-xs:        0 1px 2px 0 rgba(15, 23, 42, 0.05);
    --mag-shadow-sm:        0 1px 3px 0 rgba(15, 23, 42, 0.08), 0 1px 2px -1px rgba(15, 23, 42, 0.08);
    --mag-shadow-md:        0 4px 6px -1px rgba(15, 23, 42, 0.08), 0 2px 4px -2px rgba(15, 23, 42, 0.06);
    --mag-shadow-lg:        0 10px 15px -3px rgba(15, 23, 42, 0.08), 0 4px 6px -4px rgba(15, 23, 42, 0.04);
    --mag-shadow-xl:        0 20px 25px -5px rgba(15, 23, 42, 0.1), 0 8px 10px -6px rgba(15, 23, 42, 0.04);

    /* Radii */
    --mag-radius-sm:        6px;
    --mag-radius-md:        8px;
    --mag-radius-lg:        12px;
    --mag-radius-xl:        16px;
    --mag-radius-full:      9999px;

    /* Transitions */
    --mag-transition:       all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Global Font & Antialiasing */
body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif !important;
    background-color: var(--mag-bg) !important;
    color: var(--mag-text-body) !important;
    font-size: 14px !important;
    line-height: 1.5 !important;
    -webkit-font-smoothing: antialiased;
}

/* Accessible Focus States */
:focus-visible {
    outline: 2px solid var(--mag-primary) !important;
    outline-offset: 2px !important;
}

/* -------------------------------------------------------------
 * Top Master Header Bar
 * ------------------------------------------------------------- */
.mag-header {
    height: 64px;
    background: #ffffff;
    border-bottom: 1px solid var(--mag-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    position: sticky;
    top: 0;
    z-index: 1000;
    box-shadow: var(--mag-shadow-xs);
}

.mag-header-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.mag-hamburger-btn {
    display: none;
    background: transparent;
    border: 1px solid var(--mag-border);
    border-radius: var(--mag-radius-md);
    padding: 6px;
    color: var(--mag-text-heading);
    cursor: pointer;
    line-height: 1;
}
.mag-hamburger-btn:hover {
    background: var(--mag-surface-subtle);
}

.mag-breadcrumbs {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    font-weight: 500;
    color: var(--mag-text-muted);
}
.mag-breadcrumbs a {
    color: var(--mag-text-muted);
    text-decoration: none;
    transition: var(--mag-transition);
}
.mag-breadcrumbs a:hover {
    color: var(--mag-primary);
}
.mag-breadcrumbs .separator {
    color: var(--mag-text-disabled);
}
.mag-breadcrumbs .current {
    color: var(--mag-text-heading);
    font-weight: 600;
}

.mag-header-center {
    flex: 1;
    max-width: 440px;
    margin: 0 24px;
}

.mag-search-wrap {
    position: relative;
    width: 100%;
}
.mag-search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--mag-text-subtle);
    pointer-events: none;
}
.mag-search-input {
    width: 100%;
    height: 38px;
    padding: 0 44px 0 36px;
    background: var(--mag-surface-subtle);
    border: 1px solid transparent;
    border-radius: var(--mag-radius-md);
    font-size: 13px;
    color: var(--mag-text-heading);
    transition: var(--mag-transition);
}
.mag-search-input:focus {
    background: #ffffff;
    border-color: var(--mag-primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
    outline: none;
}
.mag-search-kbd {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 11px;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 4px;
    background: #ffffff;
    border: 1px solid var(--mag-border);
    color: var(--mag-text-subtle);
    pointer-events: none;
}

.mag-header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.mag-btn-quick-create {
    background: var(--mag-primary);
    color: #ffffff !important;
    padding: 7px 14px;
    border-radius: var(--mag-radius-md);
    font-size: 13px;
    font-weight: 600;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    box-shadow: var(--mag-shadow-xs);
    transition: var(--mag-transition);
}
.mag-btn-quick-create:hover {
    background: var(--mag-primary-hover);
    color: #ffffff !important;
    transform: translateY(-1px);
    box-shadow: var(--mag-shadow-sm);
}

.mag-notif-btn {
    position: relative;
    background: transparent;
    border: 1px solid var(--mag-border);
    border-radius: var(--mag-radius-md);
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--mag-text-body);
    cursor: pointer;
    transition: var(--mag-transition);
}
.mag-notif-btn:hover {
    background: var(--mag-surface-subtle);
    color: var(--mag-text-heading);
}
.mag-notif-dot {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 8px;
    height: 8px;
    background: var(--mag-danger);
    border-radius: 50%;
    border: 2px solid #ffffff;
}

/* User Menu in Header */
.mag-user-menu {
    position: relative;
}
.mag-user-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    background: transparent;
    border: 1px solid var(--mag-border);
    border-radius: var(--mag-radius-full);
    padding: 3px 12px 3px 3px;
    cursor: pointer;
    transition: var(--mag-transition);
}
.mag-user-btn:hover {
    background: var(--mag-surface-subtle);
    border-color: var(--mag-border-hover);
}
.mag-user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--mag-primary);
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 13px;
    overflow: hidden;
}
.mag-user-info {
    text-align: left;
    line-height: 1.2;
}
.mag-user-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--mag-text-heading);
    max-width: 120px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.mag-user-role {
    font-size: 11px;
    color: var(--mag-text-muted);
}

.mag-dropdown-menu {
    position: absolute;
    right: 0;
    top: calc(100% + 8px);
    width: 220px;
    background: #ffffff;
    border: 1px solid var(--mag-border);
    border-radius: var(--mag-radius-lg);
    box-shadow: var(--mag-shadow-lg);
    padding: 6px;
    display: none;
    z-index: 1050;
    animation: magFadeDown 0.15s ease-out;
}
.mag-dropdown-menu.show {
    display: block;
}
.mag-dropdown-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    font-size: 13px;
    font-weight: 500;
    color: var(--mag-text-body);
    text-decoration: none;
    border-radius: var(--mag-radius-md);
    transition: var(--mag-transition);
}
.mag-dropdown-item:hover {
    background: var(--mag-surface-subtle);
    color: var(--mag-primary);
}
.mag-dropdown-divider {
    height: 1px;
    background: var(--mag-border);
    margin: 6px 0;
}
.mag-dropdown-item.danger {
    color: var(--mag-danger);
}
.mag-dropdown-item.danger:hover {
    background: var(--mag-danger-bg);
}

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

/* -------------------------------------------------------------
 * SaaS Card Components & Layout
 * ------------------------------------------------------------- */
.mag-card {
    background: var(--mag-surface);
    border: 1px solid var(--mag-border);
    border-radius: var(--mag-radius-lg);
    padding: 24px;
    margin-bottom: 24px;
    box-shadow: var(--mag-shadow-xs);
    transition: var(--mag-transition);
}
.mag-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 18px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--mag-surface-subtle);
}
.mag-card-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--mag-text-heading);
    margin: 0;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* KPI Overview Grid */
.mag-kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 20px;
    margin-bottom: 24px;
}
.mag-kpi-card {
    background: var(--mag-surface);
    border: 1px solid var(--mag-border);
    border-radius: var(--mag-radius-lg);
    padding: 20px;
    box-shadow: var(--mag-shadow-xs);
    transition: var(--mag-transition);
}
.mag-kpi-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--mag-shadow-md);
    border-color: var(--mag-primary-light);
}
.mag-kpi-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}
.mag-kpi-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--mag-text-muted);
}
.mag-kpi-icon {
    width: 36px;
    height: 36px;
    border-radius: var(--mag-radius-md);
    background: var(--mag-primary-subtle);
    color: var(--mag-primary);
    display: flex;
    align-items: center;
    justify-content: center;
}
.mag-kpi-val {
    font-size: 24px;
    font-weight: 800;
    color: var(--mag-text-heading);
    line-height: 1.2;
    margin-bottom: 4px;
}
.mag-kpi-sub {
    font-size: 12px;
    color: var(--mag-text-muted);
}

/* Status Badges */
.mag-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 9px;
    border-radius: var(--mag-radius-full);
    font-size: 12px;
    font-weight: 600;
    line-height: 1;
}
.mag-badge-success {
    background: var(--mag-success-bg);
    border: 1px solid var(--mag-success-border);
    color: var(--mag-success-text);
}
.mag-badge-warning {
    background: var(--mag-warning-bg);
    border: 1px solid var(--mag-warning-border);
    color: var(--mag-warning-text);
}
.mag-badge-danger {
    background: var(--mag-danger-bg);
    border: 1px solid var(--mag-danger-border);
    color: var(--mag-danger-text);
}
.mag-badge-info {
    background: var(--mag-info-bg);
    border: 1px solid var(--mag-info-border);
    color: var(--mag-info-text);
}
.mag-badge-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
}

/* -------------------------------------------------------------
 * DataTables & Modern Table Styling
 * ------------------------------------------------------------- */
.table-responsive {
    border-radius: var(--mag-radius-lg);
    border: 1px solid var(--mag-border);
    background: #ffffff;
    box-shadow: var(--mag-shadow-xs);
    overflow-x: auto;
}
table.dataTable, table.table {
    width: 100% !important;
    margin-bottom: 0 !important;
    border-collapse: separate !important;
    border-spacing: 0 !important;
}
table.dataTable thead th, table.table thead th {
    background: var(--mag-surface-subtle) !important;
    color: var(--mag-text-muted) !important;
    font-size: 11px !important;
    font-weight: 700 !important;
    text-transform: uppercase !important;
    letter-spacing: 0.05em !important;
    padding: 12px 16px !important;
    border-bottom: 1px solid var(--mag-border) !important;
    border-top: none !important;
    white-space: nowrap;
}
table.dataTable tbody td, table.table tbody td {
    padding: 14px 16px !important;
    vertical-align: middle !important;
    border-top: 1px solid var(--mag-surface-subtle) !important;
    color: var(--mag-text-body) !important;
    font-size: 13px !important;
}
table.dataTable tbody tr:hover, table.table tbody tr:hover {
    background-color: #fafbfc !important;
}

/* DataTables Controls Integration */
.dataTables_wrapper .dataTables_length,
.dataTables_wrapper .dataTables_filter {
    padding: 14px 16px;
    font-size: 13px;
    color: var(--mag-text-muted);
}
.dataTables_wrapper .dataTables_filter input {
    border: 1px solid var(--mag-border);
    border-radius: var(--mag-radius-md);
    padding: 6px 12px;
    margin-left: 8px;
    outline: none;
    transition: var(--mag-transition);
}
.dataTables_wrapper .dataTables_filter input:focus {
    border-color: var(--mag-primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}
.dataTables_wrapper .dataTables_info,
.dataTables_wrapper .dataTables_paginate {
    padding: 14px 16px;
    font-size: 13px;
}
.dataTables_wrapper .paginate_button.current,
.dataTables_wrapper .paginate_button.current:hover {
    background: var(--mag-primary) !important;
    color: #ffffff !important;
    border-color: var(--mag-primary) !important;
    border-radius: var(--mag-radius-md);
}

/* -------------------------------------------------------------
 * Buttons & Form Controls
 * ------------------------------------------------------------- */
.btn-primary, .action.primary {
    background-color: var(--mag-primary) !important;
    border-color: var(--mag-primary) !important;
    color: #ffffff !important;
    font-weight: 600 !important;
    border-radius: var(--mag-radius-md) !important;
    padding: 9px 18px !important;
    transition: var(--mag-transition) !important;
}
.btn-primary:hover, .action.primary:hover {
    background-color: var(--mag-primary-hover) !important;
    border-color: var(--mag-primary-hover) !important;
    transform: translateY(-1px);
    box-shadow: var(--mag-shadow-sm);
}

.btn-secondary {
    background-color: #ffffff !important;
    border: 1px solid var(--mag-border) !important;
    color: var(--mag-text-heading) !important;
    font-weight: 600 !important;
    border-radius: var(--mag-radius-md) !important;
    padding: 8px 16px !important;
    transition: var(--mag-transition) !important;
}
.btn-secondary:hover {
    background-color: var(--mag-surface-subtle) !important;
    border-color: var(--mag-border-hover) !important;
}

.btn-danger {
    background-color: var(--mag-danger) !important;
    border-color: var(--mag-danger) !important;
    color: #ffffff !important;
    font-weight: 600 !important;
    border-radius: var(--mag-radius-md) !important;
}
.btn-danger:hover {
    background-color: var(--mag-danger-text) !important;
    border-color: var(--mag-danger-text) !important;
}

/* Empty States */
.mag-empty-state {
    text-align: center;
    padding: 48px 24px;
    background: #ffffff;
    border: 2px dashed var(--mag-border);
    border-radius: var(--mag-radius-xl);
    margin: 20px 0;
}
.mag-empty-icon {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: var(--mag-primary-subtle);
    color: var(--mag-primary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 16px;
}
.mag-empty-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--mag-text-heading);
    margin-bottom: 6px;
}
.mag-empty-desc {
    color: var(--mag-text-muted);
    font-size: 14px;
    max-width: 440px;
    margin: 0 auto 20px;
}

/* -------------------------------------------------------------
 * Responsive Off-Canvas Navigation (< 1024px)
 * ------------------------------------------------------------- */
@media (max-width: 1023px) {
    .mag-hamburger-btn {
        display: inline-flex;
    }
    
    .mag-header-center {
        display: none;
    }

    .dashboard-left-part {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        width: 280px !important;
        min-width: 280px !important;
        height: 100vh !important;
        z-index: 1060 !important;
        transform: translateX(-100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        box-shadow: var(--mag-shadow-xl);
    }
    .dashboard-left-part.sidebar-open {
        transform: translateX(0);
    }

    .sidebar-backdrop {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(15, 23, 42, 0.55);
        backdrop-filter: blur(4px);
        z-index: 1050;
    }
    .sidebar-backdrop.active {
        display: block;
    }

    .dashboard-right-part {
        margin-left: 0 !important;
        width: 100% !important;
        padding: 0 !important;
    }
    
    .main_div {
        padding: 16px !important;
    }
}
