/* Global MudBlazor design overrides — flat, bordered, rounded.
   Ported from the SignageServer design system. The intent is to give the
   whole app a consistent look without per-page styling: kill shadows, use
   1px divider borders for separation, round corners to 8px, and apply
   pill-style chrome to nav links and tabs. */

/* ── Base ── */
html, body {
    /* Suppress horizontal overflow at the document root. Position:fixed
       widgets that use logical inset properties (e.g. GlobalChatWidget's
       `inset-inline-end:Xpx`) are anchored to a different physical edge in
       RTL and can extend past the opposite edge — without this, Arabic
       mode developed a huge horizontal scroll. */
    overflow-x: hidden;
}

body {
    background-color: var(--mud-palette-background);
}

/* ── Kill all shadows ── */
.mud-button-root,
.mud-fab,
.mud-tooltip,
.mud-picker,
.mud-picker-container,
.mud-select,
.mud-alert,
.mud-expansion-panels,
.mud-expansion-panel,
.mud-card,
.mud-paper,
.mud-dialog,
.mud-popover-paper,
.mud-snackbar,
.mud-table,
.mud-drawer {
    box-shadow: none !important;
}

/* ── Consistent border radius ── */
.mud-paper,
.mud-card,
.mud-dialog,
.mud-alert,
.mud-expansion-panel,
.mud-popover-paper,
.mud-snackbar,
.mud-picker-container {
    border-radius: 8px !important;
}

/* ── Borders on containers (not nested children) ── */
.mud-paper.mud-elevation-1,
.mud-paper.mud-elevation-2,
.mud-paper.mud-elevation-3,
.mud-paper.mud-elevation-4 {
    border: 1px solid var(--mud-palette-divider);
}

/* Tables — only when they are the top-level container */
.mud-table:not(.mud-paper .mud-table) {
    border: 1px solid var(--mud-palette-divider);
    border-radius: 8px !important;
}

/* Tables inside paper — no extra border */
.mud-paper .mud-table {
    border: none;
}

/* Softer table row dividers */
.mud-table .mud-table-row td {
    border-bottom: 1px solid rgba(0, 0, 0, 0.06) !important;
}

.dark-mode .mud-table .mud-table-row td {
    border-bottom: 1px solid rgba(255, 255, 255, 0.06) !important;
}

.mud-table .mud-table-row:last-child td {
    border-bottom: none;
}

/* Table header — subtle separation */
.mud-table .mud-table-head th {
    border-bottom: 1px solid var(--mud-palette-divider);
}

/* Progress bar — match container rounding */
.mud-progress-linear {
    border-radius: 6px !important;
}

/* ── Layout ── */

/* AppBar — subtle bottom border + translucent blur */
.mud-appbar {
    border-bottom: 1px solid var(--mud-palette-divider) !important;
}

/* AppBar honors the org's AppbarBackground from the theme but renders at
   80% opacity with a backdrop blur for the translucent flat-design feel.
   color-mix lets us reuse the theme variable directly so customised
   branding flows through automatically (light + dark modes both). */
.appbar-blur {
    background-color: color-mix(in srgb,
                                var(--mud-palette-appbar-background) 80%,
                                transparent) !important;
    color: var(--mud-palette-appbar-text) !important;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

/* Drawer — no border by default. overflow-x:hidden prevents the
   horizontal scrollbar that otherwise appears when the vertical
   scrollbar's gutter eats ~16px from a nav-link sized at width:100%
   by MudBlazor. */
.mud-drawer {
    border-right: none !important;
    overflow-x: hidden;
}

/* Right (AI / conversation) drawer: subtle 1px divider on BOTH inline edges
   so it reads as separated from the main canvas regardless of language
   direction. Targets `.right-pane-drawer` (custom class on the MudDrawer
   in MainLayout) → `.mud-drawer-content` (the inner content surface).
   We can't key off `.mud-drawer-pos-right` because Anchor.End flips that
   class to `.mud-drawer-pos-left` in RTL — the custom class is stable. */
.right-pane-drawer .mud-drawer-content {
    border-left:  1px solid var(--mud-palette-divider) !important;
    border-right: 1px solid var(--mud-palette-divider) !important;
}

/* GlobalChatWidget bottom bar — position uses `inset-inline-end` inline
   so it anchors to the inline-end edge (right in LTR, left in RTL).
   Static layout lives here. */
.global-chat-widget__bar {
    display: flex;
    align-items: flex-end;
    gap: 4px;
    padding-inline-end: 4px;
}
/* ── Overlays ── */
.mud-dialog {
    border: 1px solid var(--mud-palette-divider);
}

.mud-popover-paper,
.mud-popover,
.mud-popover.mud-paper {
    border: 1px solid var(--mud-palette-divider) !important;
}

.mud-snackbar {
    border: 1px solid var(--mud-palette-divider);
}

.mud-tooltip {
    border: 1px solid var(--mud-palette-divider);
}

.mud-picker-container {
    border: 1px solid var(--mud-palette-divider);
}

/* ── ApexCharts: inherit site font and adapt to theme ── */
.apexcharts-canvas,
.apexcharts-text,
.apexcharts-title-text,
.apexcharts-subtitle-text,
.apexcharts-xaxis-label,
.apexcharts-yaxis-label,
.apexcharts-xaxis-title text,
.apexcharts-yaxis-title text,
.apexcharts-legend-text,
.apexcharts-datalabel,
.apexcharts-datalabel-label,
.apexcharts-datalabel-value,
.apexcharts-tooltip,
.apexcharts-tooltip-title,
.apexcharts-tooltip-text,
.apexcharts-xaxistooltip,
.apexcharts-yaxistooltip {
    font-family: "IBM Plex Sans Arabic", "Helvetica Neue", Helvetica, Arial, sans-serif !important;
}

/* Text colors — use MudBlazor theme vars so they track light/dark automatically */
.apexcharts-text tspan,
.apexcharts-title-text,
.apexcharts-subtitle-text,
.apexcharts-xaxis-label,
.apexcharts-yaxis-label,
.apexcharts-xaxis-title text,
.apexcharts-yaxis-title text,
.apexcharts-datalabel,
.apexcharts-datalabel-label,
.apexcharts-datalabel-value {
    fill: var(--mud-palette-text-primary) !important;
}

.apexcharts-legend-text {
    color: var(--mud-palette-text-primary) !important;
}

/* Gridlines, axis lines, and ticks */
.apexcharts-gridline,
.apexcharts-grid-borders line {
    stroke: var(--mud-palette-divider) !important;
}

.apexcharts-xaxis line,
.apexcharts-yaxis line,
.apexcharts-xaxis-tick,
.apexcharts-yaxis-tick {
    stroke: var(--mud-palette-lines-default, var(--mud-palette-divider)) !important;
}

/* Tooltip — dark mode needs a readable background */
.dark-mode .apexcharts-tooltip.apexcharts-theme-light {
    background: var(--mud-palette-surface) !important;
    color: var(--mud-palette-text-primary) !important;
    border: 1px solid var(--mud-palette-divider) !important;
    box-shadow: none !important;
}

.dark-mode .apexcharts-tooltip.apexcharts-theme-light .apexcharts-tooltip-title {
    background: var(--mud-palette-background-grey, var(--mud-palette-surface)) !important;
    color: var(--mud-palette-text-primary) !important;
    border-bottom: 1px solid var(--mud-palette-divider) !important;
}

.dark-mode .apexcharts-xaxistooltip,
.dark-mode .apexcharts-yaxistooltip {
    background: var(--mud-palette-surface) !important;
    color: var(--mud-palette-text-primary) !important;
    border-color: var(--mud-palette-divider) !important;
}

/* ── Components ── */

/* Tabs — pill style like nav menu */
.mud-tabs-tabbar,
.mud-tabs-tabbar-inner,
.mud-tabs-header {
    border-bottom: none !important;
    background-color: transparent !important;
}

.mud-tab {
    border-radius: 8px !important;
    margin: 0;
    min-height: unset !important;
    padding: 8px 16px !important;
    text-transform: none !important;
    font-weight: 400;
    letter-spacing: normal !important;
    transition: background-color 0.15s;
}

.mud-tab.mud-tab-active {
    background-color: rgba(var(--mud-palette-primary-rgb), 0.08) !important;
    color: var(--mud-palette-primary) !important;
    font-weight: 600;
}

.mud-tab:hover:not(.mud-tab-active) {
    background-color: var(--mud-palette-action-default-hover, rgba(0,0,0,0.04)) !important;
}

.mud-tabs-tabbar .mud-tooltip-root.mud-tooltip-inline {
    margin: 4px 6px;
}

.mud-tabs-tabbar .mud-tooltip-root.mud-tooltip-inline:first-child {
    margin-left: 0;
}

.mud-tabs-tabbar .mud-tooltip-root.mud-tooltip-inline:last-of-type {
    margin-right: 0;
}

/* Hide the default slider */
.mud-tab-slider {
    display: none !important;
}

/* Chips */
.mud-chip {
    border: 1px solid var(--mud-palette-divider);
}

/* Alert */
.mud-alert {
    border: 1px solid var(--mud-palette-divider);
}

/* Card */
.mud-card {
    border: 1px solid var(--mud-palette-divider);
}

/* Expansion panels */
.mud-expansion-panels {
    border: 1px solid var(--mud-palette-divider);
}

.mud-expansion-panel {
    border-bottom: 1px solid var(--mud-palette-divider);
}

.mud-expansion-panel:last-child {
    border-bottom: none;
}

/* ── Nav menu ── */
.mud-nav-link {
    margin: 4px 8px;
    border-radius: 8px !important;
    transition: background-color 0.15s;
}

.mud-nav-link.active {
    background-color: rgba(var(--mud-palette-primary-rgb), 0.08) !important;
    color: var(--mud-palette-primary) !important;
    font-weight: 600;
}

.mud-nav-link:hover:not(.active) {
    background-color: var(--mud-palette-action-default-hover, rgba(0,0,0,0.04)) !important;
}

/* ── Mobile responsiveness ── */
@media (max-width: 599px) {
    .page-header {
        flex-direction: column;
        align-items: flex-start !important;
    }
}

/* Responsive page headers */
.mud-typography-h3 {
    font-size: clamp(1.5rem, 4vw, 2.5rem) !important;
}

.mud-typography-h4 {
    font-size: clamp(1.3rem, 3.5vw, 2rem) !important;
}

.mud-typography-h5 {
    font-size: clamp(1.15rem, 3vw, 1.5rem) !important;
}

.mud-typography-h6 {
    font-size: clamp(1rem, 2.5vw, 1.25rem) !important;
}

/* Hide redundant table toolbar labels on mobile */
@media (max-width: 599px) {
    .mud-table-toolbar .mud-typography {
        display: none;
    }
}

/* ── Dark mode logo invert ── */
.dark-mode .appbar-logo,
.dark-mode .banner-image {
    filter: invert(1) brightness(2);
}
