/* Dashboard Exact Styling - Matching Design Image */

/* Design tokens for device analytics cards (Figma design spec) */
:root {
  --spacing-padding-spacing-16: 16px;
  --spacing-padding-spacing-20: 20px;
  --spacing-gap-gap-2: 2px;
}

body {
    background-color: #F8F9FA; /* Light grey background for the dashboard */
}

/* Page-specific gray background - use {% block body_class %}page-gray-bg{% endblock %} in templates */
/* This overrides section-improvements.css white background with !important */
body.page-gray-bg {
    background-color: #D1D5DB !important; /* Tailwind gray-300 */
}

/* Base card styling */
.summary-card, .alerts-panel, .collectors-panel, .dashboard-card {
    background-color: #FFFFFF;
    border-radius: var(--border-border-radius-rounded-base, 12px);
    border: var(--border-border-width-border, 1px) solid var(--colors-border-border-base, #E5E7EB);
    box-shadow: 0 1px 0.5px 0.05px rgba(29, 41, 61, 0.02);
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* Summary Card Specifics (Top Row) */
.summary-card,
a.summary-card {
    flex-direction: row;
    align-items: center;
    gap: 16px;
    text-decoration: none;
    color: inherit;
}

a.summary-card:hover {
    text-decoration: none;
    color: inherit;
}

.summary-card-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    /* Colors from Figma: COLOR_METRIC_ICON_BG / COLOR_METRIC_ICON in dashboard.py */
    background-color: var(--color-metric-icon-bg, #E6F7ED);
    color: var(--color-metric-icon, #004F3B);
    font-size: 20px;
}

.summary-card-value {
    font-size: 28px;
    font-weight: 700;
    color: #1F2937; /* Dark grey */
    line-height: 1.2;
    margin-bottom: 4px;
}

.summary-card-label {
    color: var(--colors-text-text-body, #4A5565);
    font-family: var(--typography-font-family-font-base, "Ubuntu Sans");
    font-size: var(--typography-font-size-text-base, 16px);
    font-style: normal;
    font-weight: 400;
    line-height: var(--typography-line-height-leading-6, 24px);
}


/* Panel Headers (for Recent Alerts and Data Collectors Status) */
.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px; /* Reduced from 16px for tighter spacing */
}

.panel-title {
    color: var(--colors-text-text-heading, #101828);
    font-family: var(--typography-font-family-font-base, "Ubuntu Sans");
    font-size: var(--typography-font-size-text-lg, 18px);
    font-style: normal;
    font-weight: 500;
    line-height: var(--typography-line-height-leading-7, 28px);
}

.panel-button {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 6px 12px;
    border-radius: var(--themes-border-border-radius-rounded-sm, 4px);
    background-color: var(--color-brand-green);
    color: white;
    font-size: 14px;
    font-weight: 500;
    text-decoration: none;
    box-shadow: 0 1px 0.5px 0.05px rgba(29, 41, 61, 0.02);
    transition: background-color 0.2s ease-in-out;
}

.panel-button:hover {
    background-color: var(--color-brand-green-hover);
    color: white;
    text-decoration: none;
}

/* Recent Alerts Panel */
.alerts-list {
    display: flex;
    flex-direction: column;
}

.alert-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px;
    border-radius: 8px;
    border: 1px solid #E5E7EB; /* Subtle border */
    background-color: #FFFFFF;
    margin-bottom: 8px;
}

.alert-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    font-size: 16px;
    flex-shrink: 0;
}

.alert-icon.severity-critical {
    background-color: #FEF2F2; /* Light Red Background */
    color: #DC2626; /* Dark Red Icon */
    border: 1px solid #FECACA; /* Red border for emphasis */
}
.alert-icon.severity-major {
    background-color: #FFF7ED; /* Light Orange Background */
    color: #EA580C; /* Dark Orange Icon */
    border: 1px solid #FED7AA; /* Orange border */
}
.alert-icon.severity-warning {
    background-color: #FFFBEB; /* Light Yellow Background */
    color: #D97706; /* Dark Yellow Icon */
    border: 1px solid #FDE68A; /* Yellow border */
}
.alert-icon.severity-minor {
    background-color: #EFF6FF; /* Light Blue Background */
    color: #2563EB; /* Dark Blue Icon */
    border: 1px solid #BFDBFE; /* Blue border */
}
.alert-icon.severity-info {
    background-color: #ECFEFF; /* Light Cyan Background */
    color: #0891B2; /* Dark Cyan Icon */
    border: 1px solid #A7F3D0; /* Cyan border */
}
.alert-icon.severity-error {
    background-color: #FEF2F2; /* Light Red Background */
    color: #DC2626; /* Dark Red Icon */
    border: 1px solid #FECACA; /* Red border */
}
.alert-icon.severity-neutral {
    background-color: #F8FAFC; /* Light Grey Background */
    color: #64748B; /* Dark Grey Icon */
    border: 1px solid #E2E8F0; /* Grey border */
}

.alert-content {
    flex-grow: 1;
}

.alert-title {
    font-size: 16px;
    font-weight: 700;
    color: #1F2937;
    line-height: 1.4;
    margin-bottom: 4px;
}

.alert-subtitle {
    font-size: 14px;
    color: #6B7280;
    font-weight: 400;
}

/* Data Collectors Status Panel */
.collectors-summary {
    display: flex;
    align-items: baseline;
    gap: 8px;
    margin-bottom: 16px;
}

.summary-count {
    font-size: 36px;
    font-weight: 700;
    line-height: 1;
}

.summary-label {
    font-size: 16px;
    color: #343A40;
}

.status-categories {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 24px;
    margin-top: 16px;
}

.status-category {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.category-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding-bottom: 8px;
    border-bottom: 1px solid #E5E7EB;
    min-width: 0;
}

.category-icon {
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    width: 44px !important;
    height: 44px !important;
    border-radius: 50% !important;
}

.category-icon.status-connected {
    background-color: #E6FFF3 !important;
    color: #16A34A !important;
} /* Very Light Green Background, Green Icon */
.category-icon.status-disconnected {
    background-color: #FEF0F2 !important;
    color: #DC2626 !important;
} /* Light Red Background, Red Icon */
.category-icon.status-other {
    background-color: #EFF6FF !important;
    color: #1c398e !important;
} /* Light Blue Background, Blue Icon */

.category-label {
    font-size: 16px;
    font-weight: 600;
    color: #343A40;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex-shrink: 0;
    min-width: 0;
}

.collector-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-top: 8px;
}

.collector-item {
    font-size: 14px;
    color: #343A40;
    padding: 4px 0;
}

.orange-text {
    color: orange;
}

/* Segmented Time Filter (Latest Alerts) */
.time-filter {
    display: inline-flex;
    border: 1px solid #E5E7EB;
    border-radius: 6px;
    overflow: hidden;
    background-color: #FFFFFF;
}

.time-filter-btn {
    padding: 6px 14px;
    font-size: 14px;
    font-weight: 400;
    color: #6B7280;
    background-color: #FFFFFF;
    border: none;
    border-right: 1px solid #E5E7EB;
    cursor: pointer;
    transition: background-color 0.15s ease, color 0.15s ease, font-weight 0.15s ease;
    line-height: 1.4;
    white-space: nowrap;
}

.time-filter-btn:last-child {
    border-right: none;
}

.time-filter-btn:hover {
    background-color: #F9FAFB;
    color: #374151;
}

.time-filter-btn.active {
    font-weight: 700;
    color: #1F2937;
    background-color: #FFFFFF;
}

/* Card Divider - Gray horizontal line below title section */
.dashboard-card-divider {
    height: 1px;
    background-color: #E5E7EB;
    margin: 12px 0 16px 0;
    width: 100%;
}

/* Large Count Display - For Total Devices card */
.device-count-display {
    font-size: 64px;
    font-weight: 700;
    color: #1F2937;
    line-height: 1;
    text-align: center;
}

/* Chart with Side Legend Layout */
.chart-with-legend {
    display: flex;
    align-items: center;
    gap: 16px;
}

.chart-with-legend .chart-area {
    flex: 1;
    min-width: 0;
}

/* Low Battery Devices List */
.low-battery-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    flex: 1;
    overflow-y: auto;
}

/* Dashboard cards: balanced, consistent layout */
/* All four cards equal width on desktop for visual consistency */
#device-analytics-charts-container {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
    align-items: stretch;
}

@media (min-width: 768px) {
    #device-analytics-charts-container {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (min-width: 1024px) {
    #device-analytics-charts-container {
        /* Total Devices 20% narrower, Device Status & Importance 10% wider each */
        grid-template-columns: 0.8fr 1.1fr 1.1fr minmax(0, 1fr);
    }
}

#device-analytics-charts-container > div {
    display: flex;
    height: 100%;
}

/* All cards: unified styling (border-radius 8px, #DCDCDC border, #FDFDFD background) */
#device-analytics-charts-container .device-analytics-card-total .dashboard-card,
#device-analytics-charts-container .device-analytics-card-chart .dashboard-card,
#device-analytics-charts-container .device-analytics-card-low-battery .dashboard-card {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
    min-height: 0;
    padding: var(--spacing-padding-spacing-16, 16px) var(--spacing-padding-spacing-20, 20px);
    border-radius: 8px;
    border: 1px solid #DCDCDC;
    background: #FDFDFD;
    box-shadow: none;
}

#device-analytics-charts-container .device-analytics-card-total .dashboard-card {
    gap: var(--spacing-gap-gap-2, 2px);
    align-items: stretch;
}

#device-analytics-charts-container .device-analytics-card-chart .dashboard-card {
    align-items: stretch;
}

#device-analytics-charts-container .device-analytics-card-low-battery .dashboard-card {
    gap: var(--spacing-gap-gap-2, 2px);
    align-items: stretch;
}

#device-analytics-charts-container .dashboard-card {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
    min-height: 0;
}

#device-analytics-charts-container .dashboard-card .chart-container {
    flex-shrink: 0;
    /* Height is set inline via CHART_HEIGHT_DONUT - grid will equalize all cards */
}

#device-analytics-charts-container .dashboard-card .low-battery-list {
    flex: 1;
    min-height: 0;
}

.low-battery-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.low-battery-item .device-name {
    font-size: 14px;
    color: #4A5565;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.low-battery-item .battery-percentage {
    font-size: 14px;
    font-weight: 500;
    color: #DC2626;
    min-width: 40px;
    text-align: right;
}

.low-battery-item .battery-bar {
    width: 60px;
    height: 4px;
    background-color: #E5E7EB;
    border-radius: 2px;
    overflow: hidden;
}

.low-battery-item .battery-bar-fill {
    height: 100%;
    background-color: #DC2626;
    border-radius: 2px;
}

.low-battery-item .battery-bar-fill.battery-bar-critical {
    background-color: #991B1B;
}
