:root {
  color-scheme: light;
}

/* ============================================
   LIGHT MODE STYLES (Default)
   ============================================ */

/* Body base */
body {
  background-color: #f8fafc; /* slate-50 */
  color: #0f172a; /* slate-900 */
}

/* White backgrounds - cards, sections */
.bg-white {
  background-color: #ffffff !important;
}

/* Slate backgrounds */
.bg-slate-50 {
  background-color: #f8fafc !important;
}

.bg-slate-100 {
  background-color: #f1f5f9 !important;
}

/* Border colors */
.border,
.border-b,
.border-t {
  border-color: #e2e8f0 !important; /* slate-200 */
}

/* Text colors */
.text-slate-900 {
  color: #0f172a !important;
}

.text-slate-700 {
  color: #334155 !important;
}

.text-slate-600 {
  color: #475569 !important;
}

.text-slate-500 {
  color: #64748b !important;
}

/* Links */
a {
  color: #0369a1; /* sky-700 */
}

a:hover {
  color: #0284c7; /* sky-600 */
}

/* Form elements */
input,
textarea,
select {
  background-color: #ffffff;
  border-color: #e2e8f0; /* slate-200 */
  color: #0f172a; /* slate-900 */
}

input:focus,
textarea:focus,
select:focus {
  border-color: #0ea5e9; /* sky-500 */
  outline-color: #0ea5e9;
}

input::placeholder,
textarea::placeholder {
  color: #94a3b8; /* slate-400 */
}

/* Buttons */
button {
  color: #0f172a;
}

.bg-sky-600 {
  background-color: #0284c7 !important;
}

.bg-sky-600:hover {
  background-color: #0369a1 !important;
}

.bg-slate-900 {
  background-color: #0f172a !important;
}

.bg-slate-900:hover {
  background-color: #1e293b !important;
}

/* Hover states */
.hover\:bg-slate-50:hover {
  background-color: #f8fafc !important;
}

.hover\:bg-slate-100:hover {
  background-color: #f1f5f9 !important;
}

/* ============================================
   DARK MODE STYLES (when html.dark)
   ============================================ */

html.dark {
  color-scheme: dark;
}

html.dark body {
  background-color: #0f172a !important; /* slate-900 */
  color: #e2e8f0 !important; /* slate-200 */
}

html.dark .bg-white {
  background-color: #1e293b !important; /* slate-800 */
}

html.dark .bg-slate-50 {
  background-color: #0f172a !important; /* slate-900 */
}

html.dark .bg-slate-100 {
  background-color: #1e293b !important; /* slate-800 */
}

html.dark .border,
html.dark .border-b,
html.dark .border-t {
  border-color: #334155 !important; /* slate-700 */
}

html.dark .text-slate-900,
html.dark .text-slate-700 {
  color: #e2e8f0 !important; /* slate-200 */
}

html.dark .text-slate-600 {
  color: #cbd5e1 !important; /* slate-300 */
}

html.dark .text-slate-500 {
  color: #94a3b8 !important; /* slate-400 */
}

html.dark .hover\:bg-slate-50:hover {
  background-color: #1e293b !important;
}

html.dark .hover\:bg-slate-100:hover {
  background-color: #334155 !important;
}

html.dark a {
  color: #60a5fa !important; /* blue-400 */
}

html.dark a:hover {
  color: #93c5fd !important; /* blue-300 */
}

/* Dark mode form elements */
html.dark input,
html.dark textarea,
html.dark select {
  background-color: #1e293b !important; /* slate-800 */
  border-color: #334155 !important; /* slate-700 */
  color: #e2e8f0 !important; /* slate-200 */
}

html.dark input:focus,
html.dark textarea:focus,
html.dark select:focus {
  border-color: #60a5fa !important;
  outline-color: #60a5fa !important;
}

html.dark input::placeholder,
html.dark textarea::placeholder {
  color: #64748b !important; /* slate-500 */
}

/* Dark mode buttons */
html.dark button {
  color: #e2e8f0;
}

html.dark .bg-sky-600 {
  background-color: #3b82f6 !important; /* blue-500 */
}

html.dark .bg-sky-600:hover {
  background-color: #2563eb !important; /* blue-600 */
}

html.dark .bg-slate-900 {
  background-color: #1e293b !important;
}

html.dark .bg-slate-900:hover {
  background-color: #334155 !important;
}

/* White text elements in dark mode */
html.dark .text-white {
  color: #ffffff !important;
}

/* Small RTL helpers */
[dir="rtl"] .rtl-flip {
  transform: scaleX(-1);
}

/* ============================================
   MOBILE-FIRST RESPONSIVE STYLES
   ============================================ */

/* Touch-friendly tap targets (minimum 44px) */
.mobile-nav-link,
button,
.btn,
input[type="submit"],
input[type="button"],
select {
  min-height: 44px;
}

/* Mobile form elements */
@media (max-width: 639px) {
  input,
  textarea,
  select {
    font-size: 16px !important; /* Prevents iOS zoom on focus */
    padding: 0.75rem !important;
    min-height: 48px;
  }

  /* Larger buttons on mobile */
  button,
  .btn,
  input[type="submit"],
  input[type="button"] {
    padding: 0.75rem 1rem !important;
    font-size: 1rem !important;
  }

  /* Full-width form elements on mobile */
  .mobile-full-width {
    width: 100% !important;
  }

  /* Stack form groups vertically - but NOT header elements */
  .form-group,
  main .flex.gap-2,
  main .flex.gap-3,
  main .flex.gap-4,
  section .flex.gap-2,
  section .flex.gap-3,
  section .flex.gap-4 {
    flex-direction: column;
  }

  /* Keep header elements horizontal */
  header .flex,
  header .flex.gap-2 {
    flex-direction: row !important;
  }

  /* Reduce padding on mobile */
  .px-4 {
    padding-left: 1rem !important;
    padding-right: 1rem !important;
  }

  .py-6 {
    padding-top: 1rem !important;
    padding-bottom: 1rem !important;
  }

  /* Card adjustments */
  .rounded-xl {
    border-radius: 0.75rem !important;
  }

  /* Table responsiveness */
  table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Smaller headings on mobile */
  h1, .text-2xl {
    font-size: 1.5rem !important;
  }

  h2, .text-xl {
    font-size: 1.25rem !important;
  }

  h3, .text-lg {
    font-size: 1.125rem !important;
  }
}

/* Small tablets and large phones (640px - 767px) */
@media (min-width: 640px) and (max-width: 767px) {
  .grid-cols-2 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  input,
  textarea,
  select {
    font-size: 16px !important;
  }
}

/* Medium devices - tablets (768px+) */
@media (min-width: 768px) {
  /* Desktop navigation is shown, mobile menu hidden */
  .mobile-menu {
    display: none !important;
  }
}

/* Mobile menu animation */
.mobile-menu {
  transition: max-height 0.2s ease-out, opacity 0.2s ease-out;
}

.mobile-menu.hidden {
  max-height: 0;
  opacity: 0;
  overflow: hidden;
}

.mobile-menu:not(.hidden) {
  max-height: 500px;
  opacity: 1;
}

/* Card grid responsive */
.card-grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: 1fr;
}

@media (min-width: 640px) {
  .card-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (min-width: 1024px) {
  .card-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

/* Responsive flex utilities */
@media (max-width: 639px) {
  .sm\:flex-row {
    flex-direction: column !important;
  }

  .sm\:items-start {
    align-items: flex-start !important;
  }

  .sm\:w-full {
    width: 100% !important;
  }

  .sm\:text-center {
    text-align: center !important;
  }

  /* Hide on mobile */
  .sm\:hidden {
    display: none !important;
  }

  /* Stack buttons on mobile */
  .button-group {
    flex-direction: column;
    width: 100%;
  }

  .button-group > * {
    width: 100%;
  }
}

/* Dashboard stats cards */
.stats-grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(2, 1fr);
}

@media (min-width: 768px) {
  .stats-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

/* Modal responsiveness */
@media (max-width: 639px) {
  .modal-content,
  [class*="max-w-md"],
  [class*="max-w-lg"],
  [class*="max-w-xl"] {
    max-width: calc(100vw - 2rem) !important;
    margin: 1rem !important;
  }
}

/* Table card style on mobile */
@media (max-width: 639px) {
  .responsive-table {
    display: block;
  }

  .responsive-table thead {
    display: none;
  }

  .responsive-table tbody {
    display: block;
  }

  .responsive-table tr {
    display: block;
    margin-bottom: 1rem;
    padding: 1rem;
    background: white;
    border-radius: 0.5rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  }

  html.dark .responsive-table tr {
    background: #1e293b;
  }

  .responsive-table td {
    display: flex;
    justify-content: space-between;
    padding: 0.5rem 0;
    border-bottom: 1px solid #e2e8f0;
  }

  html.dark .responsive-table td {
    border-bottom-color: #334155;
  }

  .responsive-table td:last-child {
    border-bottom: none;
  }

  .responsive-table td::before {
    content: attr(data-label);
    font-weight: 600;
    margin-right: 1rem;
  }
}

/* Safe area insets for notched phones */
@supports (padding: max(0px)) {
  header {
    padding-left: max(1rem, env(safe-area-inset-left));
    padding-right: max(1rem, env(safe-area-inset-right));
  }

  main {
    padding-left: max(1rem, env(safe-area-inset-left));
    padding-right: max(1rem, env(safe-area-inset-right));
  }

  footer {
    padding-left: max(1rem, env(safe-area-inset-left));
    padding-right: max(1rem, env(safe-area-inset-right));
    padding-bottom: max(0.75rem, env(safe-area-inset-bottom));
  }
}

/* Fixed footer styles */
footer {
  transition: box-shadow 0.3s ease;
}

footer.fixed {
  box-shadow: 0 -4px 20px -5px rgba(0, 0, 0, 0.1);
}

html.dark footer.fixed {
  box-shadow: 0 -4px 20px -5px rgba(0, 0, 0, 0.3);
}

/* Improved scrollbar for touch */
@media (pointer: coarse) {
  ::-webkit-scrollbar {
    width: 4px;
    height: 4px;
  }

  ::-webkit-scrollbar-thumb {
    background: #94a3b8;
    border-radius: 4px;
  }
}

/* Prevent text selection on interactive elements */
button,
.nav-link,
.mobile-nav-link {
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

/* ============================================
   ANIMATIONS & VISUAL EFFECTS
   ============================================ */

/* Hide scrollbar for horizontal nav */
.scrollbar-hide {
  -ms-overflow-style: none;
  scrollbar-width: none;
}
.scrollbar-hide::-webkit-scrollbar {
  display: none;
}

/* Base transitions for all interactive elements */
a,
button,
input,
select,
textarea,
.nav-link,
.mobile-nav-link {
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Card hover effects */
section,
.rounded-2xl {
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}

section:hover,
.card-hover:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
}

html.dark section:hover,
html.dark .card-hover:hover {
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.3), 0 8px 10px -6px rgba(0, 0, 0, 0.2);
}

/* Button press effect */
button:active,
.btn:active,
input[type="submit"]:active {
  transform: scale(0.97);
}

/* Primary button gradient */
.bg-sky-600 {
  background: linear-gradient(135deg, #0ea5e9 0%, #0284c7 100%) !important;
  box-shadow: 0 4px 14px 0 rgba(14, 165, 233, 0.35);
}

.bg-sky-600:hover {
  background: linear-gradient(135deg, #38bdf8 0%, #0ea5e9 100%) !important;
  box-shadow: 0 6px 20px 0 rgba(14, 165, 233, 0.45);
}

/* Dark button gradient */
.bg-slate-900 {
  background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%) !important;
  box-shadow: 0 4px 14px 0 rgba(15, 23, 42, 0.25);
}

.bg-slate-900:hover {
  background: linear-gradient(135deg, #334155 0%, #1e293b 100%) !important;
  box-shadow: 0 6px 20px 0 rgba(15, 23, 42, 0.35);
}

/* Input focus glow */
input:focus,
textarea:focus,
select:focus {
  box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.15);
  transform: translateY(-1px);
}

html.dark input:focus,
html.dark textarea:focus,
html.dark select:focus {
  box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.2);
}

/* Link hover underline animation */
a.hover-underline {
  position: relative;
}

a.hover-underline::after {
  content: '';
  position: absolute;
  width: 0;
  height: 2px;
  bottom: -2px;
  left: 0;
  background-color: currentColor;
  transition: width 0.3s ease;
}

a.hover-underline:hover::after {
  width: 100%;
}

/* Nav link active indicator */
.nav-link {
  position: relative;
}

.nav-link::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 50%;
  width: 0;
  height: 2px;
  background: linear-gradient(90deg, #0ea5e9, #38bdf8);
  transition: width 0.3s ease, left 0.3s ease;
  border-radius: 2px;
}

.nav-link:hover::after {
  width: 80%;
  left: 10%;
}

/* Mobile nav link tap feedback */
.mobile-nav-link:active {
  transform: scale(0.95);
  background-color: rgba(14, 165, 233, 0.2) !important;
}

/* Fade in animation */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.fade-in {
  animation: fadeIn 0.4s ease-out forwards;
}

/* Slide down animation for mobile menu */
@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.mobile-menu:not(.hidden) {
  animation: slideDown 0.25s ease-out;
}

/* Pulse animation for notifications */
@keyframes pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}

.animate-pulse {
  animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

/* Spin animation for loading */
@keyframes spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

.animate-spin {
  animation: spin 1s linear infinite;
}

/* Bounce animation */
@keyframes bounce {
  0%, 100% {
    transform: translateY(-5%);
    animation-timing-function: cubic-bezier(0.8, 0, 1, 1);
  }
  50% {
    transform: translateY(0);
    animation-timing-function: cubic-bezier(0, 0, 0.2, 1);
  }
}

.animate-bounce {
  animation: bounce 1s infinite;
}

/* Scale in animation for modals */
@keyframes scaleIn {
  from {
    opacity: 0;
    transform: scale(0.9);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.scale-in {
  animation: scaleIn 0.2s ease-out forwards;
}

/* Shimmer loading effect */
@keyframes shimmer {
  0% {
    background-position: -200% 0;
  }
  100% {
    background-position: 200% 0;
  }
}

.shimmer {
  background: linear-gradient(90deg, #f1f5f9 25%, #e2e8f0 50%, #f1f5f9 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
}

html.dark .shimmer {
  background: linear-gradient(90deg, #1e293b 25%, #334155 50%, #1e293b 75%);
  background-size: 200% 100%;
}

/* Ripple effect for buttons */
.ripple {
  position: relative;
  overflow: hidden;
}

.ripple::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
  background: rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  transition: width 0.6s ease, height 0.6s ease;
}

.ripple:active::before {
  width: 300px;
  height: 300px;
}

/* Glassmorphism effect */
.glass {
  background: rgba(255, 255, 255, 0.7);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.3);
}

html.dark .glass {
  background: rgba(30, 41, 59, 0.7);
  border: 1px solid rgba(51, 65, 85, 0.3);
}

/* Gradient text */
.gradient-text {
  background: linear-gradient(135deg, #0ea5e9 0%, #8b5cf6 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* Glow effect for primary elements */
.glow {
  box-shadow: 0 0 20px rgba(14, 165, 233, 0.4);
}

html.dark .glow {
  box-shadow: 0 0 20px rgba(96, 165, 250, 0.3);
}

/* Smooth page transitions */
main {
  animation: fadeIn 0.3s ease-out;
}

/* Header shadow on scroll (controlled by JS) */
header {
  transition: box-shadow 0.3s ease;
}

header.scrolled {
  box-shadow: 0 4px 20px -5px rgba(0, 0, 0, 0.1);
}

html.dark header.scrolled {
  box-shadow: 0 4px 20px -5px rgba(0, 0, 0, 0.3);
}

/* Logo hover effect */
header a.logo-link img,
header a.logo-link span.inline-flex {
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}

header a.logo-link:hover img,
header a.logo-link:hover span.inline-flex {
  transform: scale(1.05) rotate(-3deg);
  box-shadow: 0 4px 15px rgba(14, 165, 233, 0.3);
}

/* Staggered animation for list items */
.stagger-item {
  opacity: 0;
  animation: fadeIn 0.4s ease-out forwards;
}

.stagger-item:nth-child(1) { animation-delay: 0.05s; }
.stagger-item:nth-child(2) { animation-delay: 0.1s; }
.stagger-item:nth-child(3) { animation-delay: 0.15s; }
.stagger-item:nth-child(4) { animation-delay: 0.2s; }
.stagger-item:nth-child(5) { animation-delay: 0.25s; }
.stagger-item:nth-child(6) { animation-delay: 0.3s; }
.stagger-item:nth-child(7) { animation-delay: 0.35s; }
.stagger-item:nth-child(8) { animation-delay: 0.4s; }

/* Tooltip styles */
.tooltip {
  position: relative;
}

.tooltip::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%) translateY(-5px);
  padding: 0.5rem 0.75rem;
  background: #0f172a;
  color: white;
  font-size: 0.75rem;
  border-radius: 0.5rem;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.tooltip:hover::after {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* Badge/notification dot */
.badge {
  position: relative;
}

.badge::after {
  content: '';
  position: absolute;
  top: -2px;
  right: -2px;
  width: 8px;
  height: 8px;
  background: #ef4444;
  border-radius: 50%;
  border: 2px solid white;
}

html.dark .badge::after {
  border-color: #1e293b;
}

/* Success/error flash animation */
@keyframes flash {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.6;
  }
}

.flash-success {
  animation: flash 0.5s ease;
  background-color: rgba(16, 185, 129, 0.1) !important;
}

.flash-error {
  animation: flash 0.5s ease;
  background-color: rgba(239, 68, 68, 0.1) !important;
}

/* Skeleton loading */
.skeleton {
  background: linear-gradient(90deg, #e2e8f0 25%, #f1f5f9 50%, #e2e8f0 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: 0.5rem;
}

html.dark .skeleton {
  background: linear-gradient(90deg, #334155 25%, #475569 50%, #334155 75%);
  background-size: 200% 100%;
}

/* Floating action button */
.fab {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 6px 20px rgba(14, 165, 233, 0.4);
  transition: transform 0.3s ease, box-shadow 0.3s ease;
  z-index: 50;
}

.fab:hover {
  transform: scale(1.1);
  box-shadow: 0 8px 25px rgba(14, 165, 233, 0.5);
}

.fab:active {
  transform: scale(0.95);
}

/* Progress bar animation */
@keyframes progressFill {
  from {
    width: 0;
  }
}

.progress-bar {
  animation: progressFill 1s ease-out forwards;
}

/* Theme transition */
html {
  transition: background-color 0.3s ease, color 0.3s ease;
}

html.dark {
  transition: background-color 0.3s ease, color 0.3s ease;
}

/* Smooth scrolling */
html {
  scroll-behavior: smooth;
}

/* Focus visible styles for accessibility */
:focus-visible {
  outline: 2px solid #0ea5e9;
  outline-offset: 2px;
}

html.dark :focus-visible {
  outline-color: #60a5fa;
}

/* Print styles - disable animations */
@media print {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}

/* Back button for file viewing (especially on mobile) */
.file-back-button {
  position: fixed;
  top: 1rem;
  left: 1rem;
  z-index: 9999;
  background: rgba(0, 0, 0, 0.8);
  color: white;
  padding: 0.75rem 1.5rem;
  border-radius: 0.5rem;
  font-weight: 600;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  cursor: pointer;
  border: none;
  display: none;
}

.file-back-button:hover {
  background: rgba(0, 0, 0, 0.9);
}

@media (max-width: 768px) {
  .file-back-button {
    display: block;
  }
}

