@font-face {
    font-family: "Vazirmatn";
    src: local("Vazirmatn"), local("Tahoma");
    font-weight: 400;
    font-style: normal;
}

* {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

html, body {
    margin: 0;
    padding: 0;
    font-family: "Vazirmatn", Tahoma, "Segoe UI", sans-serif;
    background: linear-gradient(165deg, #eef3f8 0%, #f7f4ee 45%, #e8eef5 100%);
    color: #1f2a37;
    min-height: 100%;
    overflow-x: hidden;
}

.home-wrap,
.report-page {
    max-width: 1200px;
    margin: 0 auto;
    padding: 28px 20px 40px;
}

.user-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
    padding: 10px 14px;
    background: #fff;
    border: 1px solid #c9d6e3;
    border-radius: 10px;
    box-shadow: 0 4px 12px rgba(15, 61, 94, 0.04);
}

.user-bar-name {
    color: #0f3d5e;
    font-weight: 700;
    font-size: 0.92rem;
    word-break: break-word;
}

.user-bar-logout {
    color: #8a1f17;
    text-decoration: none;
    font-weight: 600;
    font-size: 0.9rem;
    white-space: nowrap;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
}

.user-bar-logout:hover {
    text-decoration: underline;
}

.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px 16px;
    padding-bottom: calc(24px + env(safe-area-inset-bottom, 0px));
}

.login-card {
    width: 100%;
    max-width: 420px;
    background: #fff;
    border: 1px solid #c9d6e3;
    border-radius: 14px;
    padding: 28px 22px;
    box-shadow: 0 12px 30px rgba(15, 61, 94, 0.08);
}

.login-card h1 {
    margin: 0 0 6px;
    font-size: 1.4rem;
    color: #0f3d5e;
}

.login-subtitle {
    margin: 0 0 20px;
    color: #5b6b7c;
    font-size: 0.9rem;
}

.form-field {
    margin-bottom: 14px;
}

.form-field label,
.form-field .aspNetLabel {
    display: block;
    margin-bottom: 6px;
    color: #3d4d5c;
    font-size: 0.9rem;
    font-weight: 600;
}

.form-input,
.form-field input[type="text"],
.form-field input[type="password"] {
    width: 100%;
    min-height: 44px;
    padding: 10px 12px;
    border: 1px solid #c9d6e3;
    border-radius: 8px;
    background: #fff;
    color: #1f2a37;
    font-family: inherit;
    font-size: 1rem;
}

.form-check {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 44px;
}

.form-check label {
    margin: 0;
    font-weight: 500;
}

.btn-login {
    width: 100%;
    margin-top: 8px;
}

.home-wrap h1,
.report-header h1 {
    margin: 0 0 8px;
    font-size: 1.75rem;
    font-weight: 700;
    color: #0f3d5e;
    line-height: 1.35;
    word-wrap: break-word;
}

.home-wrap p,
.report-meta {
    margin: 0 0 20px;
    color: #5b6b7c;
    font-size: 0.95rem;
}

.report-links {
    list-style: none;
    padding: 0;
    margin: 0;
}

.report-links li {
    margin-bottom: 12px;
}

.report-links a {
    display: block;
    padding: 16px 18px;
    background: #fff;
    border: 1px solid #c9d6e3;
    border-radius: 10px;
    color: #0b6e99;
    text-decoration: none;
    font-weight: 600;
    box-shadow: 0 4px 14px rgba(15, 61, 94, 0.05);
}

.report-links a:hover,
.back-link:hover {
    text-decoration: none;
    background: #f3f8fc;
}

.back-link {
    color: #0b6e99;
    text-decoration: none;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    padding: 6px 0;
    font-size: 0.95rem;
}

.report-header {
    margin-bottom: 18px;
    border-bottom: 2px solid #c5d4e2;
    padding-bottom: 14px;
}

.toolbar {
    display: flex;
    gap: 12px;
    margin-bottom: 16px;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
}

.toolbar-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.sort-box {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1 1 auto;
    min-width: 220px;
}

.sort-label {
    color: #5b6b7c;
    font-size: 0.9rem;
    white-space: nowrap;
}

.sort-select {
    flex: 1 1 auto;
    min-width: 180px;
    max-width: 320px;
    min-height: 44px;
    padding: 8px 12px;
    border: 1px solid #c9d6e3;
    border-radius: 8px;
    background: #fff;
    color: #1f2a37;
    font-family: inherit;
    font-size: 0.92rem;
    -webkit-tap-highlight-color: transparent;
}

.btn,
.btn-secondary {
    appearance: none;
    border: 1px solid #0b6e99;
    background: #0b6e99;
    color: #fff;
    padding: 10px 18px;
    min-height: 44px;
    border-radius: 8px;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.95rem;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.btn-secondary {
    background: #fff;
    color: #0b6e99;
}

.btn:hover,
.btn-secondary:hover {
    opacity: 0.9;
}

.error-box {
    background: #fdeceb;
    border: 1px solid #e8a9a4;
    color: #8a1f17;
    padding: 12px 14px;
    border-radius: 8px;
    margin-bottom: 16px;
    line-height: 1.7;
    word-break: break-word;
}

.mobile-totals {
    display: none;
}

.grid-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    background: #fff;
    border: 1px solid #c9d6e3;
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(15, 61, 94, 0.06);
}

.report-grid {
    width: 100%;
    border-collapse: collapse;
    min-width: 780px;
}

.report-grid th,
.report-grid td {
    padding: 10px 12px;
    border-bottom: 1px solid #e3ebf3;
    vertical-align: middle;
    font-size: 0.92rem;
}

.report-grid .grid-header th {
    background: #0f3d5e;
    color: #fff;
    font-weight: 700;
    text-align: center;
    white-space: nowrap;
}

.report-grid .grid-row td {
    background: #fff;
}

.report-grid .grid-alt td {
    background: #f5f8fb;
}

.report-grid .grid-footer td {
    background: #e8f1f8;
    font-weight: 700;
    border-top: 2px solid #0f3d5e;
    border-bottom: none;
}

.col-row {
    text-align: center;
    width: 70px;
}

.col-name {
    text-align: right;
}

.col-group {
    text-align: right;
    white-space: nowrap;
}

.col-num {
    text-align: left;
    font-variant-numeric: tabular-nums;
    direction: ltr;
    unicode-bidi: embed;
    white-space: nowrap;
}

.footer-label {
    text-align: center;
}

.footer-total {
    color: #0b4f73;
}

.empty-row td {
    text-align: center;
    padding: 28px;
    color: #6b7c8d;
}

.report-footer {
    margin-top: 14px;
    color: #5b6b7c;
    font-size: 0.9rem;
}

.report-meta .meta-sep {
    margin: 0 6px;
    color: #9aa8b5;
}

.desktop-only {
    display: block;
}

@media (max-width: 768px) {
    .home-wrap,
    .report-page {
        padding: 14px 12px 28px;
        padding-bottom: calc(28px + env(safe-area-inset-bottom, 0px));
    }

    .report-header {
        margin-bottom: 12px;
        padding-bottom: 10px;
    }

    .report-header h1,
    .home-wrap h1 {
        font-size: 1.25rem;
    }

    .report-meta,
    .home-wrap p {
        margin-bottom: 12px;
        font-size: 0.85rem;
    }

    .toolbar {
        display: grid;
        grid-template-columns: 1fr;
        gap: 8px;
        margin-bottom: 12px;
        position: sticky;
        top: 0;
        z-index: 20;
        background: linear-gradient(165deg, #eef3f8 0%, #f7f4ee 100%);
        padding: 8px 0;
    }

    .sort-box {
        min-width: 0;
        width: 100%;
    }

    .sort-select {
        max-width: none;
        width: 100%;
    }

    .toolbar-actions {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 8px;
    }

    .toolbar-actions .btn,
    .toolbar-actions .btn-secondary {
        width: 100%;
        margin: 0;
    }

    .toolbar .btn,
    .toolbar .btn-secondary {
        width: 100%;
        margin: 0;
    }

    .mobile-totals {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 8px;
        margin-bottom: 12px;
    }

    .mobile-total-item {
        background: #fff;
        border: 1px solid #c9d6e3;
        border-radius: 10px;
        padding: 10px 12px;
        display: flex;
        flex-direction: column;
        gap: 4px;
        box-shadow: 0 4px 12px rgba(15, 61, 94, 0.05);
    }

    .mobile-total-item span {
        font-size: 0.78rem;
        color: #5b6b7c;
    }

    .mobile-total-item strong {
        font-size: 0.98rem;
        color: #0b4f73;
        font-variant-numeric: tabular-nums;
        direction: ltr;
        unicode-bidi: embed;
        word-break: break-word;
    }

    .mobile-total-count {
        grid-column: 1 / -1;
    }

    .desktop-only {
        display: none !important;
    }

    .grid-wrap {
        overflow: visible;
        background: transparent;
        border: none;
        border-radius: 0;
        box-shadow: none;
    }

    .report-grid {
        min-width: 0;
        width: 100%;
        border-collapse: separate;
        border-spacing: 0;
    }

    .report-grid .grid-header {
        display: none;
    }

    .report-grid tbody {
        display: block;
        width: 100%;
    }

    /* سه سطر دوتایی: ردیف|گروه ، نام|موجودی ، قیمت|جمع */
    .report-grid .grid-row,
    .report-grid .grid-alt {
        display: grid !important;
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
        grid-template-areas:
            "row group"
            "name stock"
            "price total";
        width: 100%;
        background: #fff;
        border: 1px solid #c9d6e3;
        border-radius: 12px;
        margin-bottom: 10px;
        padding: 0;
        box-shadow: 0 4px 14px rgba(15, 61, 94, 0.05);
        overflow: hidden;
    }

    .report-grid .grid-row > td.cell-row,
    .report-grid .grid-alt > td.cell-row { grid-area: row; }

    .report-grid .grid-row > td.cell-group,
    .report-grid .grid-alt > td.cell-group { grid-area: group; }

    .report-grid .grid-row > td.cell-name,
    .report-grid .grid-alt > td.cell-name { grid-area: name; }

    .report-grid .grid-row > td.cell-stock,
    .report-grid .grid-alt > td.cell-stock { grid-area: stock; }

    .report-grid .grid-row > td.cell-price,
    .report-grid .grid-alt > td.cell-price { grid-area: price; }

    .report-grid .grid-row > td.cell-total,
    .report-grid .grid-alt > td.cell-total { grid-area: total; }

    .report-grid .grid-row > td,
    .report-grid .grid-alt > td {
        display: flex !important;
        flex-direction: column;
        align-items: flex-start;
        justify-content: flex-start;
        gap: 3px;
        width: auto !important;
        max-width: none !important;
        min-width: 0;
        background: transparent !important;
        border: none;
        border-bottom: 1px solid #eef2f6;
        border-left: 1px solid #eef2f6;
        padding: 8px 10px;
        text-align: right !important;
        white-space: normal;
        font-size: 0.88rem;
        line-height: 1.35;
        direction: rtl;
    }

    .report-grid .grid-row > td.cell-name,
    .report-grid .grid-row > td.cell-stock,
    .report-grid .grid-alt > td.cell-name,
    .report-grid .grid-alt > td.cell-stock {
        border-bottom: 1px solid #eef2f6;
    }

    .report-grid .grid-row > td.cell-price,
    .report-grid .grid-row > td.cell-total,
    .report-grid .grid-alt > td.cell-price,
    .report-grid .grid-alt > td.cell-total {
        border-bottom: none;
    }

    .report-grid .grid-row > td.cell-row,
    .report-grid .grid-row > td.cell-name,
    .report-grid .grid-row > td.cell-price,
    .report-grid .grid-alt > td.cell-row,
    .report-grid .grid-alt > td.cell-name,
    .report-grid .grid-alt > td.cell-price {
        border-left: 1px solid #eef2f6;
    }

    .report-grid .grid-row > td.cell-group,
    .report-grid .grid-row > td.cell-stock,
    .report-grid .grid-row > td.cell-total,
    .report-grid .grid-alt > td.cell-group,
    .report-grid .grid-alt > td.cell-stock,
    .report-grid .grid-alt > td.cell-total {
        border-left: none;
    }

    .report-grid td::before {
        content: attr(data-label);
        display: block;
        width: 100%;
        max-width: none;
        flex: none;
        color: #5b6b7c;
        font-weight: 700;
        font-size: 0.72rem;
        line-height: 1.2;
        text-align: right;
        direction: rtl;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .report-grid td .cell-value {
        display: block;
        width: 100%;
        font-weight: 600;
        color: #1f2a37;
        word-break: break-word;
        overflow-wrap: anywhere;
    }

    .report-grid td.col-num .cell-value,
    .report-grid td.cell-row .cell-value {
        font-variant-numeric: tabular-nums;
        direction: ltr;
        unicode-bidi: embed;
        text-align: left;
    }

    .report-grid .grid-footer {
        display: none !important;
    }

    .report-grid .empty-row {
        display: block !important;
        background: #fff;
        border: 1px solid #c9d6e3;
        border-radius: 12px;
        padding: 8px 0;
    }

    .report-grid .empty-row td {
        display: block !important;
        text-align: center !important;
        border: none;
        padding: 24px 14px;
    }

    .report-grid .empty-row td::before {
        display: none;
    }
}

@media (max-width: 480px) {
    .report-header h1,
    .home-wrap h1 {
        font-size: 1.15rem;
    }

    .mobile-totals {
        grid-template-columns: 1fr;
    }

    .mobile-total-count {
        grid-column: auto;
    }

    .report-grid .grid-row > td,
    .report-grid .grid-alt > td {
        font-size: 0.84rem;
        padding: 7px 8px;
    }

    .report-grid td::before {
        font-size: 0.68rem;
    }
}

@media print {
    body {
        background: #fff;
    }

    .no-print {
        display: none !important;
    }

    .report-page {
        max-width: none;
        padding: 0;
    }

    .grid-wrap {
        box-shadow: none;
        border: none;
        border-radius: 0;
        overflow: visible;
    }

    .report-grid {
        min-width: 0;
    }

    .report-grid th,
    .report-grid td {
        border: 1px solid #999 !important;
        padding: 6px 8px;
        font-size: 11px;
    }

    .report-grid .grid-header th {
        background: #ddd !important;
        color: #000 !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    .report-grid .grid-footer {
        display: table-row-group !important;
    }

    .report-grid .grid-footer td {
        display: table-cell !important;
    }

    .report-grid td::before {
        display: none !important;
    }
}
