:root {
  --bg: #0f1419;
  --panel: #1a2230;
  --panel-2: #222d3d;
  --line: #2c3a4f;
  --text: #e6edf3;
  --muted: #8aa0b6;
  --accent: #00c2a8;
  --accent-2: #ffb020;
  --flash: #4d9fff;
  --on: #2ee06a;
  --red: #ff5a5a;
  --dock-h: 0px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  font-family: "Segoe UI", Roboto, system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding: 12px 12px calc(12px + var(--dock-h) + var(--safe-bottom));
  max-width: 720px;
  margin-inline: auto;
}

.topbar { margin-bottom: 8px; }

.brand {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.brand h1 {
  margin: 0;
  font-size: clamp(1.25rem, 5vw, 1.5rem);
  font-weight: 700;
  line-height: 1.2;
}

.brand .accent { color: var(--accent); }

.brand .subtitle {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.brand code { color: var(--accent-2); }

.hub-back {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  border-radius: 8px;
  border: 1px solid var(--line);
  color: var(--accent);
  text-decoration: none;
  font-size: 18px;
  margin-top: 2px;
}

.mobile-tip {
  margin: 0 0 8px;
  padding: 8px 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.45;
}

.diag-hint {
  margin: 8px 0 0;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--red);
  background: rgba(255, 90, 90, 0.1);
  color: #ffb4b4;
  font-size: 12px;
  line-height: 1.5;
}

.diag-hint.ok {
  border-color: var(--on);
  background: rgba(46, 224, 106, 0.1);
  color: #9dffc0;
}

.status {
  color: var(--muted);
  font-size: 13px;
  margin: 0 0 12px;
  line-height: 1.4;
}

.status.error { color: var(--red); }
.status.ok { color: var(--on); }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 12px;
}

.panel h2 {
  margin: 0 0 10px;
  font-size: 14px;
  color: var(--muted);
  font-weight: 600;
}

.panel-hint {
  margin: -4px 0 12px;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.45;
}

.panel-hint code { color: var(--accent-2); }

.panel-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}

.panel-head h2 { margin: 0; }

.filter-irel {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
  cursor: pointer;
}

.filter-irel input { accent-color: var(--accent); width: 16px; height: 16px; }

.device-toolbar {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  margin: 10px 0;
}

.scan-status {
  margin: 0 0 10px;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.4;
}

.scan-status.active { color: var(--accent); }

.device-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 220px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.device-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-2);
  cursor: pointer;
  text-align: left;
  min-height: 52px;
  touch-action: manipulation;
}

.device-item input {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
  pointer-events: none;
}

.device-item.selected {
  border-color: var(--accent);
  background: rgba(0, 194, 168, 0.12);
}

.device-item.connected {
  border-color: var(--on);
}

.device-meta { flex: 1; min-width: 0; }

.device-name {
  font-size: 14px;
  font-weight: 600;
  word-break: break-word;
}

.device-id {
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
}

.device-rssi {
  font-size: 11px;
  color: var(--accent-2);
  flex-shrink: 0;
}

.device-empty {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
  text-align: center;
  padding: 12px;
}

.device-empty.hidden { display: none; }

@media (max-width: 480px) {
  .device-toolbar { grid-template-columns: 1fr; }
}

.file-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 12px;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.info-list {
  margin: 0;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 12px;
  font-size: 13px;
}

.info-list dt { color: var(--muted); }
.info-list dd { margin: 0; word-break: break-all; }

.info-compact { font-size: 12px; }

.progress-wrap {
  height: 12px;
  background: var(--panel-2);
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid var(--line);
}

.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--flash));
  width: 0;
  transition: width .2s ease;
}

.progress-text {
  margin: 8px 0 0;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.4;
}

.log {
  margin: 0;
  max-height: 160px;
  overflow: auto;
  background: #0b1016;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  font-family: Consolas, "Courier New", monospace;
  font-size: 11px;
  color: var(--muted);
  white-space: pre-wrap;
  -webkit-overflow-scrolling: touch;
}

.btn {
  background: var(--accent);
  color: #03201c;
  border: none;
  border-radius: 10px;
  padding: 12px 14px;
  font-weight: 600;
  cursor: pointer;
  font-size: 15px;
  touch-action: manipulation;
  min-height: 44px;
}

.btn:hover { filter: brightness(1.08); }
.btn:disabled { opacity: .45; cursor: not-allowed; filter: none; }

.btn-sec {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
}

.btn-sec:hover:not(:disabled) { border-color: var(--accent); filter: none; }

.btn-flash {
  background: var(--flash);
  color: #061428;
}

.btn-block { width: 100%; }

.dock {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 100;
  background: rgba(15, 20, 25, .96);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
  padding: 8px 10px calc(8px + var(--safe-bottom));
  max-width: 720px;
  margin: 0 auto;
}

.model-select {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 13px;
  color: var(--muted);
}

.model-select select {
  flex: 1;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 15px;
  min-height: 44px;
}

.dock-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr 0.7fr 1.2fr;
  gap: 6px;
}

.dock-btn {
  padding: 10px 6px;
  font-size: 13px;
  min-height: 48px;
}

.dock-btn-primary {
  font-size: 15px;
  font-weight: 700;
}

.foot {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 6px;
  margin-top: 4px;
  font-size: 11px;
  color: var(--muted);
}

.foot a { color: var(--accent); text-decoration: none; }

.dropzone-desktop { display: none !important; }

@media (min-width: 640px) {
  body {
    padding: 20px;
    padding-bottom: calc(20px + var(--dock-h) + var(--safe-bottom));
  }

  .grid-2 { grid-template-columns: 1fr 1fr; }

  .dock {
    position: sticky;
    bottom: 0;
    border-radius: 12px;
    margin-top: 8px;
    border: 1px solid var(--line);
  }

  .dock-buttons {
    grid-template-columns: auto auto auto 1fr;
  }

  .dock-btn-primary { max-width: 180px; margin-left: auto; }

  .mobile-tip { font-size: 13px; }

  .dropzone-desktop {
    display: block !important;
    border: 2px dashed var(--line);
    border-radius: 12px;
    padding: 14px;
    text-align: center;
    color: var(--muted);
    font-size: 13px;
    margin-bottom: 12px;
  }

  .dropzone-desktop.drag {
    border-color: var(--accent);
    background: var(--panel);
  }
}

@media (max-width: 380px) {
  .dock-buttons {
    grid-template-columns: 1fr 1fr;
  }

  .dock-btn-primary {
    grid-column: 1 / -1;
  }
}
