﻿/* ============================================
   XDOCKET DESIGN SYSTEM - SHARED FOUNDATION
   ============================================ */

:root {
    /* Primary Brand Colors */
    --xd-primary: #007AFF;
    --xd-primary-rgb: 0, 122, 255;
    --xd-secondary: #5856D6;
    --xd-success: #34C759;
    --xd-warning: #FF9500;
    --xd-danger: #FF3B30;
    --xd-info: #5AC8FA;
    --xd-light: #F2F2F7;
    --xd-dark: #1C1C1E;
    /* Grays */
    --xd-gray-50: #FAFBFC;
    --xd-gray-100: #F8F9FA;
    --xd-gray-200: #E9ECEF;
    --xd-gray-300: #DEE2E6;
    --xd-gray-400: #CED4DA;
    --xd-gray-500: #ADB5BD;
    --xd-gray-600: #6C757D;
    --xd-gray-700: #495057;
    --xd-gray-800: #343A40;
    --xd-gray-900: #212529;
    /* Spacing */
    --xd-spacing-xs: 0.25rem;
    --xd-spacing-sm: 0.5rem;
    --xd-spacing-md: 1rem;
    --xd-spacing-lg: 1.5rem;
    --xd-spacing-xl: 2rem;
    --xd-spacing-xxl: 3rem;
    /* Border Radius */
    --xd-radius-xs: 4px;
    --xd-radius-sm: 6px;
    --xd-radius-md: 8px;
    --xd-radius-lg: 12px;
    --xd-radius-xl: 16px;
    --xd-radius-round: 50%;
    /* Shadows */
    --xd-shadow-xs: 0 1px 3px rgba(0, 0, 0, 0.05);
    --xd-shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.05);
    --xd-shadow-md: 0 4px 8px rgba(0, 0, 0, 0.1);
    --xd-shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.12);
    --xd-shadow-xl: 0 10px 32px rgba(0, 0, 0, 0.15);
    /* Typography */
    --xd-font-family-base: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    --xd-font-family-mono: 'SF Mono', Monaco, 'Cascadia Code', 'Courier New', monospace;
    /* Transitions */
    --xd-transition-fast: 0.15s ease;
    --xd-transition-normal: 0.3s ease;
    --xd-transition-slow: 0.5s ease;
    /* Z-index */
    --xd-z-dropdown: 1000;
    --xd-z-sticky: 100;
    --xd-z-modal: 1050;
    --xd-z-popover: 1060;
    --xd-z-tooltip: 1070;
    --xd-z-notification: 9999;
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    :root {
        --xd-gray-900: #f0f0f0;
        --xd-gray-800: #e0e0e0;
        --xd-gray-100: #2d2d2d;
        --xd-gray-50: #1a1a1a;
    }
}

/* ========== SHARED BASE COMPONENTS ========== */

/* Page Structure */
.page-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.main-content {
    display: flex;
    flex-direction: column;
    padding-bottom: var(--xd-spacing-md);
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--xd-spacing-xs);
    padding: 0 var(--xd-spacing-lg);
}

.page-title {
    display: flex;
    align-items: center;
    gap: var(--xd-spacing-sm);
    margin: 0;
    font-size: 1.875rem;
    font-weight: 600;
    color: var(--xd-gray-900);
}

.page-actions {
    display: flex;
    gap: var(--xd-spacing-sm);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: var(--xd-spacing-xs);
    padding: var(--xd-spacing-sm) var(--xd-spacing-md);
    border: 1px solid transparent;
    border-radius: var(--xd-radius-md);
    font-size: 0.875rem;
    font-weight: 500;
    text-decoration: none;
    cursor: pointer;
    transition: all var(--xd-transition-fast);
    white-space: nowrap;
    user-select: none;
}

    .btn:disabled {
        opacity: 0.65;
        cursor: not-allowed;
    }

.btn-primary {
    background-color: var(--xd-primary);
    color: white;
    border-color: var(--xd-primary);
}

    .btn-primary:hover:not(:disabled) {
        background-color: #0051d5;
        border-color: #0051d5;
    }

.btn-outline-secondary {
    border-color: var(--xd-gray-300);
    color: var(--xd-gray-700);
    background-color: white;
}

    .btn-outline-secondary:hover:not(:disabled) {
        border-color: var(--xd-gray-600);
        background-color: var(--xd-gray-50);
    }

.btn-sm {
    padding: 0.375rem 0.875rem;
    font-size: 0.8125rem;
}

.btn:focus-visible {
    outline: 2px solid var(--xd-primary);
    outline-offset: 2px;
}

/* Form Controls */
.form-control,
.form-select {
    width: 100%;
    padding: 0.625rem 0.875rem;
    border: 1px solid var(--xd-gray-300);
    border-radius: var(--xd-radius-md);
    font-size: 0.875rem;
    background-color: white;
    color: var(--xd-gray-900);
    transition: all var(--xd-transition-fast);
}

    .form-control:focus,
    .form-select:focus {
        outline: none;
        border-color: var(--xd-primary);
        box-shadow: 0 0 0 0.25rem rgba(var(--xd-primary-rgb), 0.25);
    }

    .form-control.is-invalid,
    .form-select.is-invalid {
        border-color: var(--xd-danger);
    }

.filter-panel {
    background: var(--xd-gray-50);
    border: 1px solid var(--xd-gray-200);
    border-radius: var(--xd-radius-lg);
    padding: var(--xd-spacing-lg);
    margin-bottom: var(--xd-spacing-lg);
}

.filter-row {
    display: flex;
    gap: var(--xd-spacing-md);
    align-items: end;
    flex-wrap: wrap;
}

.filter-group {
    flex: 1;
    min-width: 200px;
}

.filter-label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--xd-gray-600);
    margin-bottom: var(--xd-spacing-sm);
}

/* Table Container - Shared */
.table-container {
    background: white;
    border: 1px solid var(--xd-gray-200);
    border-radius: var(--xd-radius-lg);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 400px;
    max-height: calc(100vh - 200px);
}

.table-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--xd-spacing-md) var(--xd-spacing-lg);
    border-bottom: 1px solid var(--xd-gray-200);
    background: var(--xd-gray-50);
    flex-shrink: 0;
}

.table-info {
    font-size: 0.875rem;
    color: var(--xd-gray-600);
    display: flex;
    align-items: center;
    gap: var(--xd-spacing-md);
}

.table-status {
    display: flex;
    align-items: center;
    gap: var(--xd-spacing-sm);
}

    .table-status.loading::before {
        content: "";
        width: 12px;
        height: 12px;
        border: 2px solid var(--xd-gray-200);
        border-top-color: var(--xd-primary);
        border-radius: 50%;
        animation: xd-spin 1s linear infinite;
    }

.table-scroll-container {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    position: relative;
    min-height: 200px;
    padding-bottom: var(--xd-spacing-md);
    scrollbar-width: thin;
    scrollbar-color: var(--xd-gray-400) var(--xd-gray-100);
}

    .table-scroll-container::-webkit-scrollbar {
        width: 10px;
    }

    .table-scroll-container::-webkit-scrollbar-track {
        background: var(--xd-gray-100);
        border-radius: 5px;
    }

    .table-scroll-container::-webkit-scrollbar-thumb {
        background: var(--xd-gray-400);
        border-radius: 5px;
        border: 2px solid var(--xd-gray-100);
    }

        .table-scroll-container::-webkit-scrollbar-thumb:hover {
            background: var(--xd-gray-600);
        }

/* Empty States */
.empty-state {
    text-align: center;
    padding: var(--xd-spacing-xxl) var(--xd-spacing-lg);
    color: var(--xd-gray-600);
}

    .empty-state i {
        font-size: 3rem;
        margin-bottom: var(--xd-spacing-md);
        opacity: 0.5;
    }

.error-state {
    color: var(--xd-danger);
}

    .error-state i {
        color: var(--xd-danger);
    }

/* Loading States */
.loading-container {
    padding: var(--xd-spacing-xl) var(--xd-spacing-lg);
}

.loading-skeleton {
    height: 1rem;
    background: linear-gradient(90deg, var(--xd-gray-100) 25%, var(--xd-gray-300) 50%, var(--xd-gray-100) 75%);
    background-size: 200% 100%;
    border-radius: var(--xd-radius-xs);
    margin-bottom: var(--xd-spacing-sm);
    animation: xd-shimmer 1.5s infinite;
}

.loading-state {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: var(--xd-spacing-lg);
    padding: var(--xd-spacing-lg);
}

/* Dropdown Menu */
.dropdown {
    position: relative;
    display: inline-block;
}

.dropdown-menu {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: var(--xd-spacing-xs);
    background: white;
    border: 1px solid var(--xd-gray-200);
    border-radius: var(--xd-radius-md);
    box-shadow: var(--xd-shadow-lg);
    min-width: 180px;
    z-index: var(--xd-z-dropdown);
    display: none;
    padding: var(--xd-spacing-xs) 0;
}

    .dropdown-menu.show {
        display: block;
    }

.dropdown-item {
    display: flex;
    align-items: center;
    gap: var(--xd-spacing-sm);
    padding: var(--xd-spacing-sm) var(--xd-spacing-md);
    color: var(--xd-gray-900);
    text-decoration: none;
    font-size: 0.875rem;
    transition: all var(--xd-transition-fast);
    cursor: pointer;
    background: none;
    border: none;
    width: 100%;
    text-align: left;
}

    .dropdown-item:hover {
        background: var(--xd-gray-50);
    }

    .dropdown-item.text-danger {
        color: var(--xd-danger);
    }

.dropdown-divider {
    height: 1px;
    background: var(--xd-gray-200);
    margin: var(--xd-spacing-xs) 0;
}

/* ========================================
   PAGE HEADER - Consistent Border Radius
   ======================================== */

/* Primary fix for all page-header elements */
.page-header {
    border-radius: 8px !important;
    background: transparent;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    box-shadow: none; /* Remove shadow since background is transparent */
}

    /* Fix for any nested elements that might break the radius */
    .page-header > *:first-child {
        border-top-left-radius: 8px;
        border-top-right-radius: 8px;
    }

    .page-header > *:last-child {
        border-bottom-left-radius: 8px;
        border-bottom-right-radius: 8px;
    }

    /* Ensure status indicators don't break the radius */
    .page-header .matter-status-indicator {
        border-radius: 8px 0 0 8px; /* Maintain left radius if positioned absolutely */
    }

/* Maintain consistency for all module page headers */
.page-container[data-module="addressbook"] .page-header,
.page-container[data-module="matter-table"] .page-header,
.page-container[data-module="calendar"] .page-header,
.page-container[data-module="accounting"] .page-header
.page-container[data-module="library"] .page-header {
    border-radius: 8px !important;
    background: transparent;
}

/* ========================================
   FILTER PANELS - Matching Border Radius
   ======================================== */

/* Ensure filter panels also have consistent radius */
.filter-panel {
    border-radius: 8px !important;
    background: var(--bs-white, #ffffff);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

/* ========================================
   CARDS & CONTAINERS - Consistent Design
   ======================================== */

/* Apply to all card elements for consistency */
.card {
    border-radius: 8px !important;
    border: 1px solid var(--bs-border-color, #dee2e6);
    overflow: hidden;
}

.card-header {
    border-radius: 8px 8px 0 0 !important;
}

.card-footer {
    border-radius: 0 0 8px 8px !important;
}

/* Modal content should also match */
.modal-content {
    border-radius: 8px !important;
    overflow: hidden;
}

.modal-header {
    border-radius: 8px 8px 0 0 !important;
}

.modal-footer {
    border-radius: 0 0 8px 8px !important;
}

/* ========================================
   TAB CONTAINERS - Consistent Radius
   ======================================== */

.tab-container {
    border-radius: 8px !important;
    overflow: hidden;
}

.tab-content-container {
    border-radius: 0 8px 8px 8px !important;
}

/* First tab should have top-left radius */
.xdocket-tabs .tab-item:first-child {
    border-top-left-radius: 6px;
}

/* Last visible tab should respect container */
.xdocket-tabs .tab-item:last-child:not(.tab-more) {
    border-top-right-radius: 6px;
}

/* ========================================
   SPECIFIC MATTER DETAILS FIXES
   ======================================== */

/* Fix for MatterDetails specific layout - WHITE BACKGROUND ONLY FOR THIS PAGE */
.page-container[data-module="matter-details"] .page-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 1rem;
    border-radius: 8px !important;
    overflow: visible;
    position: relative;
    z-index: 10;
    background: var(--bs-white, #ffffff) !important; /* White background ONLY for matter details */
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05); /* Add subtle shadow back for this page */
    position: relative;
}

/* Ensure the colored status indicator respects radius */
.page-container[data-module="matter-details"] .matter-status-indicator {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 4px;
    border-radius: 8px 0 0 8px;
}

/* Adjust padding to account for status indicator */
.page-container[data-module="matter-details"] .matter-header-info {
    padding-left: 1rem;
}

/* ========================================
   RESPONSIVE ADJUSTMENTS
   ======================================== */

@media (max-width: 768px) {
    /* Maintain border radius on mobile */
    .page-header {
        border-radius: 8px !important;
        padding: 1rem;
        background: transparent;
    }

    .filter-panel {
        border-radius: 8px !important;
        padding: 1rem;
    }
}

/* ========================================
   UTILITY CLASSES
   ======================================== */

/* Utility class for manual application if needed */
.rounded-8 {
    border-radius: 8px !important;
}

.rounded-top-8 {
    border-top-left-radius: 8px !important;
    border-top-right-radius: 8px !important;
}

.rounded-bottom-8 {
    border-bottom-left-radius: 8px !important;
    border-bottom-right-radius: 8px !important;
}

.rounded-left-8 {
    border-top-left-radius: 8px !important;
    border-bottom-left-radius: 8px !important;
}

.rounded-right-8 {
    border-top-right-radius: 8px !important;
    border-bottom-right-radius: 8px !important;
}

/* ========================================
   SHADOW ADJUSTMENTS
   ======================================== */

/* Page headers with transparent background don't need shadows */
.page-header {
    box-shadow: none;
}

/* Keep shadows for solid elements */
.filter-panel,
.card {
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05), 0 1px 2px rgba(0, 0, 0, 0.1);
}

    /* Hover state for interactive elements */
    .card:hover {
        box-shadow: 0 4px 6px rgba(0, 0, 0, 0.07), 0 2px 4px rgba(0, 0, 0, 0.06);
        transition: box-shadow 0.3s ease;
    }

/* ========================================
   BROWSER COMPATIBILITY
   ======================================== */

/* Ensure compatibility across browsers */
.page-header,
.filter-panel,
.card,
.modal-content {
    -webkit-border-radius: 8px;
    -moz-border-radius: 8px;
    -ms-border-radius: 8px;
    -o-border-radius: 8px;
    border-radius: 8px;
}

/* Animations */
@keyframes xd-spin {
    to {
        transform: rotate(360deg);
    }
}

@keyframes xd-shimmer {
    0% {
        background-position: 200% 0;
    }

    100% {
        background-position: -200% 0;
    }
}

/* Accessibility */
.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;
}

/* High contrast mode */
@media (prefers-contrast: high) {
    .btn {
        border-width: 2px;
    }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
