:root {
  /* Architectural Stone, Graphite & Terracotta Palette */
  --ink: #111827;
  --ink-2: #1F2937;
  --muted: #4B5563;
  --subtle: #6B7280;
  --bg: #F4F3EF;            /* Warm architectural paper/stone */
  --surface: #FFFFFF;
  --surface-2: #FAF9F6;
  --border: #E5E2DC;
  --border-strong: #D1CCC2;

  --accent: #D9531E;        /* Brick terracotta / Engineering copper */
  --accent-hover: #B84214;
  --accent-soft: #FDF1EC;

  --blue: #1E40AF;
  --blue-soft: #EFF4FF;
  --green: #166534;
  --green-soft: #ECFDF3;
  --red: #B91C1C;
  --red-soft: #FEF2F2;
  --purple: #5B21B6;
  --purple-soft: #F5F2FF;

  --font-sans: "Be Vietnam Pro", "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, Arial, sans-serif;
  --font-mono: "JetBrains Mono", Consolas, Monaco, monospace;

  --radius-sm: 8px;
  --radius: 14px;
  --radius-lg: 18px;
  --shadow-sm: 0 1px 2px rgba(17, 24, 39, 0.04), 0 2px 6px rgba(17, 24, 39, 0.04);
  --shadow-md: 0 4px 12px rgba(17, 24, 39, 0.06), 0 1px 3px rgba(17, 24, 39, 0.05);
  --shadow-lg: 0 14px 36px rgba(17, 24, 39, 0.14);
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--ink);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.hidden { display: none !important; }

/* Subtle custom scrollbars */
::-webkit-scrollbar { width: 7px; height: 7px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #C7C2B8; border-radius: 999px; }
::-webkit-scrollbar-thumb:hover { background: #9CA3AF; }

/* ==================== HEADER (ARCHITECTURAL BLUEPRINT GRID) ==================== */
.app-header {
  position: sticky;
  top: 0;
  z-index: 40;
  background-color: var(--ink);
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.035) 1px, transparent 1px);
  background-size: 24px 24px;
  color: #FFFFFF;
  box-shadow: 0 6px 20px rgba(17, 24, 39, 0.22);
  border-bottom: 2px solid var(--accent);
}

.header-inner {
  max-width: 1140px;
  margin: 0 auto;
  padding: 12px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 13px;
  cursor: pointer;
}

.brand-badge {
  font-family: var(--font-mono);
  background: var(--accent);
  color: #FFFFFF;
  font-weight: 700;
  font-size: 13px;
  padding: 7px 10px;
  border-radius: 8px;
  letter-spacing: 0.8px;
  box-shadow: 0 2px 8px rgba(217, 83, 30, 0.45);
}

.brand-title {
  font-weight: 800;
  font-size: 15.5px;
  letter-spacing: -0.01em;
  line-height: 1.25;
}

.brand-sub {
  font-size: 11.5px;
  color: #9CA3AF;
  letter-spacing: 0.02em;
  margin-top: 1px;
}

.icon-btn {
  font-family: var(--font-sans);
  background: rgba(255, 255, 255, 0.09);
  color: #F9FAFB;
  border: 1px solid rgba(255, 255, 255, 0.16);
  padding: 7px 13px;
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.18s var(--ease);
}
.icon-btn:hover { background: rgba(255, 255, 255, 0.18); border-color: rgba(255, 255, 255, 0.3); }
.icon-btn.accent-btn { background: var(--accent); border-color: var(--accent); color: #FFFFFF; }
.icon-btn.accent-btn:hover { background: var(--accent-hover); }

/* MAIN NAV */
.main-nav {
  max-width: 1140px;
  margin: 0 auto;
  display: flex;
  gap: 6px;
  padding: 0 14px;
  overflow-x: auto;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.nav-tab {
  font-family: var(--font-sans);
  background: transparent;
  color: #9CA3AF;
  border: none;
  border-bottom: 3px solid transparent;
  padding: 11px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: color 0.16s var(--ease);
}
.nav-tab:hover { color: #F9FAFB; }
.nav-tab.active {
  color: #FFFFFF;
  font-weight: 700;
  border-bottom-color: var(--accent);
}
.nav-count {
  font-family: var(--font-mono);
  background: rgba(255, 255, 255, 0.14);
  color: #F3F4F6;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 11px;
  margin-left: 5px;
}

/* ==================== CONTAINER ==================== */
.container {
  max-width: 1140px;
  margin: 0 auto;
  padding: 20px 18px 130px;
}

/* RECENT BAR */
.recent-bar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 15px;
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  box-shadow: var(--shadow-sm);
}
.recent-chip {
  font-family: var(--font-sans);
  background: var(--surface-2);
  color: var(--ink);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 5px 11px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.16s var(--ease);
}
.recent-chip:hover { background: var(--ink); color: #FFFFFF; border-color: var(--ink); }
.recent-chip:hover .mod-dot { background: #FFFFFF !important; }
.recent-chip.mod-c0 .mod-dot { background: #334155; }
.recent-chip.mod-c1 .mod-dot { background: #9A3412; }
.recent-chip.mod-c2 .mod-dot { background: #0F172A; }
.recent-chip.mod-c3 .mod-dot { background: #0369A1; }
.recent-chip.mod-c4 .mod-dot { background: #C2410C; }
.recent-chip.mod-c5 .mod-dot { background: #5B21B6; }
.recent-chip.mod-c6 .mod-dot { background: #166534; }
.recent-chip.mod-c7 .mod-dot { background: #0F766E; }

/* SEARCH & FILTER PANEL */
.search-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
  box-shadow: var(--shadow-md);
  margin-bottom: 24px;
}

.search-box { position: relative; display: flex; align-items: center; }
.search-icon { position: absolute; left: 15px; font-size: 16px; opacity: 0.7; }
#searchInput {
  font-family: var(--font-sans);
  width: 100%;
  padding: 13px 42px 13px 44px;
  font-size: 14.5px;
  background: var(--surface-2);
  border: 1.5px solid var(--border-strong);
  border-radius: 11px;
  outline: none;
  color: var(--ink);
  font-weight: 500;
  transition: all 0.18s var(--ease);
}
#searchInput:focus {
  background: #FFFFFF;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(217, 83, 30, 0.12);
}

.clear-btn {
  position: absolute;
  right: 11px;
  background: var(--border);
  border: none;
  border-radius: 50%;
  width: 26px;
  height: 26px;
  cursor: pointer;
  font-weight: 700;
  color: var(--ink);
}

/* MODULE FILTER PILLS */
.module-filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  padding: 13px 0 4px;
}

.mod-pill {
  font-family: var(--font-sans);
  background: var(--surface-2);
  color: var(--ink-2);
  border: 1.5px solid var(--border-strong);
  border-radius: 9px;
  padding: 6px 12px;
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.16s var(--ease);
}
.mod-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}
.mod-pill.active .mod-dot { background: #FFFFFF !important; }

/* Synced Module Pill Colors */
.mod-pill.mod-all.active { background: var(--ink); color: #FFFFFF; border-color: var(--ink); }

.mod-pill.mod-c0 { border-color: #94A3B8; color: #334155; background: #F8FAFC; }
.mod-pill.mod-c0 .mod-dot { background: #334155; }
.mod-pill.mod-c0:hover, .mod-pill.mod-c0.active { background: #334155; color: #FFFFFF; border-color: #334155; }

.mod-pill.mod-c1 { border-color: #FDBA74; color: #9A3412; background: #FFF7ED; }
.mod-pill.mod-c1 .mod-dot { background: #9A3412; }
.mod-pill.mod-c1:hover, .mod-pill.mod-c1.active { background: #9A3412; color: #FFFFFF; border-color: #9A3412; }

.mod-pill.mod-c2 { border-color: #93C5FD; color: #0F172A; background: #F1F5F9; }
.mod-pill.mod-c2 .mod-dot { background: #0F172A; }
.mod-pill.mod-c2:hover, .mod-pill.mod-c2.active { background: #0F172A; color: #FFFFFF; border-color: #0F172A; }

.mod-pill.mod-c3 { border-color: #7DD3FC; color: #0369A1; background: #F0F9FF; }
.mod-pill.mod-c3 .mod-dot { background: #0369A1; }
.mod-pill.mod-c3:hover, .mod-pill.mod-c3.active { background: #0369A1; color: #FFFFFF; border-color: #0369A1; }

.mod-pill.mod-c4 { border-color: #FDBA74; color: #C2410C; background: #FDF1EC; }
.mod-pill.mod-c4 .mod-dot { background: #C2410C; }
.mod-pill.mod-c4:hover, .mod-pill.mod-c4.active { background: #C2410C; color: #FFFFFF; border-color: #C2410C; }

.mod-pill.mod-c5 { border-color: #C4B5FD; color: #5B21B6; background: #F5F2FF; }
.mod-pill.mod-c5 .mod-dot { background: #5B21B6; }
.mod-pill.mod-c5:hover, .mod-pill.mod-c5.active { background: #5B21B6; color: #FFFFFF; border-color: #5B21B6; }

.mod-pill.mod-c6 { border-color: #86EFAC; color: #166534; background: #ECFDF3; }
.mod-pill.mod-c6 .mod-dot { background: #166534; }
.mod-pill.mod-c6:hover, .mod-pill.mod-c6.active { background: #166534; color: #FFFFFF; border-color: #166534; }

.mod-pill.mod-c7 { border-color: #5EEAD4; color: #0F766E; background: #F0FDFA; }
.mod-pill.mod-c7 .mod-dot { background: #0F766E; }
.mod-pill.mod-c7:hover, .mod-pill.mod-c7.active { background: #0F766E; color: #FFFFFF; border-color: #0F766E; }

.troubleshoot-bar {
  margin-top: 12px;
  display: flex;
  align-items: flex-start;
  gap: 8px;
  flex-wrap: wrap;
}

.bar-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding-top: 6px;
  white-space: nowrap;
}

.chip-list { display: flex; flex-wrap: wrap; gap: 6px; }

.chip {
  font-family: var(--font-sans);
  background: var(--accent-soft);
  color: #9A3412;
  border: 1px solid #F6C5AF;
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s var(--ease);
}
.chip:hover, .chip.active {
  background: var(--accent);
  color: #FFFFFF;
  border-color: var(--accent);
}

.tier-bar {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

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

.tier-switch {
  display: inline-flex;
  background: #ECE9E2;
  padding: 3px;
  border-radius: 10px;
  border: 1px solid var(--border-strong);
}
.tier-switch.compact .tier-btn { padding: 4px 10px; font-size: 12px; }

.tier-btn {
  font-family: var(--font-sans);
  border: none;
  background: transparent;
  padding: 6px 13px;
  border-radius: 7px;
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
  color: var(--muted);
  transition: all 0.16s var(--ease);
}
.tier-btn.active[data-tier="standard"] {
  background: #FFFFFF;
  color: var(--blue);
  box-shadow: 0 1px 4px rgba(17, 24, 39, 0.12);
}
.tier-btn.active[data-tier="premium"] {
  background: #FFFFFF;
  color: var(--purple);
  box-shadow: 0 1px 4px rgba(17, 24, 39, 0.12);
}

.holdpoint-toggle {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--red);
  background: var(--red-soft);
  border: 1px solid #FECACA;
  padding: 6px 12px;
  border-radius: 9px;
  cursor: pointer;
}
.holdpoint-toggle input { width: 15px; height: 15px; accent-color: var(--red); cursor: pointer; }

/* ==================== MODULE SECTIONS & ARCHITECTURAL SOP CARDS ==================== */
.sop-sections { display: flex; flex-direction: column; gap: 28px; }

.module-group-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  padding: 12px 18px;
  background: var(--ink);
  color: #FFFFFF;
  border: none;
  border-radius: 11px;
  box-shadow: 0 3px 10px rgba(17, 24, 39, 0.14);
}
.module-group-title {
  font-size: 15px;
  font-weight: 800;
  color: #FFFFFF;
  letter-spacing: 0.01em;
}
.module-group-count {
  font-family: var(--font-mono);
  font-size: 11.5px;
  font-weight: 700;
  color: #FFFFFF;
  background: rgba(255, 255, 255, 0.2);
  padding: 3px 11px;
  border-radius: 999px;
}

/* Distinct Header Band & Card Accent Colors per Module */
.module-group-header.mod-c0 { background: linear-gradient(135deg, #334155, #475569); }
.module-group-header.mod-c1 { background: linear-gradient(135deg, #7C2D12, #B45309); }
.module-group-header.mod-c2 { background: linear-gradient(135deg, #0F172A, #1E3A5F); }
.module-group-header.mod-c3 { background: linear-gradient(135deg, #0369A1, #0284C7); }
.module-group-header.mod-c4 { background: linear-gradient(135deg, #C2410C, #EA580C); }
.module-group-header.mod-c5 { background: linear-gradient(135deg, #5B21B6, #7C3AED); }
.module-group-header.mod-c6 { background: linear-gradient(135deg, #166534, #15803D); }
.module-group-header.mod-c7 { background: linear-gradient(135deg, #115E59, #0F766E); }

.sop-card.mod-c0 .sop-id { background: #334155; }
.sop-card.mod-c1 .sop-id { background: #9A3412; }
.sop-card.mod-c2 .sop-id { background: #0F172A; }
.sop-card.mod-c3 .sop-id { background: #0369A1; }
.sop-card.mod-c4 .sop-id { background: #C2410C; }
.sop-card.mod-c5 .sop-id { background: #5B21B6; }
.sop-card.mod-c6 .sop-id { background: #166534; }
.sop-card.mod-c7 .sop-id { background: #0F766E; }

.sop-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 14px;
}

.sop-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3.5px solid var(--ink);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 11px;
  transition: transform 0.2s var(--ease), box-shadow 0.2s var(--ease), border-color 0.2s var(--ease);
}
.sop-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
  border-color: var(--border-strong);
}

/* Refined Architectural Module Colors */
.mod-c0 { border-left-color: #4B5563 !important; }
.mod-c1 { border-left-color: #9A3412 !important; }
.mod-c2 { border-left-color: #111827 !important; }
.mod-c3 { border-left-color: #0369A1 !important; }
.mod-c4 { border-left-color: #D9531E !important; }
.mod-c5 { border-left-color: #6D28D9 !important; }
.mod-c6 { border-left-color: #15803D !important; }
.mod-c7 { border-left-color: #0F766E !important; }

.sop-card-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }

.sop-id {
  font-family: var(--font-mono);
  background: var(--ink);
  color: #FFFFFF;
  font-weight: 700;
  font-size: 11.5px;
  padding: 4px 9px;
  border-radius: 6px;
  letter-spacing: 0.3px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 6px;
}
.badge-red { background: var(--red-soft); color: var(--red); border: 1px solid #FECACA; }
.badge-green { background: var(--green-soft); color: var(--green); border: 1px solid #BBF7D0; }
.badge-blue { background: var(--blue-soft); color: var(--blue); border: 1px solid #BFDBFE; }
.badge-amber { background: #FEF3C7; color: #92400E; border: 1px solid #FDE68A; }

.sop-card-title {
  margin: 0;
  font-size: 15.5px;
  font-weight: 700;
  color: var(--ink);
  line-height: 1.4;
  letter-spacing: -0.01em;
}
.sop-card-module { font-size: 12px; color: var(--muted); }
.sop-card-tags { display: flex; flex-wrap: wrap; gap: 5px; }
.mini-tag {
  font-size: 11px;
  background: var(--surface-2);
  color: var(--muted);
  border: 1px solid var(--border);
  padding: 2px 8px;
  border-radius: 999px;
  font-weight: 500;
}
.sop-card-footer {
  margin-top: auto;
  padding-top: 11px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 700;
  color: var(--ink-2);
}
.sop-card-footer span:last-child { color: var(--accent); }

/* ==================== DETAIL VIEW ==================== */
.detail-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 14px;
}
.back-btn {
  font-family: var(--font-sans);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  padding: 8px 15px;
  border-radius: var(--radius-sm);
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
  color: var(--ink);
  box-shadow: var(--shadow-sm);
  transition: all 0.15s var(--ease);
}
.back-btn:hover { background: var(--ink); color: #FFFFFF; border-color: var(--ink); }

.detail-header {
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: 5px solid var(--accent);
  border-radius: var(--radius);
  padding: 20px 22px;
  margin-bottom: 14px;
  box-shadow: var(--shadow-sm);
}
.detail-header.mod-c0 { border-top-color: #334155; }
.detail-header.mod-c0 .detail-meta { color: #334155; }
.detail-header.mod-c1 { border-top-color: #9A3412; }
.detail-header.mod-c1 .detail-meta { color: #9A3412; }
.detail-header.mod-c2 { border-top-color: #0F172A; }
.detail-header.mod-c2 .detail-meta { color: #0F172A; }
.detail-header.mod-c3 { border-top-color: #0369A1; }
.detail-header.mod-c3 .detail-meta { color: #0369A1; }
.detail-header.mod-c4 { border-top-color: #C2410C; }
.detail-header.mod-c4 .detail-meta { color: #C2410C; }
.detail-header.mod-c5 { border-top-color: #5B21B6; }
.detail-header.mod-c5 .detail-meta { color: #5B21B6; }
.detail-header.mod-c6 { border-top-color: #166534; }
.detail-header.mod-c6 .detail-meta { color: #166534; }
.detail-header.mod-c7 { border-top-color: #0F766E; }
.detail-header.mod-c7 .detail-meta { color: #0F766E; }
.detail-meta-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}
.detail-meta {
  font-family: var(--font-mono);
  font-size: 12.5px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.02em;
}
.detail-title {
  margin: 0;
  font-size: 22px;
  font-weight: 800;
  line-height: 1.32;
  letter-spacing: -0.02em;
  color: var(--ink);
}

.sub-tabs { display: flex; gap: 8px; margin-bottom: 16px; overflow-x: auto; }
.sub-tab {
  font-family: var(--font-sans);
  flex: 1;
  min-width: 150px;
  background: var(--surface);
  border: 1.5px solid var(--border-strong);
  border-radius: 11px;
  padding: 11px 14px;
  font-size: 13.5px;
  font-weight: 700;
  color: var(--muted);
  cursor: pointer;
  text-align: center;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: all 0.16s var(--ease);
}
.sub-tab:hover { border-color: var(--ink); color: var(--ink); }
.sub-tab.active {
  background: var(--ink);
  color: #FFFFFF;
  border-color: var(--ink);
  box-shadow: 0 3px 10px rgba(17, 24, 39, 0.2);
}
.draft-dot { width: 8px; height: 8px; border-radius: 50%; background: #F59E0B; display: inline-block; }

/* QUICK JUMP BAR */
.quick-jump-bar {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  padding-bottom: 16px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border);
}
.jump-btn {
  font-family: var(--font-sans);
  background: var(--surface-2);
  color: var(--ink-2);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  padding: 5px 13px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s var(--ease);
}
.jump-btn:hover { background: var(--accent); color: #FFFFFF; border-color: var(--accent); }

/* PREV / NEXT BAR */
.prev-next-bar {
  margin-top: 30px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.pn-btn {
  font-family: var(--font-sans);
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  padding: 11px 15px;
  font-size: 13px;
  font-weight: 700;
  color: var(--ink);
  cursor: pointer;
  max-width: 48%;
  text-align: left;
  transition: all 0.16s var(--ease);
}
.pn-btn:hover { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-hover); }
.pn-btn.next { text-align: right; margin-left: auto; }

/* ==================== EDITORIAL MARKDOWN RENDERING ==================== */
.card-surface, #sub-guide {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px 26px;
  box-shadow: var(--shadow-sm);
}

.md-body h1 {
  font-size: 20px;
  font-weight: 800;
  margin-top: 0;
  color: var(--ink);
  border-bottom: 1.5px solid var(--border);
  padding-bottom: 10px;
  letter-spacing: -0.015em;
}
.md-body h2 {
  font-size: 16.5px;
  font-weight: 800;
  color: var(--ink);
  margin-top: 28px;
  padding: 4px 0 4px 12px;
  border-left: 3.5px solid var(--accent);
  scroll-margin-top: 125px;
  letter-spacing: -0.01em;
}
.md-body h3 { font-size: 15px; font-weight: 700; color: var(--blue); margin-top: 20px; }
.md-body p { margin: 9px 0; color: var(--ink-2); }
.md-body ul, .md-body ol { padding-left: 22px; margin: 9px 0; color: var(--ink-2); }
.md-body li { margin: 6px 0; }
.md-body code {
  font-family: var(--font-mono);
  background: #F3EFEA;
  color: #9A3412;
  padding: 1px 6px;
  border-radius: 5px;
  font-size: 12.5px;
  font-weight: 600;
}
.md-body blockquote {
  margin: 14px 0;
  padding: 14px 18px;
  background: var(--accent-soft);
  border-left: 4px solid var(--accent);
  border-radius: 0 10px 10px 0;
}
.md-body pre {
  font-family: var(--font-mono);
  background: var(--ink);
  color: #F3F4F6;
  padding: 15px;
  border-radius: 10px;
  overflow-x: auto;
  font-size: 12px;
}
.md-body pre code { background: transparent; color: inherit; padding: 0; font-weight: 400; }

.table-wrap { overflow-x: auto; margin: 14px 0; border-radius: 10px; border: 1px solid var(--border); }
.md-body table { width: 100%; border-collapse: collapse; font-size: 13.5px; min-width: 520px; }
.md-body th {
  background: var(--surface-2);
  color: var(--ink);
  font-weight: 700;
  text-align: left;
  padding: 11px 12px;
  border-bottom: 1.5px solid var(--border-strong);
  border-right: 1px solid var(--border);
}
.md-body th:last-child, .md-body td:last-child { border-right: none; }
.md-body td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  vertical-align: top;
}
.md-body tr:last-child td { border-bottom: none; }
.md-body tr:nth-child(even) td { background: #FCFCFA; }

/* TIER COLUMN HIGHLIGHTING */
body[data-active-tier="standard"] th.tier-col-standard { background: #DBEAFE !important; color: #1E3A8A !important; }
body[data-active-tier="standard"] td.tier-col-standard { background: #F0F6FF !important; font-weight: 600; }
body[data-active-tier="standard"] th.tier-col-premium,
body[data-active-tier="standard"] td.tier-col-premium { opacity: 0.45; }

body[data-active-tier="premium"] th.tier-col-premium { background: #EDE9FE !important; color: #4C1D95 !important; }
body[data-active-tier="premium"] td.tier-col-premium { background: #F7F4FF !important; font-weight: 600; }
body[data-active-tier="premium"] th.tier-col-standard,
body[data-active-tier="premium"] td.tier-col-standard { opacity: 0.45; }

/* EMBEDDED SVG DIAGRAM CARD */
.diagram-box {
  margin: 18px 0;
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  overflow: hidden;
  background: #FFFFFF;
  box-shadow: var(--shadow-sm);
}
.diagram-bar {
  background: var(--surface-2);
  padding: 9px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--border);
  font-size: 12.5px;
  font-weight: 700;
  color: var(--ink);
}
.diagram-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.diagram-zoom-btn, .diagram-dl-btn {
  font-family: var(--font-sans);
  border-radius: 7px;
  padding: 5px 11px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s var(--ease);
}
.diagram-zoom-btn { background: var(--blue-soft); color: var(--blue); border: 1px solid #BFDBFE; }
.diagram-zoom-btn:hover { background: var(--blue); color: #FFFFFF; }
.diagram-dl-btn { background: var(--accent-soft); color: var(--accent-hover); border: 1px solid #F6C5AF; }
.diagram-dl-btn:hover { background: var(--accent); color: #FFFFFF; }
.diagram-canvas { padding: 10px; cursor: zoom-in; }
.diagram-canvas svg { width: 100%; height: auto; display: block; }

/* ==================== CHECKLIST ZALO PANEL ==================== */
.checklist-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px 22px;
  box-shadow: var(--shadow-sm);
}
.checklist-intro { display: flex; flex-direction: column; gap: 4px; margin-bottom: 16px; }
.checklist-intro-top { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 8px; }
.checklist-intro span { font-size: 13px; color: var(--muted); }
.autosave-badge {
  background: var(--green-soft);
  color: var(--green);
  border: 1px solid #BBF7D0;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 700;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.form-grid label, .field-stack {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.form-grid input, .field-stack input {
  font-family: var(--font-sans);
  padding: 10px 13px;
  border: 1.5px solid var(--border-strong);
  border-radius: 9px;
  font-size: 14px;
  color: var(--ink);
  background: var(--surface-2);
  outline: none;
}
.form-grid input:focus, .field-stack input:focus { background: #FFFFFF; border-color: var(--accent); }

.checklist-quick-actions { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.small-btn {
  font-family: var(--font-sans);
  background: var(--green-soft);
  color: var(--green);
  border: 1px solid #86EFAC;
  padding: 7px 13px;
  border-radius: 8px;
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
}
.small-btn.ghost { background: var(--surface-2); color: var(--muted); border-color: var(--border-strong); }

.checklist-items { display: flex; flex-direction: column; gap: 10px; }
.chk-row {
  border: 1.5px solid var(--border);
  border-radius: 11px;
  padding: 13px;
  background: #FFFFFF;
  transition: all 0.15s var(--ease);
}
.chk-row.status-pass { border-color: #22C55E; background: var(--green-soft); }
.chk-row.status-fail { border-color: #EF4444; background: var(--red-soft); }

.chk-main { display: flex; align-items: flex-start; gap: 12px; cursor: pointer; }
.chk-state-btn {
  min-width: 36px;
  height: 36px;
  border-radius: 9px;
  border: 1.5px solid var(--border-strong);
  background: #FFFFFF;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.chk-text { font-size: 14.5px; font-weight: 600; color: var(--ink); padding-top: 5px; }
.chk-note-input {
  font-family: var(--font-sans);
  width: 100%;
  margin-top: 10px;
  padding: 10px 12px;
  border: 1.5px solid #EF4444;
  border-radius: 8px;
  font-size: 13.5px;
  background: #FFFFFF;
}

/* STICKY BOTTOM BAR */
.sticky-bottom-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 50;
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--border-strong);
  box-shadow: 0 -8px 24px rgba(17, 24, 39, 0.12);
  padding: 11px 18px;
}
.sticky-bottom-inner {
  max-width: 1140px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
}
.progress-wrap { flex: 1; min-width: 200px; }
.progress-text { font-size: 13px; font-weight: 700; margin-bottom: 5px; }
.progress-text.pass { color: var(--green); }
.progress-text.fail { color: var(--red); }
.progress-text.pending { color: var(--ink); }
.progress-track { height: 6px; background: var(--border); border-radius: 999px; overflow: hidden; }
.progress-fill { height: 100%; width: 0%; background: #16A34A; transition: width 0.25s var(--ease); }
.progress-fill.fail { background: #DC2626; }

.sticky-actions { display: flex; gap: 8px; }
.action-buttons-inline { margin-top: 14px; }

.btn-primary, .btn-accent {
  font-family: var(--font-sans);
  border: none;
  border-radius: 10px;
  padding: 12px 18px;
  font-size: 13.5px;
  font-weight: 700;
  color: #FFFFFF;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.16s var(--ease);
}
.btn-primary { background: var(--ink); }
.btn-primary:hover { background: #000000; }
.btn-accent { background: var(--accent); }
.btn-accent:hover { background: var(--accent-hover); }

/* WORKER 1-PAGE PRINTABLE POSTER */
.print-toolbar {
  background: var(--accent-soft);
  border: 1px solid #F6C5AF;
  border-radius: 12px;
  padding: 12px 16px;
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  font-size: 13px;
  font-weight: 600;
  color: #9A3412;
}
.worker-sheet {
  background: #FFFFFF;
  border: 2.5px solid var(--ink);
  border-radius: 12px;
  padding: 28px;
  box-shadow: var(--shadow-md);
}
.worker-sheet-header {
  border-bottom: 3px solid var(--accent);
  padding-bottom: 12px;
  margin-bottom: 16px;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 8px;
}
.worker-sheet h3 { font-size: 20px; font-weight: 800; color: var(--red); margin: 0 0 12px; }
.worker-sheet ol li { font-size: 16px; margin: 10px 0; line-height: 1.55; color: var(--ink); }
.worker-sheet svg { width: 100%; height: auto; margin-top: 16px; border: 1px solid var(--border); border-radius: 8px; }

/* MODAL */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal-backdrop { position: absolute; inset: 0; background: rgba(17, 24, 39, 0.78); backdrop-filter: blur(3px); }
.modal-box {
  position: relative;
  background: #FFFFFF;
  border-radius: 14px;
  width: 100%;
  max-width: 480px;
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: var(--shadow-lg);
}
.modal-box.modal-wide { max-width: 1060px; }
.modal-header {
  background: var(--ink);
  color: #FFFFFF;
  padding: 13px 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  font-weight: 700;
}
.modal-header-actions { display: flex; gap: 8px; }
.modal-content { padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.modal-footer { display: flex; justify-content: flex-end; padding-top: 6px; }
.svg-zoom-body { padding: 16px; overflow: auto; background: var(--bg); }
.svg-zoom-body svg { width: 100%; min-width: 720px; height: auto; display: block; border-radius: 8px; }

/* TOAST */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100vw - 32px);
  background: var(--ink);
  color: #FFFFFF;
  padding: 11px 18px;
  border-radius: 14px;
  font-size: 13.5px;
  font-weight: 600;
  line-height: 1.4;
  text-align: center;
  box-shadow: var(--shadow-lg);
  z-index: 220;
  white-space: normal;
  word-break: break-word;
}
body.has-sticky-bar .toast { bottom: 96px; }

@media (max-width: 640px) {
  .header-inner { padding: 10px 12px; }
  .brand-title { font-size: 14px; }
  .brand-sub { font-size: 10.5px; }
  .icon-btn { padding: 6px 10px; font-size: 11.5px; }
  .nav-tab { padding: 9px 11px; font-size: 12px; }
  .container { padding: 12px 12px 136px; }
  .recent-bar {
    flex-wrap: nowrap;
    overflow-x: auto;
    padding: 8px 11px;
    margin-bottom: 10px;
  }
  .recent-bar .chip-list { flex-wrap: nowrap; }
  .recent-chip { white-space: nowrap; flex-shrink: 0; }

  /* Compact First-Fold Search & Horizontal Swipe Filters on 390x844 Mobile */
  .search-panel { padding: 12px; margin-bottom: 14px; border-radius: 14px; }
  #searchInput { padding: 10px 36px 10px 38px; font-size: 13.5px; }
  .module-filter-bar {
    flex-wrap: nowrap;
    overflow-x: auto;
    padding: 10px 0 4px;
    margin: 0 -4px;
    padding-left: 4px;
    padding-right: 4px;
    -webkit-overflow-scrolling: touch;
  }
  .mod-pill { padding: 5px 10px; font-size: 12px; flex-shrink: 0; }
  .troubleshoot-bar {
    margin-top: 8px;
    flex-wrap: nowrap;
    align-items: center;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 2px;
  }
  .troubleshoot-bar .bar-label { padding-top: 0; font-size: 11px; }
  .troubleshoot-bar .chip-list { flex-wrap: nowrap; }
  .chip { white-space: nowrap; flex-shrink: 0; padding: 4px 10px; font-size: 11.5px; }
  .tier-bar { margin-top: 10px; padding-top: 10px; gap: 8px; }
  .tier-group .bar-label { display: none; }
  .tier-btn { padding: 5px 10px; font-size: 11.5px; }
  .holdpoint-toggle { padding: 5px 10px; font-size: 11.5px; }

  .sticky-bottom-inner { flex-direction: column; align-items: stretch; gap: 8px; }
  .sticky-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .detail-title { font-size: 18px; }
  .card-surface, #sub-guide { padding: 16px; }
  .pn-btn { max-width: 100%; width: 100%; }
  body.has-sticky-bar .toast { bottom: 136px; }
  body.has-sticky-bar .scroll-top-btn { bottom: 134px; }
}

@media print {
  body { background: #FFFFFF; }
  .no-print { display: none !important; }
  .container { max-width: 100%; padding: 0; }
  .detail-header { box-shadow: none; border: 1.5px solid #111827; border-top-width: 5px; margin-bottom: 12px; padding: 14px 18px; }
  body.printing-worker .detail-header { display: none !important; }
  #sub-guide, .card-surface { border: none; box-shadow: none; padding: 0; }
  .worker-sheet { border: 2px solid #000000; box-shadow: none; padding: 18px; }
}

/* ==================== V4.0: CLIENT MODE, PHOTOS GALLERY & PIN LOCK ==================== */
.header-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.client-mode-btn.active { background: #16A34A; border-color: #16A34A; color: #FFFFFF; }

.client-banner {
  background: #166534;
  color: #FFFFFF;
  font-size: 12.5px;
  padding: 7px 16px;
  text-align: center;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.client-banner button {
  background: rgba(255, 255, 255, 0.2);
  color: #FFFFFF;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 6px;
  padding: 3px 10px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

body.client-mode .internal-only { display: none !important; }
body.client-mode .internal-block { display: none !important; }

/* Photorealistic & Real Site Photos Gallery */
.photos-section { margin-bottom: 18px; }
.photos-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
  margin-top: 8px;
}
.photo-card {
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  overflow: hidden;
  background: #FFFFFF;
  box-shadow: var(--shadow-sm);
  cursor: zoom-in;
}
.photo-card img {
  width: 100%;
  height: 195px;
  object-fit: cover;
  display: block;
}
.photo-caption {
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 700;
  color: var(--ink);
  background: var(--surface-2);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
}
.photo-placeholder {
  background: var(--surface-2);
  border: 1.5px dashed var(--border-strong);
  border-radius: 10px;
  padding: 11px 14px;
  font-size: 12.5px;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

/* SCROLL TO TOP BUTTON */
.scroll-top-btn {
  position: fixed;
  right: 18px;
  bottom: 24px;
  z-index: 60;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1.5px solid var(--border-strong);
  background: var(--ink);
  color: #FFFFFF;
  font-size: 18px;
  cursor: pointer;
  box-shadow: var(--shadow-md);
  transition: transform 0.16s var(--ease), background 0.16s var(--ease), bottom 0.18s var(--ease);
}
body.has-sticky-bar .scroll-top-btn { bottom: 96px; }
.scroll-top-btn:hover { background: var(--accent); border-color: var(--accent); transform: translateY(-2px); }

/* PIN Lock Screen */
.pin-overlay {
  position: fixed;
  inset: 0;
  z-index: 300;
  background: rgba(17, 24, 39, 0.94);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.pin-box {
  background: #FFFFFF;
  border-radius: 16px;
  padding: 28px 24px;
  width: 100%;
  max-width: 380px;
  text-align: center;
  box-shadow: var(--shadow-lg);
}
.pin-box input {
  width: 100%;
  padding: 13px;
  font-family: var(--font-mono);
  font-size: 18px;
  text-align: center;
  letter-spacing: 4px;
  border: 2px solid var(--border-strong);
  border-radius: 10px;
  outline: none;
}
.pin-box input:focus { border-color: var(--accent); }
.pin-error { color: var(--red); font-size: 13px; font-weight: 700; margin-top: 8px; }
