/* IoT 工具箱 - 自定义样式（配合 Bootstrap 5.3） */

:root {
  --iot-radius: 14px;
  --iot-shadow: 0 6px 24px rgba(84, 112, 198, .08);
  --iot-shadow-hover: 0 10px 32px rgba(84, 112, 198, .18);
  /* 输入框描边：比卡片边线更轻，视觉上更接近发丝线 */
  --iot-input-border: rgba(2, 6, 23, .08);
  --iot-input-border-focus: rgba(84, 112, 198, .55);

  /* ---------------------------- 主题色 #5470c6 ---------------------------- */
  --iot-primary: #5470c6;
  --iot-primary-rgb: 84, 112, 198;
  --iot-primary-dark: #4460b4;   /* hover */
  --iot-primary-darker: #3d55a2; /* active */
  --iot-primary-soft: #7f9ada;   /* 渐变亮端 */
  --iot-primary-deep: #3f57ab;   /* 渐变暗端 */

  /* 覆盖 Bootstrap 主色变量（text-primary / bg-primary / 链接色 / 边框色等） */
  --bs-primary: #5470c6;
  --bs-primary-rgb: 84, 112, 198;
  --bs-link-color: #5470c6;
  --bs-link-color-rgb: 84, 112, 198;
  --bs-link-hover-color: #4460b4;
  --bs-link-hover-color-rgb: 68, 96, 180;
}

[data-bs-theme="dark"] {
  --iot-input-border: rgba(255, 255, 255, .14);
}

/* ---------------------------- 主题色组件覆盖 ---------------------------- */
/* Bootstrap 的按钮/表单项把主色写死成了 #0d6efd，这里统一改到 --iot-primary */
.btn-primary {
  --bs-btn-bg: var(--iot-primary);
  --bs-btn-border-color: var(--iot-primary);
  --bs-btn-hover-bg: var(--iot-primary-dark);
  --bs-btn-hover-border-color: var(--iot-primary-dark);
  --bs-btn-active-bg: var(--iot-primary-darker);
  --bs-btn-active-border-color: var(--iot-primary-darker);
  --bs-btn-disabled-bg: var(--iot-primary);
  --bs-btn-disabled-border-color: var(--iot-primary);
  --bs-btn-focus-shadow-rgb: var(--iot-primary-rgb);
}

.btn-outline-primary {
  --bs-btn-color: var(--iot-primary);
  --bs-btn-border-color: var(--iot-primary);
  --bs-btn-hover-bg: var(--iot-primary);
  --bs-btn-hover-border-color: var(--iot-primary);
  --bs-btn-active-bg: var(--iot-primary-dark);
  --bs-btn-active-border-color: var(--iot-primary-dark);
  --bs-btn-disabled-color: var(--iot-primary);
  --bs-btn-disabled-border-color: var(--iot-primary);
  --bs-btn-focus-shadow-rgb: var(--iot-primary-rgb);
}

.form-check-input:focus {
  border-color: var(--iot-input-border-focus);
}

.form-check-input:checked,
.form-check-input[type="checkbox"]:indeterminate,
.form-range::-webkit-slider-thumb,
.form-range::-moz-range-thumb {
  background-color: var(--iot-primary);
  border-color: var(--iot-primary);
}

.nav-link:focus-visible {
  box-shadow: 0 0 0 .25rem rgba(var(--iot-primary-rgb), .25);
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-family: system-ui, -apple-system, "Segoe UI", "Microsoft YaHei", "PingFang SC", "Hiragino Sans GB", sans-serif;
}

main {
  flex: 1 0 auto;
}

a {
  text-decoration: none;
}

/* ------------------------------- 顶部导航 ------------------------------- */
.iot-navbar {
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--bs-border-color);
}

.brand-badge {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--iot-primary), var(--iot-primary-soft));
  color: #fff;
  font-size: 1.1rem;
}

/* ------------------------------- 首页 Hero ------------------------------ */
.iot-hero {
  background: linear-gradient(135deg, var(--iot-primary-deep) 0%, var(--iot-primary) 45%, var(--iot-primary-soft) 100%);
  color: #fff;
  border-radius: 0 0 24px 24px;
  padding: 3rem 0 2.5rem;
}

.iot-hero .search-box {
  max-width: 720px;
  margin: 0 auto;
}

.iot-hero .form-control {
  border: 0;
  padding: .95rem 1.1rem;
  font-size: 1.05rem;
}

.hero-stat {
  background: rgba(255, 255, 255, .16);
  border: 1px solid rgba(255, 255, 255, .28);
  border-radius: var(--iot-radius);
  padding: .6rem .9rem;
  min-width: 96px;
}

.hero-stat strong {
  display: block;
  font-size: 1.35rem;
  line-height: 1.2;
}

.hero-stat span {
  font-size: .8rem;
  opacity: .9;
}

/* --------------------------------- 卡片 -------------------------------- */
.tool-card {
  height: 100%;
  border: 1px solid var(--bs-border-color);
  border-radius: var(--iot-radius);
  background: var(--bs-body-bg);
  transition: transform .16s ease, box-shadow .16s ease, border-color .16s ease;
}

.tool-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--iot-shadow-hover);
  border-color: rgba(var(--iot-primary-rgb), .45);
}

/* 工具图标底色块：卡片、首页分类标题、工具页标题共用同一套尺寸 */
.tool-icon {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.15rem;
  line-height: 1;
  padding: 0;
  flex: 0 0 auto;
}

/* 工具页标题旁放大一档，和 h1 的视觉重量匹配 */
#tool-head .tool-icon {
  width: 3rem;
  height: 3rem;
  border-radius: 12px;
  font-size: 1.4rem;
}

.tool-card .tool-name {
  font-weight: 600;
  font-size: 1rem;
  color: var(--bs-body-color);
}

.tool-card .tool-desc {
  font-size: .84rem;
  color: var(--bs-secondary-color);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  min-height: 2.4em;
}

.cat-chip {
  cursor: pointer;
  border-radius: 999px;
  font-size: .82rem;
  padding: .3rem .8rem;
  white-space: nowrap;
}

.cat-chip.active {
  color: #fff !important;
}

.fav-btn {
  border: 0;
  background: transparent;
  color: var(--bs-secondary-color);
  padding: 0 .15rem;
  line-height: 1;
  flex: 0 0 auto; /* 星标按钮不参与压缩，避免被标题挤出卡片 */
}

.fav-btn.active {
  color: #ffc107;
}

/* Bootstrap 5.3 没有 min-width 工具类，而卡片标题块依赖它才能正确收缩 */
.min-w-0 {
  min-width: 0 !important;
}

.tool-card .tool-name .badge {
  flex: 0 0 auto;
}

/* -------------------------------- 工具页 ------------------------------- */
.field-label {
  font-size: .86rem;
  font-weight: 600;
  margin-bottom: .3rem;
}

/* 输入控件：统一为更纤细的 1px 描边，避免在卡片上显得笨重 */
.form-control,
.form-select,
textarea.form-control,
.input-group-text {
  border-width: 1px;
  border-color: var(--iot-input-border);
  box-shadow: none;
}

.form-control:focus,
.form-select:focus {
  border-color: var(--iot-input-border-focus);
  box-shadow: none;
}

/* 校验态同样不要光圈，只保留红/绿描边提示 */
.form-control.is-invalid:focus,
.form-control.is-valid:focus,
.form-select.is-invalid:focus,
.form-select.is-valid:focus {
  box-shadow: none;
}

/* 勾选框/单选框同理，聚焦只换描边色，不加光圈 */
.form-check-input:focus {
  box-shadow: none;
}

.result-value {
  font-weight: 600;
  font-size: 1.12rem;
  word-break: break-all;
}

.result-value.big {
  font-size: 1.45rem;
  color: var(--bs-primary);
}

.result-tile {
  border: 1px solid var(--bs-border-color);
  border-radius: 12px;
  padding: .75rem .9rem;
  height: 100%;
  background: var(--bs-tertiary-bg);
}

[data-bs-theme="dark"] .result-tile {
  background: rgba(255, 255, 255, .04);
}

.result-tile .tile-label {
  font-size: .8rem;
  color: var(--bs-secondary-color);
}

.mono-block {
  font-family: "JetBrains Mono", Consolas, "Courier New", monospace;
  font-size: .86rem;
  white-space: pre-wrap;
  word-break: break-all;
  background: var(--bs-tertiary-bg);
  border: 1px solid var(--bs-border-color);
  border-radius: 10px;
  padding: .75rem .9rem;
  max-height: 380px;
  overflow: auto;
  margin: 0;
}

[data-bs-theme="dark"] .mono-block {
  background: rgba(255, 255, 255, .04);
}

.block-label {
  font-size: .84rem;
  font-weight: 600;
  color: var(--bs-secondary-color);
  margin-bottom: .35rem;
}

.sticky-side {
  position: sticky;
  top: 84px;
}

.related-link {
  display: block;
  padding: .45rem .6rem;
  border-radius: 8px;
  font-size: .88rem;
  color: var(--bs-body-color);
}

.related-link:hover {
  background: var(--bs-tertiary-bg);
  color: var(--bs-primary);
}

.tag-pill {
  font-size: .74rem;
  border-radius: 999px;
  padding: .18rem .6rem;
}

/* ------------------------------ 在线调试日志 ------------------------------ */
.debug-log {
  max-height: 420px;
  overflow: auto;
  font-size: .82rem;
  line-height: 1.55;
  background: var(--bs-body-bg);
}

.debug-log-empty {
  padding: .9rem 1rem;
  color: var(--bs-secondary-color);
}

.debug-log-row {
  display: flex;
  gap: .5rem;
  align-items: baseline;
  padding: .3rem 1rem;
  border-bottom: 1px solid var(--bs-border-color);
}

.debug-log-row:last-child {
  border-bottom: 0;
}

.debug-log-time {
  flex: 0 0 auto;
  color: var(--bs-secondary-color);
  font-variant-numeric: tabular-nums;
}

.debug-log-dir {
  flex: 0 0 auto;
  width: 1rem;
  text-align: center;
}

.debug-log-dir.dir-in {
  color: var(--bs-success);
}

.debug-log-dir.dir-out {
  color: var(--iot-primary);
}

.debug-log-dir.dir-sys {
  color: var(--bs-secondary-color);
}

.debug-log-topic {
  flex: 0 1 auto;
  max-width: 42%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--iot-primary);
  font-weight: 600;
}

.debug-log-text {
  flex: 1 1 auto;
  white-space: pre-wrap;
  word-break: break-all;
}

.debug-log-row.is-error .debug-log-text {
  color: var(--bs-danger);
}

.debug-log-row.is-ok .debug-log-text {
  color: var(--bs-success);
}

.debug-log-row.is-warn .debug-log-text {
  color: var(--bs-warning-text-emphasis);
}

/* --------------------------------- 页脚 -------------------------------- */
.iot-footer {
  border-top: 1px solid var(--bs-border-color);
  background: var(--bs-tertiary-bg);
  font-size: .88rem;
  margin-top: 3rem;
}

.iot-footer .icp-link {
  color: inherit;
}

.iot-footer .icp-link:hover {
  color: var(--bs-primary);
}

kbd {
  background: var(--bs-tertiary-bg);
  color: var(--bs-body-color);
  border: 1px solid var(--bs-border-color);
  border-radius: 5px;
  padding: .05rem .35rem;
  font-size: .78rem;
}

/* -------------------------------- 响应式 ------------------------------- */
@media (max-width: 767.98px) {
  .iot-hero {
    padding: 1.75rem 0 1.5rem;
    border-radius: 0 0 16px 16px;
  }

  .iot-hero h1 {
    font-size: 1.6rem;
  }

  .hero-stat {
    min-width: 78px;
    padding: .45rem .6rem;
  }

  .hero-stat strong {
    font-size: 1.1rem;
  }

  .result-value.big {
    font-size: 1.25rem;
  }

  .sticky-side {
    position: static;
  }
}

/* 打印时只保留工具内容 */
@media print {
  .iot-navbar, .iot-footer, .sticky-side, .no-print {
    display: none !important;
  }
}

/* 滚动条美化 */
::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

::-webkit-scrollbar-thumb {
  background: rgba(128, 128, 128, .4);
  border-radius: 8px;
}

::-webkit-scrollbar-track {
  background: transparent;
}
