/* ============================================================
   AIN Custom Dashboard — visual styles
   Prefix: .dwd- (DashboardWidget)
   Designed to drop in alongside the main styles.css without
   colliding with existing classes.
   ============================================================ */

/* ── Page shell ─────────────────────────────────────────── */
.dwd-page {
  /* IMPORTANT: do NOT set `position: relative` here. The parent class
     `.scr` (in styles.css) sets `position: absolute; inset: 0` so this
     element fills the #main scroll viewport. Overriding to `relative`
     breaks that and disables overflow-y: auto. */
  padding: 20px 24px 40px;
  min-height: 600px;
}
.dwd-page::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse at 20% 0%, rgba(6, 182, 212, 0.06), transparent 50%),
    radial-gradient(ellipse at 80% 100%, rgba(139, 92, 246, 0.05), transparent 50%);
  pointer-events: none;
  z-index: 0;
}
.dwd-page > * { position: relative; z-index: 1; }

.dwd-page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
  padding: 12px 16px;
  background: linear-gradient(135deg, rgba(6, 182, 212, 0.06), rgba(139, 92, 246, 0.03));
  border: 1px solid rgba(6, 182, 212, 0.2);
  border-radius: 6px;
  backdrop-filter: blur(10px);
  flex-wrap: wrap;
}
.dwd-page-header-left,
.dwd-page-header-right {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.dwd-select {
  padding: 7px 12px;
  background: rgba(0,0,0,0.4);
  border: 1px solid rgba(6, 182, 212, 0.25);
  color: #e5e7eb;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  min-width: 220px;
}
.dwd-select:focus { outline: none; border-color: #06B6D4; box-shadow: 0 0 0 2px rgba(6,182,212,0.2); }

.dwd-btn {
  padding: 7px 14px;
  background: rgba(6, 182, 212, 0.08);
  border: 1px solid rgba(6, 182, 212, 0.25);
  color: #67e8f9;
  border-radius: 4px;
  cursor: pointer;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.5px;
  transition: all 0.18s ease;
  text-transform: uppercase;
}
.dwd-btn:hover { background: rgba(6, 182, 212, 0.18); border-color: rgba(6, 182, 212, 0.55); transform: translateY(-1px); }
.dwd-btn:active { transform: translateY(0); }
.dwd-btn:disabled { opacity: .4; cursor: not-allowed; transform: none !important; }
.dwd-btn-primary {
  background: linear-gradient(135deg, #06B6D4, #0891b2);
  border: none;
  color: #fff;
}
.dwd-btn-primary:hover { box-shadow: 0 0 16px rgba(6, 182, 212, 0.5); }
.dwd-btn-edit-active {
  background: rgba(245, 158, 11, 0.18);
  border-color: rgba(245, 158, 11, 0.55);
  color: #fbbf24;
}
.dwd-btn-edit-active:hover { background: rgba(245, 158, 11, 0.28); }
.dwd-btn-danger {
  background: rgba(239, 68, 68, 0.08);
  border-color: rgba(239, 68, 68, 0.25);
  color: #fca5a5;
}
.dwd-btn-danger:hover { background: rgba(239, 68, 68, 0.18); }

/* ── Empty state ────────────────────────────────────────── */
.dwd-empty-state {
  text-align: center;
  padding: 80px 20px;
}
.dwd-empty-icon { font-size: 64px; margin-bottom: 16px; opacity: 0.5; }
.dwd-empty-title { font-size: 16px; font-weight: 700; color: #e5e7eb; margin-bottom: 6px; }
.dwd-empty-desc { font-size: 12px; color: #9ca3af; margin-bottom: 20px; }

/* ── Grid ───────────────────────────────────────────────── */
.dwd-grid-wrap { position: relative; }
.dwd-grid {
  display: grid;
  /* grid-template-columns + grid-auto-rows + gap set inline by canvas.js */
  position: relative;
}
/* Edit mode background grid lines */
.dwd-editing .dwd-grid::before {
  content: '';
  position: absolute;
  inset: -2px;
  pointer-events: none;
  background-image:
    repeating-linear-gradient(to right,
      rgba(245, 158, 11, 0.07) 0,
      rgba(245, 158, 11, 0.07) 1px,
      transparent 1px,
      transparent calc((100% - 11 * 16px) / 12 + 16px)),
    repeating-linear-gradient(to bottom,
      rgba(245, 158, 11, 0.07) 0,
      rgba(245, 158, 11, 0.07) 1px,
      transparent 1px,
      transparent 116px);
  border-radius: 4px;
}

/* ── Widget shell ───────────────────────────────────────── */
.dwd-widget {
  background: linear-gradient(145deg, rgba(15, 23, 42, 0.85), rgba(20, 30, 50, 0.75));
  border: 1px solid rgba(6, 182, 212, 0.15);
  border-radius: 8px;
  padding: 14px 16px 16px;
  backdrop-filter: blur(10px);
  position: relative;
  overflow: hidden;
  transition: border-color 0.25s, box-shadow 0.25s, transform 0.25s;
  display: flex;
  flex-direction: column;
  animation: dwd-slide-up 0.45s cubic-bezier(0.4, 0, 0.2, 1) backwards;
}
.dwd-widget:hover {
  border-color: rgba(6, 182, 212, 0.4);
  box-shadow: 0 6px 30px rgba(6, 182, 212, 0.1);
}
.dwd-widget::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(6, 182, 212, 0.5), transparent);
}
.dwd-editing .dwd-widget {
  border-color: rgba(245, 158, 11, 0.45);
  border-style: dashed;
  cursor: move;
}
.dwd-editing .dwd-widget:hover {
  border-color: rgba(245, 158, 11, 0.75);
  transform: scale(1.01);
}
.dwd-widget.dwd-dragging {
  pointer-events: none;
}
.dwd-widget.dwd-resizing {
  outline: 2px solid #06B6D4;
}

.dwd-widget-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  flex-shrink: 0;
}
.dwd-widget-title {
  font-size: 10px;
  font-weight: 700;
  color: #67e8f9;
  letter-spacing: 1.5px;
  text-transform: uppercase;
}
.dwd-widget-actions {
  display: none;
  gap: 4px;
}
.dwd-editing .dwd-widget-actions { display: flex; }
.dwd-widget-actions button {
  width: 24px; height: 24px;
  background: rgba(0,0,0,0.4);
  border: 1px solid rgba(6, 182, 212, 0.3);
  color: #67e8f9;
  border-radius: 3px;
  cursor: pointer;
  font-size: 12px;
  display: inline-flex; align-items: center; justify-content: center;
  transition: all 0.15s;
}
.dwd-widget-actions button:hover {
  background: rgba(6, 182, 212, 0.2);
  border-color: rgba(6, 182, 212, 0.6);
}
.dwd-widget-actions .dwd-act-delete:hover {
  background: rgba(239, 68, 68, 0.3);
  border-color: rgba(239, 68, 68, 0.6);
  color: #fca5a5;
}

.dwd-widget-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.dwd-resize-handle {
  position: absolute;
  bottom: 2px; right: 2px;
  width: 14px; height: 14px;
  cursor: nwse-resize;
  display: none;
  background-image: linear-gradient(135deg, transparent 50%, rgba(245,158,11,0.6) 50%, rgba(245,158,11,0.6) 60%, transparent 60%, transparent 70%, rgba(245,158,11,0.6) 70%, rgba(245,158,11,0.6) 80%, transparent 80%);
}
.dwd-editing .dwd-resize-handle { display: block; }

/* ── Loading + empty + error ────────────────────────────── */
.dwd-loading {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}
.dwd-spinner {
  width: 24px; height: 24px;
  border: 2px solid rgba(6, 182, 212, 0.2);
  border-top-color: #06B6D4;
  border-radius: 50%;
  animation: dwd-spin 0.7s linear infinite;
}
.dwd-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  color: #6b7280;
}
.dwd-empty.dwd-err { color: #fca5a5; }

/* ── KPI ────────────────────────────────────────────────── */
.dwd-kpi { flex: 1; display: flex; flex-direction: column; justify-content: center; }
.dwd-kpi-value {
  font-size: 38px;
  font-weight: 800;
  line-height: 1;
  margin-bottom: 6px;
  text-shadow: 0 0 24px rgba(6, 182, 212, 0.3);
}
.dwd-kpi-label {
  font-size: 10px;
  color: #6b7280;
  text-transform: uppercase;
  letter-spacing: 1.2px;
}

/* ── Donut ──────────────────────────────────────────────── */
.dwd-donut-wrap {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
}
.dwd-donut-svg { width: 100%; height: 100%; max-height: 220px; }
.dwd-donut-center {
  position: absolute;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  pointer-events: none;
}
.dwd-donut-value { font-size: 24px; font-weight: 800; color: #fff; }
.dwd-donut-label { font-size: 9px; color: #6b7280; text-transform: uppercase; letter-spacing: 1px; margin-top: 2px; }
.dwd-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 10px;
  margin-top: 6px;
  font-size: 10px;
  color: #9ca3af;
  justify-content: center;
}
.dwd-legend-item { display: inline-flex; align-items: center; gap: 4px; }
.dwd-legend-dot { width: 8px; height: 8px; border-radius: 50%; }
.dwd-legend-item strong { color: #e5e7eb; font-weight: 700; margin-left: 2px; }

/* ── List ───────────────────────────────────────────────── */
.dwd-list { font-size: 11px; }
.dwd-list-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 0;
  border-bottom: 1px solid rgba(255,255,255,0.04);
  animation: dwd-slide-up 0.4s ease backwards;
}
.dwd-list-row:last-child { border-bottom: none; }
.dwd-list-name {
  flex: 1.2;
  color: #d4d4d4;
  font-weight: 500;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.dwd-list-bar {
  flex: 1;
  height: 6px;
  background: rgba(255,255,255,0.05);
  border-radius: 3px;
  overflow: hidden;
}
.dwd-list-fill {
  height: 100%;
  background: linear-gradient(90deg, #06B6D4, #0891b2);
  border-radius: 3px;
  box-shadow: 0 0 8px rgba(6, 182, 212, 0.5);
  transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}
.dwd-list-fill.high  { background: linear-gradient(90deg, #F59E0B, #d97706); box-shadow: 0 0 8px rgba(245,158,11,0.5); }
.dwd-list-fill.crit  { background: linear-gradient(90deg, #EF4444, #b91c1c); box-shadow: 0 0 8px rgba(239,68,68,0.5); }
.dwd-list-val {
  color: #67e8f9;
  font-weight: 700;
  font-size: 10px;
  min-width: 50px;
  text-align: right;
  font-family: monospace;
}

/* ── Feed (alerts / recent) ─────────────────────────────── */
.dwd-feed { font-size: 11px; overflow-y: auto; max-height: 100%; }
.dwd-feed-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-left: 2px solid;
  margin-bottom: 5px;
  background: rgba(255,255,255,0.02);
  border-radius: 0 3px 3px 0;
  animation: dwd-slide-up 0.4s ease backwards;
}
.dwd-feed-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.dwd-feed-body { flex: 1; min-width: 0; }
.dwd-feed-title {
  color: #fff;
  font-weight: 600;
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.dwd-feed-meta {
  color: #6b7280;
  font-size: 9px;
  letter-spacing: 0.3px;
}
.dwd-feed-sev { font-weight: 700; }

/* ── Status wall ────────────────────────────────────────── */
.dwd-wall {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(14px, 1fr));
  gap: 3px;
  align-content: start;
  height: 100%;
  overflow-y: auto;
}
.dwd-cell {
  aspect-ratio: 1;
  border-radius: 1px;
  cursor: pointer;
  transition: transform 0.15s;
}
.dwd-cell:hover { transform: scale(1.5); z-index: 5; position: relative; }
.dwd-cell.dwd-pulse { animation: dwd-pulse 1.5s ease-in-out infinite; }

/* ── Clock ──────────────────────────────────────────────── */
.dwd-clock {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.dwd-clock-time {
  font-size: 44px;
  font-weight: 800;
  font-family: 'Courier New', monospace;
  color: #06B6D4;
  text-shadow: 0 0 30px rgba(6, 182, 212, 0.7);
  letter-spacing: 3px;
}
.dwd-clock-date {
  font-size: 11px;
  color: #9ca3af;
  margin-top: 4px;
  letter-spacing: 2px;
}

/* ── Note ───────────────────────────────────────────────── */
.dwd-note {
  flex: 1;
  font-size: 12px;
  color: #d4d4d4;
  line-height: 1.5;
  padding: 4px 0;
  white-space: pre-wrap;
  overflow-y: auto;
}

/* ── Gauge ──────────────────────────────────────────────── */
.dwd-gauge {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}
.dwd-gauge-svg { width: 100%; max-height: 180px; }

/* ── Catalog modal ──────────────────────────────────────── */
.dwd-catalog-search {
  width: 100%;
  padding: 10px 14px;
  background: rgba(0,0,0,0.4);
  border: 1px solid rgba(6, 182, 212, 0.2);
  color: #fff;
  border-radius: 4px;
  font-size: 13px;
  margin-bottom: 14px;
}
.dwd-catalog-search:focus { outline: none; border-color: #06B6D4; box-shadow: 0 0 0 2px rgba(6,182,212,0.2); }
.dwd-catalog-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 10px;
}
.dwd-catalog-cat-header {
  grid-column: 1 / -1;
  color: #67e8f9;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  margin: 8px 0 -2px;
  padding-bottom: 4px;
  border-bottom: 1px solid rgba(6, 182, 212, 0.15);
}
.dwd-catalog-item {
  background: rgba(6, 182, 212, 0.04);
  border: 1px solid rgba(6, 182, 212, 0.15);
  border-radius: 6px;
  padding: 14px 10px;
  cursor: pointer;
  transition: all 0.18s;
  text-align: center;
  user-select: none;
}
.dwd-catalog-item:hover {
  background: rgba(6, 182, 212, 0.12);
  border-color: rgba(6, 182, 212, 0.5);
  transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(6, 182, 212, 0.18);
}
.dwd-catalog-icon {
  font-size: 28px;
  margin-bottom: 6px;
  line-height: 1;
}
.dwd-catalog-name {
  color: #fff;
  font-weight: 600;
  font-size: 11px;
  margin-bottom: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.dwd-catalog-desc {
  color: #6b7280;
  font-size: 9px;
  line-height: 1.35;
}

/* ── Animations ─────────────────────────────────────────── */
@keyframes dwd-slide-up {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes dwd-spin {
  to { transform: rotate(360deg); }
}
@keyframes dwd-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%      { opacity: 0.55; transform: scale(0.95); }
}