/* ============================================================
   MAD About Words News — Writing Industry Briefings
   Clean, professional design inspired by madaboutwords.com
   ============================================================ */

:root {
  --bg: #f9fafb;
  --white: #ffffff;
  --navy: #1a2332;
  --navy-mid: #2c3e50;
  --navy-light: #3d5a73;
  --navy-pale: #e8eef3;
  --coral: #e74c3c;
  --coral-light: #f25c4e;
  --coral-pale: #fde8e6;
  --teal: #26a69a;
  --text: #2d3748;
  --text-light: #718096;
  --border: #e2e8f0;
  --green: #38a169;
  --red: #e53e3e;
  --radius: 8px;
  --shadow: 0 2px 8px rgba(0,0,0,0.08);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
  min-height: 100vh;
}

/* ---- Header ---- */
.site-header {
  background: var(--navy);
  padding: 16px 24px;
  display: flex;
  align-items: center;
  gap: 16px;
}
.site-header .logo-area {
  display: flex;
  align-items: center;
  gap: 14px;
}
.site-header .logo-area img {
  height: 44px;
  width: auto;
}
.site-header h1 {
  color: #fff;
  font-size: 1.35em;
  font-weight: 700;
  letter-spacing: 0.01em;
}
.site-header h1 .brand-mad {
  color: var(--coral);
  font-weight: 800;
}
.site-header .tagline {
  color: rgba(255,255,255,0.6);
  font-size: 0.82em;
  font-style: italic;
}

/* ---- Nav tabs ---- */
.nav-tabs {
  display: flex;
  background: var(--navy-mid);
  padding: 0 16px;
  gap: 2px;
  overflow-x: auto;
}
.nav-tab {
  padding: 10px 20px;
  color: rgba(255,255,255,0.65);
  cursor: pointer;
  font-size: 0.88em;
  border-bottom: 3px solid transparent;
  white-space: nowrap;
  font-family: inherit;
  transition: color 0.2s, border-color 0.2s;
  background: none;
  border-top: none;
  border-left: none;
  border-right: none;
}
.nav-tab:hover { color: #fff; }
.nav-tab.active { color: #fff; border-bottom-color: var(--coral); }

/* ---- Main layout ---- */
.main-content {
  max-width: 900px;
  margin: 0 auto;
  padding: 28px 20px;
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ---- Cards ---- */
.card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
}
.card-title {
  font-size: 1.1em;
  font-weight: 600;
  color: var(--navy);
  margin-bottom: 16px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

/* ---- Forms ---- */
.form-group { margin-bottom: 18px; }
.form-group label {
  display: block;
  font-size: 0.9em;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}
.form-group .hint {
  font-size: 0.82em;
  color: var(--text-light);
  margin-top: 4px;
  font-style: italic;
}
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="time"],
select,
textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 5px;
  font-size: 0.95em;
  font-family: inherit;
  color: var(--text);
  background: var(--white);
  transition: border-color 0.2s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--coral);
  box-shadow: 0 0 0 3px var(--coral-pale);
}

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 10px 20px;
  border-radius: 5px;
  border: none;
  cursor: pointer;
  font-size: 0.95em;
  font-family: inherit;
  font-weight: 600;
  transition: opacity 0.2s, transform 0.1s;
}
.btn:hover { opacity: 0.88; }
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--coral); color: #fff; }
.btn-gold { background: var(--teal); color: #fff; }
.btn-outline { background: transparent; color: var(--navy); border: 1.5px solid var(--navy); }
.btn-sm { padding: 6px 14px; font-size: 0.85em; }
.btn-danger { background: var(--red); color: #fff; }

/* ---- Topic chip selector ---- */
.topic-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 6px;
}
.topic-chip {
  padding: 5px 13px;
  border-radius: 20px;
  border: 1.5px solid var(--border);
  font-size: 0.85em;
  cursor: pointer;
  color: var(--text-light);
  background: #fff;
  transition: all 0.15s;
  font-family: inherit;
}
.topic-chip:hover { border-color: var(--coral-light); color: var(--coral); }
.topic-chip.selected {
  background: var(--coral);
  color: #fff;
  border-color: var(--coral);
}

/* ---- Radio/toggle rows ---- */
.option-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.option-btn {
  padding: 7px 16px;
  border-radius: 5px;
  border: 1.5px solid var(--border);
  cursor: pointer;
  font-size: 0.88em;
  font-family: inherit;
  color: var(--text-light);
  background: #fff;
  transition: all 0.15s;
}
.option-btn.active { background: var(--coral); color: #fff; border-color: var(--coral); }

/* ---- Toggle switch ---- */
.toggle-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}
.toggle-label { font-size: 0.9em; color: var(--text); }
.toggle {
  position: relative;
  width: 44px;
  height: 24px;
  flex-shrink: 0;
}
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--border);
  border-radius: 24px;
  cursor: pointer;
  transition: background 0.2s;
}
.toggle-slider::before {
  content: '';
  position: absolute;
  width: 18px;
  height: 18px;
  left: 3px;
  top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s;
}
.toggle input:checked + .toggle-slider { background: var(--coral); }
.toggle input:checked + .toggle-slider::before { transform: translateX(20px); }

/* ---- Inbox address display ---- */
.inbox-address {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--navy-pale);
  border: 1px solid var(--navy-light);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 16px;
}
.inbox-address code {
  font-size: 1em;
  color: var(--navy);
  font-weight: 600;
  font-family: monospace;
  flex: 1;
}
.inbox-not-setup {
  color: var(--text-light);
  font-style: italic;
  font-size: 0.9em;
}

/* ---- Recipient tags ---- */
.recipient-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}
.recipient-tag {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--navy-pale);
  color: var(--navy);
  border: 1px solid var(--navy-light);
  border-radius: 20px;
  padding: 4px 12px;
  font-size: 0.87em;
}
.recipient-tag button {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--navy-light);
  font-size: 1em;
  padding: 0;
  line-height: 1;
}
.recipient-tag button:hover { color: var(--red); }

/* ---- Progress / SSE updates ---- */
.progress-area {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-top: 16px;
  display: none;
}
.progress-area.visible { display: block; }
.progress-log {
  max-height: 280px;
  overflow-y: auto;
  font-size: 0.88em;
  font-family: 'SF Mono', 'Fira Code', monospace;
  color: var(--text);
}
.log-line { padding: 2px 0; }
.log-line.success { color: var(--green); }
.log-line.error { color: var(--red); }
.log-line.info { color: var(--text-light); }

/* ---- Briefing display ---- */
.briefing-text {
  white-space: pre-wrap;
  font-size: 0.92em;
  line-height: 1.8;
  color: var(--text);
  max-height: 600px;
  overflow-y: auto;
  padding: 16px;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

/* ---- Briefing history list ---- */
.briefing-list { list-style: none; }
.briefing-item {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}
.briefing-item:last-child { border-bottom: none; }
.briefing-item-meta {
  flex: 1;
}
.briefing-item-date { font-weight: 600; font-size: 0.9em; color: var(--navy); }
.briefing-item-count { font-size: 0.82em; color: var(--text-light); }
.briefing-item-preview {
  font-size: 0.85em;
  color: var(--text-light);
  margin-top: 4px;
  font-style: italic;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.briefing-item-actions { display: flex; gap: 8px; flex-shrink: 0; }

/* ---- Pending subscription confirmations ---- */
.confirmation-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}
.confirmation-item:last-child { border-bottom: none; }
.confirmation-item-meta { flex: 1; min-width: 0; }
.confirmation-item-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
  align-items: center;
}
.confirmation-item-actions .btn { text-decoration: none; }

/* ---- Scheduler day chips ---- */
.day-chips { display: flex; gap: 6px; flex-wrap: wrap; }
.day-chip {
  padding: 5px 12px;
  border-radius: 20px;
  border: 1.5px solid var(--border);
  font-size: 0.85em;
  cursor: pointer;
  background: #fff;
  color: var(--text-light);
  transition: all 0.15s;
  font-family: inherit;
}
.day-chip.selected { background: var(--coral); color: #fff; border-color: var(--coral); }

/* ---- Status badges ---- */
.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 12px;
  font-size: 0.78em;
  font-weight: 600;
}
.badge-green { background: #c6f6d5; color: #276749; }
.badge-red { background: #fed7d7; color: #9b2c2c; }
.badge-gray { background: var(--border); color: var(--text-light); }

/* ---- Alerts ---- */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 0.9em;
  margin-bottom: 14px;
}
.alert-success { background: #c6f6d5; color: #276749; border: 1px solid #9ae6b4; }
.alert-error { background: #fed7d7; color: #9b2c2c; border: 1px solid #feb2b2; }
.alert-info { background: var(--coral-pale); color: #92400e; border: 1px solid #f5b7b1; }

/* ---- Empty states ---- */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-light);
  font-style: italic;
}

/* ---- Auth pages ---- */
.auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
}
.auth-card {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: 0 4px 24px rgba(0,0,0,0.12);
  max-width: 420px;
  width: 100%;
  overflow: hidden;
}
.auth-header {
  background: var(--white);
  padding: 28px 24px 20px;
  text-align: center;
  border-bottom: 1px solid var(--border);
}
.auth-header .auth-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-bottom: 10px;
}
.auth-header .auth-logo img {
  height: 40px;
  width: auto;
}
.auth-header .auth-logo-full {
  display: flex;
  justify-content: center;
  margin-bottom: 6px;
}
.auth-header .auth-logo-full img {
  width: 280px;
  max-width: 100%;
  height: auto;
}
.auth-header h1 { color: var(--navy); font-size: 1.3em; margin: 0 0 6px; }
.auth-header h1 .brand-mad { color: var(--coral); font-weight: 800; }
.auth-header p { color: var(--text-light); font-size: 0.9em; margin: 0; font-style: italic; }
.auth-card form,
.auth-card > div:not(.auth-header) { padding: 0 24px; }
.auth-card form { padding: 20px 24px 24px; }
.btn-full { width: 100%; justify-content: center; }

/* ---- User header bar ---- */
.user-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-left: auto;
}
.user-bar .greeting {
  font-size: 0.88em;
  color: rgba(255,255,255,0.75);
  font-style: italic;
}
.user-bar .btn-logout {
  background: rgba(255,255,255,0.12);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.25);
  padding: 5px 14px;
  font-size: 0.82em;
  border-radius: 4px;
  cursor: pointer;
  font-family: inherit;
}
.user-bar .btn-logout:hover { background: rgba(255,255,255,0.22); }

/* ---- Setup checklist ---- */
.setup-checklist {
  background: var(--coral-pale);
  border: 1px solid #f5b7b1;
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 20px;
}
.setup-checklist h3 {
  color: #922b21;
  font-size: 1em;
  margin: 0 0 12px;
}
.setup-step {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 0;
  font-size: 0.9em;
  color: var(--text);
}
.setup-step .step-icon {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75em;
  flex-shrink: 0;
}
.setup-step .step-icon.done { background: #c6f6d5; color: #276749; }
.setup-step .step-icon.todo { background: var(--border); color: var(--text-light); }
.setup-step.done { color: var(--text-light); text-decoration: line-through; }

/* ---- User management table ---- */
.user-table { width: 100%; border-collapse: collapse; }
.user-table th, .user-table td {
  padding: 10px 12px;
  text-align: left;
  font-size: 0.9em;
  border-bottom: 1px solid var(--border);
}
.user-table th { color: var(--text-light); font-weight: 600; font-size: 0.82em; text-transform: uppercase; letter-spacing: 0.05em; }
.user-table td .badge { margin-left: 6px; }

/* ---- Loading spinner ---- */
.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--coral);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Responsive ---- */
@media (max-width: 600px) {
  .main-content { padding: 16px 12px; }
  .card { padding: 16px; }
  .briefing-item { flex-direction: column; }
  .briefing-item-actions { width: 100%; }
  .confirmation-item { flex-direction: column; align-items: flex-start; }
  .confirmation-item-actions { width: 100%; }
  .site-header { flex-direction: column; align-items: flex-start; gap: 8px; }
  .user-bar { margin-left: 0; }
}
