:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --line: #e5e7eb;
  --text: #0f172a;
  --muted: #64748b;
  --brand: #4f46e5;
  --brand-soft: #eef2ff;
  --success: #16a34a;
  --warn: #f59e0b;
  --danger: #ef4444;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Inter", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--text);
  background: #f3f6fa;
}

.index-wrap {
  padding: 24px;
  max-width: 1720px;
  margin: 0 auto;
}

.index-title {
  font-size: 28px;
  font-weight: 800;
  margin: 0 0 8px;
}

.index-sub {
  color: var(--muted);
  margin: 0 0 24px;
}

.preview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 18px;
}

.preview-card {
  background: #fff;
  border-radius: 18px;
  border: 1px solid #e2e8f0;
  padding: 12px;
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.08);
}

.preview-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.preview-name {
  font-size: 14px;
  font-weight: 700;
}

.preview-file {
  font-size: 12px;
  color: var(--muted);
}

.phone-frame {
  width: 100%;
  aspect-ratio: 9 / 19.5;
  border-radius: 28px;
  border: 8px solid #111827;
  background: #fff;
  overflow: hidden;
  position: relative;
}

.phone-frame::before {
  content: "";
  position: absolute;
  top: 4px;
  left: 50%;
  width: 120px;
  height: 20px;
  transform: translateX(-50%);
  background: #111827;
  border-radius: 999px;
  z-index: 2;
}

.phone-frame iframe {
  width: 100%;
  height: 100%;
  border: 0;
  background: #fff;
}

.app {
  min-height: 100vh;
  background: #f5f7fb;
}

/* Page title bar: frozen at top while content scrolls (iframe + phone-shell). */
.app > header {
  position: sticky;
  top: 0;
  z-index: 20;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

/*
 * Standalone pages (phone-shell.js): same viewport as index .phone-frame > iframe.
 * .app scrolls; .bottom-nav sits at the bottom inside the shell.
 */
html.standalone-page {
  height: 100%;
}

html.standalone-page body {
  margin: 0;
  min-height: 100%;
}

.phone-shell {
  --shell-w: min(430px, calc((100vh - 24px) * 9 / 19.5));
  width: var(--shell-w);
  height: calc(var(--shell-w) * 19.5 / 9);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
  border-radius: 28px;
  border: 8px solid #111827;
  background: #fff;
  box-shadow: 0 14px 30px rgba(15, 23, 42, 0.18);
  flex-shrink: 0;
}

.phone-shell::before {
  content: "";
  position: absolute;
  top: 4px;
  left: 50%;
  width: 120px;
  height: 20px;
  transform: translateX(-50%);
  background: #111827;
  border-radius: 999px;
  z-index: 30;
  pointer-events: none;
}

.phone-shell > .app {
  flex: 1 1 auto;
  width: 100%;
  min-height: 0;
  margin: 0;
  position: relative;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.phone-shell > .app::-webkit-scrollbar {
  display: none;
}

.phone-shell > .app .fixed {
  position: absolute;
}

/* Chat page: flex column so composer sits above bottom nav (iframe + standalone). */
.app.chat-app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  padding-bottom: 3.5rem;
}

.phone-shell > .app.chat-app {
  min-height: 0;
  overflow: hidden;
  padding-bottom: 0;
}

.app.chat-app > .chat-thread {
  flex: 1 1 auto;
  min-height: 0;
}

.phone-shell > .bottom-nav {
  position: relative;
  left: auto;
  right: auto;
  bottom: auto;
  transform: none;
  flex: 0 0 auto;
  width: 100%;
  max-width: none;
  z-index: 20;
}

@media (min-width: 700px) {
  html.standalone-page body {
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 12px;
    background: radial-gradient(circle at top, #eef2ff, #f8fafc 45%, #f1f5f9);
  }
}

@media (max-width: 699px) {
  html.standalone-page,
  html.standalone-page body {
    height: 100%;
    min-height: 100dvh;
  }

  html.standalone-page body {
    padding: 0;
    background: #f5f7fb;
  }

  .phone-shell {
    width: 100%;
    height: 100%;
    min-height: 100dvh;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .phone-shell::before {
    display: none;
  }
}

.hero-banner {
  border-radius: 16px;
  padding: 14px;
  color: #fff;
  background: linear-gradient(120deg, #2563eb, #3b82f6);
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 11px;
  font-weight: 600;
}

.chip-soft {
  background: var(--brand-soft);
  color: #4338ca;
}

.chip-ok {
  background: #ecfdf3;
  color: #047857;
}

.chip-warn {
  background: #fff7ed;
  color: #c2410c;
}

.card {
  background: var(--surface);
  border-radius: 16px;
  border: 1px solid var(--line);
  box-shadow: 0 3px 12px rgba(15, 23, 42, 0.04);
}

/* Bottom action bar inside scrollable .app (not viewport-fixed) */
.page-footer-actions {
  margin-top: 0.5rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--line);
  background: #fff;
}

.bottom-nav {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 0;
  width: min(100%, 430px);
  border-top: 1px solid #e2e8f0;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(8px);
}

.tab-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  color: #64748b;
  font-size: 10px;
}

.tab-btn.active {
  color: #4f46e5;
  font-weight: 700;
}

a.tab-btn {
  text-decoration: none;
  color: inherit;
}

.metric-bar {
  height: 8px;
  border-radius: 999px;
  background: #e2e8f0;
  overflow: hidden;
}

.metric-fill {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #4f46e5, #7c3aed);
}
