/* Riffaso shared UI components.
   Plain CSS, no framework. Reuses the tokens already declared in
   riffaso/static/style.css (:root --ink, --line, --accent, ...) so these
   components inherit the site's look automatically.
   Load it once, after style.css:
     <link rel="stylesheet" href="{{ url_for('static', filename='ui.css') }}">
   (or `import './components/ui.css'` from main.jsx if you prefer Vite to
   bundle it into static/dist/riffaso.css). */

/* ---------------------------------------------------------------- buttons */
.rf-btn {
  position: relative;
  overflow: hidden;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  border: 1px solid var(--accent);
  border-radius: 8px;
  background: var(--accent);
  color: var(--ink-invert);
  font: inherit;
  font-weight: 600;
  padding: 0.6rem 1.1rem;
  cursor: pointer;
  transform: translateZ(0);
  transition: transform 0.12s ease, box-shadow 0.18s ease,
              background 0.18s ease, color 0.18s ease, opacity 0.18s ease;
}
.rf-btn:hover:not(:disabled) { box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18); transform: translateY(-1px); }
.rf-btn:active:not(:disabled) { transform: translateY(0) scale(0.985); box-shadow: none; }
.rf-btn:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.rf-btn:disabled { opacity: 0.55; cursor: not-allowed; }

.rf-btn--ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.rf-btn--ghost:hover:not(:disabled) { background: var(--surface-2); }
.rf-btn--danger { background: var(--red); border-color: var(--red); }
.rf-btn--success { background: var(--green); border-color: var(--green); }
.rf-btn--block { display: flex; width: 100%; }
.rf-btn--sm { padding: 0.35rem 0.7rem; font-size: 0.85rem; border-radius: 6px; }

/* click ripple */
.rf-btn__ripple {
  position: absolute;
  border-radius: 50%;
  transform: scale(0);
  background: rgba(255, 255, 255, 0.45);
  pointer-events: none;
  animation: rf-ripple 0.55s ease-out forwards;
}
.rf-btn--ghost .rf-btn__ripple { background: rgba(0, 0, 0, 0.12); }
@keyframes rf-ripple { to { transform: scale(2.4); opacity: 0; } }

/* loading spinner + success check swap */
.rf-btn__spinner {
  width: 1em; height: 1em; border-radius: 50%;
  border: 2px solid currentColor; border-top-color: transparent;
  animation: rf-spin 0.7s linear infinite;
}
@keyframes rf-spin { to { transform: rotate(360deg); } }
.rf-btn__label { display: inline-flex; align-items: center; gap: 0.4rem; }
.rf-btn__check { animation: rf-pop 0.35s cubic-bezier(0.2, 1.5, 0.4, 1); }
@keyframes rf-pop { from { transform: scale(0.2); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.rf-btn--pulse:not(:disabled) { animation: rf-pulse 1.8s ease-in-out infinite; }
@keyframes rf-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(10, 10, 10, 0.25); }
  50%      { box-shadow: 0 0 0 10px rgba(10, 10, 10, 0); }
}

/* ----------------------------------------------------------------- modal */
.rf-overlay {
  position: fixed; inset: 0; z-index: 900;
  display: flex; align-items: center; justify-content: center;
  padding: 1rem;
  background: rgba(0, 0, 0, 0.45);
  animation: rf-fade 0.18s ease-out;
}
@keyframes rf-fade { from { opacity: 0; } to { opacity: 1; } }
.rf-modal {
  width: 100%; max-width: 480px; max-height: 88vh; overflow: auto;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--line); border-radius: 12px;
  box-shadow: var(--shadow);
  animation: rf-rise 0.22s cubic-bezier(0.2, 0.9, 0.3, 1);
}
.rf-modal--wide { max-width: 760px; }
@keyframes rf-rise { from { opacity: 0; transform: translateY(14px) scale(0.98); } to { opacity: 1; transform: none; } }
.rf-modal__head {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: 1rem 1.15rem; border-bottom: 1px solid var(--line-soft);
}
.rf-modal__title { margin: 0; font-size: 1.05rem; font-weight: 700; }
.rf-modal__close {
  border: 0; background: transparent; color: var(--muted);
  font-size: 1.35rem; line-height: 1; cursor: pointer; padding: 0.1rem 0.3rem; border-radius: 6px;
}
.rf-modal__close:hover { background: var(--surface-2); color: var(--ink); }
.rf-modal__body { padding: 1.15rem; }
.rf-modal__foot {
  display: flex; justify-content: flex-end; gap: 0.6rem;
  padding: 0.9rem 1.15rem; border-top: 1px solid var(--line-soft);
}

/* ---------------------------------------------------------------- toasts */
.rf-toasts {
  position: fixed; right: 1rem; bottom: 1rem; z-index: 950;
  display: flex; flex-direction: column; gap: 0.55rem; max-width: 340px;
}
.rf-toast {
  display: flex; align-items: flex-start; gap: 0.6rem;
  padding: 0.7rem 0.85rem;
  border: 1px solid var(--line); border-left-width: 4px;
  border-radius: 10px; background: var(--surface);
  box-shadow: var(--shadow); font-size: 0.9rem;
  animation: rf-slide-in 0.22s ease-out;
}
.rf-toast--leaving { animation: rf-slide-out 0.2s ease-in forwards; }
@keyframes rf-slide-in { from { opacity: 0; transform: translateX(18px); } to { opacity: 1; transform: none; } }
@keyframes rf-slide-out { to { opacity: 0; transform: translateX(18px); } }
.rf-toast--success { border-left-color: var(--green); background: var(--success-bg); }
.rf-toast--error   { border-left-color: var(--red);   background: var(--error-bg); }
.rf-toast--info    { border-left-color: var(--line);  background: var(--info-bg); }
.rf-toast__text { flex: 1; }
.rf-toast__close { border: 0; background: transparent; cursor: pointer; color: var(--muted); font-size: 1rem; }

/* ----------------------------------------------------------------- table */
.rf-table-wrap { border: 1px solid var(--line); border-radius: 12px; background: var(--surface); overflow: hidden; }
.rf-table-bar {
  display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap;
  padding: 0.75rem 0.9rem; border-bottom: 1px solid var(--line-soft); background: var(--bg-soft);
}
.rf-table-bar__search {
  flex: 1; min-width: 180px;
  padding: 0.45rem 0.65rem; border: 1px solid var(--line); border-radius: 8px; font: inherit; background: var(--surface);
}
.rf-table-scroll { overflow-x: auto; }
.rf-table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
.rf-table th, .rf-table td { padding: 0.65rem 0.9rem; text-align: left; border-bottom: 1px solid var(--line-soft); white-space: nowrap; }
.rf-table thead th { background: var(--bg-soft); color: var(--muted); font-weight: 600; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; }
.rf-table th.rf-th--sortable { cursor: pointer; user-select: none; }
.rf-table th.rf-th--sortable:hover { color: var(--ink); }
.rf-table__arrow { opacity: 0.5; margin-left: 0.3rem; font-size: 0.7rem; }
.rf-table tbody tr { transition: background 0.14s ease; }
.rf-table tbody tr:hover { background: var(--surface-2); }
.rf-table tbody tr:last-child td { border-bottom: 0; }
.rf-table__num { text-align: right; font-variant-numeric: tabular-nums; }
.rf-table__empty { padding: 2rem; text-align: center; color: var(--muted); }
.rf-table-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 0.75rem;
  padding: 0.65rem 0.9rem; border-top: 1px solid var(--line-soft); background: var(--bg-soft);
  font-size: 0.85rem; color: var(--muted);
}
.rf-pager { display: flex; gap: 0.4rem; }

/* skeleton rows */
.rf-skeleton { display: block; height: 0.8rem; border-radius: 4px;
  background: linear-gradient(90deg, var(--line-soft), var(--surface-2), var(--line-soft));
  background-size: 200% 100%; animation: rf-shimmer 1.2s linear infinite; }
@keyframes rf-shimmer { to { background-position: -200% 0; } }

/* -------------------------------------------------------------- dashboard */
.rf-dash { display: grid; gap: 1rem; }
.rf-dash__stats { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.rf-stat {
  border: 1px solid var(--line); border-radius: 12px; background: var(--surface);
  padding: 0.95rem 1.05rem; transition: transform 0.16s ease, box-shadow 0.16s ease;
}
.rf-stat:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.rf-stat__label { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.rf-stat__value { font-size: 1.6rem; font-weight: 700; margin-top: 0.25rem; font-variant-numeric: tabular-nums; }
.rf-stat__delta { margin-top: 0.3rem; font-size: 0.82rem; font-weight: 600; }
.rf-stat__delta--up { color: var(--green); }
.rf-stat__delta--down { color: var(--red); }
.rf-stat__delta--flat { color: var(--muted); }
.rf-panel { border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.rf-panel__head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 0.85rem 1.05rem; border-bottom: 1px solid var(--line-soft); }
.rf-panel__title { margin: 0; font-size: 0.98rem; font-weight: 700; }
.rf-panel__body { padding: 1.05rem; }
.rf-dash__cols { display: grid; gap: 1rem; grid-template-columns: 2fr 1fr; }
@media (max-width: 860px) { .rf-dash__cols { grid-template-columns: 1fr; } }

/* sparkline bars */
.rf-bars { display: flex; align-items: flex-end; gap: 4px; height: 90px; }
.rf-bars__bar { flex: 1; background: var(--accent); border-radius: 3px 3px 0 0; opacity: 0.85;
  transform-origin: bottom; animation: rf-grow 0.5s cubic-bezier(0.2, 0.9, 0.3, 1) both; }
.rf-bars__bar:hover { opacity: 1; }
@keyframes rf-grow { from { transform: scaleY(0); } to { transform: scaleY(1); } }

/* ------------------------------------------------------------------ forms */
.rf-form { display: grid; gap: 0.9rem; }
.rf-field { display: grid; gap: 0.3rem; }
.rf-field__label { font-size: 0.85rem; font-weight: 600; }
.rf-field__req { color: var(--red); margin-left: 0.15rem; }
.rf-field__hint { font-size: 0.78rem; color: var(--muted); }
.rf-field__error { font-size: 0.78rem; color: var(--red); animation: rf-shake 0.28s ease; }
@keyframes rf-shake { 25% { transform: translateX(-3px); } 75% { transform: translateX(3px); } }
.rf-input, .rf-select, .rf-textarea {
  width: 100%; font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: 8px; padding: 0.55rem 0.7rem;
  transition: border-color 0.16s ease, box-shadow 0.16s ease;
}
.rf-input:focus, .rf-select:focus, .rf-textarea:focus {
  outline: none; border-color: var(--ink); box-shadow: 0 0 0 3px rgba(10, 10, 10, 0.08);
}
.rf-input--invalid, .rf-select--invalid, .rf-textarea--invalid { border-color: var(--red); }
.rf-textarea { min-height: 96px; resize: vertical; }
.rf-row { display: grid; gap: 0.9rem; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.rf-check { display: flex; align-items: flex-start; gap: 0.5rem; font-size: 0.9rem; }

/* --------------------------------------------------------------- badges */
.rf-badge {
  display: inline-block; padding: 0.15rem 0.5rem; border-radius: 999px;
  font-size: 0.75rem; font-weight: 600; border: 1px solid var(--line); background: var(--surface-2); color: var(--vendor-ink);
}
.rf-badge--success { background: var(--success-bg); border-color: var(--success-line); color: var(--green); }
.rf-badge--error { background: var(--error-bg); border-color: var(--error-line); color: var(--red); }

@media (prefers-reduced-motion: reduce) {
  .rf-btn, .rf-modal, .rf-overlay, .rf-toast, .rf-bars__bar, .rf-skeleton,
  .rf-btn__ripple, .rf-btn__check, .rf-field__error {
    animation: none !important; transition: none !important;
  }
}

/* ---------------------------------------------------- admin: Subastas island */
.admin-listings { display: grid; gap: 1rem; }
.admin-filters { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.admin-filter {
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  border-radius: 999px; padding: 0.3rem 0.8rem; font: inherit; font-size: 0.85rem; font-weight: 600; cursor: pointer;
}
.admin-filter span { color: var(--muted); font-weight: 500; margin-left: 0.2rem; }
.admin-filter:hover { border-color: var(--ink); }
.admin-filter.is-active { background: var(--ink); border-color: var(--ink); color: var(--ink-invert); }
.admin-filter.is-active span { color: inherit; opacity: 0.75; }
.admin-filter.is-urgent:not(.is-active) { border-color: var(--error-line); color: var(--red); }
.admin-row-title {
  display: inline-flex; align-items: center; gap: 0.6rem; text-align: left;
  background: none; border: 0; padding: 0; font: inherit; color: var(--ink); cursor: pointer;
}
.admin-row-title:hover span { text-decoration: underline; }
.admin-row-title img, .admin-row-nophoto {
  width: 40px; height: 40px; flex-shrink: 0; border-radius: 6px; object-fit: cover; background: var(--surface-2);
}
.admin-detail { display: grid; grid-template-columns: 160px 1fr; gap: 1rem; align-items: start; }
.admin-detail--no-photo { grid-template-columns: 1fr; }
.admin-detail__photo { width: 100%; aspect-ratio: 1 / 1; object-fit: cover; border-radius: 10px; background: var(--surface-2); }
.admin-detail__facts { display: grid; grid-template-columns: max-content 1fr; gap: 0.35rem 1rem; margin: 0; font-size: 0.92rem; }
.admin-detail__facts dt { color: var(--muted); }
.admin-detail__facts dd { margin: 0; display: flex; flex-wrap: wrap; gap: 0.3rem; align-items: center; }
.admin-detail__note { grid-column: 1 / -1; margin: 0; padding: 0.6rem 0.8rem; border-radius: 8px;
  background: var(--error-bg); border: 1px solid var(--error-line); font-size: 0.88rem; }
@media (max-width: 560px) { .admin-detail { grid-template-columns: 1fr; } .admin-detail__photo { max-width: 160px; } }
