/* Aly Market — Shared UI Components
 *
 * Mobile-first primitive classes (.aly-card, .aly-btn, .aly-input, etc.)
 * that all 3 web frontends can use directly. Pair with tokens.css.
 *
 * Naming: every class starts with `aly-` so it never conflicts with
 * Tailwind utilities or framework styles. Each class maps cleanly to a
 * Flutter widget (Card, FilledButton, TextField, Chip, ...).
 */

* { box-sizing: border-box; }

html, body { font-family: var(--aly-font); }
body {
  background: var(--aly-bg);
  color: var(--aly-ink);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* App shell — mobile-first layout with optional top bar + bottom nav */
.aly-app {
  min-height: 100dvh;
  background: var(--aly-bg);
  padding-bottom: calc(var(--aly-bottom-nav-h) + var(--aly-safe-bottom));
}
.aly-app--no-nav { padding-bottom: var(--aly-safe-bottom); }

/* Top bar — sticky, frosted, market-style */
.aly-topbar {
  position: sticky; top: 0; z-index: 100;
  height: 56px;
  padding: 0 12px;
  display: flex; align-items: center; gap: 10px;
  background: rgba(255,255,255,.94);
  backdrop-filter: saturate(160%) blur(14px);
  -webkit-backdrop-filter: saturate(160%) blur(14px);
  border-bottom: 1px solid var(--line);
}
.aly-topbar__back {
  width: 36px; height: 36px; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 50%; background: transparent; border: 0;
  color: var(--ink); cursor: pointer; font-size: 22px;
}
.aly-topbar__back:hover { background: var(--aly-line-soft); }
.aly-topbar__title {
  flex: 1; font-weight: 800; font-size: 16px; line-height: 1.1;
  color: var(--ink); margin: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.aly-topbar__icon-btn {
  width: 40px; height: 40px; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--aly-r-pill); background: transparent; border: 0;
  color: var(--ink); cursor: pointer; transition: background .15s; font-size: 18px;
  position: relative;
}
.aly-topbar__icon-btn:hover { background: var(--aly-line-soft); }
.aly-topbar__icon-btn .dot {
  position: absolute; top: 8px; right: 8px;
  width: 8px; height: 8px; border-radius: 50%; background: var(--red);
  border: 2px solid var(--white);
}
.aly-topbar__search {
  flex: 1; position: relative;
}
.aly-topbar__search input {
  width: 100%; padding: 8px 38px 8px 14px;
  border-radius: 999px; border: 1px solid var(--line);
  background: var(--aly-line-soft); color: var(--ink);
  font-size: 14px; min-height: 38px; font-family: inherit;
}
.aly-topbar__search input:focus {
  outline: 0; border-color: var(--red); background: var(--white);
  box-shadow: 0 0 0 3px var(--aly-red-soft);
}
.aly-topbar__search::before {
  content: '🔍'; position: absolute; right: 12px; top: 50%;
  transform: translateY(-50%); opacity: .55; pointer-events: none; font-size: 13px;
}

/* Bottom navigation — pixel-matched to aly-market-fe storefront */
.aly-bottomnav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 200;
  height: calc(62px + var(--aly-safe-bottom));
  padding-bottom: var(--aly-safe-bottom);
  background: var(--white);
  border-top: 1px solid var(--line);
  display: flex;
}
.aly-bottomnav__item {
  flex: 1; position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; padding: 6px 0;
  color: var(--muted); text-decoration: none; cursor: pointer;
  font-family: inherit; background: transparent; border: 0;
  transition: color .15s;
}
.aly-bottomnav__item .icon { font-size: 20px; line-height: 1; }
.aly-bottomnav__item .label {
  font-size: 9px; font-weight: 700; color: var(--muted);
}
.aly-bottomnav__item.active .label,
.aly-bottomnav__item.active { color: var(--red); }
.aly-bottomnav__item.active::after {
  content: ''; width: 4px; height: 4px; border-radius: 50%;
  background: var(--red); margin-top: 2px;
}
.aly-bottomnav__badge {
  position: absolute; top: 6px; right: calc(50% - 22px);
  background: var(--red); color: #fff;
  width: 17px; height: 17px; border-radius: 50%;
  border: 2px solid var(--white);
  display: flex; align-items: center; justify-content: center;
  font-size: 9px; font-weight: 900;
}
/* Hide on tablet+ — desktop uses sidebar/top nav */
@media (min-width: 768px) {
  .aly-bottomnav { display: none; }
  .aly-app { padding-bottom: 0; }
}

/* Page container */
.aly-page { padding: var(--aly-s-4); }
.aly-page--flush { padding: 0; }
.aly-page__title { font-size: 20px; font-weight: 700; margin: 0 0 var(--aly-s-4); }

/* Cards */
.aly-card {
  background: var(--aly-card);
  border-radius: var(--aly-r-lg);
  border: 1px solid var(--aly-line-soft);
  box-shadow: var(--aly-sh-sm);
  padding: var(--aly-s-4);
}
.aly-card--flush { padding: 0; overflow: hidden; }
.aly-card--lift { box-shadow: var(--aly-sh-md); }
.aly-card--bare { border: 0; box-shadow: none; background: transparent; padding: 0; }

/* KPI tile — for dashboard / analytics */
.aly-kpi {
  background: var(--aly-card);
  border-radius: var(--aly-r-lg);
  padding: var(--aly-s-4);
  border: 1px solid var(--aly-line-soft);
  display: flex; flex-direction: column; gap: var(--aly-s-2);
  min-height: 96px;
}
.aly-kpi__label { font-size: 12px; color: var(--aly-muted); font-weight: 500; }
.aly-kpi__value { font-size: 24px; font-weight: 800; line-height: 1.1; color: var(--aly-ink); }
.aly-kpi__delta { font-size: 12px; font-weight: 600; display: inline-flex; align-items: center; gap: 4px; }
.aly-kpi__delta.up { color: var(--aly-success-text); }
.aly-kpi__delta.down { color: var(--aly-danger-text); }
.aly-kpi--accent-red    { border-color: var(--aly-red);    box-shadow: var(--aly-sh-glow); }
.aly-kpi--accent-green  { border-color: var(--aly-green); }
.aly-kpi--accent-blue   { border-color: var(--aly-blue); }
.aly-kpi--accent-gold   { border-color: var(--aly-gold); }

/* Buttons */
.aly-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 16px;
  border-radius: var(--aly-r-pill);
  font-weight: 600; font-size: 14px; line-height: 1;
  border: 0; cursor: pointer; text-decoration: none;
  transition: transform .08s, box-shadow .15s, opacity .15s;
  min-height: 40px; font-family: inherit;
}
.aly-btn:active { transform: scale(.97); }
.aly-btn:disabled { opacity: .55; cursor: not-allowed; }
.aly-btn--primary  { background: var(--aly-red);    color: #fff; box-shadow: var(--aly-sh-glow); }
.aly-btn--primary:hover { background: var(--aly-red-light); }
.aly-btn--secondary{ background: var(--aly-ink);    color: #fff; }
.aly-btn--success  { background: var(--aly-green);  color: #fff; }
.aly-btn--ghost    { background: transparent;       color: var(--aly-ink); border: 1px solid var(--aly-line); }
.aly-btn--ghost:hover { background: var(--aly-line-soft); }
.aly-btn--soft-red { background: var(--aly-red-soft); color: var(--aly-danger-text); }
.aly-btn--soft-green{ background: var(--aly-green-soft); color: var(--aly-success-text); }
.aly-btn--block    { width: 100%; }
.aly-btn--lg       { min-height: 52px; padding: 14px 22px; font-size: 16px; border-radius: var(--aly-r-lg); }
.aly-btn--sm       { min-height: 32px; padding: 6px 12px; font-size: 12px; }

/* FAB */
.aly-fab {
  position: fixed; bottom: calc(var(--aly-bottom-nav-h) + 16px + var(--aly-safe-bottom));
  left: 16px; width: 56px; height: 56px;
  border-radius: var(--aly-r-pill);
  background: var(--aly-red); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 24px; border: 0; cursor: pointer;
  box-shadow: var(--aly-sh-glow);
  z-index: 44;
}

/* Inputs */
.aly-input, .aly-textarea, .aly-select {
  width: 100%; padding: 12px 14px;
  border: 1px solid var(--aly-line);
  background: var(--aly-card);
  color: var(--aly-ink);
  border-radius: var(--aly-r-md);
  font-size: 14px; font-family: inherit;
  transition: border-color .15s, box-shadow .15s;
  min-height: 44px;
}
.aly-input:focus, .aly-textarea:focus, .aly-select:focus {
  outline: 0; border-color: var(--aly-red);
  box-shadow: 0 0 0 3px var(--aly-red-soft);
}
.aly-field { display: flex; flex-direction: column; gap: 6px; margin-bottom: var(--aly-s-3); }
.aly-label { font-size: 13px; font-weight: 600; color: var(--aly-ink-2); }
.aly-helper { font-size: 12px; color: var(--aly-muted); }

/* Search input with leading icon */
.aly-search {
  position: relative; display: block;
}
.aly-search input {
  width: 100%; padding: 12px 44px 12px 14px;
  border-radius: var(--aly-r-pill);
  border: 1px solid var(--aly-line);
  background: var(--aly-card); color: var(--aly-ink);
  font-size: 14px; min-height: 44px;
  font-family: inherit;
}
.aly-search input:focus { outline: 0; border-color: var(--aly-red); box-shadow: 0 0 0 3px var(--aly-red-soft); }
.aly-search::before {
  content: '🔍'; position: absolute; right: 14px; top: 50%;
  transform: translateY(-50%); opacity: .55; pointer-events: none; font-size: 14px;
}

/* Badges / chips */
.aly-badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 10px; border-radius: var(--aly-r-pill);
  font-size: 11px; font-weight: 700; line-height: 1.4;
  background: var(--aly-line-soft); color: var(--aly-ink-2);
}
.aly-badge--success { background: var(--aly-success-bg); color: var(--aly-success-text); }
.aly-badge--warning { background: var(--aly-warning-bg); color: var(--aly-warning-text); }
.aly-badge--danger  { background: var(--aly-danger-bg);  color: var(--aly-danger-text); }
.aly-badge--info    { background: var(--aly-info-bg);    color: var(--aly-info-text); }

/* Filter chip row (scrollable) */
.aly-chiprow {
  display: flex; gap: 8px; overflow-x: auto; padding: 4px 0;
  scrollbar-width: none;
}
.aly-chiprow::-webkit-scrollbar { display: none; }
.aly-chip {
  flex-shrink: 0; padding: 7px 14px;
  border-radius: var(--aly-r-pill);
  background: var(--aly-card); border: 1px solid var(--aly-line);
  color: var(--aly-ink-2); font-size: 13px; font-weight: 600;
  cursor: pointer; user-select: none; white-space: nowrap;
  transition: all .15s;
}
.aly-chip:hover { border-color: var(--aly-ink-2); }
.aly-chip.active { background: var(--aly-ink); border-color: var(--aly-ink); color: #fff; }

/* List rows */
.aly-row {
  display: flex; align-items: center; gap: var(--aly-s-3);
  padding: var(--aly-s-3) var(--aly-s-4);
  background: var(--aly-card);
  border-bottom: 1px solid var(--aly-line-soft);
  text-decoration: none; color: inherit;
  transition: background .15s;
}
.aly-row:last-child { border-bottom: 0; }
.aly-row:hover { background: var(--aly-line-soft); }
.aly-row__avatar {
  width: 44px; height: 44px; border-radius: var(--aly-r-pill);
  background: var(--aly-line-soft); display: flex; align-items: center; justify-content: center;
  font-weight: 700; color: var(--aly-ink-2); flex-shrink: 0; font-size: 16px;
  overflow: hidden;
}
.aly-row__main { flex: 1; min-width: 0; }
.aly-row__title { font-size: 14px; font-weight: 600; color: var(--aly-ink); margin-bottom: 2px;
                  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.aly-row__sub { font-size: 12px; color: var(--aly-muted);
                white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.aly-row__trail { font-size: 12px; color: var(--aly-muted); text-align: end; flex-shrink: 0; }

/* Section header above list/grid */
.aly-section-head {
  display: flex; align-items: baseline; justify-content: space-between;
  padding: var(--aly-s-5) var(--aly-s-1) var(--aly-s-2);
}
.aly-section-head h2 { margin: 0; font-size: 16px; font-weight: 700; }
.aly-section-head .see-all { font-size: 12px; color: var(--aly-red); text-decoration: none; font-weight: 600; }

/* Empty state */
.aly-empty {
  text-align: center; padding: 48px 24px; color: var(--aly-muted);
}
.aly-empty .ico { font-size: 48px; margin-bottom: 12px; opacity: .6; }
.aly-empty h3   { font-size: 16px; color: var(--aly-ink-2); margin: 0 0 6px; }
.aly-empty p    { font-size: 13px; margin: 0; }

/* Skeleton loader */
.aly-skel {
  background: linear-gradient(90deg, var(--aly-line-soft) 25%, var(--aly-line) 50%, var(--aly-line-soft) 75%);
  background-size: 200% 100%;
  animation: aly-skel 1.4s ease-in-out infinite;
  border-radius: var(--aly-r-sm);
}
@keyframes aly-skel { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* Divider */
.aly-divider { height: 1px; background: var(--aly-line-soft); margin: var(--aly-s-3) 0; }

/* Animations */
@keyframes aly-fade-up { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
.aly-fade-up { animation: aly-fade-up .3s ease-out; }
@keyframes aly-slide-up { from { transform: translateY(100%); } to { transform: translateY(0); } }
.aly-slide-up { animation: aly-slide-up .22s ease-out; }

/* Bottom sheet */
.aly-sheet-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 60;
  display: flex; align-items: flex-end; justify-content: center;
}
.aly-sheet {
  background: var(--aly-card); width: 100%; max-width: 480px;
  border-top-left-radius: var(--aly-r-2xl); border-top-right-radius: var(--aly-r-2xl);
  padding: var(--aly-s-4) var(--aly-s-4) calc(var(--aly-s-4) + var(--aly-safe-bottom));
  animation: aly-slide-up .25s ease-out;
}
.aly-sheet__grab { width: 40px; height: 4px; border-radius: 2px; background: var(--aly-line); margin: 0 auto var(--aly-s-3); }

/* Pull-to-refresh-style toast */
.aly-toast {
  position: fixed; top: calc(var(--aly-safe-top) + 12px); left: 50%; transform: translateX(-50%);
  background: var(--aly-ink); color: #fff;
  padding: 10px 18px; border-radius: var(--aly-r-pill);
  font-size: 13px; font-weight: 600; z-index: 200;
  box-shadow: var(--aly-sh-lg);
  animation: aly-fade-up .25s;
}

/* Grid helpers (no Tailwind needed) */
.aly-grid       { display: grid; gap: var(--aly-s-3); }
.aly-grid--2    { grid-template-columns: repeat(2, 1fr); }
.aly-grid--3    { grid-template-columns: repeat(3, 1fr); }
.aly-grid--auto { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }

/* Responsive: at sm+ keep mobile feel but allow wider gutters */
@media (min-width: 640px) {
  .aly-page { padding: var(--aly-s-5) var(--aly-s-6); }
}
@media (min-width: 1024px) {
  /* On desktop, the app frame caps width and centers */
  .aly-app--centered { max-width: 480px; margin: 0 auto; box-shadow: var(--aly-sh-lg); }
}
