/**
 * Text Input Component Styles
 *
 * Wiederverwendbare Styles fuer Kurztext- und Langtext-Felder.
 * Basiert auf dem audatis MANAGER Design-System.
 *
 * Verwendung:
 *   <link rel="stylesheet" href="/public/css/components/text-input.css">
 */

/* ========================================
   Text Input Container
   ======================================== */
.text-input-component {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* ========================================
   Label (globally available)
   ======================================== */
.text-input-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 6px;
}

.text-input-label-required {
  color: var(--error-color, #dc2626);
}

/* Form group with label - consistent spacing */
.form-group:has(.text-input-label) {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* ========================================
   Input Wrapper (for consistent height)
   ======================================== */
.text-input-wrapper {
  position: relative;
  display: flex;
  align-items: flex-end;
  min-height: 36px;
  background-color: transparent;
}

/* ========================================
   Text Input (Kurztext)
   ======================================== */
.text-input-field {
  width: 100%;
  padding: 10px 0;
  border: none;
  border-bottom: 1px solid var(--border-color, #e5e7eb);
  border-radius: 0;
  font-size: 14px;
  background-color: transparent;
  color: var(--text-primary, #1f2937);
  transition: border-color 0.2s;
  box-sizing: border-box;
  text-overflow: ellipsis;
  overflow: hidden;
}

.text-input-field:hover {
  border-bottom-color: var(--grey-500, #6b7280);
}

.text-input-field:focus {
  outline: none;
  border-bottom: 2px solid var(--primary-color, #007abb);
  margin-bottom: -0.75px;
}

.text-input-field::placeholder {
  color: var(--text-disabled, #9ca3af);
}

.text-input-field:disabled,
.text-input-field[readonly] {
  background-color: transparent;
  border-bottom-color: var(--grey-200, #e5e7eb);
  color: var(--text-muted, #6b7280);
  cursor: text;
}

.text-input-field[readonly] {
  cursor: text;
}

/* HTML5 Validation Error States */
.text-input-field:invalid:not(:placeholder-shown):not(:focus),
.text-input-field:user-invalid:not(:focus) {
  border-bottom-color: var(--error-color, #c84646);
}

.text-input-field:invalid:not(:placeholder-shown):focus,
.text-input-field:user-invalid:focus {
  border-bottom: 2px solid var(--error-color, #c84646);
  margin-bottom: -0.75px;
}

/* Custom Validation Error Class (from JS) */
.text-input-field.has-validation-error {
  border-bottom-color: var(--error-color, #c84646);
}

.text-input-field.has-validation-error:focus {
  border-bottom: 2px solid var(--error-color, #c84646);
  margin-bottom: -0.75px;
}

/* ========================================
   Textarea Wrapper (for Langtext)
   ======================================== */
.textarea-wrapper {
  position: relative;
  display: flex;
  flex-direction: column;
  background-color: transparent;
}

/* ========================================
   Textarea (Langtext)
   ======================================== */
.textarea-field {
  width: 100%;
  padding: 10px 0px;
  border: none;
  border-bottom: 1px solid var(--border-color, #e5e7eb);
  border-radius: 0;
  font-size: 14px;
  font-family: inherit;
  background-color: transparent;
  color: var(--text-primary, #1f2937);
  resize: vertical;
  min-height: 100px;
  transition: border-color 0.2s;
  box-sizing: border-box;
  line-height: 1.5;
}

/* Auto-resize textareas: overflow hidden for correct scrollHeight calculation,
   no manual resize, flex:none to prevent flex-basis:0 from overriding JS-set height */
.textarea-field[data-auto-resize="true"] {
  overflow: hidden;
  resize: none;
  flex: none;
}

.textarea-field:hover {
  border-bottom-color: var(--grey-500, #6b7280);
}

.textarea-field:focus {
  outline: none;
  border-bottom: 2px solid var(--primary-color, #007abb);
  margin-bottom: -0.75px;
}

.textarea-field::placeholder {
  color: var(--text-disabled, #9ca3af);
}

.textarea-field:disabled,
.textarea-field[readonly] {
  background-color: transparent;
  border-bottom-color: var(--grey-200, #e5e7eb);
  color: var(--text-muted, #6b7280);
  cursor: text;
}

.textarea-field:disabled {
  resize: none;
}

.textarea-field[readonly] {
  cursor: text;
}

/* HTML5 Validation Error States for Textarea */
.textarea-field:invalid:not(:placeholder-shown):not(:focus),
.textarea-field:user-invalid:not(:focus) {
  border-bottom-color: var(--error-color, #c84646);
}

.textarea-field:invalid:not(:placeholder-shown):focus,
.textarea-field:user-invalid:focus {
  border-bottom: 2px solid var(--error-color, #c84646);
  margin-bottom: -0.75px;
}

/* Custom Validation Error Class (from JS) */
.textarea-field.has-validation-error {
  border-bottom-color: var(--error-color, #c84646);
}

.textarea-field.has-validation-error:focus {
  border-bottom: 2px solid var(--error-color, #c84646);
  margin-bottom: -0.75px;
}

/* ========================================
   Character Counter
   ======================================== */
.text-input-counter {
  font-size: 12px;
  color: var(--text-muted, #6b7280);
  text-align: right;
  margin-top: 4px;
}

.text-input-counter.warning {
  color: var(--warning-color, #f59e0b);
}

.text-input-counter.error {
  color: var(--error-color, #dc2626);
}

/* ========================================
   Help Text
   ======================================== */
.text-input-help {
  font-size: 12px;
  color: var(--text-muted, #6b7280);
  margin-top: 4px;
}

/* ========================================
   Error State
   ======================================== */
.text-input-component.has-error .text-input-field,
.text-input-component.has-error .textarea-field {
  border-bottom-color: var(--error-color, #dc2626);
}

.text-input-component.has-error .text-input-field:focus,
.text-input-component.has-error .textarea-field:focus {
  border-bottom: 2px solid var(--error-color, #dc2626);
  margin-bottom: -0.75px;
}

.text-input-error {
  font-size: 12px;
  color: var(--error-color, #dc2626);
  margin-top: 4px;
}

/* ========================================
   Form Group Integration
   ======================================== */
.form-group .text-input-wrapper {
  min-height: 40px;
}

.form-group .text-input-field {
  padding: 8px 0;
}

/* ========================================
   Size Variants
   ======================================== */

/* Small */
.text-input-component.text-input-sm .text-input-wrapper {
  min-height: 36px;
}

.text-input-component.text-input-sm .text-input-field {
  padding: 8px 0;
  font-size: 13px;
}

.text-input-component.text-input-sm .textarea-field {
  padding: 8px 10px;
  font-size: 13px;
  min-height: 80px;
}

/* Large */
.text-input-component.text-input-lg .text-input-wrapper {
  min-height: 48px;
}

.text-input-component.text-input-lg .text-input-field {
  padding: 12px 0;
  font-size: 15px;
}

.text-input-component.text-input-lg .textarea-field {
  padding: 12px 14px;
  font-size: 15px;
  min-height: 120px;
}

/* ========================================
   Input with Icon
   ======================================== */
.text-input-wrapper.has-icon-left .text-input-field {
  padding-left: 40px;
}

.text-input-wrapper.has-icon-right .text-input-field {
  padding-right: 40px;
}

.text-input-icon {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 100%;
  color: var(--text-muted, #6b7280);
  pointer-events: none;
}

.text-input-icon.icon-left {
  left: 0;
}

.text-input-icon.icon-right {
  right: 0;
}

/* ========================================
   Password Toggle Button
   ======================================== */
.text-input-wrapper .toggle-password {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--text-muted, #6b7280);
  cursor: pointer;
  padding: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: color 0.2s, background-color 0.2s;
}

.text-input-wrapper .toggle-password:hover {
  color: var(--text-secondary, #374151);
}

.text-input-wrapper .toggle-password svg,
.text-input-wrapper .toggle-password .mdi {
  width: 20px;
  height: 20px;
}

/* Eye icon visibility states */
.text-input-wrapper .toggle-password .eye-closed {
  display: none;
}

.text-input-wrapper .toggle-password.password-visible .eye-open {
  display: none;
}

.text-input-wrapper .toggle-password.password-visible .eye-closed {
  display: block;
}

/* ========================================
   Responsive
   ======================================== */
@media (max-width: 480px) {
  .text-input-field,
  .textarea-field {
    font-size: 16px; /* Prevents zoom on iOS */
  }
}
