/* Forms CSS - Input, Label, Select, Textarea, Checkbox, Radio */

/* ============================================
   Form Container
   ============================================ */
.form {
    width: 100%;
}

.form-group {
    margin-bottom: var(--spacing-md);
}

.form-row {
    display: grid;
    gap: var(--spacing-md);
}

.form-row-2 {
    grid-template-columns: repeat(2, 1fr);
}

.form-row-3 {
    grid-template-columns: repeat(3, 1fr);
}

@media (max-width: 640px) {
    .form-row-2,
    .form-row-3 {
        grid-template-columns: 1fr;
    }
}

/* ============================================
   Labels
   ============================================ */
.form-label {
    display: block;
    margin-bottom: var(--spacing-sm);
    font-size: var(--text-sm);
    font-weight: 500;
    color: hsl(var(--foreground));
}

.form-label-required::after {
    content: " *";
    color: hsl(var(--destructive));
}

.form-label-inline {
    display: inline-flex;
    align-items: center;
    gap: var(--spacing-sm);
    cursor: pointer;
}

/* ============================================
   Text Inputs
   ============================================ */
.form-input {
    display: block;
    width: 100%;
    height: 2.75rem;
    padding: 0 0.75rem;
    font-size: var(--text-sm);
    line-height: 1.5;
    color: hsl(var(--foreground));
    background-color: hsl(var(--background));
    border: 1px solid hsl(var(--input));
    border-radius: calc(var(--radius) - 2px);
    transition: border-color var(--transition-fast) ease-in-out, box-shadow var(--transition-fast) ease-in-out;
}

.form-input::placeholder {
    color: hsl(var(--muted-foreground));
}

.form-input:focus {
    outline: none;
    border-color: hsl(var(--primary));
    box-shadow: 0 0 0 1px hsl(var(--primary) / 0.2);
}

.form-input:disabled {
    cursor: not-allowed;
    opacity: 0.5;
    background-color: hsl(var(--muted));
}

.form-input.error,
.form-input:invalid:not(:placeholder-shown) {
    border-color: hsl(var(--destructive));
}

.form-input.error:focus {
    box-shadow: 0 0 0 1px hsl(var(--destructive) / 0.2);
}

/* Input with icon */
.form-input-wrapper {
    position: relative;
}

.form-input-icon {
    position: absolute;
    left: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    color: hsl(var(--muted-foreground));
    pointer-events: none;
}

.form-input-icon svg,
.form-input-icon .icon {
    width: 1.25rem;
    height: 1.25rem;
}

.form-input-with-icon {
    padding-left: 2.5rem;
}

.form-input-icon-right {
    left: auto;
    right: 0.75rem;
    pointer-events: auto;
    cursor: pointer;
}

.form-input-with-icon-right {
    padding-right: 2.5rem;
}

/* Input sizes */
.form-input-sm {
    height: 2rem;
    padding: 0 0.5rem;
    font-size: var(--text-sm);
}

.form-input-lg {
    height: 3rem;
    padding: 0 1rem;
    font-size: var(--text-base);
}

/* ============================================
   Textarea
   ============================================ */
.form-textarea {
    display: block;
    width: 100%;
    min-height: 5rem;
    padding: 0.75rem;
    font-size: var(--text-sm);
    line-height: 1.5;
    color: hsl(var(--foreground));
    background-color: hsl(var(--background));
    border: 1px solid hsl(var(--input));
    border-radius: calc(var(--radius) - 2px);
    resize: vertical;
    transition: border-color var(--transition-fast) ease-in-out;
}

.form-textarea::placeholder {
    color: hsl(var(--muted-foreground));
}

.form-textarea:focus {
    outline: none;
    border-color: hsl(var(--primary));
    box-shadow: 0 0 0 1px hsl(var(--primary) / 0.2);
}

.form-textarea:disabled {
    cursor: not-allowed;
    opacity: 0.5;
    background-color: hsl(var(--muted));
}

/* ============================================
   Select
   ============================================ */
.form-select {
    display: block;
    width: 100%;
    height: 2.75rem;
    padding: 0 2rem 0 0.75rem;
    font-size: var(--text-sm);
    line-height: 1.5;
    color: hsl(var(--foreground));
    background-color: hsl(var(--background));
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 0.5rem center;
    background-size: 1.25rem;
    border: 1px solid hsl(var(--input));
    border-radius: calc(var(--radius) - 2px);
    cursor: pointer;
    appearance: none;
    transition: border-color var(--transition-fast) ease-in-out;
}

.form-select:focus {
    outline: none;
    border-color: hsl(var(--primary));
    box-shadow: 0 0 0 1px hsl(var(--primary) / 0.2);
}

.form-select:disabled {
    cursor: not-allowed;
    opacity: 0.5;
    background-color: hsl(var(--muted));
}

/* ============================================
   Checkbox
   ============================================ */
.form-checkbox {
    width: 1rem;
    height: 1rem;
    margin: 0;
    cursor: pointer;
    accent-color: hsl(var(--primary));
    border: none;
    border-radius: calc(var(--radius) - 4px);
}

.form-checkbox:focus {
    outline: 2px solid hsl(var(--ring));
    outline-offset: 2px;
}

.form-checkbox:disabled {
    cursor: not-allowed;
    opacity: 0.5;
}

/* Custom checkbox */
.checkbox-wrapper {
    display: inline-flex;
    align-items: center;
    gap: var(--spacing-sm);
    cursor: pointer;
}

.checkbox-wrapper input[type="checkbox"] {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.checkbox-custom {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1rem;
    height: 1rem;
    border: 1px solid hsl(var(--input));
    border-radius: calc(var(--radius) - 4px);
    background-color: hsl(var(--background));
    transition: all var(--transition-fast) ease-in-out;
}

.checkbox-wrapper input[type="checkbox"]:checked + .checkbox-custom {
    background-color: hsl(var(--primary));
    border-color: hsl(var(--primary));
}

.checkbox-wrapper input[type="checkbox"]:checked + .checkbox-custom::after {
    content: "";
    display: block;
    width: 0.25rem;
    height: 0.5rem;
    border: solid hsl(var(--background));
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
    margin-bottom: 2px;
}

.checkbox-wrapper input[type="checkbox"]:focus + .checkbox-custom {
    outline: 2px solid hsl(var(--ring));
    outline-offset: 2px;
}

.checkbox-wrapper input[type="checkbox"]:disabled + .checkbox-custom {
    opacity: 0.5;
    cursor: not-allowed;
}

.checkbox-label {
    font-size: var(--text-sm);
    color: hsl(var(--foreground));
}

/* ============================================
   Radio
   ============================================ */
.form-radio {
    width: 1rem;
    height: 1rem;
    margin: 0;
    cursor: pointer;
    accent-color: hsl(var(--primary));
}

.form-radio:focus {
    outline: 2px solid hsl(var(--ring));
    outline-offset: 2px;
}

.form-radio:disabled {
    cursor: not-allowed;
    opacity: 0.5;
}

/* Radio Group */
.radio-group {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
}

.radio-group-horizontal {
    flex-direction: row;
    flex-wrap: wrap;
    gap: var(--spacing-md);
}

.radio-item {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    cursor: pointer;
}

.radio-item input[type="radio"] {
    width: 1rem;
    height: 1rem;
    margin: 0;
    accent-color: hsl(var(--primary));
}

.radio-item-label {
    font-size: var(--text-sm);
    color: hsl(var(--foreground));
}

/* Custom radio */
.radio-wrapper {
    display: inline-flex;
    align-items: center;
    gap: var(--spacing-sm);
    cursor: pointer;
}

.radio-wrapper input[type="radio"] {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.radio-custom {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1rem;
    height: 1rem;
    border: 1px solid hsl(var(--input));
    border-radius: 50%;
    background-color: hsl(var(--background));
    transition: all var(--transition-fast) ease-in-out;
}

.radio-wrapper input[type="radio"]:checked + .radio-custom {
    border-color: hsl(var(--primary));
}

.radio-wrapper input[type="radio"]:checked + .radio-custom::after {
    content: "";
    display: block;
    width: 0.5rem;
    height: 0.5rem;
    border-radius: 50%;
    background-color: hsl(var(--primary));
}

.radio-wrapper input[type="radio"]:focus + .radio-custom {
    outline: 2px solid hsl(var(--ring));
    outline-offset: 2px;
}

/* Radio Card (for payment method selection, etc.) */
.radio-card {
    position: relative;
    display: flex;
    align-items: flex-start;
    gap: var(--spacing-md);
    padding: var(--spacing-md);
    border: 1px solid hsl(var(--border));
    border-radius: var(--radius);
    cursor: pointer;
    transition: all var(--transition-fast) ease-in-out;
}

.radio-card:hover {
    border-color: hsl(var(--primary) / 0.5);
}

.radio-card.selected,
.radio-card:has(input[type="radio"]:checked) {
    border-color: hsl(var(--primary));
    background-color: hsl(var(--primary) / 0.05);
}

.radio-card input[type="radio"] {
    margin-top: 0.125rem;
}

.radio-card-content {
    flex: 1;
}

.radio-card-title {
    font-weight: 500;
    color: hsl(var(--foreground));
}

.radio-card-description {
    font-size: var(--text-sm);
    color: hsl(var(--muted-foreground));
    margin-top: 0.25rem;
}

/* ============================================
   Switch / Toggle
   ============================================ */
.switch {
    position: relative;
    display: inline-flex;
    align-items: center;
    cursor: pointer;
}

.switch input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.switch-slider {
    position: relative;
    width: 2.5rem;
    height: 1.5rem;
    background-color: hsl(var(--muted));
    border-radius: 9999px;
    transition: background-color var(--transition-fast) ease-in-out;
}

.switch-slider::before {
    content: "";
    position: absolute;
    top: 0.125rem;
    left: 0.125rem;
    width: 1.25rem;
    height: 1.25rem;
    background-color: hsl(var(--background));
    border-radius: 50%;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    transition: transform var(--transition-fast) ease-in-out;
}

.switch input:checked + .switch-slider {
    background-color: hsl(var(--primary));
}

.switch input:checked + .switch-slider::before {
    transform: translateX(1rem);
}

.switch input:focus + .switch-slider {
    outline: 2px solid hsl(var(--ring));
    outline-offset: 2px;
}

.switch input:disabled + .switch-slider {
    opacity: 0.5;
    cursor: not-allowed;
}

.switch-label {
    margin-left: var(--spacing-sm);
    font-size: var(--text-sm);
}

/* ============================================
   Form Help Text & Errors
   ============================================ */
.form-help {
    display: block;
    margin-top: var(--spacing-xs);
    font-size: var(--text-xs);
    color: hsl(var(--muted-foreground));
}

.form-error {
    display: block;
    margin-top: var(--spacing-xs);
    font-size: var(--text-xs);
    color: hsl(var(--destructive));
}

/* ============================================
   Form Actions
   ============================================ */
.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: var(--spacing-sm);
    margin-top: var(--spacing-lg);
    padding-top: var(--spacing-md);
}

.form-actions-left {
    justify-content: flex-start;
}

.form-actions-center {
    justify-content: center;
}

.form-actions-between {
    justify-content: space-between;
}

/* ============================================
   Filled Input Style (Material-like)
   ============================================ */
.form-input-filled {
    background-color: hsl(var(--muted) / 0.5);
    border: none;
    border-bottom: 2px solid hsl(var(--border));
    border-radius: calc(var(--radius) - 2px) calc(var(--radius) - 2px) 0 0;
}

.form-input-filled:focus {
    border-bottom-color: hsl(var(--primary));
    box-shadow: none;
}

/* ============================================
   Floating Label
   ============================================ */
.form-floating {
    position: relative;
}

.form-floating .form-input {
    padding-top: 1.5rem;
    padding-bottom: 0.5rem;
}

.form-floating .form-label {
    position: absolute;
    top: 50%;
    left: 0.75rem;
    transform: translateY(-50%);
    transition: all var(--transition-fast) ease-in-out;
    pointer-events: none;
    margin: 0;
    color: hsl(var(--muted-foreground));
}

.form-floating .form-input:focus + .form-label,
.form-floating .form-input:not(:placeholder-shown) + .form-label {
    top: 0.5rem;
    transform: translateY(0);
    font-size: var(--text-xs);
    color: hsl(var(--primary));
}

/* ============================================
   Input Group
   ============================================ */
.input-group {
    display: flex;
}

.input-group .form-input {
    border-radius: 0;
}

.input-group .form-input:first-child {
    border-top-left-radius: calc(var(--radius) - 2px);
    border-bottom-left-radius: calc(var(--radius) - 2px);
}

.input-group .form-input:last-child {
    border-top-right-radius: calc(var(--radius) - 2px);
    border-bottom-right-radius: calc(var(--radius) - 2px);
}

.input-group-text {
    display: flex;
    align-items: center;
    padding: 0 0.75rem;
    font-size: var(--text-sm);
    color: hsl(var(--muted-foreground));
    background-color: hsl(var(--muted));
    border: 1px solid hsl(var(--input));
}

.input-group-text:first-child {
    border-right: none;
    border-top-left-radius: calc(var(--radius) - 2px);
    border-bottom-left-radius: calc(var(--radius) - 2px);
}

.input-group-text:last-child {
    border-left: none;
    border-top-right-radius: calc(var(--radius) - 2px);
    border-bottom-right-radius: calc(var(--radius) - 2px);
}

.input-group .btn {
    border-radius: 0;
}

.input-group .btn:last-child {
    border-top-right-radius: calc(var(--radius) - 2px);
    border-bottom-right-radius: calc(var(--radius) - 2px);
}
