/**
 * Caper Captcha - 前端验证码组件样式
 *
 * 布局规范：标签置顶 → 输入框（左）与验证码图片（右）同一行；
 * 空间不足时图片自动等比收缩以保持一栏、绝不换行；
 * 移动端（视口 ≤480px）回退为纵向堆叠。
 *
 * @package Caper_Captcha
 * @since 1.2.0
 */

/* ========== 组件容器（输入框左 + 图片右，同一行、不换行） ========== */
.caper-captcha-wrapper,
.caper-captcha-wrap {
  display: flex;
  flex-wrap: nowrap;
  align-items: center; /* 输入框与图片均 40px，整行与上方字段同高 */
  gap: 8px;
  width: 100%;
  max-width: 100%;
  margin: 8px 0;
  box-sizing: border-box;
}

.caper-captcha-label {
  display: block;
  width: 100%;
  margin-bottom: 6px;
  font-size: 13px;
  font-weight: 500;
  color: #374151;
}

/* ========== 输入框（左：占满剩余宽度，可收缩） ========== */
.caper-captcha-input {
  flex: 1 1 110px;
  min-width: 0;        /* 允许收缩，避免与图片并排时整行超出表单宽度导致横向滚动条 */
  width: auto;
  height: 40px;      /* 与上方字段同高 */
  margin: 0;         /* 清除 WP 默认 .input 的 margin（右 6px 撑大间隙、下 16px 致垂直错位） */
  padding: 0 12px;
  border: 1px solid #949494;
  font-size: 14px;
  color: #1e293b;
  background: #fff;
  box-sizing: border-box;
  outline: none;
  transition:
    border-color 0.2s ease,
    box-shadow 0.2s ease;
}

.caper-captcha-input:focus {
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.08);
}

/* wp-login 等场景：压过 WP 默认 `.login form .input`（width:100% / margin:0 6px 16px 0 / min-height:40px） */
p.caper-captcha-field .caper-captcha-wrapper .caper-captcha-input {
  flex: 1 1 110px;
  min-width: 0;        /* 同上：并排时允许收缩，避免横向溢出 */
  width: auto;
  height: 40px;
  margin: 0;
}

/* ========== 图片容器（右：定高 40px，与输入框同高） ========== */
.caper-captcha-image-wrap {
  flex: 0 1 auto;
  min-width: 0;
  max-width: 100%;
  height: 40px;                  /* 与输入框同高，整行与上方字段一致 */
  display: flex;
  align-items: center;
  border: 1px solid #d1d5db;
  overflow: hidden;
  background: #fff;
  line-height: 0; /* 去掉 inline 图片底部间隙 */
  box-sizing: border-box;
}

/* ========== 验证码图片（按 40px 高度等比缩放） ========== */
.caper-captcha-img {
  display: block;
  height: 100%;                  /* 按 40px 高度等比缩放，与输入框同高 */
  width: auto;
  max-width: 100%;
  cursor: pointer;
  image-rendering: auto;
}

/* 点击图片刷新提示 */
.caper-captcha-img:hover {
  opacity: 0.88;
}

/* ========== 加载/错误占位 ========== */
.caper-captcha-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 50px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  font-size: 12px;
  color: #94a3b8;
}

.caper-captcha-error {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 50px;
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 6px;
  font-size: 12px;
  color: #dc2626;
}

/* wp-login.php 的表单字段兼容（保留原有类名） */
p.caper-captcha-field {
  margin-bottom: 16px;
}
p.caper-captcha-field .caper-captcha-wrapper {
  margin-top: 4px;
}

/* 评论表单兼容 */
p.comment-form-captcha {
  margin-bottom: 16px;
}
p.comment-form-captcha .caper-captcha-wrapper {
  margin-top: 4px;
}

/* ========== 响应式：移动端纵向堆叠 ========== */
@media (max-width: 480px) {
  .caper-captcha-wrapper,
  .caper-captcha-wrap {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }
  .caper-captcha-input {
    width: 100%;
    min-width: 0;
  }
  .caper-captcha-image-wrap {
    align-self: flex-start;
  }
}
.caper-captcha-refresh {
    display: block;
    height: 100%;
    max-width: 100%;
    min-width: 0;
    border: 0;
    padding: 0;
    background: transparent;
    cursor: pointer;
}
.caper-captcha-refresh:disabled { opacity: .5; cursor: wait; }
.caper-captcha-refresh:focus-visible { outline: 2px solid #2271b1; outline-offset: -2px; }
.caper-captcha-status { display: block; color: #b32d2e; font-size: 12px; }
@media (max-width: 480px) {
    p.caper-captcha-field .caper-captcha-wrapper .caper-captcha-input { flex: 0 0 40px; width: 100%; }
}
