:root {
    color-scheme: light;
    --text-main: #12214b;
    --text-muted: #4f5c88;
    --primary: #2b24ba;
    --primary-hover: #2242a3;
    --primary-soft: #d4deff;
    --panel-bg: #ababf2;
    --success: #28a745;
    --success-hover: #218838;

    /* Portal semantic palette: keep page styles variable-driven. */
    --portal-white: #fff;
    --portal-surface: #fff;
    --portal-surface-alt: #ffffff;
    --portal-surface-soft: #f7f8ff;
    --portal-surface-subtle: #fbfcff;
    --portal-surface-muted: #f0f2fb;
    --portal-surface-input: #f0f1fd;
    --portal-surface-disabled: #f2f4ff;
    --portal-surface-table-even: #ffffff;
    --portal-surface-table-odd: #fafbff;
    --portal-surface-table-hover: #f1f4ff;
    --portal-surface-table-head: #eef2ff;
    --portal-surface-total: #e9ecff;
    --portal-surface-page-state: #dfe2f1;
    --portal-surface-warning: #fff8e6;
    --portal-surface-error: #fff3f3;
    --portal-surface-error-strong: #ffe5e5;
    --portal-surface-success: #e9fff2;
    --portal-error-boundary-bg: #b32121;

    --portal-text-on-primary: #fff;
    --portal-text-on-primary-soft: #f2f4ff;
    --portal-text-strong: #132f7d;
    --portal-text-strong-alt: #14277e;
    --portal-text-brand: #001f5b;
    --portal-text-page: #0f2f84;
    --portal-text-title: #12348f;
    --portal-text-secondary: #4d5a8e;
    --portal-text-muted: #58627e;
    --portal-text-help: #6d789e;
    --portal-text-info-label: #6270a5;
    --portal-text-state: #435690;
    --portal-text-success: #136b3e;
    --portal-text-danger: #b00020;
    --portal-text-danger-soft: #ffdddd;
    --portal-text-warning: #806000;

    --portal-border-subtle: #d9def7;
    --portal-border-soft: #dce2ff;
    --portal-border-input: #d7def6;
    --portal-border-image: #d8def8;
    --portal-border-table: #dfe4f7;
    --portal-border-header: #e4e8fb;
    --portal-border-strong: #4f578f;
    --portal-border-muted: #929292;

    --portal-focus-primary: #596de8;
    --portal-focus-ring: rgba(92, 126, 255, 0.25);
    --portal-focus-ring-soft: rgba(89, 109, 232, 0.18);
    --portal-dialog-backdrop: rgba(8, 18, 58, 0.55);
    --portal-shadow-page: rgba(0, 0, 0, 0.1) 0 20px 25px -5px, rgba(0, 0, 0, 0.04) 0 10px 10px -5px;
    --portal-shadow-dialog: rgba(0, 0, 0, 0.22) 0 24px 60px;
    --portal-shadow-card: rgba(23, 38, 105, 0.08) 0 10px 26px;

    --portal-body-background: linear-gradient(180deg, #6E79DD 0%, #102b7c 100%);
    --portal-dashboard-action-gradient: linear-gradient(90deg, #13378f 0%, #5f73d8 100%);
    --portal-card-gradient: linear-gradient(180deg, #ffffff 0%, #fbfcff 100%);
    --portal-placeholder-pattern: repeating-linear-gradient(45deg, #f2f4ff, #f2f4ff 10px, #e9edff 10px, #e9edff 20px);
}

* {
    box-sizing: border-box;
}

@font-face {
    font-family: 'IRANSans';
    src: url('/fonts/IRANSansWeb.woff') format('woff');
    font-weight: 400;
    font-style: normal;
}

@font-face {
    font-family: 'IRANSans';
    src: url('/fonts/IRANSansWeb_Bold.woff') format('woff');
    font-weight: 700;
    font-style: normal;
}

@font-face {
    font-family: 'IRANSans';
    src: url('/fonts/IRANSansWeb_Medium.woff') format('woff');
    font-weight: 500;
    font-style: normal;
}

@font-face {
    font-family: 'IRANSans';
    src: url('/fonts/IRANSansWeb_Light.woff') format('woff');
    font-weight: 300;
    font-style: normal;
}

@font-face {
    font-family: 'IRANSans';
    src: url('/fonts/IRANSansWeb_UltraLight.woff') format('woff');
    font-weight: 200;
    font-style: normal;
}

html,
body {
    width: 100%;
    height: 100%;
    min-height: 100%;
    margin: 0;
    padding: 0;
    overflow-x: hidden;
    overflow-y: hidden;
    font-family: IRANSans, "Segoe UI", Tahoma, sans-serif !important;
    background: var(--portal-body-background);
    color: var(--text-main);
}

a,
button,
input,
select,
textarea {
    font-family: inherit;
}

button {
    font-weight: 400;
}

h1:focus {
    outline: none;
}

.valid.modified:not([type=checkbox]) {
    width: 100%;
/*    padding: 15px;*/
    border-radius: 10px;
}

.invalid {
    width: 100%;
    padding: 15px;
    border-radius: 10px;
    outline: 1px solid var(--portal-text-danger);
}

.validation-message {
    color: var(--portal-text-danger);
}

.blazor-error-boundary {
    padding: 1rem 1rem 1rem 3.7rem;
    color: var(--portal-white);
    background: url(data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNTYiIGhlaWdodD0iNDkiIHhtbG5zPSJodHRwOi8vd3d3LnczMub3JnLzIwMDAvc3ZnIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayIgb3ZlcmZsb3c9ImhpZGRlbiI+PGRlZnM+PGNsaXBQYXRoIGlkPSJjbGlwMCI+PHJlY3QgeD0iMjM1IiB5PSI1MSIgd2lkdGg9IjU2IiBoZWlnaHQ9IjQ5Ii8+PC9jbGlwUGF0aD48L2RlZnM+PGcgY2xpcC1wYXRoPSJ1cmwoI2NsaXAwKSIgdHJhbnNmb3JtPSJ0cmFuc2xhdGUoLTIzNSAtNTEpIj48cGF0aCBkPSJNMjYzLjUwNiA1MUMyNjQuNzE3IDUxIDI2NS44MTMgNTEuNDgzNyAyNjYuNjA2IDUyLjI2NThMMjY3LjA1MiA1Mi43OTg3IDI2Ny41MzkgNTMuNjI4MyAyOTAuMTg1IDkyLjE4MzEgMjkwLjU0NSA5Mi43OTUgMjkwLjY1NiA5Mi45OTZDMjkwLjg3NyA5My41MTMgMjkxIDk0LjA4MTUgMjkxIDk0LjY3ODIgMjkxIDk3LjA2NTEgMjg5LjAzOCA5OSAyODYuNjE3IDk5TDI0MC4zODMgOTlDMjM3Ljk2MyA5OSAyMzYgOTcuMDY1MSAyMzYgOTQuNjc4MiAyMzYgOTQuMzc5OSAyMzYuMDMxIDk0LjA4ODYgMjM2LjA4OSA5My44MDcyTDIzNi4zMzggOTMuMDE2MiAyMzYuODU4IDkyLjEzMTQgMjU5LjQ3MyA1My42Mjk0IDI1OS45NjEgNTIuNzk4NSAyNjAuNDA3IDUyLjI2NThDMjYxLjIgNTEuNDgzNyAyNjIuMjk2IDUxIDI2My41MDYgNTFaTTI2My41ODYgNjYuMDE4M0MyNjAuNzM3IDY2LjAxODMgMjU5LjMxMyA2Ny4xMjQ1IDI1OS4zMTMgNjkuMzM3IDI1OS4zMTMgNjkuNjEwMiAyNTkuMzMyIDY5Ljg2MDggMjU5LjM3MSA3MC4wODg3TDI2MS43OTUgODQuMDE2MSAyNjUuMzggODQuMDE2MSAyNjcuODIxIDY5Ljc0NzVDMjY3Ljg2IDY5LjczMDkgMjY3Ljg3OSA2OS41ODc3IDI2Ny44NzkgNjkuMzE3OSAyNjcuODc5IDY3LjExODIgMjY2LjQ0OCA2Ni4wMTgzIDI2My41ODYgNjYuMDE4M1pNMjYzLjU3NiA4Ni4wNTQ3QzI2MS4wNDkgODYuMDU0NyAyNTkuNzg2IDg3LjMwMDUgMjU5Ljc4NiA4OS43OTIxIDI1OS43ODYgOTIuMjgzNyAyNjEuMDQ5IDkzLjUyOTUgMjYzLjU3NiA5My41Mjk1IDI2Ni4xMTYgOTMuNTI5NSAyNjcuMzg3IDkyLjI4MzcgMjY3LjM4NyA4OS43OTIxIDI2Ny4zODcgODcuMzAwNSAyNjYuMTE2IDg2LjA1NDcgMjYzLjU3NiA4Ni4wNTQ3WiIgZmlsbD0iI0ZGRDUwMCIgZmlsbC1ydWxlPSJldmVub2RkIi8+PC9nPjwvc3ZnPg==) no-repeat 1rem/1.8rem, var(--portal-error-boundary-bg);
}

.blazor-error-boundary::after {
    content: "An error has occurred.";
}

.darker-border-checkbox.form-check-input {
    border-color: var(--portal-border-muted);
}

.form-floating > .form-control-plaintext::placeholder,
.form-floating > .form-control::placeholder {
    color: var(--bs-secondary-color);
    text-align: end;
}

.form-floating > .form-control-plaintext:focus::placeholder,
.form-floating > .form-control:focus::placeholder {
    text-align: start;
}

input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus,
input:-webkit-autofill:active {
    -webkit-box-shadow: 0 0 0 1000px var(--portal-surface-alt) inset !important;
    box-shadow: 0 0 0 1000px var(--portal-surface-alt) inset !important;
    -webkit-text-fill-color: var(--portal-text-brand) !important;
    caret-color: var(--portal-text-brand);
}

/* ===== Dashboard shell / shared page layout ===== */

.portal-dashboard {
    width: 100%;
    height: 100dvh;
    min-height: 0;
    overflow: hidden;
}

.dashboard-frame {
    width: 100%;
    height: 100%;
    min-height: 0;
    display: flex;
    align-items: stretch;
    justify-content: center;
    gap: clamp(0.75rem, 1.4vw, 2rem);
    padding: clamp(0.75rem, 1.25vw, 1.45rem);
    box-sizing: border-box;
    overflow: hidden;
}

.dashboard-main {
    flex: 1 1 auto;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    color: var(--portal-text-page);
}

.header-dashboard {
    flex: 0 0 auto;
    display: flex;
    justify-content: space-between;
}

.user-strip {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 15px;
    text-decoration: none;
}

.user-strip p {
    margin: 0;
    font-size: 1.5rem;
    color: var(--portal-white);
}

.user-avatar {
    width: 64px;
    height: 64px;
    border: 5px solid var(--portal-white);
    border-radius: 50%;
    background: var(--portal-surface);
    color: var(--portal-white);
    display: grid;
    place-items: center;
    font-size: 1.65rem;
    font-weight: 700;
}

.icon-dashboard {
    width: 2rem;
    padding-left: .4rem;
    filter: brightness(0) invert(1);
}

.today-strip {
    width: min(17vw, 100%);
    min-height: 50px;
    border-radius: 15px;
    background: var(--primary-soft);
    color: var(--portal-text-strong);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 20px;
    text-align: center;
    font-size: 1rem;
}

.welcome-title {
    flex: 0 0 auto;
    margin: clamp(0.75rem, 2vh, 2rem) 0 clamp(1rem, 3vh, 3rem);
    color: var(--portal-white);
    font-size: clamp(1.3rem, 1.7vw, 2rem);
    font-weight: 500;
}

.dashboard-state {
    width: 100%;
    height: 100%;
    min-height: 0;
    display: grid;
    place-items: center;
    padding: 1.5rem;
    background: var(--portal-surface-page-state);
    text-align: center;
    overflow: hidden;
}

.dashboard-state h1 {
    margin-bottom: 0.75rem;
    color: var(--portal-text-title);
}

.dashboard-state p {
    margin-bottom: 1.2rem;
    color: var(--portal-text-state);
}

.workflow-panel,
.reports-panel,
.complaints-panel {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
}

.complaints-panel {
    overflow: hidden;
}

.company-name-title {
    padding-right: 12px;
    margin: 0 0 10px 0;
}

.workflow-actions,
.reports-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* ===== Shared buttons ===== */

.btn-dashboard,
.btn-refresh,
.btn-export,
.btn-create-complaint {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border: none;
    border-radius: 15px;
    background-color: var(--primary);
    color: var(--portal-white);
    cursor: pointer;
    font-size: 1rem;
    font-weight: 400;
}

.btn-dashboard:hover,
.btn-refresh:hover,
.btn-export:hover,
.btn-create-complaint:hover {
    background-color: var(--primary-hover);
}

.btn-dashboard:disabled,
.btn-refresh:disabled,
.btn-export:disabled,
.btn-create-complaint:disabled {
    opacity: 0.75;
    cursor: not-allowed;
}

.dashboard-action {
    min-width: 130px;
    min-height: 44px;
    margin: 5px 0;
    padding: 0 1rem;
    border: 0;
    border-radius: 999px;
    background: var(--portal-dashboard-action-gradient);
    color: var(--portal-white);
    cursor: pointer;
    font-size: 1rem;
    font-weight: 600;
}

.btn-download {
    min-width: 100px;
    border: none;
    border-radius: 6px;
    background-color: var(--primary);
    color: var(--portal-white);
    cursor: pointer;
    padding: 6px 10px;
    font-size: 0.85rem;
    transition: background 0.3s ease, opacity 0.2s ease;
}
    .btn-download:hover {
        background-color: var(--primary-hover);
    }
.btn-view {
    min-width: 80px;
    border: none;
    border-radius: 6px;
    background-color: var(--success);
    color: var(--portal-white);
    cursor: pointer;
    padding: 6px 10px;
    font-size: 0.85rem;
    transition: background 0.3s ease, opacity 0.2s ease;
}


.btn-view:hover {
    background-color: var(--success-hover);
}
.btn-download:disabled,
.btn-view:disabled {
    opacity: 0.75;
    cursor: not-allowed;
}

/*.download-action {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}*/

/*.download-action .btn-download {
    min-width: 100px;
}*/

.download-hint {
    color: var(--portal-text-secondary);
    font-size: 0.72rem;
    line-height: 1.2;
    text-align: center;
}

/* ===== Shared inputs ===== */

.portal-input {
    width: 100%;
    min-height: 60px;
    padding: 0 1.3rem;
    border: 2px solid var(--portal-border-strong);
    border-radius: 0.75rem;
    background: var(--portal-surface-input);
    color: var(--portal-border-strong);
    font-size: 1.1rem;
    text-align: right;
    transition: box-shadow 0.2s ease, transform 0.2s ease;
}

.portal-input:focus {
    outline: 0;
    transform: translateY(-1px);
    box-shadow: 0 0 0 4px var(--portal-focus-ring);
}

/* ===== Shared dynamic table fallback styles ===== */

.table-scroll-container {
    max-width: 100%;
    overflow-x: auto;
}

.amount-cell {
    direction: ltr;
    white-space: nowrap;
}

.negative-amount {
    color: var(--portal-text-danger);
}

.totals-row {
    background: var(--portal-surface-total) !important;
    font-weight: 700;
}

/* ===== Shared report dialog ===== */

.report-dialog-backdrop {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    direction: rtl;
    background: var(--portal-dialog-backdrop);
}

.report-dialog {
    width: min(890px, 100%);
    max-height: calc(100dvh - 48px);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    min-height: 0;
    border-radius: 22px;
    background: var(--portal-surface);
    box-shadow: var(--portal-shadow-dialog);
    color: var(--portal-text-strong);
}

.report-dialog-wide {
    width: min(1280px, 100%);
}

.report-dialog-header {
    flex-shrink: 0;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    padding: 20px 24px;
    border-bottom: 1px solid var(--portal-border-subtle);
    border-radius: 22px 22px 0 0;
    background: var(--portal-surface-soft);
}

.report-dialog-header h3,
.report-dialog-title h3 {
    margin: 0 0 8px;
    color: var(--portal-text-strong);
    font-size: 1.25rem;
    line-height: 1.8;
}

.report-dialog-header p,
.report-dialog-title p {
    margin: 0;
    color: var(--portal-text-secondary);
    font-size: 0.95rem;
}

.report-dialog-close {
    width: 38px;
    height: 38px;
    flex-shrink: 0;
    border: none;
    border-radius: 50%;
    background: var(--portal-surface-total);
    color: var(--portal-text-strong);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.6rem;
    line-height: 1;
}

.report-dialog-close:hover {
    background: var(--portal-border-subtle);
}

.report-dialog-close:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.report-dialog-body {
    flex: 1 1 auto;
    min-height: 0;
    padding: 24px;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
}


.dialog-state {
    padding: 18px;
    border-radius: 14px;
    background: var(--portal-surface-soft);
    color: var(--portal-text-strong);
    text-align: center;
    font-weight: 600;
}

.dialog-error {
    background: var(--portal-surface-error);
    color: var(--portal-text-danger);
}

.dialog-empty {
    background: var(--portal-surface-soft);
    color: var(--portal-text-muted);
}

.report-dialog-footer {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 10px;
    padding: 18px 24px 22px;
    border-top: 1px solid var(--portal-border-subtle);
}

.btn-dialog-primary,
.btn-dialog-secondary {
    min-width: 120px;
    border: none;
    border-radius: 12px;
    color: var(--portal-white);
    cursor: pointer;
    padding: 12px 20px;
}

.btn-dialog-primary {
    background-color: var(--success);
}

.btn-dialog-primary:hover {
    background-color: var(--success-hover);
}

.btn-dialog-secondary {
    background-color: var(--primary);
}

.btn-dialog-secondary:hover {
    background-color: var(--primary-hover);
}

.btn-dialog-primary:disabled,
.btn-dialog-secondary:disabled {
    opacity: 0.75;
    cursor: not-allowed;
}


.service-grid {
    min-height: 0;
    overflow: hidden;
}

.portal-users,
.users-main {
    min-width: 0;
    min-height: 0;
    overflow: hidden;
}

/* ===== Media queries: large to small ===== */

@media (max-width: 1400px) {
    .dashboard-frame {
        gap: 2rem;
    }
}

@media (max-width: 1120px) {
    .dashboard-frame {
        display: block;
        padding: 0.75rem;
    }

    .dashboard-main {
        width: 100%;
        height: 100%;
        max-width: 100%;
    }

    .workflow-panel,
    .reports-panel,
    .complaints-panel {
        padding-inline: 0;
    }

    .workflow-actions,
    .reports-actions {
        justify-content: flex-start;
    }
}

@media (max-width: 760px) {
    .dashboard-frame {
        padding: 0.5rem;
    }

    .header-dashboard {
        flex-wrap: wrap;
        gap: 0.75rem;
    }

    .user-strip p {
        font-size: 1.35rem;
    }

    .today-strip {
        width: 100%;
    }

    .workflow-actions,
    .reports-actions {
        flex-wrap: wrap;
    }

    .report-dialog-backdrop {
        padding: 12px;
    }

    .report-dialog {
        max-height: calc(100dvh - 24px);
        min-height: 0;
        border-radius: 18px;
    }

    .report-dialog-header,
    .report-dialog-body,
    .report-dialog-footer {
        padding-left: 16px;
        padding-right: 16px;
    }

    .report-dialog-header {
        border-radius: 18px 18px 0 0;
    }

    .report-dialog-header h3,
    .report-dialog-title h3 {
        font-size: 1rem;
    }

    .report-dialog-footer {
        flex-direction: column;
        align-items: stretch;
    }

    .btn-dialog-primary,
    .btn-dialog-secondary {
        width: 100%;
    }
}

/* ===== Phase 9 responsive overflow policy =====
   Width decides the shell mode. Low-height desktop must stay in the desktop
   two-column layout; otherwise 1500px x 760px devices collapse like mobile. */
@media (max-width: 1120px) {
    html,
    body {
        height: auto;
        min-height: 100%;
        overflow-x: hidden;
        overflow-y: auto;
    }

    .portal-dashboard {
        height: auto;
        min-height: 100dvh;
        overflow-x: hidden;
        overflow-y: visible;
    }

    .dashboard-frame {
        height: auto;
        min-height: 100dvh;
        display: block;
        overflow-x: hidden;
        overflow-y: visible;
    }

    .dashboard-main {
        width: 100%;
        height: auto;
        min-height: calc(100dvh - 1.5rem);
        overflow-x: hidden;
        overflow-y: visible;
        display: block;
        padding-top: calc(76px + env(safe-area-inset-top));
    }

    .workflow-panel,
    .reports-panel,
    .complaints-panel,
    .service-grid,
    .portal-users,
    .users-main {
        height: auto;
        max-height: none;
        overflow-y: visible;
    }

    .workflow-actions,
    .reports-actions,
    .dynamic-header,
    .dynamic-header-buttons,
    .header-dashboard {
        max-width: 100%;
    }
}

@media (min-width: 1121px) and (max-height: 760px) {
    html,
    body {
        height: 100%;
        overflow-x: hidden;
        overflow-y: hidden;
    }

    .portal-dashboard {
        height: 100dvh;
        min-height: 0;
        overflow: hidden;
    }

    .dashboard-frame {
        height: 100%;
        min-height: 0;
        display: flex;
        align-items: stretch;
        gap: clamp(0.5rem, 1vw, 1.2rem);
        padding: clamp(0.5rem, 1vw, 1rem);
        overflow: hidden;
    }

    .dashboard-main {
        width: auto;
        height: 100%;
        min-height: 0;
        overflow-x: hidden;
        overflow-y: auto;
        display: flex;
        flex-direction: column;
        padding-top: 0;
        scrollbar-width: thin;
    }

    .workflow-panel,
    .reports-panel,
    .complaints-panel,
    .portal-users,
    .users-main {
        min-height: 0;
        max-height: 100%;
    }

    .service-grid {
        min-height: 0;
        max-height: none;
    }
}

@media (max-width: 760px) {
    .dashboard-main {
        min-height: calc(100dvh - 1rem);
        padding-top: calc(70px + env(safe-area-inset-top));
    }

    .company-name-title,
    .welcome-title {
        overflow-wrap: anywhere;
    }

    .btn-dashboard,
    .btn-refresh,
    .btn-export,
    .btn-create-complaint,
    .dashboard-action,
    .dynamic-header-button {
        max-width: 100%;
        white-space: normal;
    }
}
