/* ==========================================================================
   E-Portfolio smart layer (eportfolio-smart.css)
   Loaded by every page. Uses :where() so it has zero specificity: it fills
   gaps but never overrides what a page already styles.
   ========================================================================== */

:root {
  --ep-focus: #1d4ed8;
  --ep-gold: #c99a3d;
  --ep-gold-2: #f0d799;
  --ep-teal: #0f7a6c;
}

/* ---------- 1. Smoother navigation ---------- */
/* Pages cross-fade instead of flashing white (Chrome/Edge 126+; ignored elsewhere) */
@view-transition { navigation: auto; }
::view-transition-old(root), ::view-transition-new(root) { animation-duration: .18s; }

html {
  scroll-behavior: smooth;
  /* anchors and scrollIntoView stop below sticky headers */
  scroll-padding-top: calc(var(--mobile-bar-h, 0rem) + 4.5rem);
  -webkit-tap-highlight-color: transparent;
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  ::view-transition-group(*), ::view-transition-old(*), ::view-transition-new(*) { animation: none !important; }
}

/* ---------- 2. Reading progress bar (pure CSS, Chrome/Edge 115+) ---------- */
@supports (animation-timeline: scroll()) {
  @keyframes ep-progress { from { transform: scaleX(0); } to { transform: scaleX(1); } }
  html::before {
    content: "";
    position: fixed; inset: 0 0 auto 0; height: 3px;
    z-index: 2147483000; pointer-events: none;
    background: linear-gradient(90deg, var(--ep-gold), var(--ep-gold-2));
    transform-origin: 0 50%;
    animation: ep-progress linear both;
    animation-timeline: scroll(root block);
  }
  @media (prefers-reduced-motion: reduce) { html::before { display: none; } }
}

/* ---------- 3. Typography ---------- */
:where(body) { text-rendering: optimizeLegibility; -webkit-font-smoothing: antialiased; overflow-wrap: break-word; }
:where(h1, h2, h3, h4) { text-wrap: balance; }
:where(p, li, figcaption) { text-wrap: pretty; }
:where(a:not([class])) { text-underline-offset: .2em; text-decoration-thickness: 1px; }
:where(table, .badge, .count, time, output) { font-variant-numeric: tabular-nums; }
::selection { background: rgba(201, 154, 61, .35); color: inherit; }

/* ---------- 4. Focus, taps and states ---------- */
:where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
  outline: 2px solid var(--ep-focus); outline-offset: 2px;
}
:where(.navrail, #sidebar) :where(a, button):focus-visible { outline-color: var(--ep-gold-2); }
:where(button, [role="button"], a, input, select, textarea, label, summary) { touch-action: manipulation; }
:where(button:not(:disabled), [role="button"], summary) { cursor: pointer; }
:where(button, input, select, textarea):disabled { cursor: not-allowed; }
:where(button:not(:disabled), [role="button"]):active { scale: .98; }
:where(input[type="checkbox"], input[type="radio"], input[type="range"], progress) { accent-color: var(--ep-teal); }
:where(input, textarea) { caret-color: var(--ep-teal); }
:where(input, textarea)::placeholder { opacity: .7; }
[aria-busy="true"] { cursor: progress; }

/* Comfortable tap targets on touch screens */
@media (pointer: coarse) {
  :where(nav a, .navlink, .side-link, .nav-item, [role="tab"]) { min-height: 44px; }
}

/* ---------- 5. Tables ---------- */
:where(tbody tr) { transition: background-color .15s; }
@media (hover: hover) { :where(tbody tr:hover) { background-color: rgba(29, 63, 139, .05); } }
/* Sticky header row inside a scrollable table wrapper, only if the page opts in */
:where(.sticky-thead) thead th {
  position: sticky; top: 0; z-index: 1;
  background: var(--surface, #fff);
}

/* ---------- 6. Scrolling ---------- */
* { scrollbar-width: thin; scrollbar-color: rgba(100, 116, 139, .5) transparent; }
/* scrolling inside a drawer or modal never drags the page behind it */
:where(dialog, [role="dialog"], .modal, .modal-body, aside, .navrail, .sidebar) { overscroll-behavior: contain; }
dialog::backdrop { background: rgba(10, 23, 48, .55); backdrop-filter: blur(3px); }

/* ---------- 7. Print (grade sheets, registers, reports) ---------- */
@page { margin: 14mm; }
@media print {
  :where(.navrail, #sidebar, aside, nav, .app-header, #appHeader, #overlay, .toast, .no-print, button, [role="button"]) { display: none !important; }
  :where(main) { padding: 0 !important; margin: 0 !important; }
  :where(html, body) { background: #fff !important; color: #000 !important; }
  * { box-shadow: none !important; text-shadow: none !important; }
  :where(tr, img, .card, .panel, section) { break-inside: avoid; }
  :where(h1, h2, h3) { break-after: avoid; }
}

/* ---------- 8. Images & media ---------- */
:where(img) { max-width: 100%; height: auto; vertical-align: middle; }
:where(img.icon, svg.icon, [aria-hidden="true"] svg) { user-select: none; pointer-events: none; }
:where(picture, .thumb, .avatar-img) { display: inline-block; overflow: hidden; }
:where(video, iframe) { max-width: 100%; }

/* ---------- 9. Forms & content polish ---------- */
:where(fieldset) { border: 1px solid var(--line, #e3e8f0); border-radius: var(--r-sm, 10px); padding: .75rem 1rem; min-width: 0; }
:where(legend) { padding: 0 .4rem; color: var(--muted, #5d6b85); font-size: .85em; }
:where(hr) { border: none; border-top: 1px solid var(--line, #e3e8f0); margin: 1.25rem 0; }
:where(blockquote) {
  margin: 1rem 0; padding: .5rem 1rem;
  border-left: 3px solid var(--ep-gold);
  color: var(--muted, #5d6b85);
}
:where(code, kbd, samp) { font-family: ui-monospace, "SFMono-Regular", Consolas, monospace; font-size: .92em; }
:where(code) { background: rgba(100, 116, 139, .12); padding: .1em .4em; border-radius: 6px; }
:where(pre) { overflow-x: auto; padding: .85rem 1rem; border-radius: var(--r-sm, 10px); background: rgba(100, 116, 139, .08); }
:where(pre code) { background: none; padding: 0; }
:where(kbd) {
  background: var(--surface, #fff); border: 1px solid var(--line-strong, #c3cee2);
  border-bottom-width: 2px; border-radius: 6px; padding: .1em .45em;
}
:where(select) { padding-right: 1.75rem; }
:where(label) { cursor: pointer; }
:where(dl dt) { font-weight: 600; }
:where(dl dd) { margin-left: 0; color: var(--muted, #5d6b85); }

/* ---------- 10. Sticky headers ---------- */
/* Purely additive: only styles a scrolled state the page's own JS already toggles */
:where(.app-header, #appHeader).scrolled,
:where(.app-header, #appHeader)[data-scrolled="true"] {
  backdrop-filter: saturate(1.2) blur(8px);
  border-bottom: 1px solid var(--line, rgba(255,255,255,.12));
}

/* ---------- 11. Badges, pills, tags ---------- */
:where(.badge, .pill, .tag) {
  display: inline-flex; align-items: center; gap: .3em;
  padding: .15em .6em; border-radius: 999px;
  font-size: .8em; line-height: 1.6; white-space: nowrap;
}

/* ---------- 12. Empty & loading states ---------- */
@keyframes ep-shimmer { 0% { background-position: -200% 0; } 100% { background-position: 200% 0; } }
:where(.skeleton, [data-loading="true"]) {
  background: linear-gradient(90deg, rgba(100,116,139,.08) 25%, rgba(100,116,139,.16) 37%, rgba(100,116,139,.08) 63%);
  background-size: 400% 100%;
  animation: ep-shimmer 1.4s ease infinite;
  border-radius: var(--r-sm, 10px);
  color: transparent !important;
}
@media (prefers-reduced-motion: reduce) { :where(.skeleton, [data-loading="true"]) { animation: none; } }
:where(.empty-state) {
  display: flex; flex-direction: column; align-items: center; text-align: center;
  gap: .5rem; padding: 2.5rem 1rem; color: var(--muted, #5d6b85);
}

/* ---------- 13. Accessibility utilities ---------- */
:where(.sr-only) {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}
:where(.skip-link) {
  position: absolute; left: -9999px; top: auto;
  background: var(--ep-focus, #1d4ed8); color: #fff;
  padding: .6em 1em; border-radius: var(--r-sm, 10px);
  z-index: 2147483001;
}
:where(.skip-link):focus {
  left: 1rem; top: 1rem;
}

/* ---------- 14. Details / summary ---------- */
:where(summary) { list-style: none; }
:where(summary)::-webkit-details-marker { display: none; }
:where(summary)::before {
  content: "▸"; display: inline-block; margin-right: .5em;
  color: var(--ep-gold); transition: transform .15s;
}
:where(details[open] > summary)::before { transform: rotate(90deg); }

/* ---------- 15. Long text safety (emails, IDs, usernames) ---------- */
:where(.truncate) { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
:where(td, .cell, .stat, .kv-value) { overflow-wrap: anywhere; }

/* ---------- 16. Autofill fix ---------- */
:where(input):-webkit-autofill,
:where(input):-webkit-autofill:hover,
:where(input):-webkit-autofill:focus {
  -webkit-text-fill-color: var(--ink, #101828);
  box-shadow: 0 0 0 1000px var(--surface, #fff) inset;
  transition: background-color 9999s ease-in-out 0s;
}

/* ---------- 17. Dialog / modal motion ---------- */
@keyframes ep-pop-in { from { opacity: 0; transform: scale(.97); } to { opacity: 1; transform: scale(1); } }
:where(dialog[open], .modal.open, .modal[data-open="true"]) {
  animation: ep-pop-in .16s var(--ease, cubic-bezier(.2,.8,.2,1)) both;
}
@media (prefers-reduced-motion: reduce) {
  :where(dialog[open], .modal.open, .modal[data-open="true"]) { animation: none; }
}
