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

/* UI Pagination Component Styling (for Pagy) */
.ui-pagination .pagy {
  @apply flex items-center space-x-2;
}

.ui-pagination .pagy a,
.ui-pagination .pagy span {
  @apply inline-flex items-center justify-center px-3 py-2 text-sm font-medium rounded-md border transition-all duration-200 shadow-sm;
}

.ui-pagination .pagy a {
  @apply text-slate-700 bg-white border-slate-300 hover:bg-slate-50 hover:text-slate-900 hover:border-slate-400 hover:shadow-md;
}

.ui-pagination .pagy span.current {
  @apply bg-iihs-700 text-white border-iihs-700 shadow-md;
}

.ui-pagination .pagy span.gap {
  @apply px-3 py-2 text-sm font-medium text-slate-500 border-0 bg-transparent shadow-none;
}

/* Disabled state for pagination buttons (links without href) */
.ui-pagination .pagy a:not([href]) {
  @apply text-slate-400 bg-slate-100 border-slate-200 cursor-not-allowed;
}

@layer base {
  html {
    @apply text-slate-900;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
  }

  body {
    @apply bg-slate-50;
  }

  h1, h2, h3, h4, h5, h6 {
    @apply font-semibold tracking-tight;
  }

  h1 {
    @apply text-3xl sm:text-4xl;
  }

  h2 {
    @apply text-2xl sm:text-3xl;
  }

  h3 {
    @apply text-xl sm:text-2xl;
  }

  /* Override Tailwind's list reset for Trix editor */
  trix-editor ul {
    list-style-type: disc !important;
    margin-left: 1.5rem !important;
    padding-left: 0 !important;
  }

  trix-editor ol {
    list-style-type: decimal !important;
    margin-left: 1.5rem !important;
    padding-left: 0 !important;
  }

  trix-editor li {
    display: list-item !important;
  }
}

@layer components {
  .btn {
    @apply inline-flex items-center justify-center rounded-md border border-transparent px-4 py-2 text-sm font-medium shadow-sm transition-all duration-150 focus:outline-none focus:ring-2 focus:ring-offset-2;
  }

  .btn:active {
    @apply transform scale-95 shadow-inner;
  }

  .btn-loading {
    @apply cursor-not-allowed opacity-75;
    position: relative;
  }

  .btn-loading .btn-text {
    @apply opacity-0;
  }

  .btn-loading .btn-spinner {
    @apply opacity-100;
  }

  .btn-spinner {
    @apply absolute left-1/2 top-1/2 transform -translate-x-1/2 -translate-y-1/2 opacity-0 transition-all duration-200;
    animation: spin 1s linear infinite;
  }

  @keyframes spin {
    from { transform: translate(-50%, -50%) rotate(0deg); }
    to { transform: translate(-50%, -50%) rotate(360deg); }
  }

  /* File upload area enhancements */
  .file-upload-area {
    @apply border-2 border-dashed border-slate-300 rounded-lg p-6 text-center hover:border-iihs-400 transition-colors;
  }

  .file-upload-area.drag-over {
    @apply border-iihs-500 bg-iihs-50;
  }

  .btn-primary {
    @apply bg-iihs-700 text-white hover:bg-iihs-800 focus-visible:ring-iihs-500;
  }

  .btn-secondary {
    @apply border-slate-300 bg-white text-slate-700 hover:bg-slate-50 focus:ring-blue-500;
  }

  .btn-outline {
    @apply border-slate-300 bg-transparent text-slate-700 hover:bg-slate-50 focus:ring-blue-500;
  }

  .btn-danger {
    @apply bg-red-600 text-white hover:bg-red-700 focus:ring-red-500;
  }

  .btn-sm {
    @apply px-3 py-1.5 text-xs;
  }

  .btn-lg {
    @apply px-6 py-3 text-base;
  }

  .input {
    @apply w-full rounded-md border border-slate-200 bg-white px-3 py-2 text-sm text-slate-900 placeholder-slate-400 focus:border-blue-500 focus:outline-none focus:ring-1 focus:ring-blue-500;
  }

  .card {
    @apply rounded-lg border border-slate-200 bg-white shadow-sm;
  }

  .auth-layout {
    @apply flex flex-col items-center justify-center bg-iihs-700 px-8 py-10 text-white;
  }

  .auth-card {
    @apply w-full max-w-md rounded-lg bg-white p-8 shadow-lg;
  }

  .auth-header {
    @apply mb-6 text-center;
  }

  .auth-form {
    @apply space-y-4;
  }

  /* Specific login form input styling */
  .auth-form input[type="email"],
  .auth-form input[type="password"] {
    color: #0f172a !important; /* slate-900 */
    background-color: #ffffff !important;
    -webkit-text-fill-color: #0f172a !important; /* For Safari */
  }

  .auth-form input[type="email"]:focus,
  .auth-form input[type="password"]:focus {
    color: #0f172a !important; /* slate-900 */
    -webkit-text-fill-color: #0f172a !important; /* For Safari */
  }

  .auth-form input::placeholder {
    color: #94a3b8 !important; /* slate-400 */
    opacity: 1 !important;
  }

  .form-group {
    @apply space-y-1;
  }

  .form-label {
    @apply block text-sm font-medium text-slate-700;
  }

  .form-input {
    @apply w-full rounded-md border border-slate-200 bg-white px-3 py-2 text-sm text-slate-900 placeholder-slate-400 focus:border-iihs-700 focus:outline-none focus:ring-1 focus:ring-iihs-700;
  }

  .form-textarea {
    @apply w-full rounded-md border border-slate-200 bg-white px-3 py-2 text-sm text-slate-900 placeholder-slate-400 focus:border-iihs-700 focus:outline-none focus:ring-1 focus:ring-iihs-700;
  }

  .form-select {
    @apply w-full rounded-md border border-slate-200 bg-white px-3 py-2 text-sm text-slate-900 focus:border-iihs-700 focus:outline-none focus:ring-1 focus:ring-iihs-700;
  }

  .form-error {
    @apply text-sm text-red-600;
  }

  .alert {
    @apply rounded-md p-4;
  }

  .alert-success {
    @apply bg-green-50 text-green-800;
  }

  .alert-error {
    @apply bg-red-50 text-red-800;
  }

  .alert-warning {
    @apply bg-yellow-50 text-yellow-800;
  }

  .alert-info {
    @apply bg-blue-50 text-blue-800;
  }

  .stats-card {
    @apply rounded-lg border border-slate-200 bg-white p-6 shadow-sm;
  }

  .main-layout {
    @apply flex h-screen overflow-hidden;
  }

  .main-content {
    @apply flex flex-1 flex-col overflow-hidden;
  }

  .page-content {
    @apply flex-1 overflow-auto bg-slate-50 p-6;
  }

  .page-container {
    @apply mx-auto max-w-7xl;
  }

  /* Navigation Styles */
  .nav-link {
    @apply flex items-center rounded-md px-3 py-2 text-sm font-medium transition-colors text-slate-600 hover:bg-slate-100 hover:text-slate-900;
    box-shadow: none !important;
    border: none !important;
  }

  .nav-link-active {
    @apply bg-iihs-50 text-iihs-700;
    box-shadow: none !important;
  }

  .nav-link i {
    @apply flex-shrink-0;
  }

  /* Navigation section styles */
  .nav-section-header {
    @apply px-3 py-2 border-b border-slate-200;
  }

  .nav-section-title {
    @apply text-xs font-semibold text-slate-500 uppercase tracking-wider;
  }

  .nav-link-sub {
    @apply ml-2 pl-2 border-l border-slate-200;
    box-shadow: none !important;
    border-right: none !important;
    border-top: none !important;
    border-bottom: none !important;
  }

  .nav-link-sub:hover {
    @apply bg-slate-50 border-l-slate-300;
    box-shadow: none !important;
  }

  .nav-link-sub.nav-link-active {
    @apply bg-iihs-50 text-iihs-900 border-l-iihs-600 border-l-2;
    box-shadow: none !important;
    border-right: none !important;
    border-top: none !important;
    border-bottom: none !important;
  }

  /* Additional utility classes */
  .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;
  }

  .sidebar-item {
    @apply flex items-center px-3 py-2 text-sm font-medium rounded-md transition-colors;
  }

  .sidebar-item.active {
    @apply bg-iihs-50 text-iihs-700;
  }

  .sidebar-item:hover {
    @apply bg-slate-100 text-slate-900;
  }

  /* File Upload Component Styles */
  .file-drop-zone {
    @apply relative;
  }

  .file-drop-zone.drag-over .file-upload-area {
    @apply border-iihs-300 bg-iihs-50;
  }

  .file-upload-area {
    @apply mt-1 flex justify-center px-6 pt-5 pb-6 border-2 border-gray-300 border-dashed rounded-md transition-colors;
  }

  .file-preview {
    @apply mt-1 p-4 bg-slate-50 rounded-md border border-slate-200;
  }

  .file-preview .file-info {
    @apply flex items-center justify-between;
  }

  .file-preview .file-details {
    @apply flex items-center space-x-3;
  }

  .file-preview .file-icon {
    @apply text-2xl;
  }

  .file-preview .file-name {
    @apply text-sm font-medium text-slate-900;
  }

  .file-preview .file-size {
    @apply text-xs text-slate-500;
  }

  .file-preview .file-actions {
    @apply flex space-x-2;
  }

  .remove-file {
    @apply text-red-600 hover:text-red-800 text-sm cursor-pointer;
  }

  /* Drag and drop enhancement */
  .file-drop-zone.drag-over {
    @apply ring-2 ring-iihs-500 ring-offset-2;
  }

  /* Clickable table rows */
  .job-row {
    @apply cursor-pointer select-none;
  }

  .job-row:hover {
    @apply bg-slate-50;
  }

  .job-row:active {
    @apply bg-slate-100 transform scale-[0.999];
  }

  /* Rich Text Editor Styles */
  .rich-text-field {
    @apply border border-slate-200 rounded-md;
  }

  .rich-text-field trix-editor {
    @apply min-h-[120px] p-3 focus:border-iihs-700 focus:ring-1 focus:ring-iihs-700 focus:outline-none;
  }

  /* Trix Editor Content Styling */
  trix-editor {
    line-height: 1.6;
  }

  trix-editor ul,
  trix-editor .attachment-gallery > .attachment {
    list-style-type: disc !important;
    margin-left: 1.5rem !important;
    margin-bottom: 1rem !important;
    padding-left: 0 !important;
  }

  trix-editor ol {
    list-style-type: decimal !important;
    margin-left: 1.5rem !important;
    margin-bottom: 1rem !important;
    padding-left: 0 !important;
  }

  trix-editor li {
    margin-bottom: 0.25rem !important;
    padding-left: 0.25rem !important;
    display: list-item !important;
  }

  trix-editor ul li {
    list-style-type: disc !important;
  }

  trix-editor ol li {
    list-style-type: decimal !important;
  }

  /* Ensure lists are visible */
  trix-editor ul,
  trix-editor ol {
    display: block !important;
  }

  trix-editor blockquote {
    border-left: 4px solid #e2e8f0;
    padding-left: 1rem;
    margin: 1rem 0;
    font-style: italic;
    color: #64748b;
  }

  trix-editor pre {
    background-color: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 0.375rem;
    padding: 1rem;
    margin: 1rem 0;
    overflow-x: auto;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 0.875rem;
  }

  trix-editor h1 {
    font-size: 1.5rem;
    font-weight: 600;
    margin: 1rem 0 0.5rem 0;
  }

  trix-editor strong {
    font-weight: 600;
  }

  trix-editor em {
    font-style: italic;
  }

  trix-editor a {
    color: var(--iihs-700);
    text-decoration: underline;
  }

  trix-editor a:hover {
    color: var(--iihs-800);
  }

  /* Trix Toolbar Styling */
  trix-toolbar {
    border-bottom: 1px solid #e2e8f0;
    padding: 0.75rem;
  }

  trix-toolbar .trix-button-group {
    margin-right: 0.75rem;
    border-radius: 0.375rem;
    overflow: hidden;
  }

  trix-toolbar .trix-button {
    background: white;
    border: 1px solid #e2e8f0;
    color: #475569;
    padding: 0.5rem;
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.15s ease;
  }

  trix-toolbar .trix-button:hover {
    background: #f8fafc;
    color: #334155;
  }

  trix-toolbar .trix-button.trix-active {
    background: var(--iihs-700);
    color: white;
    border-color: var(--iihs-700);
  }

  trix-toolbar .trix-button:not(:first-child) {
    border-left: none;
  }

  trix-toolbar .trix-button-group:last-child {
    margin-right: 0;
  }

  /* Search Input Icon Fix */
  .search-input-container {
    @apply relative;
  }

  .search-input-container .search-icon {
    @apply absolute left-3 top-1/2 transform -translate-y-1/2 text-slate-400 pointer-events-none z-10;
  }

  .search-input-container input {
    @apply pl-10;
  }

  /* Custom select styling to prevent arrow overlap */
  .custom-select {
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='m6 8 4 4 4-4'/%3e%3c/svg%3e");
    background-position: right 0.5rem center;
    background-repeat: no-repeat;
    background-size: 1.5em 1.5em;
    padding-right: 2.5rem;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
  }

  /* Ensure form inputs have proper text visibility */
  input[type="email"],
  input[type="password"],
  input[type="text"],
  textarea,
  select {
    color: #0f172a !important; /* slate-900 */
    background-color: #ffffff !important;
  }

  input[type="email"]:focus,
  input[type="password"]:focus,
  input[type="text"]:focus,
  textarea:focus,
  select:focus {
    color: #0f172a !important; /* slate-900 */
  }

  /* Ensure placeholder text is visible */
  input::placeholder,
  textarea::placeholder {
    color: #94a3b8 !important; /* slate-400 */
    opacity: 1 !important;
  }
}

/* Custom IIHS color definitions */
:root {
  --iihs-50: #fef7f3;
  --iihs-100: #fde8dc;
  --iihs-200: #fbd5bf;
  --iihs-300: #f7b896;
  --iihs-400: #f19066;
  --iihs-500: #ed7142;
  --iihs-600: #de5a2a;
  --iihs-700: #881803;
  --iihs-800: #a0461f;
  --iihs-900: #83391c;
  --iihs-950: #471b0b;
}

/* Tailwind color utilities for IIHS brand */
.bg-iihs-50 { background-color: var(--iihs-50); }
.bg-iihs-100 { background-color: var(--iihs-100); }
.bg-iihs-200 { background-color: var(--iihs-200); }
.bg-iihs-300 { background-color: var(--iihs-300); }
.bg-iihs-400 { background-color: var(--iihs-400); }
.bg-iihs-500 { background-color: var(--iihs-500); }
.bg-iihs-600 { background-color: var(--iihs-600); }
.bg-iihs-700 { background-color: var(--iihs-700); }
.bg-iihs-800 { background-color: var(--iihs-800); }
.bg-iihs-900 { background-color: var(--iihs-900); }
.bg-iihs-950 { background-color: var(--iihs-950); }

.text-iihs-50 { color: var(--iihs-50); }
.text-iihs-100 { color: var(--iihs-100); }
.text-iihs-200 { color: var(--iihs-200); }
.text-iihs-300 { color: var(--iihs-300); }
.text-iihs-400 { color: var(--iihs-400); }
.text-iihs-500 { color: var(--iihs-500); }
.text-iihs-600 { color: var(--iihs-600); }
.text-iihs-700 { color: var(--iihs-700); }
.text-iihs-800 { color: var(--iihs-800); }
.text-iihs-900 { color: var(--iihs-900); }
.text-iihs-950 { color: var(--iihs-950); }

.border-iihs-50 { border-color: var(--iihs-50); }
.border-iihs-100 { border-color: var(--iihs-100); }
.border-iihs-200 { border-color: var(--iihs-200); }
.border-iihs-300 { border-color: var(--iihs-300); }
.border-iihs-400 { border-color: var(--iihs-400); }
.border-iihs-500 { border-color: var(--iihs-500); }
.border-iihs-600 { border-color: var(--iihs-600); }
.border-iihs-700 { border-color: var(--iihs-700); }
.border-iihs-800 { border-color: var(--iihs-800); }
.border-iihs-900 { border-color: var(--iihs-900); }
.border-iihs-950 { border-color: var(--iihs-950); }

.ring-iihs-50 { --tw-ring-color: var(--iihs-50); }
.ring-iihs-100 { --tw-ring-color: var(--iihs-100); }
.ring-iihs-200 { --tw-ring-color: var(--iihs-200); }
.ring-iihs-300 { --tw-ring-color: var(--iihs-300); }
.ring-iihs-400 { --tw-ring-color: var(--iihs-400); }
.ring-iihs-500 { --tw-ring-color: var(--iihs-500); }
.ring-iihs-600 { --tw-ring-color: var(--iihs-600); }
.ring-iihs-700 { --tw-ring-color: var(--iihs-700); }
.ring-iihs-800 { --tw-ring-color: var(--iihs-800); }
.ring-iihs-900 { --tw-ring-color: var(--iihs-900); }
.ring-iihs-950 { --tw-ring-color: var(--iihs-950); }


/* Flash Messages / Toast Notifications (bottom-right positioned) */
.flash-message {
  animation: flashMessage 3s forwards;
}

@keyframes flashMessage {
  0% {
    opacity: 0;
    transform: translateX(100%);
  }

  8% {
    opacity: 1;
    transform: translateX(0);
  }

  92% {
    opacity: 1;
    transform: translateX(0);
  }

  100% {
    opacity: 0;
    transform: translateX(100%);
  }
}
