/**
 * iFeed LMS Cluster — Shared Components
 * Requires: tokens.css loaded first
 *
 * These are copy-paste-ready component classes for all modules.
 * Never override these at the module level — extend via additional classes.
 */

/* ─── Reset ───────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; }
body {
  font-family: var(--lms-font-sans);
  font-size: var(--lms-text-base);
  color: var(--lms-text-primary);
  background: var(--lms-bg);
  line-height: var(--lms-leading-normal);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--lms-text-link); text-decoration: none; }
a:hover { text-decoration: underline; }
img, svg { display: block; max-width: 100%; }

/* ─── Layout Shell ────────────────────────────────────────────────────────── */
.lms-shell {
  display: grid;
  grid-template-rows: 56px 1fr;
  grid-template-columns: 240px 1fr;
  grid-template-areas: "nav topbar" "nav main";
  min-height: 100vh;
}
.lms-shell.embedded {  /* when inside ClinAssure iframe */
  grid-template-rows: 1fr;
  grid-template-columns: 220px 1fr;
  grid-template-areas: "nav main";
}
.lms-topbar {
  grid-area: topbar;
  background: var(--lms-surface);
  border-bottom: 1px solid var(--lms-border);
  display: flex;
  align-items: center;
  padding: 0 var(--lms-space-6);
  gap: var(--lms-space-4);
}
.lms-nav {
  grid-area: nav;
  background: var(--lms-nav-bg);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
}
.lms-main {
  grid-area: main;
  overflow-y: auto;
  padding: var(--lms-space-8);
}

/* ─── Navigation ──────────────────────────────────────────────────────────── */
.lms-nav-brand {
  padding: var(--lms-space-5) var(--lms-space-5);
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.lms-nav-brand h1 {
  font-size: var(--lms-text-sm);
  font-weight: var(--lms-weight-bold);
  color: var(--lms-nav-text-active);
  letter-spacing: 0.03em;
  text-transform: uppercase;
}
.lms-nav-brand p {
  font-size: var(--lms-text-xs);
  color: var(--lms-nav-text);
  margin-top: 2px;
}
.lms-nav-section {
  padding: var(--lms-space-4) 0 var(--lms-space-2);
}
.lms-nav-section-label {
  font-size: var(--lms-text-xs);
  font-weight: var(--lms-weight-semibold);
  color: var(--lms-nav-text);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 0 var(--lms-space-5) var(--lms-space-2);
  opacity: 0.6;
}
.lms-nav-item {
  display: flex;
  align-items: center;
  gap: var(--lms-space-3);
  padding: var(--lms-space-2) var(--lms-space-5);
  color: var(--lms-nav-text);
  font-size: var(--lms-text-sm);
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: var(--lms-transition-fast);
  user-select: none;
}
.lms-nav-item:hover { background: var(--lms-nav-hover); color: var(--lms-nav-text-active); }
.lms-nav-item.active {
  color: var(--lms-nav-text-active);
  border-left-color: var(--lms-nav-accent);
  background: rgba(14,165,233,0.12);
}
.lms-nav-item .icon { font-size: 14px; width: 16px; text-align: center; flex-shrink: 0; }
.lms-nav-badge {
  margin-left: auto;
  font-size: var(--lms-text-xs);
  font-weight: var(--lms-weight-bold);
  background: var(--lms-nav-accent);
  color: white;
  padding: 1px 6px;
  border-radius: var(--lms-radius-full);
}

/* ─── Cards ───────────────────────────────────────────────────────────────── */
.lms-card {
  background: var(--lms-surface);
  border: 1px solid var(--lms-border);
  border-radius: var(--lms-radius-lg);
  padding: var(--lms-space-6);
  box-shadow: var(--lms-shadow-sm);
  transition: var(--lms-transition-base);
}
.lms-card:hover { box-shadow: var(--lms-shadow-md); }
.lms-card-clickable { cursor: pointer; }
.lms-card-clickable:hover { border-color: var(--lms-border-focus); }
.lms-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--lms-space-4);
  margin-bottom: var(--lms-space-4);
}
.lms-card-title {
  font-size: var(--lms-text-md);
  font-weight: var(--lms-weight-semibold);
  color: var(--lms-text-primary);
  line-height: var(--lms-leading-snug);
}
.lms-card-meta {
  font-size: var(--lms-text-xs);
  color: var(--lms-text-muted);
  margin-top: var(--lms-space-1);
}
.lms-card-body { color: var(--lms-text-secondary); font-size: var(--lms-text-sm); line-height: var(--lms-leading-relaxed); }
.lms-card-footer {
  margin-top: var(--lms-space-5);
  padding-top: var(--lms-space-4);
  border-top: 1px solid var(--lms-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* ─── Grid layouts ────────────────────────────────────────────────────────── */
.lms-grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--lms-space-5); }
.lms-grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--lms-space-5); }
.lms-grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--lms-space-5); }
.lms-grid-auto { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: var(--lms-space-5); }
@media (max-width: 900px) { .lms-grid-3, .lms-grid-4 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 600px) { .lms-grid-2, .lms-grid-3, .lms-grid-4, .lms-grid-auto { grid-template-columns: 1fr; } }

/* ─── Buttons ─────────────────────────────────────────────────────────────── */
.lms-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--lms-space-2);
  padding: var(--lms-space-2) var(--lms-space-5);
  border-radius: var(--lms-radius-md);
  font-size: var(--lms-text-sm);
  font-weight: var(--lms-weight-semibold);
  cursor: pointer;
  border: 1px solid transparent;
  transition: var(--lms-transition-fast);
  text-decoration: none;
  white-space: nowrap;
}
.lms-btn:focus-visible { outline: 2px solid var(--lms-border-focus); outline-offset: 2px; }
.lms-btn-primary { background: var(--lms-brand-accent); color: white; border-color: var(--lms-brand-accent); }
.lms-btn-primary:hover { background: var(--lms-brand-accent-hover); text-decoration: none; color: white; }
.lms-btn-secondary { background: var(--lms-surface-2); color: var(--lms-text-primary); border-color: var(--lms-border); }
.lms-btn-secondary:hover { background: var(--lms-surface-3); text-decoration: none; }
.lms-btn-ghost { background: transparent; color: var(--lms-brand-accent); }
.lms-btn-ghost:hover { background: var(--lms-surface-2); text-decoration: none; }
.lms-btn-sm { padding: var(--lms-space-1) var(--lms-space-3); font-size: var(--lms-text-xs); }
.lms-btn-lg { padding: var(--lms-space-3) var(--lms-space-8); font-size: var(--lms-text-md); }

/* ─── Badges ──────────────────────────────────────────────────────────────── */
.lms-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: var(--lms-radius-full);
  font-size: var(--lms-text-xs);
  font-weight: var(--lms-weight-semibold);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.lms-badge-success { background: var(--lms-bg-success); color: var(--lms-brand-success); }
.lms-badge-warning { background: var(--lms-bg-warning); color: var(--lms-brand-warning); }
.lms-badge-danger  { background: var(--lms-bg-danger);  color: var(--lms-brand-danger); }
.lms-badge-info    { background: var(--lms-bg-info);    color: var(--lms-brand-info); }
.lms-badge-neutral { background: var(--lms-surface-2);  color: var(--lms-text-secondary); }

/* ─── Progress Bar ────────────────────────────────────────────────────────── */
.lms-progress-wrap { margin: var(--lms-space-2) 0; }
.lms-progress-label {
  display: flex;
  justify-content: space-between;
  font-size: var(--lms-text-xs);
  color: var(--lms-text-secondary);
  margin-bottom: 4px;
}
.lms-progress-track {
  height: 6px;
  background: var(--lms-progress-track);
  border-radius: var(--lms-radius-full);
  overflow: hidden;
}
.lms-progress-fill {
  height: 100%;
  background: var(--lms-progress-fill);
  border-radius: var(--lms-radius-full);
  transition: width 0.4s ease;
}
.lms-progress-fill.complete { background: var(--lms-progress-complete); }

/* ─── Page header ─────────────────────────────────────────────────────────── */
.lms-page-header {
  margin-bottom: var(--lms-space-8);
}
.lms-page-header h1 {
  font-size: var(--lms-text-3xl);
  font-weight: var(--lms-weight-bold);
  color: var(--lms-text-primary);
  line-height: var(--lms-leading-tight);
}
.lms-page-header p {
  font-size: var(--lms-text-md);
  color: var(--lms-text-secondary);
  margin-top: var(--lms-space-2);
}
.lms-section-title {
  font-size: var(--lms-text-xs);
  font-weight: var(--lms-weight-bold);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--lms-text-muted);
  margin-bottom: var(--lms-space-4);
  padding-bottom: var(--lms-space-2);
  border-bottom: 1px solid var(--lms-border);
}

/* ─── Stat tiles ──────────────────────────────────────────────────────────── */
.lms-stat {
  background: var(--lms-surface);
  border: 1px solid var(--lms-border);
  border-radius: var(--lms-radius-lg);
  padding: var(--lms-space-5);
}
.lms-stat-value {
  font-size: var(--lms-text-3xl);
  font-weight: var(--lms-weight-extrabold);
  color: var(--lms-brand-accent);
  line-height: 1;
}
.lms-stat-label { font-size: var(--lms-text-sm); color: var(--lms-text-secondary); margin-top: var(--lms-space-1); }

/* ─── Filter / tab bar ────────────────────────────────────────────────────── */
.lms-tabs {
  display: flex;
  gap: var(--lms-space-1);
  background: var(--lms-surface-2);
  padding: var(--lms-space-1);
  border-radius: var(--lms-radius-lg);
  margin-bottom: var(--lms-space-6);
  flex-wrap: wrap;
}
.lms-tab {
  padding: var(--lms-space-2) var(--lms-space-4);
  border-radius: var(--lms-radius-md);
  font-size: var(--lms-text-sm);
  font-weight: var(--lms-weight-medium);
  color: var(--lms-text-secondary);
  cursor: pointer;
  border: none;
  background: transparent;
  transition: var(--lms-transition-fast);
  white-space: nowrap;
}
.lms-tab:hover { color: var(--lms-text-primary); }
.lms-tab.active {
  background: var(--lms-surface);
  color: var(--lms-text-primary);
  box-shadow: var(--lms-shadow-sm);
  font-weight: var(--lms-weight-semibold);
}

/* ─── Search input ────────────────────────────────────────────────────────── */
.lms-search {
  display: flex;
  align-items: center;
  gap: var(--lms-space-2);
  background: var(--lms-surface);
  border: 1px solid var(--lms-border);
  border-radius: var(--lms-radius-lg);
  padding: var(--lms-space-2) var(--lms-space-4);
  width: 100%;
  max-width: 360px;
}
.lms-search input {
  border: none;
  background: transparent;
  font-size: var(--lms-text-sm);
  color: var(--lms-text-primary);
  width: 100%;
  outline: none;
}
.lms-search input::placeholder { color: var(--lms-text-muted); }

/* ─── Empty state ─────────────────────────────────────────────────────────── */
.lms-empty {
  text-align: center;
  padding: var(--lms-space-16) var(--lms-space-8);
  color: var(--lms-text-muted);
}
.lms-empty-icon { font-size: 48px; margin-bottom: var(--lms-space-4); }
.lms-empty-title { font-size: var(--lms-text-lg); font-weight: var(--lms-weight-semibold); color: var(--lms-text-secondary); }
.lms-empty-sub { font-size: var(--lms-text-sm); margin-top: var(--lms-space-2); }

/* ─── Toast notifications ─────────────────────────────────────────────────── */
.lms-toast-container {
  position: fixed;
  bottom: var(--lms-space-6);
  right: var(--lms-space-6);
  z-index: var(--lms-z-toast);
  display: flex;
  flex-direction: column;
  gap: var(--lms-space-3);
}
.lms-toast {
  background: var(--lms-surface);
  border: 1px solid var(--lms-border);
  border-radius: var(--lms-radius-lg);
  padding: var(--lms-space-4) var(--lms-space-5);
  box-shadow: var(--lms-shadow-lg);
  font-size: var(--lms-text-sm);
  display: flex;
  align-items: center;
  gap: var(--lms-space-3);
  min-width: 260px;
  animation: lms-toast-in 0.2s ease;
}
.lms-toast.success { border-left: 4px solid var(--lms-brand-success); }
.lms-toast.warning { border-left: 4px solid var(--lms-brand-warning); }
.lms-toast.error   { border-left: 4px solid var(--lms-brand-danger); }
@keyframes lms-toast-in {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ─── Responsive nav collapse ─────────────────────────────────────────────── */
@media (max-width: 768px) {
  .lms-shell {
    grid-template-columns: 1fr;
    grid-template-areas: "topbar" "main";
    grid-template-rows: 56px 1fr;
  }
  .lms-nav { display: none; }
  .lms-nav.open {
    display: flex;
    position: fixed;
    top: 0; left: 0;
    width: 280px; height: 100vh;
    z-index: var(--lms-z-overlay);
    box-shadow: var(--lms-shadow-lg);
  }
  .lms-main { padding: var(--lms-space-5); }
}

/* ─── Accessibility ───────────────────────────────────────────────────────── */
:focus-visible { outline: 2px solid var(--lms-border-focus); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; } }
