/* Determination – chart styles for the vanilla JS chart components.
   The host page defines the design tokens:
   --chart-1..5, --grid, --axis, --ink, --ink-2, --ink-3,
   --surface, --surface-2, --edge.
   Spacing mirrors the React ChartCard so the charts drop into a card with
   overflow:hidden and no inner padding. */

.det-chart {
  position: relative;
}

/* --- Timeseries block -------------------------------------------------- */

.det-ts-top {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 1rem 1rem 0;
  overflow-x: auto;
  scrollbar-width: none;
}
.det-ts-top::-webkit-scrollbar {
  display: none;
}
.det-ts-top .seg {
  margin-left: auto; /* right-aligned when there is room, scrollable when not */
  flex: none;
}

.det-ts-header {
  padding: 0.75rem 1rem 0;
}
.det-ts-value {
  margin: 0;
  font-size: 1.875rem;
  line-height: 2.25rem;
  font-weight: 700;
  letter-spacing: -0.025em;
  color: var(--ink);
}
.det-ts-unit {
  font-size: 1rem;
  font-weight: 500;
  color: var(--ink-3);
}
.det-ts-meta {
  margin: 0.125rem 0 0;
  font-size: 0.75rem;
  line-height: 1.1rem;
  color: var(--ink-3);
}

.det-ts-chartwrap {
  padding: 0.5rem 0.5rem 0;
}
.det-ts-canvas {
  position: relative;
  user-select: none;
  -webkit-user-select: none;
}

.det-chart-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-size: 0.75rem;
  color: var(--ink-3);
  padding: 0 1rem;
}

/* --- Segmented control (range tabs) ------------------------------------ */

.seg {
  display: inline-flex;
  border-radius: 9999px;
  background: var(--surface-2);
  border: 1px solid var(--edge);
  padding: 2px;
}
.seg-btn {
  appearance: none;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 9999px;
  padding: 4px 10px;
  margin: 0;
  font: inherit;
  font-size: 11px;
  line-height: 1.25;
  font-weight: 500;
  color: var(--ink-3);
  cursor: pointer;
  transition: color 0.15s ease;
}
.seg-btn:hover {
  color: var(--ink-2);
}
.seg-btn-active,
.seg-btn-active:hover {
  background: var(--surface);
  color: var(--ink);
  border-color: var(--edge);
  box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
}

/* --- Tooltip (timeseries + bars) ---------------------------------------- */

.det-tooltip {
  position: absolute;
  z-index: 10;
  pointer-events: none;
  transform: translateX(-50%);
  white-space: nowrap;
  border-radius: 0.75rem;
  border: 1px solid var(--edge);
  background: var(--surface);
  padding: 0.5rem 0.75rem;
  box-shadow:
    0 10px 15px -3px rgba(0, 0, 0, 0.1),
    0 4px 6px -4px rgba(0, 0, 0, 0.1);
}
.det-tooltip[hidden] {
  display: none;
}
.det-tooltip--sm {
  border-radius: 0.5rem;
  padding: 0.375rem 0.625rem;
  font-size: 0.75rem;
}
.det-tooltip-date {
  margin: 0;
  font-size: 11px;
  font-weight: 500;
  color: var(--ink-2);
}
.det-tooltip-row {
  margin: 0;
  display: flex;
  align-items: center;
  gap: 0.375rem;
  font-size: 0.75rem;
  line-height: 1.15rem;
  color: var(--ink);
}
.det-tooltip-dot {
  display: inline-block;
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 9999px;
  flex: none;
}
.det-tooltip-label {
  color: var(--ink-3);
}
.det-tooltip-val {
  font-weight: 600;
  color: var(--ink);
}

/* --- Legend chips + table toggle ---------------------------------------- */

.det-ts-legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.375rem;
  padding: 0.25rem 1rem 1rem;
}
.det-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  border-radius: 9999px;
  border: 1px solid var(--edge);
  background: var(--surface-2);
  color: var(--ink-2);
  padding: 0.25rem 0.625rem;
  margin: 0;
  font: inherit;
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  transition:
    color 0.15s ease,
    background-color 0.15s ease,
    opacity 0.15s ease;
}
.det-chip-off {
  background: transparent;
  color: var(--ink-3);
  opacity: 0.6;
}
.det-chip-dot {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 9999px;
  flex: none;
}
.det-chip-dot--dashed {
  border-radius: 2px;
}
.det-chip-off .det-chip-dot {
  opacity: 0.4;
}

.det-table-btn {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  border: 0;
  background: transparent;
  border-radius: 9999px;
  padding: 0.25rem 0.625rem;
  font: inherit;
  font-size: 11px;
  font-weight: 500;
  color: var(--ink-3);
  cursor: pointer;
  transition: color 0.15s ease;
}
.det-table-btn:hover {
  color: var(--ink-2);
}
.det-table-btn svg {
  width: 0.875rem;
  height: 0.875rem;
}

/* --- Table view ---------------------------------------------------------- */

.det-ts-tablewrap {
  max-height: 16rem;
  overflow-y: auto;
  border-top: 1px solid var(--edge);
  padding: 0.75rem 1rem;
}
.det-ts-tablewrap[hidden] {
  display: none;
}
.det-ts-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.75rem;
}
.det-ts-table th {
  text-align: left;
  font-weight: 500;
  color: var(--ink-3);
  padding: 0.25rem 0;
}
.det-ts-table th:last-child {
  text-align: right;
}
.det-ts-table td {
  padding: 0.375rem 0;
  color: var(--ink);
  border-top: 1px solid color-mix(in srgb, var(--edge) 50%, transparent);
}
.det-ts-table td:last-child {
  text-align: right;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

/* --- Bar chart ----------------------------------------------------------- */

.det-bars-row {
  display: flex;
  align-items: flex-end;
  gap: 2px;
}
.det-bars-cell {
  display: flex;
  flex: 1 1 0%;
  min-width: 0;
  height: 100%;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  cursor: pointer;
}
.det-bar {
  width: 100%;
  max-width: 1.75rem;
  border-radius: 4px 4px 0 0;
  transition: opacity 0.15s ease;
}
.det-bars-labels {
  margin-top: 0.25rem;
  display: flex;
  gap: 2px;
}
.det-bars-label {
  flex: 1 1 0%;
  min-width: 0;
  text-align: center;
  font-size: 10px;
  color: var(--ink-3);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* --- Donut --------------------------------------------------------------- */

.det-donut {
  display: flex;
  flex-wrap: wrap; /* legend drops below the ring when space is tight */
  align-items: center;
  gap: 1rem;
}
.det-donut-figure {
  position: relative;
  flex: none;
}
.det-donut-figure circle[data-seg] {
  cursor: pointer;
  transition:
    stroke-width 0.2s ease,
    opacity 0.2s ease;
}
.det-donut-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  pointer-events: none;
}
.det-donut-center-value {
  font-size: 1.125rem;
  line-height: 1.2;
  font-weight: 700;
  color: var(--ink);
}
.det-donut-center-label {
  max-width: 70%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 10px;
  color: var(--ink-3);
}
.det-donut-legend {
  list-style: none;
  margin: 0;
  padding: 0;
  min-width: 0;
  flex: 1 1 10rem; /* wraps below the ring when narrower than ~10rem */
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
}
.det-donut-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.75rem;
  transition: opacity 0.15s ease;
}
.det-donut-row--dim {
  opacity: 0.5;
}
.det-donut-swatch {
  width: 0.625rem;
  height: 0.625rem;
  flex: none;
  border-radius: 3px;
}
.det-donut-label {
  min-width: 0;
  flex: 1 1 0%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--ink-2);
}
.det-donut-value {
  font-weight: 600;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.det-donut-pct {
  width: 2.5rem;
  text-align: right;
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
}

/* --- Animations (copied from the app's globals.css so charts are
       self-contained; identical names/timings, safe to double-define) ----- */

/* Chart line draw-in (paths use pathLength=1). */
@keyframes det-draw {
  from {
    stroke-dashoffset: 1;
  }
  to {
    stroke-dashoffset: 0;
  }
}
.det-draw {
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
  animation: det-draw 0.9s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}
.det-draw-dashed {
  animation: det-fade-in 0.8s ease-out 0.35s both;
}
@keyframes det-fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}
.det-fade-in-late {
  animation: det-fade-in 0.5s ease-out 0.5s both;
}

/* Bars grow from the baseline. */
@keyframes det-grow-y {
  from {
    transform: scaleY(0);
  }
  to {
    transform: scaleY(1);
  }
}
.det-grow-y {
  animation: det-grow-y 0.5s cubic-bezier(0.2, 0.9, 0.3, 1) both;
  transform-origin: bottom;
}

@media (prefers-reduced-motion: reduce) {
  .det-draw,
  .det-draw-dashed,
  .det-fade-in-late,
  .det-grow-y {
    animation-duration: 0.01ms !important;
    animation-delay: 0ms !important;
    animation-iteration-count: 1 !important;
  }
  .det-chart *,
  .seg-btn,
  .det-chip {
    transition-duration: 0.01ms !important;
  }
}
