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

@layer components {
  .ts-wrapper .ts-control {
    border: 2px solid #e2e8f0;
    border-radius: 0.75rem;
    padding: 0.625rem 2.5rem 0.625rem 1rem;
    font-size: 0.875rem;
    line-height: 1.25rem;
    background: #fff;
    color: #1e293b;
    cursor: text;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
    font-family: 'Inter', 'Noto Kufi Arabic', sans-serif;
  }

  .ts-wrapper.focus .ts-control,
  .ts-wrapper.dropdown-active .ts-control {
    border-color: #005696;
    box-shadow: 0 0 0 3px rgba(0, 86, 150, 0.2);
    outline: none;
  }

  .ts-wrapper .ts-control > input {
    font-family: 'Inter', 'Noto Kufi Arabic', sans-serif;
    font-size: inherit;
    line-height: inherit;
    color: inherit;
  }

  .ts-wrapper .ts-control > input::placeholder {
    color: #94a3b8;
  }

  .ts-wrapper .ts-control .item {
    color: #1e293b;
  }

  .ts-wrapper .ts-control::after {
    border-color: #94a3b8 transparent transparent transparent;
    border-width: 5px 5px 0 5px;
    margin-top: -2px;
  }

  .ts-wrapper.dropdown-active .ts-control::after {
    border-color: transparent transparent #94a3b8 transparent;
    border-width: 0 5px 5px 5px;
    margin-top: -2px;
  }

  .ts-wrapper.has-items .ts-control > input {
    color: inherit;
  }

  .ts-wrapper .ts-control > input:focus {
    box-shadow: none;
    outline: none;
  }

  .ts-dropdown {
    border: 1px solid #e2e8f0;
    border-radius: 0.75rem;
    background: #fff;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.05);
    margin-top: 4px;
    font-family: 'Inter', 'Noto Kufi Arabic', sans-serif;
    z-index: 100;
  }

  .ts-dropdown .ts-dropdown-content {
    padding: 0.25rem 0;
  }

  .ts-dropdown .ts-option {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    color: #475569;
    cursor: pointer;
    transition: background-color 0.1s ease, color 0.1s ease;
  }

  .ts-dropdown .ts-option.active {
    background-color: #eef6fb;
    color: #005696;
  }

  .ts-dropdown .ts-option.selected {
    background-color: #005696;
    color: #fff;
  }

  .ts-dropdown .ts-option.selected.active {
    background-color: #004a7f;
    color: #fff;
  }

  .ts-dropdown .no-results {
    padding: 0.75rem 1rem;
    font-size: 0.875rem;
    color: #94a3b8;
    font-style: italic;
  }

  .ts-wrapper.disabled .ts-control {
    background: #f8fafc;
    color: #94a3b8;
    cursor: not-allowed;
    opacity: 0.6;
  }

  .ts-wrapper.ts-compact .ts-control {
    padding: 0.375rem 2rem 0.375rem 0.75rem;
    font-size: 0.75rem;
    line-height: 1rem;
    border-radius: 0.5rem;
    border-width: 1px;
  }

  .ts-wrapper.ts-compact .ts-dropdown {
    border-radius: 0.5rem;
  }

  .ts-wrapper.ts-compact .ts-dropdown .ts-option {
    padding: 0.375rem 0.75rem;
    font-size: 0.75rem;
  }

  [dir="rtl"] .ts-wrapper .ts-control {
    padding: 0.625rem 1rem 0.625rem 2.5rem;
  }

  [dir="rtl"] .ts-wrapper.ts-compact .ts-control {
    padding: 0.375rem 0.75rem 0.375rem 2rem;
  }
}

/*
 * TomSelect wrapper reset — placed AFTER @tailwind layers so it beats
 * any utility classes (border, rounded-xl, px-4, etc.) that TomSelect
 * copies from the original <select> to the .ts-wrapper div.
 * Only .ts-control should be visually styled, not the wrapper itself.
 */
.ts-wrapper {
  position: relative !important;
  width: 100% !important;
  border: none !important;
  padding: 0 !important;
  margin: 0 !important;
  background: transparent !important;
  box-shadow: none !important;
  border-radius: 0 !important;
  outline: none !important;
  display: block;
}

.ts-wrapper.ts-compact {
  width: auto !important;
  min-width: 350px !important;
}

.ts-wrapper:focus,
.ts-wrapper:focus-visible,
.ts-wrapper:focus-within {
  border: none !important;
  box-shadow: none !important;
  outline: none !important;
}

/*
 * hh-form-input / hh-form-select
 * Replacement classes applied by bootstrap-to-tailwind.js migration script.
 * Maps: form-control → hh-form-input, form-select → hh-form-select
 */
.hh-form-input,
.hh-form-select {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 2px solid #cbd5e1;
  border-radius: 0.75rem;
  font-size: 0.95rem;
  transition: all 0.2s;
  background: white;
  color: #1e293b;
  font-family: 'Inter', sans-serif;
}

.hh-form-input:focus,
.hh-form-select:focus {
  outline: none;
  border-color: #005696;
  box-shadow: 0 0 0 4px rgba(0, 86, 150, 0.1);
}

textarea.hh-form-input {
  resize: vertical;
  min-height: 120px;
}

select.hh-form-select {
  appearance: none;
  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 8l4 4 4-4'/%3e%3c/svg%3e");
  background-position: right 0.75rem center;
  background-repeat: no-repeat;
  background-size: 1.25em 1.25em;
  padding-right: 2.5rem;
}

/*
 * .form-control / .form-select
 * Bootstrap-compatible aliases used by Django form widgets.
 */
.form-control,
.form-select {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 2px solid #cbd5e1;
  border-radius: 0.75rem;
  font-size: 0.95rem;
  transition: all 0.2s;
  background: white;
  color: #1e293b;
  font-family: 'Inter', sans-serif;
}

.form-control:focus,
.form-select:focus {
  outline: none;
  border-color: #005696;
  box-shadow: 0 0 0 4px rgba(0, 86, 150, 0.1);
}

textarea.form-control {
  resize: vertical;
  min-height: 120px;
}

select.form-select {
  appearance: none;
  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 8l4 4 4-4'/%3e%3c/svg%3e");
  background-position: right 0.75rem center;
  background-repeat: no-repeat;
  background-size: 1.25em 1.25em;
  padding-right: 2.5rem;
}
