html,
body {
    margin: 0;
    font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
    background: var(--ops-body-bg);
    color: var(--ops-text);
    transition: background-color 0.2s ease, color 0.2s ease;
}

:root {
    --ops-body-bg: #f3f6fb;
    --ops-surface: #ffffff;
    --ops-surface-soft: #f8fbff;
    --ops-border: #d8e1ec;
    --ops-text: #1f2937;
    --ops-text-muted: #5f6f86;
    --ops-accent: #3c8dbc;
    --ops-accent-soft: #eaf4ff;
    --ops-success: #2f8f62;
    --ops-radius: 10px;
    --ops-radius-compact: 6px;
    --ops-shadow: 0 10px 24px rgba(15, 23, 42, 0.06);
    --ops-shadow-strong: 0 10px 24px rgba(15, 23, 42, 0.12);
    --ops-button-height-compact: 32px;
    --ops-table-head-bg: #edf3fa;
    --ops-table-row-hover: #f8fbff;
    --ops-table-cell-y: 0.45rem;
    --ops-table-cell-x: 0.7rem;
    --ops-appbar-border: rgba(216, 225, 236, 0.85);
    --ops-link: #13446a;
    --ops-login-bg-start: #f7fafc;
    --ops-login-bg-mid: #eef4f8;
    --ops-login-bg-end: #e8eff5;
}

html[data-theme="dark"] {
    color-scheme: dark;

    /* ops custom variables */
    --ops-body-bg: #0f1722;
    --ops-surface: #14202c;
    --ops-surface-soft: #192736;
    --ops-border: #2a3b4f;
    --ops-text: #e6edf5;
    --ops-text-muted: #9bb0c8;
    --ops-accent: #6cb7ff;
    --ops-accent-soft: rgba(108, 183, 255, 0.12);
    --ops-success: #61c58b;
    --ops-shadow: 0 12px 28px rgba(0, 0, 0, 0.22);
    --ops-shadow-strong: 0 14px 36px rgba(0, 0, 0, 0.32);
    --ops-table-head-bg: #182738;
    --ops-table-row-hover: #172433;
    --ops-appbar-border: rgba(42, 59, 79, 0.92);
    --ops-link: #8dc8ff;
    --ops-login-bg-start: #0f1722;
    --ops-login-bg-mid: #101a27;
    --ops-login-bg-end: #132031;

    /* MudBlazor palette overrides — keep in sync with PaletteDark in Rota34MudTheme.cs */
    /* This ensures MudBlazor components get dark colours immediately via CSS,            */
    /* before IsDarkMode re-render completes (avoids light/dark mix on first paint).      */
    --mud-palette-primary: #6cb7ff;
    --mud-palette-primary-text: #ffffff;
    --mud-palette-secondary: #9bb0c8;
    --mud-palette-tertiary: #8dc8ff;
    --mud-palette-info: #6cb7ff;
    --mud-palette-success: #61c58b;
    --mud-palette-warning: #e0a94f;
    --mud-palette-error: #e07a7a;
    --mud-palette-background: #0f1722;
    --mud-palette-surface: #14202c;
    --mud-palette-appbar-background: #10253a;
    --mud-palette-appbar-text: #f3f7fb;
    --mud-palette-drawer-background: #0f1824;
    --mud-palette-drawer-text: #e6edf5;
    --mud-palette-text-primary: #e6edf5;
    --mud-palette-text-secondary: #9bb0c8;
    --mud-palette-text-disabled: rgba(230, 237, 245, 0.38);
    --mud-palette-action-default: #c1d0e0;
    --mud-palette-action-disabled: rgba(95, 114, 136, 0.38);
    --mud-palette-action-disabled-background: rgba(27, 42, 59, 0.38);
    --mud-palette-lines-default: #2a3b4f;
    --mud-palette-lines-inputs: #39506a;
    --mud-palette-table-lines: #2a3b4f;
    --mud-palette-table-striped: #172433;
    --mud-palette-divider: rgba(42, 59, 79, 0.8);
    --mud-palette-divider-light: rgba(42, 59, 79, 0.4);
    --mud-palette-overlay-dark: rgba(0, 0, 0, 0.5);
    --mud-palette-overlay-light: rgba(230, 237, 245, 0.08);
}

html[data-theme="dark"] .ops-db-primary,
html[data-theme="dark"] .ops-db-primary-soft,
html[data-theme="dark"] .ops-week-box,
html[data-theme="dark"] .operator-menu-card,
html[data-theme="dark"] .operator-menu-result-card,
html[data-theme="dark"] .machine4-matrix-wrap,
html[data-theme="dark"] .ops-report-card {
    background: color-mix(in srgb, var(--ops-surface-soft) 76%, var(--ops-surface));
    border-color: var(--ops-border);
}

html[data-theme="dark"] .ops-db-success,
html[data-theme="dark"] .ops-test-card-success,
html[data-theme="dark"] .operator-test-card-success {
    background: color-mix(in srgb, var(--ops-success) 14%, var(--ops-surface));
    border-color: color-mix(in srgb, var(--ops-success) 52%, var(--ops-border));
}

html[data-theme="dark"] .ops-db-danger,
html[data-theme="dark"] .ops-test-card-error,
html[data-theme="dark"] .operator-test-card-danger {
    background: color-mix(in srgb, #d97878 16%, var(--ops-surface));
    border-color: color-mix(in srgb, #d97878 52%, var(--ops-border));
}

html[data-theme="dark"] .machine4-matrix .matrix-total td,
html[data-theme="dark"] .machine2-matrix .matrix-total td,
html[data-theme="dark"] .station-export-matrix .matrix-total td,
html[data-theme="dark"] .station-sarf-matrix .matrix-total td {
    background: color-mix(in srgb, var(--ops-accent-soft) 48%, var(--ops-surface));
}

html[data-theme="dark"] #blazor-error-ui {
    background: #4a3a14;
    color: #f9e7aa;
}

/* ── Dashboard shared styles ─────────────────────────────────────── */
.ops-dashboard-body {
    padding-top: 0.5rem;
}

.ops-dashboard-body .ops-flow-header {
    margin-bottom: 6px;
}

.ops-dashboard-card-title {
    font-weight: 700;
    line-height: 1.2;
    margin-bottom: 2px;
    color: var(--ops-text);
}

.ops-dashboard-note {
    display: block;
    line-height: 1.35;
    margin-top: 0;
    max-width: 72ch;
}

.ops-dashboard-filter-card {
    border-top: 4px solid var(--ops-accent);
    background:
        radial-gradient(circle at top right, rgba(60, 141, 188, 0.10), transparent 30%),
        var(--ops-surface);
}

.ops-dashboard-filter-card .mud-paper-content,
.ops-dashboard-filter-card {
    padding-bottom: 0.8rem;
}

.ops-dashboard-filter-card .ops-dashboard-card-title {
    margin-bottom: 4px;
}

.ops-dashboard-filter-grid .mud-grid-item {
    padding-top: 12px;
    padding-bottom: 4px;
}

.ops-dashboard-filter-grid .mud-input-control {
    font-size: 0.9rem;
}

.ops-dashboard-filter-grid .mud-input-label {
    font-size: 0.85rem;
}

.ops-dashboard-filter-card .ops-dashboard-actions {
    margin-top: 8px;
    padding-top: 12px;
    border-top: 1px solid rgba(60, 141, 188, 0.14);
}

.ops-dashboard-filter-actions {
    justify-content: flex-start;
}

.ops-dashboard-summary-row {
    padding-top: 12px;
    border-top: 1px solid rgba(60, 141, 188, 0.14);
}

.ops-db-primary {
    border-color: #9ec1ea;
    background: var(--ops-surface);
}

.ops-db-primary-soft {
    border-color: #d0e1f5;
    background: var(--ops-surface-soft);
}

.ops-db-success {
    border-color: #8cd49c;
    background: #edf9f0;
}

.ops-db-danger {
    border-color: #e6b8b8;
    background: #fff5f5;
}

.machine4-matrix-wrap {
    overflow-x: auto;
    border-radius: 16px;
    border: 1px solid var(--ops-border);
    background: var(--ops-surface);
}

.machine4-matrix,
.machine2-matrix {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.82rem;
}

.machine2-matrix {
    min-width: 1800px;
}

.machine4-matrix th,
.machine4-matrix td {
    border: 1px solid var(--ops-border);
    padding: 0.35rem 0.5rem;
    white-space: nowrap;
    text-align: center;
}

.machine4-matrix thead th,
.machine2-matrix thead th,
.machine4-matrix .sticky-col,
.machine2-matrix .sticky-col {
    background: linear-gradient(180deg, #243447, #2f485f);
    color: #ffffff;
}

.machine4-matrix thead th,
.machine2-matrix thead th {
    position: sticky;
    top: 0;
    z-index: 3;
}

.machine4-matrix .sticky-col,
.machine2-matrix .sticky-col {
    position: sticky;
    left: 0;
    z-index: 2;
    text-align: left;
    font-weight: 600;
}

.machine4-matrix thead .sticky-col,
.machine2-matrix thead .sticky-col {
    z-index: 5;
}

.machine4-matrix .matrix-total td {
    font-weight: 600;
    background: var(--ops-surface-soft);
}

.machine4-matrix th.machine-col-header,
.machine2-matrix th.machine-col-header {
    writing-mode: vertical-rl;
    transform: rotate(180deg);
    text-align: center;
    vertical-align: middle;
    white-space: nowrap;
    padding: 8px 4px;
    width: 34px;
    min-width: 34px;
}

.machine4-matrix th:first-child,
.machine4-matrix td:first-child {
    min-width: 150px;
    width: 150px;
}

.machine4-matrix th:nth-child(2),
.machine4-matrix td:nth-child(2),
.machine4-matrix th:nth-child(3),
.machine4-matrix td:nth-child(3),
.machine4-matrix th:nth-child(4),
.machine4-matrix td:nth-child(4) {
    min-width: 200px;
    width: 200px;
}

.machine4-matrix th:nth-child(n + 5),
.machine4-matrix td:nth-child(n + 5) {
    min-width: 250px;
}

.machine2-matrix th:first-child,
.machine2-matrix td:first-child {
    min-width: 150px;
    width: 150px;
}

.machine2-matrix th:nth-child(2),
.machine2-matrix td:nth-child(2),
.machine2-matrix th:nth-child(3),
.machine2-matrix td:nth-child(3) {
    min-width: 200px;
    width: 200px;
}

.machine2-matrix th:nth-child(n + 4),
.machine2-matrix td:nth-child(n + 4) {
    min-width: 250px;
}

.ops-dashboard-table thead th:first-child,
.ops-dashboard-table tbody td:first-child {
    white-space: nowrap;
}

.ops-dashboard-body .ops-db-card + .ops-dashboard-table {
    margin-top: 8px;
}

@media (max-width: 992px) {
    .machine4-matrix th.machine-col-header,
    .machine2-matrix th.machine-col-header {
        writing-mode: horizontal-tb;
        transform: none;
        width: auto;
        min-width: 140px;
        padding: 6px 8px;
    }

    .ops-dashboard-filter-actions,
    .ops-dashboard-summary-row {
        gap: 0.25rem;
    }
}
/* ── End dashboard shared styles ─────────────────────────────────── */

.main-content {
    padding: 14px;
}

.page-header {
    padding: 16px 18px;
    display: flex;
    flex-wrap: wrap;
    gap: 14px;
    justify-content: space-between;
    align-items: center;
    background: var(--ops-surface);
    border: 1px solid var(--ops-border);
    border-radius: var(--ops-radius);
    box-shadow: var(--ops-shadow);
}

.page-breadcrumb {
    margin-bottom: 6px;
}

:root .page-breadcrumb .mud-breadcrumb-item {
    font-size: 0.8rem;
    color: var(--ops-text-muted);
}

.header-actions {
    align-items: center;
    gap: 8px;
}

.page-body {
    padding: 16px;
    background: var(--ops-surface);
    border: 1px solid var(--ops-border);
    border-radius: var(--ops-radius);
    box-shadow: var(--ops-shadow);
}

.text-muted {
    color: var(--ops-text-muted);
}

.scanner-grid {
    display: grid;
    gap: 12px;
}

.scan-submit {
    min-height: 44px;
}

.mobile-card {
    padding: 14px;
    border: 1px solid var(--ops-border);
    border-radius: var(--ops-radius);
    background: var(--ops-surface);
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.03);
}

.app-page-shell {
    gap: 14px;
}

.app-page-shell .page-header .mud-typography-h5 {
    letter-spacing: -0.01em;
    font-weight: 650;
}

.app-page-shell .page-body > :first-child {
    margin-top: 0;
}

.app-page-shell .page-body > :last-child {
    margin-bottom: 0;
}

.app-data-table {
    font-size: 0.84rem;
}

.app-data-table :deep(.mud-table-container) {
    border: 1px solid var(--ops-border);
    border-radius: var(--ops-radius-compact);
    background: var(--ops-surface);
    box-shadow: 0 6px 16px rgba(15, 23, 42, 0.04);
    overflow: auto;
}

.app-data-table :deep(.mud-table-head th) {
    background: var(--ops-table-head-bg);
    color: var(--ops-text);
    font-weight: 650;
    white-space: nowrap;
    border-bottom: 1px solid var(--ops-border);
    padding: var(--ops-table-cell-y) var(--ops-table-cell-x);
}

.app-data-table :deep(.mud-table-body td) {
    border-bottom: 1px solid var(--ops-border);
    padding: var(--ops-table-cell-y) var(--ops-table-cell-x);
    vertical-align: middle;
}

.app-data-table :deep(.mud-table-row:hover) {
    background: var(--ops-table-row-hover);
}

.app-data-table :deep(.mud-button-root) {
    min-height: 30px;
    border-radius: var(--ops-radius-compact);
    box-shadow: none;
}

.app-data-table :deep(.mud-table-empty-row),
.app-data-table :deep(.mud-table-loading) {
    background: var(--ops-surface-soft);
}

.app-data-table :deep(.mud-table-empty-row td),
.app-data-table :deep(.mud-table-loading td) {
    padding: 1rem var(--ops-table-cell-x);
    color: var(--ops-text-muted);
}

.ops-menu-list {
    display: grid;
    gap: 12px;
}

:root .ops-menu-btn {
    min-height: 54px;
    font-weight: 600;
    letter-spacing: 0;
}

.ops-test-card {
    border-width: 2px;
}

.ops-test-card-success {
    border-color: color-mix(in srgb, var(--ops-success) 80%, var(--ops-border));
    background: color-mix(in srgb, var(--ops-success) 10%, var(--ops-surface));
}

.ops-test-card-error {
    border-color: #d97878;
    background: color-mix(in srgb, #d97878 12%, var(--ops-surface));
}

.ops-flow-header {
    background: transparent;
    border: none;
    box-shadow: none;
    padding: 0 0 8px;
    display: block;
}

.ops-flow-header .page-breadcrumb {
    margin-bottom: 2px;
}

.ops-flow-header .mud-typography-h5 {
    font-size: 1.25rem;
    font-weight: 600;
    margin: 0;
}

.ops-flow-body {
    background: transparent;
    border: none;
    box-shadow: none;
    padding: 0;
}

.ops-compact-page {
    padding: 8px;
}

.ops-flow-header .mud-typography-body2 {
    font-size: 0.8rem;
}

.ops-flow-header .header-actions .mud-button-root {
    min-height: 30px;
}

.ops-flow-body .scanner-grid {
    gap: 8px;
}

.ops-flow-body .mobile-card {
    padding: 10px;
    border: 1px solid var(--ops-border);
    border-radius: 3px;
    box-shadow: none;
    background: var(--ops-surface);
}

.ops-flow-body .mud-input-control,
.ops-flow-body .mud-input-slot {
    min-height: 36px;
}

.ops-flow-body .mud-button-root {
    min-height: var(--ops-button-height-compact);
}

.ops-flow-body .mud-chip {
    min-height: 30px;
}

.ops-flow-body .mud-alert {
    padding-top: 6px;
    padding-bottom: 6px;
}

:root .top-quick-link {
    min-width: 96px;
}

:root .ops-scan-row .mud-input-control {
    margin-top: 0;
    margin-bottom: 0;
}

:root .ops-scan-row .mud-input-slot {
    min-height: 50px;
}

.ops-basket-flow-title {
    margin-bottom: 2px;
    font-weight: 700;
    color: var(--ops-text);
}

.ops-section-actions {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--ops-border);
    align-items: center;
    gap: 8px;
}

:root .ops-section-actions .mud-button-root {
    min-height: 32px;
    border-radius: 3px;
    box-shadow: none;
}

:root .ops-section-actions .mud-chip {
    min-height: 28px;
}

.ops-row-actions {
    align-items: center;
    gap: 6px;
}

:root .ops-row-actions .mud-button-root {
    min-height: 28px;
    border-radius: 3px;
    box-shadow: none;
    padding-inline: 8px;
}

.ops-info-card {
    border-style: dashed;
}

:root .ops-report-card {
    border: 1px solid var(--ops-border);
    background: var(--ops-surface-soft);
}

:root .ops-action-btn {
    min-height: 50px;
    font-weight: 700;
}

:root .ops-status-field .mud-input-slot {
    min-height: 50px;
    background: var(--ops-surface-soft);
}

.theme-toggle-btn {
    min-height: 34px;
    border-radius: 999px;
    font-weight: 700;
    box-shadow: none;
}

.app-section-card {
    padding: 1rem;
}

.app-section-card-header {
    gap: 0.75rem;
    flex-wrap: wrap;
}

.app-section-card-headings {
    min-width: 0;
}

.app-section-card-title {
    font-weight: 700;
    color: var(--ops-text);
}

.app-section-card-subtitle {
    margin-top: 0.15rem;
}

.app-section-card-actions,
.app-action-bar,
.app-form-actions {
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.app-filter-bar-summary {
    display: flex;
    align-items: center;
    min-height: 1.75rem;
}

.app-form-actions-status {
    display: flex;
    align-items: center;
}

.ops-pager {
    gap: 0;
}

.ops-pager-info {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--ops-text-muted);
    padding-inline: 0.5rem;
    white-space: nowrap;
}

.ops-pager-total {
    font-size: 0.8rem;
    color: var(--ops-text-muted);
    padding-inline: 0.5rem;
    white-space: nowrap;
}

.app-empty-state {
    padding: 1.25rem;
    text-align: center;
}

.app-empty-state-icon {
    color: var(--ops-text-muted);
}

.app-table-empty-state {
    min-height: 120px;
}


#blazor-error-ui {
    background: #fff3cd;
    bottom: 0;
    box-shadow: 0 -1px 3px rgba(0, 0, 0, 0.2);
    display: none;
    left: 0;
    padding: 0.6rem 1rem;
    position: fixed;
    width: 100%;
    z-index: 9999;
}

#blazor-error-ui .dismiss {
    cursor: pointer;
    float: right;
}

@media (max-width: 600px) {
    .main-content {
        padding: 10px;
    }

    .page-header {
        padding: 12px;
    }

    .page-body {
        padding: 12px;
    }

    .top-quick-link {
        display: none;
    }
}

/* PurchaseOps route-specific pages should not show MudTabs header */
.purchaseops-hide-tabs .mud-tabs-tabbar {
    display: none !important;
}

.purchaseops-hide-tabs .mud-tabs-panels {
  padding-top: 0 !important;
}

.shipops-hide-tabs .mud-tabs-tabbar {
  display: none !important;
}

.shipops-hide-tabs .mud-tabs-panels {
  padding-top: 0 !important;
}

/* QualityReports route-specific pages should not show MudTabs header */
.qualityreports-hide-tabs .mud-tabs-tabbar {
    display: none !important;
}

.qualityreports-hide-tabs .mud-tabs-panels {
    padding-top: 0 !important;
}

/* Shared route-mode tab containers keep tabs for code reuse but hide tab headers in UI. */
.ops-hide-tab-header .mud-tabs-tabbar {
    display: none !important;
}

.ops-hide-tab-header .mud-tabs-panels {
    padding-top: 0 !important;
}
