/*
 * Document canvas visuals for the online document tools page.
 *
 * Web-only: loaded by webtranslate.html after webtranslate.css. Renders a
 * floating paper sheet (docx) or a spreadsheet grid (xlsx) on a dark stage,
 * with a sweep animation as each translation lands.
 */

.tc-canvas {
  display: flex;
  flex-direction: column;
  height: calc(100dvh - var(--tc-wt-topbar-h) - 56px);
  min-height: 420px;
  border-radius: 18px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.06);
  background:
    radial-gradient(1200px 600px at 50% -10%, rgba(56, 132, 255, 0.16), transparent 62%),
    linear-gradient(180deg, #1b2130 0%, #141924 100%);
  box-shadow:
    0 40px 80px -40px rgba(9, 14, 26, 0.6),
    0 2px 0 rgba(255, 255, 255, 0.05) inset;
}

/* ---------- toolbar ---------- */

.tc-canvas-bar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
  background: rgba(255, 255, 255, 0.03);
}
.tc-canvas-file {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.86);
}

.tc-seg {
  flex: 0 0 auto;
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.09);
}
.tc-seg button {
  appearance: none;
  border: 0;
  background: transparent;
  cursor: pointer;
  padding: 5px 15px;
  border-radius: 999px;
  font: 500 12.5px/1 inherit;
  color: rgba(255, 255, 255, 0.6);
  transition: color 0.18s, background 0.18s;
}
.tc-seg button:hover:not(.is-on):not([disabled]) { color: rgba(255, 255, 255, 0.9); }
.tc-seg button.is-on {
  color: #0e1420;
  font-weight: 650;
  background: linear-gradient(180deg, #fff, #e8eef7);
  box-shadow: 0 2px 6px -2px rgba(0, 0, 0, 0.5);
}
.tc-seg button[disabled] { opacity: 0.3; cursor: not-allowed; }
.tc-seg button:focus-visible { outline: 2px solid #7cc0ff; outline-offset: 2px; }

/* ---------- officecli full-fidelity render ("原版") ---------- */

/* The iframe scrolls itself, so this pane replaces .tc-canvas-scroll rather
   than nesting inside it. */
.tc-canvas-render {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.tc-canvas:not([data-layout="translate-render"]) .tc-canvas-render { display: none; }

/* Document translation: both 原版 and 译文 use the officecli iframe pane. */
.tc-canvas[data-layout="translate-render"] .tc-canvas-scroll { display: none; }
.tc-canvas[data-layout="translate-render"] .tc-canvas-render { display: flex; }

.tc-canvas-frame {
  flex: 1 1 auto;
  width: 100%;
  border: 0;
  background: #f0f0f0;
  display: block;
}

/* ---------- scroll area ---------- */

.tc-canvas-scroll {
  flex: 1 1 auto;
  overflow: auto;
  padding: 34px 24px 40px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.18) transparent;
  -webkit-overflow-scrolling: touch;
}
.tc-canvas-scroll::-webkit-scrollbar { width: 10px; height: 10px; }
.tc-canvas-scroll::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.16);
  border-radius: 999px;
  border: 3px solid transparent;
  background-clip: content-box;
}
.tc-canvas-scroll::-webkit-scrollbar-thumb:hover { background-color: rgba(255, 255, 255, 0.26); }

.tc-canvas-foot {
  margin: 22px auto 0;
  max-width: 760px;
  text-align: center;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.38);
}
.tc-canvas-empty {
  padding: 60px 20px;
  text-align: center;
  font-size: 14px;
  color: rgba(255, 255, 255, 0.45);
}

.tc-btn.tc-canvas-download {
  display: flex;
  width: min(760px, 100%);
  margin: 18px auto 0;
  height: auto;
  min-height: 46px;
  font-size: 15px;
  font-weight: 600;
  border-radius: 12px;
  background: linear-gradient(135deg, #0e9a54, #14b866);
  border-color: transparent;
  color: #fff;
}
.tc-btn.tc-canvas-download:hover { filter: brightness(1.06); background: linear-gradient(135deg, #0e9a54, #14b866); }

/* ---------- paper sheet (docx) ---------- */

.tc-paper {
  width: min(780px, 100%);
  margin: 0 auto;
  padding: 62px 70px 76px;
  border-radius: 4px;
  background: #fff;
  color: #1a1d23;
  box-shadow:
    0 1px 2px rgba(0, 0, 0, 0.28),
    0 24px 48px -16px rgba(0, 0, 0, 0.45),
    0 60px 120px -50px rgba(0, 0, 0, 0.6);
  transition: opacity 0.18s ease, transform 0.18s ease;
}
.tc-paper.is-swapping,
.tc-grid-wrap.is-swapping { opacity: 0.35; transform: scale(0.995); }

.tc-para {
  position: relative;
  margin: 0 0 1.05em;
  transition: opacity 0.35s ease;
}
.tc-para p { margin: 0; }

.tc-para[data-role="body"] p {
  font: 400 15.5px/1.95 "Songti SC", "SimSun", "Noto Serif SC", Georgia, serif;
  text-align: justify;
  text-indent: 2em;
  hyphens: auto;
  color: #22262e;
}
.tc-para[data-role="h1"] p {
  font: 700 26px/1.4 "Source Han Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
  text-align: center;
  text-indent: 0;
  margin: 6px 0 30px;
  letter-spacing: 0.01em;
  color: #0f1218;
}
.tc-para[data-role="h2"] p {
  font: 650 18px/1.5 "Source Han Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
  text-indent: 0;
  margin: 28px 0 12px;
  color: #10131a;
}

/* View switching is a pure attribute flip — both texts are always in the DOM. */
.tc-canvas[data-view="target"] .tc-para-s { display: none; }
.tc-canvas[data-view="source"] .tc-para-t { display: none; }
.tc-canvas[data-view="split"] .tc-para {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 34px;
}
.tc-canvas[data-view="split"] .tc-para::after {
  content: "";
  position: absolute;
  inset: 0 auto 0 50%;
  border-left: 1px solid rgba(0, 0, 0, 0.07);
}
.tc-canvas[data-view="split"] .tc-para-s { color: #7b828e; }

/* Not-yet-translated paragraphs recede until their text arrives. */
.tc-canvas[data-view="target"] .tc-para:not(.is-done),
.tc-canvas[data-view="split"] .tc-para:not(.is-done) { opacity: 0.42; }
.tc-canvas[data-view="target"] .tc-para:not(.is-done) .tc-para-t::after,
.tc-canvas[data-view="split"] .tc-para:not(.is-done) .tc-para-t::after {
  content: "…";
  color: #b9c0cb;
}

/* ---------- translation-lands animation ---------- */

@keyframes tc-sweep {
  0% { background-position: -140% 0; }
  100% { background-position: 240% 0; }
}
@keyframes tc-settle {
  0% { opacity: 0; transform: translateY(5px); filter: blur(2px); }
  100% { opacity: 1; transform: none; filter: none; }
}

.tc-para.is-new .tc-para-t {
  animation: tc-settle 0.42s cubic-bezier(0.22, 0.61, 0.36, 1) both;
}
.tc-para.is-new {
  border-radius: 3px;
  background-image: linear-gradient(
    100deg,
    transparent 0%,
    rgba(56, 132, 255, 0) 32%,
    rgba(56, 132, 255, 0.16) 46%,
    rgba(120, 190, 255, 0.26) 52%,
    rgba(56, 132, 255, 0.14) 58%,
    transparent 78%
  );
  background-size: 220% 100%;
  background-repeat: no-repeat;
  animation: tc-sweep 0.85s cubic-bezier(0.4, 0, 0.2, 1) 1;
}
.tc-para.is-new::before {
  content: "";
  position: absolute;
  left: -18px;
  top: 2px;
  bottom: 2px;
  width: 2px;
  border-radius: 2px;
  background: linear-gradient(180deg, #38bdf8, #2f6fed);
  box-shadow: 0 0 10px rgba(56, 132, 255, 0.7);
  animation: tc-settle 0.3s ease both;
}

/* ---------- spreadsheet grid (xlsx) ---------- */

.tc-grid-wrap {
  width: min(1180px, 100%);
  margin: 0 auto;
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
  box-shadow: 0 24px 48px -18px rgba(0, 0, 0, 0.5), 0 1px 2px rgba(0, 0, 0, 0.3);
  transition: opacity 0.18s ease, transform 0.18s ease;
}
.tc-grid-scroll {
  max-height: min(66vh, 620px);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}
.tc-grid {
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13px;
  width: 100%;
  color: #1e222a;
}
.tc-grid td,
.tc-grid th {
  border-right: 1px solid #e3e6ea;
  border-bottom: 1px solid #e3e6ea;
  padding: 6px 10px;
  min-width: 96px;
  max-width: 300px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: middle;
  text-align: left;
}
.tc-grid thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  height: 26px;
  padding: 0;
  text-align: center;
  font: 600 11px/26px ui-monospace, "SF Mono", Menlo, monospace;
  color: #5c6470;
  background: linear-gradient(180deg, #f6f7f9, #eceef2);
  border-bottom: 1px solid #cdd2d9;
}
.tc-grid .rn {
  position: sticky;
  left: 0;
  z-index: 1;
  width: 48px;
  min-width: 48px;
  text-align: center;
  font: 500 11px/1 ui-monospace, "SF Mono", Menlo, monospace;
  color: #5c6470;
  background: linear-gradient(90deg, #f6f7f9, #eceef2);
  border-right: 1px solid #cdd2d9;
}
.tc-grid thead .rn { z-index: 3; }
.tc-grid tbody tr:hover td:not(.rn) { background: rgba(56, 132, 255, 0.05); }

.tc-grid td .c-s { display: none; }
.tc-canvas[data-view="source"] .tc-grid td .c-t { display: none; }
.tc-canvas[data-view="source"] .tc-grid td .c-s { display: inline; }
/* Two full spreadsheets side by side are unreadable at rail width, so the
   comparison view stacks source under target inside each cell. */
.tc-canvas[data-view="split"] .tc-grid td { white-space: normal; }
.tc-canvas[data-view="split"] .tc-grid td .c-t { display: block; }
.tc-canvas[data-view="split"] .tc-grid td .c-s {
  display: block;
  margin-top: 3px;
  padding-top: 3px;
  border-top: 1px dashed #dfe3e8;
  color: #858c98;
  font-size: 12px;
}

@keyframes tc-cell-pop {
  0% { background: rgba(56, 132, 255, 0.22); }
  100% { background: transparent; }
}
.tc-grid td.is-new {
  animation: tc-cell-pop 0.7s ease 1;
  box-shadow: inset 0 0 0 2px rgba(56, 132, 255, 0.55);
}

.tc-sheet-tabs {
  display: flex;
  gap: 2px;
  padding: 6px 8px;
  background: #eceef2;
  border-top: 1px solid #cdd2d9;
  overflow-x: auto;
  scrollbar-width: none;
}
.tc-sheet-tabs::-webkit-scrollbar { display: none; }
.tc-sheet-tabs button {
  flex: 0 0 auto;
  appearance: none;
  border: 0;
  background: transparent;
  padding: 6px 14px;
  font: 500 12px/1 inherit;
  color: #5c6470;
  cursor: pointer;
  border-radius: 5px 5px 0 0;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tc-sheet-tabs button.is-on {
  background: #fff;
  color: #10131a;
  font-weight: 650;
  box-shadow: 0 -1px 0 #cdd2d9 inset;
}

/* ---------- skeleton ---------- */

@keyframes tc-skel-pulse {
  0%, 100% { opacity: 0.45; }
  50% { opacity: 0.85; }
}
.tc-skel {
  width: min(780px, 100%);
  margin: 0 auto;
  border-radius: 4px;
  background: #fff;
  padding: 62px 70px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  box-shadow: 0 24px 48px -16px rgba(0, 0, 0, 0.45);
}
.tc-skel--grid { width: min(1180px, 100%); padding: 24px; gap: 10px; }
.tc-skel-bar {
  height: 13px;
  border-radius: 4px;
  background: linear-gradient(90deg, #eef1f5, #e2e7ee, #eef1f5);
  animation: tc-skel-pulse 1.4s ease-in-out infinite;
}
.tc-skel--grid .tc-skel-bar { height: 22px; width: 100%; }

/* ---------- img2x: source image gallery ---------- */

.tc-image-gallery {
  width: min(1180px, 100%);
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
  padding: 4px;
}
.tc-image-gallery-item {
  display: flex;
  flex-direction: column;
  gap: 8px;
  border-radius: 8px;
  background: #fff;
  padding: 10px;
  box-shadow: 0 8px 24px -8px rgba(0, 0, 0, 0.35);
}
.tc-image-gallery-img {
  display: block;
  width: 100%;
  max-height: min(52vh, 520px);
  object-fit: contain;
  border-radius: 4px;
  background: #f4f6f9;
}
.tc-image-gallery-cap {
  font-size: 12px;
  line-height: 1.4;
  color: #6b7280;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- pdf2x: source PDF preview (match .tc-grid-wrap layout) ---------- */

.tc-pdf-gallery {
  width: min(1180px, 100%);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
  box-shadow: 0 24px 48px -18px rgba(0, 0, 0, 0.5), 0 1px 2px rgba(0, 0, 0, 0.3);
}
.tc-pdf-gallery-item {
  display: flex;
  flex-direction: column;
  margin: 0;
}
.tc-pdf-gallery-frame {
  display: block;
  width: 100%;
  height: min(66vh, 620px);
  border: 0;
  background: #fff;
}
.tc-pdf-gallery-cap {
  padding: 8px 12px 10px;
  font-size: 12px;
  line-height: 1.4;
  color: #6b7280;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  border-top: 1px solid #e3e6ea;
}

/* ---------- responsive ---------- */

@media (max-width: 1099px) {
  .tc-canvas {
    height: auto;
    max-height: min(78vh, 720px);
    min-height: 320px;
  }
  .tc-paper { padding: 40px 32px 48px; }
  .tc-skel { padding: 40px 32px; }
}

@media (max-width: 640px) {
  .tc-canvas-bar { flex-wrap: wrap; gap: 8px 10px; padding: 10px 12px; }
  .tc-canvas-file { flex: 1 0 100%; }
  .tc-canvas-scroll { padding: 18px 12px 28px; }
  .tc-paper { padding: 28px 20px 34px; border-radius: 3px; }
  .tc-skel { padding: 28px 20px; }
  .tc-para[data-role="body"] p { font-size: 15px; line-height: 1.85; }
  .tc-para[data-role="h1"] p { font-size: 21px; }
  .tc-para[data-role="h2"] p { font-size: 16.5px; }
  /* Two columns at phone width is unreadable — stack the comparison instead. */
  .tc-canvas[data-view="split"] .tc-para { grid-template-columns: 1fr; gap: 4px; }
  .tc-canvas[data-view="split"] .tc-para::after { display: none; }
  .tc-canvas[data-view="split"] .tc-para-s {
    padding-bottom: 4px;
    border-bottom: 1px dashed #e2e5ea;
    font-size: 13.5px;
  }
  .tc-grid td, .tc-grid th { min-width: 82px; max-width: 190px; }
}

@media (prefers-reduced-motion: reduce) {
  .tc-para.is-new,
  .tc-para.is-new .tc-para-t,
  .tc-para.is-new::before,
  .tc-grid td.is-new,
  .tc-skel-bar {
    animation: none !important;
  }
  .tc-para.is-new { background-image: none; }
  .tc-grid td.is-new { box-shadow: inset 0 0 0 2px rgba(56, 132, 255, 0.4); }
}
