/*
 * BIAN Platform — UX Enhancements v1
 * Skeleton loading, micro-interactions, improved states, feedback components.
 * Complements bian-system.css (tokens defined there).
 */

/* ── 1. SKELETON LOADING ─────────────────────────────────────────────────────── */

@keyframes skeleton-shimmer {
  0%   { background-position: -400px 0; }
  100% { background-position: 400px 0; }
}

.skeleton {
  background: linear-gradient(
    90deg,
    var(--s2) 25%,
    var(--s3) 50%,
    var(--s2) 75%
  );
  background-size: 800px 100%;
  animation: skeleton-shimmer 1.4s ease-in-out infinite;
  border-radius: 6px;
}

[data-theme="light"] .skeleton {
  background: linear-gradient(
    90deg,
    #e8ecf2 25%,
    #d0d8e4 50%,
    #e8ecf2 75%
  );
  background-size: 800px 100%;
}

.skeleton-text      { height: 14px; margin-bottom: 8px; }
.skeleton-text.lg   { height: 20px; }
.skeleton-text.sm   { height: 11px; }
.skeleton-text.w-75 { width: 75%; }
.skeleton-text.w-50 { width: 50%; }
.skeleton-text.w-33 { width: 33%; }
.skeleton-card {
  background: var(--s1);
  border: 1px solid var(--b-subtle);
  border-radius: 12px;
  padding: 20px;
}
.skeleton-avatar {
  width: 40px; height: 40px;
  border-radius: 50%;
  flex-shrink: 0;
}
.skeleton-badge {
  height: 24px; width: 80px;
  border-radius: 100px;
  display: inline-block;
}
.skeleton-button {
  height: 36px; width: 120px;
  border-radius: 8px;
}
.skeleton-table-row {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr 1fr;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--b-subtle);
}

/* ── 2. LOADING OVERLAY ──────────────────────────────────────────────────────── */

.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(12,31,26,.72);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  opacity: 0;
  visibility: hidden;
  transition: opacity .25s, visibility .25s;
}
.loading-overlay.active {
  opacity: 1;
  visibility: visible;
}
.loading-spinner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}
.loading-spinner-ring {
  width: 48px; height: 48px;
  border: 3px solid var(--b-default);
  border-top-color: var(--a2);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-spinner-label {
  color: var(--t3);
  font-size: .875rem;
  letter-spacing: .04em;
}

/* ── 3. INLINE BUTTON LOADING STATE ─────────────────────────────────────────── */

.btn-loading {
  position: relative;
  pointer-events: none;
  opacity: .75;
}
.btn-loading::after {
  content: '';
  position: absolute;
  right: 12px; top: 50%;
  transform: translateY(-50%);
  width: 14px; height: 14px;
  border: 2px solid rgba(255,255,255,.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .6s linear infinite;
}
.btn-loading .btn-label { opacity: 0; }

/* ── 4. ENHANCED TOAST SYSTEM ────────────────────────────────────────────────── */

#toast-container {
  position: fixed;
  bottom: 24px; right: 24px;
  display: flex;
  flex-direction: column-reverse;
  gap: 10px;
  z-index: 10000;
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 18px;
  border-radius: 10px;
  border: 1px solid var(--b-default);
  background: var(--s1);
  box-shadow: 0 8px 32px rgba(0,0,0,.4);
  max-width: 380px;
  pointer-events: all;
  animation: toast-in .3s cubic-bezier(.34,1.56,.64,1) forwards;
  transition: opacity .2s, transform .2s;
}
.toast.removing {
  animation: toast-out .25s ease-in forwards;
}
@keyframes toast-in {
  from { transform: translateX(120%); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}
@keyframes toast-out {
  to { transform: translateX(120%); opacity: 0; }
}
.toast-icon {
  font-size: 1.1rem;
  margin-top: 1px;
  flex-shrink: 0;
}
.toast-body { flex: 1; }
.toast-title {
  font-weight: 600;
  font-size: .875rem;
  color: var(--t1);
  margin-bottom: 2px;
}
.toast-message {
  font-size: .8125rem;
  color: var(--t3);
  line-height: 1.4;
}
.toast-close {
  background: none; border: none; cursor: pointer;
  color: var(--t4); font-size: .9rem; padding: 0;
  flex-shrink: 0;
  transition: color .15s;
}
.toast-close:hover { color: var(--t2); }
/* Toast variants */
.toast-success { border-color: var(--m-border); }
.toast-success .toast-icon { color: var(--m1); }
.toast-error   { border-color: var(--r-border); }
.toast-error   .toast-icon { color: var(--r1); }
.toast-warning { border-color: var(--w-border); }
.toast-warning .toast-icon { color: var(--w1); }
.toast-info    { border-color: var(--a-border); }
.toast-info    .toast-icon { color: var(--a1); }

/* ── 5. MICRO-INTERACTIONS ────────────────────────────────────────────────────── */

/* Button press effect */
.btn:active:not(:disabled) {
  transform: scale(.97);
}

/* Card hover lift */
.card-hover {
  transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
  cursor: pointer;
}
.card-hover:hover {
  transform: translateY(-3px);
  box-shadow: 0 12px 40px rgba(0,0,0,.35);
  border-color: var(--a-border);
}
[data-theme="light"] .card-hover:hover {
  box-shadow: 0 8px 28px rgba(0,0,0,.12);
}

/* Link underline animation */
.link-animated {
  position: relative;
  text-decoration: none;
  color: var(--a1);
}
.link-animated::after {
  content: '';
  position: absolute;
  bottom: -1px; left: 0;
  width: 0; height: 1.5px;
  background: var(--a1);
  transition: width .2s ease;
}
.link-animated:hover::after { width: 100%; }

/* Input focus ring pulse */
@keyframes focus-ring-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(45,124,104,.4); }
  70%  { box-shadow: 0 0 0 6px rgba(45,124,104,0); }
  100% { box-shadow: 0 0 0 0 rgba(45,124,104,0); }
}
input:focus, textarea:focus, select:focus {
  animation: focus-ring-pulse .5s ease-out;
}

/* Copy button check animation */
.copy-btn.copied .copy-icon::before { content: "\f00c"; }
.copy-btn.copied { color: var(--m2) !important; }

/* Badge pulse for new items */
.badge-pulse {
  position: relative;
}
.badge-pulse::before {
  content: '';
  position: absolute;
  inset: -3px;
  border-radius: inherit;
  background: var(--a2);
  opacity: .25;
  animation: badge-pulse 2s ease-in-out infinite;
}
@keyframes badge-pulse {
  0%, 100% { transform: scale(1); opacity: .25; }
  50%       { transform: scale(1.15); opacity: 0; }
}

/* ── 6. IMPROVED EMPTY STATES ────────────────────────────────────────────────── */

.empty-state-v2 {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 64px 32px;
  text-align: center;
  gap: 16px;
}
.empty-state-v2 .es-icon {
  width: 72px; height: 72px;
  border-radius: 50%;
  background: var(--a-bg);
  border: 1px solid var(--a-border);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.75rem;
  color: var(--a1);
}
.empty-state-v2 .es-title {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--t2);
  margin: 0;
}
.empty-state-v2 .es-desc {
  font-size: .875rem;
  color: var(--t3);
  max-width: 320px;
  line-height: 1.6;
  margin: 0;
}
.empty-state-v2 .es-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
  margin-top: 8px;
}

/* ── 7. IMPROVED FORM VALIDATION FEEDBACK ────────────────────────────────────── */

.field-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.field-label {
  font-size: .8125rem;
  font-weight: 500;
  color: var(--t3);
}
.field-label .required-mark {
  color: var(--r2);
  margin-left: 3px;
}
.field-hint {
  font-size: .75rem;
  color: var(--t4);
}
.field-error-msg {
  font-size: .75rem;
  color: var(--r1);
  display: flex;
  align-items: center;
  gap: 5px;
}
.field-error-msg::before {
  content: "\f071";
  font-family: "Font Awesome 6 Free";
  font-weight: 900;
  font-size: .7rem;
}
.field-input.has-error {
  border-color: var(--r2) !important;
  box-shadow: 0 0 0 3px rgba(225,72,72,.15);
}
.field-input.is-valid {
  border-color: var(--m2) !important;
}

/* Character counter */
.char-counter {
  font-size: .75rem;
  color: var(--t4);
  text-align: right;
}
.char-counter.near-limit { color: var(--w2); }
.char-counter.at-limit   { color: var(--r2); }

/* ── 8. PAGE TRANSITION ───────────────────────────────────────────────────────── */

.page-content {
  animation: page-fade-in .3s ease-out both;
}
@keyframes page-fade-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0);   }
}

/* ── 9. SCROLL-TO-TOP BUTTON ─────────────────────────────────────────────────── */

#scroll-top-btn {
  position: fixed;
  bottom: 24px; left: 24px;
  width: 40px; height: 40px;
  border-radius: 50%;
  background: var(--s2);
  border: 1px solid var(--b-default);
  color: var(--t3);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  opacity: 0; visibility: hidden;
  transition: opacity .25s, visibility .25s, background .15s;
  z-index: 500;
}
#scroll-top-btn.visible { opacity: 1; visibility: visible; }
#scroll-top-btn:hover   { background: var(--s3); color: var(--t1); }

/* ── 10. KEYBOARD SHORTCUT HINTS ─────────────────────────────────────────────── */

.kbd {
  display: inline-flex;
  align-items: center;
  padding: 2px 6px;
  font-size: .7rem;
  font-family: 'JetBrains Mono', monospace;
  background: var(--s2);
  border: 1px solid var(--b-strong);
  border-radius: 4px;
  color: var(--t3);
  vertical-align: middle;
  gap: 3px;
  box-shadow: 0 1px 0 var(--b-strong);
}

/* ── 11. PROGRESS STEPS ──────────────────────────────────────────────────────── */

.steps {
  display: flex;
  align-items: center;
  gap: 0;
  padding: 24px 0;
}
.step {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  flex: 1;
  position: relative;
}
.step::before {
  content: '';
  position: absolute;
  top: 15px; left: -50%;
  width: 100%;
  height: 2px;
  background: var(--b-default);
  z-index: 0;
}
.step:first-child::before { display: none; }
.step-dot {
  width: 32px; height: 32px;
  border-radius: 50%;
  border: 2px solid var(--b-default);
  background: var(--s2);
  display: flex; align-items: center; justify-content: center;
  font-size: .8rem;
  font-weight: 600;
  color: var(--t4);
  z-index: 1;
  position: relative;
  transition: all .2s;
}
.step.active .step-dot {
  border-color: var(--a2);
  background: var(--a-bg);
  color: var(--a1);
}
.step.completed .step-dot {
  border-color: var(--m2);
  background: var(--m-bg);
  color: var(--m1);
}
.step.completed::before { background: var(--m2); }
.step-label {
  font-size: .75rem;
  color: var(--t4);
  text-align: center;
}
.step.active .step-label   { color: var(--a1); font-weight: 500; }
.step.completed .step-label { color: var(--m1); }

/* ── 12. DIFF VIEWER (for version comparison) ─────────────────────────────────── */

.diff-viewer {
  font-family: 'JetBrains Mono', monospace;
  font-size: .8125rem;
  line-height: 1.6;
  background: var(--s1);
  border: 1px solid var(--b-default);
  border-radius: 10px;
  overflow: hidden;
}
.diff-header {
  padding: 10px 16px;
  background: var(--s2);
  border-bottom: 1px solid var(--b-default);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: .8125rem;
  color: var(--t3);
}
.diff-line {
  padding: 2px 16px;
  white-space: pre-wrap;
  word-break: break-all;
}
.diff-line.added   { background: rgba(45,122,82,.08);  color: var(--m1); }
.diff-line.removed { background: rgba(225,72,72,.08);   color: var(--r1); }
.diff-line.context { color: var(--t4); }
.diff-line.added::before   { content: '+ '; opacity: .6; }
.diff-line.removed::before { content: '- '; opacity: .6; }
.diff-line.context::before { content: '  '; }

/* ── 13. KEYBOARD NAVIGATION FOCUS RING ──────────────────────────────────────── */

*:focus-visible {
  outline: 2px solid var(--b-focus);
  outline-offset: 3px;
  border-radius: 4px;
}
*:focus:not(:focus-visible) {
  outline: none;
}

/* ── 14. REDUCED MOTION ─────────────────────────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
  .skeleton,
  .loading-spinner-ring,
  .btn-loading::after,
  .badge-pulse::before {
    animation: none !important;
  }
  .card-hover { transition: none; }
  .page-content { animation: none; }
}
