/* Enhanced Form Styling for Bootstrap 5 Admin Pages
 * Fixes visibility issues with form controls on white backgrounds
 * and provides modern card-based form layouts
 */

/* ==========================================================================
   Form Control Visibility Fixes
   ========================================================================== */

/* Light mode - enhance borders for better visibility */
.form-control,
.form-select {
    border: 1px solid #ced4da !important;
    background-color: #fff;
}

.form-control:focus,
.form-select:focus {
    border-color: #86b7fe !important;
    box-shadow: 0 0 0 0.25rem rgba(13, 110, 253, 0.25) !important;
}

.form-control:disabled,
.form-select:disabled,
.form-control[readonly] {
    background-color: #e9ecef;
    border-color: #ced4da !important;
}

/* Dark mode - enhance borders for visibility */
[data-bs-theme="dark"] .form-control,
[data-bs-theme="dark"] .form-select,
.theme-dark .form-control,
.theme-dark .form-select {
    border: 1px solid #495057 !important;
    background-color: #2b2f33;
    color: #e9ecef;
}

[data-bs-theme="dark"] .form-control:focus,
[data-bs-theme="dark"] .form-select:focus,
.theme-dark .form-control:focus,
.theme-dark .form-select:focus {
    border-color: #86b7fe !important;
    background-color: #2b2f33;
    box-shadow: 0 0 0 0.25rem rgba(13, 110, 253, 0.25) !important;
}

[data-bs-theme="dark"] .form-control:disabled,
[data-bs-theme="dark"] .form-select:disabled,
[data-bs-theme="dark"] .form-control[readonly],
.theme-dark .form-control:disabled,
.theme-dark .form-select:disabled,
.theme-dark .form-control[readonly] {
    background-color: #1e2124;
    border-color: #495057 !important;
}

/* Textarea specific styling */
textarea.form-control {
    min-height: 100px;
}

/* Input group enhancements */
.input-group-text {
    border: 1px solid #ced4da;
    background-color: #f8f9fa;
}

[data-bs-theme="dark"] .input-group-text,
.theme-dark .input-group-text {
    border: 1px solid #495057;
    background-color: #343a40;
    color: #e9ecef;
}

/* ==========================================================================
   Modern Form Card Layout
   ========================================================================== */

.form-card {
    background: #fff;
    border-radius: 0.5rem;
    border: 1px solid #adb5bd;
    box-shadow: 0 0.25rem 0.75rem rgba(0, 0, 0, 0.1);
    margin-bottom: 1.5rem;
}

.form-card .card-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #fff;
    border-radius: 0.5rem 0.5rem 0 0;
    padding: 1rem 1.25rem;
    border-bottom: none;
}

.form-card .card-header h5,
.form-card .card-header h4 {
    margin: 0;
    font-weight: 600;
}

.form-card .card-body {
    padding: 1.5rem;
    background-color: #fff;
    border-radius: 0 0 0.5rem 0.5rem;
}

/* Light mode page background contrast */
#main-content {
    background-color: #f5f7fa;
}

[data-bs-theme="dark"] .form-card,
.theme-dark .form-card {
    background: #2d3238;
    border: 1px solid #5c6370;
    box-shadow: 0 0.25rem 1rem rgba(0, 0, 0, 0.4);
}

[data-bs-theme="dark"] .form-card .card-body,
.theme-dark .form-card .card-body {
    background-color: #2d3238;
    border-radius: 0 0 0.5rem 0.5rem;
}

[data-bs-theme="dark"] .form-card .card-header,
.theme-dark .form-card .card-header {
    background: linear-gradient(135deg, #5a6abf 0%, #7b5ba8 100%);
}

[data-bs-theme="dark"] #main-content,
.theme-dark #main-content {
    background-color: #1e2227;
}

/* ==========================================================================
   Form Group Styling
   ========================================================================== */

.form-group {
    margin-bottom: 1rem;
}

.form-group label,
.form-label {
    font-weight: 500;
    margin-bottom: 0.5rem;
    color: #495057;
}

[data-bs-theme="dark"] .form-group label,
[data-bs-theme="dark"] .form-label,
.theme-dark .form-group label,
.theme-dark .form-label {
    color: #adb5bd;
}

/* Required field indicator */
.form-label.required::after,
.form-group label.required::after {
    content: " *";
    color: #dc3545;
}

/* Form help text */
.form-text {
    font-size: 0.875rem;
    color: #6c757d;
    margin-top: 0.25rem;
}

[data-bs-theme="dark"] .form-text,
.theme-dark .form-text {
    color: #9ca3af;
}

/* ==========================================================================
   Radio and Checkbox Enhancements
   ========================================================================== */

.form-check {
    padding-left: 1.75em;
    margin-bottom: 0.5rem;
}

.form-check-input {
    width: 1.25em;
    height: 1.25em;
    margin-top: 0.125em;
    border: 2px solid #adb5bd;
}

.form-check-input:checked {
    background-color: #0d6efd;
    border-color: #0d6efd;
}

.form-check-label {
    cursor: pointer;
}

/* Inline radio/checkbox groups */
.form-check-inline {
    display: inline-flex;
    align-items: center;
    margin-right: 1.5rem;
}

/* Yes/No toggle styling */
.btn-group-toggle {
    display: inline-flex;
}

.btn-group-toggle .btn {
    border: 1px solid #ced4da;
}

.btn-group-toggle .btn-check:checked + .btn {
    background-color: #0d6efd;
    border-color: #0d6efd;
    color: #fff;
}

/* ==========================================================================
   Form Actions / Button Bar
   ========================================================================== */

.form-actions {
    display: flex;
    gap: 0.75rem;
    padding-top: 1.5rem;
    margin-top: 1.5rem;
    border-top: 1px solid #e9ecef;
}

[data-bs-theme="dark"] .form-actions,
.theme-dark .form-actions {
    border-top-color: #495057;
}

.form-actions .btn {
    min-width: 120px;
}

/* Sticky action bar for long forms */
.form-actions-sticky {
    position: sticky;
    bottom: 0;
    background: #fff;
    padding: 1rem 1.5rem;
    margin: 1.5rem -1.5rem -1.5rem;
    border-top: 1px solid #e9ecef;
    box-shadow: 0 -0.125rem 0.25rem rgba(0, 0, 0, 0.075);
}

[data-bs-theme="dark"] .form-actions-sticky,
.theme-dark .form-actions-sticky {
    background: #2b2f33;
    border-top-color: #495057;
}

/* ==========================================================================
   Legacy Table-Based Form Fixes
   ========================================================================== */

/* Improve visibility of form controls in table layouts */
.table .form-control,
.table .form-select,
.table-responsive .form-control,
.table-responsive .form-select {
    border: 1px solid #ced4da !important;
}

[data-bs-theme="dark"] .table .form-control,
[data-bs-theme="dark"] .table .form-select,
[data-bs-theme="dark"] .table-responsive .form-control,
[data-bs-theme="dark"] .table-responsive .form-select,
.theme-dark .table .form-control,
.theme-dark .table .form-select,
.theme-dark .table-responsive .form-control,
.theme-dark .table-responsive .form-select {
    border: 1px solid #495057 !important;
}

/* Fix label alignment in table forms */
.table td:first-child {
    font-weight: 500;
    vertical-align: middle;
    white-space: nowrap;
    padding-right: 1rem;
}

/* Validation message styling in tables */
.table .field-validation-error,
.table .text-danger {
    font-size: 0.875rem;
}

/* ==========================================================================
   Form Sections
   ========================================================================== */

.form-section {
    margin-bottom: 2rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid #e9ecef;
}

.form-section:last-child {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}

.form-section-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: #495057;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid #0d6efd;
    display: inline-block;
}

[data-bs-theme="dark"] .form-section,
.theme-dark .form-section {
    border-bottom-color: #495057;
}

[data-bs-theme="dark"] .form-section-title,
.theme-dark .form-section-title {
    color: #e9ecef;
}

/* ==========================================================================
   Row/Grid Form Layouts
   ========================================================================== */

.form-row {
    display: flex;
    flex-wrap: wrap;
    margin-right: -0.5rem;
    margin-left: -0.5rem;
}

.form-row > .col,
.form-row > [class*="col-"] {
    padding-right: 0.5rem;
    padding-left: 0.5rem;
}

/* Responsive form columns */
@media (min-width: 768px) {
    .form-col-2 {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 1rem;
    }

    .form-col-3 {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        gap: 1rem;
    }
}

/* ==========================================================================
   Container Fixes
   ========================================================================== */

/* Fix container width for form pages */
.container-formadmin {
    max-width: 1200px;
}

/* ==========================================================================
   Button Improvements
   ========================================================================== */

/* Nav pills as button stack */
.nav-pills.nav-stacked > li {
    margin-bottom: 0.5rem;
}

.nav-pills.nav-stacked > li > .btn,
.nav-pills.nav-stacked > li > button {
    width: 100%;
    text-align: left;
}

/* Fix button group in fixed position sidebar */
.fixedpos20 {
    position: sticky;
    top: 100px;
}

.fixedpos20 .nav-stacked {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.fixedpos20 .nav-stacked li {
    list-style: none;
}

.fixedpos20 .nav-stacked .btn {
    display: block;
    width: 100%;
}

/* ==========================================================================
   Sidebar Card Styling
   ========================================================================== */

.col-lg-3 .card.position-sticky,
.col-md-4 .card.position-sticky {
    border: 1px solid #adb5bd;
    box-shadow: 0 0.25rem 0.75rem rgba(0, 0, 0, 0.1);
}

.col-lg-3 .card.position-sticky .card-header,
.col-md-4 .card.position-sticky .card-header {
    background-color: #f8f9fa;
    border-bottom: 1px solid #adb5bd;
}

.col-lg-3 .card.position-sticky .card-body,
.col-md-4 .card.position-sticky .card-body {
    padding-top: 1.25rem;
}

[data-bs-theme="dark"] .col-lg-3 .card.position-sticky,
[data-bs-theme="dark"] .col-md-4 .card.position-sticky,
.theme-dark .col-lg-3 .card.position-sticky,
.theme-dark .col-md-4 .card.position-sticky {
    border: 1px solid #5c6370;
    box-shadow: 0 0.25rem 1rem rgba(0, 0, 0, 0.4);
    background-color: #2d3238;
}

[data-bs-theme="dark"] .col-lg-3 .card.position-sticky .card-header,
[data-bs-theme="dark"] .col-md-4 .card.position-sticky .card-header,
.theme-dark .col-lg-3 .card.position-sticky .card-header,
.theme-dark .col-md-4 .card.position-sticky .card-header {
    background-color: #3a4049;
    border-bottom: 1px solid #5c6370;
}

[data-bs-theme="dark"] .col-lg-3 .card.position-sticky .card-body,
[data-bs-theme="dark"] .col-md-4 .card.position-sticky .card-body,
.theme-dark .col-lg-3 .card.position-sticky .card-body,
.theme-dark .col-md-4 .card.position-sticky .card-body {
    padding-top: 1.25rem;
}

/* ==========================================================================
   All Card Enhancements (applies to cards in admin pages)
   ========================================================================== */

.card {
    border: 1px solid #adb5bd;
}

[data-bs-theme="dark"] .card,
.theme-dark .card {
    border: 1px solid #5c6370;
}
