:root {
  /* Default (will be overridden by data-theme) */
  --bg: #ffffff;
  --text: #0f172a;
  --card: #ffffff;
  --muted: #64748b;
  --accent: #2563eb;
  --button-fg: #ffffff;
  --danger: #dc2626;
  --border: #e5e7eb;
  --input-bg: #ffffff;
  --input-border: #d0d7e2;
  --success: #16a34a;
  --warning: #f59e0b;
  --text-muted: #6b7280;

  /* Light palette */
  --light-bg: #ffffff;
  --light-text: #0f172a;
  --light-card: #ffffff;
  --light-muted: #64748b;
  --light-accent: #2563eb;
  --light-button-fg: #ffffff;
  --light-danger: #dc2626;
  --light-border: #e5e7eb;
  --light-input-bg: #ffffff;
  --light-input-border: #d0d7e2;

  /* Dark palette */
  --dark-bg: #0b1320;
  --dark-text: #e6eefc;
  --dark-card: #121a2b;
  --dark-muted: #9bb0d0;
  --dark-accent: #5aa3ff;
  --dark-button-fg: #001433;
  --dark-danger: #ff6b6b;
  --dark-border: #1e2a46;
  --dark-input-bg: #0d1526;
  --dark-input-border: #283556;
}
[data-theme="light"] {
  --bg: var(--light-bg);
  --text: var(--light-text);
  --card: var(--light-card);
  --muted: var(--light-muted);
  --accent: var(--light-accent);
  --button-fg: var(--light-button-fg);
  --danger: var(--light-danger);
  --border: var(--light-border);
  --input-bg: var(--light-input-bg);
  --input-border: var(--light-input-border);
}
[data-theme="dark"] {
  --bg: var(--dark-bg);
  --text: var(--dark-text);
  --card: var(--dark-card);
  --muted: var(--dark-muted);
  --accent: var(--dark-accent);
  --button-fg: var(--dark-button-fg);
  --danger: var(--dark-danger);
  --border: var(--dark-border);
  --input-bg: var(--dark-input-bg);
  --input-border: var(--dark-input-border);
}

* { box-sizing: border-box; }
html,body { margin:0; padding:0; font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial; background: var(--bg); color: var(--text); }
header { padding: 16px; border-bottom: 1px solid var(--border); }
.row { display:flex; gap: 8px; }
.between { justify-content: space-between; }
.center { align-items: center; }
h1 { margin: 0 0 6px; font-size: 24px; letter-spacing: 0.2px; }
main { max-width: 900px; margin: 20px auto; padding: 0 16px; display: grid; gap: 16px; }
.card { background: var(--card); padding: 16px; border: 1px solid var(--border); border-radius: 10px; }
label { display:block; margin: 8px 0 6px; color: var(--muted); }
input { width: 100%; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--input-border); background: var(--input-bg); color: var(--text); }
button { 
  margin-top: 10px; 
  padding: 12px 18px; 
  border:0; 
  border-radius: 8px; 
  background: var(--accent); 
  color: var(--button-fg); 
  font-weight: 600; 
  cursor: pointer;
  transition: all 0.2s ease;
  font-size: 15px;
}
button:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
}
button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
button.danger { background: var(--danger); color: #fff; }

/* Make Add button more prominent */
#subscribe {
  background: var(--accent);
  font-size: 16px;
  padding: 14px 24px;
  margin-top: 16px;
}

/* Save Contact button styling */
#saveContact {
  background: var(--success);
  padding: 12px 20px;
}

.checks { display:flex; flex-wrap: wrap; gap: 10px 16px; margin-top: 10px; }
.checks label { color: var(--text); }
.status { margin-top:8px; }
.status.ok { color: #16a34a; }
.status.bad { color: #dc2626; }

/* Field status indicators */
.field-status {
  display: block;
  font-size: 12px;
  margin-top: 4px;
  min-height: 16px;
}
.field-status.verified { color: var(--success); }
.field-status.unverified { color: var(--warning); }
.field-status.error { color: var(--danger); }

/* Better field layout */
.field {
  position: relative;
  margin-bottom: 8px;
}

/* Section styling for better organization */
.forms-section {
  border-top: 1px solid var(--border);
  padding-top: 12px;
  margin-top: 16px;
}

h3 {
  font-weight: 600;
  letter-spacing: -0.02em;
}
#watchlist .row { display:grid; grid-template-columns: 40px 90px 1fr 1fr 120px; gap: 8px; align-items:center; padding: 8px 0; border-bottom: 1px solid var(--border); }
.delete { width: 32px; height: 32px; border-radius: 50%; background:#253456; color:#d7e6ff; font-weight:900; display:flex; align-items:center; justify-content:center; padding:0; margin:0; }
.delete:hover { background:#2e4170; }
.form { color: var(--muted); }
.hint { color: var(--muted); font-size: 12px; }

/* Saved note feedback */
.btn-saved { background: #16a34a; color: #fff; position: relative; }
.btn-saved::after { content: "✓"; font-weight: 900; margin-left: 6px; }
footer { text-align:center; padding: 16px; color: var(--muted); }
details { margin: 6px 0 8px; }
.methods { display:flex; gap:16px; flex-wrap:wrap; margin: 8px 0 6px; }

/* Theme control with label */
.theme-control { 
  display: flex; 
  align-items: center; 
  gap: 8px; 
}
.theme-label { 
  font-size: 12px; 
  color: var(--muted); 
  font-weight: 500;
  min-width: 32px;
  text-align: center;
}

/* Compact theme switch */
.switch { position: relative; display: inline-block; width: 40px; height: 22px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: #cbd5e1; transition: .2s; border-radius: 999px; border: 1px solid var(--border); }
.slider:before { position: absolute; content: ""; height: 18px; width: 18px; left: 1px; bottom: 1px; background-color: #ffffff; transition: .2s; border-radius: 50%; }
.switch input:checked + .slider { background-color: #334155; }
.switch input:checked + .slider:before { transform: translateX(18px); background-color: #e2e8f0; }

/* Footer links: ensure readable contrast on dark and light */
footer .links a,
footer a { color: var(--accent); text-decoration: underline; font-weight: 600; }
footer .links a:visited,
footer a:visited { color: var(--accent); }

/* Suggestions dropdown */
.suggestions { display: none; margin-top: 6px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); box-shadow: 0 4px 12px rgba(0,0,0,0.08); max-height: 240px; overflow: auto; }
.suggestions.show { display: block; }
.suggestions .item { padding: 8px 10px; cursor: pointer; display: flex; gap: 8px; align-items: center; }
.suggestions .item .ticker { font-weight: 600; color: var(--text); }
.suggestions .item .name { color: var(--muted); }
.suggestions .item:hover, .suggestions .item.active { background: var(--muted-bg); }

/* Forms inline under ticker */
.forms-inline { margin-top: 8px; }
.forms-inline .label { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.forms-inline .checks { display: flex; flex-wrap: wrap; gap: 8px 10px; }
.forms-inline .checks label { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; }

/* Chip-style checkboxes - Enhanced for visibility */
.chips { gap: 8px 8px; }
.chip { 
  border: 2px solid var(--input-border); 
  padding: 8px 12px; 
  border-radius: 8px; 
  background: var(--input-bg); 
  transition: all .2s ease; 
  white-space: nowrap; 
  cursor: pointer;
  position: relative;
  min-height: 36px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.chip input { 
  margin: 0; 
  accent-color: var(--accent); 
  width: 16px;
  height: 16px;
}
.chip .t { 
  font-weight: 600; 
  letter-spacing: 0.2px; 
  color: var(--text);
  font-size: 13px;
  display: block;
}
.chip:hover { 
  background: var(--accent);
  border-color: var(--accent);
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}
.chip:hover .t,
.chip:hover .form-desc {
  color: var(--button-fg);
}
.chip input:checked ~ div .t {
  color: var(--accent);
  font-weight: 700;
}
.chip input:checked ~ div .form-desc {
  color: var(--accent);
}
.chip:has(input:checked) {
  background: rgba(37,99,235,0.1);
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

/* Form descriptions - Always visible */
.form-desc {
  font-size: 11px;
  color: var(--muted);
  display: block;
  margin-top: 2px;
  line-height: 1.2;
}

.all-forms { 
  display: grid; 
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); 
  gap: 12px 10px; 
  align-items: center; 
}

@media (max-width: 720px) {
  .all-forms { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
}
@media (max-width: 500px) {
  .all-forms { grid-template-columns: 1fr; }
}

/* Compact contact section */
.contact-grid { 
  display: grid; 
  grid-template-columns: 1fr 1fr; 
  gap: 12px; 
  align-items: start; 
}
.contact-grid .field { 
  display: flex; 
  flex-direction: column; 
}
.contact-grid .field label { 
  display: block; 
  font-size: 14px; 
  color: var(--muted); 
  margin-bottom: 6px; 
}
.actions { 
  display: flex; 
  gap: 12px; 
  margin-top: 16px; 
}
.actions button {
  flex: 1;
}

@media (max-width: 720px) {
  .contact-grid { 
    grid-template-columns: 1fr; 
    gap: 16px; 
  }
  .actions { 
    flex-direction: column; 
    gap: 10px; 
  }
  .actions button {
    flex: none;
    width: 100%;
  }
}

@media (max-width: 480px) {
  .contact-grid .field input {
    font-size: 16px; /* Prevents zoom on iOS */
  }
  .contact-grid .field label {
    font-size: 13px;
  }
  .actions {
    margin-top: 20px;
  }
}

@media (max-width: 640px) {
  #watchlist .row { grid-template-columns: 40px 1fr 1fr; grid-auto-rows: auto; }
  #watchlist .row strong { grid-column: 2 / span 2; }
  #watchlist .row .form { grid-column: 2 / span 2; }
  #watchlist .row .note { grid-column: 2 / span 2; }
  #watchlist .row .save { grid-column: 3; justify-self: end; }
}

/* Modal/Popup System */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0.2s ease;
}

.modal-overlay.show {
  opacity: 1;
  visibility: visible;
}

.modal {
  background: var(--card);
  border-radius: 16px;
  padding: 24px;
  max-width: 420px;
  width: 90%;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.15);
  border: 1px solid var(--border);
  transform: translateY(10px);
  transition: transform 0.2s ease;
}

.modal-overlay.show .modal {
  transform: translateY(0);
}

.modal-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.modal-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
}

.modal-icon.success {
  background: rgba(34, 197, 94, 0.1);
  color: #22c55e;
}

.modal-icon.info {
  background: rgba(59, 130, 246, 0.1);
  color: #3b82f6;
}

.modal-icon.warning {
  background: rgba(251, 146, 60, 0.1);
  color: #fb923c;
}

.modal-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
  margin: 0;
}

.modal-message {
  color: var(--muted);
  line-height: 1.5;
  margin-bottom: 20px;
}

.modal-actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
}

.modal-button {
  padding: 10px 20px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.15s;
  border: none;
}

.modal-button.primary {
  background: var(--accent);
  color: var(--button-fg);
}

.modal-button.primary:hover {
  background: #1d4ed8;
}

.modal-button.secondary {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}

.modal-button.secondary:hover {
  background: var(--border);
  color: var(--text);
}

/* New Header Layout */
.header-layout {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
}

.header-center {
  flex: 1;
  text-align: center;
}

.header-center h1 {
  margin: 0 0 6px;
  font-size: 24px;
  letter-spacing: 0.2px;
}

.header-center p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.4;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 12px;
}

.login-btn {
  margin: 0;
  padding: 8px 16px;
  font-size: 14px;
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
}

.login-btn:hover {
  background: var(--accent);
  color: var(--button-fg);
}

.upgrade {
  margin: 0;
  padding: 8px 16px;
  font-size: 14px;
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  color: white;
  border: none;
  font-weight: 600;
}

.upgrade:hover {
  background: linear-gradient(135deg, #1d4ed8, #1e40af);
  transform: translateY(-1px);
}

/* Enhanced Theme Control with Icons */
.theme-control { 
  display: flex; 
  align-items: center; 
  gap: 6px; 
}

.theme-icon {
  font-size: 16px;
  opacity: 0.6;
  transition: opacity 0.2s;
}

.theme-icon.light {
  opacity: 1;
}

[data-theme="dark"] .theme-icon.light {
  opacity: 0.4;
}

[data-theme="dark"] .theme-icon.dark {
  opacity: 1;
}

[data-theme="light"] .theme-icon.dark {
  opacity: 0.4;
}

/* Frequency Options */
.frequency-options {
  display: grid;
  gap: 12px;
  margin: 16px 0;
}

.frequency-option {
  display: flex;
  align-items: stretch;
}

.frequency-option input[type="radio"] {
  margin: 0;
  width: auto;
}

.frequency-label {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 16px 20px;
  border: 2px solid var(--input-border);
  border-radius: 12px;
  background: var(--input-bg);
  cursor: pointer;
  transition: all 0.2s ease;
  margin-left: 12px;
}

.frequency-label:hover {
  border-color: var(--accent);
  background: rgba(37,99,235,0.05);
}

.frequency-option input:checked + .frequency-label {
  border-color: var(--accent);
  background: rgba(37,99,235,0.1);
  box-shadow: 0 0 0 1px var(--accent);
}

.frequency-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
}

.frequency-desc {
  font-size: 14px;
  color: var(--muted);
  margin-bottom: 8px;
  line-height: 1.4;
}

.frequency-price {
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
}

.frequency-label.pro .frequency-title {
  background: linear-gradient(135deg, #2563eb, #7c3aed);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.frequency-label.pro .frequency-price {
  color: #16a34a;
}

/* Responsive adjustments */
@media (max-width: 768px) {
  .header-layout {
    flex-direction: column;
    gap: 16px;
  }
  
  .header-center {
    order: 1;
  }
  
  .header-controls {
    order: 2;
    justify-content: center;
  }
  
  .frequency-options {
    gap: 8px;
  }
  
  .frequency-label {
    padding: 12px 16px;
  }
}

/* PRO Settings Styles */
.pro-settings {
  background: linear-gradient(135deg, rgba(37, 99, 235, 0.05), rgba(124, 58, 237, 0.05));
  border: 2px solid transparent;
  background-clip: padding-box;
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 20px;
  position: relative;
  overflow: hidden;
}

.pro-settings::before {
  content: '';
  position: absolute;
  inset: 0;
  padding: 2px;
  background: linear-gradient(135deg, #2563eb, #7c3aed);
  border-radius: 12px;
  mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  mask-composite: xor;
  -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  pointer-events: none;
}

.pro-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.pro-badge {
  background: linear-gradient(135deg, #2563eb, #7c3aed);
  color: white;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.pro-header h3 {
  margin: 0;
  color: var(--text);
  font-size: 18px;
  font-weight: 600;
}

.pro-content {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.toggle-switch {
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  user-select: none;
}

.toggle-switch input[type="checkbox"] {
  position: relative;
  width: 50px;
  height: 26px;
  appearance: none;
  background: var(--border);
  border-radius: 13px;
  transition: all 0.3s ease;
  cursor: pointer;
}

.toggle-switch input[type="checkbox"]:checked {
  background: linear-gradient(135deg, #2563eb, #7c3aed);
}

.toggle-switch input[type="checkbox"]::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 22px;
  height: 22px;
  background: white;
  border-radius: 50%;
  transition: all 0.3s ease;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.toggle-switch input[type="checkbox"]:checked::after {
  transform: translateX(24px);
}

.toggle-text {
  font-weight: 600;
  color: var(--text);
  font-size: 16px;
}

.pro-description {
  font-size: 14px;
  color: var(--muted);
  margin: 0;
  line-height: 1.4;
}

[data-theme="dark"] .pro-settings {
  background: linear-gradient(135deg, rgba(90, 163, 255, 0.08), rgba(139, 92, 246, 0.08));
}

[data-theme="dark"] .toggle-switch input[type="checkbox"]::after {
  background: var(--dark-card);
}

/* Animation for toggle state change */
.toggle-switch input[type="checkbox"]:focus {
  outline: 2px solid rgba(37, 99, 235, 0.2);
  outline-offset: 2px;
}

/* Loading states */
.loading-spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid transparent;
  border-top: 2px solid currentColor;
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-right: 8px;
}

.loading-spinner.large {
  width: 24px;
  height: 24px;
  border-width: 3px;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

.button-loading {
  opacity: 0.8;
  cursor: not-allowed;
  position: relative;
}

.button-loading::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 16px;
  height: 16px;
  border: 2px solid transparent;
  border-top: 2px solid currentColor;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

/* Loading overlay for sections */
.section-loading {
  position: relative;
  pointer-events: none;
}

.section-loading::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(255, 255, 255, 0.8);
  backdrop-filter: blur(2px);
  z-index: 10;
  border-radius: 8px;
}

[data-theme="dark"] .section-loading::before {
  background: rgba(0, 0, 0, 0.8);
}

.section-loading::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 32px;
  height: 32px;
  border: 3px solid transparent;
  border-top: 3px solid var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  z-index: 11;
}

@media (max-width: 768px) {
  .pro-settings {
    padding: 16px;
    margin-bottom: 16px;
  }
  
  .pro-header h3 {
    font-size: 16px;
  }
  
  .toggle-text {
    font-size: 14px;
  }
}