/* ==========================================================================
   RankFlow Design System
   White-label-ready design tokens, components, and layout primitives.
   All subsequent UI templates reference these custom properties and classes.
   ========================================================================== */

/* Google Fonts */
@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;500;600;700&family=DM+Sans:wght@300;400;500;600;700&family=Fira+Code:wght@400;500;600;700&display=swap');

/* ==========================================================================
   1. Design Tokens (CSS Custom Properties)
   ========================================================================== */
:root {
  /* Brand Colors */
  --color-primary: #2563EB;
  --color-primary-hover: #1D4ED8;
  --color-primary-light: #EFF6FF;
  --color-primary-dark: #1E3A8A;
  --color-cta: #F97316;
  --color-cta-hover: #EA580C;
  --color-success: #10B981;
  --color-warning: #EAB308;
  --color-error: #EF4444;

  /* Surfaces */
  --sidebar-bg: #0F172A;
  --sidebar-hover: #1E293B;
  --sidebar-active: var(--color-primary-dark);
  --sidebar-text: #94A3B8;
  --sidebar-text-active: #93C5FD;
  --surface: #FFFFFF;
  --background: #F8FAFC;
  --text-primary: #0F172A;
  --text-secondary: #64748B;
  --text-muted: #94A3B8;
  --border: #E2E8F0;
  --border-light: #F1F5F9;

  /* Typography */
  --font-heading: 'Space Grotesk', system-ui, sans-serif;
  --font-body: 'DM Sans', system-ui, sans-serif;
  --font-mono: 'Fira Code', ui-monospace, monospace;

  /* Spacing & Layout */
  --sidebar-width: 240px;
  --sidebar-collapsed-width: 64px;
  --topbar-height: 56px;
  --border-radius-sm: 6px;
  --border-radius-md: 8px;
  --border-radius-lg: 12px;
  --border-radius-pill: 9999px;

  /* Shadows */
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);

  /* Transitions */
  --transition-speed: 200ms;
}

/* ==========================================================================
   2. Base Typography
   ========================================================================== */
body {
  font-family: var(--font-body);
  color: var(--text-primary);
  background: var(--background);
}

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-heading);
  font-weight: 600;
  line-height: 1.25;
}

/* Utility: monospace / data font */
.font-data {
  font-family: var(--font-mono);
}

/* ==========================================================================
   3. Status Badges (Article Pipeline)
   ========================================================================== */
.badge-status {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1.5;
  border-radius: var(--border-radius-pill);
  white-space: nowrap;
}

.badge-queued {
  background: #F1F5F9;
  color: #475569;
}

.badge-pending_local_falcon {
  background: #FFF7ED;
  color: #9A3412;
}

.badge-researching {
  background: #DBEAFE;
  color: #1E40AF;
}

.badge-brief {
  background: #E0E7FF;
  color: #3730A3;
}

.badge-brief_approved {
  background: #D1FAE5;
  color: #065F46;
}

.badge-writing {
  background: #FEF3C7;
  color: #92400E;
}

.badge-humanizing {
  background: #FDE68A;
  color: #78350F;
}

.badge-review {
  background: #E9D5FF;
  color: #6B21A8;
}

.badge-revision_requested {
  background: #FFE4E6;
  color: #9F1239;
}

.badge-done {
  background: #D1FAE5;
  color: #065F46;
}

.badge-error {
  background: #FEE2E2;
  color: #991B1B;
}

.badge-failed {
  background: #FEE2E2;
  color: #991B1B;
}

.badge-revision_requested {
  background: #FEF3C7;
  color: #92400E;
}

/* ==========================================================================
   4. Project Status Badges
   ========================================================================== */
.badge-active {
  background: #D1FAE5;
  color: #065F46;
}

.badge-setup {
  background: #DBEAFE;
  color: #1E40AF;
}

.badge-paused {
  background: #FEF3C7;
  color: #92400E;
}

.badge-archived {
  background: #F1F5F9;
  color: #475569;
}

/* ==========================================================================
   5. Card Components
   ========================================================================== */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--border-radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 1.5rem;
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--border-radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 1.25rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.kpi-card-hero {
  background: var(--color-primary);
  color: #FFFFFF;
  border: none;
  border-radius: var(--border-radius-lg);
  box-shadow: var(--shadow-md);
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.kpi-value {
  font-family: var(--font-heading);
  font-size: 1.75rem;
  font-weight: 700;
  line-height: 1.2;
}

/* ==========================================================================
   6. Buttons
   ========================================================================== */
.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  font-weight: 600;
  font-family: var(--font-body);
  color: #FFFFFF;
  background: var(--color-primary);
  border: none;
  border-radius: var(--border-radius-md);
  cursor: pointer;
  transition: background var(--transition-speed) ease, box-shadow var(--transition-speed) ease;
}

.btn-primary:hover {
  background: var(--color-primary-hover);
  box-shadow: var(--shadow-md);
}

.btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  font-weight: 600;
  font-family: var(--font-body);
  color: var(--text-primary);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--border-radius-md);
  cursor: pointer;
  transition: background var(--transition-speed) ease, border-color var(--transition-speed) ease;
}

.btn-secondary:hover {
  background: var(--background);
  border-color: #CBD5E1;
}

/* ==========================================================================
   7. Form Elements
   ========================================================================== */

/* Labels */
.edit-label {
  display: block;
  font-family: var(--font-body);
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 0.375rem;
  letter-spacing: 0.01em;
}

/* Text inputs, selects */
.edit-input {
  display: block;
  width: 100%;
  padding: 0.75rem 1rem;
  font-family: var(--font-body);
  font-size: 0.9375rem;
  line-height: 1.5;
  color: var(--text-primary);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--border-radius-md);
  transition: border-color var(--transition-speed) ease, box-shadow var(--transition-speed) ease;
  outline: none;
}

.edit-input:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.edit-input::placeholder {
  color: var(--text-muted);
  font-weight: 400;
}

/* Textareas */
.edit-textarea {
  display: block;
  width: 100%;
  padding: 0.75rem 1rem;
  font-family: var(--font-body);
  font-size: 0.9375rem;
  line-height: 1.6;
  color: var(--text-primary);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--border-radius-md);
  transition: border-color var(--transition-speed) ease, box-shadow var(--transition-speed) ease;
  outline: none;
  resize: vertical;
  min-height: 7rem;
}

.edit-textarea:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.edit-textarea::placeholder {
  color: var(--text-muted);
  font-weight: 400;
}

/* Select dropdown arrow fix */
select.edit-input {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2394A3B8' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  padding-right: 2.5rem;
  cursor: pointer;
}

/* ==========================================================================
   7b. Tab Navigation
   ========================================================================== */
.tab-button {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.5rem 1rem;
  font-family: var(--font-body);
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-secondary);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--border-radius-pill);
  cursor: pointer;
  transition: all var(--transition-speed) ease;
  white-space: nowrap;
}

.tab-button:hover {
  color: var(--text-primary);
  background: var(--background);
  border-color: #CBD5E1;
}

.tab-button.active {
  color: #FFFFFF;
  background: var(--color-primary);
  border-color: var(--color-primary);
}

.tab-button svg {
  flex-shrink: 0;
}

/* ==========================================================================
   8. Sidebar Layout
   ========================================================================== */
.app-layout {
  display: flex;
  min-height: 100vh;
}

.app-sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 40;
  transition: width var(--transition-speed) ease;
  overflow-x: hidden;
  overflow-y: auto;
}

.app-sidebar.collapsed {
  width: var(--sidebar-collapsed-width);
}
.app-sidebar.collapsed .sidebar-label {
  display: none;
}
.app-sidebar.collapsed .sidebar-section-title {
  display: none;
}
.app-sidebar.collapsed .project-switcher-details {
  display: none;
}

.app-main {
  margin-left: var(--sidebar-width);
  flex: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: margin-left var(--transition-speed) ease;
}

.app-sidebar.collapsed + .app-main {
  margin-left: var(--sidebar-collapsed-width);
}

/* ==========================================================================
   8. Sidebar Navigation Items
   ========================================================================== */
.sidebar-nav-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--sidebar-text);
  border-radius: var(--border-radius-md);
  margin: 0 0.5rem;
  text-decoration: none;
  transition: background var(--transition-speed) ease, color var(--transition-speed) ease;
  cursor: pointer;
  white-space: nowrap;
}

.sidebar-nav-item:hover {
  background: var(--sidebar-hover);
  color: #E2E8F0;
}

.sidebar-nav-item.active {
  background: var(--sidebar-active);
  color: var(--sidebar-text-active);
}

.nav-badge {
  margin-left: auto;
  font-size: 0.6875rem;
  font-weight: 700;
  background: var(--color-primary);
  color: #FFFFFF;
  padding: 1px 6px;
  border-radius: var(--border-radius-pill);
  line-height: 1.4;
}

/* ==========================================================================
   9. Topbar
   ========================================================================== */
.app-topbar {
  height: var(--topbar-height);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  position: sticky;
  top: 0;
  z-index: 30;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 1rem;
  min-width: 0;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.topbar-search-trigger {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.375rem 0.75rem;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-muted);
  font-size: 0.8125rem;
  cursor: pointer;
  transition: border-color var(--transition-speed) ease,
              color var(--transition-speed) ease;
}

.topbar-search-trigger:hover {
  border-color: var(--text-secondary);
  color: var(--text-secondary);
}

.topbar-search-trigger kbd {
  font-size: 0.6875rem;
  padding: 0.125rem 0.375rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-family: inherit;
  line-height: 1;
}

.topbar-avatar {
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  background: var(--color-cta);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.025em;
  cursor: pointer;
  user-select: none;
}

/* ==========================================================================
   10. Breadcrumbs
   ========================================================================== */
.breadcrumbs {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  font-size: 0.8125rem;
  color: var(--text-muted);
}

.breadcrumbs a {
  color: var(--text-secondary);
  text-decoration: none;
  transition: color var(--transition-speed) ease;
}

.breadcrumbs a:hover {
  color: var(--color-primary);
}

.breadcrumbs .separator {
  color: var(--text-muted);
  user-select: none;
}

.breadcrumbs .current {
  color: var(--text-primary);
  font-weight: 600;
}

/* ==========================================================================
   11. Command Palette
   ========================================================================== */
.command-palette-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(4px);
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding-top: 20vh;
  z-index: 100;
}

.command-palette-overlay.open {
  display: flex;
}

.command-palette {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--border-radius-lg);
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
  width: 100%;
  max-width: 560px;
  overflow: hidden;
}

.command-palette input {
  width: 100%;
  padding: 0.875rem 1.25rem;
  font-size: 1rem;
  font-family: var(--font-body);
  border: none;
  border-bottom: 1px solid var(--border-light);
  outline: none;
  background: transparent;
  color: var(--text-primary);
}

.command-palette input::placeholder {
  color: var(--text-muted);
}

.command-palette-results {
  max-height: 320px;
  overflow-y: auto;
  padding: 0.5rem;
}

.command-palette-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.625rem 0.75rem;
  font-size: 0.875rem;
  color: var(--text-primary);
  border-radius: var(--border-radius-sm);
  cursor: pointer;
  transition: background var(--transition-speed) ease;
}

.command-palette-item:hover,
.command-palette-item.active,
.command-palette-item.selected {
  background: var(--color-primary-light);
}

/* ==========================================================================
   12. Notification Bell
   ========================================================================== */
.notification-bell {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border-radius: var(--border-radius-md);
  cursor: pointer;
  color: var(--text-secondary);
  transition: background var(--transition-speed) ease, color var(--transition-speed) ease;
}

.notification-bell:hover {
  background: var(--background);
  color: var(--text-primary);
}

.notification-badge {
  position: absolute;
  top: 0;
  right: 0;
  min-width: 16px;
  height: 16px;
  font-size: 0.625rem;
  font-weight: 700;
  line-height: 16px;
  text-align: center;
  color: #FFFFFF;
  background: var(--color-error);
  border-radius: var(--border-radius-pill);
  padding: 0 4px;
  transform: translate(25%, -25%);
}

.notification-dropdown {
  position: absolute;
  top: calc(100% + 0.5rem);
  right: 0;
  width: 320px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--border-radius-lg);
  box-shadow: var(--shadow-md);
  z-index: 50;
  overflow: hidden;
  display: none;
}

.notification-dropdown.open {
  display: block;
}

/* ================================================================
   Article Content Preview Typography
   Scoped to #article-html so styles don't leak outside the preview
   ================================================================ */
#article-html h1 {
  font-family: var(--font-heading);
  font-size: 2rem;
  font-weight: 700;
  line-height: 1.2;
  margin: 1.5rem 0 0.75rem 0;
  color: var(--text-primary);
}
#article-html h2 {
  font-family: var(--font-heading);
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1.25;
  margin: 1.25rem 0 0.5rem 0;
  color: var(--text-primary);
}
#article-html h3 {
  font-family: var(--font-heading);
  font-size: 1.25rem;
  font-weight: 600;
  line-height: 1.3;
  margin: 1rem 0 0.5rem 0;
  color: var(--text-primary);
}
#article-html h4 {
  font-family: var(--font-heading);
  font-size: 1.1rem;
  font-weight: 600;
  line-height: 1.35;
  margin: 1rem 0 0.25rem 0;
  color: var(--text-primary);
}
#article-html h5,
#article-html h6 {
  font-family: var(--font-heading);
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.4;
  margin: 0.75rem 0 0.25rem 0;
  color: var(--text-secondary);
}
#article-html p {
  font-size: 1rem;
  line-height: 1.7;
  margin: 0 0 0.75rem 0;
}
#article-html ul,
#article-html ol {
  padding-left: 1.5rem;
  margin: 0 0 0.75rem 0;
}
#article-html ul { list-style-type: disc; }
#article-html ol { list-style-type: decimal; }
#article-html li {
  font-size: 1rem;
  line-height: 1.7;
  margin-bottom: 0.25rem;
}
#article-html strong,
#article-html b {
  font-weight: 600;
}
#article-html em,
#article-html i {
  font-style: italic;
}
#article-html a {
  color: var(--color-brand);
  text-decoration: underline;
}
#article-html blockquote {
  border-left: 3px solid var(--color-brand);
  padding-left: 1rem;
  margin: 1rem 0;
  font-style: italic;
  color: var(--text-secondary);
}
#article-html hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 1.5rem 0;
}
#article-html img {
  max-width: 100%;
  height: auto;
  border-radius: 0.5rem;
  margin: 1rem 0;
}
#article-html table {
  width: 100%;
  border-collapse: collapse;
  margin: 1rem 0;
}
#article-html th,
#article-html td {
  border: 1px solid var(--border);
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  text-align: left;
}
#article-html th {
  background: #F8FAFC;
  font-weight: 600;
}

/* ================================================================
   Section Map Overlay
   Toggle-able color-coded section boundaries with labels
   ================================================================ */
.section-block {
  position: relative;
  border-radius: 0.5rem;
  padding: 1rem;
  margin-bottom: 0.75rem;
  border: 1.5px solid var(--sec-border, transparent);
  background: var(--sec-bg, transparent);
  transition: border-color 0.25s ease, background 0.25s ease;
}
.section-block .section-label {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  font-family: var(--font-heading);
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.2rem 0.5rem;
  border-radius: 0.25rem;
  white-space: nowrap;
  background: var(--sec-label-bg, #64748B);
  color: var(--sec-label-fg, #fff);
}

/* Section color classes */
.section-hero        { --sec-bg: #EEF2FF; --sec-border: #C7D2FE; --sec-label-bg: #6366F1; }
.section-services    { --sec-bg: #F0FDF4; --sec-border: #BBF7D0; --sec-label-bg: #16A34A; }
.section-process     { --sec-bg: #FFF7ED; --sec-border: #FED7AA; --sec-label-bg: #EA580C; }
.section-benefits    { --sec-bg: #ECFEFF; --sec-border: #A5F3FC; --sec-label-bg: #0891B2; }
.section-whychoose   { --sec-bg: #FDF4FF; --sec-border: #F0ABFC; --sec-label-bg: #A855F7; }
.section-pricing     { --sec-bg: #F0F9FF; --sec-border: #BAE6FD; --sec-label-bg: #0284C7; }
.section-faq         { --sec-bg: #FEF2F2; --sec-border: #FECACA; --sec-label-bg: #DC2626; }
.section-cta         { --sec-bg: #FFFBEB; --sec-border: #FDE68A; --sec-label-bg: #D97706; }
.section-unmatched   { --sec-bg: #F8FAFC; --sec-border: #E2E8F0; --sec-label-bg: #64748B; }

/* Legend bar */
.section-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1rem;
  padding: 0.75rem;
  background: #F8FAFC;
  border-radius: 0.5rem;
  border: 1px solid var(--border);
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--text-secondary);
}
.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  flex-shrink: 0;
}
