/*
 * ChalkyLayout Form Styles
 *
 * Custom styling for Simple Form inputs using Chalky design tokens.
 * These styles provide plug-and-play form components without adding
 * extra classes in your views.
 *
 * Include this file in your application:
 *   @import "chalky_layout/forms";
 */

/* =============================================================================
   FORM CONTAINER
   ============================================================================= */

.chalky-form {
  width: 100%;
}

.chalky-form-group {
  margin-bottom: 1rem;
}

/* =============================================================================
   LABELS
   ============================================================================= */

.chalky-label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--chalky-text-primary);
  margin-bottom: 0.25rem;
}

.chalky-required {
  color: var(--chalky-danger);
  margin-left: 0.125rem;
}

/* =============================================================================
   TEXT INPUTS
   ============================================================================= */

.chalky-input {
  display: block;
  width: 100%;
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  line-height: 1.5;
  color: var(--chalky-text-primary);
  background-color: var(--chalky-surface);
  border: 1px solid var(--chalky-border);
  border-radius: 0.375rem;
  transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
}

.chalky-input::placeholder {
  color: var(--chalky-text-muted);
}

.chalky-input:hover {
  border-color: var(--chalky-border-strong);
}

.chalky-input:focus {
  outline: none;
  border-color: var(--chalky-primary);
  box-shadow: 0 0 0 3px var(--chalky-primary-light);
}

.chalky-input:disabled {
  background-color: var(--chalky-surface-secondary);
  color: var(--chalky-text-muted);
  cursor: not-allowed;
}

/* Error state */
.chalky-input--error,
.chalky-input.chalky-input--error {
  border-color: var(--chalky-danger);
}

.chalky-input--error:focus,
.chalky-input.chalky-input--error:focus {
  border-color: var(--chalky-danger);
  box-shadow: 0 0 0 3px var(--chalky-danger-light);
}

/* Textarea specific */
textarea.chalky-input {
  min-height: 6rem;
  resize: vertical;
}

/* Select specific */
select.chalky-input {
  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.5rem center;
  background-repeat: no-repeat;
  background-size: 1.5em 1.5em;
  padding-right: 2.5rem;
}

/* Date inputs */
input[type="date"].chalky-input,
input[type="datetime-local"].chalky-input,
input[type="time"].chalky-input {
  appearance: none;
}

/* =============================================================================
   RADIO BUTTONS (Collection) - Card Style
   ============================================================================= */

.chalky-radio-group {
  margin-bottom: 1rem;
}

.chalky-radio-options {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

/* Radio collection item - Card style */
.chalky-radio-options .chalky-collection-item {
  display: block;
}

.chalky-radio-options .chalky-collection-item label {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  background-color: var(--chalky-surface);
  border: 1px solid var(--chalky-border);
  border-radius: 0.5rem;
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--chalky-text-primary);
  transition: all 0.15s ease-in-out;
  position: relative;
}

.chalky-radio-options .chalky-collection-item label:hover {
  border-color: var(--chalky-primary);
  background-color: var(--chalky-primary-light);
}

/* Hide native radio */
.chalky-radio-options input[type="radio"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

/* Custom radio indicator */
.chalky-radio-options .chalky-collection-item label::before {
  content: "";
  flex-shrink: 0;
  width: 1.25rem;
  height: 1.25rem;
  border: 2px solid var(--chalky-border-strong);
  border-radius: 50%;
  background-color: var(--chalky-surface);
  transition: all 0.15s ease-in-out;
}

/* Radio checked state - Card highlight */
.chalky-radio-options .chalky-collection-item:has(input[type="radio"]:checked) label {
  border-color: var(--chalky-primary);
  background-color: var(--chalky-primary-light);
}

.chalky-radio-options .chalky-collection-item:has(input[type="radio"]:checked) label::before {
  border-color: var(--chalky-primary);
  border-width: 5px;
}

/* Radio focus state */
.chalky-radio-options .chalky-collection-item:has(input[type="radio"]:focus) label {
  box-shadow: 0 0 0 3px var(--chalky-primary-light);
}

/* =============================================================================
   CHECKBOXES (Collection) - Card Style
   ============================================================================= */

.chalky-checkbox-group {
  margin-bottom: 1rem;
}

.chalky-checkbox-options {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

/* Checkbox collection item - Pill/Tag style */
.chalky-checkbox-options .chalky-collection-item {
  display: inline-block;
}

.chalky-checkbox-options .chalky-collection-item label {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.875rem;
  background-color: var(--chalky-surface);
  border: 1px solid var(--chalky-border);
  border-radius: 2rem;
  cursor: pointer;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--chalky-text-secondary);
  transition: all 0.15s ease-in-out;
  position: relative;
}

.chalky-checkbox-options .chalky-collection-item label:hover {
  border-color: var(--chalky-primary);
  color: var(--chalky-primary);
}

/* Hide native checkbox */
.chalky-checkbox-options input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

/* Custom checkbox indicator */
.chalky-checkbox-options .chalky-collection-item label::before {
  content: "";
  flex-shrink: 0;
  width: 1rem;
  height: 1rem;
  border: 1.5px solid var(--chalky-border-strong);
  border-radius: 0.25rem;
  background-color: var(--chalky-surface);
  transition: all 0.15s ease-in-out;
}

/* Checkbox checked state - Pill highlight */
.chalky-checkbox-options .chalky-collection-item:has(input[type="checkbox"]:checked) label {
  border-color: var(--chalky-primary);
  background-color: var(--chalky-primary-light);
  color: var(--chalky-primary-text);
}

.chalky-checkbox-options .chalky-collection-item:has(input[type="checkbox"]:checked) label::before {
  background-color: var(--chalky-primary);
  border-color: var(--chalky-primary);
  background-image: url("data:image/svg+xml,%3csvg viewBox='0 0 16 16' fill='white' xmlns='http://www.w3.org/2000/svg'%3e%3cpath d='M12.207 4.793a1 1 0 010 1.414l-5 5a1 1 0 01-1.414 0l-2-2a1 1 0 011.414-1.414L6.5 9.086l4.293-4.293a1 1 0 011.414 0z'/%3e%3c/svg%3e");
  background-size: 100% 100%;
  background-position: center;
  background-repeat: no-repeat;
}

/* Checkbox focus state */
.chalky-checkbox-options .chalky-collection-item:has(input[type="checkbox"]:focus) label {
  box-shadow: 0 0 0 3px var(--chalky-primary-light);
}

/* =============================================================================
   BOOLEAN CHECKBOX (Single)
   ============================================================================= */

.chalky-checkbox-wrapper {
  margin-bottom: 1rem;
}

.chalky-checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 0.625rem;
  cursor: pointer;
  font-size: 0.875rem;
  color: var(--chalky-text-primary);
  position: relative;
  padding-left: 1.75rem;
}

/* Hide native checkbox */
.chalky-checkbox,
.chalky-checkbox-label input[type="checkbox"] {
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 1.25rem;
  height: 1.25rem;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

/* Custom checkbox box */
.chalky-checkbox-label::before {
  content: "";
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 1.25rem;
  height: 1.25rem;
  border: 2px solid var(--chalky-border-strong);
  border-radius: 0.25rem;
  background-color: var(--chalky-surface);
  transition: all 0.15s ease-in-out;
}

/* Checkbox hover state */
.chalky-checkbox-label:hover::before {
  border-color: var(--chalky-primary);
}

/* Checkbox checked state */
.chalky-checkbox-label:has(input[type="checkbox"]:checked)::before {
  background-color: var(--chalky-primary);
  border-color: var(--chalky-primary);
  background-image: url("data:image/svg+xml,%3csvg viewBox='0 0 16 16' fill='white' xmlns='http://www.w3.org/2000/svg'%3e%3cpath d='M12.207 4.793a1 1 0 010 1.414l-5 5a1 1 0 01-1.414 0l-2-2a1 1 0 011.414-1.414L6.5 9.086l4.293-4.293a1 1 0 011.414 0z'/%3e%3c/svg%3e");
  background-size: 100% 100%;
  background-position: center;
  background-repeat: no-repeat;
}

/* Checkbox focus state */
.chalky-checkbox-label:has(input[type="checkbox"]:focus)::before {
  box-shadow: 0 0 0 3px var(--chalky-primary-light);
}

/* Checkbox disabled state */
.chalky-checkbox-label:has(input[type="checkbox"]:disabled) {
  cursor: not-allowed;
  color: var(--chalky-text-muted);
}

.chalky-checkbox-label:has(input[type="checkbox"]:disabled)::before {
  background-color: var(--chalky-surface-secondary);
  border-color: var(--chalky-border);
}

/* =============================================================================
   FILE INPUT
   ============================================================================= */

.chalky-file-input {
  display: block;
  width: 100%;
  padding: 0.5rem;
  font-size: 0.875rem;
  color: var(--chalky-text-primary);
  background-color: var(--chalky-surface);
  border: 1px dashed var(--chalky-border-strong);
  border-radius: 0.375rem;
  cursor: pointer;
  transition: border-color 0.15s ease-in-out, background-color 0.15s ease-in-out;
}

.chalky-file-input:hover {
  border-color: var(--chalky-primary);
  background-color: var(--chalky-surface-secondary);
}

.chalky-file-input:focus {
  outline: none;
  border-color: var(--chalky-primary);
  box-shadow: 0 0 0 3px var(--chalky-primary-light);
}

.chalky-file-input::file-selector-button {
  padding: 0.375rem 0.75rem;
  margin-right: 0.75rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--chalky-text-primary);
  background-color: var(--chalky-surface-tertiary);
  border: 1px solid var(--chalky-border);
  border-radius: 0.25rem;
  cursor: pointer;
  transition: background-color 0.15s ease-in-out;
}

.chalky-file-input::file-selector-button:hover {
  background-color: var(--chalky-surface-active);
}

/* =============================================================================
   HINTS & ERRORS
   ============================================================================= */

.chalky-hint {
  font-size: 0.75rem;
  color: var(--chalky-text-muted);
  margin-top: 0.25rem;
}

.chalky-error {
  font-size: 0.75rem;
  color: var(--chalky-danger-text);
  margin-top: 0.25rem;
}

/* =============================================================================
   BUTTONS
   ============================================================================= */

.chalky-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  font-weight: 500;
  line-height: 1.5;
  border-radius: 0.375rem;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s ease-in-out;
}

.chalky-button:focus {
  outline: none;
  box-shadow: 0 0 0 3px var(--chalky-primary-light);
}

.chalky-button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Primary button */
.chalky-button--primary {
  color: var(--chalky-text-inverted);
  background-color: var(--chalky-primary);
  border-color: var(--chalky-primary);
}

.chalky-button--primary:hover:not(:disabled) {
  background-color: var(--chalky-primary-hover);
  border-color: var(--chalky-primary-hover);
}

/* Secondary button */
.chalky-button--secondary {
  color: var(--chalky-text-primary);
  background-color: var(--chalky-surface);
  border-color: var(--chalky-border);
}

.chalky-button--secondary:hover:not(:disabled) {
  background-color: var(--chalky-surface-secondary);
  border-color: var(--chalky-border-strong);
}

/* Danger button */
.chalky-button--danger {
  color: var(--chalky-text-inverted);
  background-color: var(--chalky-danger);
  border-color: var(--chalky-danger);
}

.chalky-button--danger:hover:not(:disabled) {
  background-color: var(--chalky-danger-hover);
  border-color: var(--chalky-danger-hover);
}

/* =============================================================================
   ALERT (Error notification)
   ============================================================================= */

.chalky-alert {
  padding: 1rem;
  border-radius: 0.375rem;
  margin-bottom: 1rem;
}

.chalky-alert--error {
  color: var(--chalky-danger-text);
  background-color: var(--chalky-danger-light);
  border: 1px solid var(--chalky-danger-border);
}

.chalky-alert--success {
  color: var(--chalky-success-text);
  background-color: var(--chalky-success-light);
  border: 1px solid var(--chalky-success-border);
}

.chalky-alert--warning {
  color: var(--chalky-warning-text);
  background-color: var(--chalky-warning-light);
  border: 1px solid var(--chalky-warning-border);
}

.chalky-alert--info {
  color: var(--chalky-info-text);
  background-color: var(--chalky-info-light);
  border: 1px solid var(--chalky-info-border);
}

/* =============================================================================
   TOM SELECT INTEGRATION
   ============================================================================= */

/* Hide original select when TomSelect is initialized */
.chalky-select.tomselected {
  display: none !important;
}

/* TomSelect wrapper */
.ts-wrapper {
  position: relative;
  width: 100%;
}

.ts-wrapper.single .ts-control,
.ts-wrapper.multi .ts-control {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem;
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  line-height: 1.5;
  color: var(--chalky-text-primary);
  background-color: var(--chalky-surface);
  border: 1px solid var(--chalky-border);
  border-radius: 0.375rem;
  cursor: pointer;
  transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
  min-height: 2.5rem;
}

.ts-wrapper.single .ts-control:hover,
.ts-wrapper.multi .ts-control:hover {
  border-color: var(--chalky-border-strong);
}

.ts-wrapper.focus .ts-control {
  outline: none;
  border-color: var(--chalky-primary);
  box-shadow: 0 0 0 3px var(--chalky-primary-light);
}

/* Input field inside control */
/* Reset Tailwind's default focus ring - focus styling is on .ts-control */
.ts-wrapper .ts-control input {
  flex: 1;
  min-width: 50px;
  background: transparent;
  border: none !important;
  outline: none !important;
  box-shadow: none !important;
  --tw-ring-shadow: 0 0 #0000 !important;
  --tw-ring-color: transparent !important;
  color: var(--chalky-text-primary);
  font-size: 0.875rem;
}

.ts-wrapper .ts-control input::placeholder {
  color: var(--chalky-text-muted);
}

/* Hide placeholder when an item is selected */
.ts-wrapper.single.has-items .ts-control input::placeholder,
.ts-wrapper.multi.has-items .ts-control input::placeholder {
  color: transparent;
}

/* Placeholder text */
.ts-wrapper .ts-control > .item.placeholder {
  color: var(--chalky-text-muted);
}

/* Selected item (single) */
.ts-wrapper.single .ts-control > .item {
  color: var(--chalky-text-primary);
  display: flex;
  align-items: center;
}

/* Selected items (multiple) */
.ts-wrapper.multi .ts-control > .item {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.125rem 0.5rem;
  background-color: var(--chalky-primary-light);
  color: var(--chalky-primary-text);
  border-radius: 0.25rem;
  font-size: 0.8125rem;
  font-weight: 500;
}

/* Remove button for multi-select items */
.ts-wrapper.multi .ts-control > .item .remove {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-left: 0.25rem;
  width: 1rem;
  height: 1rem;
  border-radius: 50%;
  font-size: 1rem;
  line-height: 1;
  color: var(--chalky-primary-text);
  opacity: 0.6;
  cursor: pointer;
  transition: opacity 0.15s ease-in-out;
}

.ts-wrapper.multi .ts-control > .item .remove:hover {
  opacity: 1;
}

/* Dropdown arrow */
.ts-wrapper.single .ts-control::after {
  content: "";
  position: absolute;
  right: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  width: 1rem;
  height: 1rem;
  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-size: contain;
  background-repeat: no-repeat;
  pointer-events: none;
}

.ts-wrapper.single .ts-control {
  padding-right: 2.5rem;
  position: relative;
}

/* Dropdown menu */
.ts-dropdown {
  position: absolute;
  z-index: 10000;
  width: 100% !important;
  background-color: var(--chalky-surface);
  border: 1px solid var(--chalky-border);
  border-radius: 0.375rem;
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);
  margin-top: 0.25rem;
  max-height: 300px;
  overflow-y: auto;
}

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

/* Dropdown option */
.ts-dropdown .option {
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  color: var(--chalky-text-primary);
  cursor: pointer;
  transition: background-color 0.15s ease-in-out;
}

.ts-dropdown .option:hover,
.ts-dropdown .option.active {
  background-color: var(--chalky-primary-light);
  color: var(--chalky-primary-text);
}

.ts-dropdown .option.selected {
  background-color: var(--chalky-surface-secondary);
}

/* No results message */
.ts-dropdown .no-results,
.chalky-tom-no-results {
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  color: var(--chalky-text-muted);
  text-align: center;
}

/* Optgroup headers */
.ts-dropdown .optgroup-header {
  padding: 0.5rem 0.75rem;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--chalky-text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Error state */
.chalky-select--error + .ts-wrapper .ts-control,
.chalky-select-group:has(.chalky-error) .ts-control {
  border-color: var(--chalky-danger);
}

.chalky-select--error + .ts-wrapper.focus .ts-control,
.chalky-select-group:has(.chalky-error) .ts-wrapper.focus .ts-control {
  border-color: var(--chalky-danger);
  box-shadow: 0 0 0 3px var(--chalky-danger-light);
}

/* Disabled state */
.ts-wrapper.disabled .ts-control {
  background-color: var(--chalky-surface-secondary);
  color: var(--chalky-text-muted);
  cursor: not-allowed;
}

/* Loading state */
.ts-wrapper.loading .ts-control::after {
  background-image: none;
  border: 2px solid var(--chalky-border);
  border-top-color: var(--chalky-primary);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

@keyframes spin {
  to {
    transform: translateY(-50%) rotate(360deg);
  }
}
