@tailwind base;
@tailwind components;
@tailwind utilities;

@layer base {
  :root {
    /* ========================================
       MONOCHROME BASE - Light theme
       ======================================== */
    --background: 0 0% 100%;        /* Pure white #ffffff */
    --foreground: 0 0% 9%;          /* Near black #171717 */
    --card: 0 0% 100%;              /* White cards */
    --card-foreground: 0 0% 9%;
    --muted: 0 0% 96%;              /* Light gray #f5f5f5 */
    --muted-foreground: 0 0% 45%;   /* Medium gray #737373 */
    --border: 0 0% 88%;             /* Border gray #e0e0e0 */
    --input: 0 0% 88%;
    --ring: 0 0% 60%;               /* Focus ring #999999 */

    /* ========================================
       SEMANTIC COLORS - Mapped to new theme
       ======================================== */
    --primary: 0 0% 9%;             /* Black for primary */
    --primary-foreground: 0 0% 98%;
    --secondary: 0 0% 96%;          /* Light gray */
    --secondary-foreground: 0 0% 9%;
    --popover: 0 0% 100%;
    --popover-foreground: 0 0% 9%;
    --destructive: 0 72% 51%;       /* Red for errors #dc2626 */
    --destructive-foreground: 0 0% 98%;
    --accent: 0 0% 96%;
    --accent-foreground: 0 0% 9%;

    /* ========================================
       ENTITY COLORS - Updated to match website theme
       Using hex values for consistency with new design system
       ======================================== */
    --inc: 152 100% 50%;            /* #00FF88 - Neon mint green */
    --inc-foreground: 0 0% 9%;
    --inc-green: 152 100% 50%;      /* Legacy alias */
    --inc-subtle: 152 100% 50% / 0.15;

    --org: 252 75% 74%;             /* #9B8DEC - Electric lavender */
    --org-foreground: 0 0% 9%;

    --app: 42 89% 70%;              /* #F7D16F - Vibrant amber/gold */
    --app-foreground: 0 0% 9%;

    --lab: 182 100% 50%;            /* #00F5FF - Electric cyan */
    --lab-foreground: 0 0% 9%;

    --dao: 342 100% 71%;            /* #FF6B9D - Hot pink/coral */
    --dao-foreground: 0 0% 9%;

    --notification: 0 100% 63%;     /* #FF4444 - Alert red */
    --notification-foreground: 0 0% 98%;
    --notification-red: 0 100% 63%; /* Legacy alias */

    /* ========================================
       TYPOGRAPHY - Font families
       ======================================== */
    --font-sans: 'Geist', 'Geist Fallback', system-ui, sans-serif;
    --font-mono: 'Geist Mono', 'Geist Mono Fallback', monospace;
    --font-display: 'Abril Fatface', Georgia, serif;

    /* Border radius */
    --radius: 0.375rem;             /* 6px base radius */
  }

  /* ========================================
     DARK MODE - Default for the app
     ======================================== */
  .dark {
    --background: 0 0% 0%;          /* Pure black #000000 */
    --foreground: 0 0% 98.5%;       /* Off-white #fafafa */
    --card: 0 0% 6%;                /* Dark gray card #0f0f0f */
    --card-foreground: 0 0% 98.5%;
    --muted: 0 0% 8%;               /* Muted dark #141414 */
    --muted-foreground: 0 0% 55%;   /* Muted text #8c8c8c */
    --border: 0 0% 100% / 0.15;     /* Dark border */
    --input: 0 0% 100% / 0.15;
    --ring: 0 0% 40%;               /* Focus ring */
    --radius: 0.375rem;             /* 6px base radius */

    --primary: 0 0% 98%;
    --primary-foreground: 0 0% 9%;
    --secondary: 0 0% 15%;
    --secondary-foreground: 0 0% 98%;
    --popover: 0 0% 12%;
    --popover-foreground: 0 0% 98%;
    --destructive: 0 62% 70%;       /* Muted red for dark mode #ef4444 */
    --destructive-foreground: 0 0% 9%;
    --accent: 0 0% 15%;
    --accent-foreground: 0 0% 98%;

    /* Entity colors - Dark mode (pastel versions) */
    --inc: 135 100% 86%;            /* #baffc9 - Pastel mint */
    --inc-foreground: 0 0% 9%;
    --inc-green: 135 100% 86%;
    --inc-subtle: 135 100% 86% / 0.08;

    --org: 262 77% 87%;             /* #d4c4f8 - Pastel lavender */
    --org-foreground: 0 0% 9%;

    --app: 30 100% 88%;             /* #ffe4c4 - Pastel peach */
    --app-foreground: 0 0% 9%;

    --lab: 240 100% 90%;            /* #c9c9ff - Pastel periwinkle */
    --lab-foreground: 0 0% 9%;

    --dao: 205 100% 86%;            /* #bae1ff - Pastel blue */
    --dao-foreground: 0 0% 9%;

    --notification: 352 100% 85%;   /* #ffb3ba - Pastel pink */
    --notification-foreground: 0 0% 9%;
    --notification-red: 352 100% 85%;
  }
}

@layer base {
  * {
    @apply border-border;
  }
  body {
    @apply bg-background text-foreground;
    font-family: var(--font-sans);
  }
}

/* ========================================
   LIQUID GLASS EFFECT (Glassmorphism)
   ======================================== */
.glass-enabled .glass-card,
.glass-enabled .bg-card {
  background: rgba(255, 255, 255, 0.05) !important;
  backdrop-filter: blur(12px) saturate(180%);
  -webkit-backdrop-filter: blur(12px) saturate(180%);
  border: 1px solid rgba(255, 255, 255, 0.1) !important;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
}

.glass-enabled.dark .glass-card,
.glass-enabled.dark .bg-card {
  background: rgba(0, 0, 0, 0.3) !important;
  backdrop-filter: blur(16px) saturate(200%);
  -webkit-backdrop-filter: blur(16px) saturate(200%);
  border: 1px solid rgba(255, 255, 255, 0.08) !important;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.glass-enabled .glass-nav,
.glass-enabled nav {
  background: rgba(255, 255, 255, 0.7) !important;
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
}

.glass-enabled.dark .glass-nav,
.glass-enabled.dark nav {
  background: rgba(0, 0, 0, 0.5) !important;
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
}

.glass-enabled .glass-modal {
  background: rgba(255, 255, 255, 0.9) !important;
  backdrop-filter: blur(24px) saturate(200%);
  -webkit-backdrop-filter: blur(24px) saturate(200%);
}

.glass-enabled.dark .glass-modal {
  background: rgba(20, 20, 20, 0.85) !important;
  backdrop-filter: blur(24px) saturate(200%);
  -webkit-backdrop-filter: blur(24px) saturate(200%);
}

.glass-enabled .glass-button {
  background: rgba(255, 255, 255, 0.15) !important;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.2) !important;
}

.glass-enabled.dark .glass-button {
  background: rgba(255, 255, 255, 0.1) !important;
  border: 1px solid rgba(255, 255, 255, 0.15) !important;
}

/* Glass effect transition */
.glass-card,
.bg-card,
nav {
  transition: background 0.3s ease, backdrop-filter 0.3s ease, box-shadow 0.3s ease;
}

/* ========================================
   MODAL OVERLAY WITH BACKDROP BLUR
   ======================================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

.dark .modal-overlay {
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

@layer components {
  /* ========================================
     CARD COMPONENTS
     ======================================== */
  .card {
    @apply bg-card text-card-foreground rounded-none shadow-sm p-6 border border-border;
  }

  /* ========================================
     UNIFIED BUTTON COMPONENT SYSTEM
     ======================================== */

  /* Base Button - Shared properties for ALL buttons */
  .btn {
    @apply inline-flex items-center justify-center gap-2 font-medium py-2 px-4 rounded-md transition-all duration-200 cursor-pointer border border-transparent;
    @apply focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2;
    @apply disabled:opacity-50 disabled:cursor-not-allowed;
    @apply active:scale-[0.98];
    min-height: 2.5rem;
    line-height: 1.25rem;
    font-family: var(--font-mono);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    font-size: 0.75rem;
  }

  /* BLACK BACKGROUND BUTTONS (white text) - Primary CTA */
  .btn-black {
    @apply bg-background text-foreground border border-border;
    @apply hover:opacity-90;
  }

  /* WHITE BACKGROUND BUTTONS (black text) - Secondary */
  .btn-white {
    @apply bg-foreground text-background;
    @apply hover:opacity-90;
  }

  /* ENTITY-SPECIFIC BUTTONS */
  .btn-inc {
    background-color: hsl(var(--inc));
    color: hsl(var(--inc-foreground));
    @apply hover:opacity-90;
  }

  .btn-org {
    background-color: hsl(var(--org));
    color: hsl(var(--org-foreground));
    @apply hover:opacity-90;
  }

  .btn-app {
    background-color: hsl(var(--app));
    color: hsl(var(--app-foreground));
    @apply hover:opacity-90;
  }

  .btn-lab {
    background-color: hsl(var(--lab));
    color: hsl(var(--lab-foreground));
    @apply hover:opacity-90;
  }

  .btn-dao {
    background-color: hsl(var(--dao));
    color: hsl(var(--dao-foreground));
    @apply hover:opacity-90;
  }

  /* OUTLINE VARIANT (transparent with border) */
  .btn-outline {
    @apply bg-transparent text-foreground border border-border;
    @apply hover:bg-muted hover:text-foreground;
  }

  /* GHOST VARIANT (transparent, hover only) */
  .btn-ghost {
    @apply bg-transparent text-foreground;
    @apply hover:bg-muted hover:text-foreground;
  }

  /* SIZE VARIANTS */
  .btn-sm {
    @apply py-1.5 px-3;
    font-size: 0.625rem;
  }

  .btn-lg {
    @apply py-3 px-6;
    font-size: 0.875rem;
  }

  .btn-icon {
    @apply p-2 aspect-square flex items-center justify-center;
  }

  /* BLOCK VARIANT (full width) */
  .btn-block {
    @apply w-full justify-center;
  }

  /* Mobile: buttons span full width */
  @media (max-width: 640px) {
    .fc-btn:not(.fc-btn--icon):not([type="reset"]),
    .btn:not(.btn-icon):not([type="reset"]),
    button[type="submit"] {
      width: 100%;
      justify-content: center;
    }

    /* OAuth grid must stack and let each button fill the row */
    .oauth-grid {
      grid-template-columns: 1fr !important;
      width: 100%;
      gap: 0.75rem;
    }

    .oauth-grid .btn {
      width: 100%;
      justify-content: center;
    }
  }

  /* ========================================
     INPUT COMPONENTS
     ======================================== */
  .input-field {
    @apply w-full px-3 py-2 bg-muted border border-input rounded-md text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:border-transparent transition-colors duration-150;
    font-family: var(--font-sans);
  }

  /* Underline input style (new theme) */
  .input-underline {
    @apply w-full border-0 border-b border-border bg-transparent px-0 py-3 text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-0;
    border-bottom-width: 1px;
    font-family: var(--font-sans);
  }
  
  .input-underline:focus {
    border-color: hsl(var(--inc));
  }

  /* ========================================
     UNIFIED DROPDOWN/SELECT COMPONENT SYSTEM
     ======================================== */

  /* Base Select Styling - applies to all select elements */
  select,
  .select,
  select.input-field {
    @apply appearance-none cursor-pointer;
    @apply w-full px-3 py-2 bg-muted border border-input rounded-md text-foreground;
    @apply focus:outline-none focus:ring-2 focus:ring-ring focus:border-transparent;
    @apply transition-colors duration-150;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23FAFAFA' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    background-size: 12px 12px;
    padding-right: 2.5rem;
  }

  /* Light mode chevron */
  :root select,
  :root .select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23171717' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
  }

  /* Dark mode chevron */
  .dark select,
  .dark .select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23FAFAFA' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
  }

  select option,
  .select option {
    @apply bg-card text-foreground;
  }

  /* Dropdown size variants */
  .select-sm,
  select.select-sm {
    @apply py-1.5 px-2.5 text-sm;
    padding-right: 2rem;
    background-position: right 0.5rem center;
    background-size: 10px 10px;
  }

  .select-lg,
  select.select-lg {
    @apply py-3 px-4 text-lg;
    padding-right: 3rem;
    background-position: right 1rem center;
    background-size: 14px 14px;
  }

  /* Custom Dropdown Menu Container */
  .dropdown {
    @apply relative inline-block;
  }

  .dropdown-menu {
    @apply absolute z-50 min-w-[12rem] py-1;
    @apply bg-card border border-border rounded-none shadow-lg;
    @apply opacity-0 invisible -translate-y-2;
    @apply transition-all duration-200 ease-in-out;
  }

  .dropdown.open .dropdown-menu,
  .dropdown-menu.show {
    @apply opacity-100 visible translate-y-0;
  }

  /* Dropdown positioned above trigger */
  .dropdown-menu.dropdown-up {
    @apply bottom-full mb-2;
  }

  /* Dropdown positioned below trigger (default) */
  .dropdown-menu.dropdown-down {
    @apply top-full mt-2;
  }

  /* Dropdown items */
  .dropdown-item {
    @apply flex items-center gap-3 px-4 py-2 text-sm text-foreground;
    @apply hover:bg-muted transition-colors cursor-pointer;
  }

  .dropdown-item.active {
    @apply bg-muted font-medium;
  }

  .dropdown-item.disabled {
    @apply opacity-50 cursor-not-allowed pointer-events-none;
  }

  /* Dropdown divider */
  .dropdown-divider {
    @apply border-t border-border my-1;
  }

  /* Dropdown header */
  .dropdown-header {
    @apply px-4 py-2 text-xs font-semibold text-muted-foreground uppercase tracking-wider;
    font-family: var(--font-mono);
  }

  /* Dropdown trigger button */
  .dropdown-trigger {
    @apply flex items-center gap-2 cursor-pointer;
  }

  .dropdown-trigger .dropdown-arrow {
    @apply transition-transform duration-200;
  }

  .dropdown.open .dropdown-trigger .dropdown-arrow {
    @apply rotate-180;
  }

  /* ========================================
     NAVIGATION COMPONENTS - MONOCHROME ONLY
     ======================================== */
  .nav-link {
    @apply text-foreground hover:text-foreground hover:bg-muted px-4 py-2 rounded-md text-sm font-medium transition-colors duration-200;
  }

  .nav-link-active {
    @apply text-foreground bg-muted border-b-2 border-foreground;
  }

  .mobile-nav-link {
    @apply text-foreground hover:text-foreground hover:bg-muted block px-4 py-2 rounded-md text-base font-medium transition-colors duration-200;
  }

  .mobile-nav-link-active {
    @apply text-foreground bg-muted border-l-2 border-foreground;
  }

  /* ========================================
     TYPOGRAPHY COMPONENTS
     ======================================== */
  .logo-font {
    font-family: var(--font-display);
    @apply font-normal;
  }

  .font-mono-label {
    font-family: var(--font-mono);
    @apply text-[10px] uppercase tracking-[0.2em] font-medium;
  }

  /* ========================================
     SIDEBAR COMPONENTS
     ======================================== */
  .business-dropdown-menu {
    @apply transition-all duration-200 ease-in-out -translate-y-2 opacity-0;
  }

  .business-dropdown-menu.show {
    @apply translate-y-0 opacity-100;
  }

  .business-dropdown-arrow {
    @apply transition-transform duration-200 ease-in-out;
  }

  .business-dropdown.open .business-dropdown-arrow {
    @apply rotate-180;
  }

  /* Sidebar collapsed state */
  .sidebar-collapsed #sidebar {
    @apply w-16;
  }
  .sidebar-collapsed #sidebar .sidebar-text {
    @apply hidden;
  }
  .sidebar-collapsed #sidebar .sidebar-collapse-icon {
    @apply hidden;
  }
  .sidebar-collapsed #sidebar .sidebar-expand-icon {
    @apply block;
  }
  @media (min-width: 768px) {
    .sidebar-collapsed #main-wrapper {
      margin-left: 4rem;
    }
  }
}

/* ========================================
   BRAND LOGOS - Always show in original colors
   ======================================== */
.brand-logo {
  filter: none !important;
  opacity: 0.85;
  transition: opacity 0.2s ease;
}

.brand-logo:hover {
  opacity: 1;
}

/* ========================================
   MOBILE TOUCH TARGET IMPROVEMENTS
   WCAG 2.5.5 Target Size compliance (44x44px)
   ======================================== */

@media (hover: none) and (pointer: coarse) {
  /* Touch device optimizations */
  .btn, button, a {
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
  }
  
  /* Increase touch targets to 44px minimum */
  #sidebar-toggle {
    min-width: 44px;
    min-height: 44px;
    width: 44px;
    height: 44px;
  }
  
  .sidebar-link {
    min-height: 44px;
    display: flex;
    align-items: center;
  }
  
  .nav-link {
    min-height: 44px;
    display: flex;
    align-items: center;
  }
  
  /* Icon buttons */
  .btn-icon, button[class*="icon"] {
    min-width: 44px;
    min-height: 44px;
  }
  
  /* Pagination controls */
  .pagination button,
  .pagination a {
    min-width: 44px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
  
  /* Prevent text selection on UI elements */
  .nav-link, .sidebar-link, .btn, button, [role="button"] {
    user-select: none;
    -webkit-user-select: none;
  }
  
  /* Increase spacing for touch */
  .space-y-1 > * + * {
    --tw-space-y-reverse: 0;
    margin-top: calc(0.5rem * calc(1 - var(--tw-space-y-reverse)));
    margin-bottom: calc(0.5rem * var(--tw-space-y-reverse));
  }
}

/* ========================================
   PWA INSTALL PROMPT
   ======================================== */

#pwa-install-prompt {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: hsl(var(--card));
  border-top: 1px solid hsl(var(--border));
  padding: 1rem;
  box-shadow: 0 -4px 20px rgba(0,0,0,0.1);
  z-index: 9999;
  transform: translateY(100%);
  transition: transform 0.3s ease-out;
}

#pwa-install-prompt.visible {
  transform: translateY(0);
}

#pwa-install-prompt .prompt-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 1200px;
  margin: 0 auto;
  gap: 1rem;
}

#pwa-install-prompt .prompt-text {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

#pwa-install-prompt .prompt-icon {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background: hsl(var(--primary));
  display: flex;
  align-items: center;
  justify-content: center;
  color: hsl(var(--primary-foreground));
}

#pwa-install-prompt .prompt-actions {
  display: flex;
  gap: 0.5rem;
}

@media (max-width: 640px) {
  #pwa-install-prompt .prompt-content {
    flex-direction: column;
    text-align: center;
  }
  
  #pwa-install-prompt .prompt-actions {
    width: 100%;
  }
  
  #pwa-install-prompt .prompt-actions button {
    flex: 1;
  }
}

/* Mobile input-focus zoom prevention: iOS (Safari and WKWebView) auto-zooms
   any focused input/select/textarea below 16px and the zoom persists. Force
   16px on coarse/mobile viewports so the zoom never triggers. */
@media (max-width: 768px) {
  input,
  select,
  textarea {
    font-size: 16px !important;
  }
}

/* ==========================================================================
   Non-Destructive Palette Aliases for v2 Design System (DS-002 Harmonization)
   ========================================================================== */
.bg-slate-50, .bg-slate-100, .bg-gray-50, .bg-gray-100 { background-color: hsl(var(--card)) !important; }
.bg-green-10, .bg-green-50, .bg-green-100 { background-color: var(--inc-green-subtle) !important; }
.bg-green-500, .bg-green-600 { background-color: var(--inc-green) !important; }
.text-green-500, .text-green-600, .text-emerald-500 { color: var(--inc-green) !important; }
.text-red-500, .text-red-600 { color: hsl(var(--destructive)) !important; }
.border-red-20, .border-red-200 { border-color: rgba(239, 68, 68, 0.2) !important; }

