/* KempIT Forms - Main Stylesheet */

/* Variables */
:root {
    --primary-color: #D35400; /* Burnt orange */
    --primary-dark: #A04000;
    --primary-light: #E67E22;
    --secondary-color: #2C3E50; /* Dark blue/gray */
    --light-color: #FFFFFF;
    --gray-light: #ECF0F1;
    --gray-medium: #BDC3C7;
    --gray-dark: #7F8C8D;
    --success-color: #27AE60;
    --danger-color: #E74C3C;
    --warning-color: #F39C12;
    --info-color: #3498DB;
    --font-main: 'Roboto', sans-serif;
    --font-heading: 'Montserrat', sans-serif;
    --shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    --text-on-primary: #FFFFFF; /* Text color on primary background */
}

/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-main);
    line-height: 1.6;
    color: var(--secondary-color);
    background-color: var(--gray-light);
}

a {
    color: var(--primary-color);
    text-decoration: none;
    transition: color 0.3s ease;
}

a:hover {
    color: var(--primary-dark);
}

/* Typography */
h1, h2, h3, h4, h5, h6 {
    font-family: var(--font-heading);
    margin-bottom: 1rem;
    color: var(--secondary-color);
}

h1 {
    font-size: 2.5rem;
    color: var(--primary-color);
}

h2 {
    font-size: 2rem;
}

h3 {
    font-size: 1.75rem;
}

p {
    margin-bottom: 1rem;
}

/* Layout */
.container {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 15px;
}

.row {
    display: flex;
    flex-wrap: wrap;
    margin: 0 -15px;
}

.col {
    flex: 1;
    padding: 0 15px;
}

/* Header */
.header {
    background-color: var(--light-color);
    box-shadow: var(--shadow);
    padding: 1rem 0;
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo {
    display: flex;
    align-items: center;
}

.logo img {
    height: 50px;
    margin-right: 10px;
}

.logo-text {
    font-family: var(--font-heading);
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary-color);
}

/* Navigation */
.nav {
    display: flex;
    align-items: center;
}

.nav-list {
    display: flex;
    list-style: none;
}

.nav-item {
    margin-left: 1.5rem;
}

.nav-link {
    color: var(--secondary-color);
    font-weight: 500;
    padding: 0.5rem;
    border-radius: 4px;
    transition: all 0.3s ease;
}

.nav-link:hover, .nav-link.active {
    color: var(--primary-color);
    background-color: rgba(211, 84, 0, 0.1);
}

/* Buttons */
.btn {
    display: inline-block;
    padding: 0.5rem 1rem;
    border-radius: 4px;
    font-weight: 500;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    border: none;
}

.btn-primary {
    background-color: var(--primary-color);
    color: var(--light-color);
}

.btn-primary:hover {
    background-color: var(--primary-dark);
    color: var(--light-color);
}

/* Modal styling */
.modal-footer .btn {
    width: auto !important;
    display: inline-block !important;
}

.modal-dialog {
    margin: 1.75rem auto;
}

.modal-content {
    border-radius: 8px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
}

.modal-header {
    border-top-left-radius: 8px;
    border-top-right-radius: 8px;
    padding: 1.25rem;
}

.modal-body {
    padding: 1.5rem;
}

.modal-footer {
    border-bottom-left-radius: 8px;
    border-bottom-right-radius: 8px;
    padding: 1.25rem;
}

/* Fix modal display */
.modal.fade {
    opacity: 0;
    transition: opacity 0.15s linear;
    display: none;
}

.modal.fade.show {
    opacity: 1;
    display: block;
}

.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 1040;
    width: 100vw;
    height: 100vh;
    background-color: #000;
}

.modal-backdrop.fade {
    opacity: 0;
}

.modal-backdrop.show {
    opacity: 0.5;
}

/* Ensure modals appear above other content */
.modal {
    z-index: 1050 !important;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    outline: 0;
}

/* Fix modal form fields */
.modal .form-control {
    z-index: auto;
    position: relative;
}

/* Fix Bootstrap 4 DataTables styling */
.table.dataTable thead th,
.table.dataTable.table-striped thead th,
.table.dataTable.table-bordered thead th,
.table.dataTable.table-hover thead th {
    color: white !important;
    background-color: var(--primary-color) !important;
}

/* Fix modal dialog positioning */
.modal-dialog {
    position: relative;
    width: auto;
    margin: 0.5rem;
    pointer-events: none;
    transform: translate(0, 0);
}

.modal.fade .modal-dialog {
    transition: transform 0.3s ease-out;
    transform: translate(0, -50px);
}

.modal.show .modal-dialog {
    transform: none;
}

@media (min-width: 576px) {
    .modal-dialog {
        max-width: 500px;
        margin: 1.75rem auto;
    }
}

/* Ensure text in primary headers is white */
.bg-primary h1, .bg-primary h2, .bg-primary h3, .bg-primary h4, .bg-primary h5, .bg-primary h6,
.card-header.bg-primary h1, .card-header.bg-primary h2, .card-header.bg-primary h3, 
.card-header.bg-primary h4, .card-header.bg-primary h5, .card-header.bg-primary h6,
.bg-primary th {
    color: white !important;
}

/* Ensure table headers in primary backgrounds have white text */
.bg-primary.text-white th,
thead.bg-primary th,
.bg-primary .text-white,
.bg-primary.text-white {
    color: white !important;
}

/* Fix bg-primary background color */
.bg-primary {
    background-color: var(--primary-color) !important;
    color: white !important;
}

/* Fix table headers with bg-primary */
thead.bg-primary, 
.bg-primary.text-white,
.card-header.bg-primary {
    background-color: var(--primary-color) !important;
    color: white !important;
}

/* Fix table headers specifically */
thead.bg-primary th {
    color: white !important;
    background-color: var(--primary-color) !important;
}

/* Fix badge colors */
.badge.bg-success {
    background-color: var(--success-color) !important;
    color: white !important;
}

.badge.bg-warning {
    background-color: var(--warning-color) !important;
    color: white !important;
}

.badge.bg-danger {
    background-color: var(--danger-color) !important;
    color: white !important;
}

.badge.bg-info {
    background-color: var(--info-color) !important;
    color: white !important;
}

/* DataTables pagination */
.dataTables_wrapper .dataTables_paginate .paginate_button {
    padding: 0.3em 0.8em;
    margin: 0 0.2em;
    border: 1px solid #ddd;
    border-radius: 4px;
}

.dataTables_wrapper .dataTables_paginate .paginate_button.current {
    background-color: var(--primary-color);
    color: var(--text-on-primary) !important;
    border-color: var(--primary-color);
}

/* Fix DataTables header styling */
table.dataTable thead th, 
table.dataTable thead td {
    color: white !important;
    background-color: var(--primary-color) !important;
}

.dataTables_wrapper .dataTables_paginate .pagination {
    display: inline-flex;
    margin: 0;
    padding: 0;
}

.dataTables_wrapper .dataTables_paginate .pagination li {
    display: inline-block;
    list-style-type: none;
}

.btn-secondary {
    background-color: var(--secondary-color);
    color: var(--light-color);
}

.btn-secondary:hover {
    background-color: #1a252f;
}

.btn-success {
    background-color: var(--success-color);
    color: var(--light-color);
}

.btn-danger {
    background-color: var(--danger-color);
    color: var(--light-color);
}

.btn-warning {
    background-color: var(--warning-color);
    color: var(--light-color);
}

.btn-info {
    background-color: var(--info-color);
    color: var(--light-color);
}

.btn-outline {
    background-color: transparent;
    border: 1px solid var(--primary-color);
    color: var(--primary-color);
}

.btn-outline:hover {
    background-color: var(--primary-color);
    color: var(--light-color);
}

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

/* Cards */
.card {
    background-color: var(--light-color);
    border-radius: 8px;
    box-shadow: var(--shadow);
    margin-bottom: 1.5rem;
    overflow: hidden;
}

.card-header {
    padding: 1rem;
    background-color: var(--primary-color);
    color: var(--light-color);
}

.card-body {
    padding: 1.5rem;
}

.card-footer {
    padding: 1rem;
    background-color: var(--gray-light);
    border-top: 1px solid var(--gray-medium);
}

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

.form-label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
}

.form-control {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--gray-medium);
    border-radius: 4px;
    font-family: var(--font-main);
    font-size: 1rem;
    transition: border-color 0.3s ease;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(211, 84, 0, 0.2);
}

.form-text {
    display: block;
    margin-top: 0.25rem;
    font-size: 0.875rem;
    color: var(--gray-dark);
}

.form-check {
    display: flex;
    align-items: center;
    margin-bottom: 0.5rem;
}

.form-check-input {
    margin-right: 0.5rem;
}

/* Alerts */
.alert {
    padding: 1rem;
    border-radius: 4px;
    margin-bottom: 1rem;
}

.alert-success {
    background-color: rgba(39, 174, 96, 0.2);
    color: var(--success-color);
    border: 1px solid var(--success-color);
}

.alert-danger {
    background-color: rgba(231, 76, 60, 0.2);
    color: var(--danger-color);
    border: 1px solid var(--danger-color);
}

.alert-warning {
    background-color: rgba(243, 156, 18, 0.2);
    color: var(--warning-color);
    border: 1px solid var(--warning-color);
}

.alert-info {
    background-color: rgba(52, 152, 219, 0.2);
    color: var(--info-color);
    border: 1px solid var(--info-color);
}

/* Tables */
.table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 1.5rem;
}

.table th, .table td {
    padding: 0.75rem;
    text-align: left;
    border-bottom: 1px solid var(--gray-medium);
}

.table th {
    background-color: var(--gray-light);
    font-weight: 600;
}

.table tr:hover {
    background-color: rgba(211, 84, 0, 0.05);
}

/* Utilities */
.text-center {
    text-align: center;
}

.text-right {
    text-align: right;
}

.text-primary {
    color: var(--primary-color);
}

.text-secondary {
    color: var(--secondary-color);
}

.text-success {
    color: var(--success-color);
}

.text-danger {
    color: var(--danger-color);
}

.text-warning {
    color: var(--warning-color);
}

.text-info {
    color: var(--info-color);
}

.bg-primary {
    background-color: var(--primary-color);
    color: var(--light-color);
}

.bg-secondary {
    background-color: var(--secondary-color);
    color: var(--light-color);
}

.bg-light {
    background-color: var(--light-color);
}

.bg-gray {
    background-color: var(--gray-light);
}

.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mt-4 { margin-top: 2rem; }
.mt-5 { margin-top: 2.5rem; }

.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }
.mb-4 { margin-bottom: 2rem; }
.mb-5 { margin-bottom: 2.5rem; }

.ml-1 { margin-left: 0.5rem; }
.ml-2 { margin-left: 1rem; }
.ml-3 { margin-left: 1.5rem; }
.ml-4 { margin-left: 2rem; }
.ml-5 { margin-left: 2.5rem; }

.mr-1 { margin-right: 0.5rem; }
.mr-2 { margin-right: 1rem; }
.mr-3 { margin-right: 1.5rem; }
.mr-4 { margin-right: 2rem; }
.mr-5 { margin-right: 2.5rem; }

.p-1 { padding: 0.5rem; }
.p-2 { padding: 1rem; }
.p-3 { padding: 1.5rem; }
.p-4 { padding: 2rem; }
.p-5 { padding: 2.5rem; }

.d-flex { display: flex; }
.flex-column { flex-direction: column; }
.justify-content-center { justify-content: center; }
.justify-content-between { justify-content: space-between; }
.align-items-center { align-items: center; }
.flex-wrap { flex-wrap: wrap; }

/* Login and Registration Forms */
.auth-container {
    max-width: 500px;
    margin: 2rem auto;
}

.auth-logo {
    text-align: center;
    margin-bottom: 2rem;
}

.auth-logo img {
    height: 80px;
}

/* Footer */
.footer {
    background-color: var(--secondary-color);
    color: var(--light-color);
    padding: 2rem 0;
    margin-top: 3rem;
}

.footer a {
    color: var(--gray-light);
}

.footer a:hover {
    color: var(--primary-light);
}

.footer-content {
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
}

.footer-section {
    flex: 1;
    min-width: 200px;
    margin-bottom: 1.5rem;
}

.footer-bottom {
    text-align: center;
    padding-top: 1.5rem;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    margin-top: 1.5rem;
}

/* Responsive */
@media (max-width: 768px) {
    .row {
        flex-direction: column;
    }
    
    .col {
        width: 100%;
        margin-bottom: 1rem;
    }
    
    .header-container {
        flex-direction: column;
    }
    
    .nav {
        margin-top: 1rem;
    }
    
    .nav-list {
        flex-direction: column;
        align-items: center;
    }
    
    .nav-item {
        margin: 0.5rem 0;
    }
    
    .footer-content {
        flex-direction: column;
    }
}

/* Pagination Styles */
.pagination-info {
    font-size: 1.1rem;
    font-weight: 500;
    padding: 0.5rem 1rem;
    background-color: #f5f5f5;
    border-radius: 4px;
    display: inline-block;
}

/* Print Styles */
@media print {
    .header, .footer, .nav, .btn, .card:last-child {
        display: none;
    }
    
    body {
        font-size: 12pt;
        background: white;
    }
    
    .container {
        width: 100%;
        max-width: none;
        padding: 0;
    }
    
    .card {
        box-shadow: none;
        border: 1px solid #ddd;
    }
    
    .print-only {
        display: block !important;
    }
    
    .no-print {
        display: none !important;
    }
}

/* Enhanced Form Preview Styles */
.modal-xl {
    max-width: 95%;
}

#formPreviewModal {
    z-index: 1055; /* Higher than default Bootstrap modal */
}

#formPreviewModal .modal-dialog {
    z-index: 1056; /* Above the modal itself */
    position: relative;
}

#formPreviewModal .modal-content {
    border: none;
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
    z-index: 1057; /* Above the dialog */
    position: relative;
}

#formPreviewModal .modal-body {
    z-index: 1058; /* Above the content */
    position: relative;
}

#formPreviewModal .preview-container {
    z-index: 1059; /* Above the body */
    position: relative;
}

#formPreviewModal #preview-form-wrapper {
    z-index: 1060; /* Above the container */
    position: relative;
}

#formPreviewModal #preview-form-content {
    z-index: 1061; /* Highest - where form controls live */
    position: relative;
}

/* Ensure all form controls have proper z-index and pointer events */
#formPreviewModal .form-control,
#formPreviewModal .form-check-input,
#formPreviewModal .btn,
#formPreviewModal select,
#formPreviewModal input,
#formPreviewModal textarea,
#formPreviewModal .form-check-label,
#formPreviewModal label {
    z-index: 1062; /* Highest priority for interactions */
    position: relative;
    pointer-events: auto; /* Ensure clicks work */
}

/* Ensure form groups don't block interactions */
#formPreviewModal .form-group,
#formPreviewModal .form-check {
    position: relative;
    z-index: auto;
    pointer-events: auto;
}

/* Debug - highlight clickable areas */
#formPreviewModal .form-control:hover,
#formPreviewModal .btn:hover,
#formPreviewModal .form-check-input:hover {
    outline: 2px solid #007bff;
    outline-offset: 1px;
}

/* Ensure no elements are blocking interactions */
#formPreviewModal * {
    pointer-events: auto !important;
}

/* But allow backdrop to be non-interactive */
#formPreviewModal.modal {
    pointer-events: auto;
}

#formPreviewModal .modal-backdrop {
    z-index: 1050; /* Below everything else */
    pointer-events: none;
}

.preview-controls {
    background: #f8f9fa;
    border-bottom: 1px solid #dee2e6;
    z-index: 1063; /* Above form controls */
    position: relative;
}

.preview-controls .form-control {
    z-index: 1064; /* Highest for control interactions */
    position: relative;
}

.preview-container {
    background: #f8f9fa;
}

#preview-form-wrapper {
    transition: max-width 0.3s ease;
}

/* Secure Form Styling for Preview */
.secure-form {
    font-family: var(--font-main);
    line-height: 1.6;
}

.secure-form .form-group {
    margin-bottom: 1.5rem;
}

.secure-form .form-label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: var(--secondary-color);
}

.secure-form .form-control {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid #ced4da;
    border-radius: 4px;
    font-size: 1rem;
    transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
}

.secure-form .form-control:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(211, 84, 0, 0.1);
}

.secure-form .form-check {
    display: flex;
    align-items: center;
    margin-bottom: 0.5rem;
}

.secure-form .form-check-input {
    margin-right: 0.5rem;
    margin-top: 0;
}

.secure-form .form-check-inline {
    display: inline-flex;
    margin-right: 1rem;
}

.secure-form .form-check-inline .form-check {
    margin-bottom: 0;
}

.secure-form .text-danger {
    color: var(--danger-color) !important;
}

.secure-form .form-divider {
    border: none;
    border-top: 2px solid #e9ecef;
    margin: 2rem 0;
}

.secure-form h2 {
    font-family: var(--font-heading);
    font-size: 1.75rem;
    font-weight: 600;
    color: var(--secondary-color);
    margin-bottom: 1rem;
}

.secure-form h3 {
    font-family: var(--font-heading);
    font-size: 1.5rem;
    font-weight: 500;
    color: var(--secondary-color);
    margin-bottom: 0.75rem;
}

.secure-form p {
    color: var(--secondary-color);
    margin-bottom: 1rem;
}

/* Form Layout Classes */
.secure-form .form-group-half {
    width: 48%;
    display: inline-block;
    margin-right: 2%;
}

.secure-form .form-group-third {
    width: 31.33%;
    display: inline-block;
    margin-right: 2%;
}

.secure-form .form-group-quarter {
    width: 23%;
    display: inline-block;
    margin-right: 2%;
}

.secure-form .form-group-new-row {
    clear: both;
}

/* Preview Result Alerts */
.preview-container .alert {
    border-radius: 6px;
    padding: 1rem;
    margin-bottom: 1.5rem;
}

.preview-container .alert h5 {
    margin-bottom: 0.5rem;
}

.preview-container .alert details {
    margin-top: 0.5rem;
}

.preview-container .alert pre {
    background: rgba(0,0,0,0.05);
    padding: 0.5rem;
    border-radius: 3px;
    font-size: 0.875rem;
    margin-top: 0.5rem;
}

/* Loading Button Animation */
.btn .fa-spinner {
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Repeating Section Styling for Preview */
.secure-form .repeating-section {
    border: 2px solid #e9ecef;
    border-radius: 8px;
    padding: 1rem;
    margin-bottom: 1.5rem;
    background: #f8f9fa;
}

.secure-form .repeating-section h5 {
    color: #6c757d;
    border-bottom: 1px solid #dee2e6;
    padding-bottom: 0.5rem;
    margin-bottom: 1rem;
}

.secure-form .repeating-instance {
    border: 1px solid #dee2e6;
    border-radius: 4px;
    padding: 1rem;
    margin-bottom: 1rem;
    background: white;
}

.secure-form .repeating-instance small {
    color: #6c757d;
    font-weight: 500;
    display: block;
    margin-bottom: 0.5rem;
}

.secure-form .repeating-section .btn-outline-primary {
    border-color: var(--primary-color);
    color: var(--primary-color);
    margin-top: 0.5rem;
}

.secure-form .repeating-section .btn-outline-primary:hover {
    background-color: var(--primary-color);
    border-color: var(--primary-color);
    color: white;
}

/* Responsive Preview */
@media (max-width: 768px) {
    .modal-xl {
        max-width: 98%;
        margin: 0.5rem;
    }

    .preview-controls .row {
        flex-direction: column;
    }

    .preview-controls .col-md-4 {
        margin-bottom: 0.5rem;
    }

    .secure-form .form-group-half,
    .secure-form .form-group-third,
    .secure-form .form-group-quarter {
        width: 100%;
        display: block;
        margin-right: 0;
    }
}
