/* ============================================================
   ToolPortal.org — Unified Design System (v2.0)
   Extracted from Google Stitch prototypes, 2026-03-29
   No external dependencies — pure CSS, no Tailwind CDN
   ============================================================ */

/* --- Reset & Base --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  /* Brand */
  --tp-primary: #474bff;
  --tp-primary-hover: #3538e0;
  --tp-primary-light: rgba(71, 75, 255, 0.08);
  --tp-primary-text: #2928e8;

  /* Surfaces */
  --tp-bg: #fbf8ff;
  --tp-surface: #ffffff;
  --tp-surface-low: #f4f2ff;
  --tp-surface-container: #ececff;

  /* Text */
  --tp-text: #181b2b;
  --tp-text-secondary: #454556;
  --tp-text-muted: #767588;

  /* Borders & Outlines */
  --tp-border: #c6c4d9;
  --tp-border-light: rgba(198, 196, 217, 0.3);

  /* Feedback */
  --tp-success: #006b5d;
  --tp-success-bg: #84f6e0;
  --tp-error: #ba1a1a;
  --tp-error-bg: #ffdad6;

  /* Shadows */
  --tp-shadow-card: 0 4px 16px rgba(0, 0, 0, 0.04);
  --tp-shadow-card-hover: 0 12px 32px rgba(71, 75, 255, 0.06);
  --tp-shadow-header: 0 1px 3px rgba(0, 0, 0, 0.06);

  /* Dimensions */
  --tp-max-width: 1200px;
  --tp-sidebar-width: 260px;
  --tp-header-height: 64px;
  --tp-radius: 12px;
  --tp-radius-sm: 8px;
  --tp-radius-full: 9999px;

  /* Typography */
  --tp-font-heading: 'Space Grotesk', system-ui, sans-serif;
  --tp-font-body: 'Inter', system-ui, sans-serif;
  --tp-font-mono: 'JetBrains Mono', 'Fira Code', monospace;
}

body {
  font-family: var(--tp-font-body);
  background: var(--tp-bg);
  color: var(--tp-text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 {
  font-family: var(--tp-font-heading);
  line-height: 1.15;
  letter-spacing: -0.01em;
}

a { color: inherit; text-decoration: none; }

/* --- Utility --- */
.tp-shell {
  max-width: var(--tp-max-width);
  margin: 0 auto;
  padding: 0 24px;
}

.tp-sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0,0,0,0); border: 0;
}

/* ============================================================
   HEADER
   ============================================================ */
.tp-header {
  position: sticky;
  top: 0;
  z-index: 50;
  width: 100%;
  height: var(--tp-header-height);
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: var(--tp-shadow-header);
}

.tp-header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: var(--tp-max-width);
  margin: 0 auto;
  padding: 0 24px;
  height: 100%;
}

/* Logo */
.tp-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: var(--tp-text);
  font-family: var(--tp-font-heading);
  font-weight: 700;
  font-size: 20px;
  letter-spacing: -0.02em;
}

.tp-logo-mark {
  width: 32px;
  height: 32px;
  border-radius: var(--tp-radius-sm);
  background: var(--tp-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
}

.tp-logo-mark svg { width: 20px; height: 20px; }

/* Category Nav */
.tp-nav {
  display: flex;
  align-items: center;
  gap: 4px;
}

.tp-nav-pill {
  display: inline-flex;
  align-items: center;
  padding: 6px 16px;
  border-radius: var(--tp-radius-full);
  font-size: 14px;
  font-weight: 500;
  color: var(--tp-text-secondary);
  transition: background 0.2s, color 0.2s;
  white-space: nowrap;
}

.tp-nav-pill:hover {
  background: var(--tp-surface-low);
  color: var(--tp-primary-text);
}

.tp-nav-pill.active {
  background: var(--tp-primary);
  color: #fff;
}

/* Header Search */
.tp-header-search {
  position: relative;
}

.tp-header-search input {
  width: 260px;
  height: 40px;
  padding: 0 16px 0 40px;
  border: none;
  border-radius: var(--tp-radius-full);
  background: var(--tp-surface-low);
  font: inherit;
  font-size: 14px;
  color: var(--tp-text);
  outline: none;
  transition: box-shadow 0.2s;
}

.tp-header-search input:focus {
  box-shadow: 0 0 0 2px rgba(71, 75, 255, 0.2);
}

.tp-header-search svg {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 18px;
  height: 18px;
  color: var(--tp-text-muted);
  pointer-events: none;
}

/* ============================================================
   HERO (Homepage only)
   ============================================================ */
.tp-hero {
  padding: 64px 0 48px;
}

.tp-hero h1 {
  font-size: clamp(36px, 5vw, 60px);
  font-weight: 700;
  color: var(--tp-text);
  margin-bottom: 16px;
}

.tp-hero-sub {
  font-size: 18px;
  color: var(--tp-text-secondary);
  max-width: 540px;
  margin-bottom: 32px;
}

/* Hero search */
.tp-hero-search {
  position: relative;
  margin-bottom: 24px;
}

.tp-hero-search input {
  width: 100%;
  height: 64px;
  padding: 0 24px 0 56px;
  border: none;
  border-radius: 16px;
  background: var(--tp-surface);
  font: inherit;
  font-size: 18px;
  color: var(--tp-text);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.04);
  outline: none;
  transition: box-shadow 0.2s;
}

.tp-hero-search input:focus {
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.04), 0 0 0 2px rgba(71, 75, 255, 0.1);
}

.tp-hero-search svg {
  position: absolute;
  left: 20px;
  top: 50%;
  transform: translateY(-50%);
  width: 24px;
  height: 24px;
  color: var(--tp-primary);
  pointer-events: none;
}

/* Quick filter tags */
.tp-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tp-tag {
  display: inline-flex;
  align-items: center;
  padding: 8px 20px;
  border-radius: var(--tp-radius-full);
  background: var(--tp-surface-low);
  color: var(--tp-text-secondary);
  font-size: 14px;
  font-weight: 500;
  border: none;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

.tp-tag:hover {
  background: var(--tp-primary-light);
  color: var(--tp-primary-text);
}

/* ============================================================
   CATEGORY SECTION (Homepage)
   ============================================================ */
.tp-category {
  margin-bottom: 64px;
}

.tp-category-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}

.tp-category-title {
  display: flex;
  align-items: center;
  gap: 12px;
}

.tp-category-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--tp-radius);
  background: var(--tp-primary-light);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--tp-primary);
}

.tp-category-icon svg { width: 22px; height: 22px; }

.tp-category-title h2 {
  font-size: 24px;
  font-weight: 700;
}

.tp-category-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  background: var(--tp-success-bg);
  color: #00201b;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-left: 12px;
}

.tp-category-see-all {
  font-size: 14px;
  font-weight: 500;
  color: var(--tp-primary-text);
  display: flex;
  align-items: center;
  gap: 4px;
}

.tp-category-see-all:hover { text-decoration: underline; text-underline-offset: 4px; }
.tp-category-see-all svg { width: 16px; height: 16px; }

/* ============================================================
   TOOL CARDS
   ============================================================ */
.tp-card-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
}

.tp-card {
  display: block;
  padding: 24px;
  background: var(--tp-surface);
  border: 1px solid var(--tp-border-light);
  border-radius: var(--tp-radius);
  transition: transform 0.3s, box-shadow 0.3s;
  text-decoration: none;
  color: inherit;
}

.tp-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--tp-shadow-card-hover);
}

.tp-card-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--tp-radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 20px;
}

.tp-card-icon svg { width: 22px; height: 22px; }

.tp-card h3 {
  font-family: var(--tp-font-body);
  font-size: 15px;
  font-weight: 700;
  color: var(--tp-text);
  margin-bottom: 4px;
  transition: color 0.2s;
}

.tp-card:hover h3 { color: var(--tp-primary-text); }

.tp-card p {
  font-size: 14px;
  color: var(--tp-text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ============================================================
   TOOL PAGE LAYOUT (Sidebar + Main)
   ============================================================ */
.tp-page-layout {
  display: flex;
  gap: 32px;
  max-width: var(--tp-max-width);
  margin: 0 auto;
  padding: 32px 24px 80px;
}

/* Sidebar */
.tp-sidebar {
  width: var(--tp-sidebar-width);
  flex-shrink: 0;
  position: sticky;
  top: calc(var(--tp-header-height) + 24px);
  height: calc(100vh - var(--tp-header-height) - 48px);
  overflow-y: auto;
}

.tp-sidebar-title {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 4px;
}

.tp-sidebar-subtitle {
  font-size: 12px;
  color: var(--tp-text-muted);
  margin-bottom: 16px;
}

.tp-sidebar-nav { list-style: none; }

.tp-sidebar-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  font-size: 14px;
  color: var(--tp-text-muted);
  border-radius: 0 var(--tp-radius-sm) var(--tp-radius-sm) 0;
  transition: color 0.2s, background 0.2s;
}

.tp-sidebar-link:hover {
  color: var(--tp-primary-text);
  background: var(--tp-surface-low);
}

.tp-sidebar-link.active {
  color: var(--tp-primary-text);
  font-weight: 700;
  border-left: 3px solid var(--tp-primary);
  background: var(--tp-surface);
  padding-left: 13px;
}

.tp-sidebar-link svg { width: 16px; height: 16px; flex-shrink: 0; }

/* Main content */
.tp-main { flex: 1; min-width: 0; }

/* Breadcrumb */
.tp-breadcrumb {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--tp-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 500;
  margin-bottom: 24px;
}

.tp-breadcrumb a:hover { color: var(--tp-primary-text); }
.tp-breadcrumb svg { width: 10px; height: 10px; }

/* Page title */
.tp-page-title {
  font-size: clamp(28px, 4vw, 40px);
  font-weight: 700;
  margin-bottom: 8px;
}

.tp-page-desc {
  font-size: 18px;
  color: var(--tp-text-secondary);
  max-width: 640px;
  margin-bottom: 32px;
  line-height: 1.6;
}

/* ============================================================
   TOOL WORKSPACE
   ============================================================ */
.tp-workspace {
  background: var(--tp-surface);
  border-radius: var(--tp-radius);
  border: 1px solid var(--tp-border-light);
  box-shadow: 0 12px 32px rgba(71, 75, 255, 0.04);
  overflow: hidden;
}

/* Action toolbar */
.tp-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 16px;
  background: var(--tp-surface-low);
  border-bottom: 1px solid var(--tp-border-light);
}

.tp-btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--tp-radius-full);
  background: var(--tp-primary);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: background 0.2s;
}

.tp-btn-primary:hover { background: var(--tp-primary-hover); }

.tp-btn-outline {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--tp-radius-full);
  background: var(--tp-surface);
  color: var(--tp-text-secondary);
  font-size: 14px;
  font-weight: 500;
  border: 1px solid var(--tp-border);
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s;
}

.tp-btn-outline:hover {
  border-color: var(--tp-primary);
  color: var(--tp-primary-text);
}

/* Dual-pane editor */
.tp-editor-panes {
  display: grid;
  grid-template-columns: 1fr 1fr;
  min-height: 400px;
}

.tp-editor-pane {
  position: relative;
  border-right: 1px solid var(--tp-border-light);
}

.tp-editor-pane:last-child { border-right: none; }

.tp-editor-label {
  position: absolute;
  top: 16px;
  right: 24px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: rgba(0,0,0,0.15);
  pointer-events: none;
}

.tp-editor-pane textarea {
  width: 100%;
  height: 100%;
  min-height: 400px;
  padding: 24px;
  border: none;
  background: transparent;
  font-family: var(--tp-font-mono);
  font-size: 14px;
  color: var(--tp-text);
  resize: vertical;
  outline: none;
}

.tp-editor-pane textarea::placeholder { color: rgba(0,0,0,0.2); }

/* Output action bar */
.tp-output-bar {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  padding: 12px 16px;
  border-top: 1px solid var(--tp-border-light);
  background: rgba(244, 242, 255, 0.3);
}

.tp-action-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 500;
  color: var(--tp-text-secondary);
  background: none;
  border: none;
  cursor: pointer;
  transition: color 0.2s;
}

.tp-action-btn:hover { color: var(--tp-primary-text); }

.tp-action-btn.danger { color: var(--tp-error); }
.tp-action-btn.danger:hover { background: rgba(186, 26, 26, 0.05); border-radius: var(--tp-radius-full); }

.tp-action-btn svg { width: 18px; height: 18px; }

/* ============================================================
   SIMILAR TOOLS SECTION
   ============================================================ */
.tp-similar {
  margin-top: 64px;
}

.tp-similar h2 {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 24px;
}

.tp-similar-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
}

/* ============================================================
   EDITORIAL CONTENT (What Is / How To / FAQ)
   ============================================================ */
.tp-content-section {
  margin-top: 64px;
  max-width: 720px;
}

.tp-content-section h2 {
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 20px;
}

.tp-content-section p {
  font-size: 17px;
  color: var(--tp-text-secondary);
  line-height: 1.7;
  margin-bottom: 16px;
}

/* How-to steps */
.tp-steps { list-style: none; }

.tp-step {
  display: flex;
  gap: 16px;
  margin-bottom: 24px;
}

.tp-step-num {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--tp-primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
}

.tp-step h4 {
  font-family: var(--tp-font-body);
  font-size: 17px;
  font-weight: 700;
  margin-bottom: 4px;
}

.tp-step p {
  font-size: 15px;
  color: var(--tp-text-muted);
  margin: 0;
}

/* FAQ Accordion */
.tp-faq-list { list-style: none; }

.tp-faq-item {
  background: var(--tp-surface);
  border: 1px solid var(--tp-border-light);
  border-radius: var(--tp-radius);
  margin-bottom: 12px;
  overflow: hidden;
}

.tp-faq-q {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px;
  background: none;
  border: none;
  font: inherit;
  font-weight: 700;
  font-size: 15px;
  color: var(--tp-text);
  cursor: pointer;
  text-align: left;
  transition: background 0.2s;
}

.tp-faq-q:hover { background: var(--tp-surface-low); }
.tp-faq-q svg { width: 20px; height: 20px; color: var(--tp-text-muted); flex-shrink: 0; }

.tp-faq-a {
  padding: 0 20px 20px;
  font-size: 14px;
  color: var(--tp-text-muted);
  line-height: 1.7;
  display: none;
}

.tp-faq-item.open .tp-faq-a { display: block; }
.tp-faq-item.open .tp-faq-q svg { transform: rotate(180deg); }

/* ============================================================
   FOOTER
   ============================================================ */
.tp-footer {
  padding: 48px 0;
  margin-top: 80px;
  border-top: 1px solid rgba(0,0,0,0.06);
}

.tp-footer-inner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  max-width: var(--tp-max-width);
  margin: 0 auto;
  padding: 0 24px;
}

.tp-footer p {
  font-size: 14px;
  color: var(--tp-text-muted);
}

.tp-footer-links {
  display: flex;
  gap: 32px;
}

.tp-footer-links a {
  font-size: 14px;
  color: var(--tp-text-muted);
  transition: color 0.2s;
}

.tp-footer-links a:hover { color: var(--tp-primary-text); }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 1024px) {
  .tp-nav { display: none; }
  .tp-card-grid { grid-template-columns: repeat(2, 1fr); }
  .tp-similar-grid { grid-template-columns: repeat(2, 1fr); }
  .tp-sidebar { display: none; }
  .tp-page-layout { padding: 24px 16px 60px; }
  .tp-editor-panes { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  .tp-card-grid { grid-template-columns: 1fr; }
  .tp-similar-grid { grid-template-columns: 1fr; }
  .tp-hero h1 { font-size: 32px; }
  .tp-hero-search input { height: 52px; font-size: 16px; }
  .tp-footer-inner { flex-direction: column; gap: 16px; }
  .tp-shell { padding: 0 16px; }
}

/* ============================================================
   LEGACY VARIABLE OVERRIDE
   Remap old dark-theme CSS variables → new light theme.
   Keeps original tool workspace HTML/CSS working on light bg.
   ============================================================ */
body.tp-body {
  /* Dark bg vars → light surfaces */
  --bg:    var(--tp-bg);
  --bg2:   var(--tp-surface-low);
  --paper: var(--tp-surface);
  --panel: var(--tp-surface);
  --deep:  var(--tp-surface-low);

  /* Dark text vars → light text */
  --ink:   var(--tp-text);
  --muted: var(--tp-text-secondary);

  /* Border */
  --line:  var(--tp-border);

  /* Accent colors → brand purple */
  --accent:  var(--tp-primary);
  --accent2: var(--tp-primary-hover);
  --brand:   var(--tp-primary);
  --brand2:  var(--tp-primary-hover);

  /* Status colors stay */
  --good: #1bb67b;
  --warn: #e7a63d;
  --bad:  #f06767;
}

/* Force white background on common wrapper classes */
body.tp-body .shell,
body.tp-body .panel,
body.tp-body .hero,
body.tp-body .tool,
body.tp-body .result,
body.tp-body .section,
body.tp-body .workspace,
body.tp-body main,
body.tp-body .tp-main {
  background: var(--tp-surface);
  color: var(--tp-text);
}

/* Ensure page background is light */
body.tp-body {
  background: var(--tp-bg) !important;
}

/* ============================================================
   HARDCODED DARK COLOR OVERRIDES
   Tool pages often use hardcoded hex dark colors.
   These overrides convert common tool UI elements to light theme.
   Code editors (textarea with monospace font) intentionally stay dark.
   ============================================================ */

/* Labels: were light-on-dark, now dark-on-light */
body.tp-body label {
  color: var(--tp-text-secondary) !important;
}

/* Stat boxes (INPUT CHARS, OUTPUT LINES, etc.) */
body.tp-body .stat {
  background: var(--tp-surface-low) !important;
  border-color: var(--tp-border) !important;
}
body.tp-body .stat b {
  color: var(--tp-text-secondary) !important;
}
body.tp-body .stat span {
  color: var(--tp-text) !important;
}

/* Status / output bar */
body.tp-body .status {
  background: var(--tp-surface-low) !important;
  border-color: var(--tp-border) !important;
  color: var(--tp-text) !important;
}

/* Tool tag / badge chips */
body.tp-body .tag {
  background: #eef0ff !important;
  border-color: #c7caff !important;
  color: var(--tp-primary) !important;
}

/* KPI chips */
body.tp-body .kpi {
  background: var(--tp-surface-low) !important;
  border-color: var(--tp-border) !important;
  color: var(--tp-text-secondary) !important;
}

/* FAQ and example cards */
body.tp-body .faq-item,
body.tp-body .example {
  background: var(--tp-surface-low) !important;
  border-color: var(--tp-border) !important;
}
body.tp-body .faq-item h3,
body.tp-body .example h3 {
  color: var(--tp-text) !important;
}
body.tp-body .faq-item p,
body.tp-body .example p {
  color: var(--tp-text-secondary) !important;
}

/* Section text */
body.tp-body .section p {
  color: var(--tp-text-secondary) !important;
}

/* Ghost buttons: were light-text-on-dark, restyle for light bg */
body.tp-body .ghost {
  background: var(--tp-surface-low) !important;
  color: var(--tp-text) !important;
  border-color: var(--tp-border) !important;
}

/* Nav links in old shell header (now hidden but may leak) */
body.tp-body .nav a {
  color: var(--tp-text-secondary) !important;
  border-color: var(--tp-border) !important;
}
