:root {
  --bg: #ffffff;
  --fg: #111111;
  --muted: #666;
  --line: #e8e8e8;
  --accent: #e8212a;
  --accent-hover: #c41920;
  --accent-invert: #fff;
  --ok: #0a7f42;
  --warn: #a76400;
  --err: #b00020;
  --step-pill: #fff0f0;
  --step-text: #e8212a;
  --panel-bg: #fafafa;
  --topbar-bg: #fff;
  --body-bg: #f2f2f2;
  --container-bg: #fff;
  --icon-btn-hover: #f0f0f0;
  --dropdown-bg: #fff;
  --dropdown-shadow: 0 4px 20px rgba(0,0,0,0.12);
  --dropdown-border: #e8e8e8;
}

[data-theme="dark"] {
  --bg: #1e1e1e;
  --fg: #e8e8e8;
  --muted: #999;
  --line: #333;
  --accent: #ff4d55;
  --accent-hover: #e83a42;
  --accent-invert: #fff;
  --ok: #34c97a;
  --warn: #f0a030;
  --err: #ff6b6b;
  --step-pill: #3a1515;
  --step-text: #ff6b6b;
  --panel-bg: #252525;
  --topbar-bg: #1a1a1a;
  --body-bg: #141414;
  --container-bg: #1e1e1e;
  --icon-btn-hover: #2a2a2a;
  --dropdown-bg: #252525;
  --dropdown-shadow: 0 4px 24px rgba(0,0,0,0.45);
  --dropdown-border: #333;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  background: var(--body-bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Topbar ── */
.topbar {
  background: var(--topbar-bg);
  border-bottom: 1px solid var(--line);
  border-radius: 12px 12px 0 0;
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}
.brand a {
  font-size: 20px;
  font-weight: 700;
  color: var(--fg);
  letter-spacing: -0.3px;
}
.brand .brand-sep { color: var(--line); }
.brand .brand-sub {
  font-size: 13px;
  color: var(--muted);
  font-weight: 400;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* ── Icon buttons (theme toggle, lang) ── */
.icon-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: none !important;
  border: none !important;
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
  font-weight: 600;
  color: var(--muted) !important;
  padding: 6px 8px;
  border-radius: 7px;
  transition: color 0.15s, background 0.15s;
  line-height: 1;
}
.icon-btn:hover { color: var(--fg) !important; background: var(--icon-btn-hover) !important; }
.icon-btn svg { flex-shrink: 0; }

/* Theme toggle — show sun in dark mode, moon in light */
.theme-toggle .icon-moon { display: none; }
[data-theme="dark"] .theme-toggle .icon-sun { display: none; }
[data-theme="dark"] .theme-toggle .icon-moon { display: block; }

/* Lang dropdown */
.lang-dropdown {
  position: relative;
}
.dropdown-arrow {
  transition: transform 0.2s;
}
.lang-dropdown.open .dropdown-arrow {
  transform: rotate(180deg);
}
.dropdown-menu {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 160px;
  background: var(--dropdown-bg);
  border: 1px solid var(--dropdown-border);
  border-radius: 10px;
  box-shadow: var(--dropdown-shadow);
  padding: 6px;
  z-index: 200;
  animation: dropIn 0.15s ease;
}
.dropdown-menu.open { display: block; }

@keyframes dropIn {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.dropdown-item {
  display: flex !important;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 10px !important;
  border-radius: 7px;
  background: none !important;
  border: none !important;
  cursor: pointer;
  text-align: left;
  font-size: 13px;
  color: var(--fg) !important;
  transition: background 0.13s;
}
.dropdown-item:hover { background: var(--icon-btn-hover) !important; }
.lang-flag { font-size: 18px; line-height: 1; flex-shrink: 0; }
.lang-info { flex: 1; display: flex; flex-direction: column; gap: 1px; }
.lang-name { font-weight: 600; font-size: 13px; }
.lang-code { font-size: 11px; color: var(--muted); }
.lang-check { font-size: 13px; color: var(--accent); font-weight: 700; }


.shop-link {
  font-size: 13px;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 4px 10px;
  transition: border-color 0.15s, color 0.15s;
}
.shop-link:hover { border-color: var(--accent); color: var(--accent); text-decoration: none; }

/* ── Hero ── */
.hero {
  background: var(--topbar-bg);
  border-bottom: 1px solid var(--line);
  padding: 28px 24px 20px;
}
.hero h1 {
  font-size: 22px;
  font-weight: 700;
  margin: 0 0 6px;
  color: var(--fg);
}
.hero .intro {
  color: var(--muted);
  font-size: 13px;
  margin: 0;
  max-width: 600px;
  line-height: 1.5;
}

/* ── Container ── */
.container {
  max-width: 900px;
  margin: 24px auto;
  background: var(--container-bg);
  border-radius: 12px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.08);
  overflow: hidden;
}

.content {
  padding: 20px 24px;
}

/* ── Browser compat warning ── */
.browser-warn {
  background: #fff8e1;
  border: 1px solid #f0c040;
  border-radius: 6px;
  padding: 10px 14px;
  font-size: 13px;
  color: #6b4800;
  margin-bottom: 16px;
  line-height: 1.5;
}

/* ── Browser support note ── */
.browser-note {
  background: #f0f7ff;
  border: 1px solid #c8dff8;
  border-radius: 6px;
  padding: 9px 14px;
  font-size: 13px;
  color: #2255aa;
  margin-bottom: 16px;
  line-height: 1.5;
}

/* ── Firmware release notes (shown on flasher when firmware is selected) ── */
.firmware-notes {
  display: flex;
  align-items: baseline;
  gap: 10px;
  background: #fff8e1;
  border: 1px solid #ffe082;
  border-radius: 6px;
  padding: 8px 14px;
  font-size: 13px;
  color: #5a4000;
  margin-top: 10px;
  line-height: 1.6;
  flex-wrap: wrap;
}
.firmware-notes .notes-label {
  font-weight: 600;
  white-space: nowrap;
  flex-shrink: 0;
}
.firmware-notes .notes-body {
  flex: 1;
}


/* ── Chip tabs (segmented control) ── */
.chip-tabs {
  display: inline-flex;
  background: #efefef;
  border-radius: 10px;
  padding: 4px;
  gap: 0;
  margin-bottom: 24px;
  width: 100%;
  max-width: 360px;
}
.chip-tab {
  flex: 1;
  padding: 10px 0;
  border: none;
  background: transparent;
  border-radius: 7px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  color: #888;
  cursor: pointer;
  transition: color 0.18s;
  position: relative;
  z-index: 1;
  text-align: center;
}
.chip-tab:hover { color: #333; }
.chip-tabs .chip-tab.active {
  background: #fff !important;
  color: var(--accent) !important;
  box-shadow: 0 1px 4px rgba(0,0,0,0.15), 0 0 0 0.5px rgba(0,0,0,0.06);
}
/* override the default button red bg for inactive chip tabs */
.chip-tabs .chip-tab:not(.active) {
  background: transparent !important;
  color: #888 !important;
  border-color: transparent !important;
}
/* Safari: reset -webkit-appearance so our styles apply */
.chip-tab {
  -webkit-appearance: none;
  appearance: none;
}

/* ── Mobile: full-width tabs ── */
@media (max-width: 480px) {
  .chip-tabs { max-width: 100%; }
}

/* ── Panel ── */
.panel {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 20px 24px;
  margin-bottom: 16px;
  background: var(--panel-bg);
}

.panel h2 {
  font-size: 15px;
  font-weight: 700;
  margin: 0 0 14px;
  color: var(--fg);
}

.step-label {
  display: inline-block;
  background: var(--step-pill);
  color: var(--step-text);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.5px;
  padding: 3px 10px;
  border-radius: 20px;
  margin-bottom: 8px;
  text-transform: uppercase;
}

/* ── Erase collapsible ── */
details.panel-erase {
  border: 1px dashed #e8c0c0;
  border-radius: 8px;
  padding: 14px 20px;
  margin-bottom: 14px;
  background: #fff8f8;
  color: var(--fg);
}
[data-theme="dark"] details.panel-erase {
  border-color: #6b3030;
  background: #2a1a1a;
}
details.panel-erase > summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  user-select: none;
  font-weight: 600;
  font-size: 14px;
}
details.panel-erase > summary::-webkit-details-marker { display: none; }
details.panel-erase > summary::after {
  content: '›';
  margin-left: auto;
  font-size: 18px;
  color: var(--muted);
  transition: transform 0.2s;
}
details.panel-erase[open] > summary::after {
  transform: rotate(90deg);
}
.panel-erase-body {
  margin-top: 12px;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.5;
}

/* ── Form elements ── */
label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 5px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

select,
input:not([type="submit"]):not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]),
textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--line);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  background: var(--bg);
  color: var(--fg);
  outline: none;
  transition: border-color 0.15s;
  box-sizing: border-box;
  height: auto;
  -webkit-appearance: none;
  appearance: none;
}
input[type="file"] {
  padding: 8px 12px;
  cursor: pointer;
  -webkit-appearance: auto;
  appearance: auto;
}
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='%23888' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}
select:focus, input:focus, textarea:focus {
  border-color: var(--accent);
}
textarea { min-height: 70px; resize: vertical; }

.row-3 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 14px;
}
.row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 14px;
}

/* ── Buttons ── */
button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 18px;
  border-radius: 5px;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s, border-color 0.15s;
  border: 1px solid transparent;
}

button:not(.secondary):not(.danger) {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
button:not(.secondary):not(.danger):hover { background: var(--accent-hover); border-color: var(--accent-hover); }
button:not(.secondary):not(.danger):disabled { opacity: 0.4; cursor: not-allowed; }

button.secondary {
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--line);
}
button.secondary:hover { border-color: #aaa; }
button.secondary:disabled { opacity: 0.4; cursor: not-allowed; }

button.danger {
  background: var(--bg);
  color: var(--err);
  border: 1px solid #f0c0c0;
}
button.danger:hover { background: #fff5f5; }

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-top: 12px;
}

/* ── Connection status ── */
.conn-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 4px;
  background: #f3f4f6;
  color: var(--muted);
}
.conn-status.connected { background: #eefaf3; color: var(--ok); }
.conn-status.dfu { background: #fff4e5; color: var(--warn); }

.conn-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: #ccc;
  flex-shrink: 0;
}
.connected .conn-dot { background: var(--ok); }
.dfu .conn-dot { background: var(--warn); }

/* ── Steps list ── */
ul.steps {
  margin: 0 0 10px;
  padding-left: 20px;
}
ul.steps li { margin-bottom: 6px; line-height: 1.5; }

/* ── Progress ── */
.progress-wrap {
  margin-top: 12px;
  display: none;
}
.progress-bar-bg {
  height: 8px;
  background: var(--line);
  border-radius: 4px;
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  background: var(--accent);
  border-radius: 4px;
  width: 0%;
  transition: width 0.1s;
}
.progress-label {
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
}

/* ── Status line ── */
.status-line {
  display: none;
  font-size: 13px;
  padding: 7px 12px;
  border-radius: 5px;
  background: #f3f4f6;
  margin-bottom: 12px;
}
.status-line.ok { background: #eefaf3; color: var(--ok); }
.status-line.err { background: #fff0f0; color: var(--err); }
.status-line.warn { background: #fff8e1; color: var(--warn); }

/* ── Log ── */
.log-toggle {
  display: none;
  font-size: 12px;
  color: var(--muted) !important;
  background: none !important;
  border: none !important;
  box-shadow: none !important;
  cursor: pointer;
  padding: 2px 0;
  font-family: inherit;
  font-weight: 400;
}
.log-toggle:hover { color: var(--fg) !important; background: none !important; }
.log-toggle .log-arrow {
  display: inline-block;
  font-size: 16px;
  line-height: 1;
  transition: transform 0.2s;
  vertical-align: middle;
}
.log-toggle.open .log-arrow { transform: rotate(90deg); }

.log {
  display: none;
  margin-top: 8px;
  font-family: "SF Mono", "Fira Code", monospace;
  font-size: 12px;
  background: #1a1a1a;
  color: #d4d4d4;
  border-radius: 6px;
  padding: 12px;
  max-height: 200px;
  overflow-y: auto;
  line-height: 1.5;
}
.log .ok { color: #4ec95e; }
.log .err { color: #f47067; }
.log .warn { color: #e5c07b; }

/* ── Table ── */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
th {
  text-align: left;
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.3px;
  padding: 6px 8px;
  border-bottom: 2px solid var(--line);
}
td {
  padding: 8px 8px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
tr:last-child td { border-bottom: none; }

/* ── Misc ── */
.small { font-size: 12px; color: var(--muted); }
.meta-text { color: var(--muted); }
.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 3px;
  background: #f0f0f0;
  color: var(--muted);
}
.badge.nrf { background: #e8f0ff; color: #2255cc; }
.badge.esp { background: #fff0d0; color: #a85a00; }

/* ── Serial Monitor ── */
.serial-monitor-wrap {
  border: 1px solid var(--line);
  border-radius: 10px;
  margin-top: 8px;
  margin-bottom: 16px;
  overflow: hidden;
}
.serial-monitor-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 18px;
  background: var(--panel-bg);
  border-bottom: 1px solid transparent;
  cursor: pointer;
  user-select: none;
  transition: background 0.15s;
}
.serial-monitor-wrap.open .serial-monitor-header {
  border-bottom-color: var(--line);
  background: var(--icon-btn-hover);
}
.serial-monitor-header:hover { background: var(--icon-btn-hover); }
.serial-monitor-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 600;
  color: var(--fg);
}
.serial-monitor-title .mon-icon { font-size: 16px; }
.serial-monitor-chevron {
  font-size: 18px;
  color: var(--muted);
  transition: transform 0.2s;
}
.serial-monitor-wrap.open .serial-monitor-chevron { transform: rotate(90deg); }
.serial-monitor-body {
  display: none;
  padding: 14px 18px;
}
.serial-monitor-wrap.open .serial-monitor-body { display: block; }
.serial-monitor-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: flex-end;
  margin-bottom: 10px;
}
.serial-monitor-toolbar > div {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.serial-monitor-toolbar label {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.3px;
  margin: 0;
}
.serial-monitor-toolbar select {
  width: auto;
  min-width: 130px;
  padding: 7px 30px 7px 10px;
  font-size: 13px;
}
.serial-monitor-toolbar button { align-self: flex-end; }
.serial-monitor-output {
  font-family: "SF Mono", "Fira Code", "Cascadia Code", monospace;
  font-size: 12px;
  background: #1a1a1a;
  color: #d4d4d4;
  border-radius: 6px;
  padding: 12px;
  height: 220px;
  overflow-y: auto;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-all;
}
.serial-monitor-output .mon-ts { color: #666; font-size: 11px; margin-right: 4px; }
.serial-monitor-status {
  font-size: 12px;
  color: var(--muted);
  margin-top: 6px;
  min-height: 18px;
}
.serial-monitor-status.ok { color: var(--ok); }
.serial-monitor-status.err { color: var(--err); }

@media (max-width: 600px) {
  .serial-monitor-toolbar { flex-direction: column; align-items: stretch; }
  .serial-monitor-toolbar select { width: 100%; min-width: 0; }
}

/* ── Footer ── */
.footer {
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  padding: 20px 24px 28px;
  border-top: 1px solid var(--line);
  margin-top: 12px;
}
.footer a { color: var(--muted); }
.footer a:hover { color: var(--accent); }

@media (max-width: 600px) {
  .row-3, .row { grid-template-columns: 1fr; }
  .topbar { padding: 0 12px; height: 50px; }
  .brand a { font-size: 16px; }
  .brand .brand-sub { display: none; }        /* hide sub on small screens */
  .hero { padding: 16px 14px 14px; }
  .hero h1 { font-size: 18px; }
  .content { padding: 14px; }
  .panel { padding: 14px; }
  .actions { flex-direction: column; align-items: stretch; }
  .actions button, .actions a.shop-link { width: 100%; justify-content: center; text-align: center; }
  .conn-status { width: 100%; justify-content: center; }
  .chip-tabs { max-width: 100%; }
}
