/* ============================================================
   Tokverse Studio — shared APP design system (light theme)
   Mirrors the marketing site's brand: white surfaces, soft
   shadows, signature cyan→blue→purple→pink gradient, brand logo.
   Used by every in-app page (create, dashboard, library,
   products, learnings, characters, analytics).
   ============================================================ */
:root {
  --ink:    #1a202c;
  --slate:  #4a5568;
  --muted:  #718096;
  --line:   #e2e8f0;
  --bg:     #f3f7fd;
  --bg-soft:#f8f9fc;
  --card:   #ffffff;

  --cyan:   #00d4ff;
  --teal:   #13b9d6;
  --aqua:   #06e8d8;
  --pink:   #ff006e;
  --magenta:#ff2d9e;

  --grad:       linear-gradient(135deg,#00d4ff 0%,#13b9d6 45%,#ff006e 100%);
  --brand-text: linear-gradient(90deg,#06e8d8 0%,#13b9d6 42%,#ff0a5e 100%);
  --side-grad:  linear-gradient(120deg,#06c2d4 0%,#0a90b0 22%,#2a4f82 52%,#7a2767 80%,#d11663 100%);

  --shadow-sm: 0 2px 8px rgba(20,30,55,0.06);
  --shadow-md: 0 12px 32px rgba(20,30,55,0.10);
  --radius: 14px;
}

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

body {
  font-family: 'Satoshi','Inter','Segoe UI',-apple-system,BlinkMacSystemFont,sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  display: flex;
  align-items: flex-start;
  min-height: 100vh;
}
a { color: inherit; text-decoration: none; }

/* ---- Left sidebar (signature brand-gradient background) ---- */
.top {
  display: flex; flex-direction: column; align-items: stretch; gap: 4px;
  width: 220px; flex-shrink: 0;
  height: 100vh; position: sticky; top: 0;
  padding: 18px 14px;
  background: var(--side-grad);
  box-shadow: 2px 0 18px rgba(8,40,90,0.16);
  overflow-y: auto; z-index: 20;
}

/* brand logo — 3D-spinning icon above wordmark (white on the gradient) */
.brand {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  font-weight: 800; font-size: 1.12rem; letter-spacing: -0.5px; line-height: 1;
  color: #fff; -webkit-text-fill-color: #fff;
  padding-bottom: 15px; margin-bottom: 8px;
  border-bottom: 1px solid rgba(255,255,255,0.16);
}
.brand img {
  height: 44px; width: auto; display: block;
  animation: logoSpin 8s linear infinite; transform-origin: center center;
}
@keyframes logoSpin {
  from { transform: perspective(500px) rotateY(0deg); }
  to   { transform: perspective(500px) rotateY(-360deg); }
}

.nav { display: flex; flex-direction: column; gap: 3px; width: 100%; }
.nav a {
  color: rgba(255,255,255,0.85); font-size: .9rem; font-weight: 700;
  padding: 10px 14px; border-radius: 9px; border-left: 3px solid transparent;
  transition: background .18s, color .18s, border-color .18s;
}
.nav a.active, .nav a:hover { background: rgba(255,255,255,0.18); color: #fff; border-left-color: #fff; }

/* ---- Main column beside the sidebar (top action bar + content) ---- */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

/* top action bar: credits / top-up / account / logout — right aligned, light */
.topbar {
  display: flex; align-items: center; justify-content: flex-end; gap: 11px;
  padding: 11px 22px;
  background: rgba(255,255,255,0.9);
  backdrop-filter: saturate(180%) blur(12px); -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 15; min-height: 58px;
}
.spacer { flex: 1; }
.pill {
  background: #fff; border: 1px solid var(--line); color: var(--slate);
  padding: 6px 13px; border-radius: 999px; font-size: .85rem; box-shadow: var(--shadow-sm);
}
.pill b { color: var(--teal); }
.topbar button, .topbar .btn-ghost {
  background: #fff; color: var(--slate); border: 1px solid var(--line);
  border-radius: 10px; padding: 8px 14px; font: inherit; font-size: .85rem; cursor: pointer;
  transition: border-color .18s, box-shadow .18s;
}
.topbar button:hover, .topbar .btn-ghost:hover { border-color: var(--cyan); box-shadow: var(--shadow-sm); }

/* ---- Hamburger + scrim (injected by appnav.js; hidden on desktop) ---- */
.navtoggle { display: none; }
.navscrim  { display: none; }

/* ---- Responsive: sidebar becomes an off-canvas drawer ----
   It used to reflow into a wrapped row of 12 nav links pinned to the top of the
   page, which ate most of a phone's first screen before any content. Now it
   slides in over the content and the nav keeps its readable vertical list. */
@media (max-width: 820px) {
  .top {
    position: fixed; top: 0; left: 0; z-index: 40;
    width: min(78vw, 264px); height: 100dvh;
    transform: translateX(-100%);
    transition: transform .26s cubic-bezier(.22,1,.36,1);
    box-shadow: 4px 0 30px rgba(8,40,90,0.28);
  }
  body.nav-open .top { transform: none; }

  .navscrim {
    display: block; position: fixed; inset: 0; z-index: 35;
    background: rgba(10,25,50,0.5);
    opacity: 0; pointer-events: none; transition: opacity .26s ease;
    -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px);
  }
  body.nav-open .navscrim { opacity: 1; pointer-events: auto; }
  body.nav-open { overflow: hidden; }

  .navtoggle {
    display: inline-flex; align-items: center; justify-content: center;
    margin-right: auto;                 /* push the rest of the topbar right */
    width: 42px; height: 42px; padding: 0;
    background: #fff; border: 1px solid var(--line); border-radius: 10px;
    box-shadow: var(--shadow-sm);
  }
  .navtoggle span {
    position: relative; display: block; width: 18px; height: 2px; border-radius: 2px;
    background: var(--slate);
  }
  .navtoggle span::before, .navtoggle span::after {
    content: ''; position: absolute; left: 0; width: 18px; height: 2px; border-radius: 2px;
    background: var(--slate);
  }
  .navtoggle span::before { top: -6px; }
  .navtoggle span::after  { top:  6px; }

  /* the nav links are the primary touch target here — give them real height */
  .nav a { padding: 13px 14px; font-size: .95rem; }

  /* The drawer is off-screen most of the time; don't spin the logo into an
     empty compositor layer for nothing. */
  body:not(.nav-open) .brand img { animation: none; }

  /* hamburger + credits + account + log out don't fit one 390px row */
  .topbar { padding: 9px 14px; gap: 8px; flex-wrap: wrap; }
  #userPill { max-width: 40vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .wrap   { padding: 18px 14px 56px; }
}

/* Touch devices can't hover, and the transform makes buttons feel jumpy. */
@media (hover: none) {
  .btn-primary:hover { transform: none; }
}

/* ---- Layout ---- */
.wrap { max-width: 1040px; margin: 0 auto; padding: 26px 22px 60px; width: 100%; }
h2 { font-size: 1.06rem; font-weight: 800; color: var(--ink); margin: 8px 0 15px; letter-spacing: -0.3px; }

/* ---- Cards ---- */
.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px; margin-bottom: 13px;
  box-shadow: var(--shadow-sm);
}
.empty { color: var(--muted); font-size: .9rem; padding: 18px 4px; text-align: center; }

/* ---- Default buttons (inside cards) ---- */
button {
  font: inherit; cursor: pointer; border-radius: 9px;
  background: #fff; color: var(--slate); border: 1px solid var(--line);
  padding: 8px 13px; font-size: .85rem; transition: border-color .18s, box-shadow .18s;
}
button:hover { border-color: var(--teal); box-shadow: var(--shadow-sm); }
.btn-primary {
  background: var(--grad); color: #fff; border: none; font-weight: 800;
  box-shadow: 0 10px 26px rgba(0,212,255,0.26);
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 14px 32px rgba(255,0,110,0.28); }
.btn-primary:disabled { opacity: .55; cursor: not-allowed; transform: none; }

/* ---- Form controls ---- */
label { display: block; font-size: .78rem; font-weight: 600; color: var(--slate); margin: 12px 0 5px; }
input, select, textarea {
  width: 100%; padding: 10px 12px; font-size: .92rem; font-family: inherit;
  color: var(--ink); background: #fff; border: 1px solid var(--line);
  border-radius: 9px; outline: none; transition: border-color .18s, box-shadow .18s;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--teal); box-shadow: 0 0 0 3px rgba(19,185,214,0.14);
}
textarea { resize: vertical; }

/* ---- Tables ---- */
table { width: 100%; border-collapse: collapse; font-size: .88rem; }
th, td { text-align: left; padding: 10px 11px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 700; font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; }

/* On a phone a multi-column table is wider than the viewport, and without this
   the whole PAGE scrolled sideways instead of just the table. `display:block`
   makes the table its own scroll container; rows still lay out as a table via
   the anonymous table box. Applies to dynamically-rendered tables too, which a
   JS wrapper would miss. */
@media (max-width: 820px) {
  table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  th, td { white-space: nowrap; }
}

/* ---- KPI tiles ---- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit,minmax(150px,1fr)); gap: 14px; }
.kpi {
  position: relative; overflow: hidden; background: var(--card);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 17px;
  box-shadow: var(--shadow-sm);
}
.kpi::before { content:''; position:absolute; top:0; left:0; right:0; height:3px; background: var(--grad); }
.kpi .n { font-size: 1.7rem; font-weight: 800; color: var(--ink); line-height: 1; }
.kpi .l { font-size: .75rem; color: var(--muted); font-weight: 600; margin-top: 6px; text-transform: uppercase; letter-spacing: .04em; }
.kpi.done .n { color: #059669; } .kpi.failed .n { color: #dc2626; } .kpi.running .n { color: #2563eb; }

/* ---- Job rows ---- */
.job { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; margin-bottom: 9px; box-shadow: var(--shadow-sm); }
.job-row { display: flex; align-items: center; gap: 10px; }
.job-row .t { font-weight: 700; flex: 1; color: var(--ink); }
.meta { font-size: .76rem; color: var(--muted); margin-top: 5px; }

/* ---- Status badges ---- */
.badge { font-size: .7rem; padding: 3px 9px; border-radius: 999px; font-weight: 800; text-transform: uppercase; letter-spacing: .03em; }
.b-queued  { background: #e0f2fe; color: #075985; }
.b-running { background: #dbeafe; color: #1d4ed8; }
.b-done    { background: #d1fae5; color: #065f46; }
.b-failed  { background: #fee2e2; color: #b91c1c; }

/* ---- Pipeline stage chips ---- */
.stages { display: flex; gap: 5px; margin-top: 9px; flex-wrap: wrap; }
.stages .st { font-size: .68rem; font-weight: 700; padding: 3px 9px; border-radius: 7px; background: var(--bg-soft); color: var(--muted); border: 1px solid var(--line); }
.stages .st.act  { background: #e0f7ff; color: #0369a1; border-color: #bae6fd; }
.stages .st.ok   { background: #d1fae5; color: #065f46; border-color: #a7f3d0; }
.stages .st.fail { background: #fee2e2; color: #b91c1c; border-color: #fecaca; }

/* ---- Error banner ---- */
.err { display:none; margin-top:12px; background:#fff1f2; border:1px solid #fecdd3; color:#be123c; padding:10px 13px; border-radius:9px; font-size:.83rem; }
.err.show { display:block; }

/* ---- Preview / demo mode (sample-data banner + top-bar toggle) ---- */
.preview-banner { display:flex; align-items:center; gap:10px; flex-wrap:wrap; font-size:.82rem; line-height:1.4;
  padding:10px 18px; background:#fff7ed; border-bottom:1px solid #fed7aa; color:#9a3412; }
.preview-banner b { color:#7c2d12; }
.preview-banner button { margin-left:auto; font-size:.74rem; padding:5px 11px; border:1px solid #fdba74;
  background:#fff; color:#9a3412; border-radius:8px; cursor:pointer; }
.preview-pill { background:#fff7ed; color:#9a3412; border:1px solid #fed7aa; border-radius:999px;
  padding:6px 13px; font-size:.8rem; font-weight:700; cursor:pointer; }
.preview-pill.on { background:var(--grad); color:#fff; border:none; }

/* ---- Onboarding "How to start" card (dismissible) ---- */
.howto { display:flex; align-items:center; gap:14px; flex-wrap:wrap; position:relative; overflow:hidden;
  background:var(--card); border:1px solid var(--line); border-radius:var(--radius);
  padding:15px 18px; margin-bottom:14px; box-shadow:var(--shadow-sm); }
.howto::before { content:''; position:absolute; top:0; left:0; bottom:0; width:3px; background:var(--grad); }
.howto .hicon { width:38px; height:38px; border-radius:11px; background:#e7f8fb;
  display:flex; align-items:center; justify-content:center; font-size:17px; flex-shrink:0; }
.howto .ht { flex:1; min-width:200px; }
.howto .ht b { font-size:.95rem; color:var(--ink); }
.howto .ht span { display:block; font-size:.78rem; color:var(--muted); margin-top:2px; line-height:1.45; }
.howto .hgo { background:var(--grad); color:#fff; border:none; font-weight:800; border-radius:10px;
  padding:9px 16px; font-size:.85rem; text-decoration:none; box-shadow:0 8px 20px rgba(0,212,255,0.22); }
.howto .hx { background:none; border:none; color:var(--muted); font-size:1rem; cursor:pointer; padding:4px 8px; }
.howto .hx:hover { color:var(--ink); box-shadow:none; }

/* ---- Inline SVG chart card (CSP-safe, no external libs) ---- */
.chartcard svg { width:100%; height:auto; display:block; }

/* ---- Video grid (library) ---- */
.grid { display: grid; grid-template-columns: repeat(auto-fill,minmax(180px,1fr)); gap: 14px; }
.vid { background: var(--card); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; box-shadow: var(--shadow-sm); }
.vid video, .vid .ph { width: 100%; aspect-ratio: 9/16; background: #eef3fb; object-fit: cover; display: block; }
.vid .ph { display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: .8rem; }
.vid .ph.demo-thumb { background-size: cover; background-position: center; }
.vid .ph.demo-thumb .demo-play { width: 46px; height: 46px; border-radius: 50%; background: rgba(255,255,255,.88);
  display: flex; align-items: center; justify-content: center; font-size: 1.1rem; color: var(--ink);
  box-shadow: 0 4px 14px rgba(0,0,0,.18); }
.vid .c { padding: 9px 11px; font-size: .82rem; color: var(--ink); }
.bar { font-size: .76rem; color: var(--teal); font-weight: 600; }
