/* Star Photo Lab — custom UI components (select, date picker, toast, confirm).
   Replaces native <select>, <input type=date>, and browser alert/confirm so the
   whole app shares one look. Driven by assets/js/ui-components.js (window.SPUI).
   Uses the app.css design tokens (--bg, --border, --text, --pw-*, --bad, --ok). */

/* ── Custom select ─────────────────────────────────────────────────────────── */
.sp-select { position: relative; display: inline-block; width: 100%; }
.sp-select-native { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); border: 0; }
.sp-select-trigger {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  width: 100%; height: 34px; padding: 0 10px; font: inherit; font-size: 13px;
  background: var(--bg); color: var(--text); border: 1px solid var(--border);
  border-radius: 6px; cursor: pointer; text-align: left; line-height: 1;
}
.sp-select-trigger:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--pw-100); border-color: var(--pw-400); }
.sp-select.open .sp-select-trigger { border-color: var(--pw-400); box-shadow: 0 0 0 3px var(--pw-100); }
.sp-select-trigger .sp-val { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sp-select-trigger .sp-val.placeholder { color: var(--text-mut); }
.sp-select-trigger .sp-caret { flex: none; width: 9px; height: 9px; border-right: 2px solid var(--text-2); border-bottom: 2px solid var(--text-2); transform: rotate(45deg) translateY(-2px); transition: transform .15s; }
.sp-select.open .sp-select-trigger .sp-caret { transform: rotate(-135deg) translateY(-1px); }
.sp-select-trigger[aria-disabled="true"] { opacity: .5; cursor: not-allowed; background: var(--pw-50); }

.sp-select-menu {
  position: absolute; z-index: 60; top: calc(100% + 4px); left: 0; right: 0;
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
  box-shadow: 0 8px 28px rgba(0,0,0,.12); padding: 4px; max-height: 260px; overflow: auto;
  display: none;
}
.sp-select.open .sp-select-menu { display: block; }
.sp-select.up .sp-select-menu { top: auto; bottom: calc(100% + 4px); }
.sp-opt { padding: 8px 10px; border-radius: 6px; font-size: 13px; cursor: pointer; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sp-opt:hover, .sp-opt.active { background: var(--pw-50); }
.sp-opt[aria-selected="true"] { font-weight: 650; }
.sp-opt[aria-selected="true"]::after { content: "✓"; float: right; color: var(--pw-500); }
.sp-opt.is-placeholder { color: var(--text-mut); }

/* ── Custom date picker ────────────────────────────────────────────────────── */
.sp-date { position: relative; display: inline-block; width: 100%; }
.sp-date-trigger {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  width: 100%; height: 34px; padding: 0 10px; font: inherit; font-size: 13px;
  background: var(--bg); color: var(--text); border: 1px solid var(--border);
  border-radius: 6px; cursor: pointer; text-align: left;
}
.sp-date-trigger:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--pw-100); border-color: var(--pw-400); }
.sp-date.open .sp-date-trigger { border-color: var(--pw-400); box-shadow: 0 0 0 3px var(--pw-100); }
.sp-date-trigger .sp-dval.placeholder { color: var(--text-mut); }
.sp-date-trigger .sp-cal-ico { flex: none; width: 15px; height: 15px; opacity: .55; }

.sp-cal {
  position: absolute; z-index: 60; top: calc(100% + 4px); left: 0;
  width: 248px; background: var(--bg); border: 1px solid var(--border);
  border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,.14); padding: 10px; display: none;
}
.sp-date.open .sp-cal { display: block; }
.sp-date.up .sp-cal { top: auto; bottom: calc(100% + 4px); }
.sp-cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.sp-cal-title { font-size: 13px; font-weight: 650; }
.sp-cal-nav { width: 28px; height: 28px; border: 1px solid var(--border); border-radius: 6px; background: var(--bg); cursor: pointer; font-size: 14px; color: var(--text-2); display: flex; align-items: center; justify-content: center; }
.sp-cal-nav:hover { background: var(--pw-50); }
.sp-cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.sp-cal-dow { font-size: 10px; text-transform: uppercase; letter-spacing: .03em; color: var(--text-mut); text-align: center; padding: 4px 0; font-weight: 700; }
.sp-cal-day { aspect-ratio: 1; display: flex; align-items: center; justify-content: center; font-size: 12.5px; border-radius: 6px; cursor: pointer; color: var(--text); border: 1px solid transparent; }
.sp-cal-day:hover { background: var(--pw-50); }
.sp-cal-day.other { color: var(--text-mut); opacity: .5; }
.sp-cal-day.disabled { color: var(--text-mut); opacity: .3; cursor: not-allowed; text-decoration: line-through; }
.sp-cal-day.disabled:hover { background: none; }
.sp-cal-day.today { border-color: var(--pw-300); font-weight: 700; }
.sp-cal-day.selected { background: var(--pw-500); color: #fff; font-weight: 700; }
.sp-cal-foot { display: flex; justify-content: space-between; margin-top: 8px; }
.sp-cal-foot button { background: none; border: none; font: inherit; font-size: 12px; font-weight: 600; color: var(--pw-600); cursor: pointer; padding: 4px 6px; border-radius: 6px; }
.sp-cal-foot button:hover { background: var(--pw-50); }

/* ── Toast ─────────────────────────────────────────────────────────────────── */
.sp-toasts { position: fixed; top: 18px; right: 18px; z-index: 9999; display: flex; flex-direction: column; gap: 10px; max-width: 360px; }
.sp-toast {
  display: flex; align-items: flex-start; gap: 10px; padding: 12px 14px;
  background: var(--bg); border: 1px solid var(--border); border-left: 4px solid var(--text-2);
  border-radius: 10px; box-shadow: 0 8px 28px rgba(0,0,0,.14); font-size: 13px; color: var(--text);
  animation: sp-toast-in .18s ease-out;
}
.sp-toast.leaving { animation: sp-toast-out .16s ease-in forwards; }
.sp-toast .sp-toast-ico { flex: none; width: 18px; height: 18px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 800; color: #fff; margin-top: 1px; }
.sp-toast .sp-toast-msg { flex: 1; line-height: 1.4; }
.sp-toast .sp-toast-x { background: none; border: none; cursor: pointer; color: var(--text-mut); font-size: 16px; line-height: 1; padding: 0 2px; }
.sp-toast.error   { border-left-color: var(--bad); }   .sp-toast.error .sp-toast-ico   { background: var(--bad); }
.sp-toast.success { border-left-color: var(--ok); }    .sp-toast.success .sp-toast-ico { background: var(--ok); }
.sp-toast.info    { border-left-color: var(--pw-400); }.sp-toast.info .sp-toast-ico    { background: var(--pw-400); }
.sp-toast.warn    { border-left-color: var(--warn); }  .sp-toast.warn .sp-toast-ico    { background: var(--warn); }
@keyframes sp-toast-in  { from { opacity: 0; transform: translateX(12px); } to { opacity: 1; transform: none; } }
@keyframes sp-toast-out { to { opacity: 0; transform: translateX(12px); } }

/* ── Confirm / dialog ──────────────────────────────────────────────────────── */
.sp-modal-back { position: fixed; inset: 0; background: rgba(15,16,20,.42); z-index: 9998; display: flex; align-items: center; justify-content: center; padding: 20px; animation: sp-fade .14s ease-out; }
.sp-modal { background: var(--bg); border: 1px solid var(--border); border-radius: 14px; box-shadow: 0 24px 60px rgba(0,0,0,.28); max-width: 420px; width: 100%; padding: 22px 24px; animation: sp-pop .16s ease-out; }
.sp-modal h4 { margin: 0 0 8px; font-size: 16px; font-weight: 700; }
.sp-modal p { margin: 0 0 18px; font-size: 13.5px; color: var(--text-2); line-height: 1.5; }
.sp-modal-actions { display: flex; justify-content: flex-end; gap: 10px; }
@keyframes sp-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes sp-pop { from { opacity: 0; transform: translateY(8px) scale(.98); } to { opacity: 1; transform: none; } }
