/* ---------------------------------------------------------------
   Data Driven Doctor - chart system
   Categorical palette validated with the six checks on surface
   #F1F4F6: adjacent CVD dE 11.8, normal-vision dE 20.0, all 5 >= 3:1.
   The first four slots also clear the all-pairs gate.
   --------------------------------------------------------------- */

.viz-root {
  color-scheme: light;

  --surface-1: #FFFFFF;
  --surface-2: #F8FAFE;
  --page:      #F4F7FC;

  --text-primary:   #0C1A2B;
  --text-secondary: #46586E;
  --text-muted:     #7B8CA3;

  --rule:      #DCE4F0;
  --rule-soft: #EBF0F8;
  --grid:      rgba(12,26,43,.07);

  --series-1: #3B6CBF;
  --series-2: #B47825;
  --series-3: #0C6944;
  --series-4: #BC6ECE;
  --series-5: #C74C3D;

  --seq-100: #DCE6F6;
  --seq-200: #BDD0EE;
  --seq-300: #9BB7E3;
  --seq-400: #789DD6;
  --seq-500: #5583C9;
  --seq-600: #3B6CBF;
  --seq-700: #2A5296;

  --div-neg-2: #A63A2C;
  --div-neg-1: #D08D82;
  --div-mid:   #E7EAEC;
  --div-pos-1: #8DA6D5;
  --div-pos-2: #3B6CBF;

  --good:     #0F7B3D;
  --warning:  #A66A00;
  --critical: #A62B22;

  --sans: "Archivo", "Helvetica Neue", Arial, sans-serif;
  --serif: "Source Serif 4", Georgia, serif;
}

/* ---------- figure shell ---------- */

.fig {
  background: var(--surface-1);
  border: 1px solid var(--rule);
  border-radius: 14px;
  padding: 1.15rem 1.25rem 1.25rem;
  display: flex; flex-direction: column; gap: .85rem;
  min-width: 0;
}
.fig-head { display: flex; flex-direction: column; gap: .3rem; }
.fig-title {
  font-family: var(--sans); font-weight: 600; font-size: .975rem;
  font-variation-settings: "wdth" 108; letter-spacing: -.008em;
  color: var(--text-primary); margin: 0;
}
.fig-sub { font-family: var(--sans); font-size: .8125rem; color: var(--text-muted); margin: 0; }

.fig-body { position: relative; min-width: 0; }
.fig-body svg { display: block; width: 100%; height: auto; overflow: visible; }

.fig-foot {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 1rem; flex-wrap: wrap;
  border-top: 1px solid var(--rule-soft); padding-top: .7rem; margin-top: auto;
}
.fig-insight {
  font-family: var(--serif); font-size: .9rem; line-height: 1.5;
  color: var(--text-secondary); margin: 0; max-width: 62ch;
}
.fig-insight b { color: var(--text-primary); font-weight: 600; }

/* ---------- legend ---------- */

.legend { display: flex; flex-wrap: wrap; gap: .35rem 1rem; margin: 0; padding: 0; list-style: none; }
.legend li {
  display: inline-flex; align-items: center; gap: .45rem;
  font-family: var(--sans); font-size: .78rem; color: var(--text-secondary);
}
.legend i { width: 10px; height: 10px; border-radius: 2px; flex: none; }
.legend i.line { height: 3px; border-radius: 2px; width: 14px; }

/* ---------- table view ---------- */

.fig-table-toggle {
  font-family: var(--sans); font-size: .72rem; font-weight: 600;
  letter-spacing: .06em; text-transform: uppercase;
  background: none; border: 0; padding: .2rem 0; cursor: pointer;
  color: var(--text-muted); border-bottom: 1px solid var(--rule);
}
.fig-table-toggle:hover { color: var(--text-primary); }
.fig-table { display: none; overflow-x: auto; }
.fig-table[data-open="true"] { display: block; }
.fig-table table { border-collapse: collapse; width: 100%; font-family: var(--sans); font-size: .78rem; }
.fig-table th, .fig-table td {
  text-align: right; padding: .3rem .55rem; border-bottom: 1px solid var(--rule-soft);
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
.fig-table th:first-child, .fig-table td:first-child { text-align: left; }
.fig-table thead th { color: var(--text-muted); font-weight: 600; }

/* ---------- svg primitives ---------- */

.ax-line { stroke: var(--rule); stroke-width: 1; }
.grid-line { stroke: var(--grid); stroke-width: 1; }
.ax-text {
  font-family: var(--sans); font-size: 10px; font-weight: 500;
  fill: var(--text-muted);
}
.val-text {
  font-family: var(--sans); font-size: 10.5px; font-weight: 600;
  fill: var(--text-primary); font-variant-numeric: tabular-nums;
}
.ser-label {
  font-family: var(--sans); font-size: 10.5px; font-weight: 600;
  fill: var(--text-secondary);
}

/* ---------- tooltip ---------- */

.tip {
  position: absolute; z-index: 5; pointer-events: none;
  background: var(--text-primary); color: #fff;
  border-radius: 3px; padding: .5rem .65rem;
  font-family: var(--sans); font-size: .75rem; line-height: 1.45;
  box-shadow: 0 8px 24px -10px rgba(16,26,34,.6);
  opacity: 0; transition: opacity .12s ease;
  min-width: 8rem;
}
.tip[data-show="true"] { opacity: 1; }
.tip .tip-t { font-weight: 700; margin-bottom: .25rem; display: block; }
.tip .tip-r { display: flex; align-items: center; gap: .45rem; justify-content: space-between; }
.tip .tip-r span:last-child { font-variant-numeric: tabular-nums; font-weight: 600; }
.tip .tip-k { display: inline-flex; align-items: center; gap: .4rem; }
.tip .tip-k i { width: 8px; height: 8px; border-radius: 2px; flex: none; }

.crosshair { stroke: var(--text-muted); stroke-width: 1; stroke-dasharray: 3 3; }

/* ---------- stat tiles ---------- */

.tiles {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr));
  gap: 1px; background: var(--rule-soft);
  border: 1px solid var(--rule); border-radius: 14px; overflow: hidden;
}
.tile { background: var(--surface-1); padding: 1rem 1.1rem 1.05rem; display: grid; gap: .3rem; }
.tile dt {
  font-family: var(--sans); font-size: .6875rem; font-weight: 600;
  letter-spacing: .1em; text-transform: uppercase; color: var(--text-muted); margin: 0;
}
.tile dd {
  margin: 0; font-family: var(--sans); font-weight: 700;
  font-variation-settings: "wdth" 104; font-size: 1.6rem;
  letter-spacing: -.025em; font-variant-numeric: tabular-nums; line-height: 1;
}
.tile .delta {
  font-family: var(--sans); font-size: .75rem; font-weight: 600;
  display: inline-flex; align-items: center; gap: .3rem;
}
.delta.up   { color: var(--good); }
.delta.down { color: var(--critical); }
.delta.flat { color: var(--text-muted); }
.tile .spark { margin-top: .15rem; }
.tile .spark svg { display: block; width: 100%; height: 26px; }

/* ---------- status pill ---------- */

.pill {
  display: inline-flex; align-items: center; gap: .35rem;
  font-family: var(--sans); font-size: .7rem; font-weight: 600;
  letter-spacing: .05em; text-transform: uppercase;
  border-radius: 100px; padding: .18rem .5rem .2rem;
  border: 1px solid currentColor;
}
.pill.good     { color: var(--good); }
.pill.warning  { color: var(--warning); }
.pill.critical { color: var(--critical); }
.pill svg { width: 11px; height: 11px; flex: none; }

/* ---------- grid of figures ---------- */

.fig-grid { display: grid; gap: 1.25rem; }
.fig-grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.fig-grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 1000px) { .fig-grid.cols-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 780px)  { .fig-grid.cols-2, .fig-grid.cols-3 { grid-template-columns: 1fr; } }

@media print {
  .fig { break-inside: avoid; box-shadow: none; }
  .fig-table-toggle { display: none; }
  .tip { display: none; }
}

/* ---------- ask the data ---------- */

.ask {
  background: var(--surface-1); border: 1px solid var(--rule); border-radius: 18px;
  display: grid; grid-template-rows: auto 1fr auto; overflow: hidden;
}
.ask-head {
  display: flex; align-items: center; gap: .6rem; justify-content: space-between;
  padding: .8rem 1.1rem; border-bottom: 1px solid var(--rule-soft); background: var(--surface-2);
}
.ask-head b {
  font-family: var(--sans); font-weight: 600; font-size: .9rem; letter-spacing: -.006em;
}
.ask-head .live {
  display: inline-flex; align-items: center; gap: .4rem;
  font-family: var(--sans); font-size: .68rem; font-weight: 600;
  letter-spacing: .1em; text-transform: uppercase; color: var(--text-muted);
}
.ask-head .live::before {
  content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--good);
}
.ask-log {
  padding: 1.1rem; display: flex; flex-direction: column; gap: .9rem;
  min-height: 20rem; max-height: 34rem; overflow-y: auto; scroll-behavior: smooth;
}
.msg { display: flex; flex-direction: column; gap: .5rem; max-width: 100%; }
.msg.you { align-items: flex-end; }
.msg.you .bubble {
  background: #1554F0; color: #fff; border-radius: 14px 14px 4px 14px;
  padding: .55rem .85rem; font-family: var(--sans); font-size: .88rem; max-width: 32ch;
}
.msg.ddd .bubble {
  background: var(--surface-2); border: 1px solid var(--rule-soft);
  border-radius: 14px 14px 14px 4px; padding: .8rem .95rem;
  font-size: .95rem; line-height: 1.55; color: var(--text-primary); max-width: 62ch;
}
.msg.ddd .bubble b { font-weight: 600; }
.msg.ddd .bubble .src {
  display: block; margin-top: .55rem; padding-top: .5rem;
  border-top: 1px solid var(--rule-soft);
  font-family: var(--sans); font-size: .7rem; letter-spacing: .05em; color: var(--text-muted);
}
.msg .attach { width: 100%; max-width: 34rem; }
.msg .attach .fig { padding: .85rem .95rem 1rem; }
.msg .attach table.mini {
  border-collapse: collapse; width: 100%; font-family: var(--sans); font-size: .78rem;
  background: var(--surface-1); border: 1px solid var(--rule-soft); border-radius: 3px;
}
.msg .attach table.mini th, .msg .attach table.mini td {
  text-align: right; padding: .35rem .6rem; border-bottom: 1px solid var(--rule-soft);
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
.msg .attach table.mini th:first-child, .msg .attach table.mini td:first-child { text-align: left; }
.msg .attach table.mini thead th { color: var(--text-muted); font-weight: 600; }
.msg .attach table.mini tbody tr:last-child td { border-bottom: 0; }

.typing { display: inline-flex; gap: 3px; align-items: center; padding: .2rem 0; }
.typing i { width: 5px; height: 5px; border-radius: 50%; background: var(--text-muted);
  animation: blip 1.1s infinite ease-in-out; }
.typing i:nth-child(2) { animation-delay: .16s; }
.typing i:nth-child(3) { animation-delay: .32s; }
@keyframes blip { 0%,60%,100% { opacity: .25; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-3px); } }

.ask-foot { border-top: 1px solid var(--rule-soft); padding: .8rem 1.1rem 1rem; display: grid; gap: .7rem; }
.chips { display: flex; flex-wrap: wrap; gap: .4rem; }
.chip {
  font-family: var(--sans); font-size: .78rem; font-weight: 500; color: var(--text-secondary);
  background: var(--surface-2); border: 1px solid var(--rule); border-radius: 999px;
  padding: .32rem .7rem; cursor: pointer; transition: border-color .15s, color .15s;
}
.chip:hover { border-color: var(--text-secondary); color: var(--text-primary); }
.ask-form { display: flex; gap: .5rem; }
.ask-form input {
  flex: 1; min-width: 0; font-family: var(--sans); font-size: .9rem; color: var(--text-primary);
  background: var(--surface-1); border: 1px solid var(--rule); border-radius: 999px;
  padding: .6rem .95rem;
}
.ask-form input::placeholder { color: var(--text-muted); }
.ask-form button {
  font-family: var(--sans); font-weight: 600; font-size: .82rem; cursor: pointer;
  border: 1px solid #1554F0; background: #1554F0; color: #fff;
  border-radius: 999px; padding: .6rem 1.1rem;
}
.ask-form button:hover { filter: brightness(1.08); }

@media (prefers-reduced-motion: reduce) { .typing i { animation: none; opacity: .6; } }
