/* Dashboard → API section: key card, usage charts, limits, playground.
   Components layer, so it sits above l-dashboard.css (legacy) like ui.css. */
@layer components {
  #sec-developer .section-title { margin: 0 0 4px; }
  #sec-developer .section-subtitle { margin: 0; }

  .dapi-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 22px; }
  .dapi-head-meta { display: flex; align-items: center; gap: 10px; }
  .dapi-head-meta .chip .i { color: var(--acc); }
  .dapi-updated { font: 500 12px/1 var(--f-mono); color: var(--ink-4); }
  #dapiRefresh.is-busy .i { animation: dapi-spin .8s linear infinite; }
  @keyframes dapi-spin { to { transform: rotate(360deg); } }

  .dapi-card {
    min-width: 0; padding: 20px 22px; border-radius: var(--r-lg);
    background: var(--s1); box-shadow: var(--edge), 0 0 0 1px var(--line);
  }
  .dapi-card + .dapi-card, .dapi-grid + .dapi-card, .dapi-card + .dapi-grid, .dapi-kpis + .dapi-card { margin-top: 16px; }
  .dapi-card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; flex-wrap: wrap; margin-bottom: 16px; }
  .dapi-card-head h3 { margin: 0; font: 650 15px/1.3 var(--f-ui); color: var(--ink); letter-spacing: -.005em; }
  .dapi-card-head p { margin: 4px 0 0; font-size: 12.5px; color: var(--ink-3); }
  .dapi-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
  .dapi-grid > .dapi-card { margin-top: 0; }

  /* key */
  .dapi-key {
    display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 18px 28px; align-items: center;
    background: radial-gradient(120% 140% at 0% 0%, rgb(var(--acc-rgb) / .14), transparent 55%), var(--s1);
    box-shadow: var(--edge), 0 0 0 1px rgb(var(--acc-rgb) / .22);
  }
  .dapi-key-label { display: flex; align-items: center; gap: 8px; font: 600 11px/1 var(--f-mono); letter-spacing: .1em; text-transform: uppercase; color: var(--ink-3); }
  .dapi-key-label > .i { font-size: 15px; color: var(--acc); }
  .dapi-key-label .chip { text-transform: none; letter-spacing: 0; font-family: var(--f-ui); }
  .dapi-key-row { display: flex; align-items: center; gap: 6px; margin-top: 12px; min-width: 0; }
  .dapi-key-value {
    flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    padding: 9px 13px; border-radius: var(--r-sm); background: var(--bg); box-shadow: inset 0 0 0 1px var(--line-2);
    font: 600 14px/1.2 var(--f-mono); color: var(--ink); letter-spacing: .02em;
  }
  .dapi-key-value.is-empty { color: var(--ink-4); font-weight: 500; }
  .dapi-key-row .btn.is-on { color: var(--up); }
  .dapi-key-meta { display: flex; flex-wrap: wrap; gap: 6px 18px; margin-top: 12px; font-size: 12.5px; color: var(--ink-3); }
  .dapi-key-meta span { display: inline-flex; align-items: center; gap: 6px; }
  .dapi-key-meta .i { font-size: 14px; color: var(--ink-4); }
  .dapi-key-meta b { color: var(--ink-2); font-weight: 600; }
  .dapi-key-life { margin-top: 12px; max-width: 520px; }
  .dapi-key-actions { display: flex; align-items: flex-end; gap: 10px; }
  .dapi-key-dur { margin-right: 14px !important; }
  .dapi-key-dur { display: flex; flex-direction: column; gap: 6px; margin: 0; }
  .dapi-key-dur > span { font: 600 10.5px/1 var(--f-mono); letter-spacing: .1em; text-transform: uppercase; color: var(--ink-4); }
  .dapi-key-actions .key-duration-select, .dapi-key-actions .sel { width: 120px; }
  .dapi-key-actions .btn-primary, .dapi-key-actions .btn-delete, .dapi-key-actions .sel-btn { height: 40px; }
  .dapi-key-actions .btn-primary { white-space: nowrap; }

  /* meters: accent fill, warn / bad as it fills up */
  .dapi-meter { position: relative; height: 6px; border-radius: 99px; background: rgb(var(--acc-rgb) / .14); overflow: hidden; }
  .dapi-meter > i { display: block; height: 100%; border-radius: inherit; background: var(--acc); box-shadow: 0 0 12px rgb(var(--acc-rgb) / .55); transition: width .6s var(--ease-out); }
  .dapi-meter[data-level="warn"] { background: color-mix(in srgb, var(--hi) 16%, transparent); }
  .dapi-meter[data-level="warn"] > i { background: var(--hi); box-shadow: none; }
  .dapi-meter[data-level="bad"] { background: color-mix(in srgb, var(--down) 16%, transparent); }
  .dapi-meter[data-level="bad"] > i { background: var(--down); box-shadow: none; }

  /* tabs */
  .dapi-tabs { display: flex; width: fit-content; max-width: 100%; overflow-x: auto; scrollbar-width: none; margin: 22px 0 16px; }
  .dapi-tabs > button { height: 34px; padding: 0 14px; }
  .dapi-tabs .i { font-size: 16px; }
  .dapi-pane[hidden] { display: none; }
  .dapi-pane.is-on { animation: dashFadeIn .3s var(--ease-out) both; }

  /* KPI row */
  .dapi-kpis { display: grid; grid-template-columns: 1.6fr repeat(5, minmax(0, 1fr)); gap: 12px; }
  .dapi-kpis .kpi { min-width: 0; }
  .dapi-kpis .kpi-v { font-size: 26px; overflow: hidden; text-overflow: ellipsis; }
  .dapi-kpi-hero .kpi-v { font-size: 34px; }
  .dapi-kpi-hero .dapi-meter { margin-top: 12px; }
  .dapi-kpi-text { font-size: 20px !important; }
  .dapi-kpis .kpi-s { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .dapi-delta { font-weight: 650; }
  .dapi-delta.is-up { color: var(--up); }
  .dapi-delta.is-down { color: var(--down); }

  /* charts */
  .dapi-filters { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
  .dapi-filters .sel, .dapi-select { width: 170px; }
  .dapi-filters .sel-btn { height: 36px; }
  .dapi-plot { position: relative; height: 240px; }
  .dapi-plot-lg { height: 300px; }
  .dapi-plot-sm { height: 190px; }
  .dapi-plot canvas { width: 100% !important; }
  .dapi-plot .chart-empty { position: absolute; inset: 0; min-height: 0; }
  .dapi-trend-stats { display: flex; gap: 36px; flex-wrap: wrap; margin: -2px 0 18px; }
  .dapi-trend-stats div { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
  .dapi-trend-stats span { font: 600 10.5px/1 var(--f-mono); letter-spacing: .1em; text-transform: uppercase; color: var(--ink-4); }
  .dapi-trend-stats b { font: 750 22px/1.1 var(--f-display); font-variant-numeric: tabular-nums; color: var(--ink); }
  .dapi-trend-stats small { font-size: 12px; color: var(--ink-3); }
  .dapi-legend { display: flex; gap: 16px; margin: -6px 0 10px; font-size: 12px; color: var(--ink-3); }
  .dapi-legend span { display: inline-flex; align-items: center; gap: 7px; }
  .dapi-legend i { display: inline-block; width: 16px; height: 0; border-top: 2px solid var(--acc); }
  .dapi-legend i.sw-dash { border-top: 2px dashed var(--ink-4); }

  /* endpoints */
  .dapi-ep-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
  .dapi-ep {
    width: 100%; display: grid; grid-template-columns: minmax(0, 1fr) 96px 78px; grid-template-rows: auto auto; align-items: center; gap: 7px 14px;
    padding: 9px 10px; border-radius: var(--r-sm); background: transparent; border: 0; color: inherit; text-align: left; cursor: pointer;
    transition: background var(--t-fast);
  }
  .dapi-ep:hover { background: var(--s2); }
  .dapi-ep.is-on { background: rgb(var(--acc-rgb) / .1); box-shadow: inset 0 0 0 1px rgb(var(--acc-rgb) / .3); }
  .dapi-ep-name { display: flex; align-items: baseline; gap: 8px; min-width: 0; font-weight: 600; font-size: 13.5px; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .dapi-ep-name code { font-size: 11px; color: var(--ink-4); background: none; padding: 0; }
  .dapi-spark { width: 96px; height: 26px; grid-row: 1 / 3; grid-column: 2; }
  .dapi-ep-val { grid-row: 1 / 3; grid-column: 3; display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }
  .dapi-ep-val b { font: 700 14px/1 var(--f-ui); font-variant-numeric: tabular-nums; color: var(--ink); }
  .dapi-ep-val small { font: 600 11px/1 var(--f-mono); color: var(--ink-3); }
  .dapi-ep-bar { grid-column: 1; height: 4px; border-radius: 99px; background: var(--s3); overflow: hidden; }
  .dapi-ep-bar i { display: block; height: 100%; border-radius: inherit; background: var(--acc); }
  .dapi-ep:not(:has(.dapi-spark)) { grid-template-columns: minmax(0, 1fr) 78px; }
  .dapi-ep:not(:has(.dapi-spark)) .dapi-ep-val { grid-column: 2; }
  .dapi-endpoints .empty-state { padding: 28px 12px; }

  .dapi-foot { margin: 14px 2px 0; font-size: 12px; color: var(--ink-4); }

  /* limits */
  .dapi-windows { display: flex; flex-direction: column; gap: 16px; }
  .dapi-win-top { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; margin-bottom: 8px; font-size: 13px; color: var(--ink-2); font-weight: 550; }
  .dapi-win-top b { font: 700 15px/1 var(--f-ui); font-variant-numeric: tabular-nums; color: var(--ink); }
  .dapi-win-top small { font-weight: 500; color: var(--ink-4); font-size: 12px; }
  .dapi-win-sub { margin-top: 6px; font-size: 11.5px; color: var(--ink-4); }
  .dapi-facts { margin: 0; display: flex; flex-direction: column; }
  .dapi-facts > div { display: flex; justify-content: space-between; gap: 16px; padding: 10px 0; border-bottom: 1px solid var(--line); }
  .dapi-facts > div:last-child { border-bottom: 0; }
  .dapi-facts dt { font-size: 12.5px; color: var(--ink-3); white-space: nowrap; }
  .dapi-facts dd { margin: 0; font-size: 13px; font-weight: 550; color: var(--ink); text-align: right; overflow-wrap: anywhere; }
  .dapi-card-head .chip .i { font-size: 14px; }
  .dapi-table-wrap { overflow-x: auto; }
  .dapi-table { width: 100%; border-collapse: collapse; font-size: 13px; }
  .dapi-table th, .dapi-table td { padding: 11px 14px; text-align: right; border-bottom: 1px solid var(--line); white-space: nowrap; font-variant-numeric: tabular-nums; }
  .dapi-table thead th { font: 600 10.5px/1 var(--f-mono); letter-spacing: .1em; text-transform: uppercase; color: var(--ink-4); }
  .dapi-table tbody th { text-align: left; font-weight: 600; color: var(--ink-2); }
  .dapi-table tbody th .i { font-size: 15px; color: var(--acc); margin-right: 8px; vertical-align: -3px; }
  .dapi-table td { color: var(--ink); font-weight: 600; }
  .dapi-table th, .dapi-table td { background: transparent; }
  .dapi-table tbody th { text-transform: none; letter-spacing: 0; font: 600 13px/1.3 var(--f-ui); }
  .dapi-table tbody tr:hover > * { background: var(--s2); }
  .chip.is-warn { background: color-mix(in srgb, #ffb020 13%, transparent); color: #ffc24d; box-shadow: inset 0 0 0 1px color-mix(in srgb, #ffb020 30%, transparent); }
  .dapi-table tr:last-child > * { border-bottom: 0; }
  .dapi-month { vertical-align: middle; font: 750 18px/1.1 var(--f-display) !important; }
  .dapi-month small { display: block; margin-top: 3px; font: 500 11px/1 var(--f-ui); color: var(--ink-4); }

  /* playground inside the API section */
  #sec-developer .request-bar { margin-top: 4px; }
  #sec-developer .form-group { margin-bottom: 14px; }
  #sec-developer .form-group .sel, #sec-developer .form-group .sel-btn, #endpointSelector { width: 100%; max-width: 560px; }
  #sec-developer .response-area .code-block { margin: 0; max-height: 520px; overflow: auto; }
  .dapi-resp-meta { display: flex; align-items: center; gap: 10px; }

  @media (max-width: 1340px) {
    .dapi-kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  }
  @media (max-width: 1100px) {
    .dapi-grid { grid-template-columns: minmax(0, 1fr); }
    .dapi-key { grid-template-columns: minmax(0, 1fr); }
  }
  @media (max-width: 640px) {
    .dapi-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .dapi-kpi-hero, .dapi-kpis > .kpi:last-child { grid-column: 1 / -1; }
    .dapi-kpis .kpi-v { font-size: 22px; }
    .dapi-card { padding: 16px; }
    .dapi-key-actions { flex-wrap: wrap; }
    .dapi-key-actions .btn-primary { flex: 1; justify-content: center; }
    .dapi-tabs { width: 100%; }
    .dapi-tabs > button { flex: 1; justify-content: center; padding: 0 8px; }
    .dapi-filters { width: 100%; }
    .dapi-filters .sel, .dapi-select { flex: 1; width: auto; }
    .dapi-trend-stats { gap: 22px; }
    .dapi-trend-stats b { font-size: 18px; }
    .dapi-plot-lg { height: 240px; }
    .dapi-ep { grid-template-columns: minmax(0, 1fr) 64px 64px; gap: 6px 10px; }
    .dapi-spark { width: 64px; }
    .dapi-ep-name code { display: none; }
    .dapi-facts > div { flex-direction: column; gap: 3px; }
    .dapi-facts dd { text-align: left; }
  }
}
