* {
  box-sizing: border-box;
}
:root {
  --brand-primary: #ff6b6b;
  --brand-secondary: #764ba2;
  --surface-dark: #0b0f1e;
  --surface-card: #1b1f30;
  --border-color: rgba(255, 255, 255, 0.12);
  --text-muted: #a9b1d6;
}

body {
  margin: 0;
  font-family: "Poppins", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: linear-gradient(140deg, #0d1024 0%, #21124f 50%, #46104b 100%);
  color: #fff;
  min-height: 100vh;
}

.page-shell {
  max-width: 1200px;
  margin: 0 auto;
  padding: 40px 20px 80px;
}

.tile {
  background: rgba(11, 15, 30, 0.8);
  border: 1px solid var(--border-color);
  border-radius: 18px;
  padding: 24px;
  box-shadow: 0 20px 60px rgba(5, 0, 30, 0.4);
  margin-bottom: 24px;
}

.tile h2,
.tile h3 {
  margin-top: 0;
}

.header-flex {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 16px;
  text-align: left;
}

.header-copy {
  max-width: 620px;
}

.header-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 12px;
}

.header-actions a.nav-link,
.header-actions a.nav-link:link,
.header-actions a.nav-link:visited,
.header-actions a.nav-link:hover,
.header-actions a.nav-link:active,
.header-actions a.nav-link:focus {
  color: #ff8c42 !important;
  text-decoration: none !important;
  font-weight: 600;
}

.logout-button {
  padding: 8px 20px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.05);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s ease, transform 0.2s ease;
}

.logout-button:hover {
  background: rgba(255, 255, 255, 0.15);
  transform: translateY(-2px);
}

.buy-button {
  padding: 8px 20px;
  border-radius: 999px;
  border: none;
  background: linear-gradient(135deg, #ff8c42, #ff6b6b);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 12px 25px rgba(255, 107, 107, 0.35);
  transition: transform 0.2s ease;
}

.buy-button:hover {
  transform: translateY(-2px);
}

.buy-button {
  padding: 8px 20px;
  border-radius: 999px;
  border: none;
  background: linear-gradient(135deg, #ff8c42, #ff6b6b);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 12px 25px rgba(255, 107, 107, 0.35);
  transition: transform 0.2s ease;
}

.buy-button:hover {
  transform: translateY(-2px);
}


form label {
  display: block;
  font-weight: 600;
  margin-bottom: 6px;
}

input[type="text"],
input[type="email"],
input[type="password"],
select,
textarea {
  width: 100%;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 12px;
  color: #fff;
  font-size: 1rem;
  margin-bottom: 14px;
}

select option {
  background: #1b1f30;
  color: #fff;
  padding: 12px;
}

textarea {
  min-height: 140px;
  resize: vertical;
}

button,
.cta-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 600;
  padding: 12px 22px;
  border-radius: 999px;
  border: none;
  cursor: pointer;
  font-size: 1rem;
  background: linear-gradient(135deg, var(--brand-primary), var(--brand-secondary));
  color: #fff;
  box-shadow: 0 12px 30px rgba(255, 107, 107, 0.35);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  text-decoration: none;
}

button[disabled] {
  opacity: 0.6;
  cursor: not-allowed;
  box-shadow: none;
}

button:hover:not([disabled]) {
  transform: translateY(-3px);
}

.split {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 24px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  padding: 6px 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  font-size: 0.9rem;
  color: var(--text-muted);
}

.thumb-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
  margin-top: 20px;
}

.thumb-grid img {
  width: 100%;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: #000;
}

.history-card {
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 14px;
  padding: 16px;
  margin-bottom: 12px;
  background: rgba(255, 255, 255, 0.02);
}

.message {
  margin: 12px 0;
  padding: 12px 16px;
  border-radius: 10px;
  font-size: 0.95rem;
}

.message.success {
  background: rgba(46, 213, 115, 0.15);
  color: #9ef7c1;
}

.message.error {
  background: rgba(255, 107, 107, 0.15);
  color: #ffc2c2;
}

.tabs {
  display: inline-flex;
  gap: 0;
  margin-bottom: 24px;
  border-bottom: 2px solid rgba(255, 255, 255, 0.1);
  width: 100%;
}

.tabs button {
  background: transparent;
  box-shadow: none;
  border-radius: 0;
  padding: 12px 24px;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
}

.tabs button.active {
  cursor: default;
  background: transparent;
  box-shadow: none;
  color: #fff;
  border-bottom: 2px solid var(--brand-primary);
}

.tabs button:hover:not(.active) {
  color: #fff;
  background: rgba(255, 255, 255, 0.05);
  transform: none;
}

.help-text {
  display: inline-block;
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 400;
}

.helper-card {
  margin-top: 20px;
  padding: 16px;
  border: 1px dashed rgba(255, 255, 255, 0.2);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.03);
}

.inline-form {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.inline-form input[type="email"] {
  flex: 1;
  min-width: 200px;
}

.inline-form button {
  flex-shrink: 0;
}

.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  margin-top: 20px;
  padding: 16px;
  border-radius: 14px;
  border: 1px dashed rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text-muted);
}

.loading .spinner {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 4px solid rgba(255, 255, 255, 0.2);
  border-top-color: var(--brand-primary);
  animation: spin 0.9s linear infinite;
}

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

.hidden {
  display: none !important;
}

.result-card {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 14px;
  padding: 16px;
  text-align: center;
}

.result-link {
  display: block;
}

.result-link img {
  width: 100%;
  border-radius: 12px;
}

.result-note {
  margin-top: 10px;
  font-weight: 700;
  color: #ff8c42;
}

.history-link:link,
.history-link:visited,
.result-link:link,
.result-link:visited {
  color: #ff8c42;
  font-weight: 600;
}

.reference-list {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.youtube-preview {
  margin-top: 10px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.02);
}

.youtube-preview img {
  width: 100%;
  height: auto;
  max-height: 320px;
  object-fit: contain;
  display: block;
}

@media (max-width: 600px) {
  .page-shell {
    padding: 20px 12px 60px;
  }
}

/* Responsive Header Title */
.responsive-title {
  font-size: 2.5rem;
  line-height: 1.2;
  word-wrap: break-word;
}

/* File Input Wrapper Layout */
.file-input-wrapper {
  display: grid;
  grid-template-areas: 
    "input button"
    "text text";
  gap: 10px;
  align-items: center;
  grid-template-columns: 1fr auto;
}

.file-input-wrapper input[type="file"] {
  grid-area: input;
  margin-bottom: 0;
}

.file-input-wrapper button {
  grid-area: button;
  padding: 8px 16px;
  font-size: 0.9rem;
  white-space: nowrap;
}

.file-input-wrapper .reference-list {
  grid-area: text;
  margin-top: 0;
}

/* Mobile Adjustments */
@media (max-width: 600px) {
  /* Overwrite previous media query content here if needed, but it cascades */
  
  .responsive-title {
    font-size: 1.75rem; /* Smaller font for mobile to prevent overflow */
  }
  
  .file-input-wrapper {
    grid-template-areas: 
      "input"
      "text"
      "button";
    grid-template-columns: 1fr;
  }
  
  .file-input-wrapper button {
    justify-self: start; /* Align button to start on mobile */
    width: 100%; /* Optional: make full width or keep button size? User asked for "below", default stretch might be good or just start */
  }
}

/* Fix History URL Overflow */
.history-card small {
  display: block;
  overflow-wrap: break-word;
  word-break: break-all; /* Force break long URLs */
  margin: 4px 0;
  line-height: 1.4;
}

/* Aggressive Mobile Title Fix */
@media (max-width: 480px) {
  .responsive-title {
    font-size: 1.4rem !important; /* Force smaller size on very small screens */
    word-break: break-word;
  }
  
  .header-copy {
    width: 100%; /* Ensure container doesn't overflow */
  }
}

/* Footer Styles */
footer {
  margin-top: 4rem;
  text-align: center;
  border-top: 1px solid rgba(255,255,255,0.1);
  padding-top: 2rem;
  color: var(--text-muted);
  font-size: 0.9rem;
}

footer a {
  color: #ff8c42 !important;
  text-decoration: none !important;
  margin: 0 10px;
  transition: color 0.2s;
  font-weight: 600;
}

@media (max-width: 768px) {
  .insight-grid {
    grid-template-columns: 1fr;
  }
}
footer a:hover {
  color: #ff8c42 !important;
}

/* Purchase Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 999;
}

.modal-content {
  background: rgba(16, 22, 43, 0.95);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 20px;
  padding: 24px;
  max-width: 420px;
  width: 100%;
  text-align: center;
}

.modal-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin: 20px 0;
}

.pack-button {
  padding: 12px 20px;
  border-radius: 12px;
  border: none;
  cursor: pointer;
  font-size: 1rem;
  font-weight: 600;
  background: linear-gradient(135deg, #ff8c42, #ff6b6b);
  color: #fff;
  box-shadow: 0 12px 25px rgba(255, 107, 107, 0.35);
  transition: transform 0.2s ease;
}

.pack-button:hover {
  transform: translateY(-2px);
}

.modal-close {
  background: none;
  border: none;
  color: #ff8c42;
  font-weight: 600;
  cursor: pointer;
}

/* Global nav-link rule - should work everywhere */
a.nav-link,
a.nav-link:link,
a.nav-link:visited,
a.nav-link:hover,
a.nav-link:active,
a.nav-link:focus {
  color: #ff8c42 !important;
  text-decoration: none !important;
  font-weight: 600 !important;
}

/* Pagination */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-top: 24px;
}

.page-btn {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  padding: 8px 16px;
  border-radius: 8px;
  color: #fff;
  cursor: pointer;
  font-size: 0.9rem;
  transition: all 0.2s ease;
}

.page-btn:hover:not([disabled]) {
  background: rgba(255, 255, 255, 0.2);
}

.page-btn[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
}

.page-info {
  color: var(--text-muted);
  font-size: 0.9rem;
  font-weight: 600;
}

/* User Email Display */
.user-email {
  font-size: 0.9rem;
  color: var(--text-muted);
  font-weight: 600;
  margin-bottom: 4px;
}

/* File Previews */
.file-previews {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 8px;
}

.file-preview-item {
  position: relative;
  width: 90px;
  height: 90px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: #000;
}

.file-preview-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.file-tag {
  position: absolute;
  top: 0;
  left: 0;
  background: rgba(255, 107, 107, 0.9);
  color: #fff;
  font-size: 0.6rem;
  padding: 2px 4px;
  border-bottom-right-radius: 6px;
  font-weight: 700;
  z-index: 2;
}

/* Google Sign-In Styles */
.google-divider {
  display: flex;
  align-items: center;
  margin: 20px 0;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.google-divider::before,
.google-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: rgba(255, 255, 255, 0.15);
}

.google-divider span {
  padding: 0 16px;
  text-transform: uppercase;
  letter-spacing: 1px;
  font-size: 0.8rem;
}

.google-btn-wrapper {
  display: flex;
  justify-content: center;
  margin-bottom: 20px;
}
