/* ============================================================
   Freelancer Dashboard design tokens and foundation (brand v1.1)

   This file is the only place a colour gets chosen. The values match
   the native iOS and Android apps. Dark values live in darkmode.css
   under html[data-theme="dark"] and override the same names, so any rule
   that reads a token flips with the theme and needs no dark selector.

   Load order (base.html): styles.css, Bootstrap, Font Awesome,
   brand.css (this file), components.css, darkmode.css, page CSS, base.css.

   Colour rules of thumb
     --fd-primary / --fd-success / ...      accents, icons, borders, bars
     --fd-*-text                            that colour as text on a surface
     --fd-*-fill                            a fill behind white text
   Never override --white in dark mode. Several rules use it as the text
   colour on a coloured button.
   ============================================================ */

:root {
  color-scheme: light;

  /* Fonts */
  --fd-font-sans:    Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --fd-font-display: "Plus Jakarta Sans", Inter, -apple-system, sans-serif;
  --fd-font-mono:    "JetBrains Mono", "Fira Code", "Courier New", monospace;

  /* Raw palette. Constant in both themes. Use the roles below in rules. */
  --fd-purple-50:  #F5F3FF;
  --fd-purple-100: #EDE9FE;
  --fd-purple-200: #DDD6FE;
  --fd-purple-400: #A78BFA;
  --fd-purple-500: #8B5CF6;
  --fd-purple-600: #7C3AED;
  --fd-purple-700: #6D28D9;
  --fd-purple-800: #5B21B6;
  --fd-purple-900: #4C1D95;
  --fd-green-100: #D1FAE5;
  --fd-green-300: #6EE7B7;
  --fd-green-400: #34D399;
  --fd-green-500: #10B981;
  --fd-green-600: #059669;
  --fd-green-700: #047857;
  --fd-green-800: #065F46;
  --fd-white:    #FFFFFF;
  --fd-gray-50:  #F9FAFB;
  --fd-gray-100: #F3F4F6;
  --fd-gray-200: #E5E7EB;
  --fd-gray-300: #D1D5DB;
  --fd-gray-400: #9CA3AF;
  --fd-gray-500: #6B7280;
  --fd-gray-600: #4B5563;
  --fd-gray-700: #374151;
  --fd-gray-800: #1F2937;
  --fd-gray-900: #111827;

  /* Roles: brand */
  --fd-primary:            #6D28D9;
  --fd-primary-rgb:        109, 40, 217;
  --fd-primary-hover:      #5B21B6;
  --fd-primary-fill:       #6D28D9;
  --fd-primary-fill-hover: #5B21B6;
  --fd-link:               #6D28D9;
  --fd-link-rgb:           109, 40, 217;
  --fd-link-hover:         #5B21B6;
  --fd-link-hover-rgb:     91, 33, 182;

  /* Roles: status */
  --fd-success:       #059669;
  --fd-success-rgb:   5, 150, 105;
  --fd-success-text:  #065F46;
  --fd-success-fill:  #047857;
  --fd-warning:       #D97706;
  --fd-warning-rgb:   217, 119, 6;
  --fd-warning-text:  #92400E;
  --fd-warning-fill:  #FBBF24;
  --fd-danger:        #DC2626;
  --fd-danger-rgb:    220, 38, 38;
  --fd-danger-text:   #B91C1C;
  --fd-danger-fill:   #DC2626;
  --fd-info:          #2563EB;
  --fd-info-rgb:      37, 99, 235;
  --fd-info-text:     #1D4ED8;
  --fd-info-fill:     #2563EB;

  /* Roles: surfaces and text */
  --fd-bg-page:     #F9FAFB;
  --fd-bg-surface:  #FFFFFF;
  --fd-bg-alt:      #F3F4F6;
  --fd-border:      #E5E7EB;
  --fd-text:        #111827;
  --fd-text-muted:  #5F6877;   /* gray-500 darkened: 4.5:1 on --fd-bg-alt */
  --fd-head-bg:     #1F2937;
  --fd-head-fg:     #FFFFFF;
  --fd-input-bg:    #FFFFFF;
  --fd-input-border: #D1D5DB;
  --fd-focus-ring:  rgba(109, 40, 217, 0.25);
  --fd-page-rgb:    249, 250, 251;
  --fd-surface-rgb: 255, 255, 255;
  --fd-alt-rgb:     243, 244, 246;
  --fd-border-rgb:  229, 231, 235;
  --fd-text-rgb:    17, 24, 39;
  --fd-muted-rgb:   95, 104, 119;

  /* Spacing scale (base unit: 4px) */
  --fd-space-1: 4px;
  --fd-space-2: 8px;
  --fd-space-3: 12px;
  --fd-space-4: 16px;
  --fd-space-6: 24px;
  --fd-space-8: 32px;
  --fd-space-12: 48px;
  --fd-space-16: 64px;
  --fd-space-24: 96px;

  /* Radii: sm 4, md 8 (buttons, inputs), lg 12 (cards, modals), full (pills) */
  --fd-radius-sm: 4px;
  --fd-radius-md: 8px;
  --fd-radius-lg: 12px;
  --fd-radius-xl: 16px;
  --fd-radius-full: 9999px;

  /* Shadows. Dark mode drops them and relies on borders. */
  --fd-shadow-sm: 0 1px 2px 0 rgba(0,0,0,0.05);
  --fd-shadow:    0 1px 3px 0 rgba(0,0,0,0.10), 0 1px 2px -1px rgba(0,0,0,0.10);
  --fd-shadow-md: 0 4px 6px -1px rgba(0,0,0,0.10), 0 2px 4px -2px rgba(0,0,0,0.10);
  --fd-shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.10), 0 4px 6px -4px rgba(0,0,0,0.10);

  /* Older names kept so existing templates and stylesheets keep working.
     Each one points at a role above. Do not add new ones. */
  --fd-brand-primary:    var(--fd-primary);
  --fd-brand-secondary:  var(--fd-success);
  --fd-text-primary:     var(--fd-text);
  --fd-text-secondary:   var(--fd-text-muted);
  --fd-error:            var(--fd-danger);
  --fd-error-bg:         rgba(var(--fd-danger-rgb), 0.12);
  --fd-success-bg:       rgba(var(--fd-success-rgb), 0.12);
  --fd-warning-bg:       rgba(var(--fd-warning-rgb), 0.14);
  --fd-info-bg:          rgba(var(--fd-info-rgb), 0.12);
  --white:        #ffffff;
  --black:        #000;
  --light-gray:   var(--fd-bg-page);
  --dark-gray:    var(--fd-text);
  --muted-fg:     var(--fd-text-muted);
  --purple:       var(--fd-primary);
  --green:        var(--fd-success);
  --bright-green: var(--fd-success);
  --hover-green:  var(--fd-success-text);
  --danger:       var(--fd-danger);
  --warning:      var(--fd-warning);
  --info:         var(--fd-info);
  --surface-bg:        var(--fd-bg-surface);
  --surface-bg-alt:    var(--fd-bg-alt);
  --surface-bg-raised: var(--fd-bg-surface);
  --surface-accent:    rgba(var(--fd-primary-rgb), 0.08);
  --text-primary:      var(--fd-text);
  --text-muted:        var(--fd-text-muted);
  --border-color:      var(--fd-border);
  --input-bg:          var(--fd-input-bg);

  /* Bootstrap 5.3 is driven by its own custom properties. Mapping them to
     the roles above recolours every Bootstrap component, in both themes,
     with no component-level overrides. */
  --bs-font-sans-serif: var(--fd-font-sans);
  --bs-body-font-family: var(--fd-font-sans);
  --bs-body-line-height: 1.5;
  --bs-body-color: var(--fd-text);
  --bs-body-color-rgb: var(--fd-text-rgb);
  --bs-body-bg: var(--fd-bg-surface);
  --bs-body-bg-rgb: var(--fd-surface-rgb);
  --bs-emphasis-color: var(--fd-text);
  --bs-emphasis-color-rgb: var(--fd-text-rgb);
  --bs-secondary-color: var(--fd-text-muted);
  --bs-secondary-color-rgb: var(--fd-muted-rgb);
  --bs-secondary-bg: var(--fd-bg-alt);
  --bs-secondary-bg-rgb: var(--fd-alt-rgb);
  --bs-tertiary-color: var(--fd-text-muted);
  --bs-tertiary-color-rgb: var(--fd-muted-rgb);
  --bs-tertiary-bg: var(--fd-bg-alt);
  --bs-tertiary-bg-rgb: var(--fd-alt-rgb);
  --bs-heading-color: var(--fd-text);
  --bs-link-color: var(--fd-link);
  --bs-link-color-rgb: var(--fd-link-rgb);
  --bs-link-hover-color: var(--fd-link-hover);
  --bs-link-hover-color-rgb: var(--fd-link-hover-rgb);
  --bs-border-color: var(--fd-border);
  --bs-border-color-translucent: var(--fd-border);
  --bs-code-color: var(--fd-danger-text);
  --bs-highlight-bg: rgba(var(--fd-warning-rgb), 0.25);
  --bs-primary: var(--fd-primary);
  --bs-primary-rgb: var(--fd-primary-rgb);
  --bs-success: var(--fd-success);
  --bs-success-rgb: var(--fd-success-rgb);
  --bs-warning: var(--fd-warning);
  --bs-warning-rgb: var(--fd-warning-rgb);
  --bs-danger: var(--fd-danger);
  --bs-danger-rgb: var(--fd-danger-rgb);
  --bs-info: var(--fd-info);
  --bs-info-rgb: var(--fd-info-rgb);
  --bs-secondary-rgb: 75, 85, 99;
  --bs-light-rgb: var(--fd-alt-rgb);
  --bs-dark-rgb: 31, 41, 55;
  --bs-primary-text-emphasis: var(--fd-text);
  --bs-success-text-emphasis: var(--fd-text);
  --bs-warning-text-emphasis: var(--fd-text);
  --bs-danger-text-emphasis: var(--fd-text);
  --bs-info-text-emphasis: var(--fd-text);
  --bs-primary-bg-subtle: rgba(var(--fd-primary-rgb), 0.10);
  --bs-success-bg-subtle: rgba(var(--fd-success-rgb), 0.12);
  --bs-warning-bg-subtle: rgba(var(--fd-warning-rgb), 0.14);
  --bs-danger-bg-subtle: rgba(var(--fd-danger-rgb), 0.12);
  --bs-info-bg-subtle: rgba(var(--fd-info-rgb), 0.12);
  --bs-primary-border-subtle: rgba(var(--fd-primary-rgb), 0.35);
  --bs-success-border-subtle: rgba(var(--fd-success-rgb), 0.40);
  --bs-warning-border-subtle: rgba(var(--fd-warning-rgb), 0.45);
  --bs-danger-border-subtle: rgba(var(--fd-danger-rgb), 0.40);
  --bs-info-border-subtle: rgba(var(--fd-info-rgb), 0.40);
}

/* --- Foundation ------------------------------------------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

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

body {
  font-family: var(--fd-font-sans);
  font-size: 1rem;
  line-height: 1.5;
  color: var(--fd-text);
  background-color: var(--fd-bg-page);
  margin: 0;
  padding: 0;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Headings. h1 and h2 share a size so a page title looks the same whichever
   level a template picked. */
h1, h2, h3, h4, h5, h6,
.h1, .h2, .h3, .h4, .h5, .h6 {
  font-family: var(--fd-font-display);
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: -0.02em;
  color: var(--fd-text);
}

h1, .h1,
h2, .h2 { font-size: 1.5rem; }
h3, .h3 { font-size: 1.25rem; }
h4, .h4 { font-size: 1.125rem; }
h5, .h5 { font-size: 1rem; }
h6, .h6 { font-size: 0.875rem; }

/* --- Links ------------------------------------------------- */
a {
  color: var(--fd-link);
  text-decoration: none;
}

a:hover,
a:focus {
  color: var(--fd-link-hover);
  text-decoration: underline;
}

a:focus-visible,
:focus-visible {
  outline: 2px solid var(--fd-primary);
  outline-offset: 2px;
  border-radius: var(--fd-radius-sm);
}

/* --- Misc -------------------------------------------------- */
hr {
  border: none;
  border-top: 1px solid var(--fd-border);
  opacity: 1;
  margin: var(--fd-space-6) 0;
}

::selection {
  background-color: var(--fd-purple-200);
  color: var(--fd-purple-900);
}

/* Money. Use .amount on any currency figure so digits line up. */
.amount,
.money,
.invoice-total,
.balance,
.price {
  font-family: var(--fd-font-mono);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

.amount-positive,
.amount-paid,
.revenue {
  color: var(--fd-success-text);
  font-family: var(--fd-font-mono);
  font-weight: 500;
}

.amount-negative,
.amount-overdue,
.expense {
  color: var(--fd-danger-text);
  font-family: var(--fd-font-mono);
  font-weight: 500;
}

.empty-state {
  text-align: center;
  padding: var(--fd-space-12) var(--fd-space-6);
  color: var(--fd-text-muted);
}

.empty-state-title {
  font-family: var(--fd-font-display);
  font-weight: 600;
  font-size: 1.125rem;
  color: var(--fd-text);
  margin-bottom: var(--fd-space-2);
}

.skeleton {
  background: linear-gradient(90deg, var(--fd-bg-alt) 25%, var(--fd-bg-page) 50%, var(--fd-bg-alt) 75%);
  background-size: 200% 100%;
  animation: fd-skeleton-pulse 1.5s ease-in-out infinite;
  border-radius: var(--fd-radius-md);
}

@keyframes fd-skeleton-pulse {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

@media (prefers-reduced-motion: reduce) {
  .skeleton { animation: none; }
}

/* Slim scrollbars, WebKit and Blink only. */
::-webkit-scrollbar        { width: 8px; height: 8px; }
::-webkit-scrollbar-track  { background: transparent; }
::-webkit-scrollbar-thumb  { background: rgba(var(--fd-muted-rgb), 0.45); border-radius: var(--fd-radius-full); }
::-webkit-scrollbar-thumb:hover { background: rgba(var(--fd-muted-rgb), 0.7); }

/* Assignment table row status colours */
tr.status-green     { background-color: rgba(var(--fd-success-rgb), 0.10); }
tr.status-blue      { background-color: rgba(var(--fd-info-rgb), 0.10); }
tr.status-red       { background-color: rgba(var(--fd-danger-rgb), 0.10); }
tr.status-light-red { background-color: rgba(var(--fd-warning-rgb), 0.10); }


/* A brand with a dark-surface logo renders both images (templates/_page_logo.html).
   Hide the other one. The shown image keeps whatever display its own class sets
   (.auth-logo is a block in base.css, which loads later), hence !important here. */
html:not([data-theme="dark"]) .brand-logo-dark,
html[data-theme="dark"] .brand-logo-light { display: none !important; }
