/* ═══════════════════════════════════════════════
   AEO-REX APP — Design System
   Mobile-first PWA for AI Visibility Tracking
   ═══════════════════════════════════════════════ */

:root {
  --bg: #0a0a12;
  --card: #12121e;
  --card-hover: #1a1a2e;
  --cyan: #00e5ff;
  --cyan-dim: rgba(0, 229, 255, 0.12);
  --cyan-border: rgba(0, 229, 255, 0.15);
  --red: #e94560;
  --red-dim: rgba(233, 69, 96, 0.12);
  --red-border: rgba(233, 69, 96, 0.2);
  --green: #22c55e;
  --green-dim: rgba(34, 197, 94, 0.12);
  --green-border: rgba(34, 197, 94, 0.2);
  --amber: #f59e0b;
  --amber-dim: rgba(245, 158, 11, 0.12);
  --amber-border: rgba(245, 158, 11, 0.2);
  --text: #ffffff;
  --muted: #8892a4;
  --border: rgba(255, 255, 255, 0.06);
  --font-body: 'Outfit', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
  --nav-height: 64px;
  --topbar-height: 60px;
}

/* ═══ RESET ═══ */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html { font-size: 18px; -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  padding-top: var(--topbar-height);
  padding-bottom: calc(var(--nav-height) + env(safe-area-inset-bottom, 0px));
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; border: none; background: none; }
input, select, textarea { font-family: inherit; font-size: inherit; }
img { display: block; max-width: 100%; }

/* ═══ TYPOGRAPHY ═══ */
h1 {
  font-size: 2rem;
  font-weight: 900;
  line-height: 1.15;
  letter-spacing: -0.02em;
}
h2 {
  font-size: 1.55rem;
  font-weight: 800;
  line-height: 1.2;
}
h3 {
  font-size: 1.22rem;
  font-weight: 700;
  line-height: 1.3;
}
p {
  color: var(--muted);
  line-height: 1.7;
}
.label {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  font-weight: 700;
  color: var(--cyan);
  text-transform: uppercase;
  letter-spacing: 0.15em;
}
.mono { font-family: var(--font-mono); }
.cyan { color: var(--cyan); }
.red { color: var(--red); }
.green { color: var(--green); }
.amber { color: var(--amber); }
.muted { color: var(--muted); }
.text-center { text-align: center; }

/* ═══ TOP BAR ═══ */
.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--topbar-height);
  background: var(--card);
  border-bottom: 1px solid var(--cyan-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  z-index: 100;
}
.topbar-logo {
  display: flex;
  align-items: center;
  gap: 12px;
}
.topbar-back {
  font-size: 2rem;
  color: var(--cyan);
  text-decoration: none;
  padding: 8px 12px;
  margin-right: 4px;
  line-height: 1;
  font-weight: 700;
  min-width: 48px;
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.topbar-logo img {
  width: 36px;
  height: 36px;
  border-radius: 50%;
}
.topbar-logo span {
  font-family: var(--font-mono);
  font-size: 1rem;
  font-weight: 700;
  color: var(--cyan);
  letter-spacing: 0.05em;
}
.topbar-biz {
  font-size: 0.75rem;
  color: var(--muted);
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ═══ BOTTOM NAV ═══ */
.bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: calc(var(--nav-height) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: var(--card);
  border-top: 1px solid var(--cyan-border);
  display: flex;
  align-items: center;
  justify-content: space-around;
  z-index: 100;
}
.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 0;
  min-width: 64px;
  color: var(--muted);
  transition: color 0.2s;
}
.nav-item.active { color: var(--cyan); }
.nav-icon { font-size: 1.4rem; line-height: 1; }
.nav-label { font-size: 0.6rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; }

/* ═══ PAGE CONTAINER ═══ */
.page {
  padding: 24px 20px;
  max-width: 600px;
  margin: 0 auto;
  width: 100%;
}
.page-full {
  padding: 24px 20px;
  width: 100%;
}

/* ═══ CARDS ═══ */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px;
  margin-bottom: 16px;
  width: 100%;
}
.card-cyan { border-color: var(--cyan-border); }
.card-red { border-color: var(--red-border); background: var(--red-dim); }
.card-green { border-color: var(--green-border); background: var(--green-dim); }
.card-amber { border-color: var(--amber-border); background: var(--amber-dim); }
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.card-title {
  font-size: 1.1rem;
  font-weight: 700;
}

/* ═══ SCORE RING ═══ */
.score-ring-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 32px 0;
}
.score-ring {
  position: relative;
  width: 200px;
  height: 200px;
}
.score-ring svg {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}
.score-ring-bg {
  fill: none;
  stroke: var(--card);
  stroke-width: 12;
}
.score-ring-fill {
  fill: none;
  stroke: var(--cyan);
  stroke-width: 12;
  stroke-linecap: round;
  stroke-dasharray: 565.48;
  stroke-dashoffset: 565.48;
  transition: stroke-dashoffset 1.5s ease-out;
}
.score-ring-fill.red { stroke: var(--red); }
.score-ring-fill.amber { stroke: var(--amber); }
.score-ring-fill.green { stroke: var(--green); }
.score-number {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.score-value {
  font-family: var(--font-mono);
  font-size: 3.5rem;
  font-weight: 700;
  line-height: 1;
}
.score-max {
  font-size: 0.85rem;
  color: var(--muted);
  margin-top: 4px;
}
.score-trend {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 16px;
  font-size: 1rem;
  font-weight: 600;
}
.trend-up { color: var(--green); }
.trend-down { color: var(--red); }
.trend-flat { color: var(--muted); }

/* ═══ TRAFFIC LIGHTS ═══ */
.platform-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 24px;
}
.platform-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px 16px;
  display: flex;
  align-items: center;
  gap: 14px;
}
.platform-card.full-width {
  grid-column: 1 / -1;
}
.platform-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  flex-shrink: 0;
}
.dot-green { background: var(--green); box-shadow: 0 0 8px var(--green); }
.dot-amber { background: var(--amber); box-shadow: 0 0 8px var(--amber); }
.dot-red { background: var(--red); box-shadow: 0 0 8px var(--red); }
.platform-name {
  font-size: 0.9rem;
  font-weight: 600;
}
.platform-status {
  font-size: 0.72rem;
  color: var(--muted);
  margin-top: 2px;
}

/* ═══ BUTTONS ═══ */
.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 56px;
  padding: 16px 24px;
  border-radius: 12px;
  font-size: 1rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  transition: opacity 0.2s, transform 0.1s;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.4; pointer-events: none; }

.btn-cyan {
  background: var(--cyan);
  color: #000;
}
.btn-cyan:hover { opacity: 0.85; }

.btn-outline {
  background: transparent;
  border: 2px solid var(--cyan-border);
  color: var(--cyan);
}
.btn-outline:hover { background: var(--cyan-dim); }

.btn-red {
  background: var(--red);
  color: #fff;
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
  min-height: 48px;
  text-transform: none;
  letter-spacing: 0;
  font-weight: 500;
}
.btn-ghost:hover { color: var(--text); }

.btn-sm {
  min-height: 44px;
  padding: 10px 16px;
  font-size: 0.78rem;
  border-radius: 8px;
}

.btn-row {
  display: flex;
  gap: 10px;
  margin-top: 16px;
}
.btn-row .btn { flex: 1; }

/* ═══ FORMS ═══ */
.form-group {
  margin-bottom: 20px;
  width: 100%;
}
.form-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 8px;
}
.form-input {
  width: 100%;
  min-height: 56px;
  padding: 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  font-size: 1rem;
  transition: border-color 0.2s;
}
.form-input:focus {
  outline: none;
  border-color: var(--cyan);
  box-shadow: 0 0 0 3px var(--cyan-dim);
}
.form-input::placeholder { color: rgba(136, 146, 164, 0.5); }

.form-select {
  width: 100%;
  min-height: 56px;
  padding: 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  font-size: 1rem;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%238892a4' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 16px center;
}
.form-select:focus {
  outline: none;
  border-color: var(--cyan);
}

.form-error {
  color: var(--red);
  font-size: 0.8rem;
  margin-top: 6px;
}

/* ═══ FIX CARDS ═══ */
.fix-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  margin-bottom: 12px;
  overflow: hidden;
  width: 100%;
}
.fix-header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 20px;
  cursor: pointer;
  user-select: none;
}
.fix-checkbox {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  border: 2px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.2s;
}
.fix-checkbox.checked {
  background: var(--green);
  border-color: var(--green);
}
.fix-checkbox.checked::after {
  content: '✓';
  color: #fff;
  font-size: 0.9rem;
  font-weight: 700;
}
.fix-title {
  flex: 1;
  font-size: 1rem;
  font-weight: 600;
}
.fix-title.completed {
  text-decoration: line-through;
  color: var(--muted);
}
.fix-badge {
  font-family: var(--font-mono);
  font-size: 0.6rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 6px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  flex-shrink: 0;
}
.badge-easy { background: var(--green-dim); color: var(--green); }
.badge-medium { background: var(--amber-dim); color: var(--amber); }
.badge-hard { background: var(--red-dim); color: var(--red); }
.fix-body {
  display: none;
  padding: 0 20px 20px;
  border-top: 1px solid var(--border);
}
.fix-body.open { display: block; padding-top: 20px; }
.fix-desc {
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.7;
  margin-bottom: 16px;
}
.fix-code {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--cyan);
  line-height: 1.6;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-all;
  margin-bottom: 16px;
  max-height: 200px;
  overflow-y: auto;
}

/* ═══ PROGRESS BAR ═══ */
.progress-wrap {
  margin-bottom: 24px;
}
.progress-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}
.progress-label {
  font-size: 0.85rem;
  font-weight: 600;
}
.progress-count {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--cyan);
}
.progress-bar {
  width: 100%;
  height: 8px;
  background: var(--card);
  border-radius: 4px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: var(--cyan);
  border-radius: 4px;
  transition: width 0.5s ease-out;
}

/* ═══ COMPETITOR BARS ═══ */
.comp-bar-wrap {
  margin: 16px 0;
}
.comp-bar-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}
.comp-bar-label {
  width: 80px;
  font-size: 0.78rem;
  font-weight: 600;
  text-align: right;
  flex-shrink: 0;
}
.comp-bar {
  flex: 1;
  height: 32px;
  border-radius: 8px;
  position: relative;
  overflow: hidden;
}
.comp-bar-fill {
  height: 100%;
  border-radius: 8px;
  display: flex;
  align-items: center;
  padding: 0 12px;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 700;
  min-width: 40px;
  transition: width 0.8s ease-out;
}
.comp-bar-you { background: var(--cyan); color: #000; }
.comp-bar-them { background: var(--red-dim); color: var(--red); border: 1px solid var(--red-border); }

/* ═══ EMPTY STATES ═══ */
.empty-state {
  text-align: center;
  padding: 48px 24px;
}
.empty-icon {
  font-size: 3rem;
  margin-bottom: 16px;
}
.empty-title {
  font-size: 1.2rem;
  font-weight: 700;
  margin-bottom: 8px;
}
.empty-desc {
  color: var(--muted);
  font-size: 0.9rem;
  margin-bottom: 24px;
  line-height: 1.6;
}

/* ═══ LOADING ═══ */
.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 24px;
  gap: 16px;
}
.spinner {
  width: 48px;
  height: 48px;
  border: 4px solid var(--border);
  border-top-color: var(--cyan);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text {
  color: var(--muted);
  font-size: 0.9rem;
}

/* ═══ TOAST ═══ */
.toast {
  position: fixed;
  bottom: calc(var(--nav-height) + 20px + env(safe-area-inset-bottom, 0px));
  left: 20px;
  right: 20px;
  background: var(--green);
  color: #000;
  padding: 16px 20px;
  border-radius: 12px;
  font-weight: 700;
  font-size: 0.9rem;
  text-align: center;
  z-index: 200;
  transform: translateY(100px);
  opacity: 0;
  transition: all 0.3s ease-out;
}
.toast.show {
  transform: translateY(0);
  opacity: 1;
}
.toast.error { background: var(--red); color: #fff; }

/* ═══ SECTION HEADERS ═══ */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}
.section-title {
  font-size: 1.22rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}
.section-action {
  font-size: 0.78rem;
  color: var(--cyan);
  font-weight: 600;
}

/* ═══ TIMESTAMP ═══ */
.timestamp {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--muted);
  text-align: center;
  margin-top: 12px;
}

/* ═══ DIVIDER ═══ */
.divider {
  height: 1px;
  background: var(--border);
  margin: 24px 0;
}

/* ═══ LOGIN PAGE ═══ */
.login-page {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 24px;
}
.login-page body { padding: 0; }
.login-logo {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  margin-bottom: 24px;
}
.login-title {
  font-size: 1.8rem;
  font-weight: 900;
  text-align: center;
  margin-bottom: 8px;
}
.login-sub {
  color: var(--muted);
  text-align: center;
  margin-bottom: 40px;
  font-size: 1rem;
}
.login-form {
  width: 100%;
  max-width: 400px;
}
.login-toggle {
  text-align: center;
  margin-top: 24px;
  color: var(--muted);
  font-size: 0.9rem;
}
.login-toggle a {
  color: var(--cyan);
  font-weight: 600;
}
.login-skip {
  text-align: center;
  margin-top: 16px;
}

/* ═══ PWA INSTALL BANNER ═══ */
.install-banner {
  display: none;
  background: var(--cyan-dim);
  border: 1px solid var(--cyan-border);
  border-radius: 12px;
  padding: 16px 20px;
  margin-bottom: 20px;
  align-items: center;
  gap: 12px;
}
.install-banner.show { display: flex; }
.install-text {
  flex: 1;
  font-size: 0.85rem;
  font-weight: 500;
}
.install-text strong { color: var(--cyan); }
.install-btn {
  background: var(--cyan);
  color: #000;
  font-weight: 700;
  font-size: 0.75rem;
  padding: 10px 16px;
  border-radius: 8px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
}
.install-dismiss {
  color: var(--muted);
  font-size: 1.2rem;
  padding: 4px;
  line-height: 1;
}

/* ═══ SETTINGS LINKS ═══ */
.settings-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 0;
  border-bottom: 1px solid var(--border);
  font-size: 1rem;
  font-weight: 600;
  min-height: 56px;
}
.settings-link:last-child { border-bottom: none; }

.settings-form .btn { margin-top: 8px; }

/* ═══ ANIMATIONS ═══ */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}
.fade-in { animation: fadeIn 0.4s ease-out forwards; }
.fade-in-delay-1 { animation-delay: 0.1s; opacity: 0; }
.fade-in-delay-2 { animation-delay: 0.2s; opacity: 0; }
.fade-in-delay-3 { animation-delay: 0.3s; opacity: 0; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}
.pulse { animation: pulse 2s ease-in-out infinite; }

/* ═══ RESPONSIVE ═══ */
@media (min-width: 768px) {
  html { font-size: 20px; }
  .page { max-width: 700px; padding: 32px 24px; }
  .score-ring { width: 240px; height: 240px; }
  .score-value { font-size: 4rem; }
  .platform-grid { grid-template-columns: 1fr 1fr 1fr; }
  h1 { font-size: 2.4rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
