/* ── Reset & base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --indigo-50:  #EEF2FF;
  --indigo-100: #E0E7FF;
  --indigo-200: #C7D2FE;
  --indigo-500: #6366F1;
  --indigo-600: #4F46E5;
  --indigo-700: #4338CA;
  --purple-600: #7C3AED;
  --gray-50:  #F9FAFB;
  --gray-100: #F3F4F6;
  --gray-200: #E5E7EB;
  --gray-300: #D1D5DB;
  --gray-400: #9CA3AF;
  --gray-500: #6B7280;
  --gray-600: #4B5563;
  --gray-700: #374151;
  --gray-900: #111827;
  --green-50:  #F0FDF4;
  --green-400: #4ADE80;
  --green-600: #16A34A;
  --red-50:  #FEF2F2;
  --red-400: #F87171;
  --red-600: #DC2626;
  --amber-50: #FFFBEB;
  --amber-400: #FBBF24;
  --amber-700: #B45309;
  --radius: 10px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.05);
  --shadow:    0 4px 12px rgba(0,0,0,.08), 0 2px 4px rgba(0,0,0,.05);
  --shadow-lg: 0 10px 32px rgba(79,70,229,.1), 0 4px 8px rgba(0,0,0,.06);
}

html { font-size: 15px; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: #F0EFFE;
  color: var(--gray-700);
  min-height: 100vh;
  line-height: 1.5;
}

/* ── Header ──────────────────────────────────────────────────────────────── */
header {
  background: linear-gradient(135deg, var(--indigo-600) 0%, var(--purple-600) 100%);
  padding: 28px 24px 32px;
  position: relative;
  overflow: hidden;
}
header::after {
  content: '';
  position: absolute;
  inset: 0;
  background: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23ffffff' fill-opacity='0.04'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E") repeat;
  pointer-events: none;
}
.header-inner { max-width: 900px; margin: 0 auto; position: relative; z-index: 1; }
.header-top { display: flex; align-items: center; justify-content: space-between; gap: 16px; }

.brand { display: flex; align-items: center; gap: 16px; }
.brand h1 {
  font-size: 1.75rem;
  font-weight: 800;
  color: #fff;
  letter-spacing: -.5px;
  line-height: 1.1;
}
.tagline { color: var(--indigo-200); font-size: .85rem; margin-top: 3px; }

/* Bot icon in header */
.bot-icon-wrap {
  width: 60px;
  height: 60px;
  background: rgba(255,255,255,.12);
  border-radius: 16px;
  padding: 6px;
  flex-shrink: 0;
  border: 1.5px solid rgba(255,255,255,.2);
}
.bot-svg { width: 100%; height: 100%; }

/* Usage pill in header */
.usage-pill {
  background: rgba(255,255,255,.15);
  border: 1.5px solid rgba(255,255,255,.25);
  color: #fff;
  font-size: .8rem;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: 999px;
  white-space: nowrap;
  backdrop-filter: blur(4px);
}
.usage-pill.limit-near  { background: rgba(251,191,36,.2);  border-color: rgba(251,191,36,.5);  color: #FDE68A; }
.usage-pill.limit-hit   { background: rgba(239,68,68,.2);   border-color: rgba(239,68,68,.5);   color: #FCA5A5; }
.usage-pill.premium     { background: rgba(167,139,250,.25); border-color: rgba(167,139,250,.5); color: #DDD6FE; }

/* ── Main / Layout ───────────────────────────────────────────────────────── */
main { padding: 0; }

/* Three-column layout: sidebar | content | sidebar */
.page-layout {
  display: grid;
  grid-template-columns: 160px 1fr 160px;
  grid-template-rows: auto;
  align-items: start;
  max-width: 1280px;
  margin: 0 auto;
  padding: 28px 12px 64px;
  gap: 0 16px;
}

.container {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* Sidebar ads */
.ad-sidebar {
  position: sticky;
  top: 20px;
}
.ad-sidebar-inner {
  background: #fff;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 8px 6px;
  text-align: center;
}
.ad-sidebar-inner .adsbygoogle {
  width: 148px !important;
}

/* Hide sidebars when there's not enough room */
@media (max-width: 1100px) {
  .page-layout {
    grid-template-columns: 1fr;
    padding: 20px 16px 64px;
  }
  .ad-sidebar { display: none; }
}

/* ── Card ────────────────────────────────────────────────────────────────── */
.card {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px 24px;
}

/* ── Banner ──────────────────────────────────────────────────────────────── */
.banner {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 14px 18px;
  border-radius: var(--radius);
  font-size: .875rem;
  line-height: 1.5;
}
.banner-warn {
  background: var(--amber-50);
  color: var(--amber-700);
  border: 1px solid #FCD34D;
}
.banner code {
  background: rgba(0,0,0,.08);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: .82rem;
}
.hidden { display: none !important; }

/* ── Email card ──────────────────────────────────────────────────────────── */
.card-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: .8rem;
  font-weight: 600;
  color: var(--gray-500);
  text-transform: uppercase;
  letter-spacing: .05em;
  margin-bottom: 10px;
}
.email-row { display: flex; align-items: center; gap: 10px; }
.email-field {
  flex: 1;
  padding: 10px 14px;
  border: 1.5px solid var(--gray-200);
  border-radius: 8px;
  font-size: .95rem;
  color: var(--gray-900);
  transition: border-color .15s, box-shadow .15s;
  outline: none;
  max-width: 400px;
}
.email-field:focus {
  border-color: var(--indigo-500);
  box-shadow: 0 0 0 3px rgba(99,102,241,.12);
}
.email-note {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: .82rem;
  color: var(--green-600);
}

/* ── Table toolbar ───────────────────────────────────────────────────────── */
.table-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 10px;
}
.table-toolbar-left { display: flex; align-items: center; gap: 10px; }
.table-toolbar-right { display: flex; align-items: center; gap: 8px; }
.table-toolbar h2 {
  font-size: 1rem;
  font-weight: 700;
  color: var(--gray-900);
}
.badge {
  background: var(--indigo-50);
  color: var(--indigo-600);
  font-size: .75rem;
  font-weight: 600;
  padding: 2px 9px;
  border-radius: 999px;
  border: 1px solid var(--indigo-100);
}

/* ── Table ───────────────────────────────────────────────────────────────── */
.table-wrapper {
  overflow-x: auto;
  border: 1px solid var(--gray-200);
  border-radius: 8px;
}
#formulaTable {
  width: 100%;
  border-collapse: collapse;
  font-size: .875rem;
}
#formulaTable thead tr {
  background: var(--gray-50);
  border-bottom: 1px solid var(--gray-200);
}
#formulaTable th {
  padding: 10px 14px;
  text-align: left;
  font-size: .75rem;
  font-weight: 700;
  color: var(--gray-500);
  text-transform: uppercase;
  letter-spacing: .05em;
  white-space: nowrap;
}
.col-num     { width: 42px; text-align: center !important; }
.col-request { width: 40%; }
.col-formula { width: 44%; }
.col-actions { width: 100px; }

#formulaTable tbody tr {
  border-bottom: 1px solid var(--gray-100);
  transition: background .1s;
}
#formulaTable tbody tr:last-child { border-bottom: none; }
#formulaTable tbody tr:hover { background: var(--indigo-50); }

#formulaTable td {
  padding: 10px 14px;
  vertical-align: top;
}
.td-num {
  text-align: center;
  color: var(--gray-400);
  font-size: .8rem;
  padding-top: 14px !important;
  font-weight: 600;
}

/* ── Row inputs ──────────────────────────────────────────────────────────── */
.request-input {
  width: 100%;
  border: 1.5px solid var(--gray-200);
  border-radius: 6px;
  padding: 7px 10px;
  font-size: .875rem;
  font-family: inherit;
  resize: vertical;
  min-height: 60px;
  color: var(--gray-900);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
  line-height: 1.5;
}
.request-input:focus {
  border-color: var(--indigo-500);
  box-shadow: 0 0 0 3px rgba(99,102,241,.1);
}
.request-input::placeholder { color: var(--gray-400); }

.formula-cell {
  position: relative;
}
.formula-output {
  width: 100%;
  background: var(--gray-50);
  border: 1.5px solid var(--gray-200);
  border-radius: 6px;
  padding: 7px 36px 7px 10px;
  font-family: 'Consolas', 'Fira Code', 'Cascadia Code', 'Courier New', monospace;
  font-size: .82rem;
  color: var(--indigo-700);
  min-height: 60px;
  resize: vertical;
  outline: none;
  line-height: 1.5;
  transition: border-color .15s;
  overflow-y: auto;
  word-break: break-all;
}
.formula-output.has-formula {
  background: var(--indigo-50);
  border-color: var(--indigo-200);
  color: var(--indigo-700);
}
.formula-output.loading {
  background: #FFFBEB;
  border-color: var(--amber-400);
  color: var(--gray-400);
  animation: pulse 1.2s ease-in-out infinite;
}
.formula-output.error {
  background: var(--red-50);
  border-color: var(--red-400);
  color: var(--red-600);
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .55; }
}

.copy-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--gray-400);
  padding: 3px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  transition: color .15s, background .15s;
  line-height: 1;
}
.copy-btn:hover { color: var(--indigo-600); background: var(--indigo-100); }
.copy-btn.copied { color: var(--green-600); }

/* ── Row actions ─────────────────────────────────────────────────────────── */
.row-actions {
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding-top: 4px;
}
.btn-convert-row {
  background: var(--indigo-600);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 5px 10px;
  font-size: .78rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, opacity .15s;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 4px;
}
.btn-convert-row:hover { background: var(--indigo-700); }
.btn-convert-row:disabled { opacity: .5; cursor: not-allowed; }

.btn-delete-row {
  background: transparent;
  color: var(--gray-400);
  border: 1.5px solid var(--gray-200);
  border-radius: 6px;
  padding: 5px 10px;
  font-size: .78rem;
  cursor: pointer;
  transition: color .15s, border-color .15s, background .15s;
  display: flex;
  align-items: center;
  gap: 4px;
}
.btn-delete-row:hover {
  color: var(--red-600);
  border-color: var(--red-400);
  background: var(--red-50);
}

/* ── Empty state ─────────────────────────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 24px;
  color: var(--gray-400);
  text-align: center;
  gap: 12px;
}
.empty-state p { font-size: .9rem; line-height: 1.6; }
.empty-state strong { color: var(--gray-600); }

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 7px;
  font-size: .875rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all .15s;
  white-space: nowrap;
  line-height: 1;
}
.btn:disabled { opacity: .45; cursor: not-allowed; }

.btn-primary {
  background: var(--indigo-600);
  color: #fff;
}
.btn-primary:hover:not(:disabled) { background: var(--indigo-700); }

.btn-secondary {
  background: #fff;
  color: var(--gray-700);
  border: 1.5px solid var(--gray-200);
}
.btn-secondary:hover:not(:disabled) {
  background: var(--gray-50);
  border-color: var(--gray-300);
}

.btn-email {
  background: var(--indigo-600);
  color: #fff;
  flex: 1;
  justify-content: center;
  padding: 11px 20px;
  font-size: .9rem;
}
.btn-email:hover:not(:disabled) { background: var(--indigo-700); }

.btn-download {
  background: #fff;
  color: var(--green-600);
  border: 1.5px solid var(--green-400);
  flex: 1;
  justify-content: center;
  padding: 11px 20px;
  font-size: .9rem;
}
.btn-download:hover:not(:disabled) {
  background: var(--green-50);
  border-color: var(--green-600);
}

/* ── Export card ─────────────────────────────────────────────────────────── */
.export-header {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 14px;
}
.export-header h2 { font-size: 1rem; font-weight: 700; color: var(--gray-900); }
.export-hint { font-size: .8rem; color: var(--gray-400); }
.export-buttons { display: flex; gap: 10px; }
.export-subtext {
  margin-top: 10px;
  font-size: .8rem;
  color: var(--gray-400);
}

/* ── Toast ───────────────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(16px);
  background: var(--gray-900);
  color: #fff;
  padding: 11px 20px;
  border-radius: 8px;
  font-size: .875rem;
  font-weight: 500;
  box-shadow: 0 8px 24px rgba(0,0,0,.25);
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s, transform .25s;
  z-index: 1000;
  max-width: calc(100vw - 32px);
  text-align: center;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.toast.success { background: var(--green-600); }
.toast.error   { background: var(--red-600); }
.toast.info    { background: var(--indigo-600); }

/* ── Google Ads ──────────────────────────────────────────────────────────── */
.ad-slot {
  position: relative;
  text-align: center;
  background: #fff;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 10px 12px 8px;
  min-height: 100px;
  overflow: hidden;
}
.ad-slot.hidden { display: none !important; }

.ad-label {
  display: block;
  font-size: .65rem;
  font-weight: 600;
  color: var(--gray-400);
  text-transform: uppercase;
  letter-spacing: .08em;
  margin-bottom: 6px;
}

/* Leaderboard — full width horizontal */
.ad-leaderboard { min-height: 110px; }

/* Sticky footer strip */
.ad-sticky-footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 100;
  border-radius: 0;
  border-left: none;
  border-right: none;
  border-bottom: none;
  box-shadow: 0 -4px 16px rgba(0,0,0,.1);
  padding: 8px 40px 6px;
  min-height: 80px;
}
.ad-sticky-close {
  position: absolute;
  top: 6px;
  right: 10px;
  background: transparent;
  border: none;
  font-size: .85rem;
  color: var(--gray-400);
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  line-height: 1;
  transition: color .15s, background .15s;
}
.ad-sticky-close:hover { color: var(--gray-600); background: var(--gray-100); }

/* Push page content up so sticky footer doesn't cover it */
body.has-sticky-ad { padding-bottom: 100px; }

/* ── Bot intro card ──────────────────────────────────────────────────────── */
.bot-intro-card {
  display: flex;
  gap: 20px;
  align-items: flex-start;
  position: relative;
  background: linear-gradient(135deg, #F5F3FF 0%, #EEF2FF 100%);
  border: 1.5px solid var(--indigo-200);
}
.bot-intro-card.dismissed { display: none; }

.bot-intro-avatar {
  width: 64px;
  height: 64px;
  flex-shrink: 0;
}
.bot-intro-avatar svg { width: 100%; height: 100%; }

.bot-intro-text { flex: 1; min-width: 0; }
.bot-intro-name {
  font-size: 1rem;
  font-weight: 700;
  color: var(--indigo-700);
  margin-bottom: 4px;
}
.bot-intro-tagline {
  font-size: .875rem;
  color: var(--gray-500);
  margin-bottom: 12px;
}
.bot-steps {
  list-style: none;
  counter-reset: steps;
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 14px;
}
.bot-steps li {
  counter-increment: steps;
  display: flex;
  align-items: baseline;
  gap: 9px;
  font-size: .85rem;
  color: var(--gray-600);
  line-height: 1.5;
}
.bot-steps li::before {
  content: counter(steps);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  background: var(--indigo-600);
  color: #fff;
  font-size: .68rem;
  font-weight: 700;
  border-radius: 50%;
  flex-shrink: 0;
  position: relative;
  top: 1px;
}
.bot-examples {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-bottom: 12px;
}
.bot-examples-label {
  font-size: .75rem;
  font-weight: 600;
  color: var(--gray-400);
  text-transform: uppercase;
  letter-spacing: .05em;
  white-space: nowrap;
}
.example-chip {
  background: #fff;
  border: 1.5px solid var(--indigo-200);
  color: var(--indigo-600);
  font-size: .78rem;
  font-weight: 500;
  padding: 4px 10px;
  border-radius: 999px;
  cursor: pointer;
  transition: background .15s, border-color .15s, color .15s;
  font-family: inherit;
  line-height: 1.4;
}
.example-chip:hover {
  background: var(--indigo-50);
  border-color: var(--indigo-400);
  color: var(--indigo-700);
}
.bot-free-note {
  font-size: .8rem;
  color: var(--gray-500);
  background: rgba(255,255,255,.6);
  border: 1px solid var(--indigo-100);
  border-radius: 6px;
  padding: 7px 12px;
}
.bot-free-note a {
  color: var(--indigo-600);
  text-decoration: none;
  font-weight: 600;
}
.bot-free-note a:hover { text-decoration: underline; }
.bot-intro-close {
  position: absolute;
  top: 14px;
  right: 14px;
  background: transparent;
  border: none;
  color: var(--gray-400);
  cursor: pointer;
  font-size: .9rem;
  line-height: 1;
  padding: 2px 5px;
  border-radius: 4px;
  transition: color .15s, background .15s;
}
.bot-intro-close:hover { color: var(--gray-600); background: var(--gray-100); }

/* ── Email hint & premium badge ──────────────────────────────────────────── */
.email-hint {
  margin-top: 7px;
  font-size: .78rem;
  color: var(--gray-400);
}
.premium-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: linear-gradient(135deg, #7C3AED, #4F46E5);
  color: #fff;
  font-size: .75rem;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 999px;
  letter-spacing: .03em;
}

/* ── Upgrade modal ───────────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(17,24,39,.55);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 16px;
}
.modal {
  background: #fff;
  border-radius: 16px;
  padding: 36px 32px 28px;
  max-width: 420px;
  width: 100%;
  position: relative;
  box-shadow: 0 24px 60px rgba(0,0,0,.2);
  text-align: center;
}
.modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
  background: transparent;
  border: none;
  color: var(--gray-400);
  cursor: pointer;
  font-size: 1rem;
  padding: 4px 8px;
  border-radius: 6px;
  transition: color .15s, background .15s;
}
.modal-close:hover { color: var(--gray-700); background: var(--gray-100); }

.modal-bot-icon {
  width: 72px;
  height: 72px;
  margin: 0 auto 16px;
}
.modal-bot-icon svg { width: 100%; height: 100%; }

.modal h2 {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--gray-900);
  margin-bottom: 8px;
  line-height: 1.3;
}
.modal-sub {
  font-size: .9rem;
  color: var(--gray-500);
  margin-bottom: 20px;
}
.modal-pricing {
  background: var(--indigo-50);
  border: 1.5px solid var(--indigo-100);
  border-radius: 12px;
  padding: 18px 20px;
  margin-bottom: 20px;
  text-align: left;
}
.modal-price {
  font-size: 2rem;
  font-weight: 800;
  color: var(--indigo-600);
  margin-bottom: 12px;
}
.modal-price span {
  font-size: 1rem;
  font-weight: 500;
  color: var(--gray-500);
}
.modal-features {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: .875rem;
  color: var(--gray-600);
}
.modal-features li { color: var(--gray-700); }

.btn-upgrade {
  width: 100%;
  justify-content: center;
  padding: 13px 24px;
  font-size: 1rem;
  background: linear-gradient(135deg, var(--indigo-600), var(--purple-600));
  color: #fff;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 700;
  transition: opacity .15s, transform .1s;
  margin-bottom: 10px;
}
.btn-upgrade:hover { opacity: .92; transform: translateY(-1px); }
.btn-upgrade:active { transform: translateY(0); }

.modal-fine {
  font-size: .75rem;
  color: var(--gray-400);
}

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  .col-num { display: none; }
  .td-num  { display: none; }
  .export-buttons { flex-direction: column; }
  .table-toolbar { flex-direction: column; align-items: stretch; }
  .table-toolbar-right { justify-content: flex-end; }
  .btn-email, .btn-download { flex: none; width: 100%; }
  header { padding: 20px 16px 24px; }
  .card { padding: 18px 16px; }
  main { padding: 20px 12px 48px; }
  .bot-intro-card { flex-direction: column; gap: 12px; }
  .bot-intro-avatar { width: 48px; height: 48px; }
  .header-top { flex-direction: column; align-items: flex-start; gap: 10px; }
  .modal { padding: 28px 20px 22px; }
  .ad-sticky-footer { padding: 8px 36px 4px; min-height: 70px; }
  .ad-rectangle { min-height: 200px; }
  body.has-sticky-ad { padding-bottom: 80px; }
}
