/* =============================================================================
   Photon Design System — patrones de dashboard
   Depende de tokens.css y styles.css.
   ============================================================================= */

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

.dash-frame {
  display: grid;
  grid-template-columns: 76px minmax(0, 1fr);
  min-height: 640px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--r-xl);
  background: var(--surface-soft);
  box-shadow: var(--shadow-card);
}
.dash-rail {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  padding: 16px 10px;
  border-right: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 55%, transparent);
}
.dash-canvas { min-width: 0; padding: 20px; }

.dash-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px;
  margin-bottom: 18px;
}
.dash-title { flex: 1; min-width: 180px; }
.dash-title h3 {
  margin: 0;
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 1.15;
}
.dash-title p { margin: 4px 0 0; font-size: 12px; color: var(--muted); }
.dash-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }

.segmented {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: color-mix(in srgb, var(--surface) 70%, transparent);
}
.segmented button {
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  padding: 6px 10px;
  font: inherit;
  font-size: 11.5px;
  font-weight: 500;
  cursor: pointer;
}
.segmented button:hover { color: var(--ink); }
.segmented button[aria-pressed="true"] {
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-soft);
}

/* ---------------------------------------------------------------- kpis */

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 10px;
}
.kpi {
  position: relative;
  min-height: 112px;
  padding: 14px 15px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface);
}
.kpi-label {
  display: block;
  margin-bottom: 8px;
  color: var(--soft);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.kpi-value {
  display: block;
  color: var(--ink);
  font-size: 28px;
  font-weight: 500;
  letter-spacing: -0.04em;
  line-height: 1;
}
.kpi-value small {
  margin-left: 3px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 400;
  letter-spacing: 0;
}
.kpi-foot { display: flex; align-items: center; gap: 7px; margin-top: 9px; }
.kpi-delta {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 7px;
  border-radius: var(--r-pill);
  font-size: 10.5px;
  font-weight: 600;
}
.kpi-delta.up { background: var(--success-soft); color: var(--success-ink); }
.kpi-delta.down { background: var(--danger-soft); color: var(--danger-ink); }
.kpi-delta.flat { background: var(--surface-sunken); color: var(--muted); }
.kpi-note { color: var(--soft); font-size: 10.5px; }
.kpi-spark {
  position: absolute;
  right: 10px;
  bottom: 8px;
  width: 76px;
  height: 32px;
  opacity: 0.9;
}
.kpi-spark path { fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------------------------------------------------------------- charts */

.dash-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.7fr) minmax(220px, 1fr);
  gap: 10px;
  margin-bottom: 10px;
}
.chart-card {
  position: relative;
  min-width: 0;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface);
}
.chart-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 12px;
}
.chart-title { margin: 0; color: var(--ink); font-size: 13.5px; font-weight: 600; }
.chart-sub { margin: 3px 0 0; color: var(--soft); font-size: 11px; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 10px; }
.chart-legend-item { display: inline-flex; align-items: center; gap: 5px; color: var(--muted); font-size: 10.5px; }
.chart-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--dot); }
.chart-svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart-grid-line { stroke: var(--chart-grid); stroke-width: 1; }
.chart-axis-text { fill: var(--chart-axis); font-family: var(--font-sans); font-size: 9px; }
.chart-axis-line { stroke: var(--chart-grid); stroke-width: 1; }
.chart-line { fill: none; stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
.chart-line.soft { stroke-width: 1.8; opacity: 0.75; }
.chart-area { opacity: 0.14; }

/* barras horizontales */
.bars { display: flex; flex-direction: column; gap: 11px; margin-top: 4px; }
.bar-row { display: grid; grid-template-columns: 88px minmax(0, 1fr) 44px; gap: 9px; align-items: center; }
.bar-label { overflow: hidden; color: var(--muted); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { display: block; height: 9px; overflow: hidden; border-radius: 99px; background: var(--surface-sunken); }
.bar-fill { display: block; height: 100%; border-radius: inherit; background: var(--bar, var(--chart-1)); }
.bar-value { color: var(--ink); font-family: var(--font-mono); font-size: 10.5px; text-align: right; }

/* donut */
.donut-row { display: flex; align-items: center; gap: 16px; }
.donut {
  position: relative;
  flex: 0 0 118px;
  width: 118px;
  height: 118px;
  border-radius: 50%;
  background: var(--donut);
}
.donut::after {
  content: "";
  position: absolute;
  inset: 18px;
  border-radius: 50%;
  background: var(--surface);
}
.donut-center {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: grid;
  place-content: center;
  text-align: center;
}
.donut-center b { display: block; color: var(--ink); font-size: 20px; font-weight: 500; letter-spacing: -0.04em; }
.donut-center span { display: block; color: var(--soft); font-size: 9.5px; text-transform: uppercase; letter-spacing: 0.06em; }
.donut-legend { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.donut-legend .chart-legend-item { justify-content: space-between; width: 100%; }
.donut-legend b { color: var(--ink); font-weight: 600; }

/* paleta */
.chart-palette { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 8px; margin-top: 14px; }
.chart-swatch { padding: 10px; border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--surface); }
.chart-swatch i { display: block; width: 100%; height: 22px; margin-bottom: 7px; border-radius: 6px; background: var(--swatch); }
.chart-swatch code { display: block; color: var(--muted); font-family: var(--font-mono); font-size: 9.5px; }

/* ---------------------------------------------------------------- tabla */

.data-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}
.data-search {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 210px;
  height: 34px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--soft);
}
.data-search input {
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 12px;
}
.data-search input::placeholder { color: var(--soft); }
.data-spacer { flex: 1; }
.data-table { font-size: 12.5px; }
.data-table th:first-child, .data-table td:first-child { width: 34px; padding-right: 0; }
.data-table th, .data-table td { padding: 11px 12px; }
.data-table td { vertical-align: middle; }
.data-table .num, .data-table th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table-wrap .data-table { min-width: 620px; }
.data-table .row-title { display: block; color: var(--ink); font-weight: 500; }
.data-table .row-sub { display: block; margin-top: 2px; color: var(--soft); font-size: 10.5px; }
.data-table .row-check { width: 14px; height: 14px; accent-color: var(--ink); }
.data-table .row-action { border: 0; background: transparent; color: var(--soft); cursor: pointer; padding: 4px; border-radius: 7px; }
.data-table .row-action:hover { background: var(--surface-sunken); color: var(--ink); }
.table-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 11px 14px;
  border-top: 1px solid var(--line);
  color: var(--soft);
  font-size: 11px;
}
.pager { display: flex; gap: 3px; margin-left: auto; }
.pager button {
  min-width: 26px;
  height: 26px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  color: var(--muted);
  font: inherit;
  font-size: 11px;
  cursor: pointer;
}
.pager button[aria-current="page"] { border-color: var(--ink); background: var(--ink); color: var(--surface); }

/* ---------------------------------------------------------------- estados */

.state-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.state-card {
  min-height: 172px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface);
}
.state-card.empty { border-style: dashed; background: color-mix(in srgb, var(--surface) 62%, transparent); text-align: left; }
.state-icon {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  margin-bottom: 12px;
  border-radius: 10px;
  background: var(--surface-sunken);
  color: var(--muted);
}
.state-card.compact { min-height: 0; }
.state-card b { display: block; color: var(--ink); font-size: 13px; font-weight: 600; }
.state-card p { margin: 4px 0 12px; color: var(--muted); font-size: 11.5px; line-height: 1.5; }
.skeleton { overflow: hidden; border-radius: 7px; background: var(--surface-sunken); position: relative; }
.skeleton::after {
  content: "";
  position: absolute;
  inset: 0;
  transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--surface) 65%, transparent), transparent);
  animation: dash-shimmer 1.5s infinite;
}
.skeleton.line { height: 10px; margin-bottom: 9px; }
.skeleton.line.w-70 { width: 70%; }
.skeleton.line.w-45 { width: 45%; }
.skeleton.block { height: 52px; margin-top: 16px; }
@keyframes dash-shimmer { to { transform: translateX(100%); } }

/* ---------------------------------------------------------------- responsivo */

@media (max-width: 1040px) {
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dash-grid { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .dash-frame { grid-template-columns: 1fr; }
  .dash-rail {
    min-width: 0;
    flex-direction: row;
    justify-content: flex-start;
    gap: 8px;
    padding: 10px 12px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }
  .dash-rail::-webkit-scrollbar { display: none; }
  .dash-rail .rail-mark { flex: 0 0 40px; }
  .dash-rail .rail-nav { flex-direction: row; flex: 0 0 auto; }
  .dash-rail .rail-item { width: 44px; height: 44px; flex-basis: 44px; }
  .dash-rail .rail-foot { flex-direction: row; margin-left: auto; flex: 0 0 auto; }
  .dash-rail .rail-item[data-label]::after,
  .dash-rail .rail-avatar[data-label]::after { display: none; }
  .dash-canvas { padding: 14px; }
  .kpi-grid, .state-grid { grid-template-columns: 1fr; }
  .chart-palette { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .donut-row { flex-wrap: wrap; }
  .data-toolbar .segmented { width: 100%; overflow-x: auto; }
}
@media (prefers-reduced-motion: reduce) {
  .skeleton::after { animation: none; }
}

/* ---------------------------------------------------------------- nota */

.callout {
  padding: 13px 16px;
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: var(--r-md);
  background: color-mix(in srgb, var(--surface) 72%, transparent);
  color: var(--muted);
  font-size: 12px;
  line-height: 1.65;
}
.callout b { color: var(--ink); font-weight: 600; }
.callout code {
  padding: 2px 5px;
  border-radius: 5px;
  background: var(--surface-sunken);
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 11px;
}
.callout a { color: var(--ink); text-decoration: underline; text-underline-offset: 3px; }
