/* AdminPanel dark-mode overrides — single global fix.
   MudBlazor palette handles Mud* components, but dozens of custom classes use
   hardcoded light colors (#fff, #f7f9fc, rgba(255,255,255,.96), rgba(0,0,0,.x))
   which stay white in dark mode (white cards on dark background).
   These overrides activate via html.dark (set by theme.js) and .mud-theme-dark
   (set by MudBlazor) so both selectors work. Print sheets stay white on purpose. */

html.dark body,
html.dark .main-content-surface {
    background-color: #0f1222;
    color-scheme: dark;
}

/* ---------- Shells: kill light gradients that look like dirty shadows ---------- */
html.dark .product-shell,
html.dark .blog-shell,
html.dark .customer-shell,
.mud-theme-dark .product-shell,
.mud-theme-dark .blog-shell,
.mud-theme-dark .customer-shell {
    background: transparent !important;
}

/* ---------- Hero / header gradients ending in white ---------- */
html.dark .order-hero,
html.dark .order-hero-brief-item,
.mud-theme-dark .order-hero,
.mud-theme-dark .order-hero-brief-item {
    background: linear-gradient(135deg, rgba(121, 134, 203, 0.16), var(--mud-palette-surface)) !important;
    border-color: rgba(121, 134, 203, 0.32) !important;
}

html.dark .blog-card__header,
html.dark .customer-card__header,
.mud-theme-dark .blog-card__header,
.mud-theme-dark .customer-card__header {
    background: linear-gradient(90deg, rgba(121, 134, 203, 0.12), transparent) !important;
    border-bottom-color: var(--mud-palette-table-lines) !important;
}

/* ---------- Cards forced to #fff ---------- */
html.dark .order-card,
.mud-theme-dark .order-card {
    background: var(--mud-palette-surface) !important;
}

/* ---------- Hardcoded black text on (now dark) surfaces ---------- */
html.dark .order-muted,
html.dark .order-hero-brief-label,
html.dark .order-hero-brief-value,
html.dark .order-empty-text,
html.dark .order-product__queue-label,
html.dark .customer-address-dialog-card__meta,
.mud-theme-dark .order-muted,
.mud-theme-dark .order-hero-brief-label,
.mud-theme-dark .order-hero-brief-value,
.mud-theme-dark .order-empty-text,
.mud-theme-dark .order-product__queue-label,
.mud-theme-dark .customer-address-dialog-card__meta {
    color: var(--mud-palette-text-secondary) !important;
}

html.dark .order-hero-brief-value,
.mud-theme-dark .order-hero-brief-value {
    color: var(--mud-palette-text-primary) !important;
}

/* Plain/gray pills using black alpha look broken on dark — lift them */
html.dark .order-product__stockcode--plain,
html.dark .order-return-code--disabled,
.mud-theme-dark .order-product__stockcode--plain,
.mud-theme-dark .order-return-code--disabled {
    background: rgba(255, 255, 255, 0.06) !important;
    border-color: rgba(255, 255, 255, 0.14) !important;
    color: var(--mud-palette-text-secondary) !important;
}

/* ---------- Rich-text editors (Blog/Product) ---------- */
html.dark .rich-editor,
.mud-theme-dark .rich-editor {
    background: var(--mud-palette-surface) !important;
    border-color: var(--mud-palette-table-lines) !important;
}

html.dark .editor-toolbar,
.mud-theme-dark .editor-toolbar {
    background: rgba(255, 255, 255, 0.04) !important;
    border-bottom-color: var(--mud-palette-table-lines) !important;
}

html.dark .editor-content,
.mud-theme-dark .editor-content {
    background: transparent !important;
    color: var(--mud-palette-text-primary) !important;
}

html.dark .rich-editor .blog-editor-loading,
.mud-theme-dark .rich-editor .blog-editor-loading {
    background: rgba(15, 18, 34, 0.72) !important;
}

html.dark .product-upload-loading,
.mud-theme-dark .product-upload-loading {
    background: rgba(15, 18, 34, 0.9) !important;
}

html.dark .blog-cover-thumb,
.mud-theme-dark .blog-cover-thumb {
    background: rgba(255, 255, 255, 0.06) !important;
    border-color: var(--mud-palette-table-lines) !important;
}

/* ---------- Saving / loading overlays forced white ---------- */
html.dark .order-saving-overlay,
.mud-theme-dark .order-saving-overlay {
    background: rgba(10, 13, 28, 0.72) !important;
}

html.dark .order-saving-content,
.mud-theme-dark .order-saving-content {
    background: var(--mud-palette-surface) !important;
    color: var(--mud-palette-text-primary) !important;
}

/* ---------- Generic light boxes (warehouse dialogs etc.) ---------- */
html.dark .users-perm-box,
.mud-theme-dark .users-perm-box {
    background: rgba(121, 134, 203, 0.10) !important;
    border-color: rgba(121, 134, 203, 0.35) !important;
}

/* Cards with thin black-alpha borders — visible on dark */
html.dark .product-card,
html.dark .customer-card,
html.dark .users-card,
.mud-theme-dark .product-card,
.mud-theme-dark .customer-card,
.mud-theme-dark .users-card {
    border-color: var(--mud-palette-table-lines) !important;
}

/* ---------- Order grid: secondary texts are hardcoded black (invisible on dark rows) ---------- */
html.dark .order-cell-sub,
html.dark .order-cell-address,
html.dark .order-empty-text,
.mud-theme-dark .order-cell-sub,
.mud-theme-dark .order-cell-address,
.mud-theme-dark .order-empty-text {
    color: #aeb6d3 !important;
}

/* Dark green "paid" amount on dark navy is unreadable — use light green. */
html.dark .order-money--paid,
.mud-theme-dark .order-money--paid {
    color: #81c784 !important;
}

/* Brand blues tuned for white backgrounds turn dim/dark on navy — lift them. */
html.dark .order-code,
html.dark .order-product__qty,
html.dark .order-filter-title,
html.dark .order-accordion .mud-expansion-panel-header,
html.dark .order-savedfilters .mud-expansion-panel-header,
.mud-theme-dark .order-code,
.mud-theme-dark .order-product__qty,
.mud-theme-dark .order-filter-title,
.mud-theme-dark .order-accordion .mud-expansion-panel-header,
.mud-theme-dark .order-savedfilters .mud-expansion-panel-header {
    color: #9da9e8 !important;
}

html.dark .order-filter-title,
.mud-theme-dark .order-filter-title {
    border-inline-start-color: rgba(121, 134, 203, 0.6) !important;
}

/* Stock-code pills use dark-blue text — swap to a bright indigo pill. */
html.dark .order-product__stockcode,
.mud-theme-dark .order-product__stockcode {
    background: rgba(121, 134, 203, 0.14) !important;
    border-color: rgba(121, 134, 203, 0.4) !important;
    color: #c5cae9 !important;
}

html.dark .order-grid-table.mud-table,
.mud-theme-dark .order-grid-table.mud-table {
    border-color: var(--mud-palette-table-lines) !important;
}

/* ---------- Customers grid: hardcoded black sub-texts (timestamps, empty states) ---------- */
html.dark .customer-addresses__empty,
html.dark .customer-description__empty,
html.dark .customer-created-at,
html.dark .customer-address-dialog-card__meta,
.mud-theme-dark .customer-addresses__empty,
.mud-theme-dark .customer-description__empty,
.mud-theme-dark .customer-created-at,
.mud-theme-dark .customer-address-dialog-card__meta {
    color: #aeb6d3 !important;
}

/* White-gradient dialog cards → dark tinted cards. */
html.dark .customer-description-dialog,
html.dark .customer-address-dialog-card,
.mud-theme-dark .customer-description-dialog,
.mud-theme-dark .customer-address-dialog-card {
    background: linear-gradient(135deg, rgba(121, 134, 203, 0.14), var(--mud-palette-surface)) !important;
    border-color: rgba(121, 134, 203, 0.32) !important;
}

/* ---------- Users grid: dark-indigo username is invisible on navy ---------- */
html.dark .users-username,
.mud-theme-dark .users-username {
    color: #9da9e8 !important;
}

html.dark .users-empty-text,
.mud-theme-dark .users-empty-text {
    color: #aeb6d3 !important;
}

/* ---------- Login: bright indigo backdrop + white captcha box glare in dark ---------- */
html.dark .login-wrapper,
.mud-theme-dark .login-wrapper {
    background: linear-gradient(135deg, #0a0e24 0%, #12172e 55%, #1c2447 100%) !important;
}

html.dark .cognitive-captcha-box,
.mud-theme-dark .cognitive-captcha-box {
    background-color: rgba(255, 255, 255, 0.05) !important;
    border-color: var(--mud-palette-table-lines) !important;
}

html.dark .cognitive-captcha-box .text-success,
.mud-theme-dark .cognitive-captcha-box .text-success {
    color: #81c784 !important;
}

html.dark .captcha-item-wrapper:hover,
.mud-theme-dark .captcha-item-wrapper:hover {
    background-color: rgba(255, 255, 255, 0.08) !important;
}

/* ---------- Order form (create/edit): white blocks that glare in dark ---------- */
html.dark .order-summary-sticky,
html.dark .order-sticky-bar,
html.dark .order-optional-panels .mud-expand-panel,
.mud-theme-dark .order-summary-sticky,
.mud-theme-dark .order-sticky-bar,
.mud-theme-dark .order-optional-panels .mud-expand-panel {
    background: var(--mud-palette-surface) !important;
}

html.dark .order-summary-sticky,
html.dark .order-sticky-bar,
.mud-theme-dark .order-summary-sticky,
.mud-theme-dark .order-sticky-bar {
    border-color: rgba(121, 134, 203, 0.30) !important;
}

html.dark .order-optional-panels,
.mud-theme-dark .order-optional-panels {
    border-color: var(--mud-palette-table-lines) !important;
}

html.dark .order-sidebar-title,
.mud-theme-dark .order-sidebar-title {
    color: var(--mud-palette-text-primary) !important;
    border-bottom-color: var(--mud-palette-table-lines) !important;
}

html.dark .order-product-card,
html.dark .order-product-dropdown-actions,
.mud-theme-dark .order-product-card,
.mud-theme-dark .order-product-dropdown-actions {
    border-color: var(--mud-palette-table-lines) !important;
}

/* Dropdown prices + step labels are hardcoded black — invisible on dark. */
html.dark .order-product-price,
html.dark .step-label,
.mud-theme-dark .order-product-price,
.mud-theme-dark .step-label {
    color: #aeb6d3 !important;
}

/* Inactive step circles: white discs glare and dim numbers — restyle for dark. */
html.dark .step-circle,
.mud-theme-dark .step-circle {
    background: var(--mud-palette-surface) !important;
    border-color: rgba(121, 134, 203, 0.45) !important;
    color: #aeb6d3 !important;
}

html.dark .step-indicator-track,
.mud-theme-dark .step-indicator-track {
    background: rgba(255, 255, 255, 0.14) !important;
}

/* Active/completed circles pair light fills with white numbers (weak) — dark digits. */
html.dark .step-item.active .step-circle,
html.dark .step-item.completed .step-circle,
.mud-theme-dark .step-item.active .step-circle,
.mud-theme-dark .step-item.completed .step-circle {
    color: #10142a !important;
}

/* Dark-orange "remaining" amount on navy is muddy — use warning tone. */
html.dark .order-money--remaining,
.mud-theme-dark .order-money--remaining {
    color: #ffa726 !important;
}

/* Dashed empty-state box + icon tuned for white — lift for dark. */
html.dark .order-empty-state,
.mud-theme-dark .order-empty-state {
    background: rgba(255, 255, 255, 0.03) !important;
    border-color: var(--mud-palette-table-lines) !important;
}

html.dark .order-empty-icon,
.mud-theme-dark .order-empty-icon {
    color: var(--mud-palette-text-secondary) !important;
}

/* ---------- Print sheets: سند چاپ همیشه روشن است (روی صفحه و در چاپ) ---------- */
/* شیت‌ها پس‌زمینه سفید هاردکد دارند ولی color ست نکرده‌اند؛ در تم شب رنگ روشن
   بدنه را به ارث می‌برند (سفید روی سفید). پس رنگ متن را هم صریح قفل می‌کنیم.
   توجه: فقط خود سندها (.print-part و شیت‌ها) — هاست و نوار ابزار (d-print-none)
   تابع تم می‌مانند تا در شب خوانا باشند. */

html.dark .print-part,
html.dark .invoice-sheet,
html.dark .address-print-sheet,
html.dark .warranty-print-sheet,
.mud-theme-dark .print-part,
.mud-theme-dark .invoice-sheet,
.mud-theme-dark .address-print-sheet,
.mud-theme-dark .warranty-print-sheet {
    background: #fff !important;
    background-color: #fff !important;
    color: #000 !important;
    color-scheme: light !important;
    border-color: #d0d0d0 !important;
}

html.dark .print-part th,
html.dark .invoice-sheet th,
html.dark .print-part td,
html.dark .invoice-sheet td,
html.dark .print-part fieldset,
html.dark .print-part legend,
html.dark .invoice-sheet fieldset,
html.dark .invoice-sheet legend,
html.dark .address-print-sheet fieldset,
html.dark .warranty-print-sheet fieldset,
.mud-theme-dark .print-part th,
.mud-theme-dark .invoice-sheet th,
.mud-theme-dark .print-part td,
.mud-theme-dark .invoice-sheet td,
.mud-theme-dark .print-part fieldset,
.mud-theme-dark .print-part legend,
.mud-theme-dark .invoice-sheet fieldset,
.mud-theme-dark .invoice-sheet legend,
.mud-theme-dark .address-print-sheet fieldset,
.mud-theme-dark .warranty-print-sheet fieldset {
    color: #000 !important;
    color-scheme: light !important;
}

html.dark .print-part th,
html.dark .invoice-sheet th,
.mud-theme-dark .print-part th,
.mud-theme-dark .invoice-sheet th {
    background: #eee !important;
}

html.dark .print-part .grey.lighten-3,
html.dark .invoice-sheet .grey.lighten-3,
.mud-theme-dark .print-part .grey.lighten-3,
.mud-theme-dark .invoice-sheet .grey.lighten-3 {
    background-color: #f5f5f5 !important;
}

/* ---------- Print: تم روز/شب نباید خروجی چاپ را خراب کند ---------- */
/* پیش‌نمایش روی صفحه همچنان از تم شب پیروی می‌کند؛ فقط سند واقعی چاپ
   (print-part / invoice-sheet / address-print-sheet / warranty-sheet) همیشه روشن است. */
@media print {
    html.dark body,
    html.dark .main-content-surface,
    body.print-light-lock,
    body[class*="print-pass-"] {
        background-color: #fff !important;
        color: #000 !important;
        color-scheme: light !important;
    }

    html.dark .print-part,
    html.dark .invoice-sheet,
    html.dark .address-print-sheet,
    html.dark .warranty-print-sheet,
    .mud-theme-dark .print-part,
    .mud-theme-dark .invoice-sheet,
    .mud-theme-dark .address-print-sheet,
    .mud-theme-dark .warranty-print-sheet,
    body.print-light-lock .print-part,
    body[class*="print-pass-"] .print-part {
        background: #fff !important;
        color: #000 !important;
        color-scheme: light !important;
        border-color: #d0d0d0 !important;
    }

    /* خنثی‌سازی همه اوررایدهای تیره داخل سند چاپ */
    html.dark .print-part *,
    .mud-theme-dark .print-part *,
    body.print-light-lock .print-part *,
    body[class*="print-pass-"] .print-part * {
        color-scheme: light !important;
    }
}
