/* Canvas Dashboard Styles */

#dashboard-container {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 180px); /* Account for header and tabs */
    padding: 20px;
    width: 100%;
    box-sizing: border-box;
}

/* Header */
#dashboard-header {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    padding: 1rem 2rem;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 1000;
    flex-shrink: 0; /* Don't shrink the header */
}

#dashboard-header h1 {
    font-size: 1.5rem;
    font-weight: 600;
    color: #333;
}

/* Dashboard selector styles */
.dashboard-title-section {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.dashboard-selector-controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.dashboard-dropdown {
    padding: 0.4rem 0.8rem;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 0.875rem;
    background: white;
    color: #333;
    cursor: pointer;
    min-width: 180px;
}

.dashboard-dropdown option {
    color: #333;
    background: white;
}

.dashboard-dropdown:hover {
    border-color: #9ca3af;
}

.dashboard-dropdown:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.btn-sm {
    padding: 0.4rem 0.8rem;
    font-size: 0.8rem;
}

.dashboard-controls {
    display: flex;
    gap: 0.5rem;
}

.btn {
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.btn-primary {
    background: #667eea;
    color: white;
}

.btn-primary:hover {
    background: #5a67d8;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.btn-success {
    background: #48bb78;
    color: white;
}

.btn-success:hover {
    background: #38a169;
}

.btn-warning {
    background: #ed8936;
    color: white;
}

.btn-warning:hover {
    background: #dd6b20;
}

.btn-secondary {
    background: #718096;
    color: white;
}

.btn-secondary:hover {
    background: #4a5568;
}

/* Canvas Area */
#dashboard-canvas {
    flex: 1;
    position: relative;
    overflow-x: auto; /* Enable horizontal scrollbar */
    overflow-y: auto; /* Enable vertical scrollbar */
    background: #f7fafc;
    margin: 1rem;
    border-radius: 12px;
    box-shadow: inset 0 2px 10px rgba(0, 0, 0, 0.05);
    /* Ensure proper sizing */
    width: calc(100% - 2rem); /* Account for margins */
    max-width: calc(100vw - 4rem);
    min-height: 400px;
}

/* Inner canvas container that expands */
#canvas-inner {
    position: relative;
    /* Start with a reasonable size - will be set by JavaScript */
    width: 2000px;
    height: 1500px;
    /* These will be overridden by JavaScript as needed */
}

/* Grid Overlay */
.grid-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: 
        linear-gradient(rgba(200, 200, 200, 0.2) 1px, transparent 1px),
        linear-gradient(90deg, rgba(200, 200, 200, 0.2) 1px, transparent 1px);
    background-size: 20px 20px;
    pointer-events: none;
    z-index: 1;
}

.grid-overlay.hidden {
    display: none;
}

/* Dashboard Widgets */
.dashboard-widget {
    position: absolute;
    background: white;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
    min-width: 200px;
    min-height: 150px;
    display: flex;
    flex-direction: column;
    transition: box-shadow 0.2s;
    user-select: none;
}

.dashboard-widget:hover {
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
}

.dashboard-widget.dragging {
    opacity: 0.8;
    z-index: 9999 !important;
    cursor: move;
}

.dashboard-widget.resizing {
    opacity: 0.9;
}

/* Widget Header */
.widget-header {
    padding: 0.75rem 1rem;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 12px 12px 0 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    color: white;
}

.widget-drag-handle {
    cursor: move;
    padding: 0.25rem;
    margin-right: 0.5rem;
    opacity: 0.7;
    transition: opacity 0.2s;
}

.widget-drag-handle:hover {
    opacity: 1;
}

.widget-title {
    flex: 1;
    font-size: 0.875rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.widget-actions {
    display: flex;
    gap: 0.25rem;
}

.widget-actions button {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    padding: 0.25rem;
    opacity: 0.7;
    transition: opacity 0.2s;
}

.widget-actions button:hover {
    opacity: 1;
}

/* Widget Content */
.widget-content {
    flex: 1;
    padding: 1rem;
    overflow: auto;
    position: relative;
}

.widget-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: #718096;
}

.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid #e2e8f0;
    border-top-color: #667eea;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 0.5rem;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Widget Resize Handle */
.widget-resize-handle {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 20px;
    height: 20px;
    cursor: nwse-resize;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #cbd5e0;
    font-size: 10px;
}

.widget-resize-handle:hover {
    color: #667eea;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    backdrop-filter: blur(4px);
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: white;
    border-radius: 12px;
    width: 90%;
    max-width: 600px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.modal-header {
    padding: 1.5rem;
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h2 {
    font-size: 1.25rem;
    font-weight: 600;
}

.close-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: #718096;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    transition: all 0.2s;
}

.close-btn:hover {
    background: #f7fafc;
    color: #2d3748;
}

.modal-body {
    padding: 1.5rem;
    overflow-y: auto;
    flex: 1;
}

#widget-types-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 1rem;
}

.widget-type-card {
    padding: 1rem;
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    text-align: center;
}

.widget-type-card:hover {
    border-color: #667eea;
    background: #f7fafc;
    transform: translateY(-2px);
}

.widget-type-card i {
    font-size: 2rem;
    color: #667eea;
    margin-bottom: 0.5rem;
}

.widget-type-card h4 {
    font-size: 0.875rem;
    font-weight: 600;
    color: #2d3748;
    margin-bottom: 0.25rem;
}

.widget-type-card p {
    font-size: 0.75rem;
    color: #718096;
}

/* KPI Widget Styles */
.kpi-widget {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
}

.kpi-value {
    font-size: 2.5rem;
    font-weight: 700;
    color: #2d3748;
    margin-bottom: 0.5rem;
}

.kpi-change {
    font-size: 1rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.kpi-change.positive {
    color: #48bb78;
}

.kpi-change.negative {
    color: #f56565;
}

.kpi-change.neutral {
    color: #718096;
}

.kpi-subtitle {
    font-size: 0.875rem;
    color: #718096;
    margin-top: 0.5rem;
}

/* Scrollbar Styles */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb {
    background: #cbd5e0;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #a0aec0;
}

/* Dashboard Subdata Modal */
.dashboard-subdata-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 15000;
    backdrop-filter: blur(4px);
    padding: 20px;
}

.dashboard-subdata-modal.active {
    display: flex;
}

.subdata-modal-content {
    background: white;
    border-radius: 12px;
    width: calc(100% - 40px);
    height: calc(100% - 40px);
    max-width: 1400px;
    max-height: 900px;
    display: flex;
    flex-direction: column;
    box-shadow: 0 25px 80px rgba(0, 0, 0, 0.4);
    overflow: hidden;
}

.subdata-modal-header {
    padding: 1.5rem 2rem;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.subdata-modal-header h2 {
    font-size: 1.5rem;
    font-weight: 600;
    margin: 0;
}

.subdata-modal-close {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.5rem;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    transition: all 0.2s;
}

.subdata-modal-close:hover {
    background: rgba(255, 255, 255, 0.3);
}

.subdata-modal-summary {
    padding: 1.5rem 2rem;
    background: #f8f9fa;
    border-bottom: 1px solid #e2e8f0;
    flex-shrink: 0;
}

.summary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.5rem;
}

.summary-item {
    display: flex;
    flex-direction: column;
}

.summary-label {
    font-size: 0.875rem;
    color: #718096;
    font-weight: 500;
    margin-bottom: 0.25rem;
}

.summary-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: #2d3748;
}

.subdata-modal-table-container {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    padding: 1.5rem 2rem;
}

.table-wrapper {
    flex: 1;
    overflow: hidden;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
}

.table-header-wrapper {
    flex-shrink: 0;
    overflow: hidden;
    border-bottom: 2px solid #d1d5db;
}

.subdata-table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
}

.subdata-table thead {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.subdata-table thead th {
    padding: 0.75rem 1rem;
    text-align: left;
    font-size: 0.875rem;
    font-weight: 600;
    white-space: nowrap;
    border-right: 1px solid rgba(255, 255, 255, 0.2);
}

.subdata-table thead th:last-child {
    border-right: none;
}

.table-body-wrapper {
    flex: 1;
    overflow-y: auto;
    overflow-x: auto;
}

.subdata-table tbody {
    background: white;
}

.subdata-table tbody tr {
    border-bottom: 1px solid #e5e7eb;
    transition: background-color 0.2s;
}

.subdata-table tbody tr:hover {
    background-color: #f7fafc;
}

.subdata-table tbody tr:last-child {
    border-bottom: none;
}

.subdata-table tbody td {
    padding: 0.75rem 1rem;
    font-size: 0.875rem;
    color: #2d3748;
    white-space: nowrap;
    border-right: 1px solid #e5e7eb;
}

.subdata-table tbody td:last-child {
    border-right: none;
}

.subdata-table tbody td.number {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.subdata-table tbody td.currency {
    text-align: right;
    font-variant-numeric: tabular-nums;
    font-weight: 500;
}

/* Loading state for modal */
.subdata-modal-loading {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    color: #718096;
}

.subdata-modal-loading .spinner {
    width: 48px;
    height: 48px;
    border-width: 4px;
}

/* Error state for modal */
.subdata-modal-error {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    color: #f56565;
    padding: 2rem;
}

.subdata-modal-error i {
    font-size: 3rem;
    margin-bottom: 1rem;
}