/* =========================
   RESET & BASE
   ========================= */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  /* min-height, not height. With the global box-sizing: border-box above,
     a fixed height: 100% swallows any padding-bottom instead of extending the
     page — so the space reserved for the docked composer added no scroll room
     at all and the last lines stayed pinned under it. index.html always used
     min-height, which is why the same code behaved correctly there. */
  min-height: 100%;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial;
  background: linear-gradient(180deg, #060610 0%, #08081a 25%, #0a0820 50%, #080618 75%, #040408 100%);
  color: #e5e7eb;
}

/* =========================
   NAVBAR
   ========================= */
.navbar {
  position: sticky;
  top: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 28px;
  background: rgba(6,6,16,0.85);
  backdrop-filter: blur(20px) saturate(1.4);
  -webkit-backdrop-filter: blur(20px) saturate(1.4);
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.logo {
  font-weight: 800;
  font-size: 20px;
  text-decoration: none;
  color: #fff;
  display: flex;
  align-items: center;
  gap: 9px;
  letter-spacing: -0.03em;
}
.logo img {
  width: 32px;
  height: 32px;
}
.logo .logo-dim {
  font-weight: 500;
  color: rgba(255,255,255,0.4);
}

.navbar ul {
  list-style: none;
  display: flex;
  gap: 18px;
  align-items: center;
}

.navbar a {
  text-decoration: none;
  font-size: 13px;
  color: rgba(255,255,255,0.8);
}

.navbar a:hover {
  color: #fff;
}

/* Login button */
.nav-auth-btn {
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 13px;
  font-weight: 800;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.14);
  color: #fff;
  cursor: pointer;
}

.nav-auth-btn:hover {
  background: rgba(255,255,255,0.12);
}

/* =========================
   LAYOUT
   ========================= */
.main-container {
  max-width: 980px;
  margin: 70px auto 0;
  padding: 0 22px 40px;
}

.page-title {
  font-size: 36px;
  font-weight: 900;
  margin-bottom: 8px;
}

.page-subtitle {
  color: rgba(255,255,255,0.75);
  margin-bottom: 20px;
  line-height: 1.5;
}

/* =========================
   UPLOAD BOX
   ========================= */
.chat-box {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 18px;
  border-radius: 18px;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.12);
}

.row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  width: 100%;
}

.chat-box input[type="text"],
.chat-box select,
.chat-box textarea {
  width: 100%;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid rgba(255,255,255,0.12);
  background: rgba(15,23,42,0.7);
  color: #fff;
  outline: none;
}

.chat-box textarea {
  resize: vertical;
  min-height: 90px;
  line-height: 1.45;
}

#symbolInput {
  flex: 1;
  min-width: 220px;
}

#intervalSelect {
  flex: 0 0 160px;
  min-width: 160px;
}

.field-label {
  font-size: 12px;
  opacity: 0.9;
  font-weight: 700;
  margin-top: 4px;
}

.helper {
  font-size: 12px;
  opacity: 0.75;
}

.upload-hint {
  font-size: 12px;
  opacity: 0.85;
  margin-top: -4px;
}

.file-input {
  padding: 10px 0;
  color: rgba(255,255,255,0.85);
}

/* ✅ NEW: checkbox row used by index.html */
.check-row {
  display: flex;
  align-items: center;
  gap: 10px;
  user-select: none;
  padding: 10px 12px;
  border-radius: 14px;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.10);
}

.check-row input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: #6366f1;
  cursor: pointer;
}

.check-row span {
  font-size: 12px;
  opacity: 0.9;
  line-height: 1.35;
}

/* Analyze button + spinner */
.analyze-btn {
  padding: 12px 16px;
  border-radius: 14px;
  border: none;
  font-weight: 900;
  font-size: 14px;
  background: linear-gradient(135deg, #4f46e5, #6366f1);
  color: #fff;
  cursor: pointer;

  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: fit-content;
}

.analyze-btn:hover {
  filter: brightness(1.05);
}

.analyze-btn:disabled {
  opacity: 0.75;
  cursor: not-allowed;
}

.spinner {
  width: 16px;
  height: 16px;
  border-radius: 999px;
  border: 2px solid rgba(255,255,255,0.25);
  border-top-color: rgba(255,255,255,0.9);
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* =========================
   PREVIEW
   ========================= */
.preview-wrap {
  margin-top: 14px;
  padding: 14px;
  border-radius: 16px;
  border: 1px solid rgba(255,255,255,0.12);
  background: rgba(255,255,255,0.05);
}

.preview-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.preview-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.preview-thumb {
  width: 120px;
  height: 80px;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.12);
  cursor: zoom-in;
}

.preview-title {
  font-size: 13px;
  font-weight: 800;
}

.preview-sub {
  font-size: 12px;
  opacity: 0.75;
}

/* =========================
   STATUS
   ========================= */
.upload-info {
  margin-top: 14px;
  font-size: 13px;
  color: rgba(255,255,255,0.85);
}

.upload-info .muted {
  margin-left: 8px;
  opacity: 0.75;
}

.status-warning {
  margin-top: 8px;
  font-size: 12px;
  color: #fbbf24;
  min-height: 16px;
}

/* =========================
   OUTPUT
   ========================= */
.output {
  margin-top: 22px;
}

.output-title {
  font-size: 14px;
  font-weight: 900;
  margin-bottom: 8px;
}

.output-box {
  padding: 16px;
  border-radius: 16px;
  background: rgba(15,23,42,0.7);
  border: 1px solid rgba(255,255,255,0.12);
  min-height: 140px;
  line-height: 1.55;
}

/* Markdown rendering inside output */
.output-box h1 {
  font-size: 18px;
  margin: 14px 0 8px;
  font-weight: 900;
}
.output-box h2 {
  font-size: 15px;
  margin: 14px 0 8px;
  font-weight: 900;
}
.output-box h3 {
  font-size: 14px;
  margin: 12px 0 6px;
  font-weight: 800;
}
.output-box p {
  margin: 8px 0;
  color: rgba(255,255,255,0.92);
}
.output-box ul {
  margin: 8px 0 12px 18px;
}
.output-box li {
  margin: 6px 0;
}
.output-box code {
  padding: 2px 6px;
  border-radius: 8px;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.10);
}

/* Tables */
.output-box table {
  width: 100%;
  border-collapse: collapse;
  margin: 10px 0 14px;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.12);
}
.output-box th, .output-box td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  font-size: 13px;
}
.output-box th {
  background: rgba(255,255,255,0.06);
  font-weight: 900;
}
.output-box tr:last-child td {
  border-bottom: none;
}

/* =========================
   FOOTER
   ========================= */
/* Section heading with accent bar */
.section-heading {
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 15px;
  font-weight: 800;
  color: rgba(255,255,255,0.85);
  text-transform: uppercase;
  letter-spacing: 0.10em;
  margin-bottom: 18px;
}
.section-heading::before {
  content: "";
  display: inline-block;
  width: 3px;
  height: 20px;
  border-radius: 3px;
  background: linear-gradient(180deg, #6366f1, #22c55e);
  flex-shrink: 0;
}

/* Footer strip (links row above footer) */
.footer-strip {
  max-width: 1100px;
  margin: 22px auto 0;
  padding: 0 22px;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 22px;
  font-size: 13px;
  color: rgba(255,255,255,0.55);
}
.footer-strip a {
  color: #c7d2fe;
  text-decoration: none;
  font-weight: 700;
}
.footer-strip a:hover { color: #fff; }
.footer-strip .dot { color: #22c55e; }

.footer {
  margin-top: 60px;
  padding: 24px;
  text-align: center;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.6);
  border-top: 1px solid rgba(255,255,255,0.04);
}

.footer a {
  color: #c7d2fe;
  text-decoration: none;
  font-weight: 600;
  /* 12px text gives a ~14px tap target — well under the ~44px people actually
     hit accurately on a phone. Inline-block plus vertical padding grows the
     touch area without moving anything visually. */
  display: inline-block;
  padding: 9px 4px;
}

.footer a:hover,
.footer a:focus {
  color: #e0e7ff;
  text-decoration: underline;
}

.footer .sep {
  margin: 0 2px;   /* the links carry their own padding now */
}

.footer .link-strong {
  margin: 0 4px;
}

/* =========================
   MODAL (CRITICAL)
   ========================= */

/* Blur background when modal open */
body.modal-open .navbar,
body.modal-open .main-container,
body.modal-open .footer {
  filter: blur(10px);
}

/* Overlay hidden by default */
.modal-overlay {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.55);
  z-index: 5000;
  padding: 18px;
}

/* Only visible when JS adds .open */
.modal-overlay.open {
  display: flex;
}

/* Modal card */
.modal {
  width: min(560px, 100%);
  padding: 18px;
  border-radius: 18px;
  background: rgba(15,23,42,0.95);
  border: 1px solid rgba(255,255,255,0.16);
  box-shadow: 0 30px 80px rgba(0,0,0,0.7);
  position: relative;
}

.modal-title {
  font-size: 16px;
  font-weight: 900;
  margin-bottom: 8px;
}

.modal-text {
  font-size: 14px;
  line-height: 1.6;
  opacity: 0.9;
}

/* X button */
.modal-x {
  position: absolute;
  right: 10px;
  top: 10px;
  width: 36px;
  height: 36px;
  border-radius: 12px;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.14);
  color: #fff;
  cursor: pointer;
  font-size: 18px;
  font-weight: 900;
  line-height: 1;
}

.modal-x:hover {
  background: rgba(255,255,255,0.14);
}

.modal-actions{
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 14px;
}

.modal-primary {
  padding: 12px 14px;
  border-radius: 14px;
  font-weight: 900;
  text-decoration: none;
  color: #fff;
  background: linear-gradient(135deg, #4f46e5, #6366f1);
  border: none;
}

.modal-secondary {
  padding: 12px 14px;
  border-radius: 14px;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.14);
  color: #fff;
  font-weight: 800;
  cursor: pointer;
}

.modal-secondary:hover {
  background: rgba(255,255,255,0.14);
}

.modal-preview {
  margin-top: 12px;
}

.modal-preview-img {
  width: 100%;
  max-height: 70vh;
  object-fit: contain;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.12);
  background: rgba(0,0,0,0.25);
}

/* ✅ Small responsiveness polish */
@media (max-width: 520px) {
  .page-title { font-size: 30px; }
  #intervalSelect { flex: 1; min-width: 140px; }
  .analyze-btn { width: 100%; }
}

/* =========================
   NAV AUTH LIST ITEM
   ========================= */
.nav-auth-li { list-style: none; }
.nav-auth-li .nav-auth-btn { margin: 0; }

/* =========================
   HAMBURGER MENU (mobile)
   ========================= */
.hamburger {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: 36px;
  height: 36px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  border-radius: 8px;
}

.hamburger span {
  display: block;
  width: 22px;
  height: 2px;
  background: #fff;
  border-radius: 2px;
  transition: all 0.25s ease;
}

.hamburger.open span:nth-child(1) {
  transform: translateY(7px) rotate(45deg);
}
.hamburger.open span:nth-child(2) {
  opacity: 0;
}
.hamburger.open span:nth-child(3) {
  transform: translateY(-7px) rotate(-45deg);
}

@media (max-width: 700px) {
  .navbar { padding: 12px 16px; position: relative; flex-wrap: wrap; }

  .hamburger { display: flex; }

  .navbar ul {
    display: none;
    flex-direction: column;
    align-items: flex-start;
    gap: 0;
    width: 100%;
    background: rgba(6,6,16,0.97);
    border-top: 1px solid rgba(255,255,255,0.08);
    padding: 8px 0;
    margin-top: 10px;
  }

  .navbar ul.open { display: flex; }

  .navbar ul li { width: 100%; }

  .navbar ul li a {
    display: block;
    padding: 12px 18px;
    font-size: 15px;
  }

  .navbar ul li a:hover { background: rgba(255,255,255,0.05); }

  .nav-auth-btn {
    margin-top: 4px;
    margin-bottom: 8px;
    margin-left: 12px;
    width: calc(100% - 24px);
  }

  .navbar > .nav-auth-btn { display: none; }
  .navbar ul .nav-auth-li { display: block; width: 100%; }
}
/* =========================
   PWA INSTALL BANNER
   ========================= */
.pwa-banner {
  display: flex;
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  width: calc(100% - 32px);
  max-width: 420px;
  background: #1a1a1a;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 16px;
  padding: 14px 16px;
  align-items: center;
  gap: 12px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.7);
  z-index: 9999;
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
  transition: opacity 0.35s ease, transform 0.35s cubic-bezier(0.34,1.56,0.64,1), visibility 0s 0.35s;
}
.pwa-banner.pwa-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
  pointer-events: auto;
  visibility: visible;
  transition: opacity 0.35s ease, transform 0.35s cubic-bezier(0.34,1.56,0.64,1), visibility 0s 0s;
}
.pwa-banner-icon {
  width: 46px;
  height: 46px;
  border-radius: 11px;
  background: #111;
  border: 1px solid rgba(255,255,255,0.08);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.pwa-banner-text {
  flex: 1;
  min-width: 0;
}
.pwa-banner-title {
  font-size: 13px;
  font-weight: 700;
  color: #fff;
  line-height: 1.3;
}
.pwa-banner-sub {
  font-size: 11px;
  color: rgba(255,255,255,0.4);
  margin-top: 2px;
  line-height: 1.4;
}
.pwa-ios-hint {
  font-size: 11px;
  color: rgba(255,255,255,0.35);
  margin-top: 4px;
  display: flex;
  align-items: center;
  gap: 4px;
}
.pwa-banner-actions {
  display: flex;
  flex-direction: column;
  gap: 5px;
  flex-shrink: 0;
}
.pwa-btn-install {
  background: #fff;
  color: #000;
  border: none;
  border-radius: 8px;
  padding: 7px 13px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  font-family: inherit;
}
.pwa-btn-dismiss {
  background: none;
  border: none;
  color: rgba(255,255,255,0.3);
  font-size: 11px;
  cursor: pointer;
  text-align: center;
  padding: 2px;
  font-family: inherit;
}
.pwa-btn-dismiss:hover { color: rgba(255,255,255,0.6); }

/* ── Instant logged-in navbar (nav-early.js sets the class in <head>) ──
   These rules win over the inline display:none so the FIRST paint already
   shows the correct menu — no guest-menu flash while supabase-js loads. */
html.logged-in-early #accountNavItem,
html.logged-in-early #analysesNavItem,
html.logged-in-early #publishedNavItem { display: list-item !important; }
html.logged-in-early #authBtn { font-size: 0 !important; }
html.logged-in-early #authBtn::after { content: "Log out"; font-size: 13px; font-weight: 800; }
