/* =========================================================
   Ideal Plumbing — Main Stylesheet
   Mobile-first, CSS custom properties, no framework needed
   ========================================================= */

/* ----- Reset & Base ----- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --navy:       #1B4F72;
  --navy-dark:  #154360;
  --navy-light: #2E86C1;
  --orange:     #F39C12;
  --orange-dk:  #D68910;
  --green:      #1E8449;
  --green-lt:   #27AE60;
  --red:        #C0392B;
  --red-lt:     #E74C3C;
  --purple:     #7D3C98;
  --bg:         #F0F4F8;
  --surface:    #FFFFFF;
  --border:     #DDE3EA;
  --text:       #1C2B3A;
  --text-muted: #637282;
  --sidebar-w:  260px;
  --topbar-h:   60px;
  --bottom-nav-h: 64px;
  --radius:     10px;
  --shadow-sm:  0 1px 4px rgba(0,0,0,.08);
  --shadow:     0 2px 12px rgba(0,0,0,.10);
  --shadow-lg:  0 4px 24px rgba(0,0,0,.12);
  --transition: .18s ease;

  /* Level colours */
  --l1: #2E86C1;
  --l2: #1E8449;
  --l3: #D35400;
  --l4: #7D3C98;
}

html { scroll-behavior: smooth; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--navy-light); text-decoration: none; }
a:hover { text-decoration: underline; }
svg { display: inline-block; vertical-align: middle; fill: currentColor; }

/* ----- Layout ----- */
.sidebar {
  position: fixed; top: 0; left: 0; bottom: 0;
  width: var(--sidebar-w);
  background: var(--navy);
  display: flex; flex-direction: column;
  z-index: 200;
  transition: transform var(--transition);
  overflow-y: auto;
}

.main-content {
  margin-left: var(--sidebar-w);
  min-height: 100vh;
  display: flex; flex-direction: column;
}

.topbar {
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 1rem;
  padding: 0 1.5rem;
  position: sticky; top: 0; z-index: 100;
  box-shadow: var(--shadow-sm);
}

.topbar-title {
  font-size: 1.05rem; font-weight: 700; color: var(--navy);
  flex: 1;
}

.menu-toggle { display: none; }

.content-wrapper {
  flex: 1;
  padding: 1.5rem;
  max-width: 1280px;
  width: 100%;
}

.bottom-nav { display: none; }

/* ----- Sidebar internals ----- */
.sidebar-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid rgba(255,255,255,.1);
}

.sidebar-logo {
  display: flex; align-items: center; gap: .625rem;
}

.sidebar-brand {
  color: white; font-weight: 700; font-size: 1rem;
}

.sidebar-close {
  display: none; background: none; border: none; color: rgba(255,255,255,.7);
  font-size: 1.25rem; cursor: pointer; padding: .25rem;
}

.sidebar-user {
  display: flex; align-items: center; gap: .75rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid rgba(255,255,255,.1);
}

.user-name { color: white; font-weight: 600; font-size: .9rem; }
.user-role { font-size: .75rem; margin-top: .125rem; }

.sidebar-nav {
  flex: 1;
  padding: .75rem 0;
}

.nav-link {
  display: flex; align-items: center; gap: .75rem;
  padding: .7rem 1.25rem;
  color: rgba(255,255,255,.75);
  font-size: .9rem; font-weight: 500;
  transition: background var(--transition), color var(--transition);
  border-left: 3px solid transparent;
}

.nav-link svg { width: 20px; height: 20px; flex-shrink: 0; }
.nav-link:hover { background: rgba(255,255,255,.08); color: white; text-decoration: none; }
.nav-link.active { background: rgba(255,255,255,.12); color: white; border-left-color: var(--orange); }

.sidebar-footer {
  padding: .75rem 0;
  border-top: 1px solid rgba(255,255,255,.1);
}

.nav-logout { color: rgba(255,255,255,.55); }
.nav-logout:hover { color: var(--red-lt); }

.sidebar-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.4); z-index: 199;
}

/* ----- Auth Layout ----- */
.auth-main {
  min-height: 100vh; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 2rem 1rem;
  background: linear-gradient(135deg, var(--navy) 0%, var(--navy-light) 100%);
}

.auth-container {
  width: 100%; max-width: 420px;
  display: flex; flex-direction: column; align-items: center; gap: 1rem;
}

.auth-card {
  background: white; border-radius: 16px; padding: 2.5rem 2rem;
  width: 100%; box-shadow: var(--shadow-lg);
}

.auth-logo { text-align: center; margin-bottom: 1.5rem; }
.auth-brand { color: var(--navy); font-size: 1.4rem; font-weight: 800; margin-top: .5rem; }
.auth-tagline { color: var(--text-muted); font-size: .875rem; margin-top: .25rem; }
.auth-title { font-size: 1.25rem; font-weight: 700; color: var(--text); margin-bottom: 1.25rem; }

.auth-footer {
  text-align: center; margin-top: 1.25rem;
  font-size: .875rem; color: var(--text-muted);
}
.auth-footer a { color: var(--navy-light); font-weight: 600; }

.auth-copy { color: rgba(255,255,255,.5); font-size: .8rem; }

.flash-auth { width: 100%; }

/* ----- Cards ----- */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.card-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}

.card-title { font-size: 1rem; font-weight: 700; color: var(--text); margin: 0; }
.card-link { font-size: .8rem; color: var(--navy-light); font-weight: 600; }
.card-link:hover { text-decoration: underline; }
.card-body { padding: 1.25rem; }
.card-body.p-0 { padding: 0; }
.card-footer { padding: .75rem 1.25rem; border-top: 1px solid var(--border); }
.card-danger { border-color: #fecaca; }
.card-success { border-color: #bbf7d0; }
.card-locked { opacity: .7; }

.mb-4 { margin-bottom: 1.25rem; }
.mt-4 { margin-top: 1.25rem; }

/* ----- Stats ----- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.stats-grid-4 { grid-template-columns: repeat(4, 1fr); }

.stat-card {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  padding: 1.25rem;
  display: flex; align-items: center; gap: 1rem;
}

.stat-card-current { border-color: var(--navy-light); box-shadow: 0 0 0 2px rgba(46,134,193,.2); }

.stat-icon {
  width: 48px; height: 48px; border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.stat-icon svg { width: 24px; height: 24px; color: white; }
.stat-icon-blue   { background: var(--navy-light); }
.stat-icon-orange { background: var(--orange); }
.stat-icon-green  { background: var(--green-lt); }
.stat-icon-purple { background: var(--purple); }

.stat-value { font-size: 2rem; font-weight: 800; color: var(--text); line-height: 1; }
.stat-label { font-size: .8rem; color: var(--text-muted); margin-top: .25rem; }
.stat-card-sm { flex-direction: column; align-items: flex-start; gap: .375rem; padding: 1rem; }
.stat-value-sm { font-size: 1.25rem; font-weight: 700; }
.stat-pct { font-size: .8rem; color: var(--text-muted); }

/* ----- Dashboard Grid ----- */
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
  gap: 1.25rem;
}

/* ----- Level Bars ----- */
.level-row {
  display: flex; align-items: center; gap: .75rem;
  padding: .625rem 0;
  border-bottom: 1px solid var(--border);
}
.level-row:last-child { border-bottom: none; }

.level-label {
  display: flex; align-items: center; gap: .5rem;
  min-width: 200px;
}

.level-name { font-size: .875rem; color: var(--text-muted); }

.level-bar-wrap {
  display: flex; align-items: center; gap: .5rem; flex: 1;
}

.level-bar {
  flex: 1; height: 8px; background: var(--bg);
  border-radius: 99px; overflow: hidden;
}

.level-bar-fill {
  height: 100%; border-radius: 99px;
  transition: width .6s ease;
}

.level-count { font-weight: 700; min-width: 24px; text-align: right; }

/* Progress bars */
.progress-track {
  height: 10px; background: var(--bg); border-radius: 99px; overflow: hidden; flex: 1;
}
.progress-fill { height: 100%; border-radius: 99px; background: var(--navy-light); transition: width .6s ease; }
.progress-label { font-size: .8rem; color: var(--text-muted); margin-top: .25rem; }

.progress-cell { display: flex; align-items: center; gap: .5rem; }
.progress-bar-mini { flex: 1; height: 6px; background: var(--bg); border-radius: 99px; overflow: hidden; min-width: 60px; }
.progress-bar-fill { height: 100%; background: var(--navy-light); border-radius: 99px; transition: width .6s; }

.mini-progress { height: 4px; background: var(--bg); border-radius: 99px; overflow: hidden; width: 100%; }
.mini-progress-fill { height: 100%; border-radius: 99px; transition: width .6s; }

/* Level colours for fills */
.level-1-fill { background: var(--l1); }
.level-2-fill { background: var(--l2); }
.level-3-fill { background: var(--l3); }
.level-4-fill { background: var(--l4); }

/* ----- Level Badges ----- */
.level-badge {
  display: inline-flex; align-items: center; justify-content: center;
  padding: .2rem .55rem;
  border-radius: 6px;
  font-size: .75rem; font-weight: 700;
  color: white; flex-shrink: 0;
}
.level-badge-lg { padding: .35rem .9rem; font-size: .9rem; }
.level-1 { background: var(--l1); }
.level-2 { background: var(--l2); }
.level-3 { background: var(--l3); }
.level-4 { background: var(--l4); }

/* ----- Badges ----- */
.badge {
  display: inline-flex; align-items: center; gap: .25rem;
  padding: .2rem .6rem;
  border-radius: 99px;
  font-size: .73rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .04em;
}
.badge-sm { font-size: .65rem; padding: .15rem .4rem; }
.badge-admin    { background: #dbeafe; color: #1e40af; }
.badge-apprentice { background: #d1fae5; color: #065f46; }
.badge-success  { background: #d1fae5; color: #065f46; }
.badge-inactive { background: #f3f4f6; color: #6b7280; }
.badge-current  { background: #fef3c7; color: #92400e; }
.badge-locked   { background: #f3f4f6; color: #6b7280; }
.badge-count    { background: var(--bg); color: var(--text-muted); font-weight: 700; }

/* ----- Item Lists ----- */
.item-list { list-style: none; }
.item-list-row {
  display: flex; align-items: center; gap: .75rem;
  padding: .875rem 1.25rem;
  border-bottom: 1px solid var(--border);
}
.item-list-row:last-child { border-bottom: none; }

.item-info { flex: 1; min-width: 0; }
.item-title { font-weight: 600; font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-sub   { font-size: .8rem; color: var(--text-muted); }
.item-meta  { display: flex; flex-direction: column; align-items: flex-end; gap: .25rem; flex-shrink: 0; }

/* ----- Avatars ----- */
.avatar {
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--navy-light);
  color: white; font-weight: 700; font-size: .9rem;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.avatar-sm  { width: 32px; height: 32px; font-size: .8rem; }
.avatar-lg  { width: 64px; height: 64px; font-size: 1.5rem; }
.mx-auto    { margin-left: auto; margin-right: auto; }

/* ----- Check / Status icons ----- */
.check-icon {
  width: 32px; height: 32px; border-radius: 50%;
  background: #d1fae5; color: var(--green-lt);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.check-icon svg { width: 18px; height: 18px; }
.check-icon-sm { width: 24px; height: 24px; }
.check-icon-sm svg { width: 14px; height: 14px; }

/* ----- Forms ----- */
.form-group  { margin-bottom: 1rem; }
.form-label  { display: block; font-weight: 600; font-size: .875rem; margin-bottom: .375rem; color: var(--text); }
.form-hint   { font-size: .78rem; color: var(--text-muted); margin-top: .25rem; }

.form-control {
  display: block; width: 100%;
  padding: .625rem .875rem;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: .9rem;
  color: var(--text);
  background: white;
  transition: border-color var(--transition), box-shadow var(--transition);
  -webkit-appearance: none;
}
.form-control:focus {
  outline: none;
  border-color: var(--navy-light);
  box-shadow: 0 0 0 3px rgba(46,134,193,.15);
}
.form-control.is-invalid { border-color: var(--red-lt); }

textarea.form-control { resize: vertical; min-height: 80px; }

.invalid-feedback { color: var(--red-lt); font-size: .8rem; margin-top: .25rem; }

.form-check { display: flex; align-items: center; gap: .5rem; margin-bottom: .75rem; }
.form-check-input { width: 16px; height: 16px; accent-color: var(--navy); cursor: pointer; }
.form-check-label { font-size: .9rem; cursor: pointer; }

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
}

.flex-1  { flex: 1; }
.flex-2  { flex: 2; }
.flex-center-vert { display: flex; align-items: center; }

.form-actions { display: flex; align-items: center; gap: .75rem; margin-top: 1.5rem; }
.form-page-wrap { max-width: 680px; }
.form-page-wide { max-width: 900px; }

.filter-form .filter-row {
  display: flex; align-items: center; gap: .75rem; flex-wrap: wrap;
}
.filter-form .form-control { min-width: 140px; }

.input-with-toggle { position: relative; }
.input-with-toggle .form-control { padding-right: 2.75rem; }
.password-toggle {
  position: absolute; right: .625rem; top: 50%; transform: translateY(-50%);
  background: none; border: none; cursor: pointer; color: var(--text-muted);
  display: flex; align-items: center; padding: .25rem;
}
.password-toggle svg { width: 18px; height: 18px; }
.password-toggle:hover { color: var(--text); }

/* ----- Buttons ----- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .375rem;
  padding: .6rem 1.1rem;
  border-radius: 8px;
  font-size: .875rem; font-weight: 600;
  border: none; cursor: pointer;
  transition: opacity var(--transition), background var(--transition), box-shadow var(--transition);
  text-decoration: none; white-space: nowrap;
  -webkit-appearance: none;
}
.btn:hover { text-decoration: none; opacity: .9; }
.btn:active { transform: scale(.98); }

.btn-primary      { background: var(--navy); color: white; }
.btn-primary:hover { background: var(--navy-dark); opacity: 1; }
.btn-ghost        { background: transparent; color: var(--navy); border: 1.5px solid var(--border); }
.btn-ghost:hover  { background: var(--bg); }
.btn-danger       { background: var(--red-lt); color: white; }
.btn-danger-ghost { background: transparent; color: var(--red-lt); border: none; }
.btn-danger-ghost:hover { background: #fef2f2; }

.btn-sm  { padding: .375rem .75rem; font-size: .8rem; border-radius: 6px; }
.btn-lg  { padding: .8rem 1.5rem; font-size: 1rem; }
.btn-full { width: 100%; }
.ml-auto { margin-left: auto; }
.ml-1    { margin-left: .25rem; }

/* ----- Table ----- */
.table-responsive { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th {
  text-align: left; padding: .75rem 1.25rem;
  font-size: .78rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .05em; color: var(--text-muted);
  border-bottom: 2px solid var(--border);
  background: var(--bg);
}
.table td {
  padding: .875rem 1.25rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: #f8fafc; }
.row-inactive { opacity: .6; }

.user-cell { display: flex; align-items: center; gap: .625rem; }
.action-buttons { display: flex; gap: .375rem; }

/* ----- SOP Lists ----- */
.sop-checklist { list-style: none; }
.sop-check-item {
  display: flex; align-items: center; gap: .75rem;
  padding: .875rem 1.25rem;
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
}
.sop-check-item:last-child { border-bottom: none; }
.sop-check-item:hover { background: #f8fafc; }
.sop-check-item.completed .sop-check-title { color: var(--text-muted); text-decoration: line-through; }

.sop-check-icon { width: 28px; height: 28px; flex-shrink: 0; display: flex; align-items: center; justify-content: center; }
.sop-check-icon svg { width: 22px; height: 22px; }
.icon-success { color: var(--green-lt); }
.icon-success-sm { width: 16px; height: 16px; color: var(--green-lt); }
.icon-pending { color: var(--border); }

.sop-check-info { flex: 1; min-width: 0; }
.sop-check-title { font-weight: 600; font-size: .9rem; color: var(--text); }
.sop-check-title:hover { color: var(--navy-light); }
.sop-check-sub { font-size: .78rem; color: var(--text-muted); }
.sop-check-date { flex-shrink: 0; }

/* SOP Library List */
.sop-library-list { list-style: none; }
.sop-library-item {
  display: flex; align-items: center; gap: .875rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
}
.sop-library-item:last-child { border-bottom: none; }
.sop-library-item:hover { background: #f8fafc; }

.sop-status-icon { flex-shrink: 0; }
.status-circle {
  width: 24px; height: 24px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
}
.status-done { background: #d1fae5; color: var(--green-lt); }
.status-done svg { width: 14px; height: 14px; }
.status-open { border: 2px solid var(--border); background: white; }

.sop-library-info { flex: 1; min-width: 0; }
.sop-library-title { font-weight: 600; font-size: .9rem; color: var(--text); display: block; }
.sop-library-title:hover { color: var(--navy-light); text-decoration: none; }
.sop-library-meta { margin-top: .125rem; }

.sop-category-tag {
  display: inline-block;
  font-size: .75rem; color: var(--text-muted);
  background: var(--bg); border-radius: 4px;
  padding: .1rem .4rem;
}

.level-header { display: flex; align-items: center; gap: .75rem; flex: 1; }
.level-progress-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; }
.level-progress-card {
  border: 1.5px solid var(--border); border-radius: 8px; padding: .875rem;
}
.level-progress-card.current-level { border-color: var(--navy-light); background: #eff6ff; }
.lpc-header { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; margin-bottom: .625rem; }
.lpc-progress { display: flex; flex-direction: column; gap: .25rem; }

/* SOP Nav Sidebar */
.sop-nav-list { list-style: none; }
.sop-nav-item {
  display: flex; align-items: center; gap: .625rem;
  padding: .625rem 1.25rem;
  border-bottom: 1px solid var(--border);
}
.sop-nav-item:last-child { border-bottom: none; }
.sop-nav-item.sop-nav-active { background: #eff6ff; }
.sop-nav-icon { width: 20px; flex-shrink: 0; display: flex; align-items: center; justify-content: center; }
.sop-nav-link { font-size: .85rem; color: var(--text); line-height: 1.3; }
.sop-nav-active .sop-nav-link { font-weight: 600; color: var(--navy); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--border); }
.dot-active { background: var(--navy-light); }

/* SOP View */
.sop-view-layout {
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: 1.25rem;
  align-items: start;
}
.sop-main {}
.sop-sidebar {}
.sop-header { padding: 1.5rem 1.5rem 1rem; border-bottom: 1px solid var(--border); }
.sop-header-meta { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; margin-bottom: .75rem; }
.sop-title { font-size: 1.5rem; font-weight: 800; color: var(--text); line-height: 1.3; }
.sop-dates { margin-top: .375rem; }

.sop-content {
  padding: 1.5rem;
  line-height: 1.8;
}
.sop-content h1,
.sop-content h2,
.sop-content h3 { color: var(--navy); margin: 1.5rem 0 .75rem; font-weight: 700; }
.sop-content h1 { font-size: 1.4rem; }
.sop-content h2 { font-size: 1.2rem; border-bottom: 2px solid var(--border); padding-bottom: .375rem; }
.sop-content h3 { font-size: 1rem; }
.sop-content p { margin-bottom: 1rem; }
.sop-content ul,
.sop-content ol { margin: .75rem 0 1rem 1.5rem; }
.sop-content li { margin-bottom: .375rem; }
.sop-content table {
  width: 100%; border-collapse: collapse; margin: 1rem 0;
  font-size: .875rem;
}
.sop-content th {
  background: var(--bg); padding: .625rem .875rem;
  text-align: left; font-weight: 700;
  border: 1px solid var(--border);
}
.sop-content td { padding: .5rem .875rem; border: 1px solid var(--border); }
.sop-content tr:nth-child(even) td { background: #f8fafc; }
.sop-content code {
  background: #f1f5f9; padding: .1rem .35rem;
  border-radius: 4px; font-family: 'Cascadia Code', 'Fira Code', monospace;
  font-size: .85em;
}
.sop-content pre {
  background: #1e293b; color: #e2e8f0;
  padding: 1rem; border-radius: 8px; overflow-x: auto; margin: 1rem 0;
}
.sop-content pre code { background: none; color: inherit; }
.sop-content strong { font-weight: 700; }
.sop-content blockquote {
  border-left: 4px solid var(--navy-light);
  padding-left: 1rem; color: var(--text-muted);
  margin: 1rem 0;
}

/* SOP editor */
.editor-toolbar {
  display: flex; gap: .25rem; flex-wrap: wrap;
  background: var(--bg); border: 1.5px solid var(--border);
  border-bottom: none; border-radius: 8px 8px 0 0;
  padding: .375rem .5rem;
}
.editor-btn {
  background: white; border: 1px solid var(--border);
  border-radius: 4px; padding: .25rem .5rem;
  font-size: .8rem; font-weight: 700; cursor: pointer;
  transition: background var(--transition);
}
.editor-btn:hover { background: var(--bg); }
.editor-sep { width: 1px; background: var(--border); margin: 0 .25rem; }
.sop-editor { border-radius: 0 0 8px 8px; font-family: 'Cascadia Code', monospace; font-size: .85rem; }
.sop-preview-box { border: 1.5px solid var(--border); border-radius: 0 0 8px 8px; padding: 1rem; min-height: 200px; }

/* Welcome Banner */
.welcome-banner {
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 1.25rem;
  color: white;
}
.level-1-banner { background: linear-gradient(135deg, #1B4F72, #2E86C1); }
.level-2-banner { background: linear-gradient(135deg, #145A32, #1E8449); }
.level-3-banner { background: linear-gradient(135deg, #7E5109, #D35400); }
.level-4-banner { background: linear-gradient(135deg, #4A235A, #7D3C98); }

.welcome-content { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: 1.25rem; }
.welcome-title { font-size: 1.3rem; font-weight: 800; }
.welcome-sub { font-size: .9rem; opacity: .85; margin-top: .25rem; }
.welcome-badge { display: flex; flex-direction: column; align-items: center; flex-shrink: 0; }
.big-level-badge {
  width: 56px; height: 56px; border-radius: 14px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem; font-weight: 900; color: white;
  background: rgba(255,255,255,.25);
  border: 2px solid rgba(255,255,255,.5);
}
.opacity-80 { opacity: .8; }
.text-center { text-align: center; }

.banner-progress-label { display: flex; justify-content: space-between; font-size: .85rem; opacity: .9; margin-bottom: .375rem; }
.banner-progress-track { height: 10px; background: rgba(255,255,255,.25); border-radius: 99px; overflow: hidden; }
.banner-progress-fill { height: 100%; background: white; border-radius: 99px; transition: width .6s ease; }
.banner-progress-pct { font-size: .8rem; opacity: .8; text-align: right; margin-top: .25rem; }

/* Completion card */
.completion-info { background: #f0fdf4; border-radius: 8px; padding: .875rem; }
.completion-date { display: flex; align-items: center; gap: .5rem; font-weight: 600; color: var(--green); }

/* Detail layout */
.detail-grid {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 1.25rem;
  align-items: start;
}
.detail-sidebar {}
.detail-main {}

.meta-list { display: flex; flex-direction: column; gap: .625rem; }
.meta-item { display: flex; justify-content: space-between; align-items: center; font-size: .875rem; }
.meta-label { color: var(--text-muted); font-weight: 500; }
.divider { border: none; border-top: 1px solid var(--border); margin: 1rem 0; }

/* SOP Checklist for admin detail */
.sop-checklist .sop-check-item.completed .sop-check-title { text-decoration: line-through; color: var(--text-muted); }

/* Reports */
.rank-badge {
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--navy); color: white;
  font-size: .75rem; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

/* Flash messages */
.flash-container { padding: 1rem 1.5rem 0; }
.alert {
  display: flex; align-items: center; justify-content: space-between;
  padding: .75rem 1rem; border-radius: 8px;
  font-size: .875rem; font-weight: 500;
  margin-bottom: .625rem;
}
.alert-success { background: #d1fae5; color: #065f46; }
.alert-danger   { background: #fee2e2; color: #991b1b; }
.alert-warning  { background: #fef3c7; color: #92400e; }
.alert-info     { background: #dbeafe; color: #1e40af; }
.alert-close {
  background: none; border: none; font-size: 1.1rem;
  cursor: pointer; opacity: .6; padding: 0 .25rem;
  color: inherit;
}
.alert-close:hover { opacity: 1; }

/* Utilities */
.text-muted   { color: var(--text-muted); }
.text-success { color: var(--green-lt); }
.text-danger  { color: var(--red-lt); }
.text-sm  { font-size: .875rem; }
.text-xs  { font-size: .75rem; }
.fw-600   { font-weight: 600; }
.py-8     { padding-top: 2rem; padding-bottom: 2rem; }
.p-4      { padding: 1rem; }
.gap-2    { gap: .5rem; }
.mt-1     { margin-top: .25rem; }
.mt-2     { margin-top: .5rem; }
.mt-3     { margin-top: .75rem; }
.mb-1     { margin-bottom: .25rem; }
.mb-2     { margin-bottom: .5rem; }
.mb-3     { margin-bottom: .75rem; }
.flex-center { display: flex; align-items: center; justify-content: center; }

.empty-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 3rem 1.5rem; text-align: center; color: var(--text-muted);
}
.empty-icon { width: 48px; height: 48px; margin-bottom: .75rem; opacity: .4; }

.link-primary { color: var(--navy); font-weight: 600; }
.link-primary:hover { color: var(--navy-light); }

/* =========================================================
   RESPONSIVE — Tablet / Mobile
   ========================================================= */

@media (max-width: 1024px) {
  .sop-view-layout { grid-template-columns: 1fr; }
  .sop-sidebar { order: -1; }
  .detail-grid { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
  :root { --sidebar-w: 280px; }

  /* Hide sidebar by default on mobile */
  .sidebar {
    transform: translateX(-100%);
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-close { display: flex; }

  .sidebar-overlay.visible { display: block; }

  .main-content { margin-left: 0; padding-bottom: var(--bottom-nav-h); }

  .menu-toggle {
    display: flex; flex-direction: column; gap: 5px;
    background: none; border: none; cursor: pointer; padding: .5rem;
    flex-shrink: 0;
  }
  .menu-toggle span {
    display: block; width: 22px; height: 2px;
    background: var(--text); border-radius: 99px;
    transition: all var(--transition);
  }

  .bottom-nav {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0;
    height: var(--bottom-nav-h);
    background: white; border-top: 1px solid var(--border);
    z-index: 100; box-shadow: 0 -2px 12px rgba(0,0,0,.08);
  }

  .bottom-nav-item {
    flex: 1; display: flex; flex-direction: column;
    align-items: center; justify-content: center; gap: .2rem;
    color: var(--text-muted); font-size: .65rem; font-weight: 600;
    text-decoration: none; padding: .5rem .25rem;
    transition: color var(--transition);
  }
  .bottom-nav-item svg { width: 22px; height: 22px; }
  .bottom-nav-item.active { color: var(--navy); }
  .bottom-nav-item:hover { color: var(--navy); text-decoration: none; }

  .content-wrapper { padding: 1rem; }

  .stats-grid-4 { grid-template-columns: repeat(2, 1fr); }
  .dashboard-grid { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 1fr; }
  .filter-form .filter-row { flex-direction: column; align-items: stretch; }
  .level-label { min-width: 140px; }

  .welcome-content { flex-direction: column-reverse; align-items: flex-start; }
  .welcome-badge { flex-direction: row; align-items: center; gap: .75rem; }

  .auth-card { padding: 2rem 1.25rem; }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .stats-grid-4 { grid-template-columns: repeat(2, 1fr); }
  .table th, .table td { padding: .625rem .75rem; }
  .sop-title { font-size: 1.2rem; }
  .level-progress-grid { grid-template-columns: 1fr; }
}

/* =========================================================
   Print styles
   ========================================================= */
@media print {
  .sidebar, .topbar, .bottom-nav, .btn, .flash-container { display: none !important; }
  .main-content { margin-left: 0 !important; }
  .sop-content { font-size: 11pt; }
}
