/*
 * system/styles/app.css
 * Dashboard engine styles. Requires neo-ui.css loaded first.
 */

/* ── Body ── */

body {
  font-family: var(--nu-font);
  background:
    radial-gradient(circle at 50% 0%, rgba(23, 105, 255, 0.09), transparent 34rem),
    #ffffff;
  color: var(--nu-color-text);
  min-height: 100vh;
  padding: 0 2rem 2rem;
}

/* ── Dashboard header ── */

.ds-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--nu-sp-8) 0;
  margin: 0 8px;
  position: relative;
}

.ds-header-actions { display: flex; align-items: center; gap: 10px; }

.ds-header-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px;
  border: none;
  background: none;
  border-radius: var(--nu-r-md);
  color: rgba(26, 26, 24, 0.6);
  cursor: pointer;
  transition: background var(--nu-t);
}
.ds-header-btn:hover { background: rgba(26, 26, 24, 0.07); color: var(--nu-color-text); }
.ds-header-btn svg { width: 26px; height: 26px; stroke-width: 2.5; }

/* ── Dashboard avatar ── */

.ds-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--nu-color-accent), #2563eb);
  border: 2px solid rgba(255, 255, 255, 0.7);
  box-shadow: 0 2px 10px rgba(99, 60, 219, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
  font-weight: 600;
  color: var(--nu-color-surface);
  cursor: pointer;
  user-select: none;
  flex-shrink: 0;
  position: relative;
  z-index: 10000;
}

/* ── Dashboard brand ── */

.ds-brand { display: flex; flex-direction: column; align-items: flex-start; }

.ds-brand-name {
  font-size: var(--nu-text-3xl);
  font-weight: 700;
  letter-spacing: 0.03em;
  color: var(--nu-color-text);
  line-height: 1;
}

.ds-brand-tagline {
  display: flex;
  align-items: baseline;
  gap: var(--nu-sp-1);
  padding-left: 14px;
  margin-top: 2px;
}

.ds-brand-tagline-by {
  font-size: var(--nu-text-lg);
  color: var(--nu-color-text);
  font-weight: 500;
}

.ds-brand-tagline-link { text-decoration: none; }
.ds-brand-tagline-link:hover { opacity: 0.8; }
.ds-brand-tagline-img { height: 20px; display: block; }

.ds-brand-badge {
  background: var(--nu-color-muted);
  color: var(--nu-color-surface);
  font-size: 6px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: var(--nu-r-sm);
  position: relative;
  top: 12px;
  left: -30px;
}

/* ── Dashboard title ── */

.ds-title-wrap { margin: 0 8px 1.5rem; }

.ds-title {
  font-size: var(--nu-text-4xl);
  font-weight: 500;
  outline: none;
  border-radius: var(--nu-r-sm);
  padding: 2px 6px;
  margin: 0 0 0 -6px;
  cursor: text;
  transition: background var(--nu-t);
}

.ds-title:empty::before {
  content: attr(data-placeholder);
  color: var(--nu-color-placeholder);
  pointer-events: none;
}

.ds-title[contenteditable="true"]:hover,
.ds-title[contenteditable="true"]:focus {
  background: rgba(26, 26, 24, 0.06);
}

/* ── Lock button ── */

.ds-lock-btn {
  height: 30px; padding: 0 14px;
  border: 1.5px solid rgba(26,26,24,0.6); border-radius: var(--nu-r-md);
  background: var(--nu-color-surface); cursor: pointer; color: var(--nu-color-text);
  font-size: var(--nu-text-base); font-weight: 600; font-family: inherit;
  transition: background var(--nu-t), border-color var(--nu-t);
  min-width: 60px;
}
.ds-lock-btn:hover { background: var(--nu-color-surface-hover); border-color: var(--nu-color-placeholder); }

/* ── Grid ── */

.ds-grid { padding: 0; }

.grid-stack-item,
.grid-stack-item-content { cursor: default !important; }

.grid-stack-item-content {
  overflow: visible !important;
  border-radius: var(--nu-r-lg);
  transition: box-shadow 0.15s;
}

.grid-stack-item:hover .grid-stack-item-content {
  box-shadow: 0 0 0 1px rgba(26,26,24,0.18), 0 0 12px 5px rgba(26,26,24,0.07);
  transition: box-shadow 0.12s 0.25s;
}

.grid-stack-item:has(.blk-move-btn:hover) .grid-stack-item-content,
.grid-stack-item:has(.blk-menu-btn:hover) .grid-stack-item-content,
.grid-stack-item:has(.ui-resizable-se:hover) .grid-stack-item-content {
  box-shadow: 0 0 0 1px rgba(26,26,24,0.45), 0 0 14px 6px rgba(26,26,24,0.13);
}

.ds-locked .grid-stack-item:hover .grid-stack-item-content,
.ds-locked .grid-stack-item:has(.blk-move-btn:hover) .grid-stack-item-content {
  box-shadow: none;
}

/* dragged widget */
.grid-stack-item.ui-draggable-dragging {
  opacity: 1 !important;
}

/* resizing widget */
.grid-stack-item.ui-resizable-resizing {
  opacity: 1 !important;
}

/* placeholder while moving/resizing */
.grid-stack-placeholder > .placeholder-content {
  opacity: 1 !important;
  background: rgba(26,26,26,0.06) !important;
}

.grid-stack-item-content {
  opacity: 1 !important;
}

/* ── Block host ── */

ds-block-host {
  display: flex;
  flex-direction: column;
  height: 100%;
  position: relative;
}

.blk-handles {
  position: absolute;
  top: 0; left: 0; right: 0;
  z-index: 20;
  pointer-events: none;
}

.blk-move-btn,
.blk-menu-btn {
  position: absolute;
  width: 24px; height: 24px;
  background: var(--nu-color-ink);
  border-radius: var(--nu-r-sm);
  opacity: 0; visibility: hidden;
  transition: opacity 0.12s, visibility 0s 0.13s;
  pointer-events: auto;
  display: flex; align-items: center; justify-content: center;
}

.blk-move-btn {
  top: -12px; left: -12px;
  color: var(--nu-color-surface);
  font-size: 13px;
  cursor: grab;
}
.blk-move-btn:active { cursor: grabbing; }

.blk-menu-btn {
  top: -12px; right: -12px;
  background: var(--nu-color-ink);
  border: none;
  color: var(--nu-color-surface);
  cursor: pointer;
  z-index: 21;
}
.blk-menu-btn svg { stroke: var(--nu-color-surface); }

.blk-move-btn:hover,
.blk-resize-btn:hover,
.blk-menu-btn:hover { background: var(--nu-color-ink-hover); }

.grid-stack-item:hover .blk-move-btn,
.grid-stack-item:hover .blk-menu-btn {
  opacity: 1; visibility: visible;
  transition: opacity 0.12s 0.2s, visibility 0s 0.2s;
}

/* ── GridStack resize handle — corner box ── */
.grid-stack-item .ui-resizable-handle.ui-resizable-se {
  width: 24px; height: 24px;
  background: var(--nu-color-ink);
  border-radius: var(--nu-r-sm);
  bottom: -4px !important; right: -4px !important;
  opacity: 0; visibility: hidden;
  transition: opacity 0.12s, visibility 0s 0.13s;
  display: flex; align-items: center; justify-content: center;
  transform: none;
}

.grid-stack-item .ui-resizable-handle.ui-resizable-se::after {
  content: "";
  position: absolute;
  width: 8px; height: 8px;
  border-right: 2px solid var(--nu-color-surface);
  border-bottom: 2px solid var(--nu-color-surface);
}

.grid-stack-item:hover .ui-resizable-handle.ui-resizable-se {
  opacity: 1; visibility: visible;
  transition: opacity 0.12s 0.2s, visibility 0s 0.2s;
}

/* Block menu popup */
.blk-menu-popup {
  display: none;
  position: absolute;
  top: 14px; right: -12px;
  background: var(--nu-color-surface);
  border: 1px solid var(--nu-color-border);
  border-radius: var(--nu-r-md);
  box-shadow: var(--nu-shadow-md);
  z-index: 9999;
  min-width: 120px;
  padding: var(--nu-sp-1) 0;
}
.blk-menu-popup.open { display: block; }

.blk-menu-item {
  padding: 7px 14px;
  font-size: var(--nu-text-base);
  cursor: pointer;
  white-space: nowrap;
}
.blk-menu-item:hover { background: var(--nu-color-surface-alt); }
.blk-menu-item--danger { color: var(--nu-color-danger); }

/* Render area fills the block */
.blk-render {
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* ── Header block ── */

.blk-header-wrap {
  display: flex;
  align-items: center;
  height: 100%;
  padding: 8px 16px;
}

.blk-header-text {
  outline: none;
  width: 100%;
  font-weight: 600;
  border-radius: var(--nu-r-xs);
  padding: 2px 4px;
  margin: 0 -4px;
}
.blk-header-text:empty::before {
  content: attr(data-placeholder);
  color: var(--nu-color-placeholder);
  font-weight: 400;
}
.blk-header-text[contenteditable="true"]:focus {
  background: rgba(26, 26, 24, 0.05);
}
h1.blk-header-text { font-size: var(--nu-text-4xl); }
h2.blk-header-text { font-size: var(--nu-text-2xl); }
h3.blk-header-text { font-size: var(--nu-text-xl); }

/* ── Trend block ── */

.blk-trend {
  display: flex;
  flex-direction: column;
  height: 100%;
  background: var(--nu-color-surface);
  border: 1px solid var(--nu-color-border);
  border-radius: var(--nu-r-lg);
  padding: 14px 16px 10px;
}

.blk-trend-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  flex-shrink: 0;
}

.blk-trend-title {
  font-size: var(--nu-text-base);
  font-weight: 600;
  color: var(--nu-color-text);
}

.blk-trend-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.blk-chart-wrap {
  flex: 1;
  min-height: 0;
  position: relative;
}

/* ── Funnel block ── */

.blk-funnel {
  display: flex;
  flex-direction: column;
  height: 100%;
  background: var(--nu-color-surface);
  border: 1px solid var(--nu-color-border);
  border-radius: var(--nu-r-lg);
  padding: 14px 16px 10px;
}

.blk-funnel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  flex-shrink: 0;
}

.blk-funnel-title {
  font-size: var(--nu-text-base);
  font-weight: 600;
  color: var(--nu-color-text);
}

.blk-funnel-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* ── Lifecycle block ── */

.blk-lifecycle {
  display: flex;
  flex-direction: column;
  height: 100%;
  background: var(--nu-color-surface);
  border: 1px solid var(--nu-color-border);
  border-radius: var(--nu-r-lg);
  padding: 14px 16px 10px;
}

.blk-lifecycle-header {
  display: flex;
  align-items: center;
  margin-bottom: 10px;
  flex-shrink: 0;
}

.blk-lifecycle-title {
  font-size: var(--nu-text-base);
  font-weight: 600;
  color: var(--nu-color-text);
}

.blk-lifecycle-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* ── Stickiness block ── */

.blk-stickiness {
  display: flex;
  flex-direction: column;
  height: 100%;
  background: var(--nu-color-surface);
  border: 1px solid var(--nu-color-border);
  border-radius: var(--nu-r-lg);
  padding: 14px 16px 10px;
}

.blk-stickiness-header {
  display: flex;
  align-items: center;
  margin-bottom: 10px;
  flex-shrink: 0;
}

.blk-stickiness-title {
  font-size: var(--nu-text-base);
  font-weight: 600;
  color: var(--nu-color-text);
}

.blk-stickiness-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* ── Retention block ── */

.blk-retention {
  display: flex;
  flex-direction: column;
  height: 100%;
  background: var(--nu-color-surface);
  border: 1px solid var(--nu-color-border);
  border-radius: var(--nu-r-lg);
  padding: 14px 16px 10px;
}

.blk-retention-header {
  display: flex;
  align-items: center;
  margin-bottom: 10px;
  flex-shrink: 0;
}

.blk-retention-title {
  font-size: var(--nu-text-base);
  font-weight: 600;
  color: var(--nu-color-text);
}

.blk-retention-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* ── Paragraph block ── */

.blk-paragraph-wrap {
  display: flex;
  flex-direction: column;
  height: 100%;
  padding: 8px 16px;
  overflow: hidden;
}

.blk-paragraph-text {
  outline: none;
  width: 100%;
  height: 100%;
  font-size: var(--nu-text-base);
  line-height: 1.6;
  color: var(--nu-color-text);
  white-space: pre-wrap;
  overflow-y: auto;
  border-radius: var(--nu-r-xs);
  padding: 2px 4px;
  margin: 0 -4px;
}

.blk-paragraph-text:empty::before {
  content: attr(data-placeholder);
  color: var(--nu-color-placeholder);
}

.blk-paragraph-text[contenteditable="true"]:focus {
  background: rgba(26, 26, 24, 0.05);
}

/* ── Toolbar popups ── */

.tb-popup {
  padding: 14px 16px 12px;
}

.tb-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin: 14px -16px 0;
  padding: 10px 16px 0;
}

/* ── Toolbar profile ─────────────────────────────── */

.tb-profile-views { display: none; }

.tb-profile-greeting {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin: 0 -16px;
  padding: 0 62px 12px 16px;
  border-bottom: 1px solid var(--nu-color-border-soft);
}
.tb-profile-greeting-hi   { font-size: var(--nu-text-xs); color: var(--nu-color-muted); font-weight: 500; }
.tb-profile-greeting-name { font-size: var(--nu-text-lg); font-weight: 600; color: var(--nu-color-text); }

.tb-profile-menu {
  padding: 4px 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.tb-profile-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--nu-r-md);
  font-size: var(--nu-text-base);
  font-weight: 500;
  color: var(--nu-color-text);
  background: none;
  border: none;
  width: 100%;
  text-align: left;
  font-family: inherit;
  cursor: pointer;
  transition: background var(--nu-t-fast);
}
.tb-profile-item:hover            { background: var(--nu-color-surface-alt); }
.tb-profile-item--danger          { color: var(--nu-color-danger-dark); }
.tb-profile-item--danger:hover    { background: var(--nu-color-danger-soft); }
.tb-profile-item-icon             { width: 20px; text-align: center; color: var(--nu-color-muted); flex-shrink: 0; }
.tb-profile-item-label            { flex: 1; }
.tb-profile-item-arrow            { color: var(--nu-color-muted); font-size: var(--nu-text-sm); }
.tb-profile-optional              { opacity: 0.5; font-size: .85em; }

/* ── Toolbar link ─────────────────────────────────── */

.tb-link-views { display: none; }
.tb-link-qr    { display: flex; justify-content: center; padding: 4px 0 8px; }
.tb-link-error { font-size: var(--nu-text-sm); color: var(--nu-color-danger); }

/* ── Add block picker ── */

.ds-picker {
  padding: 8px 4px;
  min-width: 200px;
}
.ds-picker-title {
  font-size: var(--nu-text-xs);
  font-weight: 600;
  color: var(--nu-color-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 4px 12px 8px;
}
.ds-picker-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  cursor: pointer;
  border-radius: var(--nu-r-sm);
}
.ds-picker-item:hover { background: var(--nu-color-surface-alt); }
.ds-picker-icon { font-size: 18px; width: 24px; text-align: center; }
.ds-picker-name { font-size: var(--nu-text-base); font-weight: 500; }
.ds-picker-desc { font-size: var(--nu-text-xs); color: var(--nu-color-muted); }

/* ── Editor panel (inside nu-surface) ── */

.ds-editor-actions {
  flex: 0 0 auto;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--nu-color-border);
}

/* ── Trend editor ── */

.te-series-block { display: flex; flex-direction: column; }

.te-series-row,
.te-filter-row,
.te-breakdown-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.te-series-color {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  flex-shrink: 0;
}

.te-series-filters {
  padding: 4px 0 2px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.te-label-input { width: 80px; flex-shrink: 0; }

.te-icon-btn { padding: 0 8px; height: 28px; flex-shrink: 0; }

.te-add-sub-btn {
  font-size: var(--nu-text-xs);
  color: var(--nu-color-muted);
  padding: 2px 4px;
  height: auto;
}
.te-add-sub-btn:hover { color: var(--nu-color-text); }

/* ── Trend table ── */

.blk-table-wrap { flex: 1; min-height: 0; overflow-y: auto; }

.blk-table { width: 100%; border-collapse: collapse; }

.blk-table thead th {
  padding: 9px 14px;
  box-shadow: inset 0 -2px 0 var(--nu-color-border-soft);
  font-size: var(--nu-text-xs);
  font-weight: 600;
  color: var(--nu-color-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  text-align: left;
  white-space: nowrap;
  position: sticky;
  top: 0;
  background: var(--nu-color-surface);
}

.blk-table thead th.blk-dt-val { text-align: right; }

.blk-table tbody tr:hover td { background: var(--nu-color-bg); }

.blk-table tbody td {
  padding: 9px 14px;
  border-bottom: 1px solid var(--nu-color-border-soft);
  font-size: var(--nu-text-base);
  color: var(--nu-color-text);
  vertical-align: middle;
}

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

.blk-table td.blk-dt-val   { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.blk-table td.blk-dt-total { font-weight: 600; }

.blk-th-sort { cursor: pointer; user-select: none; }
.blk-th-sort:hover { color: var(--nu-color-text); }

.blk-sort-icon { margin-left: 4px; opacity: 0.35; }
.blk-sort-icon--active { opacity: 1; }

.blk-series-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex-shrink: 0; }
.blk-dt-sub     { font-size: var(--nu-text-xs); color: var(--nu-color-muted); margin-top: 1px; }

/* ── Schema editor ── */

.dse-color-input {
  width: 48px;
  height: var(--nu-field-h);
  padding: 2px;
  border: 1px solid var(--nu-color-border);
  border-radius: var(--nu-r-md);
  cursor: pointer;
}

.dse-textarea {
  resize: vertical;
  height: auto;
}
