/* ==========================================================================
   LTT Dashboard — Stylesheet
   ========================================================================== */

/* ─── Design tokens ─────────────────────────────────────────────────────────── */
:root {
  --bg:      #f6f8fb;
  --card:    #ffffff;
  --ink:     #1f2937;
  --muted:   #5b6b84;
  --line:    #e5e7eb;
  --brand:   #16406f;
  --brand2:  #007fff;
  --success: #1f7a4d;
  --warn:    #b26a00;
  --danger:  #b42318;

  /* Layout */
  --page-max:     1600px;
  --page-gutter:  28px;
  --page-gap:     18px;
}

/* ─── Reset ──────────────────────────────────────────────────────────────────── */
* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ─── Page layout ────────────────────────────────────────────────────────────── */
main {
  width: min(var(--page-max), calc(100% - var(--page-gutter) * 2));
  margin: var(--page-gap) auto;
  flex: 1;
}

.grid {
  display: grid;
  gap: var(--page-gap);
}

.cols {
  display: grid;
  grid-template-columns: 1.2fr 0.9fr;
  gap: var(--page-gap);
}

.row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

.links-row { margin-top: 14px; }

.controls {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  align-items: end;
}

/* ─── Header ─────────────────────────────────────────────────────────────────── */
.app-header {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 16px;
  align-items: center;
  padding: 14px 24px;
  background: linear-gradient(135deg, var(--brand), var(--brand2));
  color: #fff;
  box-shadow: 0 4px 16px rgba(0,0,0,0.08);
}

.logo {
  width: 80px;
  height: 80px;
  object-fit: contain;
  border-radius: 12px;
  padding: 6px;
}

.titles h1 {
  margin: 0;
  font-size: 1.6rem;
}

.subtitle {
  margin: 4px 0 0;
  opacity: 0.92;
  font-size: 0.95rem;
}

/* ─── Nav ────────────────────────────────────────────────────────────────────── */
.nav {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
}

.nav-link {
  color: #fff;
  text-decoration: none;
  padding: 7px 12px;
  border-radius: 999px;
  background: rgba(255,255,255,0.12);
  font-size: 0.88rem;
  white-space: nowrap;
  transition: background 0.15s;
}

.nav-link:hover,
.nav-link.active {
  background: rgba(255,255,255,0.26);
}

/* ─── Card ───────────────────────────────────────────────────────────────────── */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px;
  box-shadow: 0 8px 20px rgba(16,24,40,0.06);
}

.card-link {
  transition: box-shadow 0.15s, transform 0.1s;
}

.card-link:hover {
  box-shadow: 0 12px 28px rgba(16,24,40,0.1);
  transform: translateY(-2px);
}

/* ─── Typography ─────────────────────────────────────────────────────────────── */
.lead  { font-size: 1rem; color: #334155; }
.tiny  { font-size: 0.87rem; color: var(--muted); }
.muted { color: var(--muted); }
.mono  { font-family: Consolas, Monaco, "Courier New", monospace; }

/* ─── Form elements ──────────────────────────────────────────────────────────── */
label {
  display: block;
  margin-bottom: 6px;
  font-weight: 600;
  color: #334155;
}

input, select, button, textarea { font: inherit; }

input[type="text"],
input[type="search"],
select,
textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #d7dce3;
  border-radius: 12px;
  background: #fff;
  color: var(--ink);
  height: 44px;
}

textarea { height: auto; }

/* ─── Buttons ────────────────────────────────────────────────────────────────── */
.btn, button {
  appearance: none;
  border: none;
  border-radius: 12px;
  padding: 10px 14px;
  background: #e9eef6;
  color: #1f2937;
  cursor: pointer;
  font-weight: 600;
  transition: filter 0.12s;
}

.btn:hover, button:hover { filter: brightness(0.95); }

.btn.primary, button.primary { background: var(--brand); color: #fff; }
.btn.secondary, button.secondary { background: #eef2f7; color: #334155; }

.sm {
  padding: 8px 12px;
  border-radius: 10px;
  font-size: 0.88rem;
}

/* ─── Status badges ──────────────────────────────────────────────────────────── */
.legend {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  margin: 6px 0;
  align-items: center;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 700;
  border: 1px solid transparent;
}

.status-badge.approved {
  background: linear-gradient(135deg, #16a34a, #22c55e);
  border-color: #15803d;
  color: #fff;
}
.status-badge.experienced {
  background: linear-gradient(135deg, #2563eb, #60a5fa);
  border-color: #1d4ed8;
  color: #fff;
}
.status-badge.notapproved {
  background: linear-gradient(135deg, #dc2626, #f87171);
  border-color: #b91c1c;
  color: #fff;
}

/* ─── Pills ──────────────────────────────────────────────────────────────────── */
.counts {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.count-pill {
  padding: 6px 12px;
  border-radius: 999px;
  background: linear-gradient(135deg, color-mix(in srgb, var(--brand) 12%, white), color-mix(in srgb, var(--brand2) 10%, white));
  border: 1px solid color-mix(in srgb, var(--brand) 20%, white);
  color: var(--brand);
  font-weight: 600;
  font-size: 0.88rem;
}

/* ─── Tables ─────────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; }

th, td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  background: #f7f9fc;
  color: #334155;
  font-size: 0.92rem;
}

.mini-table th,
.mini-table td { padding: 8px 10px; }

/* Unit table row states */
tr.row-selected { background: #eef4ff; }
tr.row-locked   { background: #f0f9f4; color: #1f7a4d; }
tr[data-code]:not([data-locked="true"]):hover { background: #f0f6ff; }

/* ─── Credential column cards ────────────────────────────────────────────────── */
.cred-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: var(--page-gap);
  align-items: start;
}

.cred-state-col {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 8px 20px rgba(16,24,40,0.06);
}

.cred-state-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 14px;
  background: linear-gradient(135deg, var(--brand), var(--brand2));
  color: #fff;
  gap: 8px;
}

.cred-state-header strong { font-size: 1rem; letter-spacing: 0.01em; }

.cred-table td { vertical-align: middle; word-break: break-word; }

/* TAE badges */
.tae-badge {
  display: inline-block;
  padding: 4px 9px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
  white-space: nowrap;
  cursor: default;
}

.tae-current    { background: #dcfce7; color: #15803d; border: 1px solid #bbf7d0; }
.tae-superseded { background: #fef9c3; color: #854d0e; border: 1px solid #fef08a; }
.tae-unknown    { background: #f1f5f9; color: var(--muted); border: 1px solid var(--line); }

/* Credential row states */
tr.cred-row-superseded td:first-child { color: var(--muted); }
tr.cred-row-incomplete                { background: #fff7ed; }
tr.cred-row-incomplete td:first-child { color: var(--warn); }
.cred-superseded-date                 { color: var(--muted); font-style: italic; }

/* ─── Credential filter row ──────────────────────────────────────────────────── */
.cred-filters {
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
}

/* ─── New Training Product ───────────────────────────────────────────────────── */
.new-product-layout {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: var(--page-gap);
  align-items: start;
}

.new-product-config-stack { display: grid; gap: 14px; }

/* ─── Packaging rules ────────────────────────────────────────────────────────── */
.rules-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(3, 1fr);
  margin-top: 10px;
}

.rule-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  background: #fbfcfe;
}

.rules-source { margin-top: 4px; }

/* ─── Validation checklist ───────────────────────────────────────────────────── */
.checklist {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-top: 12px;
}

.check-col {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  background: #fcfdff;
}

.check-col h4 { margin: 0 0 8px; }
.check-col ul  { margin: 0; padding-left: 18px; }

/* ─── Unit selection ─────────────────────────────────────────────────────────── */
.units-head, .header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.units-toolbar {
  display: grid;
  gap: 12px;
  grid-template-columns: 220px 1fr;
  margin: 12px 0;
}

.hidden-count { margin-top: 10px; }

.selected-group            { margin-top: 16px; }
.selected-group:first-child{ margin-top: 0; }
.selected-group-title      { margin-bottom: 10px; }

.selected-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.selected-card {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  padding: 12px;
  border: 1px solid #d0d5dd;
  border-radius: 10px;
  background: #fff;
}

.selected-card.locked      { background: #f8fafc; }
.selected-card-main        { min-width: 0; flex: 1; display: flex; flex-direction: column; }
.selected-card-code        { margin-bottom: 4px; }
.selected-card-title       { margin-bottom: 6px; flex: 1; }
.selected-card-footer      {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: auto;
  padding-top: 6px;
  gap: 4px;
}
.selected-card-left,
.selected-card-right       { display: flex; align-items: center; gap: 4px; }

.pill-locked { background: #f0f9f4; color: #1f7a4d; font-size: 0.75rem; padding: 3px 8px; }
.pill-5k     { background: #eff6ff; color: #1d4ed8; font-size: 0.75rem; padding: 3px 8px; }

/* Elective requirement list */
.req-met     { color: var(--success); }
.req-notmet  { color: var(--danger); }
.req-unknown { color: var(--muted); }
.req-progress { color: var(--muted); font-size: 0.82em; }

/* ─── Available units two-column layout ──────────────────────────────────── */
.units-two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--page-gap);
  align-items: start;
}

/* Group separator rows inside the grouped units table */
tr.unit-group-header td {
  background: #f0f4fa;
  color: var(--brand);
  font-weight: 700;
  font-size: 0.82rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 7px 10px;
  border-bottom: 2px solid var(--line);
}

@media (max-width: 900px) {
  .units-two-col { grid-template-columns: 1fr; }
}

/* ─── Product mapping controls ───────────────────────────────────────────────── */
.product-controls {
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  align-items: end;
}

.product-controls .search-help {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}

.product-controls .search-help small {
  display: block;
  padding: 10px 0;
  color: var(--muted);
}

/* ─── Drop zone ──────────────────────────────────────────────────────────────── */
.dropzone {
  padding: 28px 22px;
  border: 2px dashed #b8c4d6;
  border-radius: 14px;
  background: #f9fbff;
  text-align: center;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.dropzone:hover { background: #eef4ff; border-color: var(--brand2); }

/* ─── Debug ──────────────────────────────────────────────────────────────────── */
.debug-box {
  margin-top: 10px;
  background: #0f172a;
  color: #e5eefc;
  padding: 12px;
  border-radius: 12px;
  overflow: auto;
}

/* ─── Misc ───────────────────────────────────────────────────────────────────── */
.footer { padding: 16px 24px 22px; text-align: center; color: #5b6b84; }

hr { border: none; border-top: 1px solid var(--line); margin: 16px 0; }

details summary { cursor: pointer; }

/* ==========================================================================
   Responsive — consolidated, largest → smallest
   ========================================================================== */

/* Tighten selected-grid on wide-ish screens */
@media (max-width: 1400px) {
  .selected-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .cred-grid     { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

@media (max-width: 1200px) {
  .selected-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cred-grid     { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

/*
 * Header collapse at 1024px.
 * With 7 nav items the header needs to wrap sooner than 980px.
 * Nav drops to its own full-width row so it never gets squashed.
 */
@media (max-width: 1024px) {
  .app-header {
    grid-template-columns: auto 1fr;
    grid-template-rows: auto auto;
    padding: 12px 18px;
    gap: 10px;
  }

  .nav {
    grid-column: 1 / -1;
    justify-content: flex-start;
  }
}

/* Tablet — stack two-column layouts, collapse credential grid to 2 cols */
@media (max-width: 900px) {
  .new-product-layout { grid-template-columns: 1fr; }
  .cols               { grid-template-columns: 1fr; }
  .checklist          { grid-template-columns: 1fr; }
  .units-toolbar      { grid-template-columns: 1fr; }
  .cred-grid          { grid-template-columns: 1fr 1fr; }
}

/* Small tablet / large phone */
@media (max-width: 640px) {
  :root {
    --page-gutter: 12px;
    --page-gap:    12px;
  }

  main       { margin: 12px auto; }
  .card      { padding: 12px; }
  .titles h1 { font-size: 1.3rem; }
  .subtitle  { font-size: 0.88rem; }
  .app-header{ padding: 10px 14px; }
  .nav-link  { font-size: 0.82rem; padding: 6px 10px; }

  .selected-grid    { grid-template-columns: 1fr; }
  .cred-grid        { grid-template-columns: 1fr; }
  .controls         { grid-template-columns: 1fr; }
  .cred-filters     { grid-template-columns: 1fr 1fr; }
  .product-controls { grid-template-columns: 1fr; }
}

/* Phone — single column everything */
@media (max-width: 420px) {
  .cred-filters { grid-template-columns: 1fr; }
}