/* ==========================================================================
   CTSS Shared Motion & Micro-Interaction Layer
   Dùng chung cho cả 3 cổng: Phụ huynh (portal), Nhà trường (app.), Vận hành (ops.)
   ========================================================================== */

:root {
  --ctss-ease: cubic-bezier(0.16, 1, 0.3, 1);
  --ctss-spring: cubic-bezier(0.34, 1.42, 0.64, 1);
  --ctss-bar-color: var(--accent, #2563eb);
}

[data-theme="dark"] {
  --ctss-bar-color: #3b82f6;
}

/* ---------- 1. Cross-Document View Transitions ---------- */
@view-transition {
  navigation: auto;
}

::view-transition-old(root),
::view-transition-new(root) {
  animation-duration: 140ms;
  animation-timing-function: var(--ctss-ease);
}

/* ---------- 2. Bỏ hoàn toàn đường gạch chân khi hover menu & điều hướng ---------- */
.nav a,
.nav a:hover,
.nav a:focus,
.nav a:focus-visible,
.ops-nav a,
.ops-nav a:hover,
.ops-nav a:focus,
nav a,
nav a:hover,
nav a:focus,
.top a,
.top a:hover,
.ops-topbar a,
.ops-topbar a:hover,
.brand,
.brand:hover,
.ops-brand,
.ops-brand:hover,
.lc-header a,
.lc-header a:hover,
.lc-header a:focus,
.lc-brand,
.lc-brand:hover,
.lc-user-chip,
.lc-user-chip:hover,
.lc-cta-pill,
.lc-cta-pill:hover,
.lc-logout-pill,
.lc-logout-pill:hover,
.pt-ft-school,
.pt-ft-school:hover,
.report-subnav a,
.report-subnav a:hover,
.ops-tabs a,
.ops-tabs a:hover,
.ops-vtabs a,
.ops-vtabs a:hover,
.exam-step,
.exam-step:hover,
.news-tabs a,
.news-tabs a:hover,
.child-pill,
.child-pill:hover,
.auth-tab,
.auth-tab:hover,
.user-menu-item,
.user-menu-item:hover,
.combo-list a,
.combo-list a:hover,
.news-item,
.news-item:hover,
[role="navigation"] a,
[role="navigation"] a:hover,
[role="menubar"] a,
[role="menubar"] a:hover,
[role="menuitem"],
[role="menuitem"]:hover,
[role="tablist"] a,
[role="tablist"] a:hover,
[role="tab"],
[role="tab"]:hover {
  text-decoration: none !important;
}

/* ---------- 3. Thanh tiến độ tức thì ở đỉnh màn hình (#ctss-topbar) ---------- */
#ctss-topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 2.5px;
  z-index: 9999;
  pointer-events: none;
  opacity: 0;
  transition: opacity 180ms ease;
}

#ctss-topbar.is-active {
  opacity: 1;
}

#ctss-topbar > i {
  display: block;
  width: 100%;
  height: 100%;
  transform-origin: left center;
  transform: scaleX(var(--p, 0));
  transition: transform 180ms var(--ctss-ease);
  background: linear-gradient(90deg, var(--ctss-bar-color), #38bdf8, var(--ctss-bar-color));
  box-shadow: 0 0 10px color-mix(in srgb, var(--ctss-bar-color) 65%, transparent), 0 0 3px var(--ctss-bar-color);
}

#ctss-topbar.is-done {
  opacity: 0;
  transition: opacity 220ms ease 80ms;
}

/* ---------- 4. Hiệu ứng Click vật lý & Gợn sóng ánh sáng (Ripple) ---------- */
.ctss-rel {
  position: relative !important;
}

.ctss-ripple-wrap {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  overflow: hidden;
  pointer-events: none;
  z-index: 0;
}

.ctss-ripple {
  position: absolute;
  left: var(--rx, 50%);
  top: var(--ry, 50%);
  width: var(--rd, 120px);
  height: var(--rd, 120px);
  border-radius: 50%;
  pointer-events: none;
  background: color-mix(in srgb, var(--ctss-bar-color) 24%, rgba(15, 23, 42, 0.12));
  transform: translate(-50%, -50%) scale(0);
  opacity: 0.34;
  animation: ctss-ripple-anim 440ms var(--ctss-ease) forwards;
}

.ctss-ripple.is-light {
  background: rgba(255, 255, 255, 0.36);
  opacity: 0.4;
}

@keyframes ctss-ripple-anim {
  0% {
    transform: translate(-50%, -50%) scale(0);
    opacity: 0.36;
  }
  100% {
    transform: translate(-50%, -50%) scale(1);
    opacity: 0;
  }
}

/* Phản hồi độ nảy khi nhấn chuột / chạm tay */
.btn,
.lc-cta-pill,
.lc-logout-pill,
.lc-user-chip,
.news-tabs a,
.child-pill,
.auth-tab,
.seg-tabs button,
.seg button,
.phone-chip,
.lc-id-save,
.lc-id-cancel,
.pwd-toggle,
.nav a,
.ops-nav a,
.report-subnav a,
.ops-tabs a,
.ops-vtabs a,
.user-menu-item,
.exam-step,
a.kpi,
a.stat,
a.school-row,
.news-item,
.icon-btn,
.ibtn,
.lc-fab-btn {
  transition-property: background-color, border-color, color, box-shadow, transform, opacity, filter;
  transition-duration: 165ms;
  transition-timing-function: var(--ctss-spring);
}

.btn:not(:disabled):not([disabled]):not(.is-loading):not(.htmx-request):active,
.lc-cta-pill:active,
.lc-logout-pill:active,
.lc-user-chip:active,
.news-tabs a:active,
.child-pill:active,
.auth-tab:active,
.seg-tabs button:active,
.seg button:active,
.phone-chip:active,
.lc-id-save:active,
.lc-id-cancel:active,
.pwd-toggle:active {
  transform: scale(0.965);
  transition-duration: 65ms;
}

.nav a:active,
.ops-nav a:active,
.report-subnav a:active,
.ops-tabs a:active,
.ops-vtabs a:active,
.user-menu-item:active,
.exam-step:active,
a.kpi:active,
a.stat:active,
a.school-row:active,
.news-item:active {
  transform: scale(0.985);
  transition-duration: 65ms;
}

.icon-btn:active,
.ibtn:active,
.lc-fab-btn:active {
  transform: scale(0.91);
  transition-duration: 65ms;
}

/* ---------- 5. Phản hồi Menu / Tab tức thì trước khi tải xong trang mới ---------- */
.nav:has(a.is-pending-nav) a.on:not(.is-pending-nav) {
  background: transparent;
  color: var(--side-text);
  box-shadow: none;
}

.nav a.is-pending-nav {
  background: var(--side-on);
  color: var(--side-on-text);
  font-weight: 600;
}

.ops-nav:has(a.is-pending-nav) a.active:not(.is-pending-nav) {
  background: transparent;
  color: var(--side-ink);
}

.ops-nav a.is-pending-nav {
  background: #2563eb;
  color: #fff;
  font-weight: 600;
}

.report-subnav a.is-pending-nav {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

[data-theme="dark"] .report-subnav a.is-pending-nav {
  background: var(--side-active);
  color: var(--text);
}

.ops-tabs a.is-pending-nav {
  color: var(--accent) !important;
  border-color: var(--accent);
  font-weight: 600;
}

.ops-vtabs a.is-pending-nav {
  background: var(--accent-soft);
  color: var(--accent) !important;
  font-weight: 600;
}

.news-tabs a.is-pending-nav {
  background: var(--accent);
  color: #fff;
}

.child-pill.is-pending-nav {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

.exam-step.is-pending-nav {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 7%, var(--surface));
}

a.kpi.is-pending-nav {
  border-color: var(--kc, var(--accent)) !important;
  background: color-mix(in srgb, var(--kc, var(--accent)) 7%, var(--surface));
}

/* ---------- 6. Trạng thái Loading trên nút bấm ---------- */
.btn.is-loading,
button.btn.htmx-request,
a.btn.htmx-request,
.lc-logout-pill.is-loading,
.lc-id-save.is-loading {
  pointer-events: none;
  cursor: progress;
  opacity: 0.9;
}

.btn.is-loading::before,
button.btn.htmx-request::before,
a.btn.htmx-request::before,
.lc-logout-pill.is-loading::before,
.lc-id-save.is-loading::before {
  content: "";
  display: inline-block;
  width: 15px;
  height: 15px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  flex: none;
  animation: ctss-spin 0.58s linear infinite;
}

.btn-sm.is-loading::before,
.btn.sm.is-loading::before,
.btn-sm.htmx-request::before,
.btn.sm.htmx-request::before,
.lc-logout-pill.is-loading::before,
.lc-id-save.is-loading::before {
  width: 13px;
  height: 13px;
}

.btn.is-loading > svg.i:first-child,
button.btn.htmx-request > svg.i:first-child,
a.btn.htmx-request > svg.i:first-child,
.lc-logout-pill.is-loading > svg.i:first-child {
  display: none;
}

@keyframes ctss-spin {
  to {
    transform: rotate(360deg);
  }
}

/* ---------- 7. HTMX Busy Shimmer & Swap Animations ---------- */
.ctss-htmx-busy {
  opacity: 0.62;
  transition: opacity 140ms ease;
}

.ctss-htmx-busy:not(tr):not(span)::after {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  border-radius: 2px;
  pointer-events: none;
  background: linear-gradient(90deg, transparent, var(--ctss-bar-color), #38bdf8, transparent);
  background-size: 200% 100%;
  animation: ctss-shimmer 0.9s linear infinite;
}

@keyframes ctss-shimmer {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

.search-wrap.is-searching::after {
  content: "";
  position: absolute;
  right: 12px;
  top: 50%;
  width: 14px;
  height: 14px;
  margin-top: -7px;
  border: 2px solid var(--accent, #2563eb);
  border-right-color: transparent;
  border-radius: 50%;
  pointer-events: none;
  animation: ctss-spin 0.6s linear infinite;
}

.ctss-swap-in {
  animation: ctss-fade-up 190ms var(--ctss-ease) backwards;
}

tr.ctss-row-flash td {
  animation: ctss-row-flash 750ms var(--ctss-ease);
}

@keyframes ctss-row-flash {
  0% {
    background-color: color-mix(in srgb, var(--ctss-bar-color) 13%, transparent);
  }
  100% {
    background-color: transparent;
  }
}

#draft-saved .pill {
  animation: ctss-pop-in 220ms var(--ctss-spring) backwards;
}

/* ---------- 8. Hiệu ứng xuất hiện & Micro-interactions trên cả 3 cổng ---------- */
@keyframes ctss-fade-up {
  from {
    opacity: 0;
    transform: translateY(7px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes ctss-pop-in {
  from {
    opacity: 0;
    transform: translateY(6px) scale(0.975);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes ctss-pop-br {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.94);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes ctss-bar-grow {
  from {
    transform: scaleX(0);
  }
  to {
    transform: none;
  }
}

@keyframes ctss-fade-only {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

/* Cổng Phụ huynh: nội dung chính vào mượt, không giữ transform trên container có lightbox fixed */
main.pt-wrap > :not(.lb-backdrop):not([hidden]) {
  animation: ctss-fade-up 220ms var(--ctss-ease) backwards;
}
main.pt-wrap > :nth-child(2):not(.lb-backdrop):not([hidden]) { animation-delay: 25ms; }
main.pt-wrap > :nth-child(3):not(.lb-backdrop):not([hidden]) { animation-delay: 50ms; }

/* Stagger nhẹ cho thẻ KPI, thống kê, bước quy trình, danh sách việc cần làm */
.hm-process > .hm-step,
.kpis > *,
.ops-kpis > *,
.ops-kpis-4 > *,
.ops-kpis-5 > *,
.stats > *,
.exam-stepper > *,
.todo > * {
  animation: ctss-fade-up 220ms var(--ctss-ease) backwards;
}
.hm-process > .hm-step:nth-child(2),
.kpis > :nth-child(2),
.ops-kpis > :nth-child(2),
.ops-kpis-4 > :nth-child(2),
.ops-kpis-5 > :nth-child(2),
.stats > :nth-child(2),
.exam-stepper > :nth-child(2),
.todo > :nth-child(2) { animation-delay: 25ms; }
.hm-process > .hm-step:nth-child(3),
.kpis > :nth-child(3),
.ops-kpis > :nth-child(3),
.ops-kpis-4 > :nth-child(3),
.ops-kpis-5 > :nth-child(3),
.stats > :nth-child(3),
.exam-stepper > :nth-child(3),
.todo > :nth-child(3) { animation-delay: 50ms; }
.hm-process > .hm-step:nth-child(4),
.kpis > :nth-child(4),
.ops-kpis > :nth-child(4),
.ops-kpis-4 > :nth-child(4),
.ops-kpis-5 > :nth-child(4),
.stats > :nth-child(4),
.exam-stepper > :nth-child(4),
.todo > :nth-child(4) { animation-delay: 75ms; }
.kpis > :nth-child(5),
.ops-kpis > :nth-child(5),
.ops-kpis-5 > :nth-child(5),
.todo > :nth-child(5) { animation-delay: 100ms; }
.kpis > :nth-child(n+6),
.ops-kpis > :nth-child(n+6),
.todo > :nth-child(n+6) { animation-delay: 125ms; }

/* Card đăng nhập cả 3 trang */
.login .login-card,
.ops-auth-card,
.auth-card {
  animation: ctss-pop-in 240ms var(--ctss-ease) backwards;
}

/* Thanh tiến độ tăng trưởng mượt */
.bar > i,
.ops-prog > i,
.dist-bar > i,
.hm-rc-bar > i {
  transform-origin: left center;
  animation: ctss-bar-grow 440ms var(--ctss-ease) backwards;
}

/* Hover & tương tác mượt trên Portal Phụ huynh */
.hm-step {
  transition: transform 180ms var(--ctss-ease), box-shadow 180ms var(--ctss-ease);
}
.hm-step:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
}
.hm-step-ic {
  transition: transform 180ms var(--ctss-spring);
}
.hm-step:hover .hm-step-ic {
  transform: scale(1.08);
}

.hm-resume {
  transition: transform 180ms var(--ctss-ease), box-shadow 180ms var(--ctss-ease);
}
.hm-resume:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.news-item {
  transition: background-color 150ms ease, color 150ms ease, transform 180ms var(--ctss-ease), box-shadow 180ms var(--ctss-ease);
}
.news-item .news-go {
  transition: transform 180ms var(--ctss-ease), color 150ms ease;
}
.news-item:hover .news-go {
  transform: translateX(4px);
  color: var(--accent);
}
.news-list.cards-mode .news-item:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

/* Thẻ upload học bạ đang nén/tải */
.slot-card.is-uploading {
  opacity: 0.88;
  background: linear-gradient(
    90deg,
    var(--surface-2) 25%,
    color-mix(in srgb, var(--accent-soft, #eaeffa) 85%, #fff) 50%,
    var(--surface-2) 75%
  );
  background-size: 200% 100%;
  animation: ctss-shimmer 1.1s linear infinite;
}

.check-row.is-done .check-dot {
  animation: ctss-pop-in 220ms var(--ctss-spring) backwards;
}

/* Nút tư vấn nổi & Popover */
.lc-fab-btn {
  transition: transform 180ms var(--ctss-spring), filter 180ms ease;
}
.lc-fab-btn:hover {
  transform: translateY(-3px) scale(1.03);
}
.lc-fab-popover {
  transform-origin: bottom right;
  animation: ctss-pop-br 180ms var(--ctss-spring) backwards;
}

/* Form toggle, Accordion FAQ & Fold Card */
.lc-id-edit-form,
.auth-card form,
details.fold-card[open] > .fold-bd,
.hm-faq details[open] > p {
  animation: ctss-fade-up 160ms var(--ctss-ease) backwards;
}

/* Lightbox ảnh */
#doc-lightbox:not([hidden]),
.ws-lightbox {
  animation: ctss-fade-only 160ms var(--ctss-ease);
}
#doc-lightbox:not([hidden]) #lb-img,
.ws-lightbox img {
  animation: ctss-pop-in 200ms var(--ctss-ease) backwards;
}

/* ---------- 9. Giảm chuyển động & In ấn ---------- */
@media (prefers-reduced-motion: reduce) {
  ::view-transition-old(root),
  ::view-transition-new(root) {
    animation-duration: 0.01ms !important;
  }
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  .ctss-ripple-wrap {
    display: none !important;
  }
}

@media print {
  #ctss-topbar,
  .ctss-ripple-wrap {
    display: none !important;
  }
}
