/* Metrics Panel (Bottom Drawer) */
#metric-panel {
    position: fixed;
    bottom: -100%;
    /* Initially hidden */
    left: 0;
    width: 100%;
    height: calc(100vh - 65vh); /* Complement to dashboard height */
    background: white;
    box-shadow: 0px -2px 10px rgba(0, 0, 0, 0.2);
    transition: bottom 0.3s ease-in-out;
    padding: 0; /* Remove padding since header has its own */
    display: flex;
    flex-direction: column;
    z-index: 1000;
    box-sizing: border-box;
    overflow: hidden; /* Prevent panel overflow */
}

/* Opened State */
#metric-panel.open {
    bottom: 0;
}

#metric-panel.active {
    bottom: 0;
}

.main-stats-overview {
    min-width: 100%!important;
}

.metric-card {
    width: 100%;
    /* Set uniform width */
    height: 90px;
    /* Set uniform height */
    background: #fff;
    border-radius: 0.375rem;
    box-shadow: 0px 2px 4px rgba(0, 0, 0, 0.1);
    display: flex;
    align-items: center;
    padding: 12px;
    transition: transform 0.2s ease-in-out;
    cursor: grab;
}

.metric-card:hover {
    transform: scale(1.05);
}

.metric-card .metric-icon {
    font-size: 24px;
}

.remove-metric {
    background-color: red;
    color: white;
    border: none;
    padding: 5px 10px;
    cursor: pointer;
}

.metrics-dashboard {
    position: relative;
    padding: 0;
    border-top: 1px solid #e5e5e5;
    background: #fff;
    height: 200px;
    overflow: hidden;
    transition: all 0.3s ease-in-out;
    border-radius: 5px;
    display: flex;
    flex-direction: column;
}

.metrics-dashboard.editing {
    height: 45vh;
    padding-bottom: 20px;
}

/* Hide metrics container in edit mode */
.metrics-dashboard.editing #metrics-container {
    display: none;
}

/* Panel Header Layout */
.metric-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid #e2e8f0;
    background-color: #f8fafc;
    width: 100%;
    flex-shrink: 0; /* Prevent header from shrinking */
    position: sticky;
    top: 0;
    z-index: 100;
}

.metric-panel-header h3 {
    margin: 0;
    font-size: 16px;
    color: #1a202c;
    font-weight: 500;
}

.metric-panel-header .template-filter-container {
    margin: 0;
    width: auto;
}

.metric-panel-header .modern-select {
    width: 250px;
}

.metric-panel-header .modern-select select {
    font-size: 14px;
    padding: 8px 12px;
    padding-right: 32px; /* Space for arrow */
}

#available-metrics {
    padding: 16px;
}

.edit-button {
    position: absolute;
    right: 20px;
    top: 10px;
    background: #007bff;
    color: white;
    border: none;
    padding: 10px;
    cursor: pointer;
}

/* Metrics Container - Ensure max 4 metrics per row */
.metrics-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    grid-gap: 16px;
    max-width: 100%;
    margin-top: 20px;
    padding: 20px 10px;
    min-height: 0; /* Allow container to shrink */
    flex: 1;
    overflow-y: auto;
}

@media (min-width: 1200px) {
    .metrics-container {
        grid-template-columns: repeat(4, 1fr);
    }
}

@media (max-width: 1199px) and (min-width: 768px) {
    .metrics-container {
        grid-template-columns: repeat(1, 1fr);
    }
}

@media (max-width: 767px) {
    .metrics-container {
        grid-template-columns: 1fr;
    }
}

/* Icon Wrapper */
.metric-icon {
    width: 50px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    font-size: 20px;
    color: #5b6166;
    --bs-bg-opacity: 0.1;
}

.remove-metric-btn {
    position: absolute;
    top: 5px;
    right: 5px;
    background: red;
    color: white;
    border: none;
    padding: 5px;
    cursor: pointer;
}

.add-metric {
    border: 2px dashed #007bff;
    cursor: pointer;
}

/* Icon Colors */
.bg-success {
    background: rgba(40, 167, 69, 0.1);
    color: #28a745;
}

.bg-danger {
    background: rgba(220, 53, 69, 0.1);
    color: #dc3545;
}

.bg-orange {
    background: rgba(255, 159, 64, 0.1);
    color: #ff9f40;
}

.metric-content {
    display: flex;
    flex-direction: column;
    flex-grow: 1;
    justify-content: space-between;
    padding: 5px 10px;
    overflow: hidden;
    width: 100%;
}

/* Metric Name (Top Left) */
.metric-content h4 {
    font-size: 13px;
    font-weight: bold;
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Metric Details (Bottom Left) - Truncated */
.metric-content p {
    font-size: 12px;
    color: #6c757d;
    margin: 2px 0 0;
    max-height: 2.4em;
    /* Limits to 2 lines */
    overflow: hidden;
    white-space: nowrap;
    /* Prevent text wrapping */
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    /* Show max 2 lines */
    -webkit-box-orient: vertical;
    transition: all 0.3s ease;
    /* Smooth transition for scaling */
}

/* Shrink text if overflowing */
.metric-content p.shrink-text,
.metric-content h4.shrink-text {
    font-size: 12px;
    transform-origin: left;
    -webkit-line-clamp: unset;
    display: block;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Number (Right Side) */
.metric-number {
    font-size: 15px;
    font-weight: bold;
    color: #333;
    margin-left: auto;
    text-align: right;
    min-width: 35px;
}

/* Metrics Title */
.metrics-title {
    font-size: 16px;
    color: #1a202c;
    margin: 20px 0 0 10px;
    display: inline-block;
}

/* Edit Button */
#edit-metrics-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    color: #5b6167;
    padding: 8px 12px;
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 5px;
    position: absolute;
    top: 10px;
    right: 20px;
}

#edit-metrics-btn:hover {
    color: #0056b3;
}

/* Empty Slot (Dotted Border) */
.empty-metric {
    width: 100%;
    height: 80px;
    border: 2px dashed #ccc;
    background: rgba(0, 0, 0, 0.05);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #aaa;
    font-size: 20px;
    cursor: pointer;
    transition: background 0.2s ease-in-out;
}

.empty-metric:hover {
    border-color: #999;
    color: #666;
    background: rgba(0, 255, 0, 0.1);

}

/* Responsive Grid Layout */
@media (min-width: 768px) {
    .metrics-container {
        grid-template-columns: repeat(1, 1fr);
        /* 2 per row on medium screens */
    }

    .dashboard-metric-card {
        height:120px!important;
    }

    .metric-icon {
        width: 60px;
        height: 50px;
        margin-right: 20px;
    }

    
    .loading-content p {
        font-size: 28px!important;    
    }

@media (min-width: 1024px) {
    .metrics-container {
        grid-template-columns: repeat(4, 1fr);
        /* 4 per row on larger screens */
    }
}

/* Animated "Add Metric" Slot */
#add-metric-slot {
    width: 240px;
    height: 80px;
    border: 2px dashed #ccc;
    border-radius: 0.375rem;
    display: flex;
    /* Keep flex for center alignment */
    align-items: center;
    justify-content: center;
    color: #aaa;
    font-size: 20px;
    cursor: pointer;
    opacity: 0;
    max-height: 0;
    background: rgba(255, 255, 255, 0.5);
    overflow: hidden;
    transition: opacity 0.3s ease-in-out, max-height 0.3s ease-in-out;
}


/* Highlight when dragging */
.add-metric-slot.drag-over {
    background: rgba(0, 200, 0, 0.1);
    border-color: #28a745;
}

/* Show Animation */
#add-metric-slot.show {
    opacity: 1;
    max-height: 80px;
    align-content: center;
    text-align: center;
}

/* Plus Button Centered */
#add-metric-slot span {
    font-size: 30px;
    font-weight: bold;
    color: #aaa;
}

/* Remove Button for Edit Mode */
.remove-metric-btn {
    background: none;
    border: none;
    font-size: 10px;
    color: red;
    cursor: pointer;
    position: absolute;
    right: 10px;
    top: 10px;
    display: none;
}

.metrics-container.edit-mode .remove-metric-btn {
    display: block;
}





/* Available Metric Card */
.dashboard-metric-card {
    background: white;
    border-radius: 0.375rem;
    padding: 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: relative;
    box-shadow: 0px 2px 8px rgba(0, 0, 0, 0.1);
    transition: transform 0.2s ease-in-out;
    height: 80px;
    min-height: 80px;
    min-width: 24%;
}

/* AVAILABLE METRICS */

/* Available Metrics Container */
#available-metrics {
    display: grid;
    gap: 16px;
    padding: 20px;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    grid-template-columns: repeat(1, 1fr);
    overflow-y: auto;
    overflow-x: hidden;
    max-height: calc(100vh - 65vh - 70px); /* Subtracting panel height and header height */
    height: 100%;
}

/* Hide all metrics containers in edit mode */
.metrics-dashboard.editing .metrics-container,
.metrics-dashboard.editing #metrics-container {
    display: none !important;
}

@media (min-width: 768px) {
    #available-metrics {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (min-width: 1024px) {
    #available-metrics {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (min-width: 1200px) {
    #available-metrics {
        grid-template-columns: repeat(4, 1fr);
    }
}

/* Available Metric Card */
.available-metric-card {
    background: white;
    border-radius: 0.375rem;
    padding: 16px;
    display: flex;
    align-items: left;
    justify-content: space-between;
    box-shadow: 0px 2px 8px rgba(0, 0, 0, 0.1);
    transition: transform 0.2s ease-in-out;
    cursor: grab;
    height: 80px;
    width: 100%;
    box-sizing: border-box;
    min-width: 0;
}

/* Hover Effect */
.available-metric-card:hover {
    transform: translateY(-5px);
}

/* Dragging effect */
.available-metric-card.dragging {
    opacity: 0.5;
    transform: scale(1.1);
}

/* Template Filter Styles */
.template-filter-container {
    display: flex;
    justify-content: flex-end;
    margin: 0;
}

.modern-select {
    padding: 12px 16px;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    background-color: white;
    color: #1a202c;
    font-size: 14px;
    width: 300px;
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 16px;
    transition: all 0.2s ease;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
    position: relative;
    z-index: 10;
}

.modern-select:hover {
    border-color: #cbd5e0;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.modern-select:focus {
    outline: none;
    border-color: #4299e1;
    box-shadow: 0 0 0 3px rgba(66, 153, 225, 0.15);
}

/* Dropdown Options Styling */
.modern-select option {
    padding: 10px 16px;
    font-size: 14px;
    color: #1a202c;
    background-color: white;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.modern-select option:hover,
.modern-select option:focus {
    background-color: #f7fafc !important;
    color: #2b6cb0 !important;
}

.modern-select option:checked {
    background-color: #ebf8ff !important;
    color: #2b6cb0;
    font-weight: 500;
}

/* Option Groups */
.modern-select optgroup {
    padding: 12px;
    font-size: 14px;
    font-weight: 600;
    color: #4a5568;
    background-color: #f8fafc;
    border-bottom: 1px solid #e2e8f0;
}

.modern-select optgroup option {
    padding-left: 24px;
    font-weight: normal;
}

/* Webkit Scrollbar Styling */
.modern-select::-webkit-scrollbar {
    width: 8px;
    background-color: #f8fafc;
}

.modern-select::-webkit-scrollbar-track {
    border-radius: 8px;
    background-color: #f8fafc;
}

.modern-select::-webkit-scrollbar-thumb {
    border-radius: 8px;
    background-color: #cbd5e0;
}

.modern-select::-webkit-scrollbar-thumb:hover {
    background-color: #a0aec0;
}

/* Firefox Scrollbar */
.modern-select {
    scrollbar-width: thin;
    scrollbar-color: #cbd5e0 #f8fafc;
}

/* Microsoft Edge */
.modern-select::-ms-expand {
    display: none;
}

.modern-select::-ms-value {
    background-color: transparent;
    color: #1a202c;
}

/* Add Button (Top Right) */
.add-metric-to-dashboard {
    position: absolute;
    top: 8px;
    right: 8px;
    background: white;
    border: 2px solid #ccc;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    display: none;
    /*flex*/
    ;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    cursor: pointer;
    transition: background 0.2s ease-in-out, transform 0.2s;

}

/* Hover Animation */
.add-metric-to-dashboard:hover {
    background: #f1f1f1;
    transform: scale(1.1);
}
}