/* ========================================
   Form Controls CSS
   Sourced from saas/temp/form-controls.css — full theme styles for forms
   ======================================== */

/* CSS Variables - Matching Theme */
:root {
    --form-primary-color: #2E5C3E;
    --form-secondary-color: #4A7C59;
    --form-accent-color: #6B9B7A;
    --form-light-green: #E8F5E8;
    --form-background-color: #F8FDF8;
    --form-text-dark: #1A3A1A;
    --form-text-medium: #2E5C3E;
    --form-white: #FFFFFF;
    --form-border-color: #D1E7DD;
    --form-error-color: #dc3545;
    --form-success-color: #28a745;
    --form-warning-color: #ffc107;
    --form-shadow: 0 4px 20px rgba(46, 92, 62, 0.1);
    --form-border-radius: 12px;
    --form-font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* ========================================
   Base Form Styling
   ======================================== */

.rp-form {
    font-family: var(--form-font-family);
    color: var(--form-text-dark);
    line-height: 1.6;
}

.rp-form-container {
    background: #FFFFFF;
    padding: 2rem;
    border-radius: 12px;
    box-shadow: var(--form-shadow);
    border: 1px solid var(--form-border-color);
    max-width: clamp(640px, 50vw, 1100px); /* responsive: min 640px, ideal 50% of viewport, max 1100px */
    margin: 20px auto;
}

/* ========================================
   Form Groups and Labels
   ======================================== */

.rp-form-group {
    margin-bottom: 1.5rem;
    position: relative;
}

.rp-form-group.required .rp-form-label::after {
    content: ' *';
    color: var(--form-error-color);
    font-weight: bold;
}

.rp-form-label {
    display: block;
    margin-bottom: 0.5rem;
    color: var(--form-text-medium);
    font-weight: 500;
    font-size: 0.95rem;
    transition: color 0.3s ease;
}

.rp-form-label.focused {
    color: var(--form-primary-color);
}

/* ========================================
   Input Controls
   ======================================== */

.rp-form-control {
    width: 100%;
    padding: 1rem;
    border: 2px solid var(--form-border-color);
    border-radius: var(--form-border-radius);
    font-size: 1rem;
    font-family: var(--form-font-family);
    color: var(--form-text-dark);
    background: var(--form-background-color);
    transition: all 0.3s ease;
    outline: none;
    box-sizing: border-box;
}

.rp-form-control:focus {
    border-color: var(--form-primary-color);
    background: var(--form-white);
    box-shadow: 0 0 0 3px rgba(46, 92, 62, 0.1);
    transform: translateY(-1px);
}

.rp-form-control:hover:not(:focus) {
    border-color: var(--form-accent-color);
    background: var(--form-white);
}

.rp-form-control::placeholder {
    color: rgba(46, 92, 62, 0.5);
    font-style: italic;
}

/* Input States */
.rp-form-control.valid {
    border-color: var(--form-success-color);
    background: rgba(40, 167, 69, 0.05);
}

.rp-form-control.invalid {
    border-color: var(--form-error-color);
    background: rgba(220, 53, 69, 0.05);
}

.rp-form-control:disabled {
    background: #f8f9fa;
    color: #6c757d;
    border-color: #dee2e6;
    cursor: not-allowed;
    opacity: 0.7;
}

/* ========================================
   Specific Input Types
   ======================================== */

/* Text Inputs */
.rp-form-control[type="text"],
.rp-form-control[type="email"],
.rp-form-control[type="password"],
.rp-form-control[type="tel"],
.rp-form-control[type="url"] {
    height: 48px;
}

/* Number Inputs */
.rp-form-control[type="number"] {
    text-align: right;
    font-family: 'Courier New', monospace;
    font-weight: 500;
}

/* Date Inputs */
.rp-form-control[type="date"],
.rp-form-control[type="datetime-local"] {
    font-family: 'Courier New', monospace;
}

/* Textarea */
.rp-form-control.textarea {
    min-height: 120px;
    resize: vertical;
    padding-top: 1rem;
    line-height: 1.5;
}

/* ========================================
   Select Dropdowns
   ======================================== */

.rp-form-select {
    width: 100%;
    padding: 1rem;
    border: 2px solid var(--form-border-color);
    border-radius: var(--form-border-radius);
    font-size: 1rem;
    font-family: var(--form-font-family);
    color: var(--form-text-dark);
    background: var(--form-background-color);
    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='%236b9b7a' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='m6 8 4 4 4-4'/%3e%3c/svg%3e");
    background-position: right 1rem center;
    background-repeat: no-repeat;
    background-size: 1.5em 1.5em;
    padding-right: 3rem;
    appearance: none;
    cursor: pointer;
    transition: all 0.3s ease;
    outline: none;
}

.rp-form-select:focus {
    border-color: var(--form-primary-color);
    background-color: var(--form-white);
    box-shadow: 0 0 0 3px rgba(46, 92, 62, 0.1);
    transform: translateY(-1px);
}

.rp-form-select:hover:not(:focus) {
    border-color: var(--form-accent-color);
    background-color: var(--form-white);
}

/* ========================================
   Checkboxes and Radio Buttons
   ======================================== */

.rp-form-check {
    display: flex;
    align-items: center;
    margin-bottom: 0.75rem;
    cursor: pointer;
}

.rp-form-check-input {
    width: 20px;
    height: 20px;
    margin-right: 0.75rem;
    border: 2px solid var(--form-border-color);
    border-radius: 4px;
    background: var(--form-white);
    cursor: pointer;
    transition: all 0.3s ease;
    appearance: none;
    outline: none;
    position: relative;
    flex-shrink: 0;
}

.rp-form-check-input[type="radio"] {
    border-radius: 50%;
}

.rp-form-check-input:checked {
    background: var(--form-primary-color);
    border-color: var(--form-primary-color);
}

.rp-form-check-input:checked::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.rp-form-check-input[type="checkbox"]:checked::after {
    width: 6px;
    height: 10px;
    border: 2px solid white;
    border-top: none;
    border-left: none;
    transform: translate(-50%, -60%) rotate(45deg);
}

.rp-form-check-input[type="radio"]:checked::after {
    width: 8px;
    height: 8px;
    background: white;
    border-radius: 50%;
}

.rp-form-check-input:focus {
    box-shadow: 0 0 0 3px rgba(46, 92, 62, 0.2);
}

.rp-form-check-label {
    color: var(--form-text-dark);
    font-size: 0.95rem;
    cursor: pointer;
    user-select: none;
}

/* ========================================
   Buttons
   ======================================== */

.rp-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 1rem 2rem;
    border: none;
    border-radius: var(--form-border-radius);
    font-size: 1rem;
    font-weight: 600;
    font-family: var(--form-font-family);
    text-decoration: none;
    cursor: pointer;
    transition: all 0.3s ease;
    outline: none;
    position: relative;
    overflow: hidden;
    min-height: 48px;
    gap: 0.5rem;
}

.rp-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none !important;
}

/* Primary Button */
.rp-btn-primary {
    background: var(--form-primary-color);
    color: var(--form-white);
    box-shadow: var(--form-shadow);
}

.rp-btn-primary:hover:not(:disabled) {
    background: var(--form-secondary-color);
    transform: translateY(-2px);
    box-shadow: 0 6px 25px rgba(46, 92, 62, 0.2);
}

.rp-btn-primary:active {
    transform: translateY(0);
}

/* Secondary Button */
.rp-btn-secondary {
    background: transparent;
    color: var(--form-primary-color);
    border: 2px solid var(--form-primary-color);
}

.rp-btn-secondary:hover:not(:disabled) {
    background: var(--form-primary-color);
    color: var(--form-white);
    transform: translateY(-2px);
}

/* Success Button */
.rp-btn-success {
    background: var(--form-success-color);
    color: var(--form-white);
}

.rp-btn-success:hover:not(:disabled) {
    background: #218838;
    transform: translateY(-2px);
}

/* Danger Button */
.rp-btn-danger {
    background: var(--form-error-color);
    color: var(--form-white);
}

.rp-btn-danger:hover:not(:disabled) {
    background: #c82333;
    transform: translateY(-2px);
}

/* Button Sizes */
.rp-btn-sm {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    min-height: 36px;
}

.rp-btn-lg {
    padding: 1.25rem 2.5rem;
    font-size: 1.125rem;
    min-height: 56px;
}

.rp-btn-block {
    width: 100%;
}

/* ========================================
   Input Groups and Add-ons
   ======================================== */

.rp-input-group {
    display: flex;
    width: 100%;
    position: relative;
}

.rp-input-group .rp-form-control {
    border-radius: 0;
    z-index: 2;
}

.rp-input-group .rp-form-control:first-child {
    border-top-left-radius: var(--form-border-radius);
    border-bottom-left-radius: var(--form-border-radius);
}

.rp-input-group .rp-form-control:last-child {
    border-top-right-radius: var(--form-border-radius);
    border-bottom-right-radius: var(--form-border-radius);
}

.rp-input-group-text {
    display: flex;
    align-items: center;
    padding: 1rem;
    background: var(--form-light-green);
    border: 2px solid var(--form-border-color);
    color: var(--form-text-medium);
    font-weight: 500;
    white-space: nowrap;
}

.rp-input-group-text:first-child {
    border-top-left-radius: var(--form-border-radius);
    border-bottom-left-radius: var(--form-border-radius);
    border-right: none;
}

.rp-input-group-text:last-child {
    border-top-right-radius: var(--form-border-radius);
    border-bottom-right-radius: var(--form-border-radius);
    border-left: none;
}

/* ========================================
   Validation Messages
   ======================================== */

.rp-form-feedback {
    display: block;
    margin-top: 0.5rem;
    font-size: 0.875rem;
    line-height: 1.4;
}

.rp-form-feedback.valid {
    color: var(--form-success-color);
}

.rp-form-feedback.invalid {
    color: var(--form-error-color);
}

.rp-form-feedback.warning {
    color: var(--form-warning-color);
}

.rp-form-feedback::before {
    content: '';
    display: inline-block;
    width: 16px;
    height: 16px;
    margin-right: 0.5rem;
    vertical-align: text-top;
    background-size: contain;
    background-repeat: no-repeat;
}

.rp-form-feedback.valid::before {
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%2328a745'%3e%3cpath fill-rule='evenodd' d='M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z' clip-rule='evenodd'/%3e%3c/svg%3e");
}

.rp-form-feedback.invalid::before {
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%23dc3545'%3e%3cpath fill-rule='evenodd' d='M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7 4a1 1 0 11-2 0 1 1 0 012 0zm-1-9a1 1 0 00-1 1v4a1 1 0 102 0V6a1 1 0 00-1-1z' clip-rule='evenodd'/%3e%3c/svg%3e");
}

/* ========================================
   Form Layout Helpers
   ======================================== */

.rp-form-row {
    display: flex;
    flex-wrap: wrap;
    margin: 0 -0.75rem;
}

.rp-form-col {
    flex: 1;
    padding: 0 0.75rem;
    min-width: 0;
}

.rp-form-col-auto {
    flex: 0 0 auto;
    width: auto;
    padding: 0 0.75rem;
}

.rp-form-col-6 {
    flex: 0 0 50%;
    max-width: 50%;
    padding: 0 0.75rem;
}

.rp-form-col-4 {
    flex: 0 0 33.333333%;
    max-width: 33.333333%;
    padding: 0 0.75rem;
}

.rp-form-col-3 {
    flex: 0 0 25%;
    max-width: 25%;
    padding: 0 0.75rem;
}

/* ========================================
   Loading States
   ======================================== */

.rp-btn.loading {
    pointer-events: none;
    opacity: 0.8;
}

.rp-btn.loading::after {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    margin: auto;
    border: 2px solid transparent;
    border-top-color: currentColor;
    border-radius: 50%;
    animation: rp-spin 1s linear infinite;
}

@keyframes rp-spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* ========================================
   Responsive Design
   ======================================== */

@media (max-width: 768px) {
    .rp-form-container {
        padding: 1.5rem;
    }
    
    .rp-form-control,
    .rp-form-select,
    .rp-btn {
        font-size: 16px; /* Prevents zoom on iOS */
    }
    
    .rp-form-row {
        margin: 0;
    }
    
    .rp-form-col,
    .rp-form-col-6,
    .rp-form-col-4,
    .rp-form-col-3 {
        flex: 0 0 100%;
        max-width: 100%;
        padding: 0;
        margin-bottom: 1rem;
    }
    
    .rp-btn-block {
        width: 100%;
    }
}

@media (max-width: 480px) {
    .rp-form-container {
        padding: 1rem;
        border-radius: 8px;
    }
    
    .rp-form-control,
    .rp-form-select {
        padding: 0.875rem;
    }
    
    .rp-btn {
        padding: 0.875rem 1.5rem;
    }
}

/* ========================================
   Focus Management and Accessibility
   ======================================== */

.rp-form-control:focus,
.rp-form-select:focus,
.rp-btn:focus,
.rp-form-check-input:focus {
    outline: 2px solid var(--form-primary-color);
    outline-offset: 2px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    :root {
        --form-border-color: #000;
        --form-text-dark: #000;
        --form-background-color: #fff;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .rp-form-control,
    .rp-form-select,
    .rp-btn,
    .rp-form-check-input {
        transition: none !important;
    }
    
    .rp-btn.loading::after {
        animation: none !important;
    }
}

/* ========================================
   Print Styles
   ======================================== */

@media print {
    .rp-btn {
        display: none !important;
    }
    
    .rp-form-control,
    .rp-form-select {
        border: 1px solid #000 !important;
        background: transparent !important;
        box-shadow: none !important;
    }
}

/* Button sizing: make .btn match .rp-btn height/appearance to align with Save button */
.btn,
.rp-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 40px; /* match data row height / header height rhythm */
    padding: 8px 14px;
    border-radius: 8px;
    font-size: 14px;
    line-height: 1;
    cursor: pointer;
    border: 1px solid transparent;
    background: #f3f6f3;
    color: var(--grid-text-dark, #1A3A1A);
}

/* Primary button style */
.rp-btn-primary {
    background: var(--grid-primary-color, #2E5C3E);
    color: var(--grid-white, #fff);
    border-color: transparent;
}

/* Add subtle hover/focus styles */
.btn:hover,
.rp-btn:hover,
.rp-btn-primary:hover {
    filter: brightness(0.97);
    transform: translateY(-1px);
}

.btn:focus,
.rp-btn:focus,
.rp-btn-primary:focus {
    outline: 2px solid rgba(46,92,62,0.2);
    outline-offset: 2px;
}
