/* 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 {
    border: 1px solid #495057 !important;
    background-color: #2b2f33;
    color: #e9ecef;
}

[data-bs-theme="dark"] .form-control:focus,
[data-bs-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] {
    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 {
    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, #1a73e8 0%, #0d9488 100%);
    color: #fff;
    border-radius: 0.5rem 0.5rem 0 0;
    padding: 0.65rem 1rem;
    border-bottom: none;
}

.form-card .card-header h2,
.form-card .card-header h3,
.form-card .card-header h4,
.form-card .card-header h5,
.form-card .card-header h6 {
    margin: 0;
    font-weight: 600;
    color: #fff;
}

/* Collapsible card-header chevron indicator */
.form-card .card-header[data-bs-toggle="collapse"] {
    cursor: pointer;
}

.form-card .card-header .collapse-chevron {
    transition: transform 0.3s ease;
    font-size: 0.85rem;
    opacity: 0.8;
}

.form-card .card-header.collapsed .collapse-chevron {
    transform: rotate(-90deg);
}

.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 {
    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 {
    background-color: #2d3238;
    border-radius: 0 0 0.5rem 0.5rem;
}

[data-bs-theme="dark"] .form-card .card-header {
    background: linear-gradient(135deg, #1565c0 0%, #0b7a72 100%);
    color: #fff;
    padding: 0.65rem 1rem;
}

[data-bs-theme="dark"] .form-card .card-header h2,
[data-bs-theme="dark"] .form-card .card-header h3,
[data-bs-theme="dark"] .form-card .card-header h4,
[data-bs-theme="dark"] .form-card .card-header h5,
[data-bs-theme="dark"] .form-card .card-header h6 {
    color: #fff;
}

[data-bs-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 {
    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 {
    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;
}

/* Theme toggle in sidebar/topbar — keep icon and switch aligned in both modes.
   Must override app-dark.css which uses html[data-bs-theme=dark] .form-check (specificity 0,2,1). */
.theme-toggle .form-check,
[data-bs-theme="dark"] .theme-toggle .form-check {
    margin-bottom: 0;
    min-height: auto;
    padding-left: 2.5em;
}

.theme-toggle .form-check-input,
[data-bs-theme="dark"] .theme-toggle .form-check-input {
    width: 2em;
    height: 1.2em;
    margin-left: -2.5em;
}

/* 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 {
    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 {
    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 {
    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 {
    border-bottom-color: #495057;
}

[data-bs-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 {
    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 {
    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 {
    padding-top: 1.25rem;
}

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

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

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

/* ==========================================================================
   Status Indicator Cards
   ========================================================================== */

.form-card.status-danger {
    border-left: 4px solid #dc3545;
}

.form-card.status-danger .card-header {
    background: linear-gradient(135deg, #dc3545 0%, #c62828 100%);
}

.form-card.status-warning {
    border-left: 4px solid #f59e0b;
}

.form-card.status-warning .card-header {
    background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
}

.form-card.status-info {
    border-left: 4px solid #06b6d4;
}

.form-card.status-info .card-header {
    background: linear-gradient(135deg, #06b6d4 0%, #0891b2 100%);
}

[data-bs-theme="dark"] .form-card.status-danger .card-header {
    background: linear-gradient(135deg, #b91c1c 0%, #991b1b 100%);
}

[data-bs-theme="dark"] .form-card.status-warning .card-header {
    background: linear-gradient(135deg, #d97706 0%, #b45309 100%);
}

[data-bs-theme="dark"] .form-card.status-info .card-header {
    background: linear-gradient(135deg, #0891b2 0%, #0e7490 100%);
}

/* ==========================================================================
   Compact Form Card (for dense General Info panels)
   ========================================================================== */

.form-card-compact .card-header {
    padding: 0.6rem 1rem;
}

.form-card-compact .card-header h5,
.form-card-compact .card-header h4 {
    font-size: 0.95rem;
}

.form-card-compact .card-body {
    padding: 0.75rem 1rem;
}

.form-card-compact .table {
    font-size: 0.875rem;
    margin-bottom: 0;
}

.form-card-compact .table td,
.form-card-compact .table th {
    padding: 0.35rem 0.5rem;
}

/* Dark mode: preserve compact sizing (override app-dark.css padding reset) */
[data-bs-theme="dark"] .form-card-compact .card-header {
    padding: 0.6rem 1rem;
}

[data-bs-theme="dark"] .form-card-compact .card-header h5,
[data-bs-theme="dark"] .form-card-compact .card-header h4 {
    font-size: 0.95rem;
}

[data-bs-theme="dark"] .form-card-compact .card-body {
    padding: 0.75rem 1rem;
}

/* ==========================================================================
   Call Events Detail Panel (sub-events expansion)
   ========================================================================== */

.call-events-detail {
    padding: 12px 20px;
    background-color: #f0f4f8;
    border-left: 3px solid #0d6efd;
    margin: 0 0 2px 0;
    font-size: 0.875rem;
}

/* Call events table styling */
.ce-table th {
    font-size: 0.85rem;
    white-space: nowrap;
}
.ce-table td {
    font-size: 0.875rem;
    vertical-align: middle;
}
.ce-row:hover {
    filter: brightness(0.96);
}
[data-bs-theme="dark"] .ce-row:hover {
    filter: brightness(1.1);
}
.ce-detail-row td {
    padding: 0 !important;
    background: transparent !important;
}
.ce-sortable:hover {
    background-color: rgba(0, 0, 0, 0.05);
}
[data-bs-theme="dark"] .ce-sortable:hover {
    background-color: rgba(255, 255, 255, 0.05);
}


.call-events-detail p {
    margin-bottom: 4px;
    padding: 2px 0;
}

.call-events-detail p:last-child {
    margin-bottom: 0;
}

[data-bs-theme="dark"] .call-events-detail {
    background-color: #1a1d21;
    border-left-color: #3b82f6;
}

/* Popover max-width for call records */
.popover {
    max-width: 360px;
}

/* Call record filter buttons */
.cdr-filter-group .btn.active {
    font-weight: 600;
}

/* ==========================================================================
   Sidebar Light-Mode Contrast
   ========================================================================== */

.sidebar-wrapper {
    background-color: #e8eaef !important;
    border-right: 1px solid #dee2e6;
}

[data-bs-theme="dark"] .sidebar-wrapper {
    background-color: #1e1e2d !important;
    border-right: 1px solid #2d2d3f;
}

/* ==========================================================================
   Sidebar Scroll Fix
   ========================================================================== */

/* Flex child needs min-height:0 to shrink below content and allow overflow */
.sidebar-wrapper .sidebar-menu {
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    position: relative; /* required for PerfectScrollbar */
}

/* Hide PerfectScrollbar rails on the wrapper — scrolling is on .sidebar-menu */
.sidebar-wrapper > .ps__rail-x,
.sidebar-wrapper > .ps__rail-y {
    display: none !important;
}

/* Thin native scrollbar fallback for sidebar menu */
.sidebar-menu::-webkit-scrollbar {
    width: 4px;
}
.sidebar-menu::-webkit-scrollbar-track {
    background: transparent;
}
.sidebar-menu::-webkit-scrollbar-thumb {
    background-color: rgba(128, 128, 128, 0.3);
    border-radius: 4px;
}
.sidebar-menu::-webkit-scrollbar-thumb:hover {
    background-color: rgba(128, 128, 128, 0.5);
}

/* ==========================================================================
   AG Grid: Column Resize Handle
   ========================================================================== */

/* Widen the hit area and show col-resize cursor */
.ag-header-cell-resize {
    width: 10px !important;
    cursor: col-resize !important;
    z-index: 1;
}

/* Visible drag indicator on hover */
.ag-header-cell-resize::after {
    content: '';
    position: absolute;
    top: 25%;
    bottom: 25%;
    left: 50%;
    transform: translateX(-50%);
    width: 2px;
    border-radius: 1px;
    background-color: transparent;
    transition: background-color 0.15s;
}
.ag-header-cell-resize:hover::after {
    background-color: rgba(0, 0, 0, 0.3);
}
[data-bs-theme="dark"] .ag-header-cell-resize:hover::after {
    background-color: rgba(255, 255, 255, 0.4);
}
