/**
 * ============================================================================
 * fTechLib Modern Table Styles (Default)
 * ============================================================================
 *
 * Modern, sleek table styling applied by default to all tables
 * generated by cui_Table() and cui_renderTable() functions.
 *
 * This is now the default styling. To use legacy styling, set
 * $modernStyle = false parameter or 'modernTable' => false in model.
 *
 * Features:
 * - Soft shadows and borders
 * - Smooth hover transitions
 * - Modern color palette with CSS variables
 * - Enhanced typography
 * - Subtle animations
 * - Density variants (compact/normal/spacious)
 *
 * @package    fTechLib
 * @subpackage CoreUI
 * @author     Thomas F Abrahamsson <thomas@alvega.company>
 * @copyright  2022-2024 Alvega & co AB / Fishy Tech Sweden AB
 * @version    1.0.0
 * ============================================================================
 */

/* =============================================================================
   CSS VARIABLES - Easily customizable color scheme
   ============================================================================= */

:root {
    /* Border and shadow colors */
    --ft-table-border-color: rgba(0, 0, 0, 0.25);
    --ft-table-border-color-light: rgba(0, 0, 0, 0.05);
    --ft-table-border-radius: 8px;
    --ft-table-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
    --ft-table-shadow-hover: 0 4px 12px rgba(0, 0, 0, 0.1);

    /* Header colors */
    --ft-table-header-bg-start: #2c3e50;
    --ft-table-header-bg-end: #34495e;
    --ft-table-header-text: #ffffff;

    /* Counter column colors */
    --ft-table-counter-bg: #34495e;
    --ft-table-counter-text: #ecf0f1;

    /* Row colors */
    --ft-table-row-even: #ffffff;
    --ft-table-row-odd: #f8f9fa;
    --ft-table-row-hover: #e8f4f8;
    --ft-table-row-hover-border: rgba(0, 123, 255, 0.15);

    /* Sort indicator color */
    --ft-table-sort-color: #fee715;

    /* Transitions */
    --ft-table-transition: all 0.2s ease-in-out;
    --ft-table-transition-fast: all 0.15s ease-in-out;
}

/* =============================================================================
   MODERN TABLE WRAPPER
   ============================================================================= */

.table-modern {
    border-radius: var(--ft-table-border-radius);
    overflow: hidden !important;
    box-shadow: var(--ft-table-shadow);
    transition: var(--ft-table-transition);
    border: 2px solid var(--ft-table-border-color) !important;
    background: white;
    -webkit-border-radius: var(--ft-table-border-radius);
    -moz-border-radius: var(--ft-table-border-radius);
    width: 100%;
    margin-bottom: 0.5rem;
    margin-top: 0.5rem;
}

.table-modern:hover {
    box-shadow: var(--ft-table-shadow-hover);
    border-color: rgba(0, 0, 0, 0.35);
}

/* Ensure nested elements don't prevent rounded corners */
.table-modern thead th font,
.table-modern thead th sup,
.table-modern thead th * {
    border-radius: inherit;
}

/* Remove legacy inline styles when using modern wrapper */
.table-modern table {
    border-left: none !important;
    border-right: none !important;
    border-bottom: none !important;
    border-top: none !important;
    margin-bottom: 0 !important;
    border-collapse: separate !important;
    border-spacing: 0 !important;
    width: 100% !important;
}

/* Force rounded corners on the wrapper to clip overflow properly */
.table-modern {
    -webkit-border-radius: var(--ft-table-border-radius);
    -moz-border-radius: var(--ft-table-border-radius);
}

/* Additional specificity for table elements to ensure corners show */
.table-modern table thead,
.table-modern table thead.table-dark {
    border-top-left-radius: calc(var(--ft-table-border-radius) - 2px);
    border-top-right-radius: calc(var(--ft-table-border-radius) - 2px);
}

.table-modern table tbody {
    border-bottom-left-radius: calc(var(--ft-table-border-radius) - 2px);
    border-bottom-right-radius: calc(var(--ft-table-border-radius) - 2px);
}

/* =============================================================================
   MODERN HEADER STYLING
   ============================================================================= */

.table-modern thead.table-dark {
    background: linear-gradient(135deg, var(--ft-table-header-bg-start) 0%, var(--ft-table-header-bg-end) 100%);
    border: none;
    border-top-left-radius: 6px !important;
    border-top-right-radius: 6px !important;
    -webkit-border-top-left-radius: 6px !important;
    -webkit-border-top-right-radius: 6px !important;
    -moz-border-top-left-radius: 6px !important;
    -moz-border-top-right-radius: 6px !important;
    overflow: hidden;
}

/* Override Bootstrap defaults that might prevent rounded corners */
.table-modern table.table {
    border-radius: 0 !important;
    border-top-left-radius: 6px !important;
    border-top-right-radius: 6px !important;
}

.table-modern table.table thead th {
    border-top: none !important;
}

/* Force table element itself to have rounded top corners */
.table-modern table {
    border-top-left-radius: 6px !important;
    border-top-right-radius: 6px !important;
    border-bottom-left-radius: 6px !important;
    border-bottom-right-radius: 6px !important;
}

.table-modern thead th {
    border: none !important;
    padding: 0.6rem 0.75rem;
    font-weight: 600;
    font-size: 0.875rem;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    color: var(--ft-table-header-text);
    vertical-align: middle;
}

.table-modern thead th:first-child {
    width: 1%;
    white-space: nowrap;
    padding: 0.4rem 0.35rem !important;
}

.table-modern thead th:last-child {
    padding-right: 0.75rem;
}

/* Second header cell (first data column when counter is present) */
.table-modern thead th:nth-child(2) {
    padding-left: 0.75rem;
}

/* Ensure thead respects rounded corners - CRITICAL: Multiple layers of specificity */

/* Top-left corner - first th in header row */
.table-modern table thead tr:first-child th:first-child,
.table-modern table thead.table-dark tr:first-child th:first-child,
.table-modern table.table thead tr:first-child th:first-child,
.table-modern table.table thead.table-dark tr:first-child th:first-child,
.table-modern > div > table > thead > tr:first-child > th:first-child {
    border-top-left-radius: 6px !important;
    -webkit-border-top-left-radius: 6px !important;
    -moz-border-top-left-radius: 6px !important;
}

/* Top-right corner - last th in header row */
.table-modern table thead tr:first-child th:last-child,
.table-modern table thead.table-dark tr:first-child th:last-child,
.table-modern table.table thead tr:first-child th:last-child,
.table-modern table.table thead.table-dark tr:first-child th:last-child,
.table-modern > div > table > thead > tr:first-child > th:last-child {
    border-top-right-radius: 6px !important;
    -webkit-border-top-right-radius: 6px !important;
    -moz-border-top-right-radius: 6px !important;
}

/* Ensure all header cells clip their content */
.table-modern thead tr:first-child th {
    background-clip: padding-box;
    position: relative;
}

/* Force the thead row itself to have rounded corners */
.table-modern thead tr:first-child {
    border-top-left-radius: 6px !important;
    border-top-right-radius: 6px !important;
}

/* Sort indicators modern styling */
.table-modern thead th u {
    color: var(--ft-table-sort-color);
    text-decoration-color: var(--ft-table-sort-color);
}

/* =============================================================================
   MODERN ROW STYLING
   ============================================================================= */

.table-modern tbody tr {
    transition: var(--ft-table-transition);
    border-bottom: 1px solid var(--ft-table-border-color-light);
}

.table-modern tbody tr:last-child {
    border-bottom: none;
}

/* Round bottom corners of last row - CRITICAL: Multiple layers of specificity */

/* Bottom-left corner - first td in last row */
.table-modern table tbody tr:last-child td:first-child,
.table-modern table.table tbody tr:last-child td:first-child,
.table-modern tbody tr:last-child td.table-counter,
.table-modern tbody tr:last-child td.table-dark:first-child {
    border-bottom-left-radius: 6px !important;
    -webkit-border-bottom-left-radius: 6px !important;
    -moz-border-bottom-left-radius: 6px !important;
}

/* Bottom-right corner - last td in last row */
.table-modern table tbody tr:last-child td:last-child,
.table-modern table.table tbody tr:last-child td:last-child {
    border-bottom-right-radius: 6px !important;
    -webkit-border-bottom-right-radius: 6px !important;
    -moz-border-bottom-right-radius: 6px !important;
}

/* Force the last tbody row itself to have rounded corners */
.table-modern tbody tr:last-child {
    border-bottom-left-radius: 6px !important;
    border-bottom-right-radius: 6px !important;
}

/* Zebra striping - more subtle */
.table-modern tbody tr.bg-white,
.table-modern.table-striped tbody tr:nth-of-type(even) {
    background-color: var(--ft-table-row-even);
}

.table-modern tbody tr.bg-light,
.table-modern.table-striped tbody tr:nth-of-type(odd) {
    background-color: var(--ft-table-row-odd);
}

/* Smooth hover effect with slight elevation */
.table-modern tbody tr:hover {
    background-color: var(--ft-table-row-hover) !important;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    position: relative;
    z-index: 1;
}

/* Clickable row enhancement */
.table-modern tbody tr.pointer {
    cursor: pointer;
}

.table-modern tbody tr.pointer:active {
    transform: translateY(0);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}

/* =============================================================================
   MODERN CELL STYLING
   ============================================================================= */

.table-modern td {
    border-top: none !important;
    border-bottom: none !important;
    padding: 0.25rem 0.75rem;
    vertical-align: middle;
    transition: var(--ft-table-transition-fast);
}

.table-modern td:first-child {
    padding-left: 0.75rem;
}

/* Second data cell (first data column when counter is present) */
.table-modern td:nth-child(2) {
    padding-left: 0.75rem;
}

.table-modern td:last-child {
    padding-right: 0.75rem;
}

/* Remove borders from cells (border is on row) */
.table-modern td.border-0 {
    border: none !important;
}

/* =============================================================================
   MODERN COUNTER COLUMN
   ============================================================================= */

.table-modern td.table-counter,
.table-modern td.table-dark {
    background: var(--ft-table-counter-text) !important;
    color: var(--ft-table-counter-bg) !important;
    opacity: 0.6;
    font-weight: 600 !important;
    font-size: 0.7rem !important;
    border: none !important;
    text-align: center;
    padding: 0.25rem 0.35rem !important;
    width: 1%;
    white-space: nowrap;
}

/* Prevent hover border on counter column */
.table-modern tbody tr:hover td.table-counter,
.table-modern tbody tr:hover td.table-dark {
    border-bottom: none !important;
    box-shadow: none !important;
}

.table-modern thead th sup {
    color: var(--ft-table-header-text);
    opacity: 0.8;
    font-size: 0.7rem;
}

/* =============================================================================
   SECTION HEADERS (full-width string rows)
   ============================================================================= */

.table-modern td.bg-secondary {
    background: linear-gradient(135deg, #6c757d 0%, #5a6268 100%) !important;
    color: white !important;
    font-weight: 600 !important;
    padding: 0.75rem 1rem !important;
}

.table-modern td.bg-secondary h5 {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
}

/* =============================================================================
   EMPTY STATE
   ============================================================================= */

.table-modern .empty-state,
.table-modern tbody td[colspan] {
    padding: 3rem 1.5rem;
    text-align: center;
    color: #6c757d;
    font-style: italic;
}

/* =============================================================================
   PAGINATION MODERN STYLING
   ============================================================================= */

.pagination-modern {
    margin-top: 1rem;
}

.pagination-modern .pagination {
    gap: 4px;
}

.pagination-modern .page-link {
    border: 1px solid var(--ft-table-border-color);
    color: #495057;
    transition: var(--ft-table-transition-fast);
    border-radius: 6px;
    margin: 0;
    padding: 0.5rem 0.75rem;
    font-weight: 500;
}

.pagination-modern .page-link:hover {
    background-color: #e9ecef;
    border-color: #dee2e6;
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08);
    color: #2c3e50;
}

.pagination-modern .page-link.active {
    background: linear-gradient(135deg, var(--ft-table-header-bg-start) 0%, var(--ft-table-header-bg-end) 100%);
    border-color: var(--ft-table-header-bg-start);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15);
    color: white;
    transform: translateY(0);
}

.pagination-modern .page-item.disabled .page-link {
    background-color: #f8f9fa;
    border-color: var(--ft-table-border-color);
    color: #adb5bd;
    cursor: not-allowed;
}

/* Arrows styling */
.pagination-modern .page-link b {
    font-size: 1.1rem;
}

/* =============================================================================
   DENSITY VARIANTS
   ============================================================================= */

/* Compact table - tighter spacing */
.table-modern.table-compact tbody td {
    padding: 0.5rem 0.75rem !important;
}

.table-modern.table-compact thead th {
    padding: 0.75rem 0.75rem !important;
}

/* Spacious table - more breathing room */
.table-modern.table-spacious tbody td {
    padding: 1.25rem 0.75rem !important;
}

.table-modern.table-spacious thead th {
    padding: 1.25rem 0.75rem !important;
}

/* =============================================================================
   RESPONSIVE ENHANCEMENTS
   ============================================================================= */

/* Better touch targets on mobile */
@media (max-width: 768px) {
    .table-modern td,
    .table-modern th {
        padding: 0.75rem 0.5rem;
    }

    .table-modern tbody tr:hover {
        transform: none; /* Disable transform on mobile */
    }
}

/* =============================================================================
   ANIMATIONS
   ============================================================================= */

/* Fade in animation for table rows */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.table-modern.table-fade-in tbody tr {
    animation: fadeInUp 0.3s ease-out backwards;
}

/* Stagger animation for multiple rows */
.table-modern.table-fade-in tbody tr:nth-child(1) { animation-delay: 0.05s; }
.table-modern.table-fade-in tbody tr:nth-child(2) { animation-delay: 0.1s; }
.table-modern.table-fade-in tbody tr:nth-child(3) { animation-delay: 0.15s; }
.table-modern.table-fade-in tbody tr:nth-child(4) { animation-delay: 0.2s; }
.table-modern.table-fade-in tbody tr:nth-child(5) { animation-delay: 0.25s; }

/* After 5th row, no more delay to avoid slowness */
.table-modern.table-fade-in tbody tr:nth-child(n+6) { animation-delay: 0.25s; }

/* =============================================================================
   FIELD-SPECIFIC ENHANCEMENTS
   ============================================================================= */

/* Pills and badges within modern tables */
.table-modern .badge,
.table-modern .pill {
    font-weight: 500;
    padding: 0.35em 0.65em;
    border-radius: 6px;
    transition: var(--ft-table-transition-fast);
}

/* Links within tables */
.table-modern a:not(.btn) {
    color: #2c3e50;
    font-weight: 500;
    text-decoration: none;
    border-bottom: 1px solid transparent;
    transition: var(--ft-table-transition-fast);
}

.table-modern a:not(.btn):hover {
    color: #1a252f;
    border-bottom-color: #2c3e50;
}

/* Email icons and status indicators */
.table-modern .text-danger,
.table-modern .text-warning,
.table-modern .text-success {
    font-weight: 500;
}

/* =============================================================================
   MODERN FORM STYLING
   ============================================================================= */

/* Form wrapper with modern styling matching tables */
.form-modern {
    border-radius: var(--ft-table-border-radius);
    overflow: hidden;
    box-shadow: var(--ft-table-shadow);
    border: 2px solid var(--ft-table-border-color);
    background: white;
}

.form-modern:hover {
    box-shadow: var(--ft-table-shadow-hover);
}

/* Modern form header */
.form-modern #editorheader,
.form-modern .form-header {
    background: linear-gradient(135deg, var(--ft-table-header-bg-start) 0%, var(--ft-table-header-bg-end) 100%) !important;
    border-top-left-radius: calc(var(--ft-table-border-radius) - 2px);
    border-top-right-radius: calc(var(--ft-table-border-radius) - 2px);
    border-bottom: none;
    margin: 0 !important;
    padding-left: 0.5rem !important;
    padding-right: 0.5rem !important;
}

/* Form rows - add horizontal padding to prevent clipping */
.form-modern .row {
    margin-left: 0 !important;
    margin-right: 0 !important;
    padding-left: 0.5rem;
    padding-right: 0.5rem;
}

/* Form row labels - adjust for new padding */
.form-modern .row > label:first-child {
    padding-left: 0.25rem;
}

/* Form row last column - adjust for new padding */
.form-modern .row > div:last-child {
    padding-right: 0.25rem;
}

/* Modern form footer */
.form-modern .btn-group:last-of-type {
    border-bottom-left-radius: calc(var(--ft-table-border-radius) - 2px);
    border-bottom-right-radius: calc(var(--ft-table-border-radius) - 2px);
}

/* Footer row padding */
.form-modern > form > .row:last-of-type {
    padding-left: 0.5rem !important;
    padding-right: 0.5rem !important;
}

/* Remove default shadow from inner form element */
.form-modern form {
    box-shadow: none !important;
}

/* =============================================================================
   DARK MODE SUPPORT (Optional - for future use)
   ============================================================================= */

@media (prefers-color-scheme: dark) {
    .table-modern.table-dark-mode {
        --ft-table-border-color: rgba(255, 255, 255, 0.1);
        --ft-table-border-color-light: rgba(255, 255, 255, 0.05);
        --ft-table-row-even: #1a1a1a;
        --ft-table-row-odd: #222222;
        --ft-table-row-hover: #2a2a2a;
        background: #1a1a1a;
    }

    .table-modern.table-dark-mode td {
        color: #e0e0e0;
    }
}

/* =============================================================================
   FORM INFO PANELS - Public/Private visibility indicators
   ============================================================================= */

.form-info-panel {
    margin-top: 12px;
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 14px;
    display: flex;
    align-items: center;
    gap: 14px;
}

.form-info-panel.public {
    background: linear-gradient(135deg, #e8f5e9 0%, #f1f8e9 100%);
    border-left: 4px solid #4caf50;
    box-shadow: 0 2px 6px rgba(76, 175, 80, 0.12);
}

.form-info-panel.private {
    margin-top: 20px;
    background: linear-gradient(135deg, #fff3e0 0%, #fff8e1 100%);
    border-left: 4px solid #ff9800;
    box-shadow: 0 2px 6px rgba(255, 152, 0, 0.12);
}

.form-info-panel .badge {
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    white-space: nowrap;
    color: white;
}

.form-info-panel.public .badge {
    background: #4caf50;
}

.form-info-panel.private .badge {
    background: #ff9800;
}

.form-info-panel .text {
    font-size: 0.9rem;
}

.form-info-panel.public .text {
    color: #2e7d32;
}

.form-info-panel.private .text {
    color: #e65100;
}
