/* =========================================================================
   ADuMa ESP Flasher — đồng bộ nhận diện theo rp2350 (giao diện chính).
   Token màu/font/bo góc + nút/ô nhập/.dot lấy từ /shared/css/base.css (tông
   xanh dương, tự động light/dark). File này chỉ còn phần BỐ CỤC riêng của
   trang esp (masthead, thẻ bước có số rail, flashmap, actionbar dính đáy,
   accordion, console, bài viết .doc) — restyle theo token chung.
   ========================================================================= */

:root {
  /* biến phụ suy ra từ token base để giữ light/dark tự động */
  --surface-2: color-mix(in srgb, var(--panel) 86%, var(--text) 7%);
  --line-soft: color-mix(in srgb, var(--border) 55%, transparent);
  --step-rail: 46px;
}

html { -webkit-text-size-adjust: 100%; }

body {
  padding: 0 0 96px;
  font-size: 15px;
  line-height: 1.6;
}

.wrap { max-width: 780px; margin: 0 auto; padding: 0 16px; }

/* ---------------- Header ---------------- */

.masthead {
  padding: 30px 0 22px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 26px;
}

.masthead-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 10px;
}
.brand b { color: var(--accent); font-weight: 600; }

#langSelect {
  flex-shrink: 0;
  width: auto;          /* ghi đè select{width:100%} bên dưới — không kéo rộng */
  min-width: 120px;
  font-size: 13px;
}

h1 {
  font-size: clamp(26px, 5.5vw, 38px);
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.12;
  margin: 0 0 10px;
}

.tagline { color: var(--muted); margin: 0 0 16px; max-width: 56ch; }

.chip-row { display: flex; flex-wrap: wrap; gap: 6px; }
.chip-tag {
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 3px 8px;
  border: 1px solid var(--border);
  border-radius: 100px;
  color: var(--muted);
}

/* ---------------- Thẻ bước ---------------- */

.step {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 18px 18px calc(var(--step-rail) + 8px);
  margin-bottom: 14px;
}
.step::before {
  content: attr(data-step);
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: var(--step-rail);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 19px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--muted);
  border-right: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: var(--radius) 0 0 var(--radius);
}
.step.done::before { color: var(--ok); }
.step h2 {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.01em;
  margin: 0 0 4px;
}
.step .hint { color: var(--muted); font-size: 13px; margin: 0 0 12px; }

/* ---------------- Điều khiển ---------------- */

label.field { display: block; margin-bottom: 12px; }
label.field > span {
  display: block;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 5px;
}

/* ô nhập/select kế thừa base.css; esp cần rộng full + cỡ chữ mono */
select, input[type='text'], input[type='number'] {
  width: 100%;
  font-family: var(--font-mono);
  font-size: 14px;
  padding: 9px 11px;
}
select:hover, input:hover { border-color: var(--accent); }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 520px) { .grid2 { grid-template-columns: 1fr; } }

/* nút mặc định của esp = trung tính (base.css đã lo). Chỉ thêm nền nhẹ khi hover. */
button:hover:not(:disabled) { background: var(--surface-2); }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---------------- Trạng thái kết nối ---------------- */

.conn-state {
  display: flex;
  align-items: center;
  gap: 9px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--muted);
  padding: 9px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 12px;
}
.conn-state.live .dot { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 18%, transparent); }
.conn-state.busy .dot { background: var(--warn); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: 0.3; } }

.dev-table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-mono);
  font-size: 12.5px;
}
.dev-table th {
  text-align: left;
  font-weight: 400;
  color: var(--muted);
  padding: 5px 0;
  width: 42%;
}
.dev-table td { padding: 5px 0; color: var(--text); }

/* ---------------- Bản đồ vùng flash ---------------- */

.flashmap {
  margin: 14px 0 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  padding: 12px;
}
.flashmap-head {
  display: flex;
  justify-content: space-between;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 8px;
}
.flashmap-track {
  position: relative;
  height: 38px;
  background:
    repeating-linear-gradient(90deg, var(--border) 0 1px, transparent 1px 40px),
    var(--surface-2);
  border-radius: 3px;
  overflow: hidden;
}
.seg {
  position: absolute;
  top: 0; bottom: 0;
  background: color-mix(in srgb, var(--accent) 55%, var(--bg));
  border-right: 1px solid var(--bg);
  overflow: hidden;
}
.seg .seg-fill {
  position: absolute;
  inset: 0 100% 0 0;
  background: var(--accent);
  transition: right 0.2s linear;
}
.seg.overlap { background: var(--err); }
.seg .seg-label {
  position: absolute;
  left: 5px; top: 50%;
  transform: translateY(-50%);
  font-family: var(--font-mono);
  font-size: 10px;
  color: #fff;
  white-space: nowrap;
  pointer-events: none;
}
.flashmap-scale {
  display: flex;
  justify-content: space-between;
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--muted);
  margin-top: 5px;
}

/* ---------------- Bảng file ---------------- */

.file-rows { display: flex; flex-direction: column; gap: 8px; }
.file-row {
  display: grid;
  grid-template-columns: 108px 1fr auto;
  gap: 8px;
  align-items: center;
}
.file-row .pick {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg);
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 11px;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
  min-width: 0;
}
.file-row .pick.filled { border-style: solid; border-color: var(--accent); color: var(--text); }
.file-row .pick .fname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-row .pick .fsize { margin-left: auto; font-family: var(--font-mono); font-size: 11px; color: var(--muted); flex: none; }
.file-row input[type='file'] { display: none; }
@media (max-width: 520px) {
  .file-row { grid-template-columns: 96px 1fr; }
  .file-row button { grid-column: 2; justify-self: start; }
}
.dropzone.dragging { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, transparent); }

/* ---------------- Thanh hành động dính đáy ---------------- */

.actionbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--border);
  padding: 11px 0;
  z-index: 40;
}
.actionbar .wrap { display: flex; align-items: center; gap: 12px; }
.actionbar .status {
  flex: 1;
  min-width: 0;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.actionbar button.primary { padding: 11px 22px; flex: none; }
.progress-thin {
  position: absolute;
  top: -1px; left: 0;
  height: 2px;
  background: var(--accent);
  width: 0;
  transition: width 0.2s linear;
}

/* ---------------- Accordion ---------------- */

details.panel {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  margin-bottom: 14px;
  overflow: hidden;
}
details.panel > summary {
  cursor: pointer;
  padding: 14px 18px;
  font-size: 14px;
  font-weight: 600;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
}
details.panel > summary::-webkit-details-marker { display: none; }
details.panel > summary::after {
  content: '+';
  margin-left: auto;
  color: var(--muted);
  font-family: var(--font-mono);
}
details.panel[open] > summary::after { content: '−'; }
details.panel > .panel-body { padding: 0 18px 18px; border-top: 1px solid var(--border); padding-top: 16px; }

/* ---------------- Console ---------------- */

.console {
  background: #05060a;
  color: #b7f5c8;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.55;
  padding: 11px;
  height: 240px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-word;
}
.console .l-warn { color: var(--warn); }
.console .l-error { color: var(--err); }
.console .l-ok { color: var(--ok); }
.console .l-dim { color: var(--muted); }

/* ---------------- Nội dung hướng dẫn / SEO ---------------- */

.doc { margin-top: 34px; }
.doc h2 {
  font-size: 21px;
  margin: 30px 0 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.doc h3 { font-size: 16px; margin: 20px 0 6px; }
.doc p, .doc li { color: var(--text); }
.doc ul, .doc ol { padding-left: 20px; }
.doc code {
  background: var(--surface-2);
  padding: 1px 5px;
  border-radius: 3px;
  color: var(--accent);
}
.doc table { width: 100%; border-collapse: collapse; font-size: 13.5px; margin: 12px 0; }
.doc th, .doc td { text-align: left; padding: 7px 9px; border-bottom: 1px solid var(--border); }
.doc th { color: var(--muted); font-weight: 500; font-family: var(--font-mono); font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; }
.doc td code { white-space: nowrap; }

.callout {
  border-left: 2px solid var(--warn);
  background: color-mix(in srgb, var(--warn) 8%, transparent);
  padding: 11px 14px;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  margin: 14px 0;
  font-size: 14px;
}
.callout.bad { border-color: var(--err); background: color-mix(in srgb, var(--err) 8%, transparent); }

footer {
  margin-top: 44px;
  padding: 22px 0 30px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 13px;
}

.unsupported {
  display: none;
  border: 1px solid var(--err);
  background: color-mix(in srgb, var(--err) 10%, transparent);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 16px;
}
.unsupported.show { display: block; }
