/** Input primitive styles */

/* ============================================================================
   INPUT WRAPPER
   ============================================================================ */

.cmm-input-wrapper {
  position: relative;
  display: inline-flex;
  width: 100%;
}

/* ============================================================================
   INPUT BASE
   ============================================================================ */

.cmm-input {
  display: block;
  width: 100%;
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius-md);
  background-color: hsl(var(--background));
  color: hsl(var(--foreground));
  font-family: inherit;
  font-size: 0.875rem;
  line-height: 1.5;
  transition:
    border-color var(--transition-fast) ease,
    box-shadow var(--transition-fast) ease;
}

.cmm-input::placeholder {
  color: hsl(var(--muted-foreground));
}

/* ============================================================================
   INPUT SIZES
   ============================================================================ */

.cmm-input--sm {
  height: 2rem;
  padding: 0.25rem 0.5rem;
  font-size: 0.75rem;
  border-radius: var(--radius-sm);
}

.cmm-input--md {
  height: 2.5rem;
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
}

.cmm-input--lg {
  height: 3rem;
  padding: 0.625rem 1rem;
  font-size: 1rem;
  border-radius: var(--radius-lg);
}

/* ============================================================================
   INPUT STATES
   ============================================================================ */

.cmm-input:focus {
  outline: 2px solid hsl(var(--focus-ring));
  outline-offset: 2px;
  border-color: hsl(var(--ring));
}

.cmm-input:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

.cmm-input--error {
  border-color: hsl(var(--destructive));
}

.cmm-input--error:focus {
  outline-color: hsl(var(--destructive));
}

/* ============================================================================
   INPUT GROUP
   ============================================================================ */

.cmm-input-group {
  display: inline-flex;
  align-items: stretch;
  width: 100%;
}

.cmm-input-group__content {
  flex: 1;
  min-width: 0;
}

.cmm-input-group__content .cmm-input-wrapper {
  width: 100%;
}

.cmm-input-group__content .cmm-input {
  border-radius: 0;
}

.cmm-input-group__prefix,
.cmm-input-group__suffix {
  display: inline-flex;
  align-items: center;
  padding: 0 0.75rem;
  background-color: hsl(var(--muted));
  color: hsl(var(--muted-foreground));
  border: 1px solid hsl(var(--border));
  font-size: 0.875rem;
  white-space: nowrap;
  user-select: none;
}

.cmm-input-group__prefix {
  border-right: none;
  border-top-left-radius: var(--radius-md);
  border-bottom-left-radius: var(--radius-md);
}

.cmm-input-group__suffix {
  border-left: none;
  border-top-right-radius: var(--radius-md);
  border-bottom-right-radius: var(--radius-md);
}

/* When prefix is present, remove left border-radius from content's input */
.cmm-input-group__prefix + .cmm-input-group__content .cmm-input {
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
}

/* When no prefix, keep left border-radius on content's input */
.cmm-input-group__content:first-child .cmm-input {
  border-top-left-radius: var(--radius-md);
  border-bottom-left-radius: var(--radius-md);
}

/* When no suffix follows, keep right border-radius */
.cmm-input-group__content:last-child .cmm-input {
  border-top-right-radius: var(--radius-md);
  border-bottom-right-radius: var(--radius-md);
}

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

.cmm-textarea-wrapper {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
}

.cmm-textarea {
  display: block;
  width: 100%;
  min-height: 5rem;
  padding: 0.5rem 0.75rem;
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius-md);
  background-color: hsl(var(--background));
  color: hsl(var(--foreground));
  font-family: inherit;
  font-size: 0.875rem;
  line-height: 1.5;
  resize: vertical;
  transition:
    border-color var(--transition-fast) ease,
    box-shadow var(--transition-fast) ease;
}

.cmm-textarea::placeholder {
  color: hsl(var(--muted-foreground));
}

.cmm-textarea:focus {
  outline: 2px solid hsl(var(--focus-ring));
  outline-offset: 2px;
  border-color: hsl(var(--ring));
}

.cmm-textarea:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

.cmm-textarea--error {
  border-color: hsl(var(--destructive));
}

.cmm-textarea--error:focus {
  outline-color: hsl(var(--destructive));
}

.cmm-textarea__count {
  display: block;
  margin-top: 0.25rem;
  text-align: right;
  font-size: 0.75rem;
  color: hsl(var(--muted-foreground));
}

/* ============================================================================
   INPUT OTP
   ============================================================================ */

.cmm-input-otp {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

.cmm-input-otp__digit {
  width: 2.5rem;
  height: 3rem;
  padding: 0;
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius-md);
  background-color: hsl(var(--background));
  color: hsl(var(--foreground));
  font-family: inherit;
  font-size: 1.25rem;
  font-weight: 600;
  text-align: center;
  caret-color: hsl(var(--primary));
  transition:
    border-color var(--transition-fast) ease,
    box-shadow var(--transition-fast) ease;
}

.cmm-input-otp__digit:focus {
  outline: 2px solid hsl(var(--focus-ring));
  outline-offset: 2px;
  border-color: hsl(var(--ring));
}

.cmm-input-otp__digit:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

.cmm-input-otp__separator {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1rem;
  color: hsl(var(--muted-foreground));
  font-size: 1.25rem;
  font-weight: 600;
  user-select: none;
}

/* ============================================================================
   IP INPUT
   ============================================================================ */

.cmm-ip-input {
  display: inline-flex;
  align-items: center;
  gap: 0;
}

.cmm-ip-input__segment {
  width: 3.5rem;
  height: 2.5rem;
  padding: 0 0.25rem;
  border: 1px solid hsl(var(--border));
  background-color: hsl(var(--background));
  color: hsl(var(--foreground));
  font-family: monospace;
  font-size: 0.875rem;
  text-align: center;
  transition:
    border-color var(--transition-fast) ease,
    box-shadow var(--transition-fast) ease;
}

.cmm-ip-input__segment:focus {
  outline: 2px solid hsl(var(--focus-ring));
  outline-offset: 2px;
  border-color: hsl(var(--ring));
  z-index: 1;
  position: relative;
}

.cmm-ip-input__segment:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

/* Remove inner border-radii for connected segments */
.cmm-ip-input__segment {
  border-radius: 0;
}

.cmm-ip-input__segment:first-of-type {
  border-top-left-radius: var(--radius-md);
  border-bottom-left-radius: var(--radius-md);
}

.cmm-ip-input__segment:last-of-type {
  border-top-right-radius: var(--radius-md);
  border-bottom-right-radius: var(--radius-md);
}

.cmm-ip-input__separator {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1rem;
  color: hsl(var(--muted-foreground));
  font-family: monospace;
  font-size: 1rem;
  font-weight: 700;
  user-select: none;
}

/* IPv6 segments are wider for hex values */
.cmm-ip-input--v6 .cmm-ip-input__segment {
  width: 4.5rem;
}
