/* Personalized Dashboard - main content area (dark theme #2e2c2c) */
.personalized-dashboard-main {
  flex: 1;
  /* Ensure main area has visible height on first load so widgets aren't shrunk */
  min-height: calc(100vh - 10px);
  padding: 1.5rem;
  background: #2e2c2c;
  overflow-y: auto;
  color: rgba(255, 255, 255, 0.9);
}

/* Toolbar on page – Add chart lives here, not in navbar */
.personalized-dashboard-toolbar {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  margin-bottom: 1.25rem;
  flex-shrink: 0;
  position: relative;
  z-index: 10;
}

/* Add chart control on page – matches navbar design */
.personalized-dashboard-add-chart-wrap {
  position: relative;
  z-index: 11;
}

.personalized-dashboard-add-chart-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  font-size: 0.8125rem;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.9);
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.personalized-dashboard-add-chart-btn:hover {
  background: rgba(242, 27, 35, 0.2);
  border-color: rgba(242, 27, 35, 0.4);
  color: #f87171;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}

.personalized-dashboard-add-chart-btn[aria-expanded="true"] {
  background: rgba(242, 27, 35, 0.2);
  border-color: rgba(242, 27, 35, 0.5);
  color: #f87171;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}

.personalized-dashboard-add-chart-dropdown {
  position: absolute;
  top: calc(100% + 0.5rem);
  left: 0;
  min-width: 280px;
  max-width: 360px;
  max-height: 70vh;
  overflow-y: auto;
  background: #3a3838;
  backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  z-index: 1000;
  padding: 0.5rem 0;
}

.personalized-dashboard-add-chart-empty {
  margin: 0;
  padding: 1rem 1.25rem;
  font-size: 0.875rem;
  color: rgba(255, 255, 255, 0.7);
}

.personalized-dashboard-add-chart-option {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  width: 100%;
  padding: 0.75rem 1.25rem;
  font-size: 0.875rem;
  text-align: left;
  color: rgba(255, 255, 255, 0.9);
  background: transparent;
  border: none;
  cursor: pointer;
  transition: background 0.15s ease;
}

.personalized-dashboard-add-chart-option:hover {
  background: rgba(255, 255, 255, 0.08);
}

.personalized-dashboard-add-chart-option-label {
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.personalized-dashboard-add-chart-option-desc {
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.65);
}

/* Widget grid - X/Y axis grid; every cell can hold a widget */
.personalized-dashboard-grid {
  min-height: 20rem;
}

.personalized-dashboard-grid--xy {
  display: grid;
  grid-template-columns: repeat(var(--grid-cols, 18), 1fr);
  grid-auto-rows: var(--grid-row-height, 100px);
  gap: 14px;
  align-content: start;
}

.personalized-dashboard-grid--clickable-empty:active {
  outline: none;
}

.personalized-dashboard-widget {
  position: relative;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  max-width: 100%;
  box-sizing: border-box;
  overflow: hidden;
  /* Default card appearance for widgets */
  background: #3a3838;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--border-radius, 8px);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

/* Tall grid rows otherwise stretch this widget to the full cell; content-height reads as a compact card */
.personalized-dashboard-widget--align-start {
  align-self: start;
}

.personalized-dashboard-widget--no-outer {
  /* Used for widgets that should rely only on their inner card (e.g. single StatCard) */
  background: transparent;
  border: none;
  box-shadow: none;
}

.personalized-dashboard-widget--no-outer .personalized-dashboard-widget-body {
  padding: 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* Stat card fills the widget so resize handle sits at card's bottom-right */
.personalized-dashboard-widget--no-outer .personalized-dashboard-widget-body > .stat-card {
  flex: 1;
  min-height: 0;
  height: 100%;
}

/* Stats widget spans full width */
.personalized-dashboard-widget--stats {
  flex: 1 1 100%;
  min-width: 0;
}

.personalized-dashboard-widget--resizing {
  pointer-events: none;
}

.personalized-dashboard-widget--resizing .personalized-dashboard-widget-resize-handle {
  pointer-events: auto;
}

.personalized-dashboard-stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  padding: 1rem 1.25rem;
}

.personalized-dashboard-stats-grid .stat-card {
  height: 100%;
}

/* Stat cards inside Personalised Dashboard – dark theme */
.personalized-dashboard .stat-card {
  background: #363434;
  border: 1px solid rgba(255, 255, 255, 0.15);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}

.personalized-dashboard .stat-card:hover {
  border-color: rgba(242, 27, 35, 0.5);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
}

.personalized-dashboard .stat-card--clickable:hover {
  border-color: rgba(242, 27, 35, 0.5);
}

.personalized-dashboard .stat-card-label {
  color: rgba(255, 255, 255, 0.7);
}

.personalized-dashboard .stat-card-value {
  color: rgba(255, 255, 255, 0.98);
}

.personalized-dashboard .stat-card-subtitle {
  color: rgba(255, 255, 255, 0.75);
}

.personalized-dashboard .stat-card-description {
  color: rgba(255, 255, 255, 0.65);
}

.personalized-dashboard .stat-card-change.up {
  color: rgba(255, 255, 255, 0.9);
}

.personalized-dashboard .stat-card-change.down {
  color: rgba(255, 255, 255, 0.65);
}

.personalized-dashboard .stat-card-icon {
  color: #f87171;
}

/* Hide "Add to personalised dashboard" (+) on widgets that are already on this page */
.personalized-dashboard .dashboard-add-to-personalized {
  display: none !important;
}

/* Body is the only scrollable area; no extra content wrapper – widget is the single card */
.personalized-dashboard-widget-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding: 0.5rem;
  padding-top: 2.5rem; /* room for actions bar */
  /* Hide scrollbar when widget shrinks; content still scrollable (wheel/touch) */
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.personalized-dashboard-widget-body::-webkit-scrollbar {
  display: none;
}

.personalized-dashboard-widget:has(.personalized-dashboard-stats-grid) .personalized-dashboard-widget-body {
  padding-top: 0.75rem;
}

/* Inner chart cards inherit the widget card – no double box */
.personalized-dashboard-widget-body .chart-card,
.personalized-dashboard-widget-body .sio-oio-ca-card {
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
}

/* RA location drilldown: one frame only — outer .personalized-dashboard-widget matches admin
   .dashboard-section + .admin-drill-pie (inner root has no card). */
.personalized-dashboard .personalized-dashboard-widget-body .pd-ra-drill {
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
  padding: 0;
}

/* Risk Assessment embedded panels: solid inner card (not washed-out rgba on #3a3838 chrome) */
.personalized-dashboard .personalized-dashboard-widget-body .pd-ra-widget-panel,
.personalized-dashboard .personalized-dashboard-widget-body .pd-ra-trend {
  background-color: #363434;
  border: 1px solid rgba(255, 255, 255, 0.14);
}

.personalized-dashboard .personalized-dashboard-widget-body .pd-ra-drill-chart-wrap {
  background-color: #2e2c2c;
}

/* Actions bar inside widget: drag (reorder) + remove, top-right */
.personalized-dashboard-widget-actions {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  display: flex;
  align-items: center;
  gap: 0.25rem;
  z-index: 2;
}

.personalized-dashboard-widget-drag-handle {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  background: rgba(255, 255, 255, 0.1);
  border: none;
  border-radius: 6px;
  color: rgba(255, 255, 255, 0.75);
  cursor: grab;
  transition: background 0.15s, color 0.15s, opacity 0.2s ease;
}

.personalized-dashboard-widget-drag-handle:active {
  cursor: grabbing;
}

.personalized-dashboard-widget-drag-handle:hover {
  background: rgba(255, 255, 255, 0.18);
  color: rgba(255, 255, 255, 0.95);
}

.personalized-dashboard-widget--dragging .personalized-dashboard-widget-drag-handle {
  cursor: grabbing;
}

.personalized-dashboard-widget--dragging {
  opacity: 0.6;
}

.personalized-dashboard-widget--drag-over {
  outline: 2px solid rgba(242, 27, 35, 0.5);
  outline-offset: 2px;
  border-radius: var(--border-radius, 8px);
}

/* Controls visible on hover */
.personalized-dashboard-widget-drag-handle,
.personalized-dashboard-widget-remove,
.personalized-dashboard-widget-resize-handle {
  opacity: 0;
  transition: opacity 0.2s ease, background 0.15s, color 0.15s;
}

.personalized-dashboard-widget:hover .personalized-dashboard-widget-drag-handle,
.personalized-dashboard-widget:hover .personalized-dashboard-widget-remove,
.personalized-dashboard-widget:hover .personalized-dashboard-widget-resize-handle,
.personalized-dashboard-widget--resizing .personalized-dashboard-widget-resize-handle,
.personalized-dashboard-widget--dragging .personalized-dashboard-widget-drag-handle {
  opacity: 1;
}

.personalized-dashboard-widget-remove {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  background: rgba(255, 255, 255, 0.1);
  border: none;
  border-radius: 6px;
  color: rgba(255, 255, 255, 0.75);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.personalized-dashboard-widget-remove:hover {
  background: rgba(242, 27, 35, 0.3);
  color: #fca5a5;
}

/* Resize handle – direct child of widget so it stays on the card’s bottom-right */
.personalized-dashboard-widget-resize-handle {
  position: absolute;
  bottom: 0.25rem;
  right: 0.25rem;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  background: rgba(0, 0, 0, 0.15);
  border: none;
  border-radius: 4px;
  color: rgba(255, 255, 255, 0.8);
  cursor: nwse-resize;
  z-index: 3;
  transition: background 0.15s, color 0.15s;
}

.personalized-dashboard-widget-resize-handle:hover {
  background: rgba(0, 0, 0, 0.25);
  color: rgba(255, 255, 255, 0.95);
}

.personalized-dashboard-widget-resize-handle svg {
  opacity: 0.7;
}

.personalized-dashboard-widget-resize-handle:hover svg {
  opacity: 1;
}

/* Empty state */
.personalized-dashboard-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 280px;
  text-align: center;
  padding: 2rem;
}

.personalized-dashboard-empty-title {
  margin: 0 0 0.5rem 0;
  font-size: 1.25rem;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.98);
}

.personalized-dashboard-empty-desc {
  margin: 0 0 1.5rem 0;
  max-width: 420px;
  font-size: 0.9375rem;
  line-height: 1.5;
  color: rgba(255, 255, 255, 0.75);
}

.personalized-dashboard-empty-btn {
  padding: 0.625rem 1.25rem;
  font-size: 0.9375rem;
  font-weight: 500;
  color: #fff;
  background: linear-gradient(180deg, #f21b23 0%, #d91820 100%);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s, box-shadow 0.2s;
}

.personalized-dashboard-empty-btn:hover {
  background: linear-gradient(180deg, #d91820 0%, #c2151d 100%);
  box-shadow: 0 4px 12px rgba(242, 27, 35, 0.35);
}

.personalized-dashboard-empty-btn:active {
  transform: scale(0.98);
}

/* Loading / error inside main */
.personalized-dashboard-loading,
.personalized-dashboard-error {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 200px;
  padding: 2rem;
}

.personalized-dashboard-loading p,
.personalized-dashboard-error p {
  margin: 1rem 0 0 0;
  font-size: 0.9375rem;
  color: rgba(255, 255, 255, 0.8);
}

.personalized-dashboard-error p {
  color: #fca5a5;
}

/* ----- Mobile & tablet responsive ----- */
@media (max-width: 768px) {
  .personalized-dashboard-main {
    padding: 1rem;
    min-height: calc(100vh - 8px);
    overflow-x: hidden;
  }

  .personalized-dashboard-toolbar {
    margin-bottom: 1rem;
  }

  .personalized-dashboard-add-chart-btn {
    padding: 0.5rem 0.875rem;
    font-size: 0.8125rem;
  }

  .personalized-dashboard-add-chart-dropdown {
    left: 0;
    right: auto;
    min-width: 260px;
    max-width: calc(100vw - 2rem);
    max-height: 60vh;
  }

  /* Single-column grid on tablet/mobile: all widgets full width */
  .personalized-dashboard-grid--xy {
    grid-template-columns: 1fr;
    gap: 1rem;
    min-height: 10rem;
  }

  .personalized-dashboard-grid--xy .personalized-dashboard-widget {
    grid-column: 1 / -1;
    grid-row: auto;
    min-height: 200px;
  }

  .personalized-dashboard-widget--stats {
    flex: 0 0 auto;
  }

  .personalized-dashboard-stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
    padding: 0.75rem 1rem;
  }

  .personalized-dashboard-widget-body {
    padding: 0.875rem 1rem;
    min-height: 180px;
  }

  .personalized-dashboard-widget:has(.personalized-dashboard-stats-grid) .personalized-dashboard-widget-body {
    padding: 0.75rem 1rem;
  }

  .personalized-dashboard-widget-actions {
    top: 0.375rem;
    right: 0.375rem;
  }

  /* Slightly larger touch targets for drag/remove on mobile */
  .personalized-dashboard-widget-drag-handle,
  .personalized-dashboard-widget-remove {
    width: 32px;
    height: 32px;
  }

  /* Hide resize handle on touch devices / small screens (widgets are full width) */
  .personalized-dashboard-widget-resize-handle {
    display: none;
  }

  .personalized-dashboard-empty {
    min-height: 240px;
    padding: 1.5rem 1rem;
  }

  .personalized-dashboard-empty-title {
    font-size: 1.125rem;
  }

  .personalized-dashboard-empty-desc {
    font-size: 0.875rem;
    max-width: 100%;
    margin-bottom: 1.25rem;
  }

  .personalized-dashboard-loading,
  .personalized-dashboard-error {
    min-height: 160px;
    padding: 1.5rem 1rem;
  }

  .personalized-dashboard-loading p,
  .personalized-dashboard-error p {
    font-size: 0.875rem;
  }
}

@media (max-width: 480px) {
  .personalized-dashboard-main {
    padding: 0.75rem;
  }

  .personalized-dashboard-toolbar {
    margin-bottom: 0.875rem;
  }

  .personalized-dashboard-add-chart-dropdown {
    position: fixed;
    left: 0.75rem;
    right: 0.75rem;
    width: auto;
    min-width: 0;
    top: 4.5rem;
    max-height: 55vh;
  }

  .personalized-dashboard-grid {
    gap: 0.875rem;
  }

  .personalized-dashboard-stats-grid {
    grid-template-columns: 1fr;
    padding: 0.625rem 0.875rem;
    gap: 0.625rem;
  }

  .personalized-dashboard-widget-body {
    padding: 0.75rem 0.875rem;
    min-height: 160px;
  }

  .personalized-dashboard-widget:has(.personalized-dashboard-stats-grid) .personalized-dashboard-widget-body {
    padding: 0.625rem 0.875rem;
  }

  .personalized-dashboard-widget-drag-handle,
  .personalized-dashboard-widget-remove {
    width: 28px;
    height: 28px;
  }

  .personalized-dashboard-empty {
    min-height: 200px;
    padding: 1.25rem 0.75rem;
  }

  .personalized-dashboard-empty-title {
    font-size: 1rem;
  }

  .personalized-dashboard-empty-desc {
    font-size: 0.8125rem;
  }

  .personalized-dashboard-empty-btn {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
  }
}
