/*
 * Round 78 - Document Templates: language tabs, category sections, item tables, "Auto calculate", the free-download
 * counter and the sign-in / watermark pop-ups, plus the motion for all of it.
 *
 * Motion is decorative: everything that moves sits inside `prefers-reduced-motion: no-preference`, and content is never
 * hidden unless doc_templates.js has run (it adds .dt-anim / .is-in itself).
 *
 * RULE (same as blog_motion.css): never put a transform / filter / perspective / fill-mode animation on <body> or on an
 * ancestor of a position:fixed pop-up - it would become the containing block of the fixed element and the pop-up would open
 * off-centre. The pop-ups (.dtq-modal) are appended to <body>; only the overlay itself and its leaf box animate, and the
 * overlay animation has no fill-mode.
 */

/* ------------------------------------------------------------------ language tabs */
.dt-langtabs { display: flex; flex-wrap: wrap; gap: 8px; margin: 16px 0 2px; padding: 0; }
.dt-ltab {
  position: relative; display: inline-flex; align-items: baseline; gap: 6px; padding: 8px 14px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--card); color: var(--text); text-decoration: none; font-weight: 700; font-size: 14px; line-height: 1.2;
  transition: background .22s ease, color .22s ease, border-color .22s ease, box-shadow .22s ease, transform .22s ease;
}
.dt-ltab:hover { border-color: var(--accent); color: var(--accent); }
.dt-ltab:focus-visible { outline: 3px solid var(--tint-border, var(--accent)); outline-offset: 2px; }
.dt-ltab-e { font-weight: 500; font-size: 12px; color: var(--text-muted); }
.dt-ltab small { font-size: 11px; font-weight: 800; padding: 1px 7px; border-radius: 999px; background: var(--tint); color: var(--accent); border: 1px solid var(--tint-border); }
.dt-ltab.active { background: var(--accent); border-color: var(--accent); color: #fff; box-shadow: 0 6px 16px -6px var(--accent); }
.dt-ltab.active .dt-ltab-e { color: rgba(255, 255, 255, .85); }
.dt-ltab.active small { background: rgba(255, 255, 255, .22); border-color: rgba(255, 255, 255, .35); color: #fff; }

/* the panel (search + filters + categories) */
.dt-panel-wrap { margin-top: 14px; }
.dt-hero { margin-bottom: 14px; }
.dt-variant-note { margin: 4px 0 8px; padding: 8px 12px; border-radius: 10px; background: var(--tint); border: 1px solid var(--tint-border); font-size: 13.5px; }
.dt-empty { margin: 18px 0; padding: 16px; text-align: center; color: var(--text-muted); border: 1px dashed var(--border); border-radius: 12px; }
.dt-browse .dts-related { display: flex; flex-wrap: wrap; gap: 8px; list-style: none; padding: 0; margin: 8px 0 16px; }
.dt-browse .dts-related a { display: inline-block; padding: 6px 12px; border-radius: 999px; border: 1px solid var(--border); text-decoration: none; color: var(--text); font-size: 13.5px; transition: border-color .2s, color .2s, background .2s; }
.dt-browse .dts-related a:hover { border-color: var(--accent); color: var(--accent); background: var(--tint); }

/* ------------------------------------------------------------------ categories inside a language */
.dt-grid.dt-sections { display: block; margin: 8px 0 18px; }
.dt-cat { margin: 0 0 14px; border: 1px solid var(--border); border-radius: 14px; background: var(--card); overflow: hidden; }
.dt-cat.dt-cat-empty { display: none; }
.dt-cat-head { margin: 0; font-size: 16px; }
.dt-cat-toggle {
  width: 100%; display: flex; align-items: center; gap: 10px; padding: 12px 16px; border: 0; background: var(--surface-soft); color: var(--text);
  font: inherit; font-weight: 800; font-size: 16px; text-align: left; cursor: pointer; transition: background .2s ease;
}
.dt-cat-toggle:hover { background: var(--tint); }
.dt-cat-toggle:focus-visible { outline: 3px solid var(--tint-border, var(--accent)); outline-offset: -3px; }
.dt-cat-chev { width: 9px; height: 9px; border-right: 2.5px solid currentColor; border-bottom: 2.5px solid currentColor; transform: rotate(45deg); margin: 0 4px 3px 2px; transition: transform .28s ease; flex: none; }
.dt-collapsed .dt-cat-chev { transform: rotate(-45deg); margin-bottom: 0; }
.dt-cat-n { font-size: 11.5px; font-weight: 800; padding: 1px 8px; border-radius: 999px; background: var(--tint); color: var(--accent); border: 1px solid var(--tint-border); }
/* expand / collapse: grid rows 1fr <-> 0fr (no fixed height needed) */
.dt-cat-body { display: grid; grid-template-rows: 1fr; transition: grid-template-rows .32s ease; }
.dt-cat-inner { min-height: 0; overflow: hidden; }
.dt-collapsed .dt-cat-body { grid-template-rows: 0fr; }
.dt-collapsed .dt-cat-inner { visibility: hidden; transition: visibility 0s .32s; }
.dt-cat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 16px; padding: 16px; }

.dt-card { transition: transform .26s cubic-bezier(.2, .8, .2, 1), box-shadow .26s ease, border-color .26s ease, opacity .5s ease; }
.dt-card:hover, .dt-card:focus-visible { transform: translateY(-5px); box-shadow: var(--shadow-lg, 0 14px 30px -14px rgba(0, 0, 0, .35)); border-color: var(--accent); }
.dt-card:active { transform: translateY(-1px) scale(.992); }
.dt-card-tags { display: inline-flex; flex-wrap: wrap; gap: 5px; margin-top: auto; }
.dt-card-calc { font-size: 11px; font-weight: 800; padding: 2px 8px; border-radius: 999px; background: #fff7e6; color: #8a5a00; border: 1px solid #f1d9a6; }

/* ------------------------------------------------------------------ the free-download counter */
.dtq-chip { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; margin: 12px 0 0; padding: 9px 14px; border-radius: 12px; border: 1px solid var(--tint-border); background: var(--tint); font-size: 14px; }
.dtq-chip.hidden { display: none; }
.dtq-chip .dtq-main { font-weight: 800; }
.dtq-chip .dtq-more { display: inline-flex; flex-wrap: wrap; gap: 8px; align-items: center; color: var(--text-muted); font-size: 13px; }
.dtq-chip .dtq-timer, .dtq-timer { font-variant-numeric: tabular-nums; font-weight: 800; color: var(--accent); }
.dtq-chip .dtq-upsell { flex: 1 1 100%; font-size: 13px; color: var(--text); }
.dtq-chip .dtq-links { display: inline-flex; gap: 8px; flex-wrap: wrap; }
.dtq-chip.dtq-out { background: #fff7e6; border-color: #f1d9a6; }
.dtq-chip.dtq-unl { background: var(--success-bg, #e8f7ee); border-color: var(--success-border, #b7e4c7); }
.dtq-chip-editor { margin: 8px 0; }
.dtq-btn { display: inline-block; padding: 4px 12px; border-radius: 999px; background: var(--accent); color: #fff !important; text-decoration: none; font-weight: 700; font-size: 12.5px; transition: filter .2s ease, transform .15s ease; }
.dtq-btn:hover { filter: brightness(1.1); }
.dtq-btn:active { transform: scale(.96); }
.dtq-btn-ghost { background: transparent; color: var(--accent) !important; border: 1px solid var(--accent); }

/* ------------------------------------------------------------------ pop-ups: fixed, centred in the viewport */
.dtq-modal { position: fixed; inset: 0; z-index: 10050; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(15, 23, 42, .55); }
.dtq-modal-box { width: min(440px, 100%); max-height: calc(100vh - 32px); overflow: auto; background: var(--card, #fff); color: var(--text, #111); border-radius: 16px; border: 1px solid var(--border); box-shadow: 0 24px 60px -16px rgba(0, 0, 0, .45); }
.dtq-modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--border); background: var(--surface-soft); font-size: 17px; }
.dtq-modal-x { border: 0; background: transparent; color: var(--text-muted); font-size: 18px; width: 32px; height: 32px; border-radius: 8px; cursor: pointer; transition: background .2s, color .2s; }
.dtq-modal-x:hover { background: var(--tint); color: var(--text); }
.dtq-modal-body { padding: 16px 18px 18px; }
.dtq-lead { margin: 0 0 8px; font-weight: 700; font-size: 15.5px; }
.dtq-note { margin: 0 0 12px; color: var(--text-muted); font-size: 13.5px; }
.dtq-countdown { margin: 0 0 8px; font-size: 15px; }
.dtq-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.dtq-actions-col { flex-direction: column; }
.dtq-actions .btn { justify-content: center; text-align: center; text-decoration: none; }

/* ------------------------------------------------------------------ item tables + the Amounts box */
.dt-items { overflow: visible; }
/* each row is a small card: the text columns take a full line, the number columns (qty / price / amount) share the next one.
   The same layout on a phone and in the narrow form column of the desktop editor. */
.dt-items-t, .dt-items-t tbody { display: block; width: 100%; }
.dt-items-t thead { display: none; }
.dt-items-t tr { display: grid; grid-template-columns: repeat(auto-fit, minmax(68px, 1fr)); gap: 6px 8px; position: relative; margin: 0 0 8px; padding: 10px 40px 10px 10px; border: 1px solid var(--border); border-radius: 12px; background: var(--card); }
.dt-items-t td { display: block; padding: 0; min-width: 0; }
.dt-items-t td::before { content: attr(data-label); display: block; font-size: 11.5px; font-weight: 700; color: var(--text-muted); margin: 0 0 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dt-items-t td:not(.num):not(.n):not(.x) { grid-column: 1 / -1; }
.dt-items-t td.n { display: none; }
.dt-items-t td.x { position: absolute; top: 8px; right: 8px; }
.dt-items-t td.x::before { content: none; }
.dt-items-t td.num input { text-align: right; }
.dt-items-t input { min-width: 0; width: 100%; box-sizing: border-box; font: inherit; font-size: 14px; padding: 8px 9px; border-radius: 9px; border: 1px solid var(--border); background: var(--surface-soft); color: var(--text); transition: border-color .2s, box-shadow .2s, background .2s; }
.dt-items-t input:focus { outline: none; border-color: var(--accent); background: var(--card); box-shadow: 0 0 0 3px var(--tint); }
.dt-item-del { width: 28px; height: 28px; border-radius: 8px; border: 1px solid var(--border); background: var(--card); color: var(--text-muted); cursor: pointer; transition: color .2s, border-color .2s, background .2s, transform .15s; }
.dt-item-del:hover { color: var(--danger, #b42318); border-color: var(--danger, #b42318); background: var(--danger-bg, #fef3f2); }
.dt-item-del:active { transform: scale(.9); }
.dt-items-empty { display: block; }
.dt-items-empty td { color: var(--text-muted); font-size: 13px; padding: 8px 0; }
.dt-items-empty td::before { content: none; }
.dt-item-add { margin-top: 4px; }

.dt-calcbox { margin: 14px 0 16px; border: 1px solid var(--tint-border); border-radius: 14px; background: var(--tint); padding: 12px 14px 14px; }
.dt-calcbox-head { display: flex; flex-direction: column; gap: 2px; margin-bottom: 8px; }
.dt-calcbox-sub { font-size: 12.5px; color: var(--text-muted); }
.dt-calcbox-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.dt-calcbox-fields .dt-field { margin-bottom: 10px; }
.dt-calcbox-fields .dt-field-textarea, .dt-calcbox-fields .dt-field[data-fk$="words"] { grid-column: 1 / -1; }
.dt-calcbox-foot { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; }
.dt-calc-go { gap: 6px; transition: transform .15s ease, box-shadow .2s ease, filter .2s ease; }
.dt-calc-go:hover { box-shadow: 0 8px 18px -8px var(--accent); }
.dt-calc-go:active { transform: scale(.96); }
.dt-calc-go.is-busy { opacity: .75; cursor: progress; }
.dt-calc-small { margin-top: 6px; }
.dt-calcbox .dt-sync { margin: 0; }

/* buttons get a pressed feel everywhere on these pages */
.dt-actions .btn, .dt-lang-btn, .hub-chip, .dt-tab, .dt-tool, .dt-zoom { transition: transform .15s ease, box-shadow .2s ease, background .2s ease, color .2s ease, border-color .2s ease; }
.dt-actions .btn:active, .hub-chip:active, .dt-tab:active, .dt-tool:active, .dt-zoom:active { transform: scale(.96); }
.dt-actions .btn.is-busy { opacity: .8; cursor: progress; }

/* ------------------------------------------------------------------ mobile */
@media (max-width: 640px) {
  .dt-langtabs { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 6px; scrollbar-width: thin; -webkit-overflow-scrolling: touch; }
  .dt-ltab { flex: none; }
  .dt-cat-grid { padding: 12px; grid-template-columns: 1fr; }
  .dt-calcbox-fields { grid-template-columns: 1fr; }
  .dtq-modal-box { border-radius: 14px; }
}

/* ------------------------------------------------------------------ motion (only when the visitor has not asked for less) */
@media (prefers-reduced-motion: no-preference) {
  /* hero entrance (leaf element, no fill-mode kept after it ends) */
  .dt-anim-in { animation: dtHeroIn .55s cubic-bezier(.2, .8, .2, 1) backwards; }
  @keyframes dtHeroIn { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: none; } }

  /* tabs: the panel fades out, the new one slides in */
  .dt-panel-wrap { transition: opacity .14s ease, transform .14s ease; }
  .dt-panel-wrap.dt-panel-out { opacity: 0; transform: translateY(6px); }
  .dt-panel-wrap.dt-panel-in { animation: dtPanelIn .32s cubic-bezier(.2, .8, .2, 1) backwards; }
  @keyframes dtPanelIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

  /* card entrance with a stagger: JS adds .dt-anim to the grid and .is-in when a card scrolls into view */
  .dt-anim .dt-card:not(.is-in) { opacity: 0; transform: translateY(18px); }
  .dt-anim .dt-card.is-in { animation: dtCardIn .5s cubic-bezier(.2, .8, .2, 1) backwards; animation-delay: calc(var(--d, 0) * 45ms); }
  @keyframes dtCardIn { from { opacity: 0; transform: translateY(18px) scale(.985); } to { opacity: 1; transform: none; } }
  .dt-cat { animation: dtCatIn .45s ease backwards; animation-delay: calc(var(--ci, 0) * 60ms); }
  @keyframes dtCatIn { from { opacity: 0; } to { opacity: 1; } }

  /* the quota chip and items */
  .dtq-chip { animation: dtChipIn .4s ease backwards; }
  @keyframes dtChipIn { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
  .dt-items-row { animation: dtRowIn .28s ease backwards; animation-delay: calc(var(--i, 0) * 30ms); }
  @keyframes dtRowIn { from { opacity: 0; transform: translateX(-6px); } to { opacity: 1; transform: none; } }
  .dt-calc-flash { animation: dtFlash 1s ease; }
  @keyframes dtFlash { 0% { background: rgba(46, 83, 149, .30); } 100% { background: transparent; } }
  .dt-calcbox { animation: dtRowIn .35s ease backwards; }

  /* pop-ups: the overlay only fades (no fill-mode), the box inside rises a little */
  .dtq-modal { animation: dtqFade .2s ease; }
  .dtq-modal-box { animation: dtqRise .26s cubic-bezier(.2, .8, .2, 1); }
  @keyframes dtqFade { from { opacity: 0; } to { opacity: 1; } }
  @keyframes dtqRise { from { opacity: 0; transform: translateY(14px) scale(.98); } to { opacity: 1; transform: none; } }

  /* editor: panels slide when the Details / Page design tab changes, preview paper settles */
  .dt-tabpane { animation: dtPaneIn .3s cubic-bezier(.2, .8, .2, 1) backwards; }
  @keyframes dtPaneIn { from { opacity: 0; transform: translateX(10px); } to { opacity: 1; transform: none; } }
  .dt-preview-col { animation: dtPrevIn .45s ease backwards; }
  @keyframes dtPrevIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
}

@media (prefers-reduced-motion: reduce) {
  .dt-card, .dt-ltab, .dt-cat-chev, .dt-cat-body, .dt-panel-wrap, .dtq-btn, .dt-calc-go, .dt-actions .btn, .hub-chip, .dt-tab, .dt-tool, .dt-zoom { transition: none !important; animation: none !important; }
  .dt-card:hover, .dt-card:active, .dt-calc-go:active { transform: none; }
  .dt-field, .dt-tabpane, .dt-list-row, .dt-items-row, .dt-calcbox, .dt-calc-flash, .dtq-chip, .dtq-modal, .dtq-modal-box, .dt-anim-in, .dt-cat { animation: none !important; }
  .dt-collapsed .dt-cat-inner { transition: none; }
}
