/* ============================================================================
   IPPRA KPI Tool — Screen-level components
   auth · dashboard/stats · charts · report form panels · reports table ·
   report show · admin tables. Depends on tokens.css + base.css.
   ========================================================================= */

/* ============================================================================
   AUTH (Devise sign-in / account) — centered card
   ========================================================================= */
.auth-shell {
  min-height: calc(100vh - 64px);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: var(--space-16) var(--space-6);
}
.auth-container {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  padding: var(--space-10);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border);
}
.auth-container .auth-mark {
  width: 46px; height: 46px;
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto var(--space-4);
  border-radius: var(--radius-md);
  background: var(--brand);
  color: var(--brand-contrast);
  font-family: var(--font-heading);
  font-weight: var(--weight-black);
  font-size: var(--text-lg);
}
.auth-container h2 {
  color: var(--text-heading);
  font-size: var(--text-2xl);
  margin: 0 0 var(--space-2);
  text-align: center;
}
.auth-container .auth-sub { text-align: center; color: var(--text-muted); font-size: var(--text-sm); margin-bottom: var(--space-6); }
.auth-container .field { margin-bottom: var(--space-4); }
.auth-container input[type="text"],
.auth-container input[type="email"],
.auth-container input[type="password"] {
  width: 100%;
  font-family: var(--font-body);
  font-size: var(--text-base);
  color: var(--text-heading);
  padding: var(--space-3);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.auth-container input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--focus-ring); }
.auth-container .field em { font-size: var(--text-xs); color: var(--text-muted); font-style: normal; }
.auth-remember { display: flex; align-items: center; gap: var(--space-2); font-size: var(--text-sm); color: var(--text-body); }
.auth-remember input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--brand); }
.auth-container .actions { margin-top: var(--space-6); }
.auth-container input[type="submit"] {
  width: 100%;
  background-color: var(--brand);
  color: var(--brand-contrast);
  border: none;
  padding: var(--space-4);
  font-family: var(--font-body);
  font-size: var(--text-md);
  font-weight: var(--weight-bold);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background-color var(--dur) var(--ease);
}
.auth-container input[type="submit"]:hover { background-color: var(--brand-dark); }
.auth-links { margin-top: var(--space-5); padding-top: var(--space-4); border-top: 1px solid var(--border); text-align: center; }
.auth-links a { color: var(--brand); font-size: var(--text-sm); font-weight: var(--weight-semibold); display: block; margin: var(--space-2) 0; }

/* ============================================================================
   DASHBOARD — hero, reminders, stat tiles, chart frame, quick actions
   ========================================================================= */
.dash-hero {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: var(--space-10) var(--space-8);
  text-align: center;
  margin-bottom: var(--space-5);
  position: relative;
  overflow: hidden;
}
.dash-hero::before {
  content: "";
  position: absolute; inset: 0 0 auto 0; height: 4px;
  background: linear-gradient(90deg, var(--brand), var(--accent-soft));
}
.dash-hero h1 { font-size: var(--text-3xl); color: var(--brand); margin-bottom: var(--space-2); }
.dash-hero .eyebrow {
  font-size: var(--text-xs); font-weight: var(--weight-bold); letter-spacing: var(--tracking-caps);
  text-transform: uppercase; color: var(--accent-soft); margin-bottom: var(--space-2);
}
.dash-hero .welcome { color: var(--text-muted); font-size: var(--text-md); }

/* Reminder banners (review / drafts) */
.reminder-row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-4); margin-bottom: var(--space-6); }
.reminder {
  display: flex; align-items: center; gap: var(--space-4);
  padding: var(--space-4) var(--space-5);
  border-radius: var(--radius-md);
  border: 1px solid;
}
.reminder .r-icon { font-size: var(--text-2xl); line-height: 1; flex: 0 0 auto; }
.reminder .r-body { flex: 1 1 auto; }
.reminder .r-title { font-family: var(--font-heading); font-weight: var(--weight-bold); font-size: var(--text-md); color: var(--text-heading); }
.reminder .r-sub { font-size: var(--text-sm); color: var(--text-muted); }
.reminder-warning { background: var(--certified-bg); border-color: color-mix(in srgb, var(--certified-fg) 30%, transparent); }
.reminder-info { background: var(--info-bg); border-color: color-mix(in srgb, var(--info-fg) 28%, transparent); }

/* Stat tiles */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--space-4);
  margin-bottom: var(--space-6);
}
.stat-card {
  display: block;
  background: var(--surface);
  padding: var(--space-5);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
  transition: box-shadow var(--dur) var(--ease), transform var(--dur) var(--ease);
}
/* Cards that are links keep the card look (no underline / inherited color). */
a.stat-card { color: inherit; text-decoration: none; }
.stat-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.stat-card h3 {
  font-family: var(--font-body);
  font-size: var(--text-xs); color: var(--text-muted);
  margin: 0 0 var(--space-2); font-weight: var(--weight-bold);
  text-transform: uppercase; letter-spacing: var(--tracking-wide);
}
.stat-card .stat-value {
  font-family: var(--font-heading);
  font-size: var(--text-3xl); color: var(--brand);
  font-weight: var(--weight-black); margin: 0; line-height: 1;
}
.stat-card .stat-label { font-size: var(--text-xs); color: var(--text-faint); margin-top: var(--space-2); }

/* Slim progress bar inside a stat card (e.g. Completion) */
.progress-mini { height: 6px; background: var(--surface-inset); border-radius: var(--radius-pill); overflow: hidden; margin-top: var(--space-2); }
.progress-mini span { display: block; height: 100%; background: var(--reviewed-dot); border-radius: var(--radius-pill); transition: width var(--dur) var(--ease); }

/* Dashboard stat tile with leading icon chip (home page variant) */
.metric-tile {
  display: flex; align-items: center; gap: var(--space-4);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-md); box-shadow: var(--shadow-sm);
  padding: var(--space-5);
}
.metric-tile .m-icon {
  width: 44px; height: 44px; flex: 0 0 auto;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-md); font-size: 20px;
  background: var(--brand-tint); color: var(--brand);
}
.metric-tile .m-num { font-family: var(--font-heading); font-size: var(--text-2xl); font-weight: var(--weight-black); color: var(--text-heading); line-height: 1; }
.metric-tile .m-label { font-size: var(--text-xs); font-weight: var(--weight-bold); text-transform: uppercase; letter-spacing: var(--tracking-wide); color: var(--text-muted); margin-top: var(--space-1); }

/* Card / panel container */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: var(--space-6);
  margin-bottom: var(--space-6);
}
.card > h2 { font-size: var(--text-lg); margin-bottom: var(--space-5); }

/* Chart frame */
.chart-frame { width: 100%; }
.chart-frame .chart-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--space-4); }
.chart-frame canvas { max-width: 100%; }

/* Quick actions */
.quick-actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--space-4); }
.quick-action {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--space-3);
  padding: var(--space-8) var(--space-5);
  border-radius: var(--radius-md);
  text-decoration: none;
  font-family: var(--font-heading);
  font-weight: var(--weight-bold);
  font-size: var(--text-md);
  border: 1px solid transparent;
  transition: transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease), background-color var(--dur) var(--ease);
}
.quick-action .qa-icon { font-size: 24px; }
.quick-action:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); text-decoration: none; }
.quick-action.primary { background: var(--brand); color: var(--brand-contrast); }
.quick-action.primary:hover { background: var(--brand-dark); color: var(--brand-contrast); }
.quick-action.neutral { background: var(--surface); color: var(--text-heading); border-color: var(--border-strong); }
.quick-action.neutral:hover { background: var(--surface-hover); }
.quick-action.dark { background: var(--brand-darker); color: var(--brand-contrast); }
.quick-action.dark:hover { filter: brightness(1.12); color: var(--brand-contrast); }

/* ============================================================================
   REPORT FORM — category panels + item cards (the heart of the app)
   ========================================================================= */
.report-member-bar {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-5);
  margin-bottom: var(--space-6);
}

.kpi-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-5);
  align-items: start;
}
.kpi-column { display: flex; flex-direction: column; gap: var(--space-5); min-width: 0; }

.category-section {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-5);
  transition: border-color var(--dur) var(--ease);
}
.category-section.has-items { background: var(--surface); }

.category-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--space-3);
  padding-bottom: var(--space-3);
  border-bottom: 2px solid var(--brand);
  margin-bottom: var(--space-4);
}
.category-section.collapsed .category-header { margin-bottom: 0; }
.category-title {
  font-family: var(--font-heading);
  font-size: var(--text-md);
  font-weight: var(--weight-bold);
  color: var(--brand);
  margin: 0;
  display: flex; align-items: center; gap: var(--space-2);
}
.category-title .count {
  font-family: var(--font-body);
  font-size: var(--text-2xs); font-weight: var(--weight-bold);
  background: var(--brand-tint); color: var(--brand-dark);
  padding: 1px var(--space-2); border-radius: var(--radius-pill);
}

/* Item card */
.item-form {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: var(--space-4);
  margin-bottom: var(--space-3);
}
.item-form + .item-form { margin-top: 0; }
.item-form .item-remove {
  position: absolute; top: var(--space-3); right: var(--space-3);
}
.btn-remove {
  background: transparent;
  border: 1px solid color-mix(in srgb, var(--danger) 40%, transparent);
  color: var(--danger);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease);
}
.btn-remove:hover { background: var(--danger); color: #fff; }
.item-actions { display: flex; justify-content: flex-end; margin-top: var(--space-3); }

/* form footer — sticky action bar */
.form-footer {
  display: flex; gap: var(--space-4); justify-content: center; align-items: center;
  padding: var(--space-4);
  margin: var(--space-8) calc(var(--space-6) * -1) 0;
  position: sticky; bottom: 0;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--border);
  box-shadow: 0 -6px 18px color-mix(in srgb, var(--text-heading) 7%, transparent);
}

/* ============================================================================
   REPORTS INDEX — filter bar + item table
   ========================================================================= */
.filter-bar {
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-3);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  padding: var(--space-4) var(--space-5);
  margin-bottom: var(--space-5);
}
.filter-bar .filters { display: flex; flex-wrap: wrap; gap: var(--space-3); flex: 1 1 auto; }
.filter-bar select.form-control { width: auto; min-width: 150px; }
.filter-bar .filter-actions { display: flex; gap: var(--space-3); }

.data-table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.data-table { width: 100%; border-collapse: collapse; }
.data-table thead th {
  text-align: left;
  font-family: var(--font-body);
  font-size: var(--text-2xs);
  font-weight: var(--weight-bold);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
  color: var(--brand);
  background: var(--surface-2);
  padding: var(--space-3) var(--space-5);
  border-bottom: 2px solid var(--border);
}
.data-table td { padding: var(--space-4) var(--space-5); border-bottom: 1px solid var(--border); font-size: var(--text-sm); color: var(--text-body); vertical-align: top; }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr { transition: background-color var(--dur) var(--ease); }
.data-table tbody tr:hover { background: var(--surface-hover); }
.data-table .t-date { font-weight: var(--weight-bold); color: var(--text-heading); white-space: nowrap; }
.data-table .t-sub { font-size: var(--text-xs); color: var(--text-muted); margin-top: 2px; }
.data-table .t-person { font-weight: var(--weight-bold); color: var(--brand); }
.data-table .t-actions { display: flex; gap: var(--space-2); flex-wrap: wrap; }

/* ============================================================================
   REPORT SHOW / DETAIL
   ========================================================================= */
.cert-banner {
  display: flex; align-items: center; gap: var(--space-4);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-md); box-shadow: var(--shadow-sm);
  padding: var(--space-5); margin-bottom: var(--space-5);
}
.cert-banner .c-check {
  width: 40px; height: 40px; flex: 0 0 auto;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-pill);
  background: var(--reviewed-bg); color: var(--reviewed-fg);
  font-size: 20px; font-weight: var(--weight-bold);
}
.cert-banner .c-title { font-family: var(--font-heading); font-weight: var(--weight-bold); font-size: var(--text-md); color: var(--text-heading); }
.cert-banner .c-sub { font-size: var(--text-sm); color: var(--text-muted); }

.detail-toolbar { display: flex; flex-wrap: wrap; gap: var(--space-3); margin-bottom: var(--space-5); }

.detail-group { margin-bottom: var(--space-6); }
.detail-group > h3 {
  font-family: var(--font-heading);
  font-size: var(--text-lg); color: var(--brand);
  margin-bottom: var(--space-3);
  padding-bottom: var(--space-2);
}
.detail-item {
  background: var(--surface-2);
  border-left: 3px solid var(--brand);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  padding: var(--space-4) var(--space-5);
  margin-bottom: var(--space-3);
}
.detail-item .d-date { font-family: var(--font-heading); font-weight: var(--weight-bold); font-size: var(--text-sm); color: var(--brand-dark); margin-bottom: var(--space-2); }
.detail-item .d-label { font-weight: var(--weight-bold); color: var(--text-heading); font-size: var(--text-sm); }
.detail-item .d-text { color: var(--text-body); font-size: var(--text-base); margin-top: var(--space-1); }
.detail-meta { text-align: center; color: var(--text-faint); font-size: var(--text-xs); padding: var(--space-4); }

/* ============================================================================
   ADMIN — content shell, header, stat grid, tables
   ========================================================================= */
.admin-body { background-color: var(--page-bg); }
.admin-content { max-width: var(--maxw-admin); margin: 0 auto; padding: var(--space-8) var(--space-6); }
.admin-header { margin-bottom: var(--space-6); }
.admin-header h1 { font-size: var(--text-2xl); color: var(--text-heading); margin-bottom: var(--space-1); }
.admin-header p { color: var(--text-muted); font-size: var(--text-sm); }

.admin-table-container {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  margin-bottom: var(--space-6);
}
.admin-table-header {
  padding: var(--space-5) var(--space-6);
  border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center; gap: var(--space-4);
  flex-wrap: wrap;
}
.admin-table-header h2 { font-size: var(--text-lg); color: var(--text-heading); }
.admin-table-tools { display: flex; gap: var(--space-3); align-items: center; flex-wrap: wrap; }

.admin-table { width: 100%; border-collapse: collapse; }
.admin-table thead { background-color: var(--surface-2); }
.admin-table th {
  padding: var(--space-3) var(--space-6);
  text-align: left;
  font-family: var(--font-body);
  font-size: var(--text-2xs);
  font-weight: var(--weight-bold);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
  border-bottom: 1px solid var(--border);
}
.admin-table td { padding: var(--space-3) var(--space-6); border-bottom: 1px solid var(--border); font-size: var(--text-sm); color: var(--text-body); }
.admin-table tbody tr { transition: background-color var(--dur) var(--ease); }
.admin-table tbody tr:hover { background-color: var(--surface-hover); }
.admin-table tbody tr:last-child td { border-bottom: none; }
.admin-table .cell-name { font-weight: var(--weight-bold); color: var(--text-heading); }
.admin-table .cell-muted { color: var(--text-muted); }
.admin-table .yes { color: var(--reviewed-fg); font-weight: var(--weight-bold); }
.admin-table .no { color: var(--text-faint); }

/* Admin stat value accents */
.stat-card .stat-value.is-amber { color: var(--certified-fg); }
.stat-card .stat-value.is-green { color: var(--reviewed-fg); }
.stat-card .stat-value.is-red { color: var(--draft-fg); }
.stat-card .stat-value.is-muted { color: var(--text-muted); }

/* ============================================================================
   RESPONSIVE
   ========================================================================= */
@media (max-width: 1200px) {
  .kpi-grid { grid-template-columns: 1fr; }
}
@media (max-width: 920px) {
  .reminder-row { grid-template-columns: 1fr; }
  .quick-actions { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
  .navbar { flex-direction: column; height: auto; gap: var(--space-3); padding: var(--space-4); }
  .navbar-nav { flex-wrap: wrap; justify-content: center; }
  .navbar-brand { text-align: center; }
  .nav-user-menu { padding-left: 0; margin-left: 0; border-left: none; }
  .page-wrap, .admin-content { padding: var(--space-5) var(--space-4); }
  .form-row { grid-template-columns: 1fr; }
  .filter-bar { flex-direction: column; align-items: stretch; }
  .filter-bar select.form-control { width: 100%; }
  .data-table thead { display: none; }
  .data-table, .data-table tbody, .data-table tr, .data-table td { display: block; width: 100%; }
  .data-table tr { border-bottom: 1px solid var(--border); padding: var(--space-2) 0; }
  .data-table td { border: none; padding: var(--space-1) var(--space-5); }
  .admin-table-container { overflow-x: auto; }
}
