/* ====================================
   ROUND 2 — Design polish overlay
   Loaded AFTER style.css to refine without rewriting.
   Focus: skeleton loaders, micro-interactions, elevation,
   modal blur, focus rings, empty states, button tap targets.
   ==================================== */

/* ── Refined elevation system ────────────────────────────── */
:root {
  --elev-1: 0 1px 2px rgba(15,23,42,0.04), 0 1px 1px rgba(15,23,42,0.03);
  --elev-2: 0 4px 8px rgba(15,23,42,0.05), 0 2px 4px rgba(15,23,42,0.04);
  --elev-3: 0 8px 24px rgba(15,23,42,0.08), 0 4px 8px rgba(15,23,42,0.04);
  --elev-4: 0 20px 48px rgba(15,23,42,0.12), 0 8px 16px rgba(15,23,42,0.06);
  --ring-brand: 0 0 0 3px rgba(10,61,46,0.12);
  --ring-error: 0 0 0 3px rgba(239,68,68,0.12);
}

/* ── Skeleton loader (replace bare spinners in lists) ────── */
.skeleton {
  background: linear-gradient(90deg, #f1f5f9 0%, #e2e8f0 50%, #f1f5f9 100%);
  background-size: 200% 100%;
  animation: skel-shimmer 1.4s linear infinite;
  border-radius: 8px;
  display: block;
}
.skeleton-line { height: 14px; margin: 6px 0; }
.skeleton-line.lg { height: 18px; }
.skeleton-line.short { width: 60%; }
.skeleton-circle { border-radius: 50%; }
.skeleton-card {
  background: #fff; border: 1px solid var(--border); border-radius: 12px;
  padding: 16px; margin-bottom: 10px;
}
@keyframes skel-shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ── Focus ring for accessibility ─────────────────────────── */
input:focus, select:focus, textarea:focus, button:focus-visible {
  outline: none;
  border-color: var(--color-brand) !important;
  box-shadow: var(--ring-brand);
}
input.error, select.error, textarea.error {
  border-color: var(--color-error) !important;
  box-shadow: var(--ring-error);
}

/* ── Cards: warmer elevation and hover lift ──────────────── */
.card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px;
  box-shadow: var(--elev-1);
  transition: box-shadow 200ms var(--ease-smooth), transform 200ms var(--ease-smooth);
}
.card.interactive:hover, .toolkit-tile:hover {
  box-shadow: var(--elev-3);
  transform: translateY(-1px);
}

/* ── Button refinements (tap target ≥ 44px) ──────────────── */
.btn-primary, .btn-ghost, .btn-danger {
  min-height: 44px;
  font-weight: 600;
  letter-spacing: 0.01em;
  border-radius: 10px;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  transition: all 160ms var(--ease-smooth);
  cursor: pointer;
}
.btn-primary {
  background: var(--color-brand);
  color: #fff;
  border: 0;
  padding: 10px 18px;
}
.btn-primary:hover {
  background: var(--color-brand-lighter);
  box-shadow: 0 6px 18px rgba(6,78,59,0.25);
  transform: translateY(-1px);
}
.btn-primary:active { transform: translateY(0); }
.btn-primary:disabled { opacity: 0.55; cursor: not-allowed; transform: none; box-shadow: none; }

.btn-ghost {
  background: transparent;
  color: var(--color-ink-2);
  border: 1px solid var(--border);
  padding: 10px 16px;
}
.btn-ghost:hover {
  background: var(--color-surface);
  border-color: var(--border-strong);
}

.btn-danger {
  background: var(--color-error);
  color: #fff;
  border: 0;
  padding: 10px 18px;
}
.btn-danger:hover { background: #dc2626; }

/* ── Modal backdrop with blur ────────────────────────────── */
.modal-backdrop {
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  background: rgba(15,23,42,0.32) !important;
  animation: backdrop-in 200ms var(--ease-smooth);
}
.modal-backdrop > .modal,
.modal-backdrop > div {
  animation: modal-in 240ms var(--ease-smooth);
}
@keyframes backdrop-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes modal-in {
  from { opacity: 0; transform: translateY(20px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ── Toast: refined position + iconography ──────────────── */
.toast {
  position: fixed;
  bottom: calc(var(--bottomnav-h) + 24px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%) translateY(100%);
  background: var(--color-ink);
  color: #fff;
  padding: 12px 22px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--elev-4);
  z-index: 2000;
  opacity: 0;
  transition: all 280ms var(--ease-smooth);
  max-width: calc(100vw - 32px);
  text-align: center;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.toast.success { background: var(--color-brand); }
.toast.error { background: var(--color-error); }
.toast.warning { background: var(--color-warning); color: #000; }

@media (min-width: 768px) {
  .toast {
    left: auto;
    right: 24px;
    bottom: 24px;
    transform: translateY(100%);
    border-radius: 12px;
  }
  .toast.show { transform: translateY(0); }
}

/* ── Empty state polish ─────────────────────────────────── */
.empty {
  text-align: center;
  padding: 48px 24px;
  color: var(--color-ink-3);
}
.empty-icon {
  width: 72px; height: 72px;
  margin: 0 auto 16px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--color-surface);
  border-radius: 50%;
  color: var(--color-ink-5);
}
.empty-title {
  font-weight: 600;
  font-size: 15px;
  color: var(--color-ink);
  margin-bottom: 4px;
}
.empty-sub {
  font-size: 13px;
  line-height: 1.5;
  color: var(--color-ink-3);
  max-width: 280px;
  margin: 0 auto;
}

/* ── Pill chips for status / score ──────────────────────── */
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  background: var(--color-surface);
  color: var(--color-ink-3);
  white-space: nowrap;
}
.chip.hot     { background: rgba(251,146,60,0.15); color: #c2410c; }
.chip.warm    { background: rgba(245,158,11,0.15); color: #b45309; }
.chip.cold    { background: rgba(148,163,184,0.18); color: #475569; }
.chip.success { background: rgba(16,185,129,0.15); color: #047857; }
.chip.danger  { background: rgba(239,68,68,0.15); color: #b91c1c; }
.chip.info    { background: rgba(59,130,246,0.15); color: #1e40af; }

/* ── Improved bottom nav badge ──────────────────────────── */
.bn-badge {
  background: #ef4444;
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 999px;
  position: absolute;
  top: 4px;
  right: calc(50% - 22px);
  min-width: 18px;
  text-align: center;
  border: 2px solid #fff;
  line-height: 1;
}

/* ── Make the AI floating bubble respect safe-area ──────── */
#aiAgChatBubble, #aiFab {
  bottom: calc(var(--bottomnav-h) + 16px + env(safe-area-inset-bottom)) !important;
}
#aiAgChatSheet {
  bottom: calc(var(--bottomnav-h) + 80px + env(safe-area-inset-bottom)) !important;
  border: 1px solid var(--border) !important;
  box-shadow: var(--elev-4) !important;
  border-radius: 14px !important;
}

/* ── Toolkit tile grid: consistent ─────────────────────── */
.toolkit-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(155px, 1fr));
  gap: 12px;
  padding: 0 16px 16px;
}
.toolkit-tile {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px 14px;
  display: flex; flex-direction: column; gap: 8px;
  text-decoration: none;
  color: var(--color-ink);
  cursor: pointer;
  transition: all 200ms var(--ease-smooth);
  position: relative;
}
.toolkit-tile:hover {
  transform: translateY(-2px);
  box-shadow: var(--elev-3);
  border-color: var(--color-brand-lighter);
}
.tk-icon {
  width: 36px; height: 36px;
  background: var(--color-brand-soft);
  color: var(--color-brand);
  border-radius: 10px;
  display: inline-flex; align-items: center; justify-content: center;
}
.tk-name { font-weight: 600; font-size: 14px; }
.tk-desc { font-size: 11px; color: var(--color-ink-3); line-height: 1.4; }
.tk-badge {
  position: absolute;
  top: 10px; right: 10px;
  font-size: 9px; font-weight: 700;
  padding: 2px 7px; border-radius: 999px;
  text-transform: uppercase; letter-spacing: 0.4px;
}
.tk-badge.popular { background: #fef3c7; color: #92400e; }
.tk-badge.new { background: #dcfce7; color: #166534; }
.tk-badge.soon { background: #e0e7ff; color: #3730a3; }

/* ── Header: sticky with subtle blur ──────────────────── */
.app-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(255,255,255,0.92);
  backdrop-filter: saturate(160%) blur(8px);
  -webkit-backdrop-filter: saturate(160%) blur(8px);
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
  display: flex; align-items: center; gap: 12px;
}
.app-header .brand-mark {
  font-family: var(--font-display);
  font-weight: 600;
  color: var(--color-brand);
  font-size: 17px;
  letter-spacing: -0.02em;
}

/* ── Subtle accent bar under page title ───────────────── */
.page-title {
  position: relative;
  display: inline-block;
  padding-bottom: 4px;
}
.page-title::after {
  content: '';
  position: absolute;
  left: 0; bottom: 0;
  width: 32px; height: 3px;
  background: var(--color-accent);
  border-radius: 2px;
}

/* ── Responsive sm tweaks ─────────────────────────────── */
@media (max-width: 360px) {
  body { font-size: 13px; }
  .toolkit-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .toolkit-tile { padding: 12px 10px; }
}

/* ── Print-friendly (for stat / commission summaries) ── */
@media print {
  .app-header, .bottom-nav, #aiAgChatBubble, #aiFab, #notifBell { display: none !important; }
  body { background: #fff; }
  .card { box-shadow: none !important; border: 1px solid #ddd; break-inside: avoid; }
}

/* ── Reduced motion ───────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *, ::before, ::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
