/**
 * Novel Forge - Custom Styles
 * Works alongside Tailwind CDN
 */

/* ==================== Design Tokens ==================== */
:root {
  /* Z-index layers */
  --z-dropdown: 50;
  --z-sticky: 55;
  --z-modal-backdrop: 60;
  --z-modal: 70;
  --z-toast: 80;
  --z-loading: 90;
}

/* ==================== Alpine.js Cloak ==================== */
/* Hide elements with x-cloak until Alpine initializes */
[x-cloak] {
  display: none !important;
}

/* ==================== Base Styles ==================== */
html {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

/* Improved focus styles for accessibility */
:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px #9A8A70, 0 0 0 4px white;
}

/* ==================== Component Styles ==================== */

/* Sidebar navigation items */
.sidebar-item {
  transition: all 0.2s ease;
}

.sidebar-item:hover {
  background-color: rgba(139, 115, 85, 0.1);
}

.sidebar-item.active {
  background-color: rgba(139, 115, 85, 0.15);
  color: #8B7355;
  font-weight: 500;
}

/* Primary button gradient */
.btn-primary {
  background: linear-gradient(135deg, #8B7355 0%, #A08060 100%);
  color: white;
  transition: all 0.2s ease;
}

.btn-primary:hover:not(:disabled) {
  box-shadow: 0 4px 12px rgba(139, 115, 85, 0.3);
  transform: translateY(-1px);
}

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Card component */
.card {
  background: white;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(74, 64, 51, 0.08);
}

.card-hover {
  background: white;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(74, 64, 51, 0.08);
  transition: box-shadow 0.2s ease;
}

.card-hover:hover {
  box-shadow: 0 4px 16px rgba(74, 64, 51, 0.12);
}

/* ==================== Responsive Table ==================== */
.table-responsive {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* Mobile card view for tables */
@media (max-width: 768px) {
  .table-cards thead {
    display: none;
  }

  .table-cards tbody {
    display: block;
  }

  .table-cards tr {
    display: block;
    margin-bottom: 1rem;
    padding: 1rem;
    background: white;
    border-radius: 0.75rem;
    box-shadow: 0 2px 8px rgba(74, 64, 51, 0.08);
  }

  .table-cards td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0;
    border-bottom: 1px solid #E8E0D4;
  }

  .table-cards td:last-child {
    border-bottom: none;
  }

  .table-cards td::before {
    content: attr(data-label);
    font-weight: 500;
    color: #6B7280;
    font-size: 0.875rem;
    flex-shrink: 0;
    margin-right: 1rem;
  }

  .table-cards td[data-label="操作"] {
    justify-content: flex-end;
    padding-top: 0.75rem;
  }

  .table-cards td[data-label="操作"]::before {
    display: none;
  }
}

/* ==================== HTMX Styles ==================== */
.htmx-indicator {
  opacity: 0;
  transition: opacity 200ms ease-in;
}

.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator {
  opacity: 1;
}

/* Page transitions */
.htmx-swapping {
  opacity: 0;
  transition: opacity 150ms ease-out;
}

.htmx-settling {
  opacity: 0;
}

.htmx-added {
  animation: fadeIn 200ms ease-in forwards;
}

/* Disable pointer events during request */
.htmx-request {
  pointer-events: none;
}

/* ==================== Animations ==================== */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes loading-bar {
  0% {
    transform: translateX(-100%);
  }
  50% {
    transform: translateX(0%);
  }
  100% {
    transform: translateX(100%);
  }
}

.animate-loading-bar {
  animation: loading-bar 1.5s ease-in-out infinite;
}

.animate-fade-in {
  animation: fadeIn 200ms ease-in forwards;
}

/* Spin animation for loading states */
@keyframes spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

.animate-spin {
  animation: spin 1s linear infinite;
}

/* ==================== Skeleton Loading ==================== */
.skeleton {
  background: linear-gradient(90deg, #E8E0D4 25%, #F5F0E6 50%, #E8E0D4 75%);
  background-size: 200% 100%;
  animation: skeleton-loading 1.5s ease-in-out infinite;
  border-radius: 0.25rem;
}

@keyframes skeleton-loading {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

.skeleton-text {
  height: 1rem;
  width: 100%;
}

.skeleton-text-sm {
  height: 0.75rem;
  width: 75%;
}

.skeleton-text-lg {
  height: 1.25rem;
  width: 60%;
}

.skeleton-avatar {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 9999px;
}

.skeleton-button {
  height: 2.5rem;
  width: 6rem;
  border-radius: 0.5rem;
}

/* ==================== Scrollbar ==================== */
.scrollbar-thin {
  scrollbar-width: thin;
  scrollbar-color: #D4C9B8 transparent;
}

.scrollbar-thin::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

.scrollbar-thin::-webkit-scrollbar-track {
  background: transparent;
}

.scrollbar-thin::-webkit-scrollbar-thumb {
  background-color: #D4C9B8;
  border-radius: 3px;
}

/* ==================== Utilities ==================== */
/* Line clamp utilities */
.line-clamp-1 {
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.line-clamp-2 {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.line-clamp-3 {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Touch target helper */
.touch-target {
  position: relative;
}

.touch-target::after {
  content: '';
  position: absolute;
  inset: -6px;
}

/* ==================== Print Styles ==================== */
@media print {
  .no-print {
    display: none !important;
  }
}
