* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: 'Inter', sans-serif; background: #f5f6f8; color: #1a1d23; font-size: 14px; min-height: 100vh; }

header { background: #1a1d23; color: #fff; padding: 0 32px; height: 56px; display: flex; align-items: center; justify-content: space-between; }
.header-title { font-size: 15px; font-weight: 600; }
.header-sub { font-family: 'JetBrains Mono', monospace; font-size: 10px; color: #6b7280; margin-top: 2px; }

.container { max-width: 960px; margin: 0 auto; padding: 32px 24px 64px; }

.card { background: #fff; border: 1px solid #e5e7eb; border-radius: 8px; padding: 24px; margin-bottom: 16px; }
.card-title { font-size: 12px; font-weight: 600; color: #6b7280; text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 16px; }

label { display: block; font-size: 12px; font-weight: 500; color: #6b7280; margin-bottom: 5px; }
input[type="text"], input[type="number"], select {
  width: 100%; padding: 8px 10px; border: 1px solid #d1d5db; border-radius: 6px;
  font-family: inherit; font-size: 14px; color: #1a1d23; background: #fff; outline: none;
  transition: border-color 0.15s, box-shadow 0.15s; -webkit-appearance: none; appearance: none;
}
input:focus, select:focus { border-color: #3b82f6; box-shadow: 0 0 0 3px rgba(59,130,246,0.12); }
select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%236b7280' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center; padding-right: 30px; cursor: pointer;
}
select option { background: #fff; }

.row { display: flex; gap: 12px; }
.row .field { flex: 1; }

.toggle-row { display: flex; gap: 20px; margin-top: 14px; padding-top: 14px; border-top: 1px solid #f3f4f6; }
.toggle-item { display: flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; }
.toggle-item input[type="checkbox"] { display: none; }
.toggle-track { width: 34px; height: 18px; background: #d1d5db; border-radius: 9px; position: relative; transition: background 0.2s; flex-shrink: 0; }
.toggle-track::after { content: ''; position: absolute; left: 3px; top: 3px; width: 12px; height: 12px; border-radius: 50%; background: #fff; transition: transform 0.2s; box-shadow: 0 1px 3px rgba(0,0,0,0.2); }
.toggle-item input:checked + .toggle-track { background: #3b82f6; }
.toggle-item input:checked + .toggle-track::after { transform: translateX(16px); }
.toggle-label { font-size: 13px; font-weight: 500; color: #374151; }

.rack-wrap { min-height: 38px; border: 1px solid #d1d5db; border-radius: 6px; padding: 4px 8px; display: flex; flex-wrap: wrap; align-items: center; gap: 5px; cursor: text; background: #fff; transition: border-color 0.15s, box-shadow 0.15s; }
.rack-wrap.focused { border-color: #3b82f6; box-shadow: 0 0 0 3px rgba(59,130,246,0.12); }
.rack-tag { display: inline-flex; align-items: center; gap: 4px; background: #eff6ff; border: 1px solid #bfdbfe; color: #1d4ed8; font-family: 'JetBrains Mono', monospace; font-size: 11px; padding: 2px 6px 2px 8px; border-radius: 4px; animation: pop 0.15s ease; }
@keyframes pop { from { transform: scale(0.85); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.rack-tag button { background: none; border: none; color: #93c5fd; cursor: pointer; font-size: 14px; line-height: 1; padding: 0 0 0 2px; display: flex; }
.rack-tag button:hover { color: #ef4444; }
.rack-hidden-input { border: none; outline: none; font-family: 'JetBrains Mono', monospace; font-size: 12px; color: #1a1d23; background: transparent; width: 80px; min-width: 40px; }

.post-card { border: 1px solid #e5e7eb; border-radius: 8px; background: #fff; margin-bottom: 10px; overflow: hidden; }
.post-placeholder { border: 2px dashed #93c5fd; border-radius: 8px; background: #eff6ff; margin-bottom: 10px; box-sizing: border-box; }
.post-head { padding: 12px 16px; display: flex; align-items: center; justify-content: space-between; cursor: pointer; background: #f9fafb; border-bottom: 1px solid #e5e7eb; }
.post-head:hover { background: #f3f4f6; }
.post-head-left { display: flex; align-items: center; gap: 10px; }
.drag-handle { cursor: grab; color: #d1d5db; padding: 0 2px; display: flex; align-items: center; user-select: none; flex-shrink: 0; }
.drag-handle:hover { color: #6b7280; }
.drag-handle:active { cursor: grabbing; }
.post-num { font-family: 'JetBrains Mono', monospace; font-size: 11px; font-weight: 500; color: #6b7280; background: #e5e7eb; padding: 2px 8px; border-radius: 4px; }
.post-preview { font-size: 13px; font-weight: 600; color: #374151; }
.post-badges { display: flex; gap: 4px; }
.badge { font-size: 10px; font-weight: 500; padding: 1px 6px; border-radius: 3px; }
.badge-v { background: #fef9ec; color: #92400e; }
.badge-a { background: #eff6ff; color: #1d4ed8; }
.badge-opt { background: #f0fdf4; color: #166534; }
.post-head-right { display: flex; align-items: center; gap: 8px; }
.btn-remove { font-size: 11px; font-weight: 500; color: #9ca3af; background: none; border: 1px solid #e5e7eb; border-radius: 4px; padding: 4px 8px; cursor: pointer; transition: all 0.15s; }
.btn-remove:hover { color: #ef4444; border-color: #fca5a5; background: #fff1f1; }
.chevron { color: #9ca3af; font-size: 11px; transition: transform 0.2s; display: inline-block; }
.post-card.open .chevron { transform: rotate(180deg); }
.post-body { display: none; padding: 16px; }
.post-card.open .post-body { display: block; }

.btn { display: inline-flex; align-items: center; gap: 6px; font-family: inherit; font-size: 13px; font-weight: 500; padding: 8px 16px; border-radius: 6px; border: none; cursor: pointer; transition: all 0.15s; }
.btn-blue { background: #3b82f6; color: #fff; }
.btn-blue:hover { background: #2563eb; }
.btn-ghost { background: transparent; border: 1px solid #e5e7eb; color: #6b7280; }
.btn-ghost:hover { border-color: #d1d5db; background: #f9fafb; color: #374151; }
.btn-generate { background: #1a1d23; color: #fff; width: 100%; justify-content: center; padding: 12px; font-size: 14px; border-radius: 6px; margin-top: 8px; }
.btn-generate:hover { background: #374151; }
.toolbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }

/* Output — document style inspired by CRS Q64DCETH manual */
#output { margin-top: 24px; }

.doc-page {
  background: #fff;
  border: 1px solid #d1d5db;
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  color: #1a1d23;
  line-height: 1.5;
}

.doc-header {
  background: #0D1B2A;
  color: #fff;
  padding: 12px 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.doc-header-title {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.doc-header-ref {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  opacity: 0.8;
}

.doc-body { padding: 32px; }

.doc-title-block {
  border-bottom: 3px solid #00AEEF;
  padding-bottom: 16px;
  margin-bottom: 28px;
}

.doc-title {
  font-size: 22px;
  font-weight: 700;
  color: #1a1d23;
  margin-bottom: 8px;
}

.doc-meta-table {
  border: 2px solid #0D1B2A;
  display: inline-block;
  margin-top: 10px;
}

.doc-meta-table td {
  border: none;
  padding: 5px 16px;
  font-size: 12px;
}

.doc-meta-label { color: #fff; background: #0D1B2A; text-align: right; border-right: 1px solid #1a2d40 !important; font-weight:500; padding: 5px 14px; }
.doc-meta-value { color: #1a1d23; font-weight: 500; padding: 5px 14px; }

/* Sections */
.doc-section { margin-bottom: 28px; overflow: hidden; }

.doc-section-title {
  font-size: 13px;
  font-weight: 700;
  color: #fff;
  background: #0D1B2A;
  padding: 7px 14px;
  margin-bottom: 0;
  letter-spacing: 0.03em;
  border-left: 4px solid #00AEEF;
}

.doc-section-sub {
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  background: #2d4a72;
  padding: 5px 14px;
  margin: 16px 0 0;
  border-left: 3px solid #00AEEF;
}

/* Tables */
.doc-table {
  width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
  font-size: 12px;
  margin-bottom: 0;
  border: 2px solid #0D1B2A;
}

.doc-table th {
  background: #0D1B2A;
  color: #fff;
  padding: 6px 12px;
  text-align: left;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  white-space: nowrap;
  border: 1px solid #1a2d40;
}

.doc-table td {
  border-bottom: 1px solid #e5e7eb;
  border-right: 1px solid #e5e7eb;
  padding: 5px 12px;
  vertical-align: middle;
  color: #1a1d23;
  word-break: break-word;
  overflow-wrap: break-word;
}

.doc-table tr:nth-child(even) td { background: #f8fafc; }
.doc-table tr:hover td { background: #eef4fb; }

/* Keep semantic row colors on doc-table */
/* Row colors synced exactly to matching bit table bg */
.doc-table tr.td-cmd    { border-left: 4px solid #1e4d8c; }
.doc-table tr.td-cmd td    { background: #e8f0fb !important; color: #1a1d23 !important; }

.doc-table tr.td-status { border-left: 4px solid #4a606e; }
.doc-table tr.td-status td { background: #f0f4f6 !important; color: #1a1d23 !important; }

.doc-table tr.td-smart  { border-left: 4px solid #c07c1a; }
.doc-table tr.td-smart td  { background: #fef9ec !important; color: #1a1d23 !important; }

.doc-table tr.td-fault  { border-left: 4px solid #c8273a; }
.doc-table tr.td-fault td  { background: #fff0f0 !important; color: #1a1d23 !important; }

.doc-table tr.td-warn   { border-left: 4px solid #c4621a; }
.doc-table tr.td-warn td   { background: #fff4ec !important; color: #1a1d23 !important; }

.doc-table tr.td-volt   { border-left: 4px solid #c07c1a; }
.doc-table tr.td-volt td   { background: #fef9ec !important; color: #1a1d23 !important; }

.doc-table tr.td-curr   { border-left: 4px solid #2563a8; }
.doc-table tr.td-curr td   { background: #eff6ff !important; color: #1a1d23 !important; }

.doc-table tr.td-ve     { border-left: 4px solid #0e9e6e; }
.doc-table tr.td-ve td     { background: #ecfdf5 !important; color: #1a1d23 !important; }

.doc-table tr.td-voie   { border-left: 4px solid #7c4fc4; }
.doc-table tr.td-voie td   { background: #f3f0fd !important; color: #1a1d23 !important; }
.doc-table tr td.td-group  { color: #0D1B2A !important; font-weight: 700; background: #f0f4f8 !important; font-family:'JetBrains Mono',monospace; font-size:11px; border-left: 4px solid #0D1B2A !important; }
.doc-table tr td.td-gray   { color: #1a1d23 !important; }
.doc-table td.c-volt  { background: #fef9ec; color: #1a1d23; }
.doc-table td.c-curr  { background: #eff6ff; color: #1a1d23; }
.doc-table td.c-voie  { background: #f3f0fd; color: #1a1d23; }
.doc-table tr:nth-child(even) td.td-group { background: #f9fafb !important; }

/* Separator row */
.doc-table tr.sep td { padding: 0; height: 3px; background: #0D1B2A33 !important; border: none; }

/* Bit sub-tables */
.bit-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}

.bit-grid-4 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 1fr;
  gap: 16px;
}

.bit-block-title {
  font-size: 11px;
  font-weight: 700;
  padding: 4px 10px;
  color: #fff;
  margin-bottom: 0;
}

/* Note box */
.doc-note {
  margin-top: 16px;
  padding: 10px 14px;
  background: #fffbeb;
  border-left: 4px solid #f59e0b;
  font-size: 11px;
  color: #92400e;
}

/* Footer */
.doc-footer {
  border-top: 1px solid #d1d5db;
  padding: 8px 32px;
  display: flex;
  justify-content: space-between;
  font-family: 'JetBrains Mono', monospace;
  font-size: 9px;
  color: #9ca3af;
  background: #f9fafb;
}

.btn-print { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 500; color: #6b7280; background: #f9fafb; border: 1px solid #e5e7eb; border-radius: 6px; padding: 6px 12px; cursor: pointer; margin-bottom: 16px; transition: all 0.15s; }
.btn-print:hover { background: #f3f4f6; color: #374151; }

.btn-export { background: #0D1B2A; color: #fff; font-family: inherit; font-size: 13px; font-weight: 600; padding: 10px 20px; border-radius: 6px; border: none; cursor: pointer; display: inline-flex; align-items: center; gap: 8px; transition: background 0.15s; }
.btn-export:hover { background: #1a2d40; }

.mono { font-family: 'JetBrains Mono', monospace; font-size: 11px; }

/* Print header/footer — hidden on screen */
.print-header, .print-footer { display: none; }

@media print {
  /* Hide UI elements */
  header, .config-section, .btn-generate, .btn-print, #exportBar { display: none !important; }

  /* Reset layout */
  * { -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; }
  html, body { background: #fff !important; margin: 0; padding: 0; }
  .container { padding: 0; max-width: 100%; margin: 0; }
  #output { margin-top: 0; display: block !important; }
  .doc-page { border: none; box-shadow: none; overflow: visible; padding-top: 0; }
  .doc-body { padding: 0 !important; }
  thead { display: table-header-group; }
  .doc-section { overflow: hidden; max-width: 100%; }

  /* Preserve all background colors and text colors exactly */
  .doc-header-title { color: #fff !important; }
  .doc-header-ref { color: rgba(255,255,255,0.8) !important; }
  .doc-section-title { background: #0D1B2A !important; color: #fff !important; border-left: 4px solid #00AEEF !important; }
  .doc-section-sub { background: #2d4a72 !important; color: #fff !important; border-left: 3px solid #00AEEF !important; }
  .doc-title-block { border-bottom: 3px solid #00AEEF !important; }
  .doc-meta-label { background: #0D1B2A !important; color: #fff !important; }
  .doc-footer { background: #f9fafb !important; border-top: 1px solid #d1d5db !important; }

  /* Tables */
  .doc-table th { background: #0D1B2A !important; color: #fff !important; }
  .doc-table tr:nth-child(even) td { background: #f8fafc !important; }
  .doc-table tr.td-cmd td    { background: #e8f0fb !important; }
  .doc-table tr.td-status td { background: #f0f4f6 !important; }
  .doc-table tr.td-smart td  { background: #fef9ec !important; }
  .doc-table tr.td-fault td  { background: #fff0f0 !important; }
  .doc-table tr.td-warn td   { background: #fff4ec !important; }
  .doc-table tr.td-volt td   { background: #fef9ec !important; }
  .doc-table tr.td-curr td   { background: #eff6ff !important; }
  .doc-table tr.td-ve td     { background: #ecfdf5 !important; }
  .doc-table tr.td-voie td   { background: #f3f0fd !important; }
  .doc-table tr td.td-group  { background: #f0f4f8 !important; }
  .doc-table tr.sep td       { background: rgba(13,27,42,0.2) !important; }

  /* Bit tables inline styles also need color-adjust (handled globally above) */

  /* Page breaks — sections et tableaux */
  .doc-section { page-break-inside: auto; }
  .doc-section-title { page-break-after: avoid; }
  .doc-section-sub { page-break-after: avoid; }
  .doc-title-block { page-break-after: avoid; }
  .doc-note { page-break-inside: avoid; }

  /* Empêcher la coupure des lignes de tableaux entre deux pages */
  .doc-table tr { page-break-inside: avoid; }
  .doc-table thead { display: table-header-group; } /* répéter l'en-tête sur chaque page */
  .doc-table { page-break-inside: auto; border-collapse: collapse; }

  /* Empêcher la coupure des petits tableaux de bits */
  .bit-block { page-break-inside: avoid; }
  .bit-grid, .bit-grid-4 { page-break-inside: avoid; }

  /* Hide in-document footer (replaced by fixed print footer) */
  .doc-footer { display: none !important; }

  @page {
    margin: 6mm;
    size: A4 portrait;
  }
}

/* Form-only classes */
.chip { display: inline-block; padding: 1px 6px; border-radius: 3px; font-size: 10px; font-weight: 500; margin-right: 3px; }
.chip-on { background: #f0fdf4; color: #15803d; }
.chip-off { background: #f3f4f6; color: #9ca3af; }
.proto-btn { background: #f9fafb; color: #6b7280; font-family: inherit; }
.proto-btn.active { background: #1a1d23; color: #fff; }
.proto-btn:hover:not(.active) { background: #f3f4f6; color: #374151; }