/* ============================================
   Enfim Japao — Shared Styles
   Single source of truth for CSS variables,
   resets, header, footer, nav, and profile UI.
   ============================================ */

/* --- CSS Custom Properties (canonical: --color-*) --- */
:root {
  --color-primary: #DC2626;
  --color-primary-dark: #B91C1C;
  --color-primary-light: #FEE2E2;
  --color-secondary: #1E40AF;
  --color-secondary-dark: #1E3A8A;
  --color-secondary-light: #DBEAFE;
  --color-accent: #D97706;
  --color-accent-light: #FEF3C7;
  --color-bg: #FAFAF9;
  --color-surface: #FFFFFF;
  --color-surface-elevated: #FFFFFF;
  --color-text: #1C1917;
  --color-text-secondary: #57534E;
  --color-text-muted: #A8A29E;
  --color-border: #E7E5E4;
  --color-border-light: #F5F5F4;
  --color-success: #16A34A;
  --color-success-light: #DCFCE7;
  --color-warning: #D97706;
  --color-warning-light: #FEF3C7;
  --color-danger: #DC2626;
  --color-danger-light: #FEE2E2;
  --color-info: #1E40AF;
  --color-info-light: #DBEAFE;

  /* Short aliases (backward compat with pages using --primary etc.) */
  --primary: #DC2626;
  --primary-dark: #B91C1C;
  --secondary: #1E40AF;
  --bg: #FAFAF9;
  --accent: #D97706;
  --text: #1C1917;
  --text-light: #78716C;
  --text-muted: #A8A29E;
  --surface: #FFFFFF;
  --surface-elevated: #FFFFFF;
  --border: #E7E5E4;
  --border-light: #F5F5F4;
  --success: #16A34A;
  --success-light: #DCFCE7;
  --danger: #DC2626;
  --danger-light: #FEE2E2;

  /* Typography */
  --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --font-size-xs: 0.75rem;
  --font-size-sm: 0.875rem;
  --font-size-base: 1rem;
  --font-size-lg: 1.125rem;
  --font-size-xl: 1.25rem;
  --font-size-2xl: 1.5rem;
  --font-size-3xl: 1.875rem;
  --font-size-4xl: 2.25rem;

  /* Spacing */
  --spacing-xs: 0.25rem;
  --spacing-sm: 0.5rem;
  --spacing-md: 1rem;
  --spacing-lg: 1.5rem;
  --spacing-xl: 2rem;
  --spacing-2xl: 3rem;
  --spacing-3xl: 4rem;

  /* Radii */
  --radius-sm: 0.375rem;
  --radius-md: 0.5rem;
  --radius-lg: 0.75rem;
  --radius-xl: 1rem;
  --radius-full: 9999px;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.07), 0 2px 4px -2px rgba(0,0,0,0.05);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.08), 0 4px 6px -4px rgba(0,0,0,0.04);
  --shadow-xl: 0 20px 25px -5px rgba(0,0,0,0.08), 0 8px 10px -6px rgba(0,0,0,0.04);

  /* Layout */
  --nav-height: 4rem;
  --nav-bottom-height: 3.5rem;

  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-base: 250ms ease;
  --transition-slow: 350ms ease;
  --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

/* --- Dark Mode --- */
@media (prefers-color-scheme: dark) {
  :root {
    --color-bg: #1A1A1A;
    --color-surface: #262626;
    --color-surface-elevated: #2E2E2E;
    --color-text: #F5F5F4;
    --color-text-secondary: #A8A29E;
    --color-text-muted: #78716C;
    --color-border: #3D3D3D;
    --color-border-light: #333333;
    --color-primary-light: #451A1A;
    --color-secondary-light: #1E2A4A;
    --color-success-light: #14332A;
    --color-warning-light: #3D2A0A;
    --color-danger-light: #451A1A;
    --color-info-light: #1E2A4A;
    --color-accent-light: #3D2A0A;

    --shadow-sm: 0 1px 2px rgba(0,0,0,0.2);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.25), 0 2px 4px -2px rgba(0,0,0,0.2);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.3), 0 4px 6px -4px rgba(0,0,0,0.2);
    --shadow-xl: 0 20px 25px -5px rgba(0,0,0,0.35), 0 8px 10px -6px rgba(0,0,0,0.2);

    /* Short aliases dark overrides */
    --primary: #EF4444;
    --primary-dark: #DC2626;
    --secondary: #60A5FA;
    --bg: #1A1A1A;
    --accent: #FBBF24;
    --text: #F5F5F4;
    --text-light: #A8A29E;
    --text-muted: #78716C;
    --surface: #262626;
    --surface-elevated: #2E2E2E;
    --border: #3D3D3D;
    --border-light: #333333;
    --success: #22C55E;
    --success-light: #14332A;
    --danger: #EF4444;
    --danger-light: #451A1A;
  }
}

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

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  /* Prevent double-tap zoom on iOS Capacitor */
  touch-action: manipulation;
}

body {
  font-family: var(--font-family);
  font-size: var(--font-size-base);
  line-height: 1.6;
  color: var(--color-text);
  background-color: var(--color-bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
  /* Safe areas for iOS notch / Dynamic Island / home indicator */
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  padding-left: env(safe-area-inset-left, 0px);
  padding-right: env(safe-area-inset-right, 0px);
}

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

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

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

/* --- Focus Visible (Accessibility) --- */
:focus-visible {
  outline: 3px solid var(--color-secondary);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

:focus:not(:focus-visible) {
  outline: none;
}

/* --- Skip to Content (Accessibility) --- */
.skip-link {
  position: absolute;
  top: -100%;
  left: var(--spacing-md);
  background: var(--color-primary);
  color: #fff;
  padding: var(--spacing-sm) var(--spacing-md);
  border-radius: var(--radius-md);
  z-index: 9999;
  font-weight: 600;
}

.skip-link:focus {
  top: var(--spacing-md);
}

/* --- Auth guard: hide content until verified --- */
body.auth-loading { visibility: hidden; }

/* --- Container --- */
.container {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 var(--spacing-md);
}

/* =========================================
   SITE HEADER
   ========================================= */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--color-surface, #fff);
  border-bottom: 1px solid var(--color-border, #E7E5E4);
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.top-nav {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1rem;
  height: var(--nav-height);
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.logo-link {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  text-decoration: none;
  color: var(--color-text, #1C1917);
}

.logo-icon { width: 32px; height: 32px; }

.logo-text { font-size: 1.1rem; font-weight: 300; }
.logo-text strong { font-weight: 800; color: var(--color-primary, #DC2626); }

.menu-toggle {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--color-text, #1C1917);
  display: block;
  order: -1;
  padding: 0.25rem;
}

/* Mobile: nav-menu as dropdown */
.site-header .nav-menu {
  display: none !important;
  position: absolute !important;
  top: 100% !important;
  left: 0 !important;
  right: 0 !important;
  background: var(--color-surface, #fff) !important;
  border-bottom: 1px solid var(--color-border, #E7E5E4) !important;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1) !important;
  padding: 0.5rem 0 !important;
  z-index: 99 !important;
  height: auto !important;
  transform: none !important;
}

.site-header .nav-menu.active { display: block !important; }

.site-header .nav-menu a {
  display: block;
  padding: 0.75rem 1.5rem;
  color: var(--color-text, #1C1917);
  text-decoration: none;
  font-size: 0.95rem;
  transition: background 0.2s;
}

.site-header .nav-menu a:hover {
  background: var(--color-bg, #FAFAF9);
  color: var(--color-primary, #DC2626);
}

.site-header .nav-menu a.nav-active {
  font-weight: 600;
  color: var(--color-primary, #DC2626);
}

/* Feature-flagged elements: hidden until PostHog confirms the flag is on.
   :not(#_) is a specificity boost so this wins over component rules. */
[data-feature-flag]:not(#_) { display: none !important; }

/* Desktop: nav-menu inline */
@media (min-width: 1024px) {
  .menu-toggle { display: none !important; }

  .site-header .nav-menu {
    display: flex !important;
    position: static !important;
    box-shadow: none !important;
    border: none !important;
    padding: 0 !important;
    gap: 0.15rem !important;
    background: transparent !important;
    flex-wrap: nowrap !important;
    height: auto !important;
    max-height: none !important;
    margin-left: 0 !important;
  }

  .site-header .nav-menu a {
    padding: 0.35rem 0.4rem !important;
    font-size: 0.73rem !important;
    border-radius: 0.25rem !important;
    white-space: nowrap !important;
    display: inline-flex !important;
  }
}

@media (prefers-color-scheme: dark) {
  .site-header {
    background: var(--color-surface, #292524);
  }
  .site-header .nav-menu {
    background: var(--color-surface, #292524) !important;
  }
}

/* --- Landing Header (index.html) --- */
.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--nav-height);
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 var(--spacing-md);
}

.btn-entrar {
  display: inline-flex;
  align-items: center;
  gap: var(--spacing-sm);
  background: var(--color-primary);
  color: #FFFFFF;
  padding: var(--spacing-sm) var(--spacing-lg);
  border-radius: var(--radius-full);
  font-weight: 600;
  font-size: var(--font-size-sm);
  border: none;
  cursor: pointer;
  transition: background var(--transition-fast), transform var(--transition-fast);
}

.btn-entrar:hover {
  background: var(--color-primary-dark);
  color: #FFFFFF;
  transform: translateY(-1px);
}

/* =========================================
   PROFILE DROPDOWN (injected by auth-guard)
   ========================================= */
.nav-user-section {
  display: flex;
  align-items: center;
  order: 2;
  margin-left: auto;
}

.profile-dropdown { position: relative; }

.profile-avatar-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
  overflow: hidden;
}

.profile-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
}

.profile-avatar-initials {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--color-primary, #DC2626);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 600;
}

.profile-dropdown-menu {
  display: none;
  position: absolute;
  top: calc(100% + 12px);
  right: 0;
  left: auto;
  min-width: 200px;
  background: var(--color-surface, #fff);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.15);
  z-index: 1000;
  overflow: hidden;
}

.profile-dropdown.open .profile-dropdown-menu {
  display: block;
  animation: dropdownFadeIn 0.15s ease-out;
}

@keyframes dropdownFadeIn {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

.profile-dropdown-header { padding: 0.75rem 1rem; }

.profile-dropdown-name {
  display: block;
  font-size: 1rem;
  font-weight: 600;
  color: var(--color-text, #1C1917);
}

.profile-dropdown-email {
  display: block;
  font-size: 0.875rem;
  color: var(--color-text-secondary, #57534E);
  margin-top: 0.25rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.profile-dropdown-divider {
  height: 1px;
  background: var(--color-border, #E7E5E4);
}

.profile-dropdown-item {
  display: block;
  padding: 0.75rem 1rem;
  font-size: 1rem;
  color: var(--color-primary, #DC2626) !important;
  text-decoration: none;
  font-weight: 500;
  transition: background 0.15s;
}

.profile-dropdown-item:hover {
  background: var(--color-bg, #FAFAF9);
}

@media (min-width: 1024px) {
  .nav-user-section {
    margin-left: auto;
    order: 2;
  }
}

@media (prefers-color-scheme: dark) {
  .profile-dropdown-menu {
    background: var(--color-surface, #292524);
    box-shadow: 0 4px 16px rgba(0,0,0,0.3);
  }
  .profile-dropdown-item:hover {
    background: rgba(255,255,255,0.05);
  }
}

/* =========================================
   BOTTOM NAVIGATION (Mobile)
   ========================================= */
.nav-bottom {
  display: none;
}

/* =========================================
   FOOTER
   ========================================= */
.footer-simple {
  text-align: center;
  padding: 2rem 1rem;
  border-top: 1px solid var(--color-border);
  color: var(--color-text-muted);
  font-size: 0.85rem;
}

/* =========================================
   PRINT STYLES
   ========================================= */
@media print {
  .site-header,
  .nav-bottom,
  .menu-toggle,
  .back-to-top,
  .nav-menu-overlay,
  .nav-menu {
    display: none !important;
  }

  body {
    padding-bottom: 0;
    background: #fff;
    color: #000;
    font-size: 12pt;
  }

  a {
    color: #000;
    text-decoration: underline;
  }
}
