/* ═══════════════════════════════════════════════════════════════
   TermSheet360 Design System — v1.0
   ═══════════════════════════════════════════════════════════════
   
   A single source of truth for all visual styling across the
   TermSheet360 platform. Every page imports this file.
   
   Usage:  <link rel="stylesheet" href="ts360-design-system.css">
   
   Sections:
     1. Design Tokens (CSS Variables)
     2. Reset & Base
     3. Typography
     4. Layout & Grid
     5. Navigation
     6. Buttons
     7. Forms & Inputs
     8. Cards & Surfaces
     9. Tables
    10. Badges & Tags
    11. Modals & Overlays
    12. Alerts & Notifications
    13. Stats & Metrics
    14. Steps & Progress
    15. Sidebar & App Shell
    16. Pipeline & Status
    17. Empty States
    18. Pagination
    19. Tooltips
    20. Tabs
    21. Accordion
    22. File Upload
    23. Utility Classes
    24. Animations
    25. Responsive Breakpoints

   ═══════════════════════════════════════════════════════════════ */


/* ─────────────────────────────────────────────────────────────
   1. DESIGN TOKENS
   ───────────────────────────────────────────────────────────── */

:root {

  /* ── Brand Colors ── */
  --ts-green-50:  #e6f5ee;
  --ts-green-100: #c2e8d4;
  --ts-green-200: #85d1a9;
  --ts-green-300: #3dba7e;
  --ts-green-400: #04a95e;
  --ts-green-500: #017848;   /* ← Primary brand green */
  --ts-green-600: #00613a;
  --ts-green-700: #004d2e;
  --ts-green-800: #003a22;
  --ts-green-900: #002816;

  /* ── Neutrals ── */
  --ts-gray-25:  #fcfcfc;
  --ts-gray-50:  #f9fafb;
  --ts-gray-100: #f0f2f1;
  --ts-gray-150: #e8ebe8;
  --ts-gray-200: #d5d8d5;
  --ts-gray-300: #b0b5b1;
  --ts-gray-400: #8e9590;
  --ts-gray-500: #6b7270;
  --ts-gray-600: #565d5a;
  --ts-gray-700: #3d4240;
  --ts-gray-800: #292b29;
  --ts-gray-900: #1a1c1a;

  /* ── Semantic Colors ── */
  --ts-red-50:   #fef2f2;
  --ts-red-100:  #fecaca;
  --ts-red-500:  #ef4444;
  --ts-red-600:  #dc2626;
  --ts-red-700:  #b91c1c;

  --ts-amber-50:  #fffbeb;
  --ts-amber-100: #fef3c7;
  --ts-amber-500: #f59e0b;
  --ts-amber-600: #d97706;

  --ts-blue-50:  #eff6ff;
  --ts-blue-100: #dbeafe;
  --ts-blue-500: #3b82f6;
  --ts-blue-600: #2563eb;
  --ts-blue-700: #1d4ed8;

  --ts-purple-50:  #f5f3ff;
  --ts-purple-100: #ede9fe;
  --ts-purple-500: #8b5cf6;
  --ts-purple-600: #7c3aed;

  /* ── Semantic Aliases ── */
  --color-primary:     var(--ts-green-500);
  --color-primary-hover: var(--ts-green-600);
  --color-primary-light: var(--ts-green-50);

  --color-success:     var(--ts-green-400);
  --color-success-bg:  var(--ts-green-50);
  --color-warning:     var(--ts-amber-500);
  --color-warning-bg:  var(--ts-amber-50);
  --color-error:       var(--ts-red-600);
  --color-error-bg:    var(--ts-red-50);
  --color-info:        var(--ts-blue-500);
  --color-info-bg:     var(--ts-blue-50);

  /* ── Backgrounds ── */
  --bg-primary:    #ffffff;
  --bg-secondary:  var(--ts-gray-50);
  --bg-tertiary:   var(--ts-green-50);
  --bg-dark:       var(--ts-gray-800);
  --bg-darker:     var(--ts-gray-900);

  /* ── Text ── */
  --text-primary:   var(--ts-gray-800);
  --text-secondary: var(--ts-gray-600);
  --text-muted:     var(--ts-gray-400);
  --text-inverse:   #ffffff;
  --text-link:      var(--ts-green-500);

  /* ── Borders ── */
  --border-default:  var(--ts-gray-200);
  --border-light:    var(--ts-gray-150);
  --border-focus:    var(--ts-green-500);
  --border-error:    var(--ts-red-500);

  /* ── Shadows ── */
  --shadow-xs:   0 1px 2px rgba(0,0,0,.04);
  --shadow-sm:   0 2px 8px rgba(0,0,0,.05);
  --shadow-md:   0 4px 16px rgba(0,0,0,.06);
  --shadow-lg:   0 8px 30px rgba(0,0,0,.07);
  --shadow-xl:   0 12px 40px rgba(0,0,0,.08);
  --shadow-focus: 0 0 0 3px rgba(1,120,72,.12);

  /* ── Typography ── */
  --font-sans:   'Inter', system-ui, -apple-system, sans-serif;
  --font-serif:  'DM Serif Display', Georgia, serif;

  --text-xs:   12px;
  --text-sm:   13px;
  --text-base: 14px;
  --text-md:   15px;
  --text-lg:   17px;
  --text-xl:   20px;
  --text-2xl:  24px;
  --text-3xl:  30px;
  --text-4xl:  36px;
  --text-5xl:  48px;
  --text-6xl:  60px;

  --leading-tight:  1.15;
  --leading-snug:   1.35;
  --leading-normal: 1.55;
  --leading-relaxed: 1.65;

  --tracking-tight:  -0.02em;
  --tracking-normal: 0;
  --tracking-wide:   0.5px;
  --tracking-wider:  1px;
  --tracking-widest: 1.5px;

  /* ── Spacing Scale ── */
  --space-0:   0;
  --space-1:   4px;
  --space-2:   8px;
  --space-3:   12px;
  --space-4:   16px;
  --space-5:   20px;
  --space-6:   24px;
  --space-8:   32px;
  --space-10:  40px;
  --space-12:  48px;
  --space-16:  64px;
  --space-20:  80px;
  --space-24:  96px;

  /* ── Radius ── */
  --radius-sm:   4px;
  --radius-md:   8px;
  --radius-lg:   12px;
  --radius-xl:   16px;
  --radius-2xl:  20px;
  --radius-full: 100px;

  /* ── Widths ── */
  --max-w-xs:    400px;
  --max-w-sm:    480px;
  --max-w-md:    640px;
  --max-w-lg:    860px;
  --max-w-xl:    1000px;
  --max-w-2xl:   1200px;
  --max-w-full:  100%;

  /* ── Sidebar ── */
  --sidebar-width: 260px;
  --sidebar-collapsed: 64px;
  --topbar-height: 60px;

  /* ── Transitions ── */
  --ease-default: cubic-bezier(.4,0,.2,1);
  --ease-bounce:  cubic-bezier(.34,1.56,.64,1);
  --duration-fast: 150ms;
  --duration-base: 200ms;
  --duration-slow: 300ms;

  /* ── Z-Index Scale ── */
  --z-dropdown:  10;
  --z-sticky:    20;
  --z-sidebar:   30;
  --z-topbar:    40;
  --z-overlay:   50;
  --z-modal:     60;
  --z-toast:     70;
  --z-tooltip:   80;
}


/* ─────────────────────────────────────────────────────────────
   2. RESET & BASE
   ───────────────────────────────────────────────────────────── */

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

html {
  font-size: 16px;
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  color: var(--text-primary);
  background: var(--bg-primary);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}

img, video, svg {
  max-width: 100%;
  height: auto;
  display: block;
}

a {
  color: var(--text-link);
  text-decoration: none;
  transition: color var(--duration-fast);
}

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

ul, ol {
  list-style: none;
}

::selection {
  background: var(--ts-green-100);
  color: var(--ts-green-700);
}

:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
}


/* ─────────────────────────────────────────────────────────────
   3. TYPOGRAPHY
   ───────────────────────────────────────────────────────────── */

/* Display headings — serif */
.ts-display-xl {
  font-family: var(--font-serif);
  font-size: clamp(42px, 6.5vw, 76px);
  font-weight: 400;
  line-height: 1.08;
  letter-spacing: var(--tracking-tight);
}

.ts-display-lg {
  font-family: var(--font-serif);
  font-size: clamp(32px, 4.5vw, 52px);
  font-weight: 400;
  line-height: var(--leading-tight);
}

.ts-display-md {
  font-family: var(--font-serif);
  font-size: clamp(28px, 3.5vw, 44px);
  font-weight: 400;
  line-height: var(--leading-tight);
}

/* Section titles — serif */
.ts-title-xl  { font-family: var(--font-serif); font-size: var(--text-5xl); line-height: var(--leading-tight); }
.ts-title-lg  { font-family: var(--font-serif); font-size: var(--text-4xl); line-height: var(--leading-tight); }
.ts-title-md  { font-family: var(--font-serif); font-size: var(--text-3xl); line-height: var(--leading-snug); }
.ts-title-sm  { font-family: var(--font-serif); font-size: var(--text-2xl); line-height: var(--leading-snug); }

/* Headings — sans */
.ts-heading-xl { font-size: var(--text-xl); font-weight: 700; line-height: var(--leading-snug); }
.ts-heading-lg { font-size: 18px; font-weight: 700; line-height: var(--leading-snug); }
.ts-heading-md { font-size: var(--text-md); font-weight: 700; line-height: var(--leading-snug); }
.ts-heading-sm { font-size: var(--text-base); font-weight: 700; line-height: var(--leading-snug); }

/* Body text */
.ts-body-lg    { font-size: var(--text-lg); line-height: var(--leading-relaxed); }
.ts-body-md    { font-size: var(--text-md); line-height: var(--leading-relaxed); }
.ts-body-base  { font-size: var(--text-base); line-height: var(--leading-normal); }
.ts-body-sm    { font-size: var(--text-sm); line-height: var(--leading-normal); }
.ts-body-xs    { font-size: var(--text-xs); line-height: var(--leading-normal); }

/* Labels */
.ts-label {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text-secondary);
  display: block;
  margin-bottom: var(--space-1);
}

.ts-label-upper {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: var(--tracking-wider);
  color: var(--text-muted);
}

/* Section label pill */
.ts-section-label {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  background: var(--color-primary-light);
  color: var(--color-primary);
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: var(--tracking-widest);
  padding: 6px var(--space-4);
  border-radius: var(--radius-full);
  margin-bottom: var(--space-5);
}

/* Text colors */
.ts-text-primary   { color: var(--text-primary); }
.ts-text-secondary { color: var(--text-secondary); }
.ts-text-muted     { color: var(--text-muted); }
.ts-text-green     { color: var(--color-primary); }
.ts-text-error     { color: var(--color-error); }
.ts-text-white     { color: var(--text-inverse); }

/* Highlight */
.ts-highlight { color: var(--color-primary); }


/* ─────────────────────────────────────────────────────────────
   4. LAYOUT & GRID
   ───────────────────────────────────────────────────────────── */

.ts-container {
  max-width: var(--max-w-2xl);
  margin: 0 auto;
  padding: 0 var(--space-6);
}

.ts-container-sm { max-width: var(--max-w-sm); margin: 0 auto; padding: 0 var(--space-6); }
.ts-container-md { max-width: var(--max-w-md); margin: 0 auto; padding: 0 var(--space-6); }
.ts-container-lg { max-width: var(--max-w-lg); margin: 0 auto; padding: 0 var(--space-6); }
.ts-container-xl { max-width: var(--max-w-xl); margin: 0 auto; padding: 0 var(--space-6); }

.ts-section     { padding: 100px 0; }
.ts-section-sm  { padding: 64px 0; }
.ts-section-alt { background: var(--bg-secondary); }
.ts-section-dark { background: var(--bg-dark); color: var(--text-inverse); }
.ts-section-green { background: var(--color-primary); color: var(--text-inverse); }

.ts-grid     { display: grid; gap: var(--space-5); }
.ts-grid-2   { grid-template-columns: repeat(2, 1fr); }
.ts-grid-3   { grid-template-columns: repeat(3, 1fr); }
.ts-grid-4   { grid-template-columns: repeat(4, 1fr); }
.ts-grid-sidebar { grid-template-columns: 1fr 420px; gap: var(--space-16); }

.ts-flex { display: flex; }
.ts-flex-center { display: flex; align-items: center; justify-content: center; }
.ts-flex-between { display: flex; align-items: center; justify-content: space-between; }
.ts-flex-col { display: flex; flex-direction: column; }
.ts-flex-wrap { flex-wrap: wrap; }
.ts-gap-1 { gap: var(--space-1); }
.ts-gap-2 { gap: var(--space-2); }
.ts-gap-3 { gap: var(--space-3); }
.ts-gap-4 { gap: var(--space-4); }
.ts-gap-5 { gap: var(--space-5); }
.ts-gap-6 { gap: var(--space-6); }
.ts-gap-8 { gap: var(--space-8); }


/* ─────────────────────────────────────────────────────────────
   5. NAVIGATION
   ───────────────────────────────────────────────────────────── */

/* Public navbar */
.ts-navbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: var(--z-topbar);
  padding: 14px 0;
  background: rgba(255,255,255,.85);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border-light);
  transition: box-shadow var(--duration-slow);
}

.ts-navbar.scrolled {
  box-shadow: var(--shadow-sm);
}

.ts-navbar-inner {
  max-width: var(--max-w-2xl);
  margin: 0 auto;
  padding: 0 var(--space-6);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* Logo */
.ts-logo {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  text-decoration: none;
  color: var(--text-primary);
}

.ts-logo-mark {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-md);
  background: var(--color-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: var(--text-base);
  color: #fff;
}

.ts-logo-text {
  font-weight: 800;
  font-size: 19px;
  letter-spacing: -0.4px;
}

.ts-logo-text span {
  color: var(--color-primary);
}

/* Nav links */
.ts-nav-links {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  list-style: none;
}

.ts-nav-link {
  color: var(--text-primary);
  text-decoration: none;
  font-size: var(--text-base);
  font-weight: 600;
  padding: 10px var(--space-4);
  border-radius: var(--radius-full);
  transition: background var(--duration-base);
}

.ts-nav-link:hover {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

/* App topbar (logged in) */
.ts-topbar {
  position: fixed;
  top: 0;
  left: var(--sidebar-width);
  right: 0;
  height: var(--topbar-height);
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-6);
  z-index: var(--z-topbar);
}

.ts-topbar-title {
  font-size: var(--text-lg);
  font-weight: 700;
}

/* Mobile hamburger */
.ts-hamburger {
  display: none;
  background: none;
  border: none;
  color: var(--text-primary);
  cursor: pointer;
  padding: var(--space-2);
}

/* Mobile menu */
.ts-mobile-menu {
  display: none;
  position: fixed;
  inset: 0;
  z-index: var(--z-overlay);
  background: var(--bg-primary);
  padding: 100px var(--space-6) var(--space-10);
  flex-direction: column;
  gap: var(--space-2);
}

.ts-mobile-menu.open { display: flex; }

.ts-mobile-menu a {
  color: var(--text-primary);
  text-decoration: none;
  font-size: var(--text-lg);
  font-weight: 600;
  padding: var(--space-3) 0;
  border-bottom: 1px solid var(--border-light);
}


/* ─────────────────────────────────────────────────────────────
   6. BUTTONS
   ───────────────────────────────────────────────────────────── */

.ts-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  font-family: var(--font-sans);
  font-weight: 700;
  font-size: var(--text-base);
  border: none;
  cursor: pointer;
  text-decoration: none;
  transition: all var(--duration-base) var(--ease-default);
  border-radius: var(--radius-full);
  padding: 12px var(--space-6);
  line-height: 1;
  white-space: nowrap;
}

.ts-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none !important;
  box-shadow: none !important;
}

/* Sizes */
.ts-btn-xs  { font-size: var(--text-xs); padding: 6px var(--space-3); }
.ts-btn-sm  { font-size: var(--text-sm); padding: 9px var(--space-5); }
.ts-btn-lg  { font-size: var(--text-lg); padding: 18px var(--space-10); }
.ts-btn-xl  { font-size: 18px; padding: 20px var(--space-12); }

/* Full width */
.ts-btn-block { width: 100%; }

/* Variants */
.ts-btn-primary {
  background: var(--color-primary);
  color: var(--text-inverse);
}
.ts-btn-primary:hover:not(:disabled) {
  background: var(--color-primary-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(1,120,72,.2);
}

.ts-btn-secondary {
  background: var(--bg-secondary);
  color: var(--text-primary);
}
.ts-btn-secondary:hover:not(:disabled) {
  background: var(--ts-gray-150);
}

.ts-btn-outline {
  background: transparent;
  color: var(--color-primary);
  border: 2px solid var(--color-primary);
}
.ts-btn-outline:hover:not(:disabled) {
  background: var(--color-primary);
  color: var(--text-inverse);
}

.ts-btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border-default);
}
.ts-btn-ghost:hover:not(:disabled) {
  border-color: var(--ts-gray-300);
  color: var(--text-primary);
}

.ts-btn-dark {
  background: var(--bg-dark);
  color: var(--text-inverse);
}
.ts-btn-dark:hover:not(:disabled) {
  background: var(--bg-darker);
  transform: translateY(-1px);
}

.ts-btn-danger {
  background: var(--color-error);
  color: var(--text-inverse);
}
.ts-btn-danger:hover:not(:disabled) {
  background: var(--ts-red-700);
}

.ts-btn-nav-cta {
  background: var(--color-primary);
  color: var(--text-inverse);
  padding: 10px var(--space-6);
}
.ts-btn-nav-cta:hover {
  background: var(--color-primary-hover);
  color: var(--text-inverse);
}

/* Icon only button */
.ts-btn-icon {
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: var(--radius-md);
  background: none;
  border: 1px solid var(--border-light);
  color: var(--text-muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all var(--duration-fast);
}
.ts-btn-icon:hover { background: var(--bg-secondary); color: var(--text-primary); }

/* Button spinner */
.ts-btn .ts-spinner {
  display: none;
  width: 16px;
  height: 16px;
  border: 2.5px solid rgba(255,255,255,.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: ts-spin .6s linear infinite;
}
.ts-btn.loading .ts-spinner { display: inline-block; }
.ts-btn.loading .ts-btn-text { opacity: .7; }


/* ─────────────────────────────────────────────────────────────
   7. FORMS & INPUTS
   ───────────────────────────────────────────────────────────── */

.ts-form-group {
  margin-bottom: 18px;
}

.ts-form-group label {
  display: block;
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.ts-form-group label .ts-required {
  color: var(--color-error);
  margin-left: 2px;
}

.ts-input,
.ts-select,
.ts-textarea {
  width: 100%;
  padding: 13px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-default);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  transition: border-color var(--duration-fast), box-shadow var(--duration-fast);
}

.ts-input:focus,
.ts-select:focus,
.ts-textarea:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: var(--shadow-focus);
}

.ts-input::placeholder,
.ts-textarea::placeholder {
  color: var(--ts-gray-300);
}

.ts-select {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%238e9590' viewBox='0 0 16 16'%3E%3Cpath d='M1.5 5.5l6.5 6 6.5-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px;
}

.ts-textarea {
  resize: vertical;
  min-height: 80px;
}

/* Input sizes */
.ts-input-sm { padding: 10px 12px; font-size: var(--text-sm); }
.ts-input-lg { padding: 16px 18px; font-size: var(--text-md); }

/* Error state */
.ts-form-group.has-error .ts-input,
.ts-form-group.has-error .ts-select,
.ts-form-group.has-error .ts-textarea {
  border-color: var(--border-error);
}

.ts-field-error {
  font-size: var(--text-xs);
  color: var(--color-error);
  margin-top: var(--space-1);
  display: none;
}

.ts-form-group.has-error .ts-field-error {
  display: block;
}

/* Form row (side by side) */
.ts-form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-4);
}

/* Password toggle */
.ts-pw-wrap {
  position: relative;
}

.ts-pw-wrap input {
  padding-right: 56px;
}

.ts-pw-toggle {
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: var(--text-sm);
  font-weight: 600;
  font-family: var(--font-sans);
}

/* Checkbox option (card style) */
.ts-checkbox-option {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-sm);
  color: var(--text-secondary);
  cursor: pointer;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-light);
  transition: all var(--duration-fast);
  user-select: none;
}

.ts-checkbox-option:hover {
  background: var(--bg-secondary);
  border-color: var(--border-default);
}

.ts-checkbox-option.selected {
  background: var(--color-primary-light);
  border-color: var(--color-primary);
  color: var(--color-primary);
  font-weight: 600;
}

.ts-checkbox-option input { display: none; }

/* Checkbox / Radio native */
.ts-checkbox,
.ts-radio {
  accent-color: var(--color-primary);
  width: 16px;
  height: 16px;
  cursor: pointer;
}

/* Toggle switch */
.ts-toggle {
  position: relative;
  width: 44px;
  height: 24px;
  border-radius: var(--radius-full);
  background: var(--ts-gray-200);
  cursor: pointer;
  transition: background var(--duration-fast);
  border: none;
  padding: 0;
}

.ts-toggle::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: white;
  box-shadow: var(--shadow-xs);
  transition: transform var(--duration-fast);
}

.ts-toggle.active {
  background: var(--color-primary);
}

.ts-toggle.active::after {
  transform: translateX(20px);
}

/* Search input */
.ts-search {
  position: relative;
}

.ts-search input {
  padding-left: 40px;
}

.ts-search::before {
  content: '🔍';
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 14px;
  pointer-events: none;
}


/* ─────────────────────────────────────────────────────────────
   8. CARDS & SURFACES
   ───────────────────────────────────────────────────────────── */

.ts-card {
  background: var(--bg-primary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-xl);
  padding: var(--space-8);
  transition: all var(--duration-slow) var(--ease-default);
}

.ts-card-sm { padding: var(--space-5); border-radius: var(--radius-lg); }
.ts-card-lg { padding: var(--space-10); border-radius: var(--radius-2xl); }

.ts-card-hover:hover {
  box-shadow: var(--shadow-lg);
  transform: translateY(-2px);
}

.ts-card-interactive {
  cursor: pointer;
}

.ts-card-interactive:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
  border-color: var(--border-default);
}

.ts-card-dark {
  background: var(--bg-dark);
  color: var(--text-inverse);
  border-color: transparent;
}

.ts-card-green {
  background: var(--color-primary);
  color: var(--text-inverse);
  border-color: transparent;
}

/* Auth card (login, register) */
.ts-auth-card {
  width: 100%;
  max-width: var(--max-w-xs);
  background: var(--bg-primary);
  border-radius: var(--radius-xl);
  padding: 44px;
  border: 1px solid var(--border-light);
  box-shadow: var(--shadow-xl);
}

/* Centered page wrapper (for auth pages) */
.ts-auth-page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.ts-auth-main {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-10) var(--space-6);
  background: var(--bg-secondary);
}


/* ─────────────────────────────────────────────────────────────
   9. TABLES
   ───────────────────────────────────────────────────────────── */

.ts-table-wrap {
  background: var(--bg-primary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  overflow-x: auto;
}

.ts-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}

.ts-table th {
  background: var(--ts-gray-50);
  text-align: left;
  padding: var(--space-3) var(--space-4);
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: var(--tracking-wide);
  border-bottom: 1px solid var(--border-light);
  white-space: nowrap;
}

.ts-table td {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--ts-gray-100);
  vertical-align: middle;
}

.ts-table tbody tr:hover td {
  background: var(--ts-gray-25);
}

.ts-table tbody tr:last-child td {
  border-bottom: none;
}

.ts-table-clickable tbody tr {
  cursor: pointer;
}


/* ─────────────────────────────────────────────────────────────
   10. BADGES & TAGS
   ───────────────────────────────────────────────────────────── */

.ts-badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  white-space: nowrap;
}

.ts-badge-green   { background: var(--ts-green-50);  color: var(--ts-green-500); }
.ts-badge-blue    { background: var(--ts-blue-50);   color: var(--ts-blue-700); }
.ts-badge-amber   { background: var(--ts-amber-50);  color: var(--ts-amber-600); }
.ts-badge-red     { background: var(--ts-red-50);    color: var(--ts-red-600); }
.ts-badge-purple  { background: var(--ts-purple-50); color: var(--ts-purple-600); }
.ts-badge-gray    { background: var(--ts-gray-100);  color: var(--ts-gray-600); }

/* Product tags */
.ts-tag {
  display: inline-flex;
  align-items: center;
  padding: 3px var(--space-2);
  border-radius: var(--radius-full);
  font-size: 11px;
  font-weight: 600;
  background: var(--color-primary-light);
  color: var(--color-primary);
  white-space: nowrap;
}

/* Dot indicator */
.ts-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

.ts-dot-green  { background: var(--color-success); }
.ts-dot-amber  { background: var(--color-warning); }
.ts-dot-red    { background: var(--color-error); }
.ts-dot-blue   { background: var(--color-info); }
.ts-dot-gray   { background: var(--ts-gray-300); }


/* ─────────────────────────────────────────────────────────────
   11. MODALS & OVERLAYS
   ───────────────────────────────────────────────────────────── */

.ts-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  background: rgba(0,0,0,.4);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  align-items: center;
  justify-content: center;
  padding: var(--space-6);
}

.ts-overlay.open { display: flex; }

.ts-modal {
  background: var(--bg-primary);
  border-radius: var(--radius-xl);
  padding: var(--space-10);
  width: 100%;
  max-width: var(--max-w-sm);
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 25px 60px rgba(0,0,0,.15);
  position: relative;
}

.ts-modal-lg { max-width: var(--max-w-md); }
.ts-modal-xl { max-width: 720px; }

.ts-modal-close {
  position: absolute;
  top: var(--space-4);
  right: var(--space-4);
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 22px;
  cursor: pointer;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: background var(--duration-fast);
}

.ts-modal-close:hover { background: var(--bg-secondary); color: var(--text-primary); }


/* ─────────────────────────────────────────────────────────────
   12. ALERTS & NOTIFICATIONS
   ───────────────────────────────────────────────────────────── */

.ts-alert {
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: 500;
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
}

.ts-alert-success { background: var(--color-success-bg); color: var(--ts-green-700); border: 1px solid var(--ts-green-200); }
.ts-alert-error   { background: var(--color-error-bg);   color: var(--ts-red-700);   border: 1px solid var(--ts-red-100); }
.ts-alert-warning { background: var(--color-warning-bg); color: var(--ts-amber-600); border: 1px solid var(--ts-amber-100); }
.ts-alert-info    { background: var(--color-info-bg);    color: var(--ts-blue-700);  border: 1px solid var(--ts-blue-100); }

/* Toast notification */
.ts-toast {
  position: fixed;
  top: var(--space-6);
  right: var(--space-6);
  z-index: var(--z-toast);
  background: var(--bg-primary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: var(--space-4) var(--space-5);
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  max-width: 400px;
  animation: ts-slide-in var(--duration-slow) var(--ease-default);
}


/* ─────────────────────────────────────────────────────────────
   13. STATS & METRICS
   ───────────────────────────────────────────────────────────── */

.ts-stat-card {
  background: var(--bg-primary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
}

.ts-stat-value {
  font-family: var(--font-serif);
  font-size: var(--text-4xl);
  color: var(--color-primary);
  line-height: 1;
}

.ts-stat-value-lg {
  font-size: 42px;
}

.ts-stat-label {
  font-size: var(--text-base);
  color: var(--text-muted);
  margin-top: var(--space-2);
  font-weight: 500;
}


/* ─────────────────────────────────────────────────────────────
   14. STEPS & PROGRESS
   ───────────────────────────────────────────────────────────── */

.ts-step-number {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--color-primary);
  color: var(--text-inverse);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: var(--text-xl);
}

.ts-step-number-sm {
  width: 40px;
  height: 40px;
  font-size: var(--text-md);
}

/* Progress bar */
.ts-progress {
  width: 100%;
  height: 6px;
  background: var(--ts-gray-100);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.ts-progress-bar {
  height: 100%;
  background: var(--color-primary);
  border-radius: var(--radius-full);
  transition: width var(--duration-slow) var(--ease-default);
}


/* ─────────────────────────────────────────────────────────────
   15. SIDEBAR & APP SHELL
   ───────────────────────────────────────────────────────────── */

.ts-app-shell {
  display: flex;
  min-height: 100vh;
}

.ts-sidebar {
  width: var(--sidebar-width);
  height: 100vh;
  position: fixed;
  top: 0;
  left: 0;
  background: var(--bg-primary);
  border-right: 1px solid var(--border-light);
  z-index: var(--z-sidebar);
  display: flex;
  flex-direction: column;
  padding: var(--space-4);
  overflow-y: auto;
}

.ts-sidebar-logo {
  padding: var(--space-3) var(--space-3);
  margin-bottom: var(--space-4);
}

.ts-sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}

.ts-sidebar-link {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 10px var(--space-3);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  text-decoration: none;
  font-size: var(--text-base);
  font-weight: 500;
  transition: all var(--duration-fast);
}

.ts-sidebar-link:hover {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

.ts-sidebar-link.active {
  background: var(--color-primary-light);
  color: var(--color-primary);
  font-weight: 600;
}

.ts-sidebar-section {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: var(--tracking-wider);
  color: var(--text-muted);
  padding: var(--space-5) var(--space-3) var(--space-2);
}

.ts-sidebar-divider {
  height: 1px;
  background: var(--border-light);
  margin: var(--space-3) 0;
}

/* Main content area (with sidebar) */
.ts-main {
  margin-left: var(--sidebar-width);
  padding-top: var(--topbar-height);
  min-height: 100vh;
}

.ts-main-content {
  padding: var(--space-6);
  max-width: var(--max-w-2xl);
}


/* ─────────────────────────────────────────────────────────────
   16. PIPELINE & STATUS
   ───────────────────────────────────────────────────────────── */

.ts-status-new       { background: var(--ts-blue-50);   color: var(--ts-blue-700); }
.ts-status-draft     { background: var(--ts-gray-100);  color: var(--ts-gray-600); }
.ts-status-sent      { background: var(--ts-amber-50);  color: var(--ts-amber-600); }
.ts-status-accepted  { background: var(--ts-green-50);  color: var(--ts-green-500); }
.ts-status-expired   { background: var(--ts-red-50);    color: var(--ts-red-600); }
.ts-status-declined  { background: var(--ts-red-50);    color: var(--ts-red-600); }
.ts-status-contacted { background: var(--ts-amber-50);  color: var(--ts-amber-600); }
.ts-status-onboarded { background: var(--ts-green-50);  color: var(--ts-green-500); }


/* ─────────────────────────────────────────────────────────────
   17. EMPTY STATES
   ───────────────────────────────────────────────────────────── */

.ts-empty {
  text-align: center;
  padding: var(--space-16) var(--space-6);
  color: var(--text-muted);
}

.ts-empty-icon {
  font-size: 48px;
  margin-bottom: var(--space-3);
}

.ts-empty-title {
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: var(--space-2);
}

.ts-empty-desc {
  font-size: var(--text-base);
  max-width: 400px;
  margin: 0 auto var(--space-6);
}


/* ─────────────────────────────────────────────────────────────
   18. PAGINATION
   ───────────────────────────────────────────────────────────── */

.ts-pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4);
  font-size: var(--text-sm);
  color: var(--text-muted);
}

.ts-page-btns {
  display: flex;
  gap: var(--space-2);
}

.ts-page-btn {
  padding: 6px 14px;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  background: none;
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  cursor: pointer;
  color: var(--text-primary);
  transition: background var(--duration-fast);
}

.ts-page-btn:hover:not(:disabled) { background: var(--bg-secondary); }
.ts-page-btn:disabled { opacity: .4; cursor: not-allowed; }


/* ─────────────────────────────────────────────────────────────
   19. TOOLTIPS
   ───────────────────────────────────────────────────────────── */

.ts-tooltip {
  position: relative;
}

.ts-tooltip::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-dark);
  color: var(--text-inverse);
  font-size: var(--text-xs);
  font-weight: 500;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--duration-fast);
  z-index: var(--z-tooltip);
}

.ts-tooltip:hover::after { opacity: 1; }


/* ─────────────────────────────────────────────────────────────
   20. TABS
   ───────────────────────────────────────────────────────────── */

.ts-tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border-light);
}

.ts-tab {
  padding: var(--space-3) var(--space-5);
  font-size: var(--text-base);
  font-weight: 600;
  color: var(--text-muted);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: all var(--duration-fast);
  font-family: var(--font-sans);
  margin-bottom: -1px;
}

.ts-tab:hover { color: var(--text-primary); }

.ts-tab.active {
  color: var(--color-primary);
  border-bottom-color: var(--color-primary);
}


/* ─────────────────────────────────────────────────────────────
   21. ACCORDION
   ───────────────────────────────────────────────────────────── */

.ts-accordion-item {
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  overflow: hidden;
  margin-bottom: var(--space-2);
}

.ts-accordion-header {
  width: 100%;
  padding: var(--space-4) var(--space-5);
  background: none;
  border: none;
  text-align: left;
  font-family: var(--font-sans);
  font-size: var(--text-md);
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--text-primary);
  transition: background var(--duration-fast);
}

.ts-accordion-header:hover { background: var(--ts-gray-25); }

.ts-accordion-body {
  padding: 0 var(--space-5) var(--space-5);
  font-size: var(--text-base);
  color: var(--text-secondary);
  line-height: var(--leading-relaxed);
}


/* ─────────────────────────────────────────────────────────────
   22. FILE UPLOAD
   ───────────────────────────────────────────────────────────── */

.ts-upload-zone {
  border: 2px dashed var(--border-default);
  border-radius: var(--radius-lg);
  padding: var(--space-10) var(--space-6);
  text-align: center;
  cursor: pointer;
  transition: all var(--duration-fast);
  background: var(--ts-gray-25);
}

.ts-upload-zone:hover {
  border-color: var(--color-primary);
  background: var(--color-primary-light);
}

.ts-upload-zone.dragover {
  border-color: var(--color-primary);
  background: var(--color-primary-light);
}


/* ─────────────────────────────────────────────────────────────
   23. UTILITY CLASSES
   ───────────────────────────────────────────────────────────── */

.ts-text-center  { text-align: center; }
.ts-text-right   { text-align: right; }
.ts-text-left    { text-align: left; }

.ts-mt-0  { margin-top: 0; }
.ts-mt-2  { margin-top: var(--space-2); }
.ts-mt-4  { margin-top: var(--space-4); }
.ts-mt-6  { margin-top: var(--space-6); }
.ts-mt-8  { margin-top: var(--space-8); }
.ts-mt-12 { margin-top: var(--space-12); }
.ts-mb-0  { margin-bottom: 0; }
.ts-mb-2  { margin-bottom: var(--space-2); }
.ts-mb-4  { margin-bottom: var(--space-4); }
.ts-mb-6  { margin-bottom: var(--space-6); }
.ts-mb-8  { margin-bottom: var(--space-8); }

.ts-mx-auto { margin-left: auto; margin-right: auto; }
.ts-w-full  { width: 100%; }
.ts-sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }
.ts-truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.ts-border-b   { border-bottom: 1px solid var(--border-light); }
.ts-border-t   { border-top: 1px solid var(--border-light); }

.ts-rounded-full { border-radius: var(--radius-full); }

.ts-bg-alt   { background: var(--bg-secondary); }
.ts-bg-white { background: var(--bg-primary); }

.ts-sticky { position: sticky; top: 90px; }

.ts-divider {
  height: 1px;
  background: var(--border-light);
  margin: var(--space-6) 0;
}


/* ─────────────────────────────────────────────────────────────
   24. ANIMATIONS
   ───────────────────────────────────────────────────────────── */

/* Scroll reveal */
/* Content starts visible by default. Only hides when JS adds .js-ready to <html>.
   This ensures content is always visible even if JS fails to load. */
html.js-ready .ts-reveal {
  opacity: 0;
  transform: translateY(24px);
  transition: opacity .6s var(--ease-default), transform .6s var(--ease-default);
}

html.js-ready .ts-reveal.visible {
  opacity: 1;
  transform: translateY(0);
}

/* Fade in (page load) */
.ts-fade-in {
  opacity: 0;
  transform: translateY(16px);
  animation: ts-fade-up .5s var(--ease-default) forwards;
}

.ts-fade-in-delay { animation-delay: .1s; }
.ts-fade-in-delay-2 { animation-delay: .2s; }

@keyframes ts-fade-up {
  to { opacity: 1; transform: translateY(0); }
}

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

@keyframes ts-slide-in {
  from { opacity: 0; transform: translateX(20px); }
  to   { opacity: 1; transform: translateX(0); }
}

@keyframes ts-pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: .4; }
}

.ts-pulse { animation: ts-pulse 2s infinite; }


/* ─────────────────────────────────────────────────────────────
   25. RESPONSIVE BREAKPOINTS
   ───────────────────────────────────────────────────────────── */

/* Tablet */
@media (max-width: 1024px) {
  .ts-grid-4      { grid-template-columns: repeat(2, 1fr); }
  .ts-grid-3      { grid-template-columns: repeat(2, 1fr); }
  .ts-grid-sidebar { grid-template-columns: 1fr; gap: var(--space-10); }

  .ts-sidebar {
    transform: translateX(-100%);
    transition: transform var(--duration-slow) var(--ease-default);
  }
  .ts-sidebar.open { transform: translateX(0); }
  .ts-main { margin-left: 0; }
  .ts-topbar { left: 0; }
}

/* Mobile */
@media (max-width: 768px) {
  :root {
    --topbar-height: 56px;
  }

  .ts-container  { padding: 0 var(--space-4); }
  .ts-section    { padding: 70px 0; }
  .ts-section-sm { padding: 48px 0; }

  .ts-grid-4,
  .ts-grid-3,
  .ts-grid-2     { grid-template-columns: 1fr; }
  .ts-form-row   { grid-template-columns: 1fr; }

  .ts-nav-links { display: none; }
  .ts-hamburger { display: block; }

  .ts-auth-card { padding: var(--space-8) var(--space-6); }
  .ts-card-lg   { padding: var(--space-6); }
  .ts-modal     { padding: var(--space-8) var(--space-6); }

  .ts-display-xl { font-size: 36px; }
}

/* Small mobile */
@media (max-width: 480px) {
  .ts-btn-xl { padding: 16px var(--space-8); font-size: var(--text-md); }
  .ts-btn-lg { padding: 14px var(--space-6); font-size: var(--text-base); }
}


/* ─────────────────────────────────────────────────────────────
   FOOTER
   ───────────────────────────────────────────────────────────── */

.ts-footer {
  background: var(--bg-dark);
  color: rgba(255,255,255,.5);
  padding: var(--space-12) 0 var(--space-8);
}

.ts-footer a {
  color: var(--ts-green-400);
  text-decoration: none;
}

.ts-footer a:hover {
  color: var(--ts-green-300);
}

.ts-page-footer {
  text-align: center;
  padding: var(--space-6);
  font-size: var(--text-xs);
  color: var(--text-muted);
}

.ts-page-footer a {
  color: var(--color-primary);
  text-decoration: none;
}
