/* entity-widgets.css — Dashboard widget framework (card P2-07).
   All selectors prefixed wg- to avoid collisions.
   ------------------------------------------------------------------ */

/* Board container */
.wg-board {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 1rem;
  font-family: inherit;
}

/* Add-widget tile */
.wg-tile-add {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.75rem;
}

.wg-add-btn {
  background: none;
  border: 2px dashed var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.5rem 1.25rem;
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--text-secondary);
  transition: border-color 0.15s, color 0.15s;
}

.wg-add-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
}

/* Section label between the hero and the configurable widgets */
.wg-section-title {
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-secondary);
  padding-top: var(--space-2);
  border-top: 1px solid var(--border-soft);
}

/* Widget grid */
.wg-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1rem;
}

/* Widget card */
.wg-card {
  background: var(--bg-card);
  border: 1px solid var(--border-soft);
  border-radius: var(--r-card);
  box-shadow: 0 1px 2px rgba(2, 6, 23, 0.4);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.wg-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.75rem;
  background: var(--bg-deep);
  border-bottom: 1px solid var(--border-soft);
  gap: 0.5rem;
}

.wg-card-title {
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.wg-card-controls {
  display: flex;
  gap: 2px;
  flex-shrink: 0;
}

.wg-card-controls button {
  background: none;
  border: 1px solid transparent;
  border-radius: 3px;
  cursor: pointer;
  font-size: 0.75rem;
  padding: 1px 4px;
  color: var(--text-secondary);
  line-height: 1.4;
  transition: background 0.1s, color 0.1s;
}

.wg-card-controls button:hover {
  background: var(--bg-light);
  color: var(--text-primary);
}

.wg-btn-remove:hover {
  background: var(--danger-bg) !important;
  color: var(--danger) !important;
}

.wg-card-body {
  padding: 0.75rem;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 80px;
}

/* Number viz */
.wg-viz-number {
  font-size: 2rem;
  font-weight: 700;
  color: var(--text-primary);
  text-align: center;
}

/* Bar chart viz */
.wg-viz-bar {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  width: 100%;
  height: 80px;
  padding-bottom: 18px; /* room for labels */
  position: relative;
}

.wg-bar-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 1;
  height: 100%;
  justify-content: flex-end;
}

.wg-bar-wrap {
  width: 100%;
  display: flex;
  align-items: flex-end;
  flex: 1;
}

.wg-bar {
  width: 100%;
  background: var(--primary);
  border-radius: 2px 2px 0 0;
  min-height: 2px;
  transition: height 0.3s;
}

.wg-bar-label {
  font-size: 0.55rem;
  color: var(--text-secondary);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
  margin-top: 2px;
}

/* Line chart viz */
.wg-viz-line {
  display: block;
  max-width: 100%;
}

.wg-line-polyline {
  stroke: var(--primary);
  stroke-width: 2;
}

/* ══ P5-W1 — analytics charts (inline SVG: time-series bars, breakdown bars,
   pie). Dark-theme, responsive, native hover tooltips via <title>. ══════════ */

/* The card body for a chart should stack the SVG over its legend, top-aligned,
   and stretch full width. (The base .wg-card-body centres a single value.) */
.wg-card-body:has(.wg-chart-svg),
.wg-card-body:has(.wg-pie-wrap),
.wg-card-body:has(.wg-chart-empty) {
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  gap: 6px;
  min-height: 170px;
}

/* Responsive SVG: scales to the card width, fixed aspect via viewBox. */
.wg-chart-svg {
  display: block;
  width: 100%;
  height: auto;
  max-height: 170px;
}

.wg-chart-bar {
  transition: opacity 0.12s ease;
  cursor: default;
}
.wg-chart-bar:hover { opacity: 0.78; }

.wg-grid-line {
  stroke: var(--border-soft);
  stroke-width: 0.5;
  shape-rendering: crispEdges;
  opacity: 0.6;
}

.wg-axis-label {
  fill: var(--text-secondary);
  font-size: 7px;
  font-family: inherit;
}

/* Legend (years / categories) */
.wg-chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 10px;
  justify-content: center;
  padding-top: 2px;
}
.wg-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.62rem;
  color: var(--text-secondary);
}
.wg-legend-swatch {
  width: 9px;
  height: 9px;
  border-radius: 2px;
  flex: none;
}
.wg-legend-label {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 120px;
}

/* Pie chart */
.wg-pie-wrap {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  width: 100%;
}
.wg-pie-svg {
  flex: none;
  max-width: 130px;
  height: auto;
}
.wg-pie-wrap .wg-chart-legend {
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  flex: 1;
  min-width: 100px;
}
.wg-pie-slice {
  stroke: var(--bg-card);
  stroke-width: 1;
  transition: opacity 0.12s ease;
  cursor: default;
}
.wg-pie-slice:hover { opacity: 0.82; }

/* Empty-state inside a chart body */
.wg-chart-empty {
  font-size: 0.8rem;
  color: var(--text-secondary);
  text-align: center;
  margin: auto;
}

/* Chart-options row in the builder form (granularity + split-year). */
.wg-chart-opts {
  border-top: 1px solid var(--border-soft);
  padding-top: 0.6rem;
}
.wg-form-check {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  color: var(--text-secondary);
  cursor: pointer;
  margin-top: 4px;
}
.wg-form-check input { cursor: pointer; }

/* Narrow cards: stack the pie above its legend. */
@media (max-width: 520px) {
  .wg-pie-wrap { flex-direction: column; }
  .wg-pie-wrap .wg-chart-legend {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
  }
}

/* List viz */
.wg-list-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}

.wg-th {
  text-align: left;
  font-weight: 600;
  padding: 4px 6px;
  border-bottom: 1px solid var(--border-soft);
  color: var(--text-secondary);
  text-transform: capitalize;
}

.wg-td {
  padding: 3px 6px;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-primary);
}

.wg-tr:last-child .wg-td {
  border-bottom: none;
}

/* Error display in card body */
.wg-viz-error {
  font-size: 0.8rem;
  color: var(--danger);
  text-align: center;
}

/* Config form overlay */
.wg-form-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.wg-form {
  background: var(--bg-dark);
  border: 1px solid var(--border-soft);
  border-radius: 8px;
  box-shadow: 0 4px 24px rgba(0,0,0,.18);
  padding: 1.5rem;
  min-width: 320px;
  max-width: 420px;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.wg-form-row {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.wg-form-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.wg-form-select,
.wg-form-input {
  border: 1px solid var(--border-color);
  background: var(--bg-dark);
  color: var(--text-primary);
  border-radius: 4px;
  padding: 6px 8px;
  font-size: 0.9rem;
  width: 100%;
  box-sizing: border-box;
}

.wg-form-select:focus,
.wg-form-input:focus {
  border-color: var(--primary);
  outline: none;
}

/* Inline helper text under a builder select (e.g. break-down hint). */
.wg-form-hint {
  font-size: 0.72rem;
  color: var(--text-secondary);
  margin-top: 2px;
  line-height: 1.3;
}

.wg-form-error {
  font-size: 0.8rem;
  color: var(--danger);
  min-height: 1.1em;
}

.wg-form-btns {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
}

.wg-btn-save {
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 4px;
  padding: 6px 18px;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 600;
  transition: background 0.15s;
}

.wg-btn-save:hover {
  background: var(--primary-dark);
}

.wg-btn-cancel {
  background: var(--bg-light);
  color: var(--text-primary);
  border: none;
  border-radius: 4px;
  padding: 6px 14px;
  cursor: pointer;
  font-size: 0.9rem;
  transition: background 0.15s;
}

.wg-btn-cancel:hover {
  background: var(--border-color);
}

/* ══ CRM redesign W5 — "what needs me today" hero ══════════════════════════
   Sits above the configurable widget grid. Atoms (avatar) from crm-design.css. */
.wg-hero {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

/* Greeting row */
.wg-hero-top {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-wrap: wrap;
}
.wg-hero-greet { flex: 1; min-width: 0; }
.wg-hero-greeting {
  font-size: var(--text-xl);
  font-weight: 800;
  letter-spacing: -0.015em;
  color: var(--text-primary);
  margin: 0;
}
.wg-hero-sub {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  margin-top: 2px;
}
.wg-streak {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 36px;
  padding: 0 15px;
  border-radius: var(--r-pill);
  background: rgba(245, 158, 11, 0.12);
  border: 1px solid rgba(245, 158, 11, 0.35);
  color: #fbbf24;
  font-size: var(--text-sm);
  font-weight: 800;
  flex: none;
}
.wg-streak.is-paused {
  background: rgba(100, 116, 139, 0.14);
  border-color: var(--border-soft);
  color: var(--text-secondary);
}
.wg-streak-flame { font-size: 14px; filter: saturate(1.1); }

/* KPI cards */
.wg-kpis {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-2);
}
.wg-kpi {
  background: var(--bg-card);
  border: 1px solid transparent;
  border-radius: var(--r-card);
  padding: var(--space-3) var(--space-4);
}
.wg-kpi-link { cursor: pointer; transition: background 0.15s ease, border-color 0.15s ease; }
.wg-kpi-link:hover {
  background: color-mix(in srgb, var(--bg-card) 82%, var(--bg-light));
  border-color: var(--border-soft);
}
.wg-kpi-link:focus-visible { outline: 2px solid #93c5fd; outline-offset: 2px; }
.wg-kpi-label {
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-secondary);
}
.wg-kpi-big {
  font-size: var(--text-lg);
  font-weight: 800;
  color: var(--text-primary);
  margin-top: 6px;
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
}
.wg-kpi-sub { font-size: var(--text-xs); color: var(--text-secondary); margin-top: 2px; }
.wg-kpi-sub.is-danger { color: var(--danger-soft); }

/* Needs-contact queue */
.wg-hero-queue {
  background: var(--bg-dark);
  border: 1px solid var(--border-soft);
  border-radius: var(--r-card);
  padding: var(--space-3) var(--space-4) var(--space-2);
}
.wg-queue-title {
  font-size: var(--text-sm);
  font-weight: 800;
  color: var(--text-primary);
  margin-bottom: var(--space-1);
}
.wg-queue-list { display: flex; flex-direction: column; }
.wg-queue-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-1);
  border-top: 1px solid var(--bg-card);
  cursor: pointer;
  min-height: var(--touch);
  border-radius: var(--radius-md);
  transition: background 0.12s ease;
}
.wg-queue-row:first-child { border-top: none; }
.wg-queue-row:hover { background: color-mix(in srgb, var(--primary) 8%, transparent); }
.wg-queue-row:focus-visible { outline: 2px solid #93c5fd; outline-offset: -2px; }
.wg-queue-text { flex: 1; min-width: 0; }
.wg-queue-name {
  font-size: var(--text-sm);
  font-weight: 700;
  color: var(--text-primary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.wg-queue-reason {
  font-size: var(--text-xs);
  color: var(--signal-contact);
  margin-top: 1px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.wg-queue-chev { color: var(--text-secondary); font-size: var(--text-lg); flex: none; }
.wg-queue-empty {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  padding: var(--space-3) var(--space-1);
}

/* Responsive */
@media (max-width: 1023px) {
  .wg-kpis { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 767px) {
  .wg-streak { width: 100%; justify-content: center; }
}
