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

/* LIGHT MODE */
:root {
  --button-outline: rgba(17,49,126, .10);
  --badge-outline: rgba(17,49,126, .05);

  /* Automatic computation of border around primary / danger buttons */
  --opaque-button-border-intensity: -8; /* In terms of percentages */

  /* Backgrounds applied on top of other backgrounds when hovered/active */
  --elevate-1: rgba(17,49,126, .03);
  --elevate-2: rgba(17,49,126, .08);

  --background: 0 0% 100%;
  --foreground: 222 76% 28%;
  --border: 220 13% 91%;
  --card: 0 0% 100%;
  --card-foreground: 222 76% 28%;
  --card-border: 220 13% 91%;
  --sidebar: 0 0% 100%;
  --sidebar-foreground: 222 76% 28%;
  --sidebar-border: 220 13% 91%;
  --sidebar-primary: 222 76% 28%;
  --sidebar-primary-foreground: 0 0% 100%;
  --sidebar-accent: 220 13% 96%;
  --sidebar-accent-foreground: 222 76% 28%;
  --sidebar-ring: 222 76% 28%;
  --popover: 0 0% 100%;
  --popover-foreground: 222 76% 28%;
  --popover-border: 220 13% 91%;
  --primary: 222 76% 28%;
  --primary-foreground: 0 0% 100%;
  --secondary: 220 13% 96%;
  --secondary-foreground: 222 76% 28%;
  --muted: 220 13% 96%;
  --muted-foreground: 220 13% 45%;
  --accent: 220 13% 96%;
  --accent-foreground: 222 76% 28%;
  --destructive: 0 84% 60%;
  --destructive-foreground: 0 0% 100%;
  --input: 220 13% 91%;
  --ring: 222 76% 28%;
  --chart-1: 142 76% 36%;
  --chart-2: 38 92% 50%;
  --chart-3: 199 89% 48%;
  --chart-4: 270 95% 75%;
  --chart-5: 25 95% 53%;

  --font-sans: Inter, sans-serif;
  --font-serif: Georgia, serif;
  --font-mono: Menlo, monospace;
  --radius: .5rem; /* 8px */
  --shadow-2xs: 0px 1px 2px 0px hsl(210 15% 6% / 0.05);
  --shadow-xs: 0px 1px 3px 0px hsl(210 15% 6% / 0.1);
  --shadow-sm: 0px 1px 2px 0px hsl(210 15% 6% / 0.05), 0px 2px 4px -1px hsl(210 15% 6% / 0.1);
  --shadow: 0px 1px 3px 0px hsl(210 15% 6% / 0.1), 0px 4px 6px -2px hsl(210 15% 6% / 0.05);
  --shadow-md: 0px 4px 6px -1px hsl(210 15% 6% / 0.1), 0px 2px 4px -2px hsl(210 15% 6% / 0.05);
  --shadow-lg: 0px 10px 15px -3px hsl(210 15% 6% / 0.1), 0px 4px 6px -4px hsl(210 15% 6% / 0.05);
  --shadow-xl: 0px 20px 25px -5px hsl(210 15% 6% / 0.1), 0px 8px 10px -6px hsl(210 15% 6% / 0.05);
  --shadow-2xl: 0px 25px 50px -12px hsl(210 15% 6% / 0.25);
  --tracking-normal: 0em;
  --spacing: 0.25rem;
}

.dark {
  --button-outline: rgba(17,49,126, .10);
  --badge-outline: rgba(17,49,126, .05);
  --opaque-button-border-intensity: -8;  /* In terms of percentages */
  --elevate-1: rgba(17,49,126, .03);
  --elevate-2: rgba(17,49,126, .08);

  --background: 0 0% 100%;
  --foreground: 222 76% 28%;
  --border: 220 13% 91%;
  --card: 0 0% 100%;
  --card-foreground: 222 76% 28%;
  --card-border: 220 13% 91%;
  --sidebar: 0 0% 100%;
  --sidebar-foreground: 222 76% 28%;
  --sidebar-border: 220 13% 91%;
  --sidebar-primary: 222 76% 28%;
  --sidebar-primary-foreground: 0 0% 100%;
  --sidebar-accent: 220 13% 96%;
  --sidebar-accent-foreground: 222 76% 28%;
  --sidebar-ring: 222 76% 28%;
  --popover: 0 0% 100%;
  --popover-foreground: 222 76% 28%;
  --popover-border: 220 13% 91%;
  --primary: 222 76% 28%;
  --primary-foreground: 0 0% 100%;
  --secondary: 220 13% 96%;
  --secondary-foreground: 222 76% 28%;
  --muted: 220 13% 96%;
  --muted-foreground: 220 13% 45%;
  --accent: 220 13% 96%;
  --accent-foreground: 222 76% 28%;
  --destructive: 0 84% 60%;
  --destructive-foreground: 0 0% 100%;
  --input: 220 13% 91%;
  --ring: 222 76% 28%;
  --chart-1: 142 76% 45%;
  --chart-2: 38 92% 60%;
  --chart-3: 199 89% 58%;
  --chart-4: 270 95% 80%;
  --chart-5: 25 95% 63%;

  --shadow-2xs: 0px 1px 2px 0px hsl(222 76% 28% / 0.05);
  --shadow-xs: 0px 1px 3px 0px hsl(222 76% 28% / 0.1);
  --shadow-sm: 0px 1px 2px 0px hsl(222 76% 28% / 0.05), 0px 2px 4px -1px hsl(222 76% 28% / 0.1);
  --shadow: 0px 1px 3px 0px hsl(222 76% 28% / 0.1), 0px 4px 6px -2px hsl(222 76% 28% / 0.05);
  --shadow-md: 0px 4px 6px -1px hsl(222 76% 28% / 0.1), 0px 2px 4px -2px hsl(222 76% 28% / 0.05);
  --shadow-lg: 0px 10px 15px -3px hsl(222 76% 28% / 0.1), 0px 4px 6px -4px hsl(222 76% 28% / 0.05);
  --shadow-xl: 0px 20px 25px -5px hsl(222 76% 28% / 0.1), 0px 8px 10px -6px hsl(222 76% 28% / 0.05);
  --shadow-2xl: 0px 25px 50px -12px hsl(222 76% 28% / 0.25);
}

@layer base {
  * {
    border-color: hsl(var(--border));
  }

  body {
    font-family: var(--font-sans);
    background-color: hsl(var(--background));
    color: hsl(var(--foreground));
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
  }
}

/* Advanced elevation system from prototype */
@layer utilities {
  /* Hide ugly search cancel button in Chrome until we can style it properly */
  input[type="search"]::-webkit-search-cancel-button {
    @apply hidden;
  }

  /* Placeholder styling for contentEditable div */
  [contenteditable][data-placeholder]:empty::before {
    content: attr(data-placeholder);
    color: hsl(var(--muted-foreground));
    pointer-events: none;
  }

  /* .no-default-hover-elevate/no-default-active-elevate is an escape hatch so consumers of
   * buttons/badges can remove the automatic brightness adjustment on interactions
   * and program their own. */
  .no-default-hover-elevate {}
  .no-default-active-elevate {}

  /**
   * Toggleable backgrounds go behind the content. Hoverable/active goes on top.
   * This way they can stack/compound. Both will overlap the parent's borders!
   * So borders will be automatically adjusted both on toggle, and hover/active,
   * and they will be compounded.
   */
  .toggle-elevate::before,
  .toggle-elevate-2::before {
    content: "";
    pointer-events: none;
    position: absolute;
    inset: 0px;
    border-radius: inherit;
    z-index: -1;
  }

  .toggle-elevate.toggle-elevated::before {
    background-color: var(--elevate-2);
  }

  /* If there's a 1px border, adjust the inset so that it covers that parent's border */
  .border.toggle-elevate::before {
    inset: -1px;
  }

  /* Does not work on elements with overflow:hidden! */
  .hover-elevate:not(.no-default-hover-elevate),
  .active-elevate:not(.no-default-active-elevate),
  .hover-elevate-2:not(.no-default-hover-elevate),
  .active-elevate-2:not(.no-default-active-elevate) {
    position: relative;
    z-index: 0;
  }

  .hover-elevate:not(.no-default-hover-elevate)::after,
  .active-elevate:not(.no-default-active-elevate)::after,
  .hover-elevate-2:not(.no-default-hover-elevate)::after,
  .active-elevate-2:not(.no-default-active-elevate)::after {
    content: "";
    pointer-events: none;
    position: absolute;
    inset: 0px;
    border-radius: inherit;
    z-index: 999;
  }

  .hover-elevate:hover:not(.no-default-hover-elevate)::after,
  .active-elevate:active:not(.no-default-active-elevate)::after {
    background-color: var(--elevate-1);
  }

  .hover-elevate-2:hover:not(.no-default-hover-elevate)::after,
  .active-elevate-2:active:not(.no-default-active-elevate)::after {
    background-color: var(--elevate-2);
  }

  /* If there's a 1px border, adjust the inset so that it covers that parent's border */
  .border.hover-elevate:not(.no-hover-interaction-elevate)::after,
  .border.active-elevate:not(.no-active-interaction-elevate)::after,
  .border.hover-elevate-2:not(.no-hover-interaction-elevate)::after,
  .border.active-elevate-2:not(.no-active-interaction-elevate)::after {
    inset: -1px;
  }

  /* SAAWMS Custom Components */
  .sidebar-width {
    width: 20rem;
  }
  
  .sidebar-width-collapsed {
    width: 4rem;
  }
  
  /* Enhanced Status Badges */
  .status-badge {
    @apply inline-flex items-center rounded-full px-2.5 py-0.5 text-xs font-medium border;
    border-color: var(--badge-outline);
  }
  
  .status-pending {
    @apply bg-yellow-100 text-yellow-800 dark:bg-yellow-900/20 dark:text-yellow-400;
    border-color: hsl(38 92% 50% / 0.2);
  }
  
  .status-approved {
    @apply bg-green-100 text-green-800 dark:bg-green-900/20 dark:text-green-400;
    border-color: hsl(142 76% 36% / 0.2);
  }
  
  .status-rejected {
    @apply bg-red-100 text-red-800 dark:bg-red-900/20 dark:text-red-400;
    border-color: hsl(0 84% 60% / 0.2);
  }
  
  .status-delivered {
    @apply bg-blue-100 text-blue-800 dark:bg-blue-900/20 dark:text-blue-400;
    border-color: hsl(199 89% 48% / 0.2);
  }
  
  /* Enhanced Cards */
  .card {
    @apply rounded-xl border bg-card text-card-foreground;
    border-color: hsl(var(--card-border));
    box-shadow: var(--shadow-sm);
  }
  
  .card-header {
    @apply flex flex-col space-y-1.5 p-6;
  }
  
  .card-content {
    @apply p-6 pt-0;
  }
  
  /* Enhanced Buttons with Elevation */
  .btn {
    @apply inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium;
    @apply focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring;
    @apply disabled:pointer-events-none disabled:opacity-50;
    @apply hover-elevate active-elevate-2;
    @apply transition-all duration-200;
  }
  
  .btn-primary {
    @apply bg-primary text-primary-foreground border min-h-9 px-4 py-2;
    border-color: hsl(from hsl(var(--primary)) h s calc(l + var(--opaque-button-border-intensity)) / alpha);
    box-shadow: var(--shadow-xs);
  }
  
  .btn-primary:active {
    box-shadow: none;
  }
  
  .btn-secondary {
    @apply bg-secondary text-secondary-foreground border min-h-9 px-4 py-2;
    border-color: hsl(from hsl(var(--secondary)) h s calc(l + var(--opaque-button-border-intensity)) / alpha);
    box-shadow: var(--shadow-xs);
  }
  
  .btn-secondary:active {
    box-shadow: none;
  }
  
  .btn-outline {
    @apply border min-h-9 px-4 py-2;
    border-color: var(--button-outline);
    box-shadow: var(--shadow-xs);
  }
  
  .btn-outline:active {
    box-shadow: none;
  }
  
  .btn-sm {
    @apply min-h-8 rounded-md px-3 text-xs;
  }
  
  .btn-lg {
    @apply min-h-10 rounded-md px-8;
  }
  
  /* Enhanced Form Elements */
  .form-input {
    @apply w-full px-3 py-2 border rounded-md bg-background text-foreground;
    @apply placeholder-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:border-transparent;
    @apply transition-all duration-200;
    border-color: hsl(var(--input));
    box-shadow: var(--shadow-2xs);
  }
  
  .form-input:focus {
    box-shadow: var(--shadow-sm);
  }
  
  /* Enhanced Tables */
  .table-container {
    @apply overflow-x-auto;
  }
  
  .table-row {
    @apply border-b border-border hover-elevate transition-all duration-200;
  }
  
  .table-row:hover {
    background-color: var(--elevate-1);
  }
  
  /* Enhanced Modals */
  .modal-overlay {
    @apply fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50;
    backdrop-filter: blur(4px);
  }

  .modal-overlay.hidden {
    display: none !important;
  }

  .modal-content {
    @apply bg-card rounded-xl p-6 w-full max-w-md mx-4;
    border: 1px solid hsl(var(--card-border));
    box-shadow: var(--shadow-xl);
  }
  
  /* Enhanced Sidebar */
  .sidebar-item {
    @apply flex items-center gap-3 rounded-md px-3 py-2 text-sm font-medium transition-all duration-200;
    @apply hover-elevate;
  }
  
  .sidebar-item:hover {
    background-color: var(--elevate-1);
  }
  
  .sidebar-item.active {
    @apply bg-sidebar-accent text-sidebar-accent-foreground;
    box-shadow: var(--shadow-2xs);
  }
  
  /* Animations */
  @keyframes slideIn {
    from {
      opacity: 0;
      transform: translateY(-10px);
    }
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }
  
  @keyframes fadeIn {
    from {
      opacity: 0;
    }
    to {
      opacity: 1;
    }
  }
  
  .animate-slide-in {
    animation: slideIn 0.2s ease-out;
  }
  
  .animate-fade-in {
    animation: fadeIn 0.15s ease-out;
  }
}

/* Hide ugly search cancel button in Chrome until we can style it properly */
input[type="search"]::-webkit-search-cancel-button {
  display: none;
}

/* Sidebar animations */
.sidebar-transition {
  transition: width 0.2s ease-in-out;
}

/* Loading spinner */
.spinner {
  border: 2px solid hsl(var(--muted));
  border-top: 2px solid hsl(var(--primary));
  border-radius: 50%;
  width: 20px;
  height: 20px;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}
