/* =================================================================
   SahlDesk Admin Styles — Reports Dashboard (sd-*) + Legacy (ts-*)
   ================================================================= */

/* ---- FONTS ---- */
@import url('https://fonts.googleapis.com/css2?family=Cairo:wght@400;600;700;800&family=Inter:wght@400;500;600;700;800&display=swap');

/* ---- WRAPPER ---- */
.sahl-dashboard-wrapper {
    font-family: 'Inter', sans-serif;
    color: #1e293b;
    max-width: 1400px;
    padding: 0 4px 40px;
    box-sizing: border-box;
}
.sahl-dashboard-wrapper.rtl {
    direction: rtl;
    font-family: 'Cairo', sans-serif;
}

/* ---- LOADING OVERLAY ---- */
.sd-loading-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(255, 255, 255, 0.75);
    z-index: 9999;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(2px);
}
.sahl-dashboard-wrapper.loading .sd-loading-overlay {
    display: flex;
}
.sd-spinner {
    width: 44px;
    height: 44px;
    border: 4px solid #e2e8f0;
    border-top-color: #2563eb;
    border-radius: 50%;
    animation: sd-spin 0.75s linear infinite;
}
@keyframes sd-spin { to { transform: rotate(360deg); } }

/* ---- HEADER ---- */
.sd-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 16px;
    padding: 24px 0 20px;
    border-bottom: 1px solid #e2e8f0;
    margin-bottom: 28px;
}
.sd-title-area {
    display: flex;
    align-items: center;
    gap: 14px;
}
.sd-title-icon {
    width: 44px;
    height: 44px;
    background: linear-gradient(135deg, #2563eb, #1d4ed8);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
}
.sd-title-icon svg {
    width: 22px;
    height: 22px;
    stroke: #fff;
}
.sd-title-text h2 {
    margin: 0 0 2px;
    font-size: 22px;
    font-weight: 800;
    color: #0f172a;
    line-height: 1.2;
}
.sd-title-text p {
    margin: 0;
    font-size: 13px;
    color: #64748b;
}

/* ---- FILTER BUTTONS ---- */
.sd-filter-group {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}
.sd-filter-btn {
    padding: 7px 16px;
    background: #f1f5f9;
    border: 1.5px solid #e2e8f0;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    color: #475569;
    cursor: pointer;
    transition: all 0.18s ease;
    font-family: inherit;
}
.sd-filter-btn:hover {
    background: #e2e8f0;
    color: #1e293b;
}
.sd-filter-btn.active {
    background: #2563eb;
    border-color: #2563eb;
    color: #fff;
    box-shadow: 0 2px 8px rgba(37, 99, 235, 0.25);
}

/* ---- KPI GRID ---- */
.sd-kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
    margin-bottom: 28px;
}

/* ---- KPI CARDS ---- */
.sd-kpi-card {
    background: #fff;
    border-radius: 14px;
    padding: 20px 22px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border: 1px solid #e2e8f0;
    box-shadow: 0 2px 8px rgba(0,0,0,0.04);
    transition: transform 0.18s ease, box-shadow 0.18s ease;
    position: relative;
    overflow: hidden;
}
.sd-kpi-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0,0,0,0.08);
}
.sd-kpi-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 3px;
    border-radius: 14px 14px 0 0;
}
.sd-kpi-total::before  { background: linear-gradient(90deg, #2563eb, #7c3aed); }
.sd-kpi-open::before   { background: linear-gradient(90deg, #f59e0b, #ef4444); }
.sd-kpi-progress::before { background: linear-gradient(90deg, #06b6d4, #3b82f6); }
.sd-kpi-pending::before  { background: linear-gradient(90deg, #f97316, #fbbf24); }
.sd-kpi-closed::before   { background: linear-gradient(90deg, #10b981, #059669); }
.sd-kpi-avg::before      { background: linear-gradient(90deg, #8b5cf6, #6366f1); }

.sd-kpi-content {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.sd-kpi-label {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: #94a3b8;
}
.sd-kpi-value {
    font-size: 32px;
    font-weight: 800;
    color: #0f172a;
    line-height: 1.1;
}
.sd-kpi-icon {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    background: #f1f5f9;
}
.sd-kpi-icon svg { width: 22px; height: 22px; stroke: #64748b; }
.sd-kpi-total  .sd-kpi-icon { background: rgba(37, 99, 235, 0.1);  } .sd-kpi-total  .sd-kpi-icon svg { stroke: #2563eb; }
.sd-kpi-open   .sd-kpi-icon { background: rgba(245, 158, 11, 0.1); } .sd-kpi-open   .sd-kpi-icon svg { stroke: #d97706; }
.sd-kpi-progress .sd-kpi-icon { background: rgba(6, 182, 212, 0.1); } .sd-kpi-progress .sd-kpi-icon svg { stroke: #0891b2; }
.sd-kpi-pending .sd-kpi-icon { background: rgba(249, 115, 22, 0.1); } .sd-kpi-pending .sd-kpi-icon svg { stroke: #ea580c; }
.sd-kpi-closed .sd-kpi-icon { background: rgba(16, 185, 129, 0.1); } .sd-kpi-closed .sd-kpi-icon svg { stroke: #059669; }
.sd-kpi-avg    .sd-kpi-icon { background: rgba(139, 92, 246, 0.1);  } .sd-kpi-avg    .sd-kpi-icon svg { stroke: #7c3aed; }

/* ---- EMPTY STATE ---- */
.sd-empty-state {
    text-align: center;
    padding: 60px 20px;
    background: #fff;
    border-radius: 16px;
    border: 1px solid #e2e8f0;
    margin-bottom: 24px;
}
.sd-empty-icon { color: #cbd5e1; margin-bottom: 16px; }
.sd-empty-state h4 { margin: 0 0 8px; font-size: 18px; font-weight: 700; color: #1e293b; }
.sd-empty-state p  { margin: 0; font-size: 14px; color: #64748b; max-width: 400px; margin: 0 auto; }

/* ---- CHARTS WRAPPER ---- */
.sd-charts-wrapper { }

/* ---- CHARTS GRID (2-column layout) ---- */
.sd-charts-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 20px;
    align-items: start;
}

/* ---- WIDGET CARDS ---- */
.sd-widget {
    background: #fff;
    border-radius: 14px;
    border: 1px solid #e2e8f0;
    box-shadow: 0 2px 8px rgba(0,0,0,0.04);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}
.sd-widget h3 {
    margin: 0;
    padding: 18px 22px 14px;
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: #475569;
    border-bottom: 1px solid #f1f5f9;
}
.sd-widget-content {
    padding: 20px 22px;
    flex: 1;
}

/* ---- CANVAS CONTAINER ---- */
.sd-canvas-container {
    position: relative;
    height: 280px;
    width: 100%;
}
.sd-canvas-container canvas {
    width: 100% !important;
    height: 100% !important;
}

/* ---- WIDGET STACK (for vertically stacked widgets) ---- */
.sd-widget-stack {
    display: flex;
    flex-direction: column;
    gap: 0;
}
.sd-widget-stack .sd-widget {
    flex: 1;
}
.sd-widget-stack .sd-widget:first-child {
    margin-bottom: 20px;
}

/* ---- PRIORITY LIST ---- */
.sd-priority-list {
    display: flex;
    flex-direction: column;
    gap: 14px;
}
.sd-priority-item {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.sd-priority-info {
    display: flex;
    align-items: center;
    gap: 8px;
    justify-content: space-between;
}
.sd-priority-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}
.sd-dot-high   { background: #ef4444; }
.sd-dot-medium { background: #f59e0b; }
.sd-dot-low    { background: #22c55e; }
.sd-priority-name { font-size: 13px; font-weight: 600; color: #374151; flex: 1; }
.sd-priority-bar-wrapper {
    display: flex;
    align-items: center;
    gap: 10px;
    background: #f1f5f9;
    border-radius: 99px;
    height: 8px;
    position: relative;
    overflow: hidden;
}
.sd-priority-bar-fill {
    height: 100%;
    border-radius: 99px;
    transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1);
    min-width: 2px;
}
.sd-fill-high   { background: linear-gradient(90deg, #ef4444, #dc2626); }
.sd-fill-medium { background: linear-gradient(90deg, #f59e0b, #d97706); }
.sd-fill-low    { background: linear-gradient(90deg, #22c55e, #16a34a); }
.sd-priority-count {
    position: absolute;
    right: 8px;
    font-size: 11px;
    font-weight: 700;
    color: #475569;
    background: transparent;
    line-height: 1;
}

/* ---- RESPONSIVE ---- */
@media (max-width: 1024px) {
    .sd-charts-grid {
        grid-template-columns: 1fr;
    }
    .sd-widget-stack {
        flex-direction: row;
        gap: 20px;
    }
    .sd-widget-stack .sd-widget:first-child {
        margin-bottom: 0;
    }
}
@media (max-width: 768px) {
    .sd-header {
        flex-direction: column;
        align-items: flex-start;
    }
    .sd-kpi-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    .sd-widget-stack {
        flex-direction: column;
    }
    .sd-widget-stack .sd-widget:first-child {
        margin-bottom: 20px;
    }
    .sd-canvas-container { height: 220px; }
}
@media (max-width: 480px) {
    .sd-kpi-grid { grid-template-columns: 1fr 1fr; }
    .sd-kpi-value { font-size: 26px; }
}

/* ---- RTL OVERRIDES ---- */
.sahl-dashboard-wrapper.rtl .sd-priority-info {
    flex-direction: row-reverse;
}
.sahl-dashboard-wrapper.rtl .sd-priority-count {
    right: auto;
    left: 8px;
}
.sahl-dashboard-wrapper.rtl .sd-title-area {
    flex-direction: row-reverse;
}

/* ---- LEGACY: Old .ts-dashboard-widget styles (backward compat) ---- */
.ts-dashboard-widget {
    background: #ffffff;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
    padding: 24px;
    margin-bottom: 24px;
    border: 1px solid #f0f2f5;
    font-family: 'Cairo', 'Segoe UI', sans-serif;
}
.ts-dashboard-widget h3 {
    margin: 0 0 20px 0;
    font-size: 16px;
    font-weight: 700;
    color: #1e293b;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 2px solid #f4f5f7;
    padding-bottom: 10px;
}
.ts-chart-canvas {
    width: 100% !important;
    max-height: 400px;
}