/* ============================================================
   AI Niche Finder SaaS — Main Stylesheet
   ============================================================ */

:root {
  --primary:     #6366f1;
  --primary-dark:#4f46e5;
  --primary-light:#e0e7ff;
  --success:     #10b981;
  --warning:     #f59e0b;
  --danger:      #ef4444;
  --info:        #3b82f6;
  --bg:          #f8fafc;
  --surface:     #ffffff;
  --border:      #e2e8f0;
  --text:        #1e293b;
  --text-muted:  #64748b;
  --radius:      10px;
  --shadow:      0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
  --shadow-md:   0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.05);
}

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

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

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

/* ── Layout ────────────────────────────────────────────────── */
.container { max-width: 1100px; margin: 0 auto; padding: 0 1.5rem; }
.main-content { padding: 2rem 0 4rem; }

/* ── Navigation ────────────────────────────────────────────── */
.app-nav {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 100;
  box-shadow: var(--shadow);
}
.nav-container {
  max-width: 1100px; margin: 0 auto; padding: 0 1.5rem;
  display: flex; align-items: center; gap: 1.5rem; height: 60px;
}
.nav-logo { font-weight: 700; font-size: 1.1rem; color: var(--text); }
.nav-links { display: flex; gap: .25rem; flex: 1; }
.nav-link {
  padding: .4rem .8rem; border-radius: 6px; color: var(--text-muted);
  font-size: .9rem; transition: all .15s;
}
.nav-link:hover, .nav-link.active {
  background: var(--primary-light); color: var(--primary); text-decoration: none;
}
.nav-user { position: relative; cursor: pointer; }
.nav-username {
  padding: .4rem .8rem; border-radius: 6px; background: var(--bg);
  font-size: .9rem; font-weight: 500;
}
.nav-dropdown {
  display: none; position: absolute; right: 0; top: 110%;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-md);
  min-width: 160px; padding: .5rem 0;
}
.nav-user:hover .nav-dropdown { display: block; }
.nav-dropdown a {
  display: block; padding: .5rem 1rem; color: var(--text);
  font-size: .9rem;
}
.nav-dropdown a:hover { background: var(--bg); text-decoration: none; }

/* ── Auth pages ────────────────────────────────────────────── */
.auth-page { background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.auth-container { width: 100%; max-width: 420px; padding: 1rem; }
.auth-logo { text-align: center; margin-bottom: 1.5rem; color: #fff; }
.auth-logo h1 { font-size: 1.8rem; margin-bottom: .25rem; }
.auth-logo p { opacity: .85; }
.auth-card { background: var(--surface); border-radius: 16px; padding: 2rem; box-shadow: 0 20px 60px rgba(0,0,0,.2); }
.auth-card h2 { margin-bottom: .25rem; }
.auth-subtitle { color: var(--text-muted); margin-bottom: 1.5rem; font-size: .9rem; }
.auth-links { text-align: center; margin-top: 1.25rem; font-size: .9rem; color: var(--text-muted); }
.auth-links a { color: var(--primary); }
.auth-links span { margin: 0 .5rem; }

/* ── Cards ─────────────────────────────────────────────────── */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 1.5rem;
}
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1rem 1.25rem; border-bottom: 1px solid var(--border);
}
.card-header h2 { font-size: 1rem; font-weight: 600; }
.card-body { padding: 1.25rem; }
.card-actions { display: flex; gap: .5rem; }
.card-full { grid-column: 1 / -1; }

/* ── Buttons ───────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .5rem 1rem; border-radius: 8px; font-size: .875rem;
  font-weight: 500; cursor: pointer; border: none; transition: all .15s;
  text-decoration: none; white-space: nowrap;
}
.btn:hover { text-decoration: none; }
.btn-primary   { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-outline   { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn-outline:hover { background: var(--bg); }
.btn-success   { background: var(--success); color: #fff; }
.btn-danger    { background: var(--danger); color: #fff; }
.btn-full      { width: 100%; justify-content: center; }
.btn-lg        { padding: .75rem 1.5rem; font-size: 1rem; }
.btn-sm        { padding: .35rem .75rem; font-size: .8rem; }
.btn-xs        { padding: .2rem .5rem; font-size: .75rem; }
.btn:disabled  { opacity: .5; cursor: not-allowed; }

/* ── Forms ─────────────────────────────────────────────────── */
.form-group { margin-bottom: 1rem; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
label { display: block; font-size: .875rem; font-weight: 500; margin-bottom: .35rem; color: var(--text); }
label small { font-weight: 400; color: var(--text-muted); }
input[type="text"], input[type="email"], input[type="password"],
input[type="number"], input[type="date"], select, textarea {
  width: 100%; padding: .6rem .85rem; border: 1px solid var(--border);
  border-radius: 8px; font-size: .9rem; color: var(--text);
  background: var(--surface); transition: border-color .15s;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99,102,241,.15);
}
input:disabled { background: var(--bg); color: var(--text-muted); }
textarea { resize: vertical; min-height: 80px; }
.required { color: var(--danger); }

/* ── Alerts ────────────────────────────────────────────────── */
.alert {
  padding: .75rem 1rem; border-radius: 8px; margin-bottom: 1rem;
  font-size: .9rem; display: flex; align-items: center; gap: .5rem;
}
.alert-success { background: #d1fae5; color: #065f46; border: 1px solid #a7f3d0; }
.alert-error   { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }
.alert-warning { background: #fef3c7; color: #92400e; border: 1px solid #fde68a; }
.alert-info    { background: #dbeafe; color: #1e40af; border: 1px solid #93c5fd; }

/* ── Stats grid ────────────────────────────────────────────── */
.stats-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem; margin-bottom: 1.5rem;
}
.stat-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.25rem;
  display: flex; align-items: center; gap: 1rem;
  box-shadow: var(--shadow);
}
.stat-icon { font-size: 1.75rem; }
.stat-info { flex: 1; }
.stat-value { display: block; font-size: 1.4rem; font-weight: 700; }
.stat-label { display: block; font-size: .8rem; color: var(--text-muted); }
.stat-bar { height: 4px; background: var(--border); border-radius: 2px; margin-top: .5rem; grid-column: 1/-1; width: 100%; }
.stat-bar-fill { height: 100%; background: var(--primary); border-radius: 2px; }

/* ── Page header ───────────────────────────────────────────── */
.page-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  margin-bottom: 1.5rem; gap: 1rem;
}
.page-header h1 { font-size: 1.5rem; }
.page-header p { color: var(--text-muted); margin-top: .25rem; }

/* ── Quick actions ─────────────────────────────────────────── */
.quick-actions {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem; margin-top: 1.5rem;
}
.action-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.25rem;
  display: flex; flex-direction: column; gap: .25rem;
  transition: all .15s; cursor: pointer;
}
.action-card:hover { border-color: var(--primary); box-shadow: var(--shadow-md); text-decoration: none; }
.action-icon { font-size: 1.5rem; }
.action-title { font-weight: 600; color: var(--text); }
.action-desc { font-size: .85rem; color: var(--text-muted); }

/* ── Steps indicator ───────────────────────────────────────── */
.steps-indicator {
  display: flex; gap: 0; margin-bottom: 1.5rem;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow);
}
.step {
  flex: 1; padding: .75rem .5rem; text-align: center;
  font-size: .8rem; color: var(--text-muted); cursor: default;
  border-right: 1px solid var(--border); transition: all .2s;
}
.step:last-child { border-right: none; }
.step span {
  display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--border); color: var(--text-muted);
  font-size: .75rem; font-weight: 600; margin-right: .35rem;
}
.step.active { background: var(--primary-light); color: var(--primary); font-weight: 600; }
.step.active span { background: var(--primary); color: #fff; }
.step.done { color: var(--success); }
.step.done span { background: var(--success); color: #fff; }

/* ── Step panels ───────────────────────────────────────────── */
.step-panel { display: none; }
.step-panel.active { display: block; }
.step-actions { display: flex; gap: .75rem; margin-top: 1rem; flex-wrap: wrap; }

/* ── Loading spinner ───────────────────────────────────────── */
.loading-spinner {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; padding: 3rem; gap: 1rem; color: var(--text-muted);
}
.spinner {
  width: 36px; height: 36px; border: 3px solid var(--border);
  border-top-color: var(--primary); border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Result content ────────────────────────────────────────── */
.result-pre {
  background: #f8fafc; border: 1px solid var(--border);
  border-radius: 8px; padding: 1rem; font-size: .85rem;
  white-space: pre-wrap; word-break: break-word;
  max-height: 500px; overflow-y: auto; font-family: 'Courier New', monospace;
}

/* ── Tables ────────────────────────────────────────────────── */
.data-table { width: 100%; border-collapse: collapse; font-size: .875rem; }
.data-table th {
  text-align: left; padding: .6rem 1rem; background: var(--bg);
  border-bottom: 2px solid var(--border); font-weight: 600; color: var(--text-muted);
  font-size: .8rem; text-transform: uppercase; letter-spacing: .05em;
}
.data-table td { padding: .7rem 1rem; border-bottom: 1px solid var(--border); }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--bg); }

/* ── Status badges ─────────────────────────────────────────── */
.status-badge {
  display: inline-block; padding: .2rem .6rem; border-radius: 20px;
  font-size: .75rem; font-weight: 600;
}
.status-active   { background: #d1fae5; color: #065f46; }
.status-inactive { background: #f1f5f9; color: #64748b; }
.status-banned   { background: #fee2e2; color: #991b1b; }
.status-expired  { background: #fef3c7; color: #92400e; }
.status-revoked  { background: #fee2e2; color: #991b1b; }
.status-cancelled{ background: #f1f5f9; color: #64748b; }
.status-past_due { background: #fef3c7; color: #92400e; }

/* ── Pricing ───────────────────────────────────────────────── */
.pricing-header { text-align: center; margin-bottom: 2rem; }
.pricing-header h1 { font-size: 2rem; margin-bottom: .5rem; }
.pricing-header p { color: var(--text-muted); font-size: 1.1rem; }
.billing-toggle {
  display: inline-flex; gap: 0; margin-top: 1.5rem;
  border: 1px solid var(--border); border-radius: 8px; overflow: hidden;
}
.toggle-btn {
  padding: .5rem 1.25rem; font-size: .9rem; color: var(--text-muted);
  background: var(--surface); border-right: 1px solid var(--border);
  transition: all .15s;
}
.toggle-btn:last-child { border-right: none; }
.toggle-btn.active { background: var(--primary); color: #fff; }
.toggle-btn:hover:not(.active) { background: var(--bg); text-decoration: none; }
.badge-save {
  background: var(--success); color: #fff;
  font-size: .7rem; padding: .1rem .4rem; border-radius: 4px; margin-left: .35rem;
}
.pricing-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 1.5rem; margin-bottom: 2rem;
}
.pricing-card {
  background: var(--surface); border: 2px solid var(--border);
  border-radius: 16px; padding: 1.75rem; position: relative;
  transition: all .2s;
}
.pricing-card.featured { border-color: var(--primary); box-shadow: 0 0 0 4px rgba(99,102,241,.1); }
.pricing-card.current  { border-color: var(--success); }
.popular-badge, .current-badge {
  position: absolute; top: -12px; left: 50%; transform: translateX(-50%);
  padding: .2rem .75rem; border-radius: 20px; font-size: .75rem; font-weight: 700;
  white-space: nowrap;
}
.popular-badge { background: var(--primary); color: #fff; }
.current-badge { background: var(--success); color: #fff; }
.plan-name { font-size: 1.1rem; font-weight: 700; margin-bottom: .25rem; }
.plan-desc { font-size: .85rem; color: var(--text-muted); margin-bottom: 1rem; }
.plan-price { margin-bottom: 1.25rem; }
.price-currency { font-size: 1.25rem; font-weight: 600; vertical-align: top; margin-top: .35rem; display: inline-block; }
.price-amount { font-size: 2.5rem; font-weight: 800; line-height: 1; }
.price-period { font-size: .9rem; color: var(--text-muted); }
.plan-features { list-style: none; margin-bottom: 1.5rem; }
.plan-features li { padding: .35rem 0; font-size: .9rem; border-bottom: 1px solid var(--border); }
.plan-features li:last-child { border-bottom: none; }
.pricing-footer { text-align: center; color: var(--text-muted); font-size: .9rem; }

/* ── Account page ──────────────────────────────────────────── */
.account-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem;
}
.subscription-info { margin-bottom: 1rem; }
.sub-plan { font-size: 1.1rem; font-weight: 700; }
.sub-detail { font-size: .85rem; color: var(--text-muted); margin-top: .25rem; }
.licence-key { font-size: .8rem; background: var(--bg); padding: .2rem .4rem; border-radius: 4px; }
.licence-key-sm { font-size: .75rem; }

/* ── Empty state ───────────────────────────────────────────── */
.empty-state { text-align: center; padding: 3rem; color: var(--text-muted); }
.empty-state p { margin-bottom: 1rem; }

/* ── Success page ──────────────────────────────────────────── */
.success-page { text-align: center; padding: 4rem 2rem; }
.success-icon { font-size: 4rem; margin-bottom: 1rem; }
.success-page h1 { font-size: 2rem; margin-bottom: .5rem; }
.success-page p { color: var(--text-muted); margin-bottom: .5rem; }
.success-actions { display: flex; gap: 1rem; justify-content: center; margin-top: 2rem; flex-wrap: wrap; }

/* ── Back link ─────────────────────────────────────────────── */
.back-link { font-size: .85rem; color: var(--text-muted); display: block; margin-bottom: .5rem; }
.result-meta { font-size: .85rem; color: var(--text-muted); margin-top: .25rem; }

/* ── Action group ──────────────────────────────────────────── */
.action-group { display: flex; gap: .35rem; flex-wrap: wrap; }

/* ── Responsive ────────────────────────────────────────────── */
@media (max-width: 768px) {
  .form-row { grid-template-columns: 1fr; }
  .account-grid { grid-template-columns: 1fr; }
  .pricing-grid { grid-template-columns: 1fr; }
  .steps-indicator { flex-wrap: wrap; }
  .step { min-width: 80px; }
  .nav-links { display: none; }
  .page-header { flex-direction: column; }
}

/* ── Result Cards ──────────────────────────────────────────── */
.result-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
  transition: box-shadow .15s;
}
.result-card:hover { box-shadow: var(--shadow-md); }

.result-card-header {
  display: flex;
  align-items: center;
  gap: .75rem;
  margin-bottom: .75rem;
}
.result-card-header h3 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  margin: 0;
}
.result-number {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: .8rem;
  font-weight: 700;
  flex-shrink: 0;
}
.result-meta {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  margin: .75rem 0;
}
.badge {
  display: inline-block;
  padding: .2rem .65rem;
  border-radius: 999px;
  font-size: .78rem;
  font-weight: 600;
}
.badge-green  { background: #d1fae5; color: #065f46; }
.badge-blue   { background: #dbeafe; color: #1e40af; }
.badge-purple { background: #ede9fe; color: #5b21b6; }
.badge-orange { background: #fef3c7; color: #92400e; }

.result-detail {
  font-size: .875rem;
  color: var(--text-muted);
  margin-top: .5rem;
}
.result-detail strong { color: var(--text); }

.task-list {
  list-style: none;
  padding: 0;
  margin: .5rem 0;
}
.task-list li {
  padding: .3rem 0;
  font-size: .9rem;
  border-bottom: 1px solid var(--border);
}
.task-list li:last-child { border-bottom: none; }

/* Builder card */
.builder-card { background: linear-gradient(135deg, #f0f4ff 0%, #fafafa 100%); }
.builder-intro { color: var(--text-muted); margin-bottom: 1rem; font-size: .9rem; }
.builder-prompt-text {
  width: 100%;
  min-height: 200px;
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: 'Courier New', monospace;
  font-size: .85rem;
  line-height: 1.6;
  background: #fff;
  resize: vertical;
  color: var(--text);
}

/* Loading spinner */
.loading-spinner {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: .75rem;
  padding: 2.5rem;
  color: var(--text-muted);
}
.spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Alert */
.alert-error {
  background: #fee2e2;
  color: #991b1b;
  border: 1px solid #fca5a5;
  border-radius: var(--radius);
  padding: .75rem 1rem;
  font-size: .9rem;
}
