/* puregrain-cf-app-base — Design System
   Dark space theme. Import this in every page. */

:root {
  --bg:       #000008;
  --panel:    #0b0b1f;
  --panel-2:  #12122e;
  --line:     #1e2044;
  --text:     #e8e4c8;
  --muted:    #6878a0;
  --accent:   #ef6008;   /* orange — CTAs, prices, primary actions */
  --accent-2: #4db8ff;   /* blue  — AI, links, member elements    */
  --success:  #4dc864;
  --warning:  #f0b030;
  --danger:   #e04040;
  --radius:   10px;
  --radius-sm: 6px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 15px;
  line-height: 1.5;
  min-height: 100vh;
}

a { color: var(--accent-2); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Starfield canvas ────────────────────────────────────────────────────────── */
#starfield { position: fixed; inset: 0; z-index: -1; pointer-events: none; }

/* ── Layout ──────────────────────────────────────────────────────────────────── */
.container { max-width: 960px; margin: 0 auto; padding: 0 16px; }
.container-wide { max-width: 1200px; margin: 0 auto; padding: 0 16px; }

/* ── Top nav ─────────────────────────────────────────────────────────────────── */
.topnav {
  background: linear-gradient(180deg, #000008 0%, #0d0d28 100%);
  border-bottom: 1px solid var(--line);
  padding: 0 20px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
}
.topnav-brand { font-size: 1rem; font-weight: 700; color: var(--accent); letter-spacing: .08em; text-transform: uppercase; text-decoration: none; }
.topnav-brand:hover { text-decoration: none; }
.topnav-right { display: flex; align-items: center; gap: 16px; font-size: .88rem; color: var(--muted); }
.topnav-right a { color: var(--muted); }
.topnav-right a:hover { color: var(--text); text-decoration: none; }

/* ── Page header ─────────────────────────────────────────────────────────────── */
.page-header {
  background: radial-gradient(ellipse 90% 55% at 50% 0%, rgba(239,96,8,.09) 0%, transparent 70%),
              linear-gradient(180deg, #000008 0%, #0d0d28 100%);
  border-bottom: 1px solid rgba(239,96,8,.15);
  padding: 32px 20px 28px;
  text-align: center;
}
.page-header h1 { font-size: clamp(1.4rem, 4vw, 2.2rem); color: var(--accent); letter-spacing: .08em; text-transform: uppercase; text-shadow: 0 0 40px rgba(239,96,8,.4); margin-bottom: 8px; }
.page-header p  { font-size: .9rem; color: var(--muted); max-width: 480px; margin: 0 auto; }

/* ── Cards ───────────────────────────────────────────────────────────────────── */
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
}
.card:hover { border-color: rgba(239,96,8,.35); }
.card-hover {
  cursor: pointer;
  transition: border-color .15s, transform .1s, box-shadow .15s;
}
.card-hover:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: 0 4px 28px rgba(239,96,8,.15);
}

/* ── Grid ────────────────────────────────────────────────────────────────────── */
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
@media (max-width: 700px) { .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; } }
@media (max-width: 900px) { .grid-4 { grid-template-columns: repeat(2, 1fr); } }

/* ── Buttons ─────────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 18px; border-radius: var(--radius-sm); font-size: .9rem; font-weight: 600;
  cursor: pointer; border: none; transition: opacity .15s, transform .1s;
  text-decoration: none; line-height: 1;
}
.btn:hover { opacity: .88; transform: translateY(-1px); text-decoration: none; }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: .45; cursor: default; transform: none; }

.btn-primary   { background: var(--accent);   color: #000008; }
.btn-secondary { background: var(--panel-2);  color: var(--text); border: 1px solid var(--line); }
.btn-blue      { background: var(--accent-2); color: #000014; }
.btn-danger    { background: var(--danger);   color: #fff; }
.btn-ghost     { background: transparent; color: var(--muted); border: 1px solid var(--line); }
.btn-ghost:hover { color: var(--text); border-color: var(--muted); }
.btn-sm { padding: 6px 12px; font-size: .82rem; }
.btn-lg { padding: 12px 28px; font-size: 1rem; }
.btn-full { width: 100%; }

/* ── Form inputs ─────────────────────────────────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.form-label { font-size: .85rem; color: var(--muted); font-weight: 500; }
.form-input, .form-select, .form-textarea {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  color: var(--text);
  font-size: .95rem;
  width: 100%;
  transition: border-color .15s;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
  outline: none;
  border-color: var(--accent);
}
.form-input::placeholder, .form-textarea::placeholder { color: var(--muted); opacity: .7; }
.form-select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%236878a0' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 30px; }
.form-textarea { resize: vertical; min-height: 80px; }
.form-hint { font-size: .8rem; color: var(--muted); }
.form-error { font-size: .82rem; color: var(--danger); min-height: 18px; }

/* ── Badges ──────────────────────────────────────────────────────────────────── */
.badge { display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 20px; font-size: .72rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; }
.badge-orange { background: rgba(239,96,8,.18); color: var(--accent); border: 1px solid rgba(239,96,8,.35); }
.badge-blue   { background: rgba(77,184,255,.12); color: var(--accent-2); border: 1px solid rgba(77,184,255,.3); }
.badge-green  { background: rgba(77,200,100,.12); color: var(--success); border: 1px solid rgba(77,200,100,.3); }
.badge-yellow { background: rgba(240,176,48,.12); color: var(--warning); border: 1px solid rgba(240,176,48,.3); }
.badge-red    { background: rgba(224,64,64,.12);  color: var(--danger);  border: 1px solid rgba(224,64,64,.3); }
.badge-muted  { background: var(--panel-2); color: var(--muted); border: 1px solid var(--line); }

/* ── Status chip (dot + label) ───────────────────────────────────────────────── */
.status-chip { display: inline-flex; align-items: center; gap: 5px; font-size: .78rem; color: var(--muted); }
.status-chip::before { content: ''; width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
.status-chip.active::before   { background: var(--success); }
.status-chip.warning::before  { background: var(--warning); }
.status-chip.inactive::before { background: var(--muted); opacity: .5; }
.status-chip.danger::before   { background: var(--danger); }

/* ── Tables ──────────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--line); }
table { width: 100%; border-collapse: collapse; }
th { background: var(--panel-2); color: var(--muted); font-size: .78rem; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--line); }
td { padding: 11px 14px; border-bottom: 1px solid var(--line); font-size: .9rem; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(255,255,255,.025); }

/* ── Modal ───────────────────────────────────────────────────────────────────── */
.modal { position: fixed; inset: 0; z-index: 800; background: rgba(0,0,8,.75); display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal-box { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 28px 24px; max-width: 440px; width: 100%; position: relative; }
.modal-title { font-size: 1.1rem; font-weight: 700; margin-bottom: 16px; }
.modal-close { position: absolute; top: 14px; right: 14px; background: none; border: none; color: var(--muted); font-size: 1.1rem; cursor: pointer; padding: 4px 8px; border-radius: var(--radius-sm); }
.modal-close:hover { color: var(--text); background: var(--panel-2); }

/* ── Toast notifications ─────────────────────────────────────────────────────── */
#toast-container { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 1000; display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
.toast {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 20px;
  font-size: .92rem;
  color: var(--text);
  box-shadow: 0 4px 24px rgba(0,0,0,.5);
  pointer-events: auto;
  animation: toast-in .25s ease;
  white-space: nowrap;
}
.toast.ok      { border-color: rgba(77,200,100,.5); }
.toast.err     { border-color: rgba(224,64,64,.5); color: #f08080; }
.toast.warning { border-color: rgba(240,176,48,.5); }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

/* ── Empty state ─────────────────────────────────────────────────────────────── */
.empty { color: var(--muted); text-align: center; padding: 60px 20px; }
.empty-icon { font-size: 2.5rem; margin-bottom: 12px; }
.empty p { font-size: .95rem; line-height: 1.6; }

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

/* ── Divider ─────────────────────────────────────────────────────────────────── */
hr { border: none; border-top: 1px solid var(--line); margin: 20px 0; }
.divider-text { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: .82rem; margin: 16px 0; }
.divider-text::before, .divider-text::after { content: ''; flex: 1; border-top: 1px solid var(--line); }

/* ── Utility ─────────────────────────────────────────────────────────────────── */
.text-muted   { color: var(--muted); }
.text-accent  { color: var(--accent); }
.text-accent2 { color: var(--accent-2); }
.text-success { color: var(--success); }
.text-danger  { color: var(--danger); }
.text-sm  { font-size: .85rem; }
.text-xs  { font-size: .75rem; }
.text-lg  { font-size: 1.1rem; }
.bold     { font-weight: 700; }
.center   { text-align: center; }
.flex     { display: flex; }
.flex-col { display: flex; flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-4  { gap: 4px; }
.gap-8  { gap: 8px; }
.gap-12 { gap: 12px; }
.gap-16 { gap: 16px; }
.mt-4   { margin-top: 4px; }
.mt-8   { margin-top: 8px; }
.mt-16  { margin-top: 16px; }
.mt-24  { margin-top: 24px; }
.mb-4   { margin-bottom: 4px; }
.mb-8   { margin-bottom: 8px; }
.mb-12  { margin-bottom: 12px; }
.mb-16  { margin-bottom: 16px; }
.mb-24  { margin-bottom: 24px; }
.hidden { display: none !important; }

/* ── Mobile bottom nav ───────────────────────────────────────────────────────── */
/* Standard pattern for all PureGrain apps. Always include in the authenticated   */
/* app shell. Primary tabs (4 max) + a "More" button that opens a bottom drawer.  */
:root { --mobile-nav-height: 60px; }

.mobile-nav {
  display: none;
  position: fixed; bottom: 0; left: 0; right: 0;
  height: var(--mobile-nav-height);
  background: var(--panel); border-top: 1px solid var(--line);
  z-index: 500; align-items: stretch; padding-bottom: env(safe-area-inset-bottom);
}
.mobile-nav-item {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; color: var(--muted); text-decoration: none; font-size: .62rem; font-weight: 500;
  padding: 6px 2px; cursor: pointer; border: none; background: none; transition: color .15s;
  letter-spacing: .01em;
}
.mobile-nav-item:hover, .mobile-nav-item.active { color: var(--accent); text-decoration: none; }
.mobile-nav-icon { font-size: 1.15rem; line-height: 1; }

/* More drawer — slides up from bottom */
.mobile-drawer-overlay {
  position: fixed; inset: 0; background: rgba(0,0,8,.65); z-index: 600;
  animation: fade-in .18s ease;
}
.mobile-drawer {
  position: fixed; bottom: var(--mobile-nav-height); left: 0; right: 0;
  background: var(--panel); border-top: 1px solid var(--line);
  border-radius: 16px 16px 0 0; z-index: 601; padding: 6px 0 12px;
  animation: drawer-up .2s cubic-bezier(.4,0,.2,1);
}
.mobile-drawer-handle {
  width: 36px; height: 4px; background: var(--line); border-radius: 2px;
  margin: 8px auto 12px;
}
.mobile-drawer-item {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 24px; color: var(--text); font-size: .95rem; text-decoration: none;
  cursor: pointer; border: none; background: none; width: 100%; text-align: left;
}
.mobile-drawer-item:hover { background: rgba(255,255,255,.04); text-decoration: none; }
.mobile-drawer-item .mobile-nav-icon { font-size: 1.1rem; }

@keyframes fade-in  { from { opacity: 0; } to { opacity: 1; } }
@keyframes drawer-up { from { transform: translateY(100%); } to { transform: translateY(0); } }

/* ── Pull-to-refresh indicator ───────────────────────────────────────────── */
/* Controlled by initPullToRefresh() in app.js. Required on every PWA page.  */
#ptr {
  position: fixed; top: -52px; left: 0; right: 0;
  display: flex; justify-content: center; padding-top: 8px;
  z-index: 9999; pointer-events: none; opacity: 0;
}
.ptr-icon {
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--accent); color: #000; font-size: 1.1rem; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 16px rgba(0,0,0,.5);
}
#ptr.ptr-ready .ptr-icon { background: var(--accent-2); color: #000; }
#ptr.ptr-loading .ptr-icon { animation: ptr-spin .6s linear infinite; }
@keyframes ptr-spin { to { transform: rotate(360deg); } }

@media (max-width: 700px) {
  .mobile-nav { display: flex; }
  /* Push page content above nav */
  .app-content { padding-bottom: calc(var(--mobile-nav-height) + 20px); }
  /* Lift Cosmo FAB and panel above the mobile nav */
  #cosmo-fab   { bottom: calc(var(--mobile-nav-height) + 14px) !important; }
  #cosmo-panel { bottom: calc(var(--mobile-nav-height) + 82px) !important; max-height: calc(100svh - var(--mobile-nav-height) - 100px) !important; }
}
