/* =============================================================================
   SynergyHub - Global Application Styles
   Modern, elegant design system integration
   ============================================================================= */

/* =============================================================================
   BASE RESETS & DEFAULTS
   ============================================================================= */

*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    margin: 0;
    font-family: var(--mud-typography-default-family);
    line-height: 1.5;
}

/* =============================================================================
   Page titles are rendered centered in the AppBar (MainLayout). Hide the legacy
   in-page hero headers so pages start flush with the toolbar/filter/content.
   ============================================================================= */
.page-header,
.dashboard-header {
    display: none !important;
}

/* =============================================================================
   RESPONSIVE LAYOUT (Phase 1) — applies globally across all CardListViews.
   Uses !important to override page-scoped CSS where needed.
   ============================================================================= */

/* A) Compact page-header on tablet/mobile — reclaim vertical space */
@media (max-width: 1199px) {
    .page-header {
        margin-bottom: 12px !important;
        padding: 12px 16px !important;
    }
    .page-title {
        font-size: 1.25rem !important;
    }
    .page-title-divider {
        margin: 6px 0 !important;
    }
    .page-subtitle {
        font-size: 0.875rem !important;
    }
}

@media (max-width: 599px) {
    .page-header {
        margin-bottom: 8px !important;
        padding: 8px 12px !important;
    }
    .page-title {
        font-size: 1.1rem !important;
    }
    /* Hide subtitle on small mobile — save ~24px */
    .page-subtitle {
        display: none !important;
    }
    .page-title-divider {
        display: none !important;
    }
    /* Reduce top padding of main content */
    .main-content-container {
        padding: 8px !important;
    }
}

/* C) CardDataGrid safety: ensure the grid container always has a usable area.
   If the auto-height JS skips due to tight header stack, min-height + overflow
   on the list container guarantee at least a partial scrollable region. */
.card-list-container {
    min-height: 300px;
}

/* Last-resort scroll on the list container so Cards never get clipped
   silently when the inner flex chain fails. */
.card-list-container {
    overflow-y: auto;
}

/* E) Card-title ellipsis: universal truncation for any slot in the card header */
.card-header-enhanced .mud-card-header-content {
    min-width: 0;
    overflow: hidden;
}

.card-header-enhanced .mud-card-header-content > * {
    min-width: 0;
}

/* Apply ellipsis to the typical title spans used by pages */
.card-header-enhanced .customer-title,
.card-header-enhanced .member-title,
.card-header-enhanced .partner-title,
.card-header-enhanced .tenant-title,
.card-header-enhanced .project-title,
.card-header-enhanced .donor-title,
.card-header-enhanced .material-title,
.card-header-enhanced .role-title,
.card-header-enhanced .plan-title,
.card-header-enhanced .deck-title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}

/* F) Pagination: hide middle pages on small viewports to prevent horizontal overflow */
@media (max-width: 499px) {
    .pagination-compact .mud-pagination-item:not(.mud-pagination-prev):not(.mud-pagination-next):not(.mud-pagination-selected) {
        display: none !important;
    }
    /* Stack pagination-group on top of action buttons */
    .pagination-group {
        flex-wrap: wrap;
    }
    /* Shrink pageSize info */
    .pagination-info {
        font-size: 0.7rem;
    }
}

/* G) MudTabs on mobile: hide icons to give labels more room */
@media (max-width: 599px) {
    .mud-tabs-tabbar .mud-tab .mud-tab-icon-wrapper,
    .mud-tabs-tabbar .mud-tab .mud-icon-root {
        display: none !important;
    }
    .mud-tabs-tabbar .mud-tab {
        min-width: auto !important;
        padding: 6px 8px !important;
        font-size: 0.8rem !important;
    }
}

/* =============================================================================
   TOUCH UX (Phase 2) — applies on coarse pointers (phones, tablets).
   `(hover: none)` targets touch-only input; `(pointer: coarse)` the same.
   ============================================================================= */

/* H) Always-visible card actions on touch devices — hover-reveal doesn't work */
@media (hover: none) {
    .card-menu-button {
        opacity: 1 !important;
    }
    /* Disable hover-lift animation — feels wrong on tap */
    .enhanced-card:hover,
    .enhanced-card.hovered {
        transform: none !important;
    }
}

/* I) Touch-target sizing — iOS requires min 44px, Material 48px. Small icon
   buttons in toolbar/pagination are too small on touch. Apply on mobile + tablet. */
@media (pointer: coarse), (max-width: 959px) {
    .mud-icon-button {
        min-width: 44px !important;
        min-height: 44px !important;
    }
    .pagination-compact .mud-pagination-item {
        min-width: 44px !important;
        min-height: 44px !important;
    }
    /* Exception: small card-menu ⋮ button within cards stays compact to not
       dominate the card — card itself is tap-target. */
    .card-menu-button {
        min-width: 36px !important;
        min-height: 36px !important;
    }
    /* PageSize selector height follows touch size */
    .pagesize-select,
    .pagesize-select .mud-input-control,
    .pagesize-select .mud-input {
        min-height: 40px !important;
    }
}

/* J) Filter chips — horizontal scroll on mobile instead of wrap.
   Gives a single swipeable row like native iOS/Android. */
@media (max-width: 767px) {
    .toolbar-buttons .mud-button-group-root,
    .toolbar-buttons .mud-toggle-group {
        flex-wrap: nowrap !important;
        overflow-x: auto;
        scroll-snap-type: x proximity;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: thin;
    }
    .toolbar-buttons .mud-button-group-root .mud-button-root,
    .toolbar-buttons .mud-toggle-group .mud-toggle-item {
        flex-shrink: 0;
        scroll-snap-align: start;
    }
    /* Hide scrollbars on mobile, the swipe itself is the affordance */
    .toolbar-buttons .mud-button-group-root::-webkit-scrollbar,
    .toolbar-buttons .mud-toggle-group::-webkit-scrollbar {
        height: 3px;
    }
}

/* K) Replace :hover effects with :active / :focus-visible on touch */
@media (hover: none) {
    .mud-button-root:hover,
    .mud-icon-button:hover {
        background: inherit !important;
    }
    .mud-button-root:active,
    .mud-icon-button:active {
        background: var(--mud-palette-action-default-hover) !important;
    }
}

/* L) Landscape mobile (e.g. 812×375) — even tighter page-header */
@media (max-width: 959px) and (max-height: 450px) {
    .page-header {
        margin-bottom: 4px !important;
        padding: 4px 8px !important;
    }
    .page-title {
        font-size: 1rem !important;
    }
    .page-subtitle,
    .page-title-divider {
        display: none !important;
    }
}

/* =============================================================================
   GLOBAL MUDBLAZOR OVERRIDES - Elegant Styling
   ============================================================================= */

/* Paper & Cards - Enterprise border + minimal shadow */
.mud-paper {
    border-radius: 6px;
}

.mud-card {
    border-radius: 6px;
    border: 1px solid rgba(0, 0, 0, 0.08);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.mud-card:hover {
    background: rgba(0, 0, 0, 0.01);
    border-color: rgba(0, 0, 0, 0.14);
}

/* Buttons - Enterprise flat style */
.mud-button-root {
    border-radius: 6px !important;
    transition: background 150ms ease, border-color 150ms ease !important;
    box-shadow: none !important;
}

.mud-icon-button {
    border-radius: 6px !important;
    transition: background 150ms ease !important;
}

/* Text Fields - Clean borders */
.mud-input-outlined .mud-input-outlined-border {
    border-radius: 6px !important;
    border-color: rgba(0, 0, 0, 0.1) !important;
    transition: border-color 200ms ease !important;
}

.mud-input-outlined:hover .mud-input-outlined-border {
    border-color: var(--mud-palette-primary) !important;
}

.mud-input-outlined.mud-input-focused .mud-input-outlined-border {
    border-width: 1px !important;
}

/* Select - Clean styling */
.mud-select .mud-input-outlined-border {
    border-radius: 6px !important;
}

/* Autocomplete */
.mud-autocomplete .mud-input-outlined-border {
    border-radius: 6px !important;
}

/* Chips - Enterprise compact (not pill-form) */
.mud-chip {
    border-radius: 6px !important;
    font-size: 0.75rem !important;
    font-weight: 500 !important;
}

/* Tables - Clean borders */
.mud-table {
    border-radius: 6px !important;
    overflow: hidden;
    border: 1px solid rgba(0, 0, 0, 0.06);
}

.mud-table-head {
    background: rgba(0, 0, 0, 0.02);
}

.mud-table-row:hover {
    background: rgba(0, 0, 0, 0.04) !important;
}

/* Dialogs - Enterprise radius */
.mud-dialog {
    border-radius: 12px !important;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12) !important;
}

/* Drawer - No shadow, clean border only */
.mud-drawer {
    box-shadow: none !important;
    border-right: 1px solid rgba(0, 0, 0, 0.08);
}

/* Menu - Clean popover */
.mud-menu .mud-popover-paper {
    border-radius: 8px !important;
    box-shadow: 0 10px 15px rgba(0, 0, 0, 0.1) !important;
    border: 1px solid rgba(0, 0, 0, 0.06);
}

.mud-menu-item {
    border-radius: 6px;
    margin: 2px 4px;
    transition: background 150ms ease;
}

/* Tooltips */
.mud-tooltip {
    border-radius: 6px !important;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.07) !important;
}

/* Snackbar - Clean notifications */
.mud-snackbar {
    border-radius: 6px !important;
    box-shadow: 0 10px 15px rgba(0, 0, 0, 0.1) !important;
}

/* Progress - Rounded */
.mud-progress-linear {
    border-radius: 4px !important;
    overflow: hidden;
}

/* Tabs - Clean underline */
.mud-tabs-toolbar {
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
}

/* Expansion Panels */
.mud-expand-panel {
    border-radius: 6px !important;
    margin-bottom: 8px;
}

/* =============================================================================
   SCROLLBAR STYLING
   ============================================================================= */

::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.15);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.25);
}

/* Firefox */
* {
    scrollbar-width: thin;
    scrollbar-color: rgba(0, 0, 0, 0.15) transparent;
}

/* =============================================================================
   TYPOGRAPHY ENHANCEMENTS
   ============================================================================= */

h1, h2, h3, h4, h5, h6 {
    font-weight: 600;
    line-height: 1.3;
}

/* =============================================================================
   LAYOUT UTILITIES
   ============================================================================= */

.page-container {
    padding: 24px;
    max-width: 1600px;
    margin: 0 auto;
}

.section-card {
    background: var(--mud-palette-surface);
    border: 1px solid rgba(0, 0, 0, 0.06);
    border-radius: 6px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    padding: 20px;
    margin-bottom: 16px;
}

/* =============================================================================
   DARK MODE ADJUSTMENTS - uses MudBlazor theme class instead of prefers-color-scheme
   ============================================================================= */

.mud-theme-dark .mud-card,
.mud-theme-dark .mud-table,
.mud-theme-dark .mud-dialog,
.mud-theme-dark .mud-menu .mud-popover-paper {
    border-color: rgba(255, 255, 255, 0.06);
}

.mud-theme-dark .mud-table-head {
    background: rgba(255, 255, 255, 0.02);
}

.mud-theme-dark .mud-table-row:hover {
    background: rgba(255, 255, 255, 0.04) !important;
}

.mud-theme-dark ::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
}

.mud-theme-dark ::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.25);
}

.mud-theme-dark * {
    scrollbar-color: rgba(255, 255, 255, 0.15) transparent;
}

/* =============================================================================
   ACCESSIBILITY
   ============================================================================= */

/* Focus visible for keyboard navigation */
:focus-visible {
    outline: 2px solid var(--mud-palette-primary);
    outline-offset: 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;
    }
}

/* High contrast */
@media (prefers-contrast: high) {
    .mud-card,
    .mud-paper,
    .mud-table,
    .mud-dialog {
        border-width: 2px;
    }
}

/* =============================================================================
   PRINT STYLES
   ============================================================================= */

@media print {
    .mud-drawer,
    .mud-appbar,
    .mud-snackbar {
        display: none !important;
    }

    .page-container {
        padding: 0;
    }

    .mud-card,
    .mud-paper {
        box-shadow: none !important;
        border: 1px solid #000;
    }
}

/* =============================================================================
   CHECKBOX & RADIO LABEL FIX
   Keep primary color for icons, readable text for labels
   ============================================================================= */

.mud-checkbox .mud-typography,
.mud-radio .mud-typography {
    color: var(--mud-palette-text-primary) !important;
}

.mud-theme-dark .mud-checkbox .mud-typography,
.mud-theme-dark .mud-radio .mud-typography {
    color: var(--mud-palette-text-primary) !important;
}
