/* 故障信息收集页样式。移动优先，720px 断点以上转桌面布局。
   设计令牌在 /tokens.css，与后台共用同一份。 */

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB',
    'Microsoft YaHei', 'Helvetica Neue', sans-serif;
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

.wrap {
  max-width: 720px;
  margin: 0 auto;
  padding: 20px 16px 120px;
}

/* ------------------------------ 页头 ------------------------------ */

.page-head {
  padding: 8px 0 20px;
}

.page-head h1 {
  margin: 0 0 6px;
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.page-head p {
  margin: 0;
  color: var(--text-soft);
  font-size: 14px;
}

/* ------------------------------ 卡片 ------------------------------ */

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 16px;
}

.card > h2 {
  margin: 0 0 16px;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

/* ------------------------------ 表单 ------------------------------ */

.field {
  margin-bottom: 18px;
}

.field:last-child {
  margin-bottom: 0;
}

.field > label {
  display: block;
  margin-bottom: 6px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
}

.field .req {
  color: var(--danger);
  margin-left: 2px;
}

.hint {
  margin-top: 6px;
  font-size: 12.5px;
  color: var(--text-mute);
}

/*
 * 工厂收货信息。客户要**照着抄**到快递面单上，所以给个浅蓝底框把它从
 * 上面的说明文字里拎出来，字号也比 .hint 大一档 —— 手机上是要念着写的。
 */
.factory-box {
  margin-top: 10px;
  padding: 12px 14px;
  background: var(--brand-soft);
  border: 1px solid #d8e3ff;
  border-radius: var(--radius);
}

.factory-info {
  font-size: 13px;
  line-height: 1.7;
  color: var(--text-soft);
  /* 保住源码里的换行。行首的缩进空格由 CSS 折掉，复制时另有 JS 逐行 trim */
  white-space: pre-line;
}

.factory-box .btn {
  margin-top: 10px;
}

/* 16px 是关键：小于 16px 时 iOS Safari 聚焦会强制放大页面 */
input[type='text'],
input[type='tel'],
input[type='password'],
select,
textarea {
  width: 100%;
  padding: 11px 12px;
  font-size: 16px;
  font-family: inherit;
  color: var(--text);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  -webkit-appearance: none;
  appearance: none;
}

textarea {
  resize: vertical;
  /* 故障描述是工程师定位问题的主依据，框子给足高度，别让人写到第三行就开始滚动 */
  min-height: 200px;
  line-height: 1.6;
}

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 fill='%238c96a8' d='M6 8 0 0h12z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

input::placeholder,
textarea::placeholder {
  color: #b3bbc9;
}

.row {
  display: grid;
  gap: 14px;
  grid-template-columns: 1fr;
}

.counter {
  float: right;
  font-size: 12px;
  color: var(--text-mute);
  font-weight: 400;
}

.counter.over {
  color: var(--danger);
}

/* 可搜索的分组下拉的样式在 /combo.css —— 和后台列表页共用同一份 */

/* ---------------------------- 附件区域 ---------------------------- */

/*
 * 桌面端按钮按内容宽度左对齐；手机上（见文件末尾的 @media）改成三等分，
 * 保证「上传文件 / 拍摄画面 / 视频录像」永远在一行里 —— 之前用 flex-wrap
 * 在 360px 的机器上会挤成两行。
 */
.attach-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.btn-file {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 15px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  background: #fff;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
  user-select: none;
}

.btn-file:hover {
  border-color: var(--brand);
  color: var(--brand);
  background: var(--brand-soft);
}

.btn-file svg {
  width: 17px;
  height: 17px;
  flex: none;
}

.attach-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/*
 * 附件摘要（已选 N 个文件，共 X MB）挂在附件列表下面。
 * 没选文件时 JS 会把文本清空，这里让空元素整个收起，避免留一行空隙。
 */
.attach-summary {
  margin-top: 10px;
  font-size: 13px;
  color: var(--text-soft);
}

.attach-summary:empty {
  display: none;
}

.attach-item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 11px;
  background: #fafbfd;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
}

.attach-item.is-error {
  background: var(--danger-soft);
  border-color: #fbd5d5;
}

.thumb {
  width: 46px;
  height: 46px;
  flex: none;
  border-radius: 7px;
  overflow: hidden;
  background: #e8ecf3;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.thumb img,
.thumb video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.thumb .kind-tag {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-mute);
  letter-spacing: 0.03em;
}

/*
 * 图片缩略图可点开看大图。这个 .thumb 是 <button> 而不是 <div>（见 submit.js 的
 * renderItem），所以要显式清掉浏览器给按钮的默认边框和内边距，否则缩略图周围
 * 会多出一圈灰边。视频/文档那两个 <div> 不带这个类，样式不受影响。
 */
.thumb-zoom {
  border: 0;
  padding: 0;
  appearance: none;
  -webkit-appearance: none;
  cursor: zoom-in;
}

.thumb-zoom:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

.attach-meta {
  flex: 1;
  min-width: 0;
}

.attach-name {
  font-size: 13.5px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.attach-sub {
  font-size: 12px;
  color: var(--text-mute);
  margin-top: 1px;
}

.attach-sub.err {
  color: var(--danger);
}

.attach-sub.done {
  color: var(--ok);
}

.bar {
  height: 3px;
  background: #e3e8f0;
  border-radius: 2px;
  margin-top: 6px;
  overflow: hidden;
}

.bar > i {
  display: block;
  height: 100%;
  width: 0;
  background: var(--brand);
  border-radius: 2px;
  transition: width 0.2s;
}

.attach-remove {
  flex: none;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: var(--text-mute);
  font-size: 19px;
  line-height: 1;
  cursor: pointer;
  border-radius: 6px;
}

.attach-remove:hover {
  background: #eef1f7;
  color: var(--danger);
}

/* ------------------------------ 按钮 ------------------------------ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 46px;
  padding: 0 22px;
  font-size: 15px;
  font-weight: 500;
  font-family: inherit;
  border: 1px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.btn-primary {
  background: var(--brand);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--brand-dark);
}

.btn-ghost {
  background: #fff;
  border-color: var(--line);
  color: var(--text);
}

.btn-ghost:hover:not(:disabled) {
  border-color: var(--brand);
  color: var(--brand);
}

.btn-danger-ghost {
  background: #fff;
  border-color: var(--line);
  color: var(--danger);
}

.btn-danger-ghost:hover:not(:disabled) {
  border-color: var(--danger);
  background: var(--danger-soft);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-block {
  width: 100%;
}

.btn-sm {
  padding: 5px 11px;
  font-size: 13px;
  border-radius: 7px;
}

/* 故障描述的模板插入按钮 */
.tpl-actions {
  margin-top: 8px;
}

/* 取消上报：次要动作，不跟主按钮抢宽度 */
.btn-cancel {
  flex: none;
}

/* --------------------------- 提交栏（移动端吸底） --------------------------- */

.submit-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--line);
  z-index: 20;
}

.submit-bar .inner {
  max-width: 720px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
}

/* ------------------------------ 提示 ------------------------------ */

.alert {
  padding: 11px 13px;
  border-radius: var(--radius);
  font-size: 13.5px;
  margin-bottom: 14px;
  border: 1px solid transparent;
}

.alert-error {
  background: var(--danger-soft);
  border-color: #fbd5d5;
  color: #991b1b;
}

.alert-warn {
  background: var(--warn-soft);
  border-color: #fde68a;
  color: var(--warn);
}

.alert-ok {
  background: var(--ok-soft);
  border-color: #a7f3d0;
  color: #065f46;
}

.toast-host {
  position: fixed;
  left: 50%;
  top: 18px;
  transform: translateX(-50%);
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
  width: calc(100% - 32px);
  max-width: 460px;
}

.toast {
  padding: 11px 15px;
  border-radius: var(--radius);
  font-size: 13.5px;
  box-shadow: 0 8px 24px rgba(16, 24, 40, 0.16);
  animation: toast-in 0.18s ease-out;
}

.toast-error {
  background: #fee2e2;
  color: #991b1b;
}

.toast-ok {
  background: #d1fae5;
  color: #065f46;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* ------------------------------ 图片预览 ------------------------------ */

/*
 * 与 admin.css 里的 .lightbox 是同一套结构，但两边**刻意各存一份**：
 * 本页是手机上用的（关闭按钮和上一张/下一张都按手指尺寸放大），后台是桌面端。
 * 合到 tokens.css 也不合适 —— 那个文件按约定只放设计令牌，不含组件样式。
 * 真要改外观，记得两边一起看。
 */
.lightbox {
  position: fixed;
  inset: 0;
  /* 压在吸底提交栏(20)和 toast(60)之上 —— 预览时不该看见它们 */
  z-index: 100;
  background: rgba(12, 16, 26, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.lightbox img {
  max-width: 100%;
  max-height: calc(100vh - 130px);
  object-fit: contain;
  border-radius: var(--radius-sm);
}

.lightbox .lb-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
}

.lightbox .lb-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 44px;
  height: 64px;
  border: 0;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  font-size: 26px;
  cursor: pointer;
}

.lightbox .lb-prev { left: 10px; }
.lightbox .lb-next { right: 10px; }

.lightbox .lb-caption {
  position: absolute;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: calc(100% - 40px);
  color: #fff;
  font-size: 13px;
  text-align: center;
  overflow-wrap: anywhere;
}

/* ---------------------------- 提交成功页 ---------------------------- */

.success {
  text-align: center;
  padding: 44px 20px;
}

.success .tick {
  width: 60px;
  height: 60px;
  margin: 0 auto 20px;
  border-radius: 50%;
  background: var(--ok-soft);
  color: var(--ok);
  display: flex;
  align-items: center;
  justify-content: center;
}

.success h2 {
  margin: 0 0 8px;
  font-size: 19px;
  font-weight: 600;
}

.success p {
  margin: 0 0 26px;
  color: var(--text-soft);
  font-size: 14px;
}

.ticket-no {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  padding: 15px 22px;
  background: var(--brand-soft);
  border: 1px dashed #bcd0fb;
  border-radius: var(--radius);
  margin-bottom: 24px;
  max-width: 100%;
}

.ticket-no .num {
  font-size: 21px;
  font-weight: 600;
  color: var(--brand-dark);
  letter-spacing: 0.02em;
  font-variant-numeric: tabular-nums;
  word-break: break-all;
}

.ticket-no button {
  flex: none;
  padding: 6px 11px;
  font-size: 12.5px;
  font-family: inherit;
  color: var(--brand);
  background: #fff;
  border: 1px solid #bcd0fb;
  border-radius: 6px;
  cursor: pointer;
}

.ticket-no button:hover {
  background: var(--brand);
  color: #fff;
  border-color: var(--brand);
}

.spinner {
  width: 15px;
  height: 15px;
  border: 2px solid rgba(255, 255, 255, 0.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex: none;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.hidden {
  display: none !important;
}

/* ------------------------------ 桌面端 ------------------------------ */

@media (min-width: 720px) {
  .wrap {
    padding: 36px 24px 60px;
  }

  .page-head h1 {
    font-size: 26px;
  }

  .card {
    padding: 26px;
  }

  .row-2 {
    grid-template-columns: 1fr 1fr;
  }

  .submit-bar {
    position: static;
    padding: 0;
    background: none;
    backdrop-filter: none;
    border: none;
  }

  .submit-bar .inner {
    justify-content: flex-end;
  }

  /*
   * 桌面端按钮右对齐，各按内容宽度站住 —— 别给这个按钮加 .btn-block：
   * width:100% 在 flex 行里等价于 flex-basis:100%，它会跟「取消上报」抢宽度
   * 再被压缩，按钮宽度就随行内其他元素起伏了。
   */
  .submit-bar .btn-submit-desktop {
    flex: none;
    min-width: 168px;
  }
}

/*
 * 移动端吸底栏里要放下「取消上报 + 确认上报」两个按钮：确认上报占满剩余宽度。
 */
@media (max-width: 719px) {
  .submit-bar .inner {
    gap: 10px;
  }

  .submit-bar .btn-submit-desktop {
    flex: 1;
  }

  /*
   * 三个附件按钮改成三等分。按 360px 窄屏算：页面左右各 16px、卡片内左右各 20px，
   * 卡片内容宽 = 360 - 32 - 40 = 288px，减去两道 8px 间隙后每格 90px；
   * 格子里是「16px 图标 + 5px 间隙 + 4 个 13px 汉字 = 52px」= 73px，
   * 加上左右各 6px 内边距仍然放得下，所以不会再换行。
   */
  .attach-actions {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .btn-file {
    justify-content: center;
    gap: 5px;
    padding: 0 6px;
    font-size: var(--fs-sm);
    white-space: nowrap;
  }

  .btn-file svg {
    width: 16px;
    height: 16px;
  }
}

/*
 * 320px 级别的老机器再挤出最后一点宽度：藏掉图标。
 * 只藏图标不缩写文字 —— 「上传文件」缩成「上传」会让人以为是传错地方。
 */
@media (max-width: 359px) {
  .btn-file svg {
    display: none;
  }

  .btn-file {
    font-size: var(--fs-xs);
  }
}
