/* Themed Components CSS - Comprehensive Theming System */

/* Base themed component styles */
.themed-component {
    transition: all 0.2s ease-in-out;
}

/* CSS Variables for theming */
:root {
    --theme-primary-color: #007bff;
    --theme-secondary-color: #6c757d;
    --theme-background-color: #ffffff;
    --theme-action-button-color: #198754;
    --theme-delete-button-color: #dc3545;
    --theme-cancel-button-color: #6c757d;
    --theme-link-color: #0d6efd;
    --theme-input-border-color: #ced4da;
    --theme-button-border-radius: 0.375rem;
    --theme-primary-color-rgb: 0, 123, 255;
    --theme-secondary-color-rgb: 108, 117, 125;
    /* Table theming variables */
    --theme-table-header-bg: #f8f9fa;
    --theme-table-header-text: #495057;
    --theme-table-border: #dee2e6;
    --theme-table-hover: #f5f5f5;
    --theme-table-striped: #f8f9fa;
    --theme-table-selected: #cfe2ff;
}

/* Themed Button Styles */
.themed-button {
    transition: all 0.15s ease-in-out;
    font-weight: 500;
    border: 1px solid transparent;
    cursor: pointer;
}

.themed-button:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
    filter: brightness(1.05);
}

.themed-button:active:not(:disabled) {
    transform: translateY(0);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15);
}

.themed-button:focus:not(:disabled) {
    outline: none;
    box-shadow: 0 0 0 0.2rem rgba(var(--theme-primary-color-rgb), 0.25);
}

.themed-button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Themed Input Styles */
.themed-input {
    transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
    font-size: 16px; /* Prevents zoom on iOS */
}

.themed-input:focus {
    border-color: var(--theme-primary-color);
    box-shadow: 0 0 0 0.2rem rgba(var(--theme-primary-color-rgb), 0.25);
    outline: none;
}

/* AB#7419 review fix: use the derived placeholder color (already contrast-checked against the input
   surface) at full opacity. The previous 0.7 opacity silently dropped the rendered placeholder below
   the 4.5:1 the validator had confirmed, so validated != rendered. */
.themed-input::placeholder {
    color: var(--theme-placeholder-text-color, #6c757d);
    opacity: 1;
}

/* Themed Dropdown Styles */
.themed-dropdown, select.themed-dropdown {
    transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
    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='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='m6 8 4 4 4-4'/%3e%3c/svg%3e");
    background-position: right 0.5rem center;
    background-repeat: no-repeat;
    background-size: 1.5em 1.5em;
    min-width: 180px; /* Ensures dropdown is at least as wide as its content */
    max-width: 100%;
    white-space: normal; /* allow wrapping if needed */
}

.themed-dropdown:focus {
    border-color: var(--theme-primary-color);
    box-shadow: 0 0 0 0.2rem rgba(var(--theme-primary-color-rgb), 0.25);
    outline: none;
}

.themed-dropdown option {
    white-space: normal;
    overflow: visible;
    text-overflow: unset;
}

.themed-dropdown-rounded {
    border-radius: 1.5rem !important;
}

.themed-dropdown-standard {
    border-radius: var(--theme-button-border-radius);
}

/* Themed Card Styles */
.themed-card {
    border: 1px solid rgba(0, 0, 0, 0.125);
    transition: box-shadow 0.15s ease-in-out;
    background-color: var(--theme-background-color);
}

.themed-card:hover {
    box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15);
}

.themed-card.shadow {
    box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075);
}

/* Themed Link Styles */
.themed-link {
    color: var(--theme-link-color);
    text-decoration: none;
    transition: color 0.15s ease-in-out, filter 0.15s ease-in-out;
}

.themed-link:hover {
    color: var(--theme-link-color);
    filter: brightness(1.1);
    text-decoration: underline;
}

.themed-link:focus {
    outline: 2px solid var(--theme-primary-color);
    outline-offset: 2px;
}

/* Themed Table Styles */
.themed-table {
    border-color: var(--theme-table-border);
    background-color: var(--theme-background-color);
    transition: all 0.15s ease-in-out;
}

.themed-table thead th {
    background-color: var(--theme-table-header-bg);
    color: var(--theme-table-header-text);
    border-color: var(--theme-table-border);
    font-weight: 600;
    position: relative;
}

.themed-table tbody tr {
    border-color: var(--theme-table-border);
    transition: background-color 0.15s ease-in-out;
}

.themed-table.table-striped tbody tr:nth-of-type(odd) {
    background-color: var(--theme-table-striped);
}

.themed-table.table-hover tbody tr:hover {
    background-color: var(--theme-table-hover);
}

.themed-table-row {
    transition: background-color 0.15s ease-in-out, transform 0.1s ease-in-out;
}

.themed-table-row:focus {
    outline: 2px solid var(--theme-primary-color);
    outline-offset: -2px;
}

.themed-table-row[aria-selected="true"] {
    background-color: var(--theme-table-selected) !important;
    border-color: var(--theme-primary-color);
    font-weight: 600;
}

.themed-table-row[tabindex="0"]:hover {
    transform: translateX(2px);
    box-shadow: inset 3px 0 0 var(--theme-primary-color);
}

.themed-table-cell {
    border-color: var(--theme-table-border);
    vertical-align: middle;
    transition: all 0.15s ease-in-out;
}

.themed-table-cell[role="columnheader"] {
    background-color: var(--theme-table-header-bg);
    color: var(--theme-table-header-text);
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.875rem;
    letter-spacing: 0.05em;
}

/* Sortable table headers */
.themed-table-cell[role="columnheader"][style*="cursor: pointer"] {
    position: relative;
    user-select: none;
}

.themed-table-cell[role="columnheader"][style*="cursor: pointer"]:hover {
    background-color: var(--theme-primary-color);
    /* AB#7419: contrast the Primary hover fill instead of hardcoding white. */
    color: var(--theme-text-color, #fff);
}

.themed-table-cell[role="columnheader"][style*="cursor: pointer"]:after {
    content: "?";
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    opacity: 0.5;
    font-size: 0.8em;
}

/* DevExpress Menu Corner Rounding - Use theme border radius */
.dx-menu,
.dx-menu-item,
.dx-menu-item-content,
.dx-menu-dropdown,
.dx-dropdown-menu,
.dx-menu-hamburger-panel,
.dx-overlay-content.dx-menu-popup,
.dx-popup-content.dx-menu-popup {
    border-radius: var(--theme-button-border-radius) !important;
}

/* Apply corner rounding to menu item containers */
.dx-menu-item-container,
.dx-menu-horizontal .dx-menu-item,
.dx-menu-vertical .dx-menu-item {
    border-radius: var(--theme-button-border-radius) !important;
}

/* Apply corner rounding to dropdown menu items */
.dx-menu-dropdown .dx-menu-item,
.dx-dropdown-menu .dx-menu-item,
.dx-menu-submenu .dx-menu-item {
    border-radius: var(--theme-button-border-radius) !important;
}

/* Apply corner rounding to hamburger menu panel */
.dx-menu-hamburger-panel,
.dx-menu-hamburger-panel .dx-overlay-content {
    border-radius: var(--theme-button-border-radius) !important;
}

/* Apply corner rounding to menu popup overlays */
.dx-overlay-wrapper .dx-menu-popup .dx-overlay-content,
.dx-popup-wrapper .dx-menu-popup .dx-popup-content {
    border-radius: var(--theme-button-border-radius) !important;
}

/* Apply corner rounding to menu buttons and interactive elements */
.dx-menu .dx-button,
.dx-menu-item .dx-button,
.dx-menu-hamburger-button,
.dx-menu-toggle-button {
    border-radius: var(--theme-button-border-radius) !important;
}

/* Apply corner rounding to focus and hover states */
.dx-menu-item:focus,
.dx-menu-item:hover,
.dx-menu-item.dx-state-focused,
.dx-menu-item.dx-state-hover {
    border-radius: var(--theme-button-border-radius) !important;
}

/* Ensure nested menu dropdowns also get corner rounding */
.dx-menu .dx-submenu,
.dx-menu .dx-submenu .dx-overlay-content {
    border-radius: var(--theme-button-border-radius) !important;
}

/* Component accessibility and styling utilities */
.themed-text-primary {
    color: var(--theme-primary-color) !important;
}

.themed-text-secondary {
    color: var(--theme-secondary-color) !important;
}

.themed-bg-primary {
    background-color: var(--theme-primary-color) !important;
    /* AB#7419: contrast the Primary fill (matches card text) rather than hardcoding white. */
    color: var(--theme-text-color, #fff);
}

.themed-bg-secondary {
    background-color: var(--theme-secondary-color) !important;
    /* AB#7419: contrast the Secondary fill (same color the table header uses). */
    color: var(--theme-table-header-text, #fff);
}

.themed-bg-background {
    background-color: var(--theme-background-color) !important;
}

.themed-border-primary {
    border-color: var(--theme-primary-color) !important;
}

/* Accessibility enhancements */
.themed-component:focus-visible {
    outline: 2px solid var(--theme-primary-color);
    outline-offset: 2px;
}

/* Screen reader only text */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Phase 1: Skip navigation accessibility enhancement */
.sr-only-focusable:focus,
.sr-only-focusable:active {
    position: static;
    width: auto;
    height: auto;
    padding: 0.375rem 0.75rem;
    margin: 0;
    overflow: visible;
    clip: auto;
    white-space: normal;
    z-index: 1050;
    top: 0;
    left: 0;
}

/* Responsive design */
@media (max-width: 768px) {
    .themed-button {
        padding: 0.5rem 1rem;
        font-size: 0.9rem;
    }
    
    .themed-input {
        font-size: 16px; /* Prevents zoom on iOS */
        padding: 0.5rem 0.75rem;
    }
    
    .themed-card {
        margin: 0.5rem;
        border-radius: 0.5rem;
    }
    
    .themed-table {
        font-size: 0.875rem;
    }
    
    .themed-table-cell {
        padding: 0.5rem 0.25rem;
    }
    
    .themed-table-cell[role="columnheader"] {
        font-size: 0.75rem;
        padding: 0.75rem 0.5rem;
    }
}

@media (max-width: 767.98px) {
  .phone-management-section .row > [class*='col-'] {
    flex: 0 0 100%;
    max-width: 100%;
  }
  .phone-management-section .themed-dropdown,
  .phone-management-section .form-control {
    min-width: 0;
    width: 100%;
  }
}
.phone-management-section .themed-dropdown,
.phone-management-section .form-control {
  min-width: 0;
  width: 100%;
  box-sizing: border-box;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .themed-input,
    .themed-dropdown {
        border-width: 2px;
    }
    
    .themed-button {
        border-width: 2px;
        font-weight: 600;
    }
    
    .themed-link {
        text-decoration: underline;
    }
    
    .themed-table,
    .themed-table-cell {
        border-width: 2px;
    }
    
    .themed-table-row[aria-selected="true"] {
        border-width: 3px;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .themed-component,
    .themed-input,
    .themed-button,
    .themed-dropdown,
    .themed-card,
    .themed-link,
    .themed-table,
    .themed-table-row,
    .themed-table-cell {
        transition: none;
    }
    
    .themed-button:hover:not(:disabled) {
        transform: none;
    }
    
    .themed-card:hover {
        transform: none;
    }
    
    .themed-table-row[tabindex="0"]:hover {
        transform: none;
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    :root {
        --theme-background-color: #1a1a1a;
        --theme-secondary-color: #adb5bd;
        --theme-table-header-bg: #2d3338;
        --theme-table-header-text: #dee2e6;
        --theme-table-border: #495057;
        --theme-table-hover: #2d3338;
        --theme-table-striped: #212529;
    }
    
    .themed-card {
        border-color: rgba(255, 255, 255, 0.125);
    }
    
    .themed-table {
        color: #dee2e6;
    }
}

/* Print styles */
@media print {
    .themed-button,
    .themed-input,
    .themed-dropdown {
        -webkit-print-color-adjust: exact;
        color-adjust: exact;
    }
    
    .themed-button:hover,
    .themed-card:hover,
    .themed-table-row:hover {
        transform: none;
        box-shadow: none;
    }
    
    .themed-table {
        border-collapse: collapse;
    }
    
    .themed-table-cell {
        border: 1px solid #000;
    }
}

/* Animation utilities */
.themed-fade-in {
    animation: themedFadeIn 0.3s ease-in-out;
}

@keyframes themedFadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Loading state */
.themed-loading {
    position: relative;
    overflow: hidden;
}

.themed-loading::after {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.3), transparent);
    animation: themedLoading 1.5s infinite;
}

@keyframes themedLoading {
    0% {
        left: -100%;
    }
    100% {
        left: 100%;
    }
}

/* --- Phone Management Section Modernization --- */
.phone-management-section .card-body {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 1rem;
    background: var(--theme-background-color, #fff);
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.04);
    padding: 1.25rem 1.5rem;
}
.phone-management-section .form-label {
    font-weight: 500;
    margin-bottom: 0.25rem;
}
.phone-management-section .form-group {
    flex: 1 1 0;
    min-width: 140px;
    margin-bottom: 0;
}
.phone-management-section .delete-btn, .phone-management-section .themed-button[style*='Delete'] {
    align-self: flex-end;
    margin-left: auto;
    min-width: 100px;
    background: var(--theme-delete-button-color, #dc3545) !important;
    color: #fff !important;
    border-radius: 8px;
    border: none;
    font-weight: 600;
    transition: background 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}
.phone-management-section .delete-btn:hover, .phone-management-section .themed-button[style*='Delete']:hover {
    background: #b52a37 !important;
}
@media (max-width: 991.98px) {
    .phone-management-section .card-body {
        flex-direction: column;
        gap: 0.5rem;
        padding: 1rem;
    }
    .phone-management-section .delete-btn, .phone-management-section .themed-button[style*='Delete'] {
        width: 100%;
        margin-left: 0;
    }
    .phone-management-section .form-group {
        width: 100%;
        min-width: 0;
    }
}
