/* Dashboard Page Styles */
.dashboard-page .content-shell {
  padding: 1.5rem 1.75rem 2rem;
  position: relative;
}

.dashboard-page .content-inner {
  gap: 1.75rem;
}

/* Custom Scrollbar Styling - Site Theme */
.widget__body::-webkit-scrollbar,
.modal__body::-webkit-scrollbar,
.widget-card::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

.widget__body::-webkit-scrollbar-track,
.modal__body::-webkit-scrollbar-track,
.widget-card::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.2);
  border-radius: 4px;
}

.widget__body::-webkit-scrollbar-thumb,
.modal__body::-webkit-scrollbar-thumb,
.widget-card::-webkit-scrollbar-thumb {
  background: rgba(255, 122, 61, 0.4);
  border-radius: 4px;
  border: 1px solid rgba(255, 122, 61, 0.2);
}

.widget__body::-webkit-scrollbar-thumb:hover,
.modal__body::-webkit-scrollbar-thumb:hover,
.widget-card::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 122, 61, 0.6);
}

/* Firefox */
.widget__body,
.modal__body,
.widget-card {
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 122, 61, 0.4) rgba(0, 0, 0, 0.2);
}

/* GridStack Container */
.dashboard-grid-section {
  position: relative;
  min-height: calc(100vh - 200px);
  padding: 2rem;
}

/* Subtle Grid Background with Gradient Fade */
.dashboard-grid-section::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image: 
    linear-gradient(rgba(255, 122, 61, 0.08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 122, 61, 0.08) 1px, transparent 1px);
  background-size: 92px 92px; /* 80px cell + 12px margin */
  background-position: 2rem 2rem; /* Match padding */
  mask-image: radial-gradient(ellipse 90% 90% at center, black 40%, transparent 100%);
  -webkit-mask-image: radial-gradient(ellipse 90% 90% at center, black 40%, transparent 100%);
  pointer-events: none;
  z-index: 0;
  opacity: 0.6;
}

/* Grid dots at intersections for snapping points */
.dashboard-grid-section::after {
  content: '';
  position: absolute;
  inset: 0;
  background-image: 
    radial-gradient(circle at center, rgba(255, 122, 61, 0.15) 2px, transparent 2px);
  background-size: 92px 92px;
  background-position: 2rem 2rem;
  mask-image: radial-gradient(ellipse 90% 90% at center, black 40%, transparent 100%);
  -webkit-mask-image: radial-gradient(ellipse 90% 90% at center, black 40%, transparent 100%);
  pointer-events: none;
  z-index: 0;
  opacity: 0.4;
}

.grid-stack {
  background: transparent;
  position: relative;
  z-index: 1;
}

/* GridStack Item Styling */
.grid-stack-item {
  border-radius: 12px;
  overflow: visible;
  z-index: 1;
}

.grid-stack-item-content {
  background: var(--glass-bg-gradient);
  backdrop-filter: var(--backdrop-blur);
  -webkit-backdrop-filter: var(--backdrop-blur);
  border: 1px solid var(--glass-border);
  border-radius: 12px;
  overflow: hidden;
  transition: border-color 0.2s ease, background 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
  cursor: default;
  display: flex;
  flex-direction: column;
  box-shadow: var(--glass-shadow);
  position: relative;
}

.grid-stack-item-content::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.15), transparent);
  pointer-events: none;
  z-index: 1;
}

.grid-stack-item:hover .grid-stack-item-content {
  border-color: var(--glass-border-hover);
  background: linear-gradient(135deg, rgba(26, 29, 36, 0.6) 0%, rgba(20, 24, 32, 0.4) 100%);
  box-shadow: var(--glass-shadow-hover);
  transform: translateY(-2px);
}

/* Edit mode - draggable cursor */
.grid-stack.edit-mode .grid-stack-item-content {
  cursor: move;
}

.grid-stack.edit-mode .grid-stack-item:hover .grid-stack-item-content {
  border-color: rgba(37, 117, 252, 0.5);
  background: rgba(37, 117, 252, 0.08);
}

/* Widget Styles */
.widget {
  display: flex;
  flex-direction: column;
  height: 100%;
  padding: 1.25rem;
  position: relative;
}

/* Widget size-based scaling */
.grid-stack-item[gs-w="1"] .widget,
.grid-stack-item[gs-h="1"] .widget {
  padding: 0.75rem;
}

.grid-stack-item[gs-w="1"] .widget__title {
  font-size: 0.85rem;
}

.grid-stack-item[gs-w="1"] .widget__body {
  gap: 0.5rem;
}

.grid-stack-item[gs-w="1"] .widget-stat__value {
  font-size: 1.25rem;
}

.grid-stack-item[gs-h="1"] .widget__title {
  font-size: 0.85rem;
}

.grid-stack-item[gs-h="1"] .widget__body {
  gap: 0.35rem;
}

/* Scale charts and content for smaller widgets */
.grid-stack-item[gs-w="2"] .widget,
.grid-stack-item[gs-h="2"] .widget {
  padding: 1rem;
}

.grid-stack-item[gs-w="2"] .widget__title,
.grid-stack-item[gs-h="2"] .widget__title {
  font-size: 0.9rem;
}

.grid-stack-item[gs-w="2"] .widget-stat__value,
.grid-stack-item[gs-h="2"] .widget-stat__value {
  font-size: 1.5rem;
}

/* Scale chart heights based on widget size - ensure no overflow */
.grid-stack-item[gs-h="1"] canvas {
  max-height: 40px !important;
}

.grid-stack-item[gs-h="2"] canvas {
  max-height: 60px !important;
}

.grid-stack-item[gs-h="3"] canvas {
  max-height: 100px !important;
}

.grid-stack-item[gs-h="4"] canvas,
.grid-stack-item[gs-h="5"] canvas {
  max-height: 120px !important;
}

/* Ensure chart containers don't overflow */
.grid-stack-item > .grid-stack-item-content > .widget > .widget__body > div[style*="position: relative"] {
  overflow: hidden;
}

/* Compact mode for small widgets (1x1 or 1x2) */
.grid-stack-item[gs-w="1"][gs-h="1"] .widget,
.grid-stack-item[gs-w="1"][gs-h="2"] .widget {
  padding: 0.65rem;
}

.grid-stack-item[gs-w="1"][gs-h="1"] .widget__header,
.grid-stack-item[gs-w="1"][gs-h="2"] .widget__header {
  margin-bottom: 0.5rem;
}

.grid-stack-item[gs-w="1"][gs-h="1"] .widget__title,
.grid-stack-item[gs-w="1"][gs-h="2"] .widget__title {
  font-size: 0.8rem;
}

.grid-stack-item[gs-w="1"][gs-h="1"] .widget-stat__label,
.grid-stack-item[gs-w="1"][gs-h="2"] .widget-stat__label {
  font-size: 0.7rem;
}

.grid-stack-item[gs-w="1"][gs-h="1"] .widget-stat__value,
.grid-stack-item[gs-w="1"][gs-h="2"] .widget-stat__value {
  font-size: 1.1rem;
}

.grid-stack-item[gs-w="1"][gs-h="1"] .widget-card,
.grid-stack-item[gs-w="1"][gs-h="2"] .widget-card {
  padding: 0.5rem;
}

.grid-stack-item[gs-w="1"][gs-h="1"] .widget-card__title,
.grid-stack-item[gs-w="1"][gs-h="2"] .widget-card__title {
  font-size: 0.8rem;
}

.grid-stack-item[gs-w="1"][gs-h="1"] .widget-card__content,
.grid-stack-item[gs-w="1"][gs-h="2"] .widget-card__content {
  font-size: 0.75rem;
}

.widget__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  flex-shrink: 0;
}

.widget__title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--color-text);
  margin: 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.widget__icon {
  font-size: 1.2rem;
}

.widget__actions {
  display: flex;
  gap: 0.5rem;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.widget:hover .widget__actions {
  opacity: 1;
}

.widget__action-btn {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 6px;
  padding: 0.25rem 0.5rem;
  font-size: 0.85rem;
  color: var(--color-text-muted);
  cursor: pointer;
  transition: all 0.2s ease;
}

.widget__action-btn:hover {
  background: rgba(255, 122, 61, 0.2);
  border-color: rgba(255, 122, 61, 0.4);
  color: var(--color-text);
}

.widget__body {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  min-height: 0; /* Allows flex children to shrink */
}

/* Link Widget Specific */
.widget--link {
  justify-content: center;
  align-items: center;
  text-align: center;
  padding: 1rem;
  cursor: pointer;
  text-decoration: none;
  color: inherit;
  transition: all 0.2s ease;
}

.widget--link:hover {
  transform: scale(1.05);
}

.widget--link .widget__icon {
  font-size: 3rem;
  margin-bottom: 0.5rem;
}

.widget--link .widget__title {
  font-size: 0.9rem;
  justify-content: center;
}

.link-favicon {
  width: 48px;
  height: 48px;
  border-radius: 8px;
  object-fit: contain;
  margin-bottom: 0.5rem;
}

/* Data Widget Specific Styles */
.widget-stat {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.widget-stat__label {
  font-size: 0.85rem;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.widget-stat__value {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--color-text);
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
}

.widget-stat__change {
  font-size: 0.9rem;
  font-weight: 500;
}

.widget-stat__change--positive {
  color: #2ecc71;
}

.widget-stat__change--negative {
  color: #e74c3c;
}

/* Mini card inside widget */
.widget-card {
  background: var(--glass-bg-gradient);
  backdrop-filter: var(--backdrop-blur);
  -webkit-backdrop-filter: var(--backdrop-blur);
  border: 1px solid var(--glass-border);
  border-radius: 8px;
  padding: 0.75rem;
  transition: background 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
  position: relative;
}

.widget-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.1), transparent);
  pointer-events: none;
}

.widget-card:hover {
  background: linear-gradient(135deg, rgba(26, 29, 36, 0.5) 0%, rgba(20, 24, 32, 0.35) 100%);
  border-color: var(--glass-border-hover);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
}

.widget-card__title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--color-text);
  margin: 0 0 0.5rem;
}

.widget-card__content {
  font-size: 0.85rem;
  color: var(--color-text-muted);
  line-height: 1.4;
}

/* Empty State */
.dashboard-empty {
  text-align: center;
  padding: 4rem 2rem;
  color: var(--color-text-muted);
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 100%;
  max-width: 400px;
}

.dashboard-empty.hidden {
  display: none;
}

.dashboard-empty__icon {
  font-size: 4rem;
  margin-bottom: 1rem;
  opacity: 0.5;
}

.dashboard-empty h3 {
  margin: 0 0 0.5rem;
  color: var(--color-text);
  font-size: 1.25rem;
}

.dashboard-empty p {
  margin: 0;
  font-size: 0.95rem;
}

/* Modal Styles */
.modal {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: none;
  align-items: center;
  justify-content: center;
}

.modal[aria-hidden="false"] {
  display: flex;
}

.modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
}

.modal__content {
  position: relative;
  background: var(--glass-bg-gradient);
  backdrop-filter: var(--backdrop-blur-strong);
  -webkit-backdrop-filter: var(--backdrop-blur-strong);
  border: 1px solid var(--glass-border);
  border-radius: 16px;
  width: 90%;
  max-width: 700px;
  max-height: 80vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255, 255, 255, 0.05) inset;
  animation: modalSlideIn 0.2s ease;
}

.modal__content::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
  pointer-events: none;
  z-index: 1;
}

.modal__content--small {
  max-width: 500px;
}

@keyframes modalSlideIn {
  from {
    opacity: 0;
    transform: translateY(-20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.modal__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.5rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.modal__header h2 {
  margin: 0;
  font-size: 1.5rem;
  color: var(--color-text);
}

.modal__close {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  padding: 0.5rem 0.75rem;
  font-size: 1.25rem;
  color: var(--color-text-muted);
  cursor: pointer;
  transition: all 0.2s ease;
}

.modal__close:hover {
  background: rgba(255, 122, 61, 0.2);
  border-color: rgba(255, 122, 61, 0.4);
  color: var(--color-text);
}

.modal__body {
  padding: 1.5rem;
  overflow-y: auto;
  overflow-x: hidden;
  flex: 1;
  max-height: calc(80vh - 100px);
}

.modal__description {
  color: var(--color-text-muted);
  margin: 0 0 1rem;
  font-size: 0.95rem;
  line-height: 1.5;
}

.modal__actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 1rem;
}

.action-button--primary {
  background: rgba(255, 122, 61, 0.9);
  color: var(--color-text);
  flex: 1;
}

.action-button--primary:hover {
  background: rgba(255, 122, 61, 1);
}

/* Widget Selector */
.widget-selector {
  display: flex;
  flex-direction: column;
  gap: 0;
}

/* Widget Accordion */
.widget-accordion {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.widget-accordion-item {
  background: var(--glass-bg-gradient);
  backdrop-filter: var(--backdrop-blur);
  -webkit-backdrop-filter: var(--backdrop-blur);
  border: 1px solid var(--glass-border);
  border-radius: 12px;
  overflow: hidden;
  transition: all 0.2s ease;
  box-shadow: var(--glass-shadow);
  position: relative;
}

.widget-accordion-item::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.1), transparent);
  pointer-events: none;
}

.widget-accordion-item.is-open {
  background: linear-gradient(135deg, rgba(26, 29, 36, 0.6) 0%, rgba(20, 24, 32, 0.4) 100%);
  border-color: var(--glass-border-hover);
  box-shadow: var(--glass-shadow-hover);
}

.widget-accordion-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  cursor: pointer;
  user-select: none;
  transition: background 0.2s ease;
}

.widget-accordion-header:hover {
  background: rgba(255, 122, 61, 0.08);
}

.widget-accordion-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--color-text);
  margin: 0;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.widget-accordion-icon {
  font-size: 1.2rem;
}

.widget-accordion-arrow {
  font-size: 0.9rem;
  color: var(--color-text-muted);
  transition: transform 0.2s ease;
}

.widget-accordion-item.is-open .widget-accordion-arrow {
  transform: rotate(90deg);
}

.widget-accordion-body {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease, padding 0.3s ease;
  padding: 0 1.25rem;
}

.widget-accordion-item.is-open .widget-accordion-body {
  max-height: 500px;
  padding: 0 1.25rem 1.25rem;
  overflow-y: auto;
  overflow-x: hidden;
}

/* Custom scrollbar for accordion body */
.widget-accordion-body::-webkit-scrollbar {
  width: 6px;
}

.widget-accordion-body::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.2);
  border-radius: 3px;
}

.widget-accordion-body::-webkit-scrollbar-thumb {
  background: rgba(255, 122, 61, 0.4);
  border-radius: 3px;
}

.widget-accordion-body::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 122, 61, 0.6);
}

.widget-accordion-body {
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 122, 61, 0.4) rgba(0, 0, 0, 0.2);
}

.widget-category {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.widget-category__title {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--color-text);
  margin: 0;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

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

.widget-template {
  background: var(--glass-bg-gradient);
  backdrop-filter: var(--backdrop-blur);
  -webkit-backdrop-filter: var(--backdrop-blur);
  border: 1px solid var(--glass-border);
  border-radius: 12px;
  padding: 1.25rem;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: var(--glass-shadow);
  position: relative;
}

.widget-template::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.15), transparent);
  pointer-events: none;
}

.widget-template:hover {
  background: linear-gradient(135deg, rgba(255, 122, 61, 0.2) 0%, rgba(255, 122, 61, 0.1) 100%);
  border-color: var(--glass-border-hover);
  transform: translateY(-2px);
  box-shadow: var(--glass-shadow-hover);
}

.widget-template__icon {
  font-size: 2.5rem;
  margin-bottom: 0.75rem;
}

.widget-template__name {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--color-text);
  margin: 0 0 0.25rem;
}

.widget-template__description {
  font-size: 0.8rem;
  color: var(--color-text-muted);
  margin: 0;
}

/* Link Widget Creator */
.link-widget-creator {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.link-input {
  background: var(--glass-bg-gradient);
  backdrop-filter: var(--backdrop-blur);
  -webkit-backdrop-filter: var(--backdrop-blur);
  border: 1px solid var(--glass-border);
  border-radius: 8px;
  padding: 0.75rem;
  font-size: 0.95rem;
  color: var(--color-text);
  font-family: inherit;
  outline: none;
  transition: all 0.2s ease;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.link-input::placeholder {
  color: var(--color-text-muted);
}

.link-input:focus {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(37, 117, 252, 0.5);
}

/* Sidebar Action Buttons */
.sidebar__action-btn {
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  border-radius: 10px;
  padding: 0.65rem 0.9rem;
  color: var(--color-text-muted);
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease;
  font-size: 0.95rem;
}

.sidebar__action-btn:hover {
  background: rgba(255, 122, 61, 0.18);
  color: var(--color-text);
}

.sidebar__action-btn.is-active {
  background: rgba(37, 117, 252, 0.25);
  color: var(--color-text);
  font-weight: 500;
}

/* Edit/Resize Mode Indicator */
.edit-mode-indicator {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  background: rgba(37, 117, 252, 0.9);
  color: var(--color-text);
  padding: 0.75rem 1.25rem;
  border-radius: 999px;
  font-weight: 600;
  box-shadow: 0 4px 12px rgba(37, 117, 252, 0.4);
  z-index: 1000;
  animation: slideInRight 0.3s ease;
}

/* Resize mode styling */
.grid-stack.resize-mode .grid-stack-item-content {
  cursor: default;
}

.grid-stack.resize-mode .grid-stack-item:hover .grid-stack-item-content {
  border-color: rgba(46, 204, 113, 0.5);
  background: rgba(46, 204, 113, 0.08);
}

@keyframes slideInRight {
  from {
    opacity: 0;
    transform: translateX(100px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

/* Responsive */
@media (max-width: 768px) {
  .widget-templates {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  }

  .widget-stat__value {
    font-size: 1.5rem;
  }

  .modal__content {
    width: 95%;
    max-height: 90vh;
  }
}

