/* FOSSGO Bulwark webmail brand overlay — sage design system */
:root {
  --color-background: #f2f6f3;
  --color-foreground: #0b1a12;
  --color-primary: #588157;
  --color-primary-foreground: #ffffff;
  --color-secondary: #eef5f0;
  --color-secondary-foreground: #0b1a12;
  --color-muted: #e6efe9;
  --color-muted-foreground: #4a5c52;
  --color-accent: #96c1a2;
  --color-accent-foreground: #0b1a12;
  --color-border: #d4e0d7;
  --color-input: #d4e0d7;
  --color-ring: #96c1a2;
  --color-card: #ffffff;
  --color-card-foreground: #0b1a12;
  --color-popover: #ffffff;
  --color-popover-foreground: #0b1a12;
  --color-sidebar: #f7faf8;
  --color-sidebar-foreground: #0b1a12;
  --color-sidebar-primary: #588157;
  --color-sidebar-primary-foreground: #ffffff;
  --color-sidebar-accent: #e6efe9;
  --color-sidebar-accent-foreground: #0b1a12;
  --color-sidebar-border: #d4e0d7;
  --color-sidebar-ring: #96c1a2;

  /* FOSSGO sidebar redesign tokens */
  --fossgo-sage: #96c1a2;
  --fossgo-sage-dark: #588157;
  --fossgo-canvas: #f2f6f3;
  --fossgo-text: #0b1a12;
  --fossgo-muted: #4a5c52;
  --fossgo-pill: #d8ebe0;
  --fossgo-pill-soft: #e6efe9;
  --fossgo-rail: #ffffff;
  --fossgo-sidebar-top: #f7faf8;
  --fossgo-sidebar-bot: #eef5f0;
}

.dark {
  --color-background: #0a100d;
  --color-foreground: #eef4f0;
  --color-primary: #96c1a2;
  --color-primary-foreground: #0b1a12;
  --color-secondary: #121a15;
  --color-secondary-foreground: #eef4f0;
  --color-muted: #152019;
  --color-muted-foreground: #a7b8ae;
  --color-accent: #1a2820;
  --color-accent-foreground: #eef4f0;
  --color-border: rgba(150, 193, 162, 0.22);
  --color-input: rgba(150, 193, 162, 0.22);
  --color-ring: #96c1a2;
  --color-card: #0f1612;
  --color-card-foreground: #eef4f0;
  --color-popover: #0f1612;
  --color-popover-foreground: #eef4f0;
  --color-sidebar: #0c120f;
  --color-sidebar-foreground: #eef4f0;
  --color-sidebar-primary: #96c1a2;
  --color-sidebar-primary-foreground: #0b1a12;
  --color-sidebar-accent: #152019;
  --color-sidebar-accent-foreground: #eef4f0;
  --color-sidebar-border: rgba(150, 193, 162, 0.18);
  --color-sidebar-ring: #96c1a2;

  --fossgo-sage: #96c1a2;
  --fossgo-sage-dark: #7aab88;
  --fossgo-canvas: #0a100d;
  --fossgo-text: #eef4f0;
  --fossgo-muted: #a7b8ae;
  --fossgo-pill: #1a2820;
  --fossgo-pill-soft: #152019;
  --fossgo-rail: #0f1612;
  --fossgo-sidebar-top: #0e1411;
  --fossgo-sidebar-bot: #0c120f;
}

html, body {
  background-color: var(--color-background) !important;
  color: var(--color-foreground);
}

/* =====================================================================
   SIDEBAR REDESIGN (FOSSGO sage — modern / keren)
   Targets Bulwark: .w-14.bg-secondary (icon rail) +
   .bg-secondary.border-e / border-r (folder pane) +
   [data-testid="folder-row"] / [data-section-name] / [data-testid="folder-counts"]
   ===================================================================== */

/* --- Folder pane surface: soft sage wash + light edge --- */
[data-slot="sidebar"],
aside[data-slot="sidebar"],
.relative.flex.flex-col.h-full.bg-secondary,
div.bg-secondary.border-e,
div.bg-secondary.border-r,
.bg-secondary.border-border.relative.flex.flex-col.h-full {
  background: linear-gradient(
    180deg,
    var(--fossgo-sidebar-top) 0%,
    var(--fossgo-sidebar-bot) 100%
  ) !important;
  color: var(--fossgo-text) !important;
  border-color: rgba(88, 129, 87, 0.12) !important;
  box-shadow: inset -1px 0 0 rgba(88, 129, 87, 0.06) !important;
}

[data-slot="sidebar"] {
  min-width: 14rem !important;
  padding-top: 0.35rem !important;
}

/* --- Far-left icon rail: frost / white, distinct from folder pane --- */
.w-14.bg-secondary,
div.w-14.bg-secondary.flex.flex-col,
.w-14.bg-secondary.flex.flex-col.flex-shrink-0 {
  background: #ffffff !important;
  background-color: #ffffff !important;
  background-image: none !important;
  box-shadow: 1px 0 0 rgba(88, 129, 87, 0.08) !important;
  border-right: 1px solid rgba(88, 129, 87, 0.1) !important;
}

.dark .w-14.bg-secondary,
.dark div.w-14.bg-secondary.flex.flex-col {
  background: var(--fossgo-rail) !important;
  border-right-color: rgba(150, 193, 162, 0.14) !important;
}

/* Rail icon buttons: smooth hover + sage active pill + soft glow */
.w-14.bg-secondary a,
.w-14.bg-secondary button,
.w-14.bg-secondary [role="button"] {
  border-radius: 0.7rem !important;
  transition: background-color 0.18s ease, color 0.18s ease, box-shadow 0.18s ease,
    transform 0.15s ease !important;
}

.w-14.bg-secondary a:hover,
.w-14.bg-secondary button:hover,
.w-14.bg-secondary [role="button"]:hover {
  background: var(--fossgo-pill-soft) !important;
  color: var(--fossgo-sage-dark) !important;
}

/* Active rail item (Bulwark: bg-primary/10 text-primary) */
.w-14.bg-secondary .bg-primary\/10,
.w-14.bg-secondary [aria-current="page"],
.w-14.bg-secondary a.bg-primary\/10,
.w-14.bg-secondary button.bg-primary\/10 {
  background: var(--fossgo-pill) !important;
  color: var(--fossgo-sage-dark) !important;
  box-shadow: 0 0 0 1px rgba(150, 193, 162, 0.35),
    0 0 14px rgba(150, 193, 162, 0.28) !important;
}

.w-14.bg-secondary .text-primary {
  color: var(--fossgo-sage-dark) !important;
}

/* --- Folder / nav rows: modern pills, tighter rhythm --- */
[data-slot="sidebar"] a,
[data-slot="sidebar"] button,
nav[role="navigation"] a,
nav[role="navigation"] button,
[data-testid="folder-row"],
[data-testid="folder-row"] > button {
  border-radius: 0.75rem !important;
  font-size: 0.875rem !important;
  font-weight: 500 !important;
  letter-spacing: -0.01em !important;
  min-height: 2.25rem !important; /* ~36px */
  transition: background-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease !important;
}

[data-testid="folder-row"] {
  margin-inline: 0.35rem !important;
  margin-block: 1px !important;
  width: calc(100% - 0.7rem) !important;
  gap: 0 !important;
  /* kill harsh left accent bar */
  border-inline-start-width: 0 !important;
  border-left-width: 0 !important;
  border-color: transparent !important;
  background: transparent !important;
}

[data-testid="folder-row"]:hover,
[data-slot="sidebar"] a:hover,
[data-slot="sidebar"] button:hover,
nav[role="navigation"] a:hover,
nav[role="navigation"] button:hover {
  background: rgba(150, 193, 162, 0.14) !important;
  color: var(--fossgo-text) !important;
}

/* Active folder: soft sage pill (not full-bleed rectangle / harsh bar) */
[data-testid="folder-row"][data-selected="true"],
[data-testid="folder-row"].bg-accent,
[data-testid="folder-row"].border-primary {
  background: var(--fossgo-pill) !important;
  color: var(--fossgo-text) !important;
  font-weight: 600 !important;
  border-inline-start-width: 0 !important;
  border-left-width: 0 !important;
  border-color: transparent !important;
  box-shadow: inset 3px 0 0 0 var(--fossgo-sage),
    0 1px 2px rgba(11, 26, 18, 0.04) !important;
}

.dark [data-testid="folder-row"][data-selected="true"],
.dark [data-testid="folder-row"].bg-accent {
  background: var(--fossgo-pill) !important;
  box-shadow: inset 3px 0 0 0 var(--fossgo-sage),
    0 0 0 1px rgba(150, 193, 162, 0.12) !important;
}

/* --- Unread / total counts as compact sage pills --- */
[data-testid="folder-counts"],
[data-testid="folder-counts"] > span {
  font-size: 0.6875rem !important; /* 11px */
  font-weight: 600 !important;
  letter-spacing: 0 !important;
}

[data-testid="folder-counts"] > span:first-child,
[data-testid="folder-counts"] [class*="font-semibold"] {
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  min-width: 1.25rem !important;
  height: 1.25rem !important;
  padding-inline: 0.4rem !important;
  border-radius: 999px !important;
  background: rgba(88, 129, 87, 0.12) !important;
  color: var(--fossgo-sage-dark) !important;
}

[data-testid="folder-row"][data-selected="true"] [data-testid="folder-counts"] > span:first-child,
[data-testid="folder-row"][data-selected="true"] [data-testid="folder-counts"] [class*="font-semibold"] {
  background: rgba(88, 129, 87, 0.22) !important;
  color: var(--fossgo-sage-dark) !important;
}

.dark [data-testid="folder-counts"] > span:first-child,
.dark [data-testid="folder-counts"] [class*="font-semibold"] {
  background: rgba(150, 193, 162, 0.18) !important;
  color: var(--fossgo-sage) !important;
}

/* Total count (secondary) stays muted */
[data-testid="folder-counts"] .text-muted-foreground,
[data-testid="folder-counts"] .text-muted-foreground\/60 {
  opacity: 0.7 !important;
  font-weight: 500 !important;
}

/* --- Section labels: Folders / Shared / Tags --- */
[data-section-name],
button[data-section-name],
button[data-testid="folders-section"],
button[data-testid="shared-section"],
button[data-testid="tags-section"],
button[data-testid="keywords-section"] {
  margin-inline: 0.35rem !important;
  margin-top: 0.65rem !important;
  padding-block: 0.35rem !important;
  border-radius: 0.5rem !important;
}

[data-section-name] > span.text-sm,
[data-section-name] > span.text-xs,
[data-section-name] span.font-semibold,
button[data-section-name] span.truncate {
  font-size: 0.6875rem !important; /* 11px */
  font-weight: 600 !important;
  letter-spacing: 0.08em !important;
  text-transform: uppercase !important;
  color: var(--fossgo-muted) !important;
}

/* --- Icon cohesion: tone rainbow folder icons toward sage/neutral --- */
[data-testid="folder-row"] .w-4.h-4,
[data-testid="folder-row"] span.flex.items-center.justify-center.flex-shrink-0.w-4.h-4,
[data-testid="folder-row"] .w-4.h-4 svg,
[data-testid="folder-row"] span.w-4 svg {
  filter: grayscale(0.75) sepia(0.4) hue-rotate(55deg) saturate(0.65) brightness(0.92) !important;
  opacity: 0.9 !important;
  transition: filter 0.15s ease, opacity 0.15s ease !important;
}

[data-testid="folder-row"]:hover .w-4.h-4,
[data-testid="folder-row"][data-selected="true"] .w-4.h-4,
[data-testid="folder-row"]:hover .w-4.h-4 svg,
[data-testid="folder-row"][data-selected="true"] .w-4.h-4 svg {
  filter: grayscale(0.35) sepia(0.45) hue-rotate(55deg) saturate(0.9) brightness(0.95) !important;
  opacity: 1 !important;
}

/* Spam / junk: keep a subtle warm/red hint */
[data-testid="folder-row"][data-folder-role="junk"] .w-4.h-4,
[data-testid="folder-row"][data-folder-role="junk"] .w-4.h-4 svg,
[data-testid="folder-row"][data-folder-role="spam"] .w-4.h-4,
[data-testid="folder-row"][data-folder-role="spam"] .w-4.h-4 svg {
  filter: grayscale(0.25) sepia(0.55) hue-rotate(-15deg) saturate(1.1) brightness(0.95) !important;
  opacity: 0.95 !important;
}

/* Trash: cooler muted */
[data-testid="folder-row"][data-folder-role="trash"] .w-4.h-4,
[data-testid="folder-row"][data-folder-role="trash"] .w-4.h-4 svg {
  filter: grayscale(0.9) brightness(0.85) !important;
  opacity: 0.75 !important;
}

/* Tags: keep color identity but refine size / weight */
[data-section-name="Tags"] ~ div [data-testid="folder-row"] .w-4.h-4,
[data-section-name="Tags"] ~ * .w-4.h-4,
[data-testid="folder-row"][data-folder-name="Red"] .w-4.h-4,
[data-testid="folder-row"][data-folder-name="Orange"] .w-4.h-4,
[data-testid="folder-row"][data-folder-name="Yellow"] .w-4.h-4,
[data-testid="folder-row"][data-folder-name="Green"] .w-4.h-4,
[data-testid="folder-row"][data-folder-name="Blue"] .w-4.h-4,
[data-testid="folder-row"][data-folder-name="Purple"] .w-4.h-4,
[data-testid="folder-row"][data-folder-name="Pink"] .w-4.h-4 {
  filter: none !important;
  opacity: 0.92 !important;
  transform: scale(0.88);
}

/* Tag rows often lack folder-role — refine any colorful keyword dots */
[data-testid="tag-row"] .w-4.h-4,
[data-testid="keyword-row"] .w-4.h-4 {
  filter: none !important;
  transform: scale(0.85);
  opacity: 0.9 !important;
}

/* --- Shared mailboxes: clearer hierarchy + subtle left rail --- */
[data-testid="folder-row"][data-shared="true"] {
  position: relative !important;
}

/* Nested shared folders: soft vertical guide */
[data-testid="folder-row"][data-shared="true"][data-folder-role] {
  /* nested items already get paddingLeft via inline style; add rail cue */
}

/* Shared mailbox header rows (account addresses — often no folder-role) */
[data-testid="folder-row"][data-shared="true"]:not([data-folder-role]),
[data-testid="folder-row"][data-shared="true"][data-folder-name*="@"] {
  font-weight: 600 !important;
  color: var(--fossgo-text) !important;
  opacity: 1 !important;
}

[data-testid="folder-row"][data-shared="true"]:not([data-folder-role]) .truncate,
[data-testid="folder-row"][data-shared="true"][data-folder-name*="@"] .truncate {
  font-weight: 600 !important;
  font-size: 0.8125rem !important;
  letter-spacing: -0.01em !important;
}

/* Indent cue: left rail line for nested shared children */
.bg-secondary [data-testid="folder-row"][data-shared="true"][data-folder-role] {
  box-shadow: none !important;
}
.bg-secondary [data-testid="folder-row"][data-shared="true"][data-folder-role][data-selected="true"] {
  box-shadow: inset 3px 0 0 0 var(--fossgo-sage),
    0 1px 2px rgba(11, 26, 18, 0.04) !important;
}

/* Soft left guide on the flex indent spacer area for shared trees */
.bg-secondary > div > div:has([data-testid="folder-row"][data-shared="true"]) {
  /* structural hook when :has is available */
}

/* Shared nest: style the padding-left container's sibling feel via border on row */
[data-testid="folder-row"][data-shared="true"][data-folder-role]::before {
  content: "" !important;
  position: absolute !important;
  left: 1.15rem !important;
  top: 0.25rem !important;
  bottom: 0.25rem !important;
  width: 1px !important;
  background: rgba(88, 129, 87, 0.18) !important;
  pointer-events: none !important;
}

.dark [data-testid="folder-row"][data-shared="true"][data-folder-role]::before {
  background: rgba(150, 193, 162, 0.2) !important;
}

/* --- Compose button (unchanged sage pill) --- */
[data-slot="compose-button"],
button[data-slot="compose-button"] {
  background: #96c1a2 !important;
  color: #040609 !important;
  font-weight: 600 !important;
  border-radius: 999px !important;
  box-shadow: 0 0 18px rgba(150, 193, 162, 0.28) !important;
}
[data-slot="compose-button"]:hover,
button[data-slot="compose-button"]:hover {
  background: #588157 !important;
  color: #040609 !important;
}

/* List + header polish */
[data-slot="email-list"] {
  background: #ffffff !important;
  border-color: var(--color-border) !important;
}
.dark [data-slot="email-list"] { background: var(--color-card) !important; }

[data-slot="search-input"],
input[data-slot="search-input"] {
  border-radius: 0.65rem !important;
  border-color: var(--color-border) !important;
  background: #ffffff !important;
}
.dark [data-slot="search-input"],
.dark input[data-slot="search-input"] {
  background: var(--color-muted) !important;
}

/* Focus ring sage */
*:focus-visible {
  outline-color: #96c1a2 !important;
}

/* Fallback broad nav polish (logged-out / alternate slots) */
[data-slot^="nav-"],
nav[role="navigation"] {
  color: var(--color-sidebar-foreground) !important;
  border-color: var(--color-sidebar-border) !important;
}

/* FOSSGO login logo size v9 — big + visible on dark login card */
form[action*="auth"] img[src*="branding"],
form[action*="login"] img[src*="branding"],
[data-slot="login"] img[src*="branding"],
[data-slot="login-logo"] img,
[data-slot="login-logo"],
img[src*="/branding/fossgo-logo"],
img[src*="/branding/fossgo-logo-dark"],
img[src*="loginLogo"],
.login img[src*="branding"],
main img[src*="/branding/fossgo-logo"] {
  height: 72px !important;
  width: auto !important;
  max-height: 96px !important;
  max-width: 320px !important;
  margin-bottom: 1rem !important;
  object-fit: contain !important;
}

@media (min-width: 420px) {
  form[action*="auth"] img[src*="branding"],
  form[action*="login"] img[src*="branding"],
  [data-slot="login"] img[src*="branding"],
  img[src*="/branding/fossgo-logo"],
  img[src*="/branding/fossgo-logo-dark"],
  main img[src*="/branding/fossgo-logo"] {
    height: 88px !important;
    max-height: 96px !important;
    max-width: 340px !important;
  }
}
