/* ============================================================
   Kalkulator BMS — Style (LUVAQ Brand)
   Kolory: Dunkelgrau #373A3B | Türkis #38B6AC | Weiß #FFFFFF
   Font: Saira (Google Fonts)
   ============================================================ */

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

body {
  font-family: 'Saira', 'Segoe UI', Arial, sans-serif;
  font-size: 14px;
  background: #f0f2f3;
  color: #1a1a1a;
}

/* ---- Header ---- */
header {
  background: #373A3B;
  border-bottom: 3px solid #38B6AC;
  padding: 12px 24px 10px 24px;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 64px;
}

.header-logo-area {
  display: flex;
  align-items: center;
}

.luvaq-logo {
  height: 42px;
  width: auto;
}

.header-title {
  border-left: 1px solid rgba(255,255,255,0.25);
  padding-left: 16px;
  margin-left: 16px;
}

.header-title h1 {
  font-size: 14px;
  font-weight: 400;
  color: #ffffff;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

/* ---- Przełącznik języka ---- */
.lang-switcher {
  position: absolute;
  bottom: 10px;
  right: 24px;
  display: flex;
  border: 1px solid rgba(255,255,255,0.35);
  overflow: hidden;
}

.lang-btn {
  background: transparent;
  color: #ffffff;
  border: none;
  border-right: 1px solid rgba(255,255,255,0.35);
  padding: 4px 14px;
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  line-height: 1.6;
  letter-spacing: 0.04em;
  transition: background 0.15s;
}

.lang-btn:last-child { border-right: none; }

.lang-btn:hover { background: rgba(56,182,172,0.25); }

.lang-btn.active {
  background: #38B6AC;
  color: #ffffff;
}

/* ---- Main layout ---- */
main {
  max-width: 1100px;
  margin: 24px auto;
  padding: 0 16px;
}

/* ---- Sekcja formularza ---- */
.form-section {
  background: #ffffff;
  border-top: 3px solid #38B6AC;
  padding: 20px 24px 24px 24px;
  margin-bottom: 24px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}

.form-row {
  display: flex;
  gap: 24px;
  flex-wrap: wrap;
  align-items: flex-end;
  margin-bottom: 20px;
}

.field-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.field-group label {
  font-size: 12px;
  font-weight: 500;
  color: #666;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

select, input[type="number"] {
  border: 1px solid #d0d4d6;
  padding: 7px 10px;
  font-size: 13px;
  font-family: inherit;
  background: #fff;
  color: #1a1a1a;
  min-width: 160px;
  outline: none;
  appearance: none;
  -webkit-appearance: none;
  transition: border-color 0.15s;
}

select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23373A3B' 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;
}

select:focus, input[type="number"]:focus {
  border-color: #38B6AC;
  box-shadow: 0 0 0 2px rgba(56,182,172,0.15);
}

/* ---- Radio group (Single/Group) ---- */
.radio-group {
  display: flex;
  gap: 16px;
  padding: 7px 0;
}

.radio-group label {
  font-size: 13px;
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  color: #1a1a1a;
  display: flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
}

.radio-group input[type="radio"] {
  accent-color: #38B6AC;
}

/* Dymek pomocy dla przycisków Single / Group */
.radio-group label.mode-tip {
  position: relative;
}
.radio-group label.mode-tip::before {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 10px);
  left: 50%;
  transform: translateX(-50%);
  background: #373A3B;
  color: #fff;
  font-size: 12px;
  line-height: 1.45;
  padding: 8px 12px;
  width: 210px;
  text-align: center;
  pointer-events: none;
  white-space: normal;
  opacity: 0;
  transition: opacity 0.18s ease;
  z-index: 20;
}
.radio-group label.mode-tip::after {
  content: '';
  position: absolute;
  bottom: calc(100% + 4px);
  left: 50%;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: #373A3B;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.18s ease;
  z-index: 20;
}
.radio-group label.mode-tip:hover::before,
.radio-group label.mode-tip:hover::after {
  opacity: 1;
}

/* ---- Sekcja urządzeń w formularzu ---- */
.devices-header {
  font-size: 12px;
  font-weight: 500;
  text-transform: uppercase;
  color: #666;
  letter-spacing: 0.06em;
  margin-bottom: 8px;
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid #e0e3e5;
}

.device-row {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.device-row select {
  min-width: 160px;
  width: auto;
}

.device-row input[type="number"] { width: 70px; min-width: unset; }

.device-row label {
  font-size: 12px;
  color: #666;
  white-space: nowrap;
}

.zone-field input[type="number"] {
  width: 70px;
  min-width: unset;
}

.btn-remove {
  background: transparent;
  border: 1px solid #ccc;
  color: #888;
  padding: 7px 10px;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  font-family: inherit;
  transition: border-color 0.15s, color 0.15s;
}
.btn-remove:hover { border-color: #c0392b; color: #c0392b; }

/* ---- Przyciski ---- */
.form-actions {
  display: flex;
  gap: 12px;
  margin-top: 16px;
  flex-wrap: wrap;
  align-items: center;
}

button {
  padding: 8px 18px;
  border: 1px solid #d0d4d6;
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
  background: #f0f2f3;
  color: #373A3B;
  white-space: nowrap;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}
button:hover { border-color: #38B6AC; color: #38B6AC; }

.btn-primary {
  background: #38B6AC;
  color: #ffffff;
  border: none;
  font-weight: 600;
  letter-spacing: 0.04em;
}
.btn-primary:hover { background: #2ea49a; color: #fff; }

.btn-secondary {
  background: transparent;
  color: #373A3B;
  border: 1px solid #c0c4c6;
  font-weight: 500;
}
.btn-secondary:hover { border-color: #38B6AC; color: #38B6AC; background: transparent; }

/* ---- Komunikat błędu formularza ---- */
.form-error {
  margin-top: 12px;
  padding: 8px 12px;
  background: #fdf2f1;
  border: 1px solid #e8b0a8;
  color: #c0392b;
  font-size: 13px;
}

/* ---- Nagłówek wyników ---- */
.results-header {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px;
  align-items: center;
  margin-bottom: 16px;
}
.results-header h2 {
  font-size: 16px;
  font-weight: 600;
  color: #373A3B;
  text-align: center;
  letter-spacing: 0.02em;
}
.results-actions-right {
  display: flex;
  gap: 6px;
}

/* ---- Blok wyniku urządzenia / sterownika / strefy ---- */
.result-block {
  background: #ffffff;
  border: 1px solid #e0e3e5;
  border-left: 4px solid #38B6AC;
  margin-bottom: 16px;
  overflow: hidden;
}

.result-block-header {
  background: #f7f9fa;
  color: #373A3B;
  padding: 10px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid #e0e3e5;
}
.result-block-header h3 { font-size: 13px; font-weight: 600; color: #373A3B; }
.result-block-header .badge {
  font-size: 10px;
  background: #38B6AC;
  color: #ffffff;
  padding: 3px 10px;
  font-weight: 500;
  letter-spacing: 0.03em;
}

/* ---- Sekcja rejestrów (IR / HR) ---- */
.reg-section { padding: 12px 16px 0; }

.reg-section-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #666;
  margin-bottom: 6px;
  padding-bottom: 4px;
  border-bottom: 1px solid #e0e3e5;
  display: flex;
  align-items: center;
  gap: 8px;
}

.reg-section-title::before {
  content: '';
  display: inline-block;
  width: 3px;
  height: 12px;
  background: #38B6AC;
  flex-shrink: 0;
}

/* ---- Tabela rejestrów ---- */
.reg-table, table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 16px;
  font-size: 12px;
  table-layout: fixed;
}

.reg-table th:nth-child(1),
.reg-table td:nth-child(1) { width: 38px; }

.reg-table th:nth-child(2),
.reg-table td:nth-child(2) { width: 120px; }

.reg-table th:nth-child(3),
.reg-table td:nth-child(3) { width: 100px; }

thead th {
  background: #38B6AC;
  color: #ffffff;
  text-align: left;
  padding: 6px 10px;
  font-weight: 500;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
  overflow: hidden;
}

thead th:first-child { width: 36px; text-align: center; }

tbody td {
  padding: 5px 10px;
  border-bottom: 1px solid #eceef0;
  color: #1a1a1a;
  vertical-align: top;
  overflow: hidden;
  text-overflow: ellipsis;
}

tbody td:first-child:not(.reg-detail-cell) { text-align: center; color: #999; font-size: 11px; }

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: #f0faf9; }

.addr-hex { font-family: 'Consolas', monospace; color: #38B6AC; font-weight: 600; }
.addr-dec { font-family: 'Consolas', monospace; color: #666; }
.reg-name { font-weight: 600; color: #373A3B; }

/* ---- Wyświetlanie wartości (values enum) ---- */
.values-list { display: flex; flex-direction: column; gap: 1px; }
.val-item { color: #445; }
.val-item b { color: #373A3B; margin-right: 3px; }
.range-info { color: #556; }
.val-desc { color: #888; font-style: italic; font-size: 11px; margin-top: 2px; }

/* ---- Znaczniki trybu (Single / Group) ---- */
.mode-tag {
  display: inline-block;
  font-size: 10px;
  padding: 1px 6px;
  font-weight: 600;
  margin-left: 6px;
}
.mode-single { background: rgba(56,182,172,0.15); color: #1f6e66; }
.mode-group  { background: rgba(55,58,59,0.10);   color: #373A3B; }

/* ---- Stan pusty ---- */
.empty-note {
  padding: 12px 16px;
  color: #999;
  font-style: italic;
  font-size: 12px;
}

.loading {
  text-align: center;
  padding: 40px;
  color: #666;
}

/* ---- Sekcja rejestrów strefy (T-box Zone) ---- */
.zone-block {
  border-left: 4px solid #38B6AC;
}
.zone-block-header {
  background: #e3f5f3;
}
.zone-block .result-block-header .badge {
  background: #38B6AC;
  color: #ffffff;
}
.zone-block .reg-section-title::before {
  background: #38B6AC;
}

/* ---- Blok Holding Registers Group (T-box Group mode) ---- */
.group-hr-block {
  border-left: 4px solid #373A3B;
}
.group-hr-header {
  background: #ececec;
}
.group-hr-block .result-block-header .badge {
  background: #373A3B;
  color: #ffffff;
}
.group-hr-block .reg-section-title::before {
  background: #373A3B;
}

/* ---- Rozwijane wiersze rejestrów (z opisem wartości) ---- */
.reg-row-expandable {
  cursor: pointer;
  user-select: none;
}
.reg-row-expandable:hover td {
  background: #f0faf9;
}
.reg-row-open td {
  background: rgba(56,182,172,0.12);
}

.reg-table td:last-child {
  overflow: visible;
}
.reg-row-expandable .reg-name {
  position: relative;
}
.reg-row-expandable:not(.reg-row-open) .reg-name::after {
  content: 'Kliknij aby rozwinąć';
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  background: #373A3B;
  color: #fff;
  font-size: 11px;
  font-weight: normal;
  padding: 3px 8px;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 50;
}
.reg-row-expandable:not(.reg-row-open):hover .reg-name::after {
  opacity: 1;
}

.expand-icon {
  display: inline-block;
  font-size: 9px;
  color: #666;
  margin-right: 6px;
  line-height: 1;
}
.expand-spacer {
  display: inline-block;
  width: 15px;
}

.reg-detail-row {
  display: none;
}
.reg-detail-row.reg-detail-open {
  display: table-row;
}
.reg-detail-cell {
  padding: 8px 16px 12px 36px;
  background: #f0faf9;
  border-bottom: 1px solid #d5ede9;
  border-left: 3px solid #38B6AC;
}

/* ============================================================
   PRINT / PDF
   ============================================================ */
@media print {

  header .lang-switcher,
  .form-section,
  #btn-reset,
  #btn-print,
  #btn-export-xlsx {
    display: none !important;
  }

  #results {
    display: block !important;
  }

  .reg-detail-row {
    display: table-row !important;
  }

  .expand-icon {
    display: none !important;
  }

  @page {
    margin: 1.5cm 1.5cm 2cm 1.5cm;
  }

  .result-block {
    page-break-inside: avoid;
    break-inside: avoid;
  }

  tr {
    page-break-inside: avoid;
    break-inside: avoid;
  }

  * {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  header { background: #373A3B !important; }
  thead th { background: #38B6AC !important; }
}

/* ============================================================
   Karta samouczka — pod dropdownem sterownika
   ============================================================ */

.tutorial-card {
  background: #f7f9fa;
  border-left: 3px solid #38B6AC;
  margin-top: 16px;
  padding: 12px 16px;
}

.tutorial-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  user-select: none;
}

.tutorial-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #373A3B;
}

.tut-icon {
  width: 16px;
  height: 16px;
  stroke: #38B6AC;
  stroke-width: 2;
  fill: none;
  flex-shrink: 0;
}

.tut-label-text {
  font-size: 12px;
  font-weight: 600;
  color: #373A3B;
}

.tut-ctrl-badge {
  background: rgba(56,182,172,0.15);
  border: 1px solid #38B6AC;
  color: #1f6e66;
  font-size: 11px;
  padding: 2px 10px;
  font-weight: 600;
}

.tutorial-toggle {
  font-size: 11px;
  color: #38B6AC;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 4px;
}

.tut-chevron { display: inline-block; transition: transform 0.2s; }
.tut-chevron.open { transform: rotate(180deg); }

.tutorial-body { margin-top: 10px; }
.tutorial-body p { font-size: 13px; color: #444; line-height: 1.5; margin-bottom: 6px; }
.tutorial-body strong { color: #373A3B; }

.tut-body-top {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 6px;
}

.tut-desc {
  font-size: 13px;
  line-height: 1.65;
  flex: 1;
}

.tut-diagram-wrap { width: 200px; }

.tut-section-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  color: #666;
  letter-spacing: 0.06em;
  margin-bottom: 6px;
  border-left: 3px solid #38B6AC;
  padding-left: 7px;
}

.tut-params-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 3px 16px;
  font-size: 12px;
  margin-bottom: 14px;
}

.tut-param-label { color: #666; font-weight: 600; white-space: nowrap; }
.tut-param-val   { color: #1a1a1a; }

.tut-modes-list { display: flex; flex-direction: column; gap: 6px; }

.tut-mode-item {
  font-size: 12px;
  line-height: 1.55;
  padding-left: 12px;
  position: relative;
}

.tut-mode-item::before {
  content: '';
  position: absolute;
  left: 0;
  top: 7px;
  width: 5px;
  height: 5px;
  background: #38B6AC;
}

.tut-mode-name { font-weight: 600; color: #373A3B; }

/* ---- Responsive ---- */
@media (max-width: 600px) {
  main { margin: 12px auto; }
  header { padding: 10px 14px 10px 14px; min-height: 56px; }
  .luvaq-logo { height: 34px; }
  .lang-switcher { right: 14px; bottom: 8px; }
  .form-section { padding: 14px 14px 18px 14px; }
  .form-row { flex-direction: column; gap: 12px; }
  table { font-size: 11px; }
  thead th, tbody td { padding: 6px 8px; }
}
