/* ================================================================================================
   SAM theme overlay - ASA design tokens
   A port of the shared `design-tokens` package (src/theme.css, colors.ts, radius.ts, spacing.ts,
   typography.ts, shadows.ts) onto the XAF Blazor UI. Pure CSS - no markup or component changes.

   TO REVERT: set "SAM:ThemeOverlay" in appsettings.json to "modern" (the previous cyan overlay) or
   "none" (stock XAF theme). No rebuild needed - just restart. See Pages/_Host.cshtml.

   STRUCTURE
     1. Token layer      - the design tokens verbatim, using the same variable names as theme.css
                           so the two can be diffed/kept in sync by name.
     2. Bridge layer     - maps Bootstrap/DevExpress theme variables onto the tokens.
     3. Component layer  - XAF/DevExpress specifics that don't follow the theme variables.

   DELIBERATE DEVIATIONS FROM THE TOKEN FILE (documented so they're not mistaken for drift):
     - Base font size stays at the DevExpress default (~14px = --font-size-sm) instead of the token
       --font-size-base (16px). SAM's grids are dense - a global 16px base reflows every list view.
       The type scale is applied per role (captions xs, body sm, headings lg/xl) instead.
     - Grid row hover uses --color-selected; actual selection uses --color-primary-background, which
       the token set doesn't distinguish, but an unmistakable selected row matters in SAM's lists.
     - colorsDark is not wired up (the token file marks dark mode "not wired yet" too).
   ================================================================================================ */

/* ================================================================================================
   1. TOKENS  (mirrors design-tokens/src/theme.css @theme block)
   ================================================================================================ */

:root {
    /* --- Colors: surfaces --- */
    --color-background: #f1f5f9;            /* slate-100  - page canvas */
    --color-card: #ffffff;                  /* white      - raised surfaces */
    --color-background-menu: #ffffff;
    --color-header-background: #f8fafc;     /* slate-50 */
    --color-input: #f8fafc;                 /* slate-50 */
    --color-selected: #f1f5f9;              /* slate-100 */

    /* --- Colors: text --- */
    --color-foreground: #262626;            /* neutral-800 */
    --color-muted-foreground: #64748b;      /* slate-500 */
    --color-secondary: #64748b;             /* slate-500 */

    /* --- Colors: primary --- */
    --color-primary: #3b82f6;               /* blue-500 */
    --color-primary-background: #dbeafe;    /* blue-100 */
    --color-primary-foreground: #ffffff;

    /* --- Colors: brand --- */
    --color-asa: #009de0;
    --color-asa-background: #d7f3ff;

    /* --- Colors: borders --- */
    --color-border: rgba(148, 163, 184, 0.3);   /* slate-400/30 */

    /* --- Colors: status --- */
    --color-warning: #f97316;               /* orange-500 */
    --color-warning-background: #ffedd5;    /* orange-100 */
    --color-danger: #ef4444;                /* red-500 */
    --color-danger-background: #fee2e2;     /* red-100 */
    --color-success: #22c55e;               /* green-500 */
    --color-success-background: #dcfce7;    /* green-100 */
    --color-highlight: #8b5cf6;             /* violet-500 */
    --color-highlight-background: #ede9fe;  /* violet-100 */

    /* --- Radius (base 0.625rem = 10px) --- */
    --radius-base: 0.625rem;
    --radius-sm: calc(var(--radius-base) - 4px);
    --radius-md: calc(var(--radius-base) - 2px);
    --radius-lg: var(--radius-base);
    --radius-xl: calc(var(--radius-base) + 4px);
    --radius-2xl: calc(var(--radius-base) + 8px);

    /* --- Spacing --- */
    --spacing-half: 0.125rem;
    --spacing-one: 0.25rem;
    --spacing-two: 0.5rem;
    --spacing-three: 1rem;
    --spacing-four: 1.5rem;
    --spacing-five: 2rem;

    /* --- Typography --- */
    --font-size-xs: 0.75rem;
    --font-size-sm: 0.875rem;
    --font-size-base: 1rem;
    --font-size-lg: 1.125rem;
    --font-size-xl: 1.25rem;
    --font-size-2xl: 1.5rem;
    --font-weight-normal: 400;
    --font-weight-medium: 500;
    --font-weight-semibold: 600;
    --font-weight-bold: 700;

    /* --- Shadows (design-tokens/src/shadows.ts -> bottomBoxShadow) --- */
    --shadow-2xs: 0 1px 1px -1px rgba(0, 0, 0, 0.05);
    --shadow-xs: 0 1px 2px -1px rgba(0, 0, 0, 0.05);
    --shadow-sm: 0 1px 3px -1px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 2px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 4px 15px -4px rgba(0, 0, 0, 0.1);
    --shadow-xl: 0 8px 25px -8px rgba(0, 0, 0, 0.1);
    --shadow-2xl: 0 12px 50px -12px rgba(0, 0, 0, 0.25);

    /* --- Derived shades (not tokens; needed for hover/active states) --- */
    --color-primary-hover: #2563eb;         /* blue-600 */
    --color-primary-active: #1d4ed8;        /* blue-700 */
    --color-primary-ring: rgba(59, 130, 246, 0.2);
    --color-border-strong: rgba(148, 163, 184, 0.55);
    --color-hover-surface: #f8fafc;         /* slate-50 */
}

/* ================================================================================================
   2. BRIDGE  - re-point the Bootstrap/DevExpress theme variables at the tokens.
   The stock XAF theme accent is orange (#fe7109); everything that reads --bs-primary follows this.
   ================================================================================================ */

:root {
    --bs-primary: var(--color-primary);
    --bs-primary-rgb: 59, 130, 246;
    --bs-body-color: var(--color-foreground);
    --bs-body-bg: var(--color-background);
    --bs-border-color: var(--color-border);
    --bs-border-radius: var(--radius-md);
    --bs-link-color: var(--color-primary);
    --bs-link-color-rgb: 59, 130, 246;
    --bs-link-hover-color: var(--color-primary-hover);
    --bs-link-hover-color-rgb: 37, 99, 235;
    --bs-secondary-color: var(--color-muted-foreground);
}

body {
    font-family: -apple-system, "Segoe UI", system-ui, Roboto, "Helvetica Neue", Arial, sans-serif;
    color: var(--color-foreground);
    background: var(--color-background);
}

/* ================================================================================================
   3. COMPONENTS
   ================================================================================================ */

/* ---------- Header (top app bar) ---------- */

.app > .header {
    background: var(--color-card) !important;
    border-bottom: 1px solid var(--color-border);
    box-shadow: var(--shadow-xs);
}

/* Replace the theme's masked "XAF" logo with a SAM wordmark in the ASA brand color. */
.app > .header .header-logo {
    -webkit-mask: none !important;
    mask: none !important;
    background: none !important;
    width: auto !important;
}

.app > .header .header-logo::after {
    content: "SAM";
    font-weight: var(--font-weight-bold);
    font-size: var(--font-size-lg);
    letter-spacing: 0.16em;
    color: var(--color-asa);
}

/* ---------- Sidebar + navigation ---------- */

.xaf-sidebar.sidebar {
    background: var(--color-background-menu);
    border-right: 1px solid var(--color-border);
}

.xaf-navmenu.dxbl-treeview {
    padding: var(--spacing-one) 6px;
}

.xaf-navmenu .dxbl-treeview-item-container {
    border-radius: var(--radius-md);
    margin: 1px var(--spacing-one);
    color: var(--color-foreground);
    font-size: var(--font-size-sm);
}

.xaf-navmenu .dxbl-treeview-item-container:hover {
    background: var(--color-selected) !important;
}

.xaf-navmenu .dxbl-treeview-item-container.dxbl-active,
.xaf-navmenu .dxbl-treeview-item-container.dxbl-active:hover {
    background: var(--color-primary-background) !important;
    color: var(--color-primary-active) !important;
    font-weight: var(--font-weight-semibold);
}

.xaf-navmenu .dxbl-treeview-item-container.dxbl-active * {
    color: var(--color-primary-active) !important;
}

/* The theme paints the selected-item pill via a ::before pseudo-element with a hardcoded orange -
   overriding --bs-primary does not reach it. Hide it; the container carries the tint above. */
.xaf-navmenu .dxbl-treeview-item-container.dxbl-active::before {
    background-color: transparent !important;
}

/* ---------- Content canvas ---------- */

.main .main-content {
    background: var(--color-background);
    padding: 0 14px var(--spacing-two) 14px;
}

/* ---------- Tabbed MDI strip ----------
   The MDI tab strip is its own white bar; the tab CONTENT area takes the canvas color so the white
   cards inside it separate visibly. Direct-child selectors ONLY - inner dxbl-tabs (detail tabs,
   nested-list tabs) must keep their own styling. */

.xaf-tabbed-mdi > .dxbl-tabs-tablist {
    background: var(--color-card);
    border-bottom: 1px solid var(--color-border);
    padding: 6px var(--spacing-two) 0 var(--spacing-two);
}

.xaf-tabbed-mdi > .dxbl-tabs-content-panel > .dxbl-tabs-content {
    background: var(--color-background);
}

/* ---------- Toolbars ----------
   The card (surface/border/radius/shadow) goes on the WRAPPER - .main-toolbar / .nested-toolbar -
   which is a normal in-flow element whose padding behaves, and the DevExpress toolbar inside keeps
   its stock geometry.

   WHY, so this isn't "simplified" back later: DxToolbar renders its items into a .dxbl-btn-toolbar
   strip that is position:absolute anchored to the toolbar's edges. That strip does not contribute to
   the toolbar's height and ignores its padding. Carding .dxbl-toolbar directly therefore needs the
   strip nudged by fixed pixel offsets - which only lines up for ONE DevExpress base theme. Under
   `office-white` the toolbar box is 30px and the strip is also 30px, so a 3px top offset pushed the
   buttons out through the bottom of the rounded card (under `fluent` the box is 40px and it fit).
   Centering the strip in whatever height the toolbar happens to have is correct in every base theme
   and size mode. Verified on office-white (30px) and fluent (40px). */

.main .main-toolbar {
    background: var(--color-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    padding: var(--spacing-one) var(--spacing-two);
    margin: 12px 14px var(--spacing-two) 14px;
}

/* Nested frames (MultiView bottom-block tabs). site.css pins this with `flex: none`, so padding is
   safe here but an outer margin would fight the pinned flex chain - keep it tight. */
.nested-toolbar {
    background: var(--color-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    padding: var(--spacing-one) var(--spacing-two);
}

.main .main-toolbar .dxbl-toolbar,
.nested-toolbar .dxbl-toolbar {
    background: transparent;
    border: 0;
    box-shadow: none;
    padding: 0;
}

/* :not(.dxbl-virtual-toolbar): DxToolbar keeps a hidden full-width COPY of the strip (its adaptive
   measuring copy, also a .dxbl-btn-toolbar) parked at top/left -10000px. Matching it here dragged
   that copy into the toolbar, where its never-collapsed items ran past the right edge and gave
   the page scroller a horizontal scrollbar on any window narrower than the full toolbar. */
.main .main-toolbar .dxbl-toolbar > .dxbl-btn-toolbar:not(.dxbl-virtual-toolbar),
.nested-toolbar .dxbl-toolbar > .dxbl-btn-toolbar:not(.dxbl-virtual-toolbar) {
    top: 50% !important;
    transform: translateY(-50%);
    left: 0 !important;
    right: 0 !important;
}

/* ---------- Buttons ---------- */

.dxbl-btn {
    border-radius: var(--radius-md) !important;
    font-weight: var(--font-weight-medium);
}

.dxbl-toolbar .dxbl-btn.dxbl-btn-secondary:not(.dxbl-btn-primary) {
    background: transparent;
    border-color: transparent;
    color: var(--color-foreground);
}

.dxbl-toolbar .dxbl-btn.dxbl-btn-secondary:not(.dxbl-btn-primary):hover {
    background: var(--color-selected);
    border-color: transparent;
    color: var(--color-foreground);
}

.dxbl-btn-primary:not(.dxbl-disabled),
.btn-primary {
    background-color: var(--color-primary) !important;
    border-color: var(--color-primary) !important;
    color: var(--color-primary-foreground) !important;
}

.dxbl-btn-primary:not(.dxbl-disabled):hover,
.btn-primary:hover {
    background-color: var(--color-primary-hover) !important;
    border-color: var(--color-primary-hover) !important;
}

.dxbl-btn-primary.dxbl-disabled {
    background-color: var(--color-primary-background) !important;
    border-color: var(--color-primary-background) !important;
    color: var(--color-primary-foreground) !important;
}

.dxbl-btn:focus-visible {
    box-shadow: 0 0 0 3px var(--color-primary-ring) !important;
}

/* ---------- Grids ---------- */

.dxbl-grid,
dxbl-tree-list.dxbl-grid {
    background: var(--color-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-xs);
}

.dxbl-grid th.dxbl-grid-header,
.dxbl-grid .dxbl-grid-header {
    background: var(--color-header-background);
    color: var(--color-muted-foreground);
    font-weight: var(--font-weight-semibold);
    font-size: var(--font-size-xs);
}

.dxbl-grid td {
    border-color: var(--color-border) !important;
    font-size: var(--font-size-sm);
}

.dxbl-grid tbody tr:hover > td:not([class*="selection"]) {
    background-color: var(--color-selected);
}

/* Token set has a single `selected`; SAM's lists need selection to read at a glance, so selected
   rows take the primary tint and hover keeps the neutral one. */
.dxbl-grid tbody tr.dxbl-selected > td,
.dxbl-grid tbody tr[class*="selected"] > td {
    background-color: var(--color-primary-background) !important;
}

.dxbl-grid .dxbl-pager {
    background: var(--color-card);
    color: var(--color-muted-foreground);
    font-size: var(--font-size-sm);
}

/* The current page button carries the theme accent as a hardcoded background. */
.dxbl-pager .dxbl-pager-page-btn.dxbl-pager-active-page-btn,
.dxbl-pager-page-btn.dxbl-pager-active-page-btn {
    background-color: var(--color-primary) !important;
    border-color: var(--color-primary) !important;
    color: var(--color-primary-foreground) !important;
}

/* ---------- Progress / loading indicators ---------- */

.progress-bar,
.dxbl-progress-bar-indicator {
    background-color: var(--color-primary) !important;
}

/* ---------- Tabs ---------- */

.dxbl-tabs {
    background: transparent;
}

.dxbl-tabs > .dxbl-tabs-tablist {
    border-bottom: 1px solid var(--color-border);
    gap: var(--spacing-half);
}

dxbl-tab-item.dxbl-tabs-item {
    color: var(--color-muted-foreground);
    font-weight: var(--font-weight-medium);
    font-size: var(--font-size-sm);
    border-top-left-radius: var(--radius-md);
    border-top-right-radius: var(--radius-md);
}

dxbl-tab-item.dxbl-tabs-item:hover {
    color: var(--color-foreground);
    background: var(--color-selected);
}

dxbl-tab-item.dxbl-tabs-item.dxbl-active {
    color: var(--color-primary-hover) !important;
    font-weight: var(--font-weight-semibold);
}

/* The active-tab underline is a 2px ::after with a hardcoded theme orange - recolor it. */
dxbl-tab-item.dxbl-tabs-item.dxbl-active::after {
    background-color: var(--color-primary) !important;
}

/* ---------- Inputs / editors ---------- */

.dxbl-text-edit,
.dxbl-memo,
.dxbl-combobox,
.dxbl-date-edit,
.dxbl-spin-edit {
    border-radius: var(--radius-md) !important;
    background-color: var(--color-input);
    font-size: var(--font-size-sm);
}

.dxbl-text-edit:focus-within,
.dxbl-memo:focus-within,
.dxbl-combobox:focus-within,
.dxbl-date-edit:focus-within,
.dxbl-spin-edit:focus-within {
    border-color: var(--color-primary) !important;
    box-shadow: 0 0 0 3px var(--color-primary-ring) !important;
}

input[type="checkbox"],
input[type="radio"] {
    accent-color: var(--color-primary);
}

/* Detail view captions */
.dxbl-fl-cpt,
.dxbl-form-layout-item-caption {
    color: var(--color-muted-foreground);
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-medium);
}

/* ---------- Popups / windows ---------- */

.dxbl-window {
    border-radius: var(--radius-xl);
    border: 1px solid var(--color-border);
    box-shadow: var(--shadow-2xl);
    overflow: hidden;
}

.dxbl-window-header {
    background: var(--color-header-background);
    border-bottom: 1px solid var(--color-border);
    font-weight: var(--font-weight-semibold);
}

/* ---------- Dynamic counter blocks (SAM-specific, rendered by our own editors) ---------- */

.sam-counter-caption {
    color: var(--color-muted-foreground);
    font-size: var(--font-size-xs);
}

.sam-counter-value {
    font-weight: var(--font-weight-semibold);
    color: var(--color-foreground);
}

/* ---------- Splitter handles (base styling lives in site.css) ---------- */

.sam-splitter-handle:hover,
.sam-splitter-handle-h:hover,
.sam-splitter-handle.sam-dragging,
.sam-splitter-handle-h.sam-dragging {
    background: var(--color-primary-ring) !important;
}

/* ---------- Scrollbars ---------- */

* {
    scrollbar-width: thin;
    scrollbar-color: var(--color-border-strong) transparent;
}

*::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

*::-webkit-scrollbar-thumb {
    background: var(--color-border-strong);
    border-radius: 5px;
    border: 2px solid transparent;
    background-clip: content-box;
}

*::-webkit-scrollbar-thumb:hover {
    background: var(--color-secondary);
    background-clip: content-box;
}

*::-webkit-scrollbar-track {
    background: transparent;
}
