/* ===========================================
   INPUT COMPONENT
   =========================================== */

.input {
  /* === Configuration === */
  --input-padding: 0.75rem 1rem;
  --input-bg: var(--bg-primary);
  --input-color: var(--text-primary);
  --input-placeholder: var(--text-tertiary);
  --input-border-width: 1px;
  --input-border-color: var(--border-default);
  --input-focus-border: var(--brand);
  --input-focus-shadow: 0 0 0 3px var(--brand-light);
  --input-radius: var(--radius-md);
  --input-font-size: 0.9375rem;

  /* === Base Styles === */
  display: block;
  width: 100%;
  padding: var(--input-padding);
  background: var(--input-bg);
  color: var(--input-color);
  border: var(--input-border-width) solid var(--input-border-color);
  border-radius: var(--input-radius);
  font-family: inherit;
  font-size: var(--input-font-size);
  line-height: 1.5;
  transition:
    border-color 0.2s ease,
    box-shadow 0.2s ease,
    background-color 0.2s ease;
}

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

/* === Interactive States === */

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

.input:focus {
  outline: none;
  border-color: var(--input-focus-border);
  box-shadow: var(--input-focus-shadow);
}

.input:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  background: var(--bg-tertiary);
}

/* === SIZES via data attributes === */

.input[data-size="sm"] {
  --input-padding: 0.5rem 0.75rem;
  --input-font-size: 0.8125rem;
}

.input[data-size="lg"] {
  --input-padding: 1rem 1.25rem;
  --input-font-size: 1rem;
}

/* === Icon support === */

.input[data-icon="left"] {
  padding-left: 3rem;
}

.input[data-icon="right"] {
  padding-right: 3rem;
}

/* === Input wrapper for icons === */

.input-wrapper {
  position: relative;
  display: block;
}

.input-wrapper .input-icon {
  position: absolute;
  left: 1rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-tertiary);
  pointer-events: none;
  width: 18px;
  height: 18px;
}

.input-wrapper .input-icon-right {
  left: auto;
  right: 1rem;
}

/* ===========================================
   SELECT COMPONENT
   =========================================== */

.select {
  /* Inherits input configuration */
  --input-padding: 0.75rem 2.5rem 0.75rem 1rem;

  display: block;
  width: 100%;
  padding: var(--input-padding);
  background-color: var(--bg-primary);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2371717a' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  background-size: 16px;
  color: var(--text-primary);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: 0.9375rem;
  line-height: 1.5;
  cursor: pointer;
  appearance: none;
  transition:
    border-color 0.2s ease,
    box-shadow 0.2s ease;
}

.select:hover {
  border-color: var(--border-emphasis);
}

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

/* ===========================================
   CHECKBOX COMPONENT
   =========================================== */

.checkbox {
  /* === Configuration === */
  --checkbox-size: 18px;
  --checkbox-radius: var(--radius-sm);
  --checkbox-border: var(--border-default);
  --checkbox-checked-bg: var(--brand);
  --checkbox-checked-border: var(--brand);

  /* === Base Styles === */
  appearance: none;
  width: var(--checkbox-size);
  height: var(--checkbox-size);
  border: 2px solid var(--checkbox-border);
  border-radius: var(--checkbox-radius);
  background: var(--bg-primary);
  cursor: pointer;
  transition:
    background-color 0.2s ease,
    border-color 0.2s ease;
  flex-shrink: 0;
}

.checkbox:hover {
  border-color: var(--brand);
}

.checkbox:checked {
  background-color: var(--checkbox-checked-bg);
  border-color: var(--checkbox-checked-border);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6 9 17l-5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: center;
  background-size: 12px;
}

.checkbox:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

/* Checkbox with label */
.checkbox-label {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  cursor: pointer;
  font-size: 0.875rem;
  color: var(--text-secondary);
  line-height: 1.4;
}

.checkbox-label .checkbox {
  margin-top: 0.1rem;
}

/* ===========================================
   TOGGLE SWITCH COMPONENT
   =========================================== */

.toggle {
  /* === Configuration === */
  --toggle-width: 44px;
  --toggle-height: 24px;
  --toggle-radius: 24px;
  --toggle-bg: var(--bg-tertiary);
  --toggle-checked-bg: var(--brand);
  --toggle-knob-size: 18px;
  --toggle-knob-offset: 3px;

  /* === Base Styles === */
  position: relative;
  display: inline-block;
  width: var(--toggle-width);
  height: var(--toggle-height);
  flex-shrink: 0;
}

.toggle input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}

.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--toggle-bg);
  border-radius: var(--toggle-radius);
  cursor: pointer;
  transition: background-color 0.3s ease;
}

.toggle-slider::before {
  content: "";
  position: absolute;
  width: var(--toggle-knob-size);
  height: var(--toggle-knob-size);
  left: var(--toggle-knob-offset);
  top: 50%;
  transform: translateY(-50%);
  background: white;
  border-radius: 50%;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
  transition: transform 0.3s ease;
}

.toggle input:checked + .toggle-slider {
  background: var(--toggle-checked-bg);
}

.toggle input:checked + .toggle-slider::before {
  transform: translateY(-50%)
    translateX(calc(var(--toggle-width) - var(--toggle-knob-size) - var(--toggle-knob-offset) * 2));
}

.toggle input:focus-visible + .toggle-slider {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

/* ===========================================
   FORM GROUP COMPONENT
   =========================================== */

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.form-label {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-primary);
}

.form-hint {
  font-size: 0.75rem;
  color: var(--text-tertiary);
}

/* Form row for side-by-side inputs */
.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
}

/* ===========================================
   PASSWORD TOGGLE COMPONENT
   =========================================== */

.password-toggle {
  position: absolute;
  right: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  cursor: pointer;
  border-radius: var(--radius-md);
  transition: all 0.2s ease;
  color: var(--text-tertiary);
  padding: 0;
}

.password-toggle:hover {
  background: var(--bg-tertiary);
  color: var(--text-secondary);
}

.password-toggle .eye-icon {
  width: 18px;
  height: 18px;
  transition: opacity 0.2s ease;
}

.password-toggle .eye-open {
  display: none;
  opacity: 0;
}

.password-toggle.visible .eye-closed {
  display: none;
  opacity: 0;
}

.password-toggle.visible .eye-open {
  display: block;
  opacity: 1;
}

/* ===========================================
   TEXTAREA COMPONENT
   =========================================== */

.textarea {
  /* === Configuration === */
  --textarea-padding: 0.75rem 1rem;
  --textarea-bg: var(--bg-primary);
  --textarea-color: var(--text-primary);
  --textarea-placeholder: var(--text-tertiary);
  --textarea-border-color: var(--border-default);
  --textarea-focus-border: var(--brand);
  --textarea-focus-shadow: 0 0 0 3px var(--brand-light);
  --textarea-radius: var(--radius-md);
  --textarea-font-size: 0.9375rem;
  --textarea-min-height: 100px;

  /* === Base Styles === */
  display: block;
  width: 100%;
  min-height: var(--textarea-min-height);
  padding: var(--textarea-padding);
  background: var(--textarea-bg);
  color: var(--textarea-color);
  border: 1px solid var(--textarea-border-color);
  border-radius: var(--textarea-radius);
  font-family: inherit;
  font-size: var(--textarea-font-size);
  line-height: 1.5;
  resize: vertical;
  transition:
    border-color 0.2s ease,
    box-shadow 0.2s ease;
}

.textarea::placeholder {
  color: var(--textarea-placeholder);
}

.textarea:hover {
  --textarea-border-color: var(--border-emphasis);
}

.textarea:focus {
  outline: none;
  border-color: var(--textarea-focus-border);
  box-shadow: var(--textarea-focus-shadow);
}

.textarea:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  background: var(--bg-tertiary);
}

/* Textarea sizes */
.textarea[data-size="sm"] {
  --textarea-padding: 0.5rem 0.75rem;
  --textarea-font-size: 0.8125rem;
  --textarea-min-height: 80px;
}

.textarea[data-size="lg"] {
  --textarea-padding: 1rem 1.25rem;
  --textarea-font-size: 1rem;
  --textarea-min-height: 150px;
}

/* ===========================================
   RADIO BUTTON COMPONENT
   =========================================== */

.radio {
  /* === Configuration === */
  --radio-size: 18px;
  --radio-border: var(--border-default);
  --radio-checked-bg: var(--brand);
  --radio-checked-border: var(--brand);
  --radio-dot-size: 8px;

  /* === Base Styles === */
  appearance: none;
  width: var(--radio-size);
  height: var(--radio-size);
  border: 2px solid var(--radio-border);
  border-radius: 50%;
  background: var(--bg-primary);
  cursor: pointer;
  transition:
    background-color 0.2s ease,
    border-color 0.2s ease;
  flex-shrink: 0;
}

.radio:hover {
  border-color: var(--brand);
}

.radio:checked {
  background-color: var(--radio-checked-bg);
  border-color: var(--radio-checked-border);
}

.radio:checked::after {
  content: "";
  display: block;
  width: var(--radio-dot-size);
  height: var(--radio-dot-size);
  margin: calc((var(--radio-size) - var(--radio-dot-size) - 4px) / 2);
  background: white;
  border-radius: 50%;
}

.radio:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

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

/* Radio with label */
.radio-label {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  cursor: pointer;
  font-size: 0.875rem;
  color: var(--text-secondary);
  line-height: 1.4;
}

.radio-label .radio {
  margin-top: 0.1rem;
}

/* Radio group */
.radio-group {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.radio-group[data-direction="horizontal"] {
  flex-direction: row;
  flex-wrap: wrap;
  gap: 1.5rem;
}

/* ===========================================
   VALIDATION STATES
   =========================================== */

/* Error state for inputs */
:is(.input, .textarea, .select)[data-state="error"],
:is(.input, .textarea, .select):invalid:not(:placeholder-shown) {
  --input-border-color: var(--state-danger);
  --textarea-border-color: var(--state-danger);
  border-color: var(--state-danger);
}

:is(.input, .textarea, .select)[data-state="error"]:focus,
:is(.input, .textarea, .select):invalid:not(:placeholder-shown):focus {
  box-shadow: 0 0 0 3px var(--state-danger-light);
}

/* Success state */
:is(.input, .textarea, .select)[data-state="success"] {
  --input-border-color: var(--state-success);
  --textarea-border-color: var(--state-success);
  border-color: var(--state-success);
}

:is(.input, .textarea, .select)[data-state="success"]:focus {
  box-shadow: 0 0 0 3px var(--state-success-light);
}

/* Form hint with states */
.form-hint[data-state="error"] {
  color: var(--state-danger);
}

.form-hint[data-state="success"] {
  color: var(--state-success);
}

/* ===========================================
   SELECT DISABLED STATE
   =========================================== */

.select:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  background-color: var(--bg-tertiary);
}

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

.file-input {
  /* === Configuration === */
  --file-input-padding: 2rem 1.5rem;
  --file-input-bg: var(--bg-primary);
  --file-input-border: var(--border-default);
  --file-input-border-style: dashed;
  --file-input-radius: var(--radius-lg);
  --file-input-hover-border: var(--brand);
  --file-input-hover-bg: var(--brand-light);

  /* === Base Styles === */
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  padding: var(--file-input-padding);
  background: var(--file-input-bg);
  border: 2px var(--file-input-border-style) var(--file-input-border);
  border-radius: var(--file-input-radius);
  cursor: pointer;
  transition:
    border-color 0.2s ease,
    background-color 0.2s ease;
}

.file-input:hover {
  border-color: var(--file-input-hover-border);
  background: var(--file-input-hover-bg);
}

.file-input:focus-within {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-light);
}

/* Hide native input but keep it accessible */
.file-input input[type="file"] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

.file-input-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-md);
  color: var(--text-tertiary);
}

.file-input-icon svg {
  width: 24px;
  height: 24px;
}

.file-input-text {
  text-align: center;
}

.file-input-title {
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--text-primary);
}

.file-input-title strong {
  color: var(--brand);
}

.file-input-hint {
  font-size: 0.75rem;
  color: var(--text-tertiary);
  margin-top: 0.25rem;
}

/* Drag over state */
.file-input[data-dragover="true"] {
  border-color: var(--brand);
  background: var(--brand-light);
}

.file-input[data-dragover="true"] .file-input-icon {
  background: var(--brand);
  color: white;
}

/* Compact variant */
.file-input[data-variant="compact"] {
  --file-input-padding: 1rem;
  flex-direction: row;
  gap: 1rem;
}

.file-input[data-variant="compact"] .file-input-icon {
  width: 40px;
  height: 40px;
}

.file-input[data-variant="compact"] .file-input-icon svg {
  width: 20px;
  height: 20px;
}

.file-input[data-variant="compact"] .file-input-text {
  text-align: left;
}

/* Error state */
.file-input[data-state="error"] {
  border-color: var(--state-danger);
}

.file-input[data-state="error"]:focus-within {
  box-shadow: 0 0 0 3px var(--state-danger-light);
}

/* File preview (when file is selected) */
.file-preview {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
}

.file-preview-icon {
  flex-shrink: 0;
  color: var(--text-tertiary);
}

.file-preview-icon svg {
  width: 20px;
  height: 20px;
}

.file-preview-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
}

.file-preview-name {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.file-preview-size {
  font-size: 0.75rem;
  color: var(--text-tertiary);
}

.file-preview-remove {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-tertiary);
  cursor: pointer;
  transition: all 0.2s ease;
}

.file-preview-remove:hover {
  background: var(--state-danger-light);
  color: var(--state-danger);
}

.file-preview-remove svg {
  width: 16px;
  height: 16px;
}
