/* ==== Design System — AppFactory Consumer AI Apps ==== */
/* Shared token + component layer. Apps set --accent and import this file.
   Mobile-first, light+dark, WCAG AA, 8pt grid, 44px touch targets. */

:root {
  --accent: #a16207;
  --accent-contrast: #ffffff;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #eef0f4;
  --text: #16181d;
  --text-2: #4b5563;
  --muted: #6b7280;
  --border: #e3e6ea;
  --danger: #b91c1c;
  --ok: #15803d;
  --radius-s: 8px; --radius-m: 12px; --radius-l: 16px;
  --space-1: 4px; --space-2: 8px; --space-3: 12px; --space-4: 16px;
  --space-6: 24px; --space-8: 32px;
  --shadow-1: 0 1px 2px rgba(15,18,25,.06), 0 1px 3px rgba(15,18,25,.08);
  --tabbar-h: 58px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101216; --surface: #181b21; --surface-2: #21252d;
    --text: #eceef2; --text-2: #b6bcc8; --muted: #8b93a2;
    --border: #2a2f39;
    --shadow-1: 0 1px 2px rgba(0,0,0,.5);
  }
}

/* ---- Base ---- */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, "Helvetica Neue", Arial, sans-serif;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px));
  min-height: 100vh;
}
button, input, textarea, select { font: inherit; color: inherit; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 var(--space-2); }
h1 { font-size: 22px; font-weight: 700; }
h2 { font-size: 18px; font-weight: 650; }
h3 { font-size: 16px; font-weight: 600; }
p { margin: 0 0 var(--space-3); }
a { color: var(--accent); text-decoration: none; }

/* ---- App bar ---- */
.appbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: var(--space-3);
  padding: calc(var(--space-3) + env(safe-area-inset-top, 0px)) var(--space-4) var(--space-3);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(12px); border-bottom: 1px solid var(--border);
}
.appbar .title { font-size: 17px; font-weight: 700; flex: 1; min-width: 0; }
.appbar .subtitle { font-size: 12px; color: var(--muted); font-weight: 400; }

/* ---- Tab bar ---- */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
  display: flex; height: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: var(--surface); border-top: 1px solid var(--border);
}
.tabbar button {
  flex: 1; border: 0; background: none; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: 44px; color: var(--muted); font-size: 11px;
}
.tabbar button[aria-selected="true"] { color: var(--accent); }
.tabbar svg { width: 22px; height: 22px; }

/* ---- Cards & lists ---- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-m); padding: var(--space-4); box-shadow: var(--shadow-1);
}
.list-item {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-3) var(--space-4); min-height: 44px;
  border-bottom: 1px solid var(--border); background: var(--surface); cursor: pointer;
}
.list-item:last-child { border-bottom: 0; }

/* ---- Buttons ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  min-height: 44px; padding: 0 var(--space-4); border-radius: var(--radius-m);
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  font-weight: 600; cursor: pointer; user-select: none; width: 100%;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--accent); }
.btn[disabled] { opacity: .55; pointer-events: none; }

/* ---- Inputs ---- */
.label { display: block; font-size: 13px; font-weight: 600; color: var(--text-2); margin: 0 0 var(--space-1); }
.input, .textarea, .select {
  width: 100%; min-height: 44px; padding: var(--space-2) var(--space-3);
  border: 1px solid var(--border); border-radius: var(--radius-m);
  background: var(--surface); color: var(--text);
}
.textarea { min-height: 110px; resize: vertical; line-height: 1.45; }
.input:focus, .textarea:focus, .select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ---- Chips / status ---- */
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px;
  border-radius: 999px; background: var(--surface-2); font-size: 12px; font-weight: 600; color: var(--text-2);
}
.chip-accent { background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent); }
.badge-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); }

/* ---- Feedback ---- */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tabbar-h) + var(--space-6) + env(safe-area-inset-bottom, 0px));
  background: var(--text); color: var(--bg); padding: var(--space-2) var(--space-4);
  border-radius: 999px; font-size: 13px; font-weight: 600; z-index: 50;
  opacity: 0; pointer-events: none; transition: opacity .18s ease;
}
.toast.show { opacity: 1; }
.skeleton {
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--border) 50%, var(--surface-2) 75%);
  background-size: 200% 100%; animation: shimmer 1.2s infinite linear;
  border-radius: var(--radius-s); min-height: 14px;
}
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
.spinner {
  width: 16px; height: 16px; border: 2px solid var(--border);
  border-top-color: var(--accent); border-radius: 50%;
  animation: spin .7s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }
.error-note { color: var(--danger); font-size: 13px; }
.demo-banner {
  display: flex; align-items: center; gap: var(--space-2);
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
  color: var(--text); border-radius: var(--radius-m);
  padding: var(--space-2) var(--space-3); font-size: 13px; margin: var(--space-3) 0;
}

/* ---- Empty state ---- */
.empty-state { text-align: center; padding: var(--space-8) var(--space-4); color: var(--muted); }
.empty-state .headline { font-size: 16px; font-weight: 650; color: var(--text-2); margin-bottom: var(--space-1); }

/* ---- Layout utilities ---- */
.container { max-width: 560px; margin: 0 auto; padding: 0 var(--space-4); }
.row { display: flex; align-items: center; gap: var(--space-3); }
.col { display: flex; flex-direction: column; gap: var(--space-3); }
.grow { flex: 1; min-width: 0; }
.mt-2 { margin-top: var(--space-2); } .mt-4 { margin-top: var(--space-4); }
.text-muted { color: var(--muted); } .text-small { font-size: 13px; }
.view { display: none; } .view.active { display: block; }

/* ---- RTL ---- */
[dir="rtl"] .appbar, [dir="rtl"] .row { flex-direction: row-reverse; }
