/* Desktop & Widget styles — gridstack overrides + widget polish */

/* Make gridstack items fill height properly */
.grid-stack-item-content {
  overflow: hidden;
  border-radius: 0.75rem;
}

.grid-stack-item-content turbo-frame,
.grid-stack-item-content turbo-frame > div {
  height: 100%;
  display: flex;
  flex-direction: column;
}

/* Gridstack item inset (matches gridstack default) */
.grid-stack > .grid-stack-item > .grid-stack-item-content {
  inset: 4px;
}

/* ── Dark mode — explicit overrides ─────────────────────────────────────────
   Tailwind JIT may miss dark: classes generated from Ruby service strings.
   These rules guarantee correct dark backgrounds regardless of JIT output. */
.dark .grid-stack-item-content turbo-frame > div {
  background-color: #1f2937 !important; /* gray-800 */
  border-color: #374151 !important;     /* gray-700 */
}

/* ── Drag handle ────────────────────────────────────────────────────────── */
.widget-drag-handle {
  cursor: grab;
  user-select: none;
  transition: background-color 150ms ease, border-color 150ms ease;
}
.widget-drag-handle:active {
  cursor: grabbing;
}
.desktop-widget-shell:hover .widget-drag-handle,
.desktop-widget-shell:focus-within .widget-drag-handle {
  background: rgba(248, 250, 252, 0.98);
  border-color: #cbd5e1;
}
.desktop-widget-shell:hover .widget-drag-handle-icon,
.desktop-widget-shell:focus-within .widget-drag-handle-icon {
  border-color: #cbd5e1;
  box-shadow: 0 8px 20px -16px rgba(15, 23, 42, 0.35);
}
.grid-stack-item.is-dragging .desktop-widget-shell {
  box-shadow: 0 28px 60px -34px rgba(15, 23, 42, 0.45);
}
.grid-stack-item.is-dragging .widget-drag-handle {
  background: rgba(224, 231, 255, 0.72);
  border-color: #a5b4fc;
}
.grid-stack-item.is-dragging .widget-drag-handle-icon {
  border-color: #818cf8;
}
/* Children must not absorb events — drag must register on the handle div */
.widget-drag-handle > * {
  pointer-events: none;
}

/* ── Gridstack placeholder ──────────────────────────────────────────────── */
.grid-stack-placeholder > .placeholder-content {
  background: rgba(99, 102, 241, 0.08) !important;
  border: 2px dashed rgba(99, 102, 241, 0.35);
  border-radius: 0.75rem;
}
.dark .grid-stack-placeholder > .placeholder-content {
  background: rgba(99, 102, 241, 0.12) !important;
  border-color: rgba(99, 102, 241, 0.45);
}

/* ── Resize handles ─────────────────────────────────────────────────────── */
/* GridStack appends .ui-resizable-handle as sibling to .grid-stack-item-content.
   Must be above content (z-index) and outside the 4px inset area. */
.grid-stack-item > .ui-resizable-handle {
  z-index: 20;
}
.grid-stack-item > .ui-resizable-se,
.grid-stack-item > .ui-resizable-sw {
  bottom: 0;
  width: 20px;
  height: 20px;
  opacity: 0.4;
  transition: opacity 0.15s;
  cursor: se-resize;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 10 10'%3E%3Cpath d='M9 1L1 9M9 5L5 9' stroke='%239ca3af' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: center;
  background-size: 10px 10px;
}
.grid-stack-item > .ui-resizable-se { right: 0; }
.grid-stack-item > .ui-resizable-sw { left: 0; cursor: sw-resize; }
.grid-stack-item:hover > .ui-resizable-se,
.grid-stack-item:hover > .ui-resizable-sw {
  opacity: 1;
}
.dark .grid-stack-item > .ui-resizable-se,
.dark .grid-stack-item > .ui-resizable-sw {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 10 10'%3E%3Cpath d='M9 1L1 9M9 5L5 9' stroke='%236b7280' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E");
}

/* ── Widget loading skeleton ───────────────────────────────────────────── */
.widget-loading-card {
  display: flex;
  flex-direction: column;
  height: 100%;
  border: 1px solid #e2e8f0;
  border-radius: 1.35rem;
  background: linear-gradient(180deg, #f8fafc 0%, #ffffff 42%);
  overflow: hidden;
}

.widget-loading-header,
.widget-loading-body,
.widget-loading-item {
  display: flex;
  align-items: center;
}

.widget-loading-header {
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.875rem 1rem;
  border-bottom: 1px solid #e2e8f0;
  background: rgba(248, 250, 252, 0.95);
}

.widget-loading-body {
  flex: 1;
  flex-direction: column;
  align-items: stretch;
  gap: 0.875rem;
  padding: 1rem;
}

.widget-loading-grip {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.25rem;
  padding: 0.75rem;
  border: 1px solid #e2e8f0;
  border-radius: 0.9rem;
  background: #fff;
}

.widget-loading-grip span,
.widget-loading-dot {
  width: 0.375rem;
  height: 0.375rem;
  border-radius: 9999px;
  background: #cbd5e1;
}

.widget-loading-title,
.widget-loading-badge,
.widget-loading-line {
  position: relative;
  overflow: hidden;
  border-radius: 9999px;
  background: #e2e8f0;
}

.widget-loading-title::after,
.widget-loading-badge::after,
.widget-loading-line::after,
.widget-loading-dot::after {
  content: "";
  position: absolute;
  inset: 0;
  transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.7), transparent);
  animation: widget-loading-shimmer 1.35s infinite;
}

.widget-loading-title {
  flex: 1;
  height: 0.9rem;
}

.widget-loading-badge {
  width: 3.5rem;
  height: 1.2rem;
}

.widget-loading-line {
  width: 70%;
  height: 0.8rem;
}

.widget-loading-line-wide {
  width: 100%;
}

.widget-loading-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.widget-loading-item {
  gap: 0.625rem;
  padding: 0.875rem;
  border: 1px solid #e2e8f0;
  border-radius: 1rem;
  background: rgba(248, 250, 252, 0.8);
}

.widget-loading-item .widget-loading-line {
  width: 100%;
}

@keyframes widget-loading-shimmer {
  100% {
    transform: translateX(100%);
  }
}

@media (prefers-reduced-motion: reduce) {
  .widget-loading-title::after,
  .widget-loading-badge::after,
  .widget-loading-line::after,
  .widget-loading-dot::after {
    animation: none;
  }
}

/* ── Widget picker ─────────────────────────────────────────────────────── */
.desktop-widget-picker {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  justify-content: flex-end;
}

.desktop-widget-picker.hidden {
  display: none;
}

.desktop-widget-picker-backdrop {
  position: absolute;
  inset: 0;
  border: 0;
  background: rgba(15, 23, 42, 0.34);
  cursor: pointer;
}

.desktop-widget-picker-panel {
  position: relative;
  z-index: 1;
  display: flex;
  width: min(100%, 28rem);
  height: 100%;
  flex-direction: column;
  border-left: 1px solid #e2e8f0;
  background: rgba(255, 255, 255, 0.98);
  box-shadow: -24px 0 70px -48px rgba(15, 23, 42, 0.55);
}
