:root {
  --sidebar-w: 240px;
  --teal:       #1a7a72;
  --teal-dark:  #0f5550;
  --teal-light: #2aa89e;
  --accent:     #e8c84a;
  --bg:         #f5f4f0;
  --content-bg: #ffffff;
  --text:       #1c2027;
  --text-muted: #5a6070;
  --border:     #dddbd4;
  --sidebar-bg: #1c2a28;
  --sidebar-text: #c8d8d5;
  --sidebar-hover: #2a3c38;
  --sidebar-active: #1a7a72;
  --header-h:   56px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'IBM Plex Sans', sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ── TOP HEADER ── */
#topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--header-h);
  background: var(--teal-dark);
  display: flex;
  align-items: center;
  padding: 0 20px;
  z-index: 200;
  gap: 16px;
  border-bottom: 3px solid var(--accent);
}
#topbar .brand {
  font-family: 'IBM Plex Mono', monospace;
  font-weight: 600;
  font-size: 18px;
  color: #fff;
  letter-spacing: 0.04em;
  white-space: nowrap;
}
#topbar .brand span { color: var(--accent); }
#topbar .tagline {
  font-size: 11px;
  color: #8aada9;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin-left: 4px;
  display: none;
}
@media (min-width: 700px) { #topbar .tagline { display: block; } }

/* hamburger for mobile */
#menu-toggle {
  display: none;
  background: none; border: none; cursor: pointer;
  color: white; font-size: 22px; margin-left: auto;
  padding: 4px 8px;
}
@media (max-width: 768px) { #menu-toggle { display: block; } }

/* ── LAYOUT ── */
#layout {
  display: flex;
  padding-top: var(--header-h);
  min-height: 100vh;
}

/* ── SIDEBAR ── */
#sidebar {
  position: fixed;
  top: var(--header-h);
  left: 0;
  width: var(--sidebar-w);
  height: calc(100vh - var(--header-h));
  background: var(--sidebar-bg);
  overflow-y: auto;
  overflow-x: hidden;
  z-index: 100;
  transition: transform 0.3s ease;
  scrollbar-width: thin;
  scrollbar-color: #3a5250 transparent;
}
#sidebar::-webkit-scrollbar { width: 4px; }
#sidebar::-webkit-scrollbar-thumb { background: #3a5250; border-radius: 2px; }

@media (max-width: 768px) {
  #sidebar { transform: translateX(-100%); }
  #sidebar.open { transform: translateX(0); }
}

/* State switcher */
.state-switcher {
  padding: 14px 14px 10px;
  border-bottom: 1px solid #2a3c38;
}
.state-label {
  font-size: 9px;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: #5a7a76;
  margin-bottom: 6px;
  font-family: 'IBM Plex Mono', monospace;
}
.state-tabs {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}
.state-tab {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 3px;
  cursor: pointer;
  border: 1px solid #3a5250;
  color: var(--sidebar-text);
  background: transparent;
  transition: all 0.15s;
  letter-spacing: 0.05em;
}
.state-tab:hover { background: var(--sidebar-hover); border-color: var(--teal-light); }
.state-tab.active { background: var(--teal); border-color: var(--teal-light); color: #fff; }
.state-tab.add-state {
  color: #5a7a76;
  border-style: dashed;
  font-size: 14px;
  padding: 2px 8px;
}
.state-tab.add-state:hover { color: var(--accent); border-color: var(--accent); background: transparent; }

/* Nav sections */
.nav-section {
  border-bottom: 1px solid #243530;
}
.nav-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  cursor: pointer;
  color: #7aada8;
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  font-family: 'IBM Plex Mono', monospace;
  user-select: none;
  transition: color 0.15s;
}
.nav-section-header:hover { color: var(--accent); }
.nav-section-header .chevron {
  font-size: 10px;
  transition: transform 0.2s;
}
.nav-section-header.collapsed .chevron { transform: rotate(-90deg); }
.nav-items { }
.nav-items.hidden { display: none; }

.nav-item {
  display: flex;
  align-items: center;
  padding: 7px 14px 7px 22px;
  font-size: 12.5px;
  color: var(--sidebar-text);
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
  line-height: 1.3;
  gap: 6px;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}
.nav-item:hover { background: var(--sidebar-hover); color: #fff; }
.nav-item.active { background: var(--teal); color: #fff; font-weight: 500; }
.nav-item .icon { font-size: 11px; opacity: 0.6; flex-shrink: 0; }

/* Sub-items */
.nav-sub { background: #16211f; }
.nav-sub .nav-item { padding-left: 32px; font-size: 12px; color: #8aada9; }
.nav-sub .nav-item:hover { color: #fff; background: #1f302d; }
.nav-sub .nav-item.active { background: var(--teal-dark); color: #fff; }

/* ── MAIN CONTENT ── */
#main {
  margin-left: var(--sidebar-w);
  flex: 1;
  padding: 36px 40px 60px;
  min-height: calc(100vh - var(--header-h));
  max-width: 1100px;
}
@media (max-width: 768px) {
  #main { margin-left: 0; padding: 24px 20px 40px; }
}

/* Content area — section HTML is injected here */
#content-area {
  animation: fadeIn 0.2s ease;
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

/* Loading indicator */
.section-loading {
  padding: 60px 0;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  letter-spacing: 0.05em;
}

/* Page header */
.page-header {
  margin-bottom: 28px;
  padding-bottom: 16px;
  border-bottom: 2px solid var(--border);
}
.page-header .breadcrumb {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  color: var(--text-muted);
  letter-spacing: 0.05em;
  margin-bottom: 8px;
}
.page-header h1 {
  font-size: 26px;
  font-weight: 600;
  color: var(--teal-dark);
  letter-spacing: -0.01em;
}
.page-header .subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* Cards grid */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
  margin-bottom: 32px;
}
.card {
  background: var(--content-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 20px;
  transition: box-shadow 0.15s, border-color 0.15s;
}
.card:hover { box-shadow: 0 4px 16px rgba(0,0,0,0.08); border-color: var(--teal-light); }
.card h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--teal-dark);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.card h3 .icon { font-size: 16px; }
.card ul { list-style: none; }
.card ul li {
  font-size: 13px;
  padding: 5px 0;
  border-bottom: 1px solid #f0ede6;
}
.card ul li:last-child { border-bottom: none; }
.card ul li a {
  color: var(--teal);
  text-decoration: none;
  transition: color 0.12s;
  display: flex;
  align-items: center;
  gap: 6px;
}
.card ul li a:hover { color: var(--teal-dark); }
.card ul li a::before { content: '→'; font-size: 10px; color: var(--accent); }

/* Standards table */
.standards-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--content-bg);
  border-radius: 6px;
  overflow: hidden;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
  font-size: 13px;
  margin-bottom: 24px;
}
.standards-table th {
  background: var(--teal-dark);
  color: #fff;
  padding: 10px 14px;
  text-align: left;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-family: 'IBM Plex Mono', monospace;
}
.standards-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
  line-height: 1.5;
}
.standards-table tr:last-child td { border-bottom: none; }
.standards-table tr:hover td { background: #f8f7f2; }
.standards-table td:first-child { font-weight: 500; color: var(--teal-dark); min-width: 180px; }
.standards-table a { color: var(--teal); text-decoration: none; }
.standards-table a:hover { text-decoration: underline; }

/* Notice box */
.notice {
  background: #fff8e1;
  border-left: 4px solid var(--accent);
  padding: 12px 16px;
  border-radius: 0 4px 4px 0;
  font-size: 13px;
  margin-bottom: 20px;
  color: #5a4a10;
}
.notice strong { color: #3a2e00; }

/* Info box */
.info-box {
  background: #e8f5f3;
  border: 1px solid #9dd0ca;
  border-radius: 6px;
  padding: 16px 20px;
  font-size: 13px;
  margin-bottom: 20px;
  color: #1a4a46;
}
.info-box h4 { font-size: 13px; font-weight: 600; margin-bottom: 6px; }

/* Section heading */
.section-heading {
  font-size: 15px;
  font-weight: 600;
  color: var(--teal-dark);
  margin: 24px 0 12px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}

/* Calculator widget */
.calculator {
  background: var(--content-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 24px;
  margin-bottom: 20px;
  max-width: 500px;
}
.calculator h3 {
  font-size: 15px;
  font-weight: 600;
  color: var(--teal-dark);
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.calc-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}
.calc-row label {
  font-size: 12px;
  color: var(--text-muted);
  min-width: 180px;
  line-height: 1.3;
}
.calc-row input, .calc-row select {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 7px 10px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s;
  background: #fafaf8;
}
.calc-row input:focus, .calc-row select:focus {
  border-color: var(--teal-light);
  background: #fff;
}
.calc-btn {
  background: var(--teal);
  color: #fff;
  border: none;
  border-radius: 4px;
  padding: 9px 20px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  margin-top: 4px;
  transition: background 0.15s;
  font-family: 'IBM Plex Sans', sans-serif;
}
.calc-btn:hover { background: var(--teal-dark); }
.calc-result {
  margin-top: 14px;
  padding: 12px 16px;
  background: #e8f5f3;
  border-radius: 4px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 14px;
  color: var(--teal-dark);
  font-weight: 600;
  display: none;
}
.calc-result.show { display: block; }

/* Download list */
.download-list { list-style: none; }
.download-list li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: var(--content-bg);
  border: 1px solid var(--border);
  border-radius: 5px;
  margin-bottom: 8px;
  transition: border-color 0.12s;
}
.download-list li:hover { border-color: var(--teal-light); }
.download-list .dl-icon { font-size: 20px; flex-shrink: 0; }
.download-list .dl-info { flex: 1; }
.download-list .dl-name { font-size: 13px; font-weight: 500; color: var(--text); }
.download-list .dl-desc { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.download-list a.dl-btn {
  font-size: 11px;
  background: var(--teal);
  color: #fff;
  padding: 4px 12px;
  border-radius: 3px;
  text-decoration: none;
  font-weight: 500;
  flex-shrink: 0;
  transition: background 0.12px;
}
.download-list a.dl-btn:hover { background: var(--teal-dark); }

/* Home page welcome */
.home-welcome {
  background: linear-gradient(135deg, var(--teal-dark) 0%, var(--teal) 100%);
  border-radius: 8px;
  padding: 32px 36px;
  color: #fff;
  margin-bottom: 28px;
  position: relative;
  overflow: hidden;
}
.home-welcome::after {
  content: '';
  position: absolute;
  right: -20px; top: -20px;
  width: 200px; height: 200px;
  border-radius: 50%;
  background: rgba(255,255,255,0.05);
}
.home-welcome h2 { font-size: 22px; font-weight: 600; margin-bottom: 8px; }
.home-welcome p { font-size: 14px; color: rgba(255,255,255,0.8); line-height: 1.6; max-width: 520px; }
.home-welcome .state-badge {
  display: inline-block;
  background: var(--accent);
  color: #3a2e00;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 3px;
  letter-spacing: 0.1em;
  margin-bottom: 12px;
  font-family: 'IBM Plex Mono', monospace;
}

/* QC checklist */
.qc-steps { list-style: none; counter-reset: step; }
.qc-steps li {
  counter-increment: step;
  display: flex;
  gap: 14px;
  align-items: flex-start;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.qc-steps li:last-child { border-bottom: none; }
.qc-steps li::before {
  content: counter(step);
  background: var(--teal);
  color: #fff;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  flex-shrink: 0;
  margin-top: 1px;
  font-family: 'IBM Plex Mono', monospace;
}

/* Drawing Setup inline index */
.ds-index {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin-bottom: 28px;
  padding: 14px 16px;
  background: #f0f4f3;
  border: 1px solid var(--border);
  border-radius: 4px;
}
.ds-index-group { display: flex; flex-direction: column; gap: 4px; min-width: 150px; }
.ds-group-label {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 9px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 2px;
}
.ds-index a {
  font-size: 12.5px;
  color: var(--teal);
  text-decoration: none;
  padding: 2px 0;
}
.ds-index a:hover { color: var(--teal-dark); text-decoration: underline; }
.ds-group-heading {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #fff;
  background: var(--teal-dark);
  padding: 5px 12px;
  border-radius: 3px;
  margin: 32px 0 4px;
}

/* Responsive overlay */
#overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 90;
}
@media (max-width: 768px) {
  #overlay.show { display: block; }
}

/* Placeholder state */
.placeholder-state {
  text-align: center;
  padding: 80px 40px;
  color: var(--text-muted);
}
.placeholder-state .emoji { font-size: 48px; margin-bottom: 16px; }
.placeholder-state h2 { font-size: 20px; color: var(--text); margin-bottom: 8px; }
.placeholder-state p { font-size: 14px; }
