@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;500;600&family=Inter:wght@400;500;600;700&family=Manrope:wght@500;600;700;800&display=swap');

/* ==========================================================================
   ALIGNINTEL ENTERPRISE DESIGN SYSTEM
   ========================================================================== */

:root {
  /* Typography */
  --font-display: 'Manrope', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'IBM Plex Mono', 'JetBrains Mono', monospace;

  /* Primary Orange / Coral Theme */
  --accent: #e8623a;
  --coral: #FF5A3C;
  --accent-hover: #d3532d;
  --accent-strong: #c44a28;
  --accent-wash: #FFF2EE;
  --accent-wash-border: #FCD8CE;
  --accent-gradient: linear-gradient(135deg, #FF5A3C 0%, #e8623a 100%);
  --accent-glow: 0 4px 14px rgba(232, 98, 58, 0.25);

  /* Neutrals (Enterprise Grays) */
  --bg: #F4F5F9;
  --surface: #FFFFFF;
  --surface-sunken: #F0F2F7;
  --surface-hover: #F8F9FD;
  --border: #E1E4EE;
  --border-strong: #CBD0E0;
  --border-subtle: #ECEEF6;

  /* Text & Inks */
  --ink-900: #0F172A;
  --ink-800: #1E293B;
  --ink-700: #334155;
  --ink-600: #475569;
  --ink-500: #64748B;
  --ink-400: #94A3B8;
  --ink-300: #CBD5E1;

  /* Legacy aliases for JS compatibility */
  --text-color: var(--ink-900);
  --muted-color: var(--ink-500);
  --border-color: var(--border);
  --primary-color: var(--accent);
  --ink-muted: var(--ink-500);

  /* Semantic Colors & Washes */
  --success: #10B981;
  --success-wash: #ECFDF5;
  --success-text: #065F46;
  --success-border: #A7F3D0;

  --warning: #F59E0B;
  --warning-wash: #FFFBEB;
  --warning-text: #92400E;
  --warning-border: #FDE68A;

  --error: #EF4444;
  --error-wash: #FEF2F2;
  --error-text: #991B1B;
  --error-border: #FECACA;

  --info: #3B82F6;
  --info-wash: #EFF6FF;
  --info-text: #1E40AF;
  --info-border: #BFDBFE;

  /* Elevation & Shadows */
  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 4px 8px -1px rgba(15, 23, 42, 0.06), 0 2px 4px -2px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 12px 20px -3px rgba(15, 23, 42, 0.08);
  --shadow-dialog: 0 20px 25px -5px rgba(15, 23, 42, 0.15), 0 8px 10px -6px rgba(15, 23, 42, 0.08);

  /* Radii */
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --radius-full: 9999px;

  /* Layout */
  --sidebar-width: 232px;
  --topbar-height: 56px;
}

[data-theme="dark"], body.dark-theme {
  --bg: #0B0E14;
  --surface: #141822;
  --surface-sunken: #0E1118;
  --surface-hover: #1C2230;
  --border: #232838;
  --border-strong: #333B50;
  --border-subtle: #191E2B;

  --ink-900: #F8FAFC;
  --ink-800: #F1F5F9;
  --ink-700: #E2E8F0;
  --ink-600: #CBD5E1;
  --ink-500: #94A3B8;
  --ink-400: #64748B;
  --ink-300: #475569;

  --accent-wash: rgba(232, 98, 58, 0.12);
  --accent-wash-border: rgba(232, 98, 58, 0.28);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 8px -1px rgba(0, 0, 0, 0.4);
}

/* ==========================================================================
   BASE & RESET
   ========================================================================== */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  font-family: var(--font-body);
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--ink-800);
  background-color: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-display);
  font-weight: 700;
  color: var(--ink-900);
  letter-spacing: -0.02em;
}

h1 { font-size: 1.55rem; line-height: 1.25; }
h2 { font-size: 1.2rem; line-height: 1.3; }
h3 { font-size: 1.02rem; line-height: 1.35; font-weight: 600; }

p { color: var(--ink-600); }
a { color: var(--accent); text-decoration: none; transition: color 0.15s ease; }
a:hover { color: var(--accent-hover); }

.mono { font-family: var(--font-mono); }
.muted { color: var(--ink-500); font-size: 0.82rem; }

/* ==========================================================================
   APP SHELL & ULTRA-COMPACT SIDEBAR (IMAGE 1)
   ========================================================================== */

.app-shell {
  display: flex;
  min-height: 100vh;
  width: 100%;
  background: var(--bg);
}

/* LEFT SIDEBAR */
.app-sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  height: 100vh;
  position: sticky;
  top: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 12px 10px;
  z-index: 40;
  overflow-y: auto;
}

.sidebar-top {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* BRAND LOGO */
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  padding: 2px;
}

.brand-mark {
  width: 26px;
  height: 26px;
  flex-shrink: 0;
}

.mark-ring-outer { fill: none; stroke: var(--accent); stroke-width: 2.2; }
.mark-ring-inner { fill: none; stroke: var(--ink-900); stroke-width: 1.8; }
.mark-dot { fill: var(--coral); }
.mark-tick { stroke: var(--accent); stroke-width: 1.8; stroke-linecap: round; }

.brand-text {
  display: flex;
  flex-direction: column;
}

.brand-name {
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--ink-900);
  letter-spacing: -0.02em;
}

.brand-tag {
  font-size: 0.68rem;
  font-weight: 500;
  color: var(--ink-500);
}

/* SIDEBAR PRIMARY CTA */
.sidebar-cta {
  width: 100%;
}

.sidebar-cta .primary-button,
#goToAlignment {
  width: 100%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: var(--accent-gradient);
  color: #FFFFFF;
  border: none;
  height: 36px;
  border-radius: var(--radius-md);
  font-family: var(--font-body);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--accent-glow);
  transition: transform 0.15s ease, box-shadow 0.15s ease, filter 0.15s ease;
}

.sidebar-cta .primary-button:hover,
#goToAlignment:hover {
  filter: brightness(1.05);
}

/* SIDEBAR NAVIGATION */
.app-navigation {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-link,
.app-navigation a {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: var(--radius-md);
  color: var(--ink-600);
  font-size: 12.5px;
  font-weight: 500;
  text-decoration: none;
  transition: all 0.15s ease;
  cursor: pointer;
}

.nav-link svg,
.app-navigation a svg {
  width: 15px;
  height: 15px;
  stroke-width: 2;
  flex-shrink: 0;
  color: var(--ink-500);
}

.nav-link:hover,
.app-navigation a:hover {
  background: var(--surface-sunken);
  color: var(--ink-900);
}

.nav-link.is-active,
.app-navigation a.is-active {
  background: var(--accent-wash);
  color: var(--accent-strong);
  font-weight: 600;
}

.nav-link.is-active svg,
.app-navigation a.is-active svg {
  color: var(--accent);
}

/* SIDEBAR BOTTOM / COMPACT USER PILL */
.sidebar-bottom {
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.auth-user-card-compact {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  width: 100%;
}

.user-pill-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: var(--radius-md);
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  cursor: pointer;
  flex: 1;
  min-width: 0;
  text-align: left;
  transition: all 0.15s ease;
}

.user-pill-btn:hover {
  background: var(--surface-hover);
  border-color: var(--border-strong);
}

.user-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--accent-gradient);
  color: #FFFFFF;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 11px;
  flex-shrink: 0;
}

.auth-user-meta {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex: 1;
  min-width: 0;
}

.auth-user-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-900);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.2;
}

.user-credits-text {
  font-size: 10.5px;
  font-weight: 600;
  color: var(--accent);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.2;
}

.user-pill-arrow {
  color: var(--ink-400);
  flex-shrink: 0;
  transition: transform 0.15s ease;
}

.user-pill-btn:hover .user-pill-arrow {
  color: var(--ink-800);
  transform: translateX(2px);
}

.sidebar-quick-logout {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface-sunken);
  color: var(--ink-500);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: all 0.15s ease;
}

.sidebar-quick-logout:hover {
  background: var(--error-wash);
  color: var(--error);
  border-color: var(--error-border);
}

/* PROFILE DIALOG ENHANCED */
.profile-details {
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
}

.profile-card-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.profile-card-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--accent-gradient);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  font-weight: 700;
  flex-shrink: 0;
}

.profile-card-userinfo h4 {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--ink-900);
  margin: 0 0 2px;
}

.profile-card-userinfo p {
  font-size: 12px;
  color: var(--ink-500);
  margin: 0;
}

.profile-meta-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.profile-meta-chips .pill {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: var(--radius-full);
}

.profile-credits-row {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.profile-credits-count {
  font-size: 13px;
  font-weight: 700;
  color: var(--ink-900);
  display: flex;
  align-items: center;
  gap: 6px;
}

.profile-actions-stack {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 14px 0;
}

/* MAIN CONTENT AREA */
.app-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

/* 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 24px;
  position: sticky;
  top: 0;
  z-index: 30;
}

.topbar-left {
  display: flex;
  flex-direction: column;
}

.topbar-page-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--ink-900);
}

.topbar-subtitle {
  font-size: 0.75rem;
  color: var(--ink-500);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.credits-pill,
#authUserCredits,
.workflow-credit-note {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px;
  border-radius: var(--radius-full);
  background: var(--accent-wash);
  border: 1px solid var(--accent-wash-border);
  color: var(--accent-strong);
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink-600);
  cursor: pointer;
  transition: all 0.15s ease;
}

.theme-toggle:hover {
  background: var(--surface-sunken);
  color: var(--ink-900);
}

.theme-label { display: none; }

/* SCROLLABLE WORKSPACE CONTENT */
.app-content {
  flex: 1;
  padding: 20px 24px 40px;
}

.content-inner {
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
}

/* Ensure hidden attribute is ALWAYS respected across all components */
[hidden],
#accessManagement[hidden],
#studioSection[hidden],
#reportSection[hidden],
#authGuestView[hidden] {
  display: none !important;
}

/* PAGE CONDITIONAL VISIBILITY */
.app-shell[data-page="management"] #accessManagement:not([hidden]) { display: block; }
.app-shell[data-page="management"] #studioSection,
.app-shell[data-page="management"] #reportSection { display: none !important; }

.app-shell[data-page="alignment"] #accessManagement,
.app-shell[data-page="alignment"] #reportSection { display: none !important; }
.app-shell[data-page="alignment"] #studioSection:not([hidden]) { display: block; }

.app-shell[data-page="results"] #accessManagement,
.app-shell[data-page="results"] #studioSection { display: none !important; }
/* Results must never be blank just because a stale `hidden` attribute remains
   after navigation or a refresh. The page state is the source of truth. */
.app-shell[data-page="results"] #reportSection { display: block !important; }

/* GUEST / AUTH-REQUIRED CLEAN VIEW */
body.auth-required .app-sidebar,
body.auth-required .app-topbar,
body.auth-required #accessManagement,
body.auth-required #studioSection,
body.auth-required #reportSection,
body.auth-required #alignmentForm,
body.auth-required .results-panel,
body.auth-required .studio-layout-wrap {
  display: none !important;
}

body.auth-required .app-shell {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
}

body.auth-required .app-main {
  max-width: 420px;
  width: 100%;
  background: transparent;
}

body.auth-required .app-content { padding: 0; }
body.auth-required #authGuestView { display: block !important; width: 100%; box-shadow: var(--shadow-lg); }

/* ==========================================================================
   FULL-WIDTH STUDIO & RESULTS LAYOUT (SEPARATE VIEWS)
   ========================================================================== */

.studio-layout-wrap {
  width: 100%;
}

#studioSection #alignmentForm {
  display: block;
  max-width: 900px;
  margin: 0 auto;
}

#reportSection .results-panel {
  display: block !important;
  width: 100%;
}

#reportSection #results {
  display: block !important;
  width: 100%;
}

body.rerun-open #alignmentForm {
  display: block !important;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 1000;
  max-width: 680px;
  width: 90%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-dialog);
}

body.rerun-open .rerun-backdrop {
  display: block !important;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(4px);
  z-index: 999;
}

body.rerun-open .rerun-close {
  display: inline-flex !important;
  position: absolute;
  top: 14px;
  right: 14px;
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 3px 8px;
  font-size: 11.5px;
  cursor: pointer;
  color: var(--ink-700);
}

/* ==========================================================================
   COMPONENTS: CARDS, HEADINGS, SUMMARY HIGHLIGHTS (SAMPLE REPORT STYLE)
   ========================================================================== */

.card,
.section-block {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 22px;
  margin-bottom: 20px;
  transition: border-color 0.15s ease;
}

.section-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 16px;
  gap: 14px;
}

.section-heading h2,
.section-heading h3 {
  color: var(--ink-900);
}

.section-heading p {
  font-size: 0.82rem;
  color: var(--ink-500);
  margin-top: 2px;
}

.eyebrow {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent);
  margin-bottom: 3px;
}

/* HIGHLIGHTS / SNAPSHOT GRID */
.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 20px;
}

.summary-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.04);
  transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}

.summary-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 18px rgba(15, 23, 42, 0.08);
}

.summary-card.primary {
  border-top: 3px solid var(--accent);
  background: linear-gradient(180deg, rgba(232, 98, 58, 0.03) 0%, var(--surface) 100%);
}

.summary-card.success {
  border-top: 3px solid #10b981;
  background: linear-gradient(180deg, rgba(16, 185, 129, 0.03) 0%, var(--surface) 100%);
}

.summary-card.neutral {
  border-top: 3px solid #3b82f6;
  background: linear-gradient(180deg, rgba(59, 130, 246, 0.03) 0%, var(--surface) 100%);
}

.summary-card.warning {
  border-top: 3px solid #f59e0b;
  background: linear-gradient(180deg, rgba(245, 158, 11, 0.03) 0%, var(--surface) 100%);
}

.summary-card-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  flex-shrink: 0;
}

.summary-card-body {
  display: flex;
  flex-direction: column;
}

.summary-card-title,
.summary-card h4 {
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-500);
  margin-bottom: 2px;
}

.summary-card strong,
.summary-card p {
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--ink-900);
  line-height: 1.2;
}

/* ==========================================================================
   REWRITE OUTPUT: SAMPLE-REPORT STYLE COMPARISON
   ========================================================================== */

#rewriteBlock {
  background: transparent;
  border: none;
  padding: 0;
  box-shadow: none;
}

.signal-group {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px 24px;
  margin-bottom: 18px;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.04);
}

.signal-group h4 {
  font-family: var(--font-display);
  font-size: 13.5px;
  font-weight: 700;
  color: var(--ink-900);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.signal-group h4 + p.muted {
  font-size: 13.5px;
  line-height: 1.65;
  color: var(--ink-800);
  background: var(--surface-sunken);
  border-left: 4px solid var(--accent);
  padding: 14px 18px;
  border-radius: var(--radius-md);
  margin: 0;
}

.signal-group:has(.pill-error),
.signal-group:has(.pill-warning) {
  background: var(--warning-wash);
  border-color: var(--warning-border);
}

.signal-group:has(.pill-error) h4,
.signal-group:has(.pill-warning) h4 {
  color: var(--warning-text);
}

.budget-message,
#rewriteContent > p.muted {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-600);
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  padding: 6px 14px;
  border-radius: var(--radius-full);
  display: inline-block;
  margin-bottom: 16px;
}

/* REWRITE LIST & COMPARATIVE CARDS */
.rewrite-list {
  display: flex;
  flex-direction: column;
  gap: 20px;
  margin-top: 12px;
}

.rewrite-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  overflow: hidden;
  box-shadow: 0 4px 16px rgba(15, 23, 42, 0.04);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.rewrite-item:hover {
  border-color: rgba(232, 98, 58, 0.35);
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
}

.rewrite-item-header {
  padding: 12px 20px;
  background: var(--surface-sunken);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.rewrite-compare-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
}

.compare-pane {
  padding: 18px 22px;
}

.compare-pane.original {
  background: rgba(248, 250, 252, 0.5);
}

.compare-pane.tailored {
  background: linear-gradient(180deg, rgba(232, 98, 58, 0.02) 0%, var(--surface) 100%);
  border-left: 1px solid var(--border);
}

.pane-label {
  margin-bottom: 8px;
}

.pane-badge {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  display: inline-block;
}

.pane-badge.original-badge {
  background: #e2e8f0;
  color: #475569;
}

.pane-badge.tailored-badge {
  background: rgba(232, 98, 58, 0.12);
  color: var(--accent);
}

.bullet-text {
  font-size: 13.5px;
  line-height: 1.6;
  margin: 0;
}

.bullet-text.original-text {
  color: var(--ink-600);
}

.bullet-text.tailored-text {
  color: var(--ink-900);
  font-weight: 500;
}

/* DIFF HIGHLIGHT COLORS */
.diff-del,
del.diff-del {
  background: rgba(239, 68, 68, 0.12);
  color: #991b1b;
  text-decoration: line-through;
  padding: 1px 4px;
  border-radius: 2px;
}

.diff-add,
ins.diff-add {
  background: rgba(16, 185, 129, 0.15);
  color: #065f46;
  text-decoration: none;
  padding: 1px 4px;
  border-radius: 2px;
  font-weight: 600;
  border-bottom: 2px solid #10b981;
}

.rewrite-card-footer {
  padding: 12px 20px;
  background: var(--surface-sunken);
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 12px;
}

.footer-meta-item {
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.meta-label {
  font-weight: 700;
  color: var(--ink-600);
  flex-shrink: 0;
}

.meta-val {
  color: var(--ink-700);
}

.code-val {
  font-family: var(--font-mono);
  font-size: 11.5px;
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 1px 6px;
  border-radius: var(--radius-sm);
  color: var(--ink-800);
}

/* KEYWORDS ADDED CHIPS */
.pill-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 5px;
}

.pill-row .pill {
  background: rgba(232, 98, 58, 0.09);
  color: var(--accent);
  border: 1px solid rgba(232, 98, 58, 0.22);
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: var(--radius-full);
}

.validation-status-pill {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.validation-status-pill.success {
  background: #ecfdf5;
  color: #059669;
  border: 1px solid rgba(5, 150, 105, 0.25);
}

/* INSIGHT BANNER ENHANCED */
.insight-banner {
  background: linear-gradient(135deg, var(--surface) 0%, rgba(232, 98, 58, 0.04) 100%);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius-lg);
  padding: 20px 24px;
  margin-bottom: 22px;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.04);
}

.insight-main {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  flex-wrap: wrap;
}

.insight-badges {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.insight-badges .pill {
  font-size: 12px;
  font-weight: 600;
  padding: 4px 12px;
  border-radius: var(--radius-full);
  background: var(--surface-sunken);
  color: var(--ink-700);
  border: 1px solid var(--border);
}

/* ==========================================================================
   SLIDE-OVER HISTORY DRAWER
   ========================================================================== */

.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(4px);
  z-index: 998;
}

.history-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 440px;
  max-width: 90vw;
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: -8px 0 32px rgba(15, 23, 42, 0.15);
  z-index: 999;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  overflow: hidden;
}

.history-drawer.is-open {
  transform: translateX(0);
}

.drawer-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--surface-sunken);
}

.drawer-header h3 {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--ink-900);
  margin: 0;
}

.history-drawer .recent-runs-list {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.history-drawer .recent-run-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  transition: all 0.15s ease;
}

.history-drawer .recent-run-item:hover {
  background: var(--surface-hover);
  border-color: var(--accent-wash-border);
  transform: translateY(-1px);
}

.recent-run-open {
  background: transparent;
  border: none;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
  text-align: left;
  flex: 1;
}

.recent-run-open strong {
  font-size: 13px;
  font-weight: 700;
  color: var(--ink-900);
}

.recent-run-open span {
  font-size: 11px;
  color: var(--ink-500);
}

.recent-run-remove {
  background: transparent;
  border: none;
  color: var(--ink-400);
  font-size: 16px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  transition: all 0.15s ease;
}

.recent-run-remove:hover {
  color: var(--error);
  background: var(--error-wash);
}

/* ==========================================================================
   MANAGEMENT TABLES
   ========================================================================== */

.management-table-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  margin-top: 10px;
  box-shadow: var(--shadow-sm);
}

.management-table,
table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 12.5px;
}

.management-table th,
table th {
  background: var(--surface-sunken);
  color: var(--ink-600);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-strong);
  white-space: nowrap;
}

.management-table td,
table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border-subtle);
  color: var(--ink-800);
  vertical-align: middle;
  white-space: nowrap;
}

.management-table tr:last-child td,
table tr:last-child td { border-bottom: none; }
.management-table tr:hover td,
table tr:hover td { background: var(--surface-hover); }
.management-table td strong { color: var(--ink-900); font-weight: 600; }

.management-toolbar {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-bottom: 12px;
}

/* ==========================================================================
   BUTTONS & INPUTS
   ========================================================================== */

.primary-button,
.secondary-button,
.btn,
.text-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 36px;
  padding: 0 14px;
  border-radius: var(--radius-md);
  font-family: var(--font-body);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.primary-button { background: var(--accent); color: #FFFFFF; border: 1px solid transparent; }
.primary-button:hover { background: var(--accent-hover); color: #FFFFFF; }
.primary-button:active { background: var(--accent-strong); transform: scale(0.98); }

.secondary-button { background: var(--surface); color: var(--ink-800); border: 1px solid var(--border-strong); }
.secondary-button:hover { background: var(--surface-sunken); color: var(--ink-900); }

.text-button { background: transparent; border: none; height: auto; padding: 3px 6px; color: var(--accent); font-size: 12px; font-weight: 600; cursor: pointer; }
.text-button:hover { text-decoration: underline; }
.text-button.danger { color: var(--error); }
.danger-button { background: var(--error) !important; color: #FFFFFF !important; }

.button-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 12px;
  width: 100%;
  text-align: left;
}

.field span { font-size: 12px; font-weight: 600; color: var(--ink-800); }
.field input[type="text"],
.field input[type="email"],
.field input[type="password"],
.field input[type="number"],
.field select,
.chip-input {
  height: 36px;
  padding: 0 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--ink-900);
  font-family: var(--font-body);
  font-size: 12.5px;
  outline: none;
  width: 100%;
}

.field textarea {
  padding: 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--ink-900);
  font-family: var(--font-body);
  font-size: 12.5px;
  line-height: 1.5;
  outline: none;
  width: 100%;
  resize: vertical;
}

.field input:focus,
.field textarea:focus,
.field select:focus,
.chip-input:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-wash);
}

.field input::placeholder, .field textarea::placeholder { color: var(--ink-400); }
.hint-text { font-size: 10.5px; color: var(--ink-500); margin-top: 2px; }

.toggle-field {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  margin-bottom: 8px;
  font-size: 12px;
  font-weight: 500;
  color: var(--ink-700);
}

.toggle-field input[type="checkbox"] { accent-color: var(--accent); width: 14px; height: 14px; }
.job-details-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.upload-shell {
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius-md);
  padding: 14px;
  text-align: center;
  background: var(--surface-sunken);
  cursor: pointer;
}
.upload-shell input[type="file"] { width: 100%; cursor: pointer; }
.upload-feedback { font-size: 11px; color: var(--ink-500); margin-top: 3px; }

/* CHIP INPUT */
.chip-input { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; height: auto; min-height: 36px; padding: 3px 6px; }
.chip-list { display: flex; flex-wrap: wrap; gap: 4px; }
.chip { display: inline-flex; align-items: center; gap: 4px; background: var(--accent-wash); color: var(--accent-strong); border: 1px solid var(--accent-wash-border); padding: 2px 6px; border-radius: var(--radius-full); font-size: 11px; }
.chip-remove { cursor: pointer; border: none; background: none; color: var(--accent); font-size: 12px; }
.chip-input input { border: none; outline: none; background: transparent; flex: 1; min-width: 90px; height: 24px; font-size: 12px; }

.options-disclosure { border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface); margin-bottom: 14px; }
.options-disclosure summary { padding: 8px 12px; font-weight: 600; font-size: 12.5px; color: var(--ink-800); cursor: pointer; background: var(--surface-sunken); }
.options-body { padding: 12px; border-top: 1px solid var(--border); }
.mode-group { border: none; margin-bottom: 10px; display: flex; gap: 12px; align-items: center; }
.mode-group legend { font-size: 12px; font-weight: 600; margin-bottom: 4px; }
.mode-group label { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; }

/* PILLS & BADGES */
.pill, .badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  border-radius: var(--radius-full);
  font-size: 10.5px;
  font-weight: 600;
  padding: 2px 7px;
  text-transform: capitalize;
}
.pill-neutral, .auth-badge { background: var(--surface-sunken); color: var(--ink-700); border: 1px solid var(--border); }
.auth-badge.is-authenticated { background: var(--accent-wash); color: var(--accent-strong); border-color: var(--accent-wash-border); }
.pill-error { background: var(--error-wash); color: var(--error-text); border: 1px solid var(--error-border); }
.pill-warning { background: var(--warning-wash); color: var(--warning-text); border: 1px solid var(--warning-border); }
.pill-success { background: var(--success-wash); color: var(--success-text); border: 1px solid var(--success-border); }

/* TABS */
.tab-bar, .tab-buttons { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 14px; }
.tab-button, .auth-tab { background: transparent; border: none; border-bottom: 2px solid transparent; padding: 6px 12px; font-family: var(--font-body); font-size: 12.5px; font-weight: 500; color: var(--ink-500); cursor: pointer; margin-bottom: -1px; }
.tab-button.is-active, .auth-tab.is-active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.auth-tabs { display: flex; border-bottom: 1px solid var(--border); margin-bottom: 14px; }
.tab-panel, .mgmt-panel { display: none; }
.tab-panel.is-active, .mgmt-panel:not([hidden]) { display: block; }

/* RECENT RUNS & HISTORY */
.recent-runs-panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 16px 20px; margin-bottom: 20px; box-shadow: var(--shadow-sm); }
.recent-runs-list { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.recent-run-item { display: flex; align-items: center; justify-content: space-between; padding: 10px 14px; background: var(--surface-sunken); border: 1px solid var(--border); border-radius: var(--radius-md); }
.recent-run-item:hover { background: var(--surface-hover); border-color: var(--border-strong); }
.recent-run-open { background: transparent; border: none; cursor: pointer; display: flex; flex-direction: column; align-items: flex-start; gap: 2px; text-align: left; flex: 1; }
.recent-run-open strong { font-size: 13px; color: var(--ink-900); }
.recent-run-open span { font-size: 11px; color: var(--ink-500); }
.recent-run-remove { background: transparent; border: none; color: var(--ink-400); font-size: 16px; cursor: pointer; padding: 2px 6px; border-radius: 4px; }
.recent-run-remove:hover { color: var(--error); background: var(--error-wash); }

/* EMPTY STATE */
.empty-state { text-align: center; padding: 40px 20px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); }
.empty-illustration { width: 130px; height: auto; margin: 0 auto 14px; }
.empty-line { stroke: var(--border-strong); stroke-dasharray: 4; }
.empty-doc { fill: var(--surface-sunken); stroke: var(--border-strong); stroke-width: 1.5; }
.empty-doc-line { stroke: var(--ink-300); stroke-width: 2; stroke-linecap: round; }
.empty-target-outer { fill: none; stroke: var(--accent-wash-border); stroke-width: 2; }
.empty-target-inner { fill: none; stroke: var(--accent); stroke-width: 2; }
.empty-target-dot { fill: var(--coral); }
.feature-list { display: flex; justify-content: center; flex-wrap: wrap; gap: 6px; margin-top: 14px; }
.feature-pill { padding: 2px 8px; background: var(--surface-sunken); border: 1px solid var(--border); border-radius: var(--radius-full); font-size: 11px; color: var(--ink-700); }

/* LOADING STATE */
.loading-state {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 36px 28px 32px;
  max-width: 620px;
  margin: 0 auto 28px;
  box-shadow: var(--shadow-sm);
  text-align: center;
}
.stepper-wrap {
  position: relative;
  max-width: 480px;
  margin: 0 auto 26px;
  padding: 0 8px;
}
.stepper-track-bg {
  position: absolute;
  top: 14px;
  left: 12.5%;
  right: 12.5%;
  height: 3px;
  background: var(--border-strong);
  z-index: 1;
  border-radius: 2px;
}
.stepper-track-fill {
  position: absolute;
  top: 14px;
  left: 12.5%;
  width: 0%;
  max-width: 75%;
  height: 3px;
  background: var(--accent);
  z-index: 2;
  border-radius: 2px;
  transition: width 0.45s cubic-bezier(0.4, 0, 0.2, 1);
}
.step-tracker {
  position: relative;
  z-index: 3;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  list-style: none;
  padding: 0;
  margin: 0;
}
.step {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  flex: 1;
  text-align: center;
}
.step-dot {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--surface);
  border: 2px solid var(--border-strong);
  display: flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  z-index: 4;
}
.step-active-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #ffffff;
  display: none;
}
.step-tick-svg {
  width: 15px;
  height: 15px;
  stroke: #ffffff;
  display: none;
}
/* ACTIVE STEP */
.step.is-active .step-dot {
  background: var(--accent) !important;
  border-color: var(--accent) !important;
  box-shadow: 0 0 0 4px var(--accent-wash);
  animation: step-pulse 1.8s ease-in-out infinite;
}
.step.is-active .step-active-dot {
  display: block;
}
.step.is-active .step-tick-svg {
  display: none !important;
}
/* COMPLETED STEP */
.step.is-done .step-dot,
.step.is-complete .step-dot {
  background: #10b981 !important;
  border-color: #10b981 !important;
  box-shadow: none !important;
  animation: none !important;
}
.step.is-done .step-active-dot,
.step.is-complete .step-active-dot {
  display: none !important;
}
.step.is-done .step-tick-svg,
.step.is-complete .step-tick-svg {
  display: block !important;
}
@keyframes step-pulse {
  0%, 100% { box-shadow: 0 0 0 4px var(--accent-wash); }
  50% { box-shadow: 0 0 0 8px var(--accent-wash); }
}
.step-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-400);
  transition: color 0.3s ease;
}
.step.is-active .step-label {
  color: var(--ink-900);
  font-weight: 700;
}
.step.is-done .step-label,
.step.is-complete .step-label {
  color: var(--ink-800);
}
.loading-status-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: 8px;
}
.loading-text {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ink-700);
  margin: 0;
}
.spinner {
  width: 22px;
  height: 22px;
  border: 2.5px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
  margin: 0;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* RESULTS HEADER */
.results-header { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 18px 20px; margin-bottom: 18px; }
.results-header-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.results-header-actions { display: flex; gap: 6px; }

/* AUTH MESSAGES */
.auth-message { padding: 8px 12px; border-radius: var(--radius-md); font-size: 12px; font-weight: 500; margin-bottom: 12px; }
.auth-message.info, .auth-message:not(.error):not(.success) { background: var(--info-wash); color: var(--info-text); border: 1px solid var(--info-border); }
.auth-message.error { background: var(--error-wash); color: var(--error-text); border: 1px solid var(--error-border); }
.auth-message.success { background: var(--success-wash); color: var(--success-text); border: 1px solid var(--success-border); }

/* MODAL DIALOGS */
dialog.app-dialog, dialog.welcome-tour-dialog { border: 1px solid var(--border-strong); border-radius: var(--radius-xl); background: var(--surface); box-shadow: var(--shadow-dialog); padding: 22px; max-width: 440px; width: 90%; margin: auto; color: var(--ink-900); }
dialog::backdrop { background: rgba(15, 23, 42, 0.5); backdrop-filter: blur(4px); }
.dialog-heading { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.dialog-heading h3 { font-size: 1.05rem; font-weight: 700; color: var(--ink-900); }
.dialog-close { background: transparent; border: none; font-size: 16px; color: var(--ink-400); cursor: pointer; }

/* RESPONSIVE (< 900px) */
@media (max-width: 900px) {
  .app-shell { flex-direction: column; }
  .app-sidebar { width: 100%; min-width: 100%; height: auto; position: relative; border-right: none; border-bottom: 1px solid var(--border); padding: 8px 12px; }
  .sidebar-top { flex-direction: row; align-items: center; justify-content: space-between; gap: 6px; }
  .sidebar-cta { width: auto; }
  .app-navigation { flex-direction: row; overflow-x: auto; padding: 4px 0; }
  .sidebar-bottom { display: none; }
  .app-topbar { padding: 0 14px; }
  .app-content { padding: 14px; }
  .summary-grid { grid-template-columns: 1fr 1fr; }
}
