/* === Design Tokens === */
@font-face {
    font-family: 'Vazirmatn';
    src: url("../fonts/Vazirmatn-Regular.cdc140628f11.woff2") format('woff2');
    font-weight: 400;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'Vazirmatn';
    src: url("../fonts/Vazirmatn-Bold.7958481fe611.woff2") format('woff2');
    font-weight: 700;
    font-style: normal;
    font-display: swap;
}

:root {
    --bg-body: #F4F6F8;
    --bg-card: #FFFFFF;
    --primary-dark: #1B263B;
    --secondary-blue: #415A77;
    --primary-blue: #0056D2;
    --accent-orange: #FF9F00;
    --shadow-card: 0 8px 24px rgba(27, 38, 59, 0.06);
    --shadow-card-active: 0 14px 32px rgba(0, 86, 210, 0.18);
    --shadow-cta-hover: 0 12px 28px rgba(255, 159, 0, 0.28);
    --radius: 12px;
    --transition: all 0.3s ease;
    --text-heading: var(--primary-dark);
    --text-label: var(--secondary-blue);
    --text-body: var(--primary-dark);
    --border: rgba(65, 90, 119, 0.2);
    --danger-color: #E02020;
    --danger-hover: #c01b1b;
    --success-color: #1F7A4C;
    --success-hover: #17633c;
    --sidebar-width: 260px;
    --touch-min: 44px;
    --bottom-nav-height: 64px;
    --app-content-pad-bottom: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom, 0px) + 16px);
    /* legacy aliases */
    --bg-color: var(--bg-body);
    --surface-color: var(--bg-card);
    --border-color: var(--border);
    --text-primary: var(--text-body);
    --text-secondary: var(--secondary-blue);
    --primary-color: var(--accent-orange);
    --primary-hover: #e08c00;
    --shadow-sm: var(--shadow-card);
    --shadow: var(--shadow-card);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    padding: 0;
    direction: rtl;
    font-family: 'Vazirmatn', Tahoma, sans-serif;
    font-size: 16px;
    font-weight: 400;
    line-height: 1.6;
    color: var(--text-body);
    background-color: var(--bg-body);
}

body.sidebar-open {
    overflow: hidden;
}

h1, h2, h3, h4 {
    margin-top: 0;
    color: var(--text-heading);
    font-weight: 700;
}

/* === Layout: App Shell === */
.app {
    min-height: 100vh;
}

.app-sidebar {
    position: fixed;
    top: 0;
    right: 0;
    z-index: 1100;
    width: var(--sidebar-width);
    height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--primary-dark);
    color: #fff;
    transform: translateX(100%);
    transition: transform var(--transition);
    box-shadow: -4px 0 24px rgba(27, 38, 59, 0.15);
}

.app-sidebar__brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: calc(20px + env(safe-area-inset-top, 0px)) 18px 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.app-sidebar__brand img {
    height: 40px;
}

.app-sidebar__brand h2 {
    margin: 0;
    font-size: 1.1rem;
    color: #fff;
}

.app-sidebar__nav {
    flex: 1;
    overflow-y: auto;
    padding: 16px 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.app-sidebar__link {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: var(--touch-min);
    padding: 12px 14px;
    border-radius: var(--radius);
    color: rgba(255, 255, 255, 0.85);
    text-decoration: none;
    font-weight: 500;
    touch-action: manipulation;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.app-sidebar__link:hover {
    background: rgba(65, 90, 119, 0.45);
    color: #fff;
}

.app-sidebar__link:active {
    background: rgba(65, 90, 119, 0.7);
    color: #fff;
}

.app-sidebar__link.is-active {
    background: rgba(65, 90, 119, 0.65);
    color: #fff;
    border-right: 3px solid var(--accent-orange);
}

.app-sidebar__link--cta {
    margin-top: 8px;
    background: var(--accent-orange);
    color: #fff;
    font-weight: 700;
    justify-content: center;
}

.app-sidebar__link--cta:hover {
    background: var(--primary-hover);
    box-shadow: var(--shadow-cta-hover);
}

.app-sidebar__footer {
    padding: 16px 12px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.app-sidebar__logout {
    width: 100%;
}

.app-backdrop {
    position: fixed;
    inset: 0;
    z-index: 1050;
    background: rgba(27, 38, 59, 0.45);
    opacity: 0;
    visibility: hidden;
    transition: var(--transition);
}

.app-backdrop.is-visible {
    opacity: 1;
    visibility: visible;
}

/* === Global calculator (floating draggable widget) === */
.app-calc {
    position: fixed;
    z-index: 1300;
    pointer-events: none;
}

.app-calc__panel {
    position: fixed;
    left: max(16px, env(safe-area-inset-left, 0px));
    bottom: max(96px, calc(80px + env(safe-area-inset-bottom, 0px)));
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    width: min(300px, calc(100vw - 32px));
    max-height: min(88dvh, 520px);
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: 0 16px 48px rgba(27, 38, 59, 0.22);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.2s ease, visibility 0.2s ease, box-shadow 0.2s ease;
    overflow-x: hidden;
    overflow-y: auto;
    outline: none;
}

.app-calc.is-active .app-calc__panel {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

.app-calc__panel.is-dragging {
    box-shadow: 0 20px 56px rgba(27, 38, 59, 0.3);
    transition: box-shadow 0.2s ease;
    user-select: none;
}

.app-calc-launch {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 0;
    border: none;
    border-radius: var(--radius);
    background: var(--accent-orange);
    color: #fff;
    font-family: inherit;
    font-size: 1.25rem;
    box-shadow: var(--shadow-cta-hover);
    cursor: pointer;
    transition: var(--transition);
    touch-action: manipulation;
}

.app-calc-launch:hover {
    background: var(--primary-hover);
}

.app-calc-launch:focus-visible {
    outline: 2px solid var(--primary-dark);
    outline-offset: 3px;
}

.app-calc-launch--fab {
    position: fixed;
    bottom: max(20px, env(safe-area-inset-bottom, 0px));
    right: max(20px, env(safe-area-inset-right, 0px));
    z-index: 1240;
    width: 56px;
    height: 56px;
    border-radius: 50%;
}

.app-calc-launch--topbar {
    margin-inline-start: auto;
    flex-shrink: 0;
    height: 44px;
    padding: 0 14px;
}

.app-calc-launch__label {
    font-size: 0.88rem;
    font-weight: 600;
}

.app-calc__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 14px;
    background: var(--primary-dark);
    color: #fff;
    flex-shrink: 0;
    cursor: grab;
    touch-action: none;
    border-radius: 16px 16px 0 0;
}

.app-calc__panel.is-dragging .app-calc__header {
    cursor: grabbing;
}

.app-calc__title {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0;
    font-size: 1rem;
    color: #fff;
}

.app-calc__drag-icon {
    opacity: 0.65;
    font-size: 0.95rem;
}

.app-calc__close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    padding: 0;
    border: 1px solid rgba(255, 255, 255, 0.35);
    border-radius: var(--radius);
    background: transparent;
    color: #fff;
    cursor: pointer;
    touch-action: manipulation;
}

.app-calc__close:hover {
    background: rgba(255, 255, 255, 0.12);
}

.app-calc__display-wrap {
    padding: 14px 18px 10px;
    flex-shrink: 0;
}

.app-calc__display {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-body);
    font-family: 'Vazirmatn', Tahoma, sans-serif;
    font-size: clamp(1.25rem, 4vw, 1.6rem);
    font-weight: 700;
    text-align: right;
    color: var(--text-heading);
}

.app-calc__keys {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    grid-auto-rows: minmax(44px, auto);
    align-content: start;
    gap: clamp(6px, 2vw, 10px);
    padding: 0 18px max(18px, env(safe-area-inset-bottom, 0px));
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    direction: ltr;
    flex: 0 0 auto;
    min-width: 0;
}

.app-calc-key {
    min-width: 0;
    min-height: clamp(44px, 11vw, 52px);
    padding: 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-card);
    font-family: 'Vazirmatn', Tahoma, sans-serif;
    font-size: clamp(1rem, 3.5vw, 1.15rem);
    font-weight: 600;
    color: var(--text-heading);
    cursor: pointer;
    touch-action: manipulation;
    transition: background 0.15s ease, transform 0.1s ease;
}

.app-calc-key:active {
    transform: scale(0.96);
}

.app-calc-key--fn {
    background: rgba(65, 90, 119, 0.12);
    color: var(--secondary-blue);
}

.app-calc-key--op {
    background: rgba(247, 127, 0, 0.12);
    color: var(--accent-orange);
}

.app-calc-key--eq {
    background: var(--accent-orange);
    color: #fff;
    border-color: var(--accent-orange);
}

.app-calc-key--wide {
    grid-column: span 2;
}

.app-main {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.app-topbar {
    display: flex;
    align-items: center;
    gap: 16px;
    padding-block: 14px;
    padding-inline: 16px;
    padding-top: max(14px, env(safe-area-inset-top, 0px));
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow-card);
}

.app-topbar__title {
    margin: 0;
    flex: 1;
    min-width: 0;
    font-size: 1.15rem;
    color: var(--text-heading);
}

.app-topbar__actions {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-inline-start: auto;
}

.nav-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-card);
    color: var(--primary-dark);
    cursor: pointer;
    transition: var(--transition);
}

.nav-toggle:hover {
    border-color: var(--secondary-blue);
    color: var(--secondary-blue);
}

.nav-toggle__icon {
    display: block;
    width: 20px;
    height: 2px;
    background: currentColor;
    position: relative;
    border-radius: 1px;
}

.nav-toggle__icon::before,
.nav-toggle__icon::after {
    content: '';
    position: absolute;
    right: 0;
    width: 20px;
    height: 2px;
    background: currentColor;
    border-radius: 1px;
    transition: var(--transition);
}

.nav-toggle__icon::before {
    top: -6px;
}

.nav-toggle__icon::after {
    top: 6px;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.app-sidebar__logout.btn-outline {
    border-color: rgba(255, 255, 255, 0.35);
    color: #fff;
}

.app-sidebar__logout.btn-outline:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: #fff;
    color: #fff;
}

.container {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding: 24px 20px var(--app-content-pad-bottom);
    flex: 1;
}

.app--guest .container,
body:not(.app) .container {
    padding-bottom: 48px;
}

body.keyboard-open {
    --app-content-pad-bottom: 48px;
}

body.keyboard-open .app-bottom-nav {
    display: none;
}

.app--guest .container {
    max-width: 1200px;
}

/* === Components: Buttons, Cards, Badges === */
.card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 25px;
    margin-bottom: 25px;
    box-shadow: var(--shadow-card);
    border: 1px solid transparent;
    transition: var(--transition);
}

.card:hover {
    box-shadow: 0 12px 32px rgba(27, 38, 59, 0.08);
}

.card-header {
    padding: 14px 18px;
    margin: -25px -25px 20px;
    border-radius: var(--radius) var(--radius) 0 0;
    font-weight: 700;
}

.card-header--warning {
    background: rgba(247, 127, 0, 0.12);
    color: var(--primary-dark);
}

.card-header--danger {
    background: rgba(192, 57, 43, 0.12);
    color: var(--danger-color);
}

.card-header--success {
    background: rgba(45, 106, 79, 0.12);
    color: var(--success-color);
}

.card-toolbar {
    padding: 0 18px 12px;
    margin-top: -8px;
}

.accountant-invoice-label {
    display: inline-block;
    line-height: 1.5;
    font-weight: 600;
}

.card--flush .card-body,
.card.card--flush {
    padding: 0;
}

.card.card--flush > .card-header {
    margin: 0;
}

.card--flush .table-responsive {
    border-radius: 0 0 var(--radius) var(--radius);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 12px 24px;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 600;
    text-decoration: none;
    text-align: center;
    transition: var(--transition);
    line-height: 1.4;
}

.btn-sm {
    padding: 8px 14px;
    font-size: 0.8rem;
}

.btn-accent,
.btn-primary {
    background: var(--accent-orange);
    color: #fff;
}

.btn-accent:hover,
.btn-primary:hover {
    background: var(--primary-hover);
    box-shadow: var(--shadow-cta-hover);
    transform: translateY(-1px);
}

.btn-outline {
    background: transparent;
    border: 2px solid var(--secondary-blue);
    color: var(--secondary-blue);
}

.btn-outline:hover {
    background: rgba(65, 90, 119, 0.08);
    border-color: var(--primary-dark);
    color: var(--primary-dark);
}

.btn-secondary {
    background: var(--secondary-blue);
    color: #fff;
}

.btn-secondary:hover {
    background: var(--primary-dark);
}

.btn-danger {
    background: var(--danger-color);
    color: #fff;
}

.btn-danger:hover {
    background: var(--danger-hover);
}

.btn-success {
    background: var(--success-color);
    color: #fff;
}

.btn-success:hover {
    background: var(--success-hover);
}

.badge,
.dash-badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    white-space: nowrap;
}

.badge--draft,
.dash-badge--draft {
    background: rgba(65, 90, 119, 0.15);
    color: var(--secondary-blue);
}

.badge--pending,
.dash-badge--pending {
    background: rgba(255, 159, 0, 0.16);
    color: #b86e00;
}

.badge--approved,
.dash-badge--approved {
    background: rgba(31, 122, 76, 0.15);
    color: var(--success-color);
}

.dash-badge--converted {
    background: rgba(0, 86, 210, 0.12);
    color: var(--primary-blue);
}

.badge--accounting-neutral,
.dash-badge--accounting-neutral {
    background: rgba(65, 90, 119, 0.12);
    color: var(--secondary-blue);
}

.badge--accounting-danger,
.dash-badge--accounting-danger {
    background: rgba(224, 32, 32, 0.12);
    color: var(--danger-color);
}

.badge--accounting-warn,
.dash-badge--accounting-warn {
    background: rgba(247, 127, 0, 0.14);
    color: #b85d00;
}

.dash-row--supply-delegate {
    background: rgba(247, 127, 0, 0.05) !important;
}

.header-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    flex-wrap: wrap;
    gap: 16px;
}

.page-title {
    margin: 0;
}

.customer-list-search {
    margin-bottom: 20px;
}

.customer-list-search label {
    margin-bottom: 8px;
}

.customer-list-search__wrap {
    position: relative;
}

.customer-list-search__icon {
    position: absolute;
    top: 50%;
    right: 14px;
    transform: translateY(-50%);
    color: var(--text-muted);
    pointer-events: none;
}

.customer-list-search__input {
    padding-right: 42px;
}

.customer-list__tbody--loading {
    opacity: 0.55;
    pointer-events: none;
}

/* === Forms & Formset === */
.form-group {
    margin-bottom: 20px;
}

label {
    display: block;
    margin-bottom: 8px;
    color: var(--text-label);
    font-weight: 400;
}

.form-control {
    width: 100%;
    min-height: 44px;
    padding: 12px 15px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text-body);
    border-radius: var(--radius);
    font-family: inherit;
    font-size: 0.95rem;
    transition: var(--transition);
}

.form-control:focus {
    outline: none;
    border-color: var(--secondary-blue);
    box-shadow: 0 0 0 3px rgba(65, 90, 119, 0.15);
}

.item-row {
    display: grid;
    grid-template-columns: 2fr 1fr 1fr 1.5fr 1.5fr auto;
    gap: 12px;
    align-items: end;
    margin-bottom: 16px;
    padding-bottom: 16px;
    border-bottom: 1px dashed var(--border);
}

.item-row .form-group {
    margin-bottom: 0;
}

.item-row__actions {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    min-width: 96px;
}

.item-row__action-buttons {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.item-row__delete-field,
.item-row__delete-field label {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.btn-item-row-vat,
.btn-item-row-delete {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    padding: 0;
    border-radius: var(--radius);
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease;
    font-size: 1rem;
    font-weight: 700;
    line-height: 1;
}

.btn-item-row-vat {
    border: 1px solid #bfdbfe;
    background: #eff6ff;
    color: #1d4ed8;
}

.btn-item-row-vat:hover,
.btn-item-row-vat[aria-expanded="true"] {
    background: #dbeafe;
    border-color: #60a5fa;
}

.btn-item-row-vat:focus-visible {
    outline: 2px solid #1d4ed8;
    outline-offset: 2px;
}

.btn-item-row-delete {
    border: 1px solid #fecaca;
    background: #fef2f2;
    color: #b91c1c;
}

.btn-item-row-delete:hover {
    background: #fee2e2;
    border-color: #f87171;
}

.btn-item-row-delete:focus-visible {
    outline: 2px solid #b91c1c;
    outline-offset: 2px;
}

.item-row__vat-helper {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 140px;
}

.item-row__vat-helper[hidden] {
    display: none !important;
}

.item-row__vat-helper-label {
    margin: 0;
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-label);
    white-space: nowrap;
}

.item-row__vat-helper-input {
    width: 100%;
    min-width: 120px;
}

.item-row-wrapper--deleted {
    display: none !important;
}

#customer-select {
    display: none;
}

.product-autocomplete-dropdown,
.customer-autocomplete-dropdown {
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    left: 0;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-card);
    z-index: 20;
    max-height: 200px;
    overflow-y: auto;
}

.product-autocomplete-option,
.customer-autocomplete-option {
    width: 100%;
    border: none;
    background: transparent;
    text-align: right;
    padding: 12px 14px;
    min-height: 44px;
    cursor: pointer;
    font-family: inherit;
    color: var(--text-body);
    transition: var(--transition);
}

.product-autocomplete-option:hover,
.customer-autocomplete-option:hover {
    background: var(--bg-body);
}

.hidden-template {
    display: none;
}

.formset-header {
    display: grid;
    grid-template-columns: 2fr 1fr 1fr 1.5fr 1.5fr auto;
    gap: 12px;
    margin-bottom: 10px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border);
    color: var(--text-label);
    font-size: 0.85rem;
}

.invoice-totals-preview {
    margin-top: 24px;
    padding-top: 20px;
    border-top: 1px solid var(--border);
    background: var(--bg-body);
    border-radius: var(--radius);
    padding: 20px;
}

.invoice-totals-preview__title {
    margin: 0 0 6px;
    font-size: 1rem;
}

.invoice-totals-preview__hint {
    margin: 0 0 16px;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.invoice-totals-preview__grid {
    margin: 0;
    display: grid;
    gap: 10px;
}

.invoice-totals-preview__row {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    gap: 16px;
    padding: 10px 12px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
}

.invoice-totals-preview__row dt {
    margin: 0;
    font-weight: 500;
    color: var(--text-label);
    font-size: 0.9rem;
}

.invoice-totals-preview__row dd {
    margin: 0;
    font-weight: 700;
    color: var(--text-heading);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.invoice-totals-preview__row--final {
    border-color: var(--accent-orange);
    background: rgba(247, 127, 0, 0.06);
}

.invoice-totals-preview__final {
    font-size: 1.15rem;
    color: var(--accent-orange);
}

.d-none-desktop,
.mobile-label {
    display: none;
}

.grid-4 {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
}

.grid-2 {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
}

.grid-accountant {
    display: grid;
    grid-template-columns: 1fr;
    gap: 24px;
}

/* === Tables (desktop + card mobile) === */
table {
    width: 100%;
    border-collapse: collapse;
}

.data-table th,
.data-table td,
table th,
table td {
    padding: 14px 16px;
    text-align: right;
    border-bottom: 1px solid var(--border);
}

.data-table th,
table thead th {
    color: var(--primary-dark);
    font-weight: 700;
    background: var(--bg-body);
}

.data-table tbody tr:hover,
table tbody tr:hover {
    background: rgba(65, 90, 119, 0.04);
}

.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    width: 100%;
}

.table-empty {
    text-align: center;
    padding: 32px 16px;
    color: var(--secondary-blue);
}

.pricing-reference-card {
    border-right: 4px solid var(--accent-orange);
}

.pricing-reference-note {
    padding: 12px 16px;
    background: var(--bg-body);
    border-radius: 8px;
    font-size: 14px;
}

.pricing-reference-note__body {
    margin-top: 8px;
    color: var(--text-body);
    line-height: 1.7;
}

.pricing-page-card {
    max-width: 960px;
    margin: 0 auto;
}

.pricing-page-intro {
    margin-bottom: 20px;
    padding: 15px;
    background: var(--bg-body);
    border-radius: 8px;
}

.pricing-items-table .pricing-status-cell {
    min-width: 200px;
}

.pricing-status-options ul {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.pricing-status-options li {
    display: flex;
    align-items: flex-start;
    gap: 6px;
    font-size: 0.9rem;
}

.pricing-description-input.is-readonly {
    background: var(--bg-body);
}

.pricing-original-hint {
    margin-top: 6px;
}

.pricing-note-group {
    margin: 20px 0;
}

.pricing-status-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 6px;
    font-size: 0.85rem;
    background: var(--bg-body);
    color: var(--secondary-blue);
}

.pricing-status-badge--unavailable {
    background: #fde8e8;
    color: #b91c1c;
}

.pricing-status-badge--substitute,
.pricing-status-badge--renamed {
    background: #e8f4fd;
    color: #1d4ed8;
}

.pricing-row-unavailable {
    background: #fff8f8;
}

/* === Error / utility === */
.errorlist,
.error-message {
    color: var(--danger-color);
    list-style: none;
    padding: 0;
    margin-top: 6px;
    font-size: 0.85rem;
}

.errorlist li {
    margin-bottom: 4px;
}

.w-100 {
    width: 100%;
}

/* === Responsive: Tablet === */
@media (min-width: 768px) {
    .grid-4 {
        grid-template-columns: repeat(2, 1fr);
    }

    .grid-2 {
        grid-template-columns: repeat(2, 1fr);
    }

    .grid-accountant {
        grid-template-columns: 1fr 1fr;
    }

    .grid-accountant__full {
        grid-column: 1 / -1;
    }
}


/* === Mobile bottom navigation (hybrid) === */
.app-bottom-nav {
    position: fixed;
    inset-inline: 0;
    bottom: 0;
    z-index: 1000;
    display: flex;
    flex-direction: row;
    align-items: stretch;
    justify-content: space-around;
    gap: 4px;
    min-height: var(--bottom-nav-height);
    padding-block: 6px;
    padding-inline: 8px;
    padding-bottom: max(6px, env(safe-area-inset-bottom, 0px));
    background: var(--bg-card);
    border-top: 1px solid var(--border);
    box-shadow: 0 -4px 20px rgba(27, 38, 59, 0.08);
}

.app-bottom-nav__item {
    flex: 1 1 0;
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-width: 0;
    min-height: var(--touch-min);
    padding: 6px 4px;
    border: none;
    border-radius: var(--radius);
    background: transparent;
    color: var(--secondary-blue);
    font-family: inherit;
    font-size: 0.75rem;
    font-weight: 600;
    line-height: 1.2;
    text-decoration: none;
    text-align: center;
    cursor: pointer;
    touch-action: manipulation;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.app-bottom-nav__item i {
    font-size: 1.25rem;
    line-height: 1;
}

.app-bottom-nav__item span {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.app-bottom-nav__item:active {
    background: rgba(27, 38, 59, 0.08);
    color: var(--primary-dark);
}

.app-bottom-nav__item.is-active {
    color: var(--accent-orange);
}

.app-bottom-nav__item--cta {
    color: var(--accent-orange);
    font-weight: 700;
}

.app-bottom-nav__item--cta:active {
    background: rgba(247, 127, 0, 0.12);
}

.app--guest .app-bottom-nav {
    display: none;
}

@media (min-width: 992px) {
    .app-bottom-nav {
        display: none;
    }

    .container {
        padding-bottom: 56px;
    }

    body {
        --app-content-pad-bottom: 56px;
    }
}

/* === Responsive: Desktop === */
@media (min-width: 992px) {
    .nav-toggle {
        display: none;
    }

    .app-sidebar {
        transform: translateX(0);
    }

    .app-backdrop {
        display: none;
    }

    .app-main {
        margin-right: var(--sidebar-width);
    }

    /* Keep topbar visible so notifications (and other actions) work on desktop.
       Calculator still uses the FAB; hide the duplicate topbar calc button below. */
    .app-topbar {
        display: flex;
        position: sticky;
        top: 0;
        z-index: 1050;
        overflow: visible;
    }

    .app-topbar__actions {
        overflow: visible;
    }

    .container {
        max-width: 1400px;
        padding: 32px 40px 56px;
    }

    .grid-4 {
        grid-template-columns: repeat(4, 1fr);
    }
}

@media (min-width: 1200px) {
    .container {
        max-width: 1400px;
    }
}

/* === Responsive: Mobile === */
@media (max-width: 767px) {
    .d-none-desktop,
    .mobile-label {
        display: inline-block;
        margin-bottom: 6px;
        color: var(--text-label);
        font-weight: 500;
        font-size: 0.85rem;
    }

    .header-actions {
        flex-direction: column;
        align-items: stretch;
    }

    .formset-header {
        display: none;
    }

    .item-row {
        grid-template-columns: 1fr;
        background: var(--bg-body);
        padding: 16px;
        border-radius: var(--radius);
        border: 1px solid var(--border);
        border-bottom: 1px solid var(--border);
    }

    .item-row .form-group {
        margin-bottom: 12px;
    }

    .item-row .form-group:last-child {
        margin-bottom: 0;
    }

    .item-row__action-buttons {
        justify-content: flex-start;
    }

    .item-row__vat-helper {
        min-width: 0;
        width: 100%;
    }

    /* Card-based tables */
    .table-card thead {
        display: none;
    }

    .table-card tbody tr {
        display: block;
        margin-bottom: 14px;
        padding: 4px 0;
        background: var(--bg-card);
        border: 1px solid var(--border);
        border-radius: var(--radius);
        box-shadow: var(--shadow-card);
    }

    .table-card tbody tr:hover {
        background: var(--bg-card);
    }

    .table-card td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: 12px;
        border: none;
        padding: 10px 16px;
    }

    .table-card td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--secondary-blue);
        font-size: 0.78rem;
        flex-shrink: 0;
    }

    .table-card td.table-card__actions {
        flex-direction: column;
        align-items: stretch;
    }

    .table-card td.table-card__actions::before {
        margin-bottom: 4px;
    }

    .table-card .table-empty td {
        display: block;
        text-align: center;
    }

    .table-card .table-empty td::before {
        display: none;
    }
}

/* Mobile sidebar open */
@media (max-width: 991px) {
    body.sidebar-open .app-sidebar {
        transform: translateX(0);
    }
}

@media (min-width: 992px) {
    .app-calc-launch--fab {
        right: calc(var(--sidebar-width) + 24px);
    }

    .app-calc-launch--topbar {
        display: none;
    }
}

@media (max-width: 991px) {
    .app-calc-launch--fab {
        display: none;
    }
}

/* === Accountant invoice preview modal === */
.accountant-preview-modal {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    visibility: hidden;
    opacity: 0;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.accountant-preview-modal--open {
    visibility: visible;
    opacity: 1;
}

body.accountant-preview-modal-open {
    overflow: hidden;
}

.accountant-preview-modal__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(27, 38, 59, 0.5);
}

.accountant-preview-modal__dialog {
    position: relative;
    width: 100%;
    max-width: 960px;
    max-height: min(90vh, 720px);
    display: flex;
    flex-direction: column;
    padding: 20px 24px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--bg-card);
    box-shadow: var(--shadow-card);
    text-align: right;
}

.accountant-preview-modal__header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 8px;
}

.accountant-preview-modal__header h2 {
    margin: 0;
    font-size: 1.15rem;
    color: var(--primary-dark);
}

.accountant-preview-modal__close {
    border: none;
    background: transparent;
    font-size: 1.75rem;
    line-height: 1;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0 4px;
}

.accountant-preview-modal__meta {
    margin: 0 0 12px;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.accountant-preview-modal__toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 12px;
}

.accountant-preview-modal__status {
    min-height: 1.25rem;
    margin-bottom: 8px;
    font-size: 0.9rem;
    color: var(--text-muted);
}

.accountant-preview-modal__status--error {
    color: var(--danger-color);
}

.accountant-preview-modal__body {
    flex: 1;
    overflow: auto;
    margin: 0 -4px;
}

.accountant-preview-modal__table .accountant-preview-modal__desc {
    max-width: 280px;
    white-space: normal;
    word-break: break-word;
}

.accountant-preview-modal__unavailable {
    color: var(--danger-color);
}

.accountant-preview-modal__empty {
    margin: 16px 0 0;
    text-align: center;
    color: var(--text-muted);
}

.accountant-preview-toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(12px);
    z-index: 2100;
    padding: 10px 20px;
    border-radius: var(--radius);
    background: var(--primary-dark);
    color: #fff;
    font-size: 0.9rem;
    opacity: 0;
    transition: opacity 0.25s ease, transform 0.25s ease;
    pointer-events: none;
}

.accountant-preview-toast--visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.sidebar-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    margin-right: auto;
    border-radius: 999px;
    background: var(--danger-color);
    color: #fff;
    font-size: 0.75rem;
    font-weight: 700;
    line-height: 1;
}

.sidebar-badge--inline {
    margin-right: 0;
    margin-inline-start: 6px;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    vertical-align: middle;
}

.post-approval-meta {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 12px 24px;
}

.post-approval-diff__old {
    background: rgba(192, 57, 43, 0.08);
}

.post-approval-diff__new {
    background: rgba(45, 106, 79, 0.08);
}

.post-approval-diff__row--added .post-approval-diff__new {
    font-weight: 600;
}

.post-approval-diff__row--removed .post-approval-diff__old {
    font-weight: 600;
}

.credit-grade-badge {
    display: inline-block;
    padding: 1px 8px;
    border-radius: 4px;
    font-size: 12px;
    background: #eee;
}

.credit-grade-a { background: #d1e7dd; color: #0f5132; }
.credit-grade-b { background: #cff4fc; color: #055160; }
.credit-grade-c { background: #fff3cd; color: #664d03; }
.credit-grade-d { background: #f8d7da; color: #842029; }
.credit-grade-e { background: #f5c2c7; color: #58151c; }
.credit-grade-none { background: #eee; color: #555; }

.ledger-balance--debit { color: #9a5200; font-weight: 600; }
.ledger-balance--credit { color: #1c6e43; font-weight: 600; }
.ledger-balance--settled { color: var(--text-secondary); }

.form-messages {
    list-style: none;
    margin: 0 0 1rem;
    padding: 0;
    display: grid;
    gap: 8px;
}
.form-messages__item {
    margin: 0;
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 14px;
    line-height: 1.6;
}
.form-messages__item--success {
    background: #e8f6ee;
    color: #146c43;
}
.form-messages__item--error {
    background: #fdecec;
    color: #b42318;
}

.due-preset-options label {
    font-size: 13px;
}

/* === Jalali datepicker (shared; used on invoice form, calendar, filters) === */
.jdp-field {
    position: relative;
}

.jdp-popup {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    z-index: 200;
    width: 280px;
    padding: 12px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--bg-card);
    box-shadow: var(--shadow-card);
    display: none;
}

.jdp-popup--portal {
    position: fixed;
    top: auto;
    right: auto;
    z-index: 4000;
    pointer-events: none;
}

.jdp-popup--open {
    display: block;
    pointer-events: auto;
}

.jdp-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
    gap: 4px;
}

.jdp-title {
    flex: 1;
    text-align: center;
    font-weight: 700;
    font-size: 0.9rem;
    color: var(--primary-dark);
}

.jdp-nav,
.jdp-day,
.jdp-today,
.jdp-clear {
    font-family: inherit;
    cursor: pointer;
    border: none;
    background: var(--bg-body);
    color: var(--text-body);
    border-radius: 8px;
    transition: var(--transition);
}

.jdp-nav:hover,
.jdp-day:hover,
.jdp-today:hover,
.jdp-clear:hover {
    background: rgba(247, 127, 0, 0.12);
}

.jdp-nav {
    width: 28px;
    height: 28px;
}

.jdp-weekdays {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 2px;
    margin-bottom: 6px;
    font-size: 0.7rem;
    color: var(--secondary-blue);
    text-align: center;
}

.jdp-days {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 4px;
}

.jdp-day {
    aspect-ratio: 1;
    font-size: 0.8rem;
    padding: 0;
}

.jdp-day--selected {
    background: var(--accent-orange);
    color: #fff;
}

.jdp-footer {
    display: flex;
    gap: 8px;
    margin-top: 10px;
}

.jdp-today,
.jdp-clear {
    flex: 1;
    padding: 8px;
    font-size: 0.8rem;
}
