/* 对齐 main.py：Tailwind / Shadcn 浅色主题 */
:root {
  --bg-page: #fafafa;
  --bg-card: #ffffff;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --text: #111827;
  --text-secondary: #374151;
  --text-muted: #6b7280;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-pressed: #1e40af;
  --success: #16a34a;
  --success-hover: #15803d;
  --danger: #dc2626;
  --radius: 8px;
  --radius-sm: 6px;
  --shadow-bar: 0 1px 0 #e5e7eb;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  min-height: 100%;
  font-family: "DM Sans", "Noto Sans SC", -apple-system, "Segoe UI", "Microsoft YaHei UI", sans-serif;
  font-size: 12px;
  color: var(--text);
  background: var(--bg-page);
  -webkit-font-smoothing: antialiased;
}

/* 用 clip 减少「横滑隐藏」在部分移动浏览器里截断纵向可滚动高度的问题 */
html {
  -webkit-text-size-adjust: 100%;
  overflow-x: clip;
}

body {
  overflow-x: clip;
  /* 避免页脚版权行贴底被刘海/手势条裁切 */
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.app-shell {
  display: flex;
  flex-direction: column;
  /* 桌面占满一屏；移动改用动态视口，避免 100vh 大于可见区域导致底部像被「吃掉」 */
  min-height: 100vh;
  min-height: 100dvh;
}

/* —— 标题栏（对应 PyQt TitleBar） —— */
.title-bar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 104px;
  padding: 20px 32px;
  background: linear-gradient(90deg, #c7e0fb 0%, #d7cff5 100%);
  border-top: 1px solid #cfdcf4;
  border-bottom: 1px solid #cfdcf4;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.65);
}

.title-bar__brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  min-width: 0;
  width: min(100%, 480px);
}

.logo-mark {
  flex-shrink: 0;
  width: 54px;
  height: 54px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.logo-mark__img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  pointer-events: none;
  user-select: none;
}

.title-bar__text {
  min-width: 0;
}

.footer__logo {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.footer__logo-img {
  width: 20px;
  height: 20px;
  object-fit: contain;
  display: block;
  pointer-events: none;
  user-select: none;
}

.title-bar__title {
  margin: 0;
  font-size: 21px;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: 0.01em;
  color: #1f82ee;
}

.title-bar__title-gradient {
  color: inherit;
}

.title-bar__subtitle {
  margin: 6px 0 0;
  font-size: 12px;
  line-height: 1.45;
  color: #5d6470;
}

.title-bar__actions {
  display: none;
}

.btn-ad-placeholder {
  width: 120px;
  height: 30px;
  border: 1px dashed var(--border);
  border-radius: 4px;
  background: transparent;
  color: var(--text-muted);
  font-size: 11px;
  cursor: default;
}

.window-chrome {
  display: flex;
  gap: 2px;
  margin-left: 4px;
}

.chrome-btn {
  width: 36px;
  height: 28px;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  line-height: 1;
}

.chrome-btn:hover {
  background: #f3f4f6;
  color: var(--text);
}

.chrome-btn--close:hover {
  background: var(--danger);
  color: #fff;
}

/* —— 按钮 —— */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 30px;
  padding: 6px 12px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 500;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-secondary);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.btn:hover:not(:disabled) {
  background: #f9fafb;
  border-color: var(--border-strong);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn--sm {
  min-height: 28px;
  padding: 0 10px;
  font-size: 12px;
}

.btn--outline {
  background: transparent;
}

.btn--primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.btn--primary:hover:not(:disabled) {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
}

.btn--success {
  background: var(--success);
  border-color: var(--success);
  color: #fff;
}

.btn--success:hover:not(:disabled) {
  background: var(--success-hover);
  border-color: var(--success-hover);
}

.btn--block {
  width: 100%;
}

.btn-row--3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
}

.btn-row--3 .btn {
  font-size: 11px;
  padding: 6px 8px;
  white-space: nowrap;
}

.btn--process {
  flex: 1;
  min-height: 36px;
  font-size: 13px;
  font-weight: 600;
  padding: 10px 22px;
}

/* —— 表单控件 —— */
.select {
  height: 28px;
  padding: 0 28px 0 8px;
  font-family: inherit;
  font-size: 12px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg-card);
  color: var(--text-secondary);
  cursor: pointer;
}

.select:hover {
  border-color: var(--primary);
}

.select--lang {
  min-width: 160px;
}

.select--thread {
  min-width: 60px;
  max-width: 70px;
  height: 30px;
  padding: 5px 24px 5px 8px;
  border-radius: var(--radius-sm);
  border-color: var(--border-strong);
}

.input {
  flex: 1;
  min-width: 0;
  height: 32px;
  padding: 8px 10px;
  font-family: inherit;
  font-size: 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--text);
}

.input:focus {
  outline: none;
  border-width: 2px;
  border-color: var(--primary);
  padding: 7px 9px;
}

/* —— 主内容 —— */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 18px;
  gap: 18px;
  min-height: 0;
}

.layout {
  display: flex;
  gap: 18px;
  align-items: stretch;
  flex: 1;
  min-height: 320px;
}

.panel--left {
  width: 380px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.panel--right {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* —— 卡片 = QGroupBox —— */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0;
  margin-top: 0;
}

.card__title {
  margin: 0;
  padding: 12px 16px 0;
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  position: relative;
}

.card__title::after {
  content: "";
  display: block;
  height: 0;
}

.card__step {
  font-weight: 600;
}

.card .btn-row,
.card .btn--block {
  margin: 20px 16px 20px;
}

.card .btn--block {
  width: calc(100% - 32px);
  box-sizing: border-box;
}

.process-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: auto;
}

.thread-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
  font-size: 11px;
  color: var(--text-secondary);
}

.thread-label {
  font-size: 11px;
}

/* —— 列表标题 —— */
.list-heading {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

/* —— 表格 —— */
/* 与 main.py custom_table_paint_event：视口居中绘制 biglogo/LOGO_BASE64，opacity 0.15，KeepAspectRatio */
.table-wrap {
  position: relative;
  flex: 1;
  min-height: 200px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: auto;
  background-color: var(--bg-card);
}

.table-wrap::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  background: url("table-watermark.png") center center / contain no-repeat;
  opacity: 0.15;
  pointer-events: none;
}

.table-wrap .data-table {
  position: relative;
  z-index: 1;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  background: transparent;
}

.data-table thead th {
  text-align: left;
  padding: 10px;
  background: #f9fafb;
  color: var(--text-secondary);
  font-weight: 600;
  border-bottom: 2px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 2;
}

.data-table tbody tr:nth-child(even) {
  background: #f9fafb;
}

.data-table tbody tr:hover {
  background: #eff6ff;
}

.data-table td {
  padding: 8px;
  border-bottom: 1px solid #f3f4f6;
  color: var(--text);
}

.cell-path {
  color: var(--text-muted);
  word-break: break-all;
  max-width: 280px;
}

.status {
  font-weight: 600;
  font-size: 13px;
}

.status--idle {
  color: var(--text-muted);
}

.status--muted {
  color: #9ca3af;
  font-weight: 500;
}

.status--loading {
  color: #f59e0b;
}

.status--ok {
  color: var(--success);
}

.status--err {
  color: var(--danger);
}

/* —— 进度条 —— */
.bottom-bar {
  flex-shrink: 0;
}

.progress {
  position: relative;
  height: 28px;
  border-radius: var(--radius-sm);
  background: #f3f4f6;
  overflow: hidden;
}

.progress__fill {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  background: linear-gradient(90deg, #2563eb, #3b82f6);
  border-radius: var(--radius-sm);
  transition: width 0.35s ease;
}

.progress__text {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  font-weight: 500;
  color: var(--text-secondary);
  font-size: 12px;
  mix-blend-mode: multiply;
}

/* —— 页脚 —— */
.footer {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 5px;
  margin-top: -6px;
}

.footer__text {
  margin: 0;
  font-size: 12px;
  color: var(--text-muted);
}

.footer__text a {
  color: var(--primary);
  text-decoration: none;
  font-weight: 500;
}

.footer__text a:hover {
  text-decoration: underline;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* —— 水印区域编辑器弹窗 —— */
.mask-modal {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  box-sizing: border-box;
}

.mask-modal[hidden] {
  display: none !important;
}

.mask-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.48);
}

.mask-modal__panel {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  max-width: min(96vw, 1100px);
  max-height: 92vh;
  width: 100%;
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.18);
  overflow: hidden;
}

.mask-modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.mask-modal__title {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

.mask-modal__close {
  border: none;
  background: transparent;
  font-size: 18px;
  cursor: pointer;
  color: var(--text-muted);
  line-height: 1;
  padding: 4px 10px;
  border-radius: var(--radius-sm);
}

.mask-modal__close:hover {
  background: #f3f4f6;
  color: var(--text);
}

.mask-modal__hint {
  margin: 0;
  padding: 8px 16px;
  font-size: 12px;
  line-height: 1.5;
  color: #b45309;
  background: #fef3c7;
  border-bottom: 1px solid #fde68a;
  flex-shrink: 0;
}

.mask-modal__toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  flex-shrink: 0;
}

.mask-modal__zoom-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-secondary);
}

.mask-modal__zoom-label input[type="range"] {
  width: 140px;
}

.mask-modal__zoom-pct {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  min-width: 40px;
}

.mask-modal__stage {
  flex: 1;
  min-height: 200px;
  overflow: auto;
  background: #1f2937;
  padding: 12px;
}

.mask-modal__zoom-inner {
  display: inline-block;
  vertical-align: top;
  isolation: isolate;
}

.mask-modal__img-wrap {
  position: relative;
  display: inline-block;
  max-width: 100%;
  line-height: 0;
  /* 整块预览区接收指针，避免子层叠顺序在部分浏览器下吞掉事件 */
  touch-action: none;
}

.mask-modal__img-wrap img {
  display: block;
  position: relative;
  z-index: 0;
  max-width: 100%;
  max-height: min(65vh, 720px);
  width: auto;
  height: auto;
  user-select: none;
  /* 必须让点击落在 canvas 上，否则部分浏览器会先命中 img，导致无法拖拽绘制 */
  pointer-events: none;
}

/* 用 DOM 叠层画选区，避免部分浏览器在 transform:scale 下 canvas 合成异常导致「看不见框」 */
.mask-modal__overlay-root {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 3;
  box-sizing: border-box;
  overflow: visible;
  cursor: crosshair;
  touch-action: none;
  pointer-events: auto;
}

.mask-modal__rect {
  position: absolute;
  box-sizing: border-box;
  border: 3px solid #b91c1c;
  background: rgba(220, 38, 38, 0.52);
  box-shadow:
    0 0 0 2px rgba(255, 255, 255, 0.95),
    inset 0 0 0 1px rgba(255, 255, 255, 0.5);
  pointer-events: none;
}

.mask-modal__rect--selected {
  border-color: #1d4ed8;
  background: rgba(37, 99, 235, 0.52);
}

.mask-modal__rect--draft {
  border-style: dashed;
  border-color: #dc2626;
  background: rgba(239, 68, 68, 0.38);
}

.mask-modal__footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

body.mask-modal--open {
  overflow: hidden;
}

.data-table tbody tr.data-table__row--selected {
  background: rgba(37, 99, 235, 0.08);
}

.data-table tbody tr.data-table__row--selected td {
  border-color: rgba(37, 99, 235, 0.2);
}

/* —— 响应式：窄屏堆叠 —— */
@media (max-width: 1024px) {
  .layout {
    flex-direction: column;
    min-height: 0;
    gap: 12px;
  }
  .panel--left,
  .panel--right {
    width: 100%;
    min-width: 0;
  }
  .btn-row--3 {
    grid-template-columns: 1fr;
  }
  .title-bar__actions .window-chrome {
    display: none;
  }
  .main-content {
    padding: 12px 12px;
    gap: 12px;
  }
}

/* —— 移动端（手机）：全宽、防溢出、触控与表格横滑 —— */
@media (max-width: 1024px) {
  .main-content {
    padding: 16px 12px 16px;
    gap: 12px;
  }

  .layout {
    gap: 12px;
  }
}

@media (max-width: 640px) {
  .main-content {
    padding: 10px 10px 14px;
    gap: 10px;
  }

  .title-bar {
    min-height: 88px;
    padding: 16px 14px;
  }

  .title-bar__brand {
    width: 100%;
    gap: 10px;
    justify-content: flex-start;
  }

  .title-bar .logo-mark {
    display: flex;
    width: 42px;
    height: 42px;
  }

  .title-bar__title {
    font-size: 16px;
    line-height: 1.35;
  }

  .title-bar__subtitle {
    margin-top: 4px;
    font-size: 11px;
  }

  .select--lang {
    min-width: 0;
    max-width: 100%;
    flex: 1 1 auto;
    height: 40px;
    font-size: 14px;
    padding: 0 32px 0 10px;
  }

  .chrome-btn {
    min-width: 44px;
    min-height: 40px;
  }

  .card__title {
    padding: 10px 12px 0;
    font-size: 13px;
  }

  .card .btn-row {
    margin: 14px 12px 16px;
  }

  /* 避免 width:100% 与左右 margin 叠加导致撑破卡片 */
  .card .btn--block {
    display: flex;
    width: calc(100% - 24px);
    margin: 14px 12px 16px;
    box-sizing: border-box;
    white-space: normal;
    text-align: center;
    line-height: 1.4;
    word-break: break-word;
    overflow-wrap: anywhere;
    min-height: 44px;
    padding: 10px 12px;
  }

  .btn-row--3 {
    gap: 8px;
  }

  .btn-row--3 .btn {
    white-space: normal;
    min-height: 44px;
    padding: 10px 10px;
    font-size: 13px;
    line-height: 1.3;
    word-break: break-word;
  }

  .process-row {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
    margin-top: 12px;
  }

  .btn--process {
    flex: none;
    width: 100%;
    min-height: 48px;
    font-size: 14px;
    padding: 12px 16px;
  }

  .thread-wrap {
    width: 100%;
    justify-content: space-between;
    padding: 0 2px;
    font-size: 13px;
  }

  .select--thread {
    height: 40px;
    min-width: 72px;
    font-size: 14px;
  }

  .list-heading {
    font-size: 13px;
    line-height: 1.35;
  }

  .panel--right {
    min-height: 160px;
  }

  .table-wrap {
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
  }

  /* 略宽于小屏视口，触发横向滚动，列宽更可读 */
  .data-table {
    min-width: 520px;
    font-size: 12px;
  }

  .data-table thead th,
  .data-table td {
    padding: 10px 8px;
  }

  .cell-path {
    max-width: none;
    word-break: break-all;
  }

  .progress {
    height: 36px;
  }

  .progress__text {
    font-size: 11px;
    padding: 0 6px;
    text-align: center;
  }

  .btn {
    min-height: 40px;
  }

  .mask-modal {
    padding: 8px;
    align-items: flex-end;
  }

  .mask-modal__panel {
    max-height: 96vh;
    border-radius: var(--radius) var(--radius) 0 0;
  }

  .mask-modal__toolbar {
    gap: 8px;
  }

  .mask-modal__zoom-label input[type="range"] {
    width: min(120px, 40vw);
  }

  /* 不再强制整屏高度，让文档自然增高，页脚可完整滚入视区 */
  .app-shell {
    min-height: 0;
  }
}
