/* ============================================================
   EduShieldID — components/cards.css
   Generic surfaces reused across every portal: .card, the KPI
   tile grid, chart placeholder, document cards, report cards.
   ============================================================ */


/* ── Card ───────────────────────────────────────────────────── */
.card {
  background: var(--clr-surface);
  border: 1px solid var(--clr-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  padding: var(--sp-6);
  transition: box-shadow var(--transition), border-color var(--transition);
}
a.card:hover,
.card.is-interactive:hover {
  box-shadow: var(--shadow-md);
  border-color: var(--clr-primary-light);
}
/* Grid rows stretch their items to the tallest panel, so a card sitting beside
   a taller sibling gets extra height whether it asked for it or not. Making
   the card a flex column lets whatever is inside claim that height (see the
   .card > *:last-child rule) instead of leaving it as a blank strip below the
   content — the "tall card, content floating at the top" shape. */
.portal-grid > .card,
.dashboard-cards > .card {
  display: flex;
  flex-direction: column;
}
.portal-grid > .card > *:last-child,
.dashboard-cards > .card > *:last-child {
  flex: 1 1 auto;
}
/* Alerting variant — e.g. the inline fraud-signal panel on the
   verification review page when an unresolved alert is open. */
.card-danger {
  border-color: var(--clr-danger);
  border-left-width: 4px;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--sp-3);
  margin-bottom: var(--sp-4);
  padding-bottom: var(--sp-4);
  border-bottom: 1px solid var(--clr-border);
}
.card-title { font-size: var(--text-lg); font-weight: var(--weight-semibold); }

/* ── KPI card ───────────────────────────────────────────────── */
/* The track minimum drives how many tiles land per row. At 180px a wide
   column produced eight-plus skinny tracks, so a six-tile set wrapped 5 + 1
   and stranded most of a row. 210px keeps the count in the 4-6 band that
   reads as a KPI strip at every width the portal targets, and `min(100%, …)`
   stops the track minimum from overflowing a container narrower than itself. */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 210px), 1fr));
  gap: var(--sp-4);
}
.kpi-card {
  background: var(--clr-surface);
  border: 1px solid var(--clr-border);
  border-radius: var(--radius-md);
  padding: var(--sp-5) var(--sp-6);
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
  text-decoration: none;
  color: inherit;
  transition: box-shadow var(--transition);
}
.kpi-card:hover { box-shadow: var(--shadow-md); text-decoration: none; }
.kpi-label { font-size: var(--text-xs); font-weight: var(--weight-medium); text-transform: uppercase; letter-spacing: .05em; color: var(--clr-text-muted); }
.kpi-value { font-size: var(--text-3xl); font-weight: var(--weight-bold); color: var(--clr-text); }
.kpi-delta { font-size: var(--text-xs); color: var(--clr-text-muted); }

/* ── Dashboard summary cards (school + student dashboards) ────── */
.dashboard-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr));
  gap: var(--sp-5);
  margin-top: var(--sp-6);
}
.dashboard-cards .card {
  position: relative;
  padding: var(--sp-5) var(--sp-6);
  border-top: 3px solid var(--clr-primary);
  transition: box-shadow var(--transition), transform var(--transition);
  /* The 2px hover rise is expressed as resting-low -> natural, so no
     negative translate is needed. The movement on hover is unchanged. */
  transform: translateY(2px);
}
.dashboard-cards .card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(0);
}
.card-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  background: var(--clr-primary-light);
  color: var(--clr-primary);
  margin-bottom: var(--sp-3);
}
.card-icon svg { width: 20px; height: 20px; }
.dashboard-cards .card h3 {
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--clr-text-muted);
  margin-bottom: var(--sp-2);
}
.dashboard-cards .card p {
  font-size: var(--text-2xl);
  font-weight: var(--weight-bold);
  color: var(--clr-primary);
  margin-bottom: 0;
}

/* ── Chart placeholder ──────────────────────────────────────── */
.chart-placeholder {
  background: var(--clr-bg);
  border: 1px dashed var(--clr-border);
  border-radius: var(--radius-md);
  height: 240px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--clr-text-muted);
  font-size: var(--text-sm);
}
.chart-placeholder::before { content: "Chart: " attr(data-chart); }

/* ── Document card (student/documents/*.html) ─────────────────── */
.doc-card {
  background: var(--clr-surface);
  border: 1px solid var(--clr-border);
  border-radius: var(--radius-md);
  padding: var(--sp-5);
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  cursor: pointer;
  transition: box-shadow var(--transition);
}
.doc-card:hover { box-shadow: var(--shadow-md); }
.doc-card .doc-icon { font-size: var(--text-3xl); }
.doc-card .doc-name { font-size: var(--text-sm); font-weight: var(--weight-semibold); overflow-wrap: anywhere; }
.doc-card .doc-meta { font-size: var(--text-xs); color: var(--clr-text-muted); overflow-wrap: anywhere; }

/* ── Report card (admin_portal/analytics + reports) ───────────── */
.report-card {
  background: var(--clr-surface);
  border: 1px solid var(--clr-border);
  border-radius: var(--radius-md);
  padding: var(--sp-5);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--sp-4);
}
.report-card h4 { font-size: var(--text-sm); font-weight: var(--weight-semibold); margin-bottom: 2px; overflow-wrap: anywhere; }
.report-card p  { font-size: var(--text-xs); color: var(--clr-text-muted); margin: 0; overflow-wrap: anywhere; }

/* ── Responsive ─────────────────────────────────────────────── */
@media (max-width: 768px) {
  .kpi-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 480px) {
  .kpi-grid { grid-template-columns: 1fr; }
}
/* Six tiles auto-fit to 5 + 1, leaving one orphaned on its own row. Three
   across is 3 + 3 from tablet width up; below that the rules above win. */
@media (min-width: 900px) {
  .kpi-grid--six { grid-template-columns: repeat(3, 1fr); }
}

/* ── Card action footer ─────────────────────────────────────── */
/* A card in a .portal-grid stretches its last child (`flex: 1 1 auto` above)
   so that CONTENT claims the leftover height rather than leaving a blank
   strip. A button is not content: as the last child it inflated into a
   full-width slab several times its natural height, which is what the
   dataset tiles on /school/data-imports/ rendered as.
   
   Wrapping the action in this makes the WRAPPER the stretching last child.
   `margin-top: auto` pushes it to the bottom so buttons line up across a row
   of tiles with descriptions of different lengths, and the button inside
   keeps its own size. */
.card-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: var(--sp-3);
  margin-top: auto;
}
/* Opts the wrapper out of the stretch rule above. Written as a more specific
   selector rather than `!important` so a page that genuinely wants a growing
   footer can still override it. */
.portal-grid > .card > .card-actions:last-child,
.dashboard-cards > .card > .card-actions:last-child {
  flex: 0 0 auto;
}

/* ── Collapsible reference card ─────────────────────────────── */
/* `<details class="card">` — column references, retention rules: material
   worth reading once and then never again. Left expanded above the form it
   put a screenful of prose between a registrar and the control they came
   for; deleted, the answer to "what goes in this column?" would be nowhere. */
details.card > summary {
  cursor: pointer;
  /* The padding belongs to the summary, not the card, so the whole header row
     is the click target rather than just the text. */
  margin: calc(var(--sp-6) * -1);
  padding: var(--sp-6);
  list-style-position: inside;
}
details.card[open] > summary {
  margin-bottom: var(--sp-4);
  border-bottom: 1px solid var(--clr-border);
}
details.card > summary:focus-visible {
  outline: 2px solid var(--clr-primary);
  outline-offset: -2px;
}
/* A card in a .portal-grid stretches its last child; a collapsed <details>
   in a normal flow does not need it, but the rule above would still make the
   table inside claim height it does not want. */
details.card > *:last-child { flex: 0 0 auto; }
