:root {
  --blue: #0a66c2;
  --blue-dark: #084f98;
  --blue-light: #e8f0fb;
  --green: #057642;
  --green-light: #e6f4ea;
  --red: #cc1016;
  --red-light: #fce8e8;
  --purple: #7c3aed;
  --purple-light: #ede9fe;
  --orange: #d97706;
  --orange-light: #fef3c7;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-500: #6b7280;
  --gray-700: #374151;
  --gray-900: #111827;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,.1), 0 2px 4px -1px rgba(0,0,0,.06);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--gray-50);
  color: var(--gray-900);
  min-height: 100vh;
}

/* ── Header ── */
header {
  background: white;
  border-bottom: 1px solid var(--gray-200);
  padding: 0 24px;
  display: flex;
  align-items: center;
  gap: 16px;
  height: 60px;
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: var(--shadow);
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 18px;
  color: var(--blue);
  white-space: nowrap;
}

.logo svg { width: 28px; height: 28px; }

/* ── Header nav tabs ── */
.header-nav {
  display: flex;
  gap: 4px;
  margin-left: 8px;
}

.nav-tab {
  padding: 6px 16px;
  border: none;
  border-radius: 20px;
  background: transparent;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  color: var(--gray-500);
  transition: all .15s;
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
}

.nav-tab:hover { background: var(--gray-100); color: var(--gray-900); }
.nav-tab.active { background: var(--blue-light); color: var(--blue); font-weight: 600; }

.nav-badge {
  background: var(--blue);
  color: white;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 700;
  padding: 1px 6px;
  min-width: 18px;
  text-align: center;
}

.auth-area { display: flex; align-items: center; gap: 12px; margin-left: auto; }

.user-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--blue-light);
  border-radius: 20px;
  padding: 6px 14px;
  font-size: 14px;
  font-weight: 500;
  color: var(--blue);
  white-space: nowrap;
}

.user-badge svg { width: 16px; height: 16px; }

/* ── Layout ── */
main {
  max-width: 900px;
  margin: 32px auto;
  padding: 0 16px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* ── Cards ── */
.card {
  background: white;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.card-header {
  padding: 18px 24px;
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  align-items: center;
  gap: 10px;
}

.card-header h2 {
  font-size: 16px;
  font-weight: 600;
  color: var(--gray-900);
}

.step-badge {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--blue);
  color: white;
  font-size: 13px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.step-badge.done { background: var(--green); }
.step-badge.locked { background: var(--gray-300); }

.card-body { padding: 24px; }

/* ── Forms ── */
label {
  display: block;
  font-size: 14px;
  font-weight: 500;
  color: var(--gray-700);
  margin-bottom: 6px;
}

input[type="text"], input[type="datetime-local"], textarea, select {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--gray-300);
  border-radius: 8px;
  font-size: 15px;
  font-family: inherit;
  color: var(--gray-900);
  outline: none;
  transition: border-color .15s;
  background: white;
}

input[type="text"]:focus, input[type="datetime-local"]:focus,
textarea:focus, select:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(10, 102, 194, .12);
}

textarea {
  resize: vertical;
  min-height: 160px;
  line-height: 1.6;
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 10px 20px;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s;
  text-decoration: none;
  white-space: nowrap;
}

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

.btn-primary { background: var(--blue); color: white; }
.btn-primary:hover:not(:disabled) { background: var(--blue-dark); }

.btn-success { background: var(--green); color: white; }
.btn-success:hover:not(:disabled) { background: #045c33; }

.btn-outline {
  background: white;
  border: 1.5px solid var(--gray-300);
  color: var(--gray-700);
}
.btn-outline:hover:not(:disabled) { border-color: var(--blue); color: var(--blue); }

.btn-danger { background: var(--red); color: white; }
.btn-danger:hover:not(:disabled) { background: #a50d12; }

.btn-purple { background: var(--purple); color: white; }
.btn-purple:hover:not(:disabled) { background: #6d28d9; }

.btn-sm { padding: 6px 12px; font-size: 13px; }

/* ── LinkedIn connect button ── */
.btn-linkedin {
  background: var(--blue);
  color: white;
  padding: 10px 20px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 14px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  transition: background .15s;
}
.btn-linkedin:hover { background: var(--blue-dark); }
.btn-linkedin svg { width: 18px; height: 18px; }

/* ── Topics grid ── */
.topics-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 16px;
}

@media (max-width: 580px) { .topics-grid { grid-template-columns: 1fr; } }

.topic-card {
  padding: 14px 16px;
  border: 2px solid var(--gray-200);
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  line-height: 1.5;
  transition: all .15s;
  background: white;
  text-align: left;
}
.topic-card:hover { border-color: var(--blue); background: var(--blue-light); }
.topic-card.selected { border-color: var(--blue); background: var(--blue-light); color: var(--blue); font-weight: 500; }

/* ── Post actions ── */
.post-actions {
  display: flex;
  gap: 10px;
  margin-top: 16px;
  flex-wrap: wrap;
}

.schedule-row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  margin-top: 12px;
  flex-wrap: wrap;
}

.schedule-row .field { flex: 1; min-width: 200px; }

/* ── Format toolbar ── */
.format-toolbar {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 6px;
}

.fmt-btn {
  width: 30px;
  height: 28px;
  border: 1px solid var(--gray-300);
  border-radius: 4px;
  background: white;
  cursor: pointer;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all .15s;
  color: var(--gray-700);
  flex-shrink: 0;
}

.fmt-btn:hover {
  border-color: var(--blue);
  color: var(--blue);
  background: var(--blue-light);
}

.fmt-hint {
  font-size: 11px;
  color: var(--gray-500);
  margin-left: 4px;
}

/* ── Counter ── */
.char-counter {
  text-align: right;
  font-size: 12px;
  color: var(--gray-500);
  margin-top: 4px;
}
.char-counter.warn { color: #d97706; }
.char-counter.over { color: var(--red); }

/* ── Queue ── */
.queue-item {
  border: 1px solid var(--gray-200);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 10px;
  background: var(--gray-50);
}
.queue-item:last-child { margin-bottom: 0; }

.queue-item-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 10px;
}

.queue-time {
  font-size: 13px;
  font-weight: 600;
  color: var(--gray-700);
}

.queue-content {
  font-size: 14px;
  color: var(--gray-700);
  line-height: 1.5;
  white-space: pre-wrap;
  max-height: 80px;
  overflow: hidden;
  mask-image: linear-gradient(to bottom, black 60%, transparent 100%);
}

.queue-actions { display: flex; gap: 6px; }

.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}
.badge-pending { background: #fef3c7; color: #92400e; }
.badge-published { background: var(--green-light); color: var(--green); }
.badge-failed { background: var(--red-light); color: var(--red); }
.badge-needs_reauth { background: var(--orange-light); color: var(--orange); }

/* ── Loading ── */
.spinner {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2.5px solid rgba(255,255,255,.4);
  border-top-color: white;
  border-radius: 50%;
  animation: spin .7s linear infinite;
  flex-shrink: 0;
}
.spinner.dark {
  border-color: rgba(10,102,194,.2);
  border-top-color: var(--blue);
}

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

/* ── Alerts ── */
.alert {
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 14px;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.alert-success { background: var(--green-light); color: var(--green); border: 1px solid #b7dfca; }
.alert-error { background: var(--red-light); color: var(--red); border: 1px solid #f5b8b9; }
.alert-info { background: var(--blue-light); color: var(--blue); border: 1px solid #b3d0f0; }
.alert-warning { background: var(--orange-light); color: var(--orange); border: 1px solid #fbbf24; }

/* ── Empty state ── */
.empty-state {
  text-align: center;
  padding: 32px 16px;
  color: var(--gray-500);
  font-size: 14px;
}

/* ── Connect prompt ── */
.connect-prompt {
  text-align: center;
  padding: 40px 24px;
}
.connect-prompt p {
  color: var(--gray-500);
  font-size: 14px;
  margin-bottom: 16px;
}

/* ── Divider ── */
.divider {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--gray-500);
  font-size: 13px;
  margin: 12px 0;
}
.divider::before, .divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--gray-200);
}

/* ── Disabled overlay ── */
.section-disabled { opacity: .45; pointer-events: none; }

/* ── Templates ── */
.templates-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 10px;
}

.template-card {
  border: 2px solid var(--gray-200);
  border-radius: 8px;
  padding: 14px;
  cursor: default;
  background: var(--gray-50);
  transition: all .15s;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.template-card.selected {
  border-color: var(--purple);
  background: var(--purple-light);
}

.template-card:hover:not(.selected) {
  border-color: var(--gray-400);
  background: white;
}

.template-card-name {
  font-size: 13px;
  font-weight: 700;
  color: var(--gray-900);
}

.template-card.selected .template-card-name {
  color: var(--purple);
}

.template-card-preview {
  font-size: 11px;
  color: var(--gray-500);
  line-height: 1.4;
  white-space: pre-wrap;
  max-height: 56px;
  overflow: hidden;
  mask-image: linear-gradient(to bottom, black 50%, transparent 100%);
}

.template-card-actions {
  display: flex;
  gap: 4px;
  margin-top: auto;
}

.template-card-actions .btn-sm {
  padding: 4px 8px;
  font-size: 12px;
  flex: 1;
  justify-content: center;
}

.template-builtin-tag {
  font-size: 10px;
  color: var(--gray-500);
  background: var(--gray-100);
  border-radius: 4px;
  padding: 1px 5px;
  display: inline-block;
}

/* ── Metrics ── */
.metrics-summary-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}

@media (max-width: 600px) {
  .metrics-summary-row { grid-template-columns: repeat(2, 1fr); }
}

.metric-stat-card {
  background: var(--gray-50);
  border: 1px solid var(--gray-200);
  border-radius: 8px;
  padding: 16px;
  text-align: center;
}

.metric-stat-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--gray-900);
  line-height: 1.2;
}

.metric-stat-label {
  font-size: 12px;
  color: var(--gray-500);
  margin-top: 4px;
  text-transform: uppercase;
  letter-spacing: .5px;
}

.metrics-post-item {
  border: 1px solid var(--gray-200);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 10px;
  background: white;
}

.metrics-post-item:last-child { margin-bottom: 0; }

.metrics-post-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 10px;
  gap: 12px;
}

.metrics-post-date {
  font-size: 12px;
  color: var(--gray-500);
}

.metrics-post-content {
  font-size: 14px;
  color: var(--gray-700);
  line-height: 1.5;
  max-height: 60px;
  overflow: hidden;
  mask-image: linear-gradient(to bottom, black 50%, transparent 100%);
  white-space: pre-wrap;
  margin-bottom: 12px;
}

.metrics-row {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}

.metric-pill {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 13px;
  font-weight: 600;
  color: var(--gray-700);
  background: var(--gray-100);
  border-radius: 20px;
  padding: 4px 12px;
}

.metric-pill span { color: var(--gray-500); font-weight: 400; }

.metrics-last-updated {
  font-size: 11px;
  color: var(--gray-400);
  margin-top: 8px;
}
