/* ============================================
   BILLING APP - CENTRALIZED THEME (VIOLET / WHITE / BLACK)
   ============================================ */

:root {
    /* Theme colors - use exactly these */
    --color-primary: #7C3AED;
    --color-primary-hover: #6D28D9;
    --color-accent: #A855F7;
    --color-bg: #F5F3FF;
    --color-card: #FFFFFF;
    --color-text: #111827;
    --color-text-muted: #6B7280;
    --color-border: #E5E7EB;
    --color-light-violet: #F5F3FF;
    --color-danger: #B91C1C;
    --color-danger-bg: #FEE2E2;
    --color-success-bg: #D1FAE5;
    --color-success-border: #10B981;
    /* Excel export — soft green, aligned with theme (not high-contrast neon) */
    --color-excel-bg: #E6F4EA;
    --color-excel-border: #B8DCC6;
    --color-excel-text: #1F5F45;
    --color-excel-hover-bg: #D8EDE0;
    --color-excel-hover-border: #9BCBB0;

    /* Shadows */
    --shadow-soft: 0 1px 3px rgba(124, 58, 237, 0.08);
    --shadow-card: 0 4px 6px -1px rgba(124, 58, 237, 0.07), 0 2px 4px -2px rgba(124, 58, 237, 0.05);
    --shadow-hover: 0 10px 15px -3px rgba(124, 58, 237, 0.08), 0 4px 6px -4px rgba(124, 58, 237, 0.05);

    /* Radius */
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;

    /* Layout */
    --sidebar-width: 240px;
    --navbar-height: 52px;
    --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: var(--font-family);
    background: var(--color-bg);
    color: var(--color-text);
    font-size: 15px;
    line-height: 1.5;
}

.app-wrapper {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    padding-top: 0;
}

/* ========== TOP NAVBAR ========== */
.top-navbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: var(--navbar-height);
    padding: 0 20px;
    background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-accent) 100%);
    color: var(--color-card);
    box-shadow: var(--shadow-card);
    display: none !important;
}

.top-navbar-left {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 0 1 auto;
    min-width: 0;
}

.brand-title {
    font-weight: 700;
    font-size: 1.1rem;
    letter-spacing: -0.02em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.top-navbar-right {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.top-info {
    font-size: 0.875rem;
    opacity: 1;
    font-weight: 700;
    color: #fff;
}

.sidebar-toggle {
    display: flex;
    position: relative;
    width: 36px;
    height: 36px;
    padding: 0;
    margin-left: 0;
    background: transparent;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    flex-shrink: 0;
    transition: opacity 0.2s ease, transform 0.2s ease;
    align-items: center;
    justify-content: center;
}
.sidebar-toggle:hover {
    opacity: 0.9;
}
/* Complete arrow: shaft runs to tip (15,12); both wings share tip — no gap */
.sidebar-toggle::before {
    content: "";
    display: block;
    width: 28px;
    height: 28px;
    flex-shrink: 0;
    border: none;
    margin: 0;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23ffffff' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M2 12L15 12L9 18M15 12L9 6'/%3E%3C/svg%3E")
        center center / contain no-repeat;
    transform: rotate(0deg);
    transform-origin: center center;
    transition: transform 0.25s ease;
}
/* Points left when sidebar is visible (desktop: not closed; mobile: open) */
@media (min-width: 1025px) {
    body:not(.sidebar-closed) .sidebar-toggle::before {
        transform: rotate(180deg);
    }
    /* Expanded navbar: more room on the right + nudge arrow left (was flush to edge) */
    body:not(.sidebar-closed) .sidebar-brand {
        padding-right: 28px;
    }
    body:not(.sidebar-closed) .sidebar-toggle--side::before {
        transform: translateX(-12px) rotate(180deg);
    }
}
@media (max-width: 1024px) {
    body.sidebar-open .sidebar-toggle::before {
        transform: rotate(180deg);
    }
}

/* ========== SIDEBAR ========== */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--sidebar-width);
    background: var(--color-primary);
    padding: 16px 0;
    overflow-y: auto;
    overflow-x: hidden;
    box-shadow: var(--shadow-card);
    z-index: 90;
    transition: transform 0.25s ease, width 0.25s ease;
    will-change: width;
}

.sidebar-brand {
    padding: 10px 16px 12px;
    color: #fff;
    text-align: left;
    border-bottom: 1px solid rgba(255, 255, 255, 0.18);
    margin-bottom: 6px;
}

.sidebar-brand-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.sidebar-brand-text {
    flex: 1 1 auto;
    min-width: auto;
    text-align: center;
    overflow: visible;
    transition: opacity 0.18s ease, width 0.25s ease;
    width: auto;
}

.sidebar-brand .brand-title {
    display: block;
    font-weight: 800;
    font-size: 1.25rem;
    white-space: nowrap;
}

.sidebar-brand .brand-subtitle {
    display: block;
    margin-top: 0;
    font-size: 1rem;
    opacity: 0.95;
    white-space: nowrap;
}

.sidebar-link,
.sidebar-nav a {
    display: block;
    padding: 10px 16px;
    color: #fff;
    text-decoration: none;
    font-size: 0.9rem;
    border-left: 3px solid transparent;
    margin: 2px 8px;
    border-radius: var(--radius-sm);
    transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    line-height: 1.15;
}

.sidebar-group {
    margin: 2px 0;
}

.sidebar-group-toggle {
    width: calc(100% - 16px);
    background: transparent;
    border: 0;
    font-family: inherit;
    text-align: left;
}

.sidebar-group-toggle .sidebar-group-caret {
    margin-left: auto;
    width: 8px;
    height: 8px;
    border-right: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    transform: rotate(45deg);
    transition: transform 0.2s ease;
}

.sidebar-group.open .sidebar-group-toggle .sidebar-group-caret {
    transform: rotate(-135deg);
}

.sidebar-submenu {
    display: none;
    margin: 0 8px 2px;
    padding-left: 18px;
    border-left: 1px solid rgba(255, 255, 255, 0.35);
}

.sidebar-group.open .sidebar-submenu {
    display: block;
}

.sidebar-sublink {
    margin: 2px 0;
    padding: 8px 12px;
    font-size: 0.86rem;
    border-left: 0;
}

.sidebar-sublink.active {
    background: rgba(255, 255, 255, 0.22);
    border-left-color: transparent;
}

.sidebar-link-logout {
    background: var(--color-danger);
    border: 1px solid var(--color-danger);
    border-left-color: var(--color-danger) !important;
    border-radius: 14px;
    justify-content: center;
    gap: 0;
    text-align: center;
}

.sidebar-logout-wrap {
    margin: 30px 8px 0;
}

.sidebar-logout-wrap .sidebar-link-logout {
    margin: 0;
}

.sidebar-link-logout:hover {
    background: var(--color-danger);
    border-color: var(--color-danger);
}

.nav-icon {
    width: 22px;
    min-width: 22px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    line-height: 1;
    color: #fff;
    flex-shrink: 0;
    align-self: center;
}

.nav-icon svg {
    width: 20px;
    height: 20px;
    display: block;
    flex-shrink: 0;
}

/* ========== FIXED WHITE TOP BAR (per page) ========== */
.app-topbar {
    position: fixed;
    top: 0;
    left: var(--sidebar-width);
    right: 0;
    height: 56px;
    background: var(--color-card);
    border-bottom: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    z-index: 85;
    box-shadow: 0 1px 0 rgba(17, 24, 39, 0.04);
}

.app-topbar-title {
    font-weight: 800;
    color: var(--color-text);
    font-size: 1.05rem;
}

.app-topbar-right {
    font-weight: 700;
    color: var(--color-text-muted);
    font-size: 0.95rem;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Make room for the fixed top bar */
.main-content {
    padding-top: 0;
}

@media (min-width: 1025px) {
    body.sidebar-closed .app-topbar {
        left: 74px;
    }
}

@media (max-width: 1024px) {
    .app-topbar {
        left: 0;
        padding-left: 56px;
    }
}

.nav-label {
    min-width: 0;
    line-height: 1.15;
    transition: opacity 0.18s ease, width 0.25s ease;
    width: auto;
    overflow: hidden;
    white-space: nowrap;
}

.sidebar-nav a:hover,
.sidebar-link:hover {
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
}

/* Keep logout button red even on hover/focus */
.sidebar-nav a.sidebar-link-logout:hover,
.sidebar-link.sidebar-link-logout:hover,
.sidebar-nav a.sidebar-link-logout:focus,
.sidebar-link.sidebar-link-logout:focus {
    background: var(--color-danger) !important;
    border-color: var(--color-danger) !important;
    color: #fff !important;
}

.sidebar-nav a.active,
.sidebar-link.active {
    background: rgba(255, 255, 255, 0.25);
    color: #fff;
    border-left-color: #fff;
    font-weight: 800;
}

/* ========== MAIN CONTENT ========== */
.main-content {
    margin-left: var(--sidebar-width);
    margin-top: 0;
    padding: 76px 20px 20px;
    flex: 1;
    min-width: 0;
    transition: margin-left 0.25s ease;
}

.sidebar-toggle--mobile {
    display: none;
}

.content-inner {
    max-width: 1600px;
    margin: 0 auto;
}

/* ========== FOOTER ========== */
.footer {
    margin-left: var(--sidebar-width);
    padding: 12px 20px;
    border-top: 1px solid var(--color-border);
    background: var(--color-card);
    font-size: 0.8rem;
    color: var(--color-text-muted);
    transition: margin-left 0.25s ease;
}

/* Desktop: collapse sidebar when .sidebar-closed */
@media (min-width: 1025px) {
    body.sidebar-closed .sidebar {
        transform: none;
        width: 74px;
    }
    body.sidebar-closed .sidebar-brand {
        padding: 10px 8px 12px;
    }
    body.sidebar-closed .sidebar-brand-text {
        opacity: 0;
        width: 0;
        overflow: hidden;
    }
    body.sidebar-closed .sidebar-brand-row {
        justify-content: center;
        gap: 0;
    }
    body.sidebar-closed .sidebar-toggle {
        margin: 0 auto;
    }
    body.sidebar-closed .sidebar-logout-wrap {
        display: none;
    }
    /* Keep menu item sizing/position stable; only hide labels */
    body.sidebar-closed .sidebar-link {
        border-left-color: transparent;
    }
    body.sidebar-closed .sidebar-link .nav-label {
        opacity: 0;
        width: 0;
        pointer-events: none;
    }
    body.sidebar-closed .sidebar-group-caret,
    body.sidebar-closed .sidebar-submenu {
        display: none !important;
    }
    body.sidebar-closed .main-content,
    body.sidebar-closed .footer {
        margin-left: 74px;
    }
}

/* When navbar is fixed, keep content spacing consistent on small screens too */
@media (max-width: 1024px) {
    body.sidebar-closed .sidebar {
        width: 100%;
    }
}

/* ========== PAGE HEADER ========== */
.page-header {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin: 0 0 14px 0;
    position: static;
    background: transparent;
    padding: 0;
    border: 0;
    box-shadow: none;
}

.page-header h1 {
    display: none;
}

.page-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

.page-actions .btn {
    margin-left: 0;
}

/* ========== BUTTONS ========== */
.btn {
    display: inline-block;
    padding: 8px 16px;
    border-radius: var(--radius-md);
    border: 1px solid var(--color-border);
    background: var(--color-card);
    color: var(--color-text);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
}

.btn:hover {
    background: var(--color-light-violet);
    border-color: var(--color-primary);
    color: var(--color-primary);
}

.btn.primary {
    background: var(--color-primary);
    color: var(--color-card);
    border-color: var(--color-primary);
}

.btn.primary:hover {
    background: var(--color-primary-hover);
    border-color: var(--color-primary-hover);
    color: var(--color-card);
    box-shadow: var(--shadow-soft);
}

.cancel-btn {
    border-color: #D1D5DB; /* slightly darker so Cancel is visible */
}

.btn.danger {
    background: var(--color-danger);
    color: var(--color-card);
    border-color: var(--color-danger);
}

.btn.danger:hover {
    background: #991B1B;
    border-color: #991B1B;
    color: var(--color-card);
}

.btn.small {
    padding: 5px 10px;
    font-size: 0.8rem;
}

/* Global edit button color (same as bill edit button) */
.btn.edit-btn {
    background: #f59e0b;
    border-color: #f59e0b;
    color: #111827;
}

.btn.edit-btn:hover {
    background: #d97706;
    border-color: #d97706;
    color: #111827;
}

/* Excel (.xlsx) export — full-width cells still center label */
.btn.btn-excel {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    background: var(--color-excel-bg);
    border-color: var(--color-excel-border);
    color: var(--color-excel-text);
}

.btn.btn-excel:hover {
    background: var(--color-excel-hover-bg);
    border-color: var(--color-excel-hover-border);
    color: var(--color-excel-text);
}

.btn.btn-excel.reports-statement-export-disabled,
.btn.btn-excel.reports-statement-export-disabled:hover {
    opacity: 0.55;
    cursor: not-allowed;
    pointer-events: none;
    box-shadow: none;
}

/* ========== ALERTS / FLASH MESSAGES ========== */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius-md);
    margin-bottom: 16px;
    border: 1px solid transparent;
}

.alert-success {
    background: var(--color-success-bg);
    border-color: var(--color-success-border);
    color: #065F46;
}

.alert-danger {
    background: var(--color-danger-bg);
    border-color: var(--color-danger);
    color: #7F1D1D;
}

.alert-info {
    background: var(--color-light-violet);
    border-color: var(--color-accent);
    color: var(--color-text);
}

/* ========== FORM SYSTEM ========== */
.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
}

.form-grid.report-filters,
.form-grid.search-filters {
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
}

/* Reports filters: All bills = single row. Customer statement = row1 view+type, row2 customer+dates+actions */
.form-grid.reports-filters-form > input[type="hidden"] {
    display: none;
}

.form-grid.reports-filters-form.reports-filters-form--range,
.form-grid.reports-filters-form.reports-filters-form--daily {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 14px 16px;
    width: 100%;
    box-sizing: border-box;
}

/* All bills: one row — row wrappers use display:contents so fields + buttons share one flex line */
.form-grid.reports-filters-form--range:not(.reports-filters-form--customer),
.form-grid.reports-filters-form--daily:not(.reports-filters-form--customer) {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: flex-end;
}

.form-grid.reports-filters-form--range:not(.reports-filters-form--customer) .reports-filters-row--top,
.form-grid.reports-filters-form--range:not(.reports-filters-form--customer) .reports-filters-row--bottom,
.form-grid.reports-filters-form--daily:not(.reports-filters-form--customer) .reports-filters-row--top,
.form-grid.reports-filters-form--daily:not(.reports-filters-form--customer) .reports-filters-row--bottom {
    display: contents;
}

.reports-filters-row--top,
.reports-filters-row--bottom {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 12px 16px;
    width: 100%;
    min-width: 0;
    box-sizing: border-box;
}

.reports-filters-row--top .form-group,
.reports-filters-row--bottom .form-group {
    min-width: 0;
}

.reports-filters-row--top .reports-field-report-view {
    flex: 0 1 13rem;
    min-width: min(100%, 11.5rem);
    max-width: 15rem;
}

.reports-filters-row--top .reports-field-report-type {
    flex: 0 1 12.5rem;
    min-width: min(100%, 11rem);
    max-width: 14rem;
}

.reports-filters-row--bottom .reports-customer-search {
    flex: 1 1 14rem;
    min-width: min(100%, 12rem);
    max-width: 100%;
}

.reports-filters-row--bottom .reports-range-from,
.reports-filters-row--bottom .reports-range-to,
.reports-filters-row--bottom .reports-daily-date {
    flex: 0 1 10.75rem;
    min-width: min(100%, 9.5rem);
    max-width: 11.5rem;
}

.reports-filters-row--top .reports-field-report-view select,
.reports-filters-row--top .reports-field-report-type select,
.reports-filters-row--bottom .reports-range-from input[type="date"],
.reports-filters-row--bottom .reports-range-to input[type="date"],
.reports-filters-row--bottom .reports-daily-date input[type="date"],
.reports-filters-row--bottom .reports-customer-search .reports-customer-combobox-field input[type="search"] {
    width: 100%;
    min-width: 0;
    box-sizing: border-box;
}

.reports-customer-combobox-field {
    position: relative;
    width: 100%;
    min-width: 0;
}

.reports-customer-combobox-list {
    position: absolute;
    left: 0;
    right: 0;
    top: calc(100% + 4px);
    z-index: 40;
    margin: 0;
    padding: 4px 0;
    list-style: none;
    max-height: min(16rem, 50vh);
    overflow-y: auto;
    background: var(--color-surface, #fff);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
}

.reports-customer-combobox-list[hidden] {
    display: none !important;
}

.reports-customer-combobox-option {
    margin: 0;
    padding: 8px 12px;
    cursor: pointer;
    line-height: 1.35;
    border: none;
    background: transparent;
    width: 100%;
    text-align: left;
    font: inherit;
    color: inherit;
    box-sizing: border-box;
}

.reports-customer-combobox-option:hover,
.reports-customer-combobox-option.is-active {
    background: var(--color-bg-muted, rgba(0, 0, 0, 0.06));
}

.reports-customer-combobox-name {
    display: block;
    font-weight: 600;
    font-size: 0.95rem;
}

.reports-customer-combobox-meta {
    display: block;
    font-size: 0.82rem;
    color: var(--color-text-muted);
    margin-top: 2px;
}

.reports-customer-combobox-empty {
    padding: 10px 12px;
    font-size: 0.9rem;
    color: var(--color-text-muted);
}

.reports-filters-row--bottom .reports-filter-actions {
    flex: 0 0 auto;
    margin-left: auto;
}

.reports-filters-row--bottom .reports-filter-actions-inner {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    justify-content: flex-end;
}

/* Reports: Generate / Export — match button and link height */
.form-grid.reports-filters-form .reports-filter-actions-inner .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    height: 2.5rem;
    min-height: 2.5rem;
    max-height: 2.5rem;
    padding: 0 16px;
    margin: 0;
    line-height: 1.2;
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 500;
    flex: 0 0 auto;
    white-space: nowrap;
    appearance: none;
    -webkit-appearance: none;
}

@media (max-width: 520px) {
    .reports-filters-row--bottom .reports-filter-actions {
        margin-left: 0;
        width: 100%;
    }

    .reports-filters-row--bottom .reports-filter-actions-inner {
        justify-content: flex-start;
        width: 100%;
    }
}

/* Customer statement on Reports */

.reports-customer-pick-card .reports-customer-pick-list {
    list-style: none;
    margin: 12px 0 0;
    padding: 0;
}

.reports-customer-pick-row {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 10px 12px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    margin-bottom: 8px;
    cursor: pointer;
}

.reports-customer-pick-row input {
    margin-top: 4px;
}

.reports-customer-pick-label {
    display: flex;
    flex-direction: column;
    gap: 2px;
    font-size: 0.95rem;
}

.reports-customer-pick-shop {
    color: var(--color-text-muted);
    font-size: 0.88rem;
}

.reports-customer-pick-meta {
    font-size: 0.85rem;
    color: var(--color-text-muted);
}

.reports-customer-statement .reports-section-title {
    margin-top: 0;
    margin-bottom: 8px;
    font-size: 1.15rem;
}

.reports-statement-period {
    margin: 0 0 12px;
    font-size: 0.95rem;
}

.reports-customer-statement-identity .reports-statement-identity-name {
    margin: 0 0 4px;
    font-size: 1rem;
}

.reports-statement-identity-shop {
    font-weight: 500;
}

.reports-statement-customer-meta {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    column-gap: clamp(16px, 3vw, 36px);
    row-gap: 10px;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--color-border);
}

@media (max-width: 520px) {
    .reports-statement-customer-meta {
        grid-template-columns: 1fr;
    }
}

.reports-statement-meta-item {
    display: grid;
    grid-template-columns: minmax(108px, 36%) 1fr;
    gap: 6px 12px;
    align-items: baseline;
    min-width: 0;
}

.reports-statement-meta-label {
    color: var(--color-text-muted);
    font-size: 0.82rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    text-transform: uppercase;
}

.reports-statement-meta-value {
    font-size: 0.92rem;
    word-break: break-word;
}

.reports-statement-meta-value--amount {
    font-variant-numeric: tabular-nums;
    font-weight: 600;
}

.reports-customer-statement-identity .reports-statement-identity-address,
.reports-customer-statement-identity .reports-statement-identity-phone {
    margin: 10px 0 0;
    font-size: 0.92rem;
}

.reports-customer-statement-identity .reports-statement-identity-phone {
    margin-top: 6px;
}

.reports-statement-section {
    margin-top: 16px;
}

.reports-statement-section .reports-section-title {
    font-size: 1.05rem;
    margin-bottom: 12px;
}

.reports-statement-subtotal {
    margin: 8px 0 12px;
    font-size: 0.95rem;
}

.reports-empty {
    color: var(--color-text-muted);
    padding: 12px 0;
}

.reports-bill-block {
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--color-border);
}

.reports-bill-block:last-child {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}

.reports-bill-summary-table {
    margin-bottom: 8px;
}

.reports-bill-items-wrap {
    margin-top: 4px;
    margin-left: 0;
}

.reports-bill-nested-table {
    font-size: 0.88rem;
}

.reports-bill-nested-table th,
.reports-bill-nested-table td {
    padding: 6px 10px;
}

.reports-statement-ledger-table {
    table-layout: fixed;
    width: 100%;
    min-width: 720px;
}

.reports-statement-ledger-table.reports-statement-ledger-table--extended {
    min-width: 960px;
}

/* Stable column widths: amounts use tabular figures so digits line up under headers */
.reports-statement-ledger-table thead th:nth-child(1),
.reports-statement-ledger-table tbody td:nth-child(1) {
    width: 9%;
    white-space: nowrap;
}

.reports-statement-ledger-table thead th:nth-child(2),
.reports-statement-ledger-table tbody td:nth-child(2) {
    width: 17%;
    min-width: 0;
    word-break: break-word;
}

.reports-statement-ledger-table thead th:nth-child(3),
.reports-statement-ledger-table tbody td:nth-child(3) {
    width: 12%;
    min-width: 0;
    word-break: break-word;
}

.reports-statement-ledger-table thead th:nth-child(4),
.reports-statement-ledger-table tbody td:nth-child(4),
.reports-statement-ledger-table thead th:nth-child(5),
.reports-statement-ledger-table tbody td:nth-child(5),
.reports-statement-ledger-table thead th:nth-child(6),
.reports-statement-ledger-table tbody td:nth-child(6),
.reports-statement-ledger-table thead th:nth-child(7),
.reports-statement-ledger-table tbody td:nth-child(7) {
    font-variant-numeric: tabular-nums;
}

.reports-statement-ledger-table:not(.reports-statement-ledger-table--extended) thead th:nth-child(4),
.reports-statement-ledger-table:not(.reports-statement-ledger-table--extended) tbody td:nth-child(4),
.reports-statement-ledger-table:not(.reports-statement-ledger-table--extended) thead th:nth-child(5),
.reports-statement-ledger-table:not(.reports-statement-ledger-table--extended) tbody td:nth-child(5) {
    width: 10%;
}

.reports-statement-ledger-table:not(.reports-statement-ledger-table--extended) thead th:nth-child(6),
.reports-statement-ledger-table:not(.reports-statement-ledger-table--extended) tbody td:nth-child(6) {
    width: 10%;
    white-space: nowrap;
}

/* Mode + Remarks share remaining width */
.reports-statement-ledger-table:not(.reports-statement-ledger-table--extended) thead th:nth-child(7),
.reports-statement-ledger-table:not(.reports-statement-ledger-table--extended) tbody td:nth-child(7) {
    width: auto;
    min-width: 0;
    word-break: break-word;
}

.reports-statement-ledger-table--extended thead th:nth-child(4),
.reports-statement-ledger-table--extended tbody td:nth-child(4),
.reports-statement-ledger-table--extended thead th:nth-child(5),
.reports-statement-ledger-table--extended tbody td:nth-child(5),
.reports-statement-ledger-table--extended thead th:nth-child(6),
.reports-statement-ledger-table--extended tbody td:nth-child(6),
.reports-statement-ledger-table--extended thead th:nth-child(7),
.reports-statement-ledger-table--extended tbody td:nth-child(7) {
    width: 9%;
}

.reports-statement-ledger-table--extended thead th:nth-child(8),
.reports-statement-ledger-table--extended tbody td:nth-child(8) {
    width: 9%;
    white-space: nowrap;
}

.reports-statement-ledger-table--extended thead th:nth-child(9),
.reports-statement-ledger-table--extended tbody td:nth-child(9) {
    width: auto;
    min-width: 0;
    word-break: break-word;
}

.reports-statement-ledger-table tbody td {
    vertical-align: top;
}

.reports-statement-ledger-table .reports-statement-total-label {
    text-align: right;
}

.reports-statement-ledger-table .reports-statement-separator td {
    border-top: 2px solid var(--color-border);
    padding: 0;
    height: 6px;
    background: var(--color-bg-muted, rgba(0, 0, 0, 0.04));
}

.reports-statement-ledger-table .reports-statement-row--bill td {
    background: var(--color-bg-muted, rgba(0, 0, 0, 0.03));
}

.reports-statement-ledger-table .reports-statement-row--payment td:nth-child(2) {
    color: var(--color-text-muted);
}

.reports-statement-ledger-table .reports-statement-row--opening td,
.reports-statement-ledger-table .reports-statement-row--legacy td {
    background: var(--color-light-violet, rgba(139, 92, 246, 0.06));
}

.reports-statement-ledger-table .reports-statement-row--total th {
    border-top: 2px solid var(--color-border);
    padding-top: 10px;
}

/* Ledger filters: keep state + from + to aligned on one row on larger screens */
.form-grid.ledger-filters {
    grid-template-columns: repeat(12, minmax(0, 1fr));
}

.form-grid.ledger-filters .ledger-filter-state {
    grid-column: span 6;
}

.form-grid.ledger-filters .ledger-filter-from,
.form-grid.ledger-filters .ledger-filter-to {
    grid-column: span 3;
}

.form-grid.ledger-filters .ledger-filter-action {
    grid-column: span 6;
}

.form-grid.ledger-filters .ledger-filter-action .btn {
    width: 100%;
    text-align: center;
}

/* Customer ledger: Credit popup */
body.ledger-credit-modal-active {
    overflow: hidden;
}

.ledger-credit-col {
    white-space: nowrap;
    width: 1%;
}

/* Ledger table row: make Credit control read clearly (default .btn.small is easy to miss). */
.btn.small.ledger-credit-open-btn {
    padding: 6px 12px;
    font-size: 0.85rem;
    font-weight: 600;
    letter-spacing: 0.01em;
    color: var(--color-primary);
    border-color: var(--color-primary);
    border-width: 1.5px;
    background: var(--color-light-violet);
    box-shadow: 0 1px 2px rgba(124, 58, 237, 0.12);
}

.btn.small.ledger-credit-open-btn:hover {
    background: var(--color-primary);
    color: var(--color-card);
    border-color: var(--color-primary);
    box-shadow: var(--shadow-soft);
}

.ledger-credit-modal {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    box-sizing: border-box;
    visibility: hidden;
    opacity: 0;
    transition: opacity 0.2s ease, visibility 0.2s ease;
}

.ledger-credit-modal--open {
    visibility: visible;
    opacity: 1;
}

.ledger-credit-modal__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    cursor: pointer;
}

.ledger-credit-modal__panel {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: min(1180px, 100%);
    /* Fixed large dialog height so toggling credit breakdown / focus does not resize the popup */
    min-height: min(560px, 85vh);
    max-height: min(88vh, 100%);
    display: flex;
    flex-direction: column;
    background: var(--color-surface, #fff);
    border-radius: var(--radius-md, 8px);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.18);
    overflow: hidden;
}

.ledger-credit-modal__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 18px;
    border-bottom: 1px solid var(--color-border);
    flex-shrink: 0;
}

.ledger-credit-modal__title {
    margin: 0;
    font-size: 1.15rem;
    font-weight: 600;
}

.ledger-credit-modal__close {
    flex-shrink: 0;
    min-width: 2.25rem;
    padding: 4px 10px;
    font-size: 1.25rem;
    line-height: 1;
}

.ledger-credit-modal__body {
    padding: 16px 18px 20px;
    overflow-y: auto;
    flex: 1;
    min-height: 0;
}

.ledger-credit-modal__loading {
    margin: 0;
    color: var(--color-text-muted);
}

.ledger-credit-modal__error {
    margin: 0;
    padding: 10px 12px;
    border-radius: var(--radius-md, 6px);
    background: rgba(220, 53, 69, 0.12);
    color: #842029;
}

.ledger-credit-summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 14px;
    margin-bottom: 20px;
}

.ledger-credit-summary__card {
    padding: 12px 14px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md, 6px);
    background: var(--color-bg-muted, #f8f9fa);
}

.ledger-credit-summary__label {
    display: block;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--color-text-muted);
    margin-bottom: 8px;
}

.ledger-credit-summary__value {
    font-size: 1.05rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.ledger-credit-calc {
    margin-bottom: 20px;
    padding: 14px 16px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md, 6px);
    background: var(--color-surface, #fff);
}

.ledger-credit-form-row {
    display: flex;
    flex-wrap: nowrap;
    align-items: flex-end;
    gap: 12px;
    width: 100%;
    overflow-x: auto;
    padding-bottom: 2px;
    -webkit-overflow-scrolling: touch;
    scrollbar-gutter: stable;
}

.ledger-credit-form-row .ledger-credit-form-field {
    flex: 1 1 0;
    min-width: 6.5rem;
    margin-bottom: 0;
}

.ledger-credit-form-row .ledger-credit-form-field label {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--color-text-muted);
    margin-bottom: 6px;
    line-height: 1.3;
}

.ledger-credit-calc__input {
    max-width: 220px;
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md, 6px);
    font-size: 0.95rem;
    font-variant-numeric: tabular-nums;
}

.ledger-credit-form-row .ledger-credit-calc__input {
    max-width: none;
    width: 100%;
    min-width: 0;
    box-sizing: border-box;
}

.ledger-credit-calc-breakdown {
    margin-top: 14px;
    padding-top: 12px;
    border-top: 1px solid var(--color-border);
}

.ledger-credit-calc-breakdown__row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 12px;
    padding: 6px 0;
    font-size: 0.9rem;
}

.ledger-credit-calc-breakdown__row strong {
    font-variant-numeric: tabular-nums;
    font-weight: 600;
}

.ledger-credit-calc-breakdown__row--highlight {
    font-weight: 600;
    margin-top: 4px;
    padding-top: 10px;
    border-top: 1px dashed var(--color-border);
}

.ledger-credit-bill-hint {
    margin: 12px 0 0;
    padding: 10px 12px;
    border-radius: var(--radius-md, 6px);
    background: rgba(13, 110, 253, 0.08);
    color: var(--color-text, #333);
    font-size: 0.9rem;
    line-height: 1.45;
}

.ledger-credit-bill-status {
    margin: 10px 0 0;
    font-size: 0.9rem;
    line-height: 1.4;
}

.ledger-credit-bill-status--ok {
    color: #0f5132;
}

.ledger-credit-bill-status--warn {
    color: #664d03;
}

.ledger-credit-bill-status--bad {
    color: #842029;
}

.ledger-credit-section {
    margin-bottom: 16px;
    padding: 14px 14px 16px;
    border-radius: var(--radius-md, 8px);
    border: 1px solid var(--color-border);
}

.ledger-credit-section--pending {
    background: rgba(245, 158, 11, 0.07);
    border-color: rgba(245, 158, 11, 0.28);
}

.ledger-credit-section--settled {
    background: rgba(16, 185, 129, 0.06);
    border-color: rgba(16, 185, 129, 0.25);
}

.ledger-credit-section--recent {
    background: var(--color-light-violet, #f5f3ff);
    border-color: rgba(124, 58, 237, 0.2);
}

.ledger-credit-section .ledger-credit-bills-heading {
    margin-top: 0;
}

.ledger-credit-bills-heading {
    margin: 0 0 12px;
    font-size: 1rem;
    font-weight: 600;
}

.ledger-credit-bills-empty {
    margin: 0;
    color: var(--color-text-muted);
    font-size: 0.95rem;
}

.ledger-credit-bills-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 12px;
}

.ledger-credit-bill-card {
    padding: 12px 14px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md, 6px);
    background: var(--color-surface, #fff);
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    gap: 10px;
    cursor: pointer;
    margin: 0;
}

.ledger-credit-bill-card--selected {
    border-color: var(--color-primary, #0d6efd);
    box-shadow: 0 0 0 1px rgba(13, 110, 253, 0.35);
}

.ledger-credit-bill-card--disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.ledger-credit-bill-card__check {
    margin-top: 4px;
    flex-shrink: 0;
    width: 1rem;
    height: 1rem;
    cursor: inherit;
}

.ledger-credit-bill-card__body {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.ledger-credit-bill-card__no {
    font-weight: 600;
    font-size: 0.95rem;
}

.ledger-credit-bill-card__date {
    font-size: 0.85rem;
    color: var(--color-text-muted);
}

.ledger-credit-bill-card__amt {
    font-size: 1rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    margin-top: 4px;
}

.ledger-credit-modal__footer {
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--color-border);
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
}

.ledger-credit-save-feedback {
    margin: 0;
    font-size: 0.9rem;
    flex: 1;
    min-width: 140px;
}

.ledger-credit-save-feedback--success {
    color: #0f5132;
    font-weight: 500;
}

.ledger-credit-delete-confirm {
    margin-top: 10px;
    padding: 10px 12px;
    border: 1px solid #f5c2c7;
    border-radius: 8px;
    background: #fff5f5;
}

.ledger-credit-delete-confirm__title {
    margin: 0;
    font-size: 0.9rem;
    font-weight: 600;
    color: #842029;
}

.ledger-credit-delete-confirm__text {
    margin: 6px 0 0;
    font-size: 0.85rem;
    color: #842029;
}

.ledger-credit-delete-confirm__actions {
    margin-top: 10px;
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

.ledger-credit-migrate-hint {
    margin-top: 10px;
    font-size: 0.85rem;
    color: var(--color-text-muted, #6b7280);
}

.ledger-credit-migrate-hint code {
    font-size: 0.8em;
}

.ledger-credit-waterfall-preview {
    margin-top: 12px;
    padding: 12px 14px;
    background: var(--color-surface-alt, #f8fafc);
    border: 1px solid var(--color-border);
    border-radius: 8px;
}

.ledger-credit-waterfall-preview__title {
    margin: 0 0 8px;
    font-size: 0.9rem;
    font-weight: 600;
}

.ledger-credit-waterfall-preview__list {
    margin: 0;
    padding-left: 1.2rem;
    font-size: 0.88rem;
    line-height: 1.45;
}

.ledger-credit-waterfall-preview__bal {
    color: var(--color-text-muted, #6b7280);
    font-weight: normal;
}

.ledger-credit-perbill-details {
    margin-top: 12px;
}

.ledger-credit-perbill-details summary {
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
}

.ledger-credit-perbill-row {
    margin-top: 12px;
    padding-bottom: 12px;
    border-bottom: 1px dashed var(--color-border);
}

.ledger-credit-perbill-row__title {
    font-size: 0.85rem;
    font-weight: 600;
}

.ledger-credit-perbill-row__fields {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: flex-end;
    margin-top: 8px;
}

.ledger-credit-perbill-row__fields label {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 0.78rem;
    min-width: 118px;
}

.ledger-credit-mini-table {
    width: 100%;
    font-size: 0.86rem;
    border-collapse: collapse;
}

.ledger-credit-mini-table th,
.ledger-credit-mini-table td {
    padding: 8px 10px;
    border-bottom: 1px solid var(--color-border);
    text-align: left;
    vertical-align: middle;
}

.ledger-credit-mini-table th {
    font-weight: 600;
    color: var(--color-text-muted, #6b7280);
    font-size: 0.8rem;
}

.ledger-credit-mini-table .ta-right {
    text-align: right;
    white-space: nowrap;
}

.ledger-credit-bills-heading--settled {
    margin-top: 0;
}

.ledger-credit-bills-pending,
.ledger-credit-bills-settled,
.ledger-credit-recent {
    overflow-x: auto;
    margin-bottom: 0;
    -webkit-overflow-scrolling: touch;
}

/* Credit popup: tables on tinted sections need a clear card surface and readable grid lines */
.ledger-credit-section .ledger-credit-mini-table {
    background: #fff;
    border: 1px solid rgba(55, 65, 81, 0.34);
    border-radius: var(--radius-sm, 6px);
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(17, 24, 39, 0.07);
}

.ledger-credit-section--pending .ledger-credit-mini-table {
    border-color: rgba(146, 64, 14, 0.55);
    box-shadow: 0 1px 3px rgba(180, 83, 9, 0.1);
}

.ledger-credit-section--settled .ledger-credit-mini-table {
    border-color: rgba(4, 100, 70, 0.52);
    box-shadow: 0 1px 3px rgba(5, 120, 85, 0.08);
}

.ledger-credit-section--recent .ledger-credit-mini-table {
    border-color: rgba(91, 33, 182, 0.45);
    box-shadow: 0 1px 3px rgba(124, 58, 237, 0.1);
}

.ledger-credit-section .ledger-credit-mini-table th,
.ledger-credit-section .ledger-credit-mini-table td {
    border-bottom: 1px solid rgba(55, 65, 81, 0.22);
}

.ledger-credit-section .ledger-credit-mini-table th:not(:last-child),
.ledger-credit-section .ledger-credit-mini-table td:not(:last-child) {
    border-right: 1px solid rgba(55, 65, 81, 0.18);
}

.ledger-credit-section .ledger-credit-mini-table th {
    background: rgba(55, 65, 81, 0.09);
    border-bottom: 1px solid rgba(55, 65, 81, 0.32);
    color: var(--color-text, #111827);
}

.ledger-credit-section .ledger-credit-mini-table tbody tr:last-child td {
    border-bottom: none;
}

/* Credit popup tables: padding, vertical rhythm, header/body alignment */
.ledger-credit-section .ledger-credit-mini-table thead th,
.ledger-credit-section .ledger-credit-mini-table tbody td {
    padding: 10px 12px;
    box-sizing: border-box;
}

.ledger-credit-section .ledger-credit-mini-table thead th {
    vertical-align: bottom;
    line-height: 1.35;
}

.ledger-credit-section .ledger-credit-mini-table tbody td {
    vertical-align: top;
}

/* Popup tables: match header alignment to columns; tabular nums for money columns */
.ledger-credit-section .ledger-credit-mini-table th.ta-right,
.ledger-credit-section .ledger-credit-mini-table td.ta-right {
    text-align: right;
    font-variant-numeric: tabular-nums;
    padding-right: 14px;
}

.ledger-credit-section .ledger-credit-mini-table th:not(.ta-right),
.ledger-credit-section .ledger-credit-mini-table td:not(.ta-right) {
    text-align: left;
}

/* Pending / settled bill tables: bill no & date columns */
.ledger-credit-section .ledger-credit-bills-pending .ledger-credit-mini-table :is(th, td):nth-child(1),
.ledger-credit-section .ledger-credit-bills-settled .ledger-credit-mini-table :is(th, td):nth-child(1) {
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

.ledger-credit-section .ledger-credit-bills-pending .ledger-credit-mini-table :is(th, td):nth-child(2),
.ledger-credit-section .ledger-credit-bills-pending .ledger-credit-mini-table :is(th, td):nth-child(5),
.ledger-credit-section .ledger-credit-bills-settled .ledger-credit-mini-table :is(th, td):nth-child(2),
.ledger-credit-section .ledger-credit-bills-settled .ledger-credit-mini-table :is(th, td):nth-child(5) {
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

.ledger-credit-section .ledger-credit-bills-pending .ledger-credit-mini-table :is(th, td):nth-child(n + 3) {
    min-width: 5.5rem;
}

.ledger-credit-section .ledger-credit-bills-settled .ledger-credit-mini-table :is(th, td):nth-child(3),
.ledger-credit-section .ledger-credit-bills-settled .ledger-credit-mini-table :is(th, td):nth-child(4) {
    min-width: 5.5rem;
}

.ledger-credit-section .ledger-credit-bills-pending .ledger-credit-mini-table :is(th, td):nth-child(5),
.ledger-credit-section .ledger-credit-bills-settled .ledger-credit-mini-table :is(th, td):nth-child(5) {
    min-width: 7.5rem;
}

/* Pending / settled bill tables: center all column titles and values (popup only) */
.ledger-credit-section .ledger-credit-bills-pending .ledger-credit-mini-table th,
.ledger-credit-section .ledger-credit-bills-pending .ledger-credit-mini-table td,
.ledger-credit-section .ledger-credit-bills-settled .ledger-credit-mini-table th,
.ledger-credit-section .ledger-credit-bills-settled .ledger-credit-mini-table td {
    text-align: center;
    padding: 10px 12px;
}

.ledger-credit-section .ledger-credit-bills-pending .ledger-credit-mini-table th.ta-right,
.ledger-credit-section .ledger-credit-bills-pending .ledger-credit-mini-table td.ta-right,
.ledger-credit-section .ledger-credit-bills-settled .ledger-credit-mini-table th.ta-right,
.ledger-credit-section .ledger-credit-bills-settled .ledger-credit-mini-table td.ta-right {
    text-align: center;
    font-variant-numeric: tabular-nums;
}

/* Recent credits table: center all headers and cells (same as bill tables) */
.ledger-credit-section .ledger-credit-recent .ledger-credit-mini-table thead th,
.ledger-credit-section .ledger-credit-recent .ledger-credit-mini-table tbody td {
    text-align: center;
    padding: 10px 12px;
}

.ledger-credit-section .ledger-credit-recent .ledger-credit-mini-table thead th.ta-right,
.ledger-credit-section .ledger-credit-recent .ledger-credit-mini-table tbody td.ta-right {
    text-align: center;
    font-variant-numeric: tabular-nums;
}

/* Recent credits: Bills (full / partial) — body cells left-aligned; chips per bill */
.ledger-credit-section .ledger-credit-recent .ledger-credit-mini-table tbody td.ledger-credit-recent-bills {
    text-align: left;
}

.ledger-credit-section .ledger-credit-recent .ledger-credit-mini-table .ledger-credit-bill-chips {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px 8px;
    align-items: stretch;
    justify-items: stretch;
    width: 100%;
}

.ledger-credit-section .ledger-credit-recent .ledger-credit-mini-table .ledger-credit-bill-chip {
    display: block;
    width: 100%;
    min-width: 0;
    padding: 5px 8px;
    border-radius: var(--radius-sm, 6px);
    background: rgba(124, 58, 237, 0.1);
    border: 1px solid rgba(124, 58, 237, 0.22);
    font-size: 0.8rem;
    line-height: 1.35;
    font-variant-numeric: tabular-nums;
    text-align: center;
    box-sizing: border-box;
    word-break: break-word;
}

@media (max-width: 520px) {
    .ledger-credit-section .ledger-credit-recent .ledger-credit-mini-table .ledger-credit-bill-chips {
        grid-template-columns: 1fr;
    }
}

/* Recent credits: date + mode nowrap; money columns minimum width */
.ledger-credit-section .ledger-credit-recent .ledger-credit-mini-table :is(th, td):nth-child(1) {
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

.ledger-credit-section .ledger-credit-recent .ledger-credit-mini-table :is(th, td):nth-child(8) {
    white-space: nowrap;
}

.ledger-credit-section .ledger-credit-recent .ledger-credit-mini-table :is(th, td):nth-child(2),
.ledger-credit-section .ledger-credit-recent .ledger-credit-mini-table :is(th, td):nth-child(3),
.ledger-credit-section .ledger-credit-recent .ledger-credit-mini-table :is(th, td):nth-child(4),
.ledger-credit-section .ledger-credit-recent .ledger-credit-mini-table :is(th, td):nth-child(6),
.ledger-credit-section .ledger-credit-recent .ledger-credit-mini-table :is(th, td):nth-child(7) {
    min-width: 5.25rem;
}

.ledger-credit-section .ledger-credit-recent .ledger-credit-mini-table :is(th, td):nth-child(5) {
    min-width: 14rem;
}

.ledger-credit-section .ledger-credit-mini-table .ledger-credit-recent-bills {
    text-align: left;
    white-space: normal;
    vertical-align: top;
}

.ledger-credit-recent-bills {
    max-width: 20rem;
    white-space: normal;
    font-size: 0.82rem;
    line-height: 1.4;
    vertical-align: top;
}

@media (max-width: 640px) {
    .ledger-credit-modal__panel {
        max-height: min(92vh, 720px);
    }
}

.form-group {
    display: flex;
    flex-direction: column;
}

.form-group.full {
    grid-column: 1 / -1;
}

.form-group label {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--color-text-muted);
    margin-bottom: 6px;
}

.form-group input,
.form-group select,
.form-group textarea {
    padding: 8px 12px;
    border-radius: var(--radius-md);
    border: 1px solid var(--color-border);
    font-size: 0.9rem;
    font-family: inherit;
    background: var(--color-card);
    color: var(--color-text);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.15);
}

.form-group input[readonly] {
    background: var(--color-bg);
    color: var(--color-text-muted);
}

.form-group textarea {
    min-height: 80px;
    resize: vertical;
}

.form-actions {
    margin-top: 20px;
    grid-column: 1 / -1;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.form-actions .btn {
    margin-right: 0;
}

/* ========== CARDS ========== */
.card {
    background: var(--color-card);
    border-radius: var(--radius-lg);
    padding: 20px;
    margin-bottom: 20px;
    border: 1px solid var(--color-border);
    box-shadow: var(--shadow-card);
    transition: box-shadow 0.2s ease;
}

.card:hover {
    box-shadow: var(--shadow-hover);
}

.card-title {
    font-size: 0.85rem;
    color: var(--color-text-muted);
    margin-bottom: 6px;
    font-weight: 500;
}

.card-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--color-text);
}

/* ========== DASHBOARD ========== */
.dashboard-layout {
    display: flex;
    flex-direction: column;
    min-height: calc(100vh - 180px);
}

.dashboard-cards {
    display: grid;
    grid-template-columns: 1fr;
    justify-items: center;
    column-gap: clamp(22px, 5.5vw, 40px);
    row-gap: clamp(22px, 4.8vw, 34px);
    margin-bottom: 28px;
    width: 100%;
    max-width: calc(100% - clamp(28px, 7vw, 72px));
    margin-left: auto;
    margin-right: auto;
    box-sizing: border-box;
}

.dashboard-cards .card {
    margin-bottom: 0;
}

@media (min-width: 560px) {
    .dashboard-cards {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

.dashboard-stat-card {
    position: relative;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: clamp(20px, 3.6vw, 30px);
    width: 100%;
    max-width: 94%;
    min-width: 0;
    min-height: clamp(124px, 26vw, 158px);
    padding: clamp(16px, 2.8vw, 24px);
    text-align: center;
    border-left-width: 4px;
    border-left-style: solid;
    animation: dashboard-card-in 0.55s ease both;
}

.dashboard-stat-card--customers {
    border-left-color: var(--color-primary);
}

.dashboard-stat-card--revenue {
    border-left-color: #059669;
}

.dashboard-stat-card--month {
    border-left-color: #D97706;
}

.dashboard-stat-card--today {
    border-left-color: #2563EB;
}

.dashboard-stat-card:nth-child(2) {
    animation-delay: 0.08s;
}

.dashboard-stat-card:nth-child(3) {
    animation-delay: 0.16s;
}

.dashboard-stat-card:nth-child(4) {
    animation-delay: 0.24s;
}

.dashboard-stat-card__icon {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    width: clamp(54px, 13vw, 66px);
    height: clamp(54px, 13vw, 66px);
    border-radius: var(--radius-md);
    color: var(--color-primary);
    background: var(--color-light-violet);
}

.dashboard-stat-card--customers .dashboard-stat-card__icon {
    color: var(--color-primary);
    background: var(--color-light-violet);
}

.dashboard-stat-card--revenue .dashboard-stat-card__icon {
    color: #047857;
    background: #ECFDF5;
}

.dashboard-stat-card--month .dashboard-stat-card__icon {
    color: #B45309;
    background: #FFFBEB;
}

.dashboard-stat-card--today .dashboard-stat-card__icon {
    color: #1D4ED8;
    background: #EFF6FF;
}

.dashboard-stat-card__icon svg {
    width: clamp(26px, 7vw, 34px);
    height: clamp(26px, 7vw, 34px);
}

.dashboard-stat-card__body {
    flex: 0 1 auto;
    min-width: 0;
    max-width: 100%;
    text-align: center;
}

.dashboard-stat-card .card-title {
    font-size: clamp(0.9rem, 2vw, 1.05rem);
    margin-bottom: 6px;
    line-height: 1.35;
    text-align: center;
}

.dashboard-stat-card .card-value {
    font-size: clamp(1.3rem, 4.2vw, 1.85rem);
    line-height: 1.2;
    word-break: break-word;
    text-align: center;
}

.dashboard-stat-card__value--money {
    display: inline-flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: center;
    gap: 0.35em 0.5em;
    max-width: 100%;
}

.dashboard-stat-card__inr {
    font-size: 0.95em;
    font-weight: 700;
    color: var(--color-text-muted);
    white-space: nowrap;
    line-height: 1;
}

.dashboard-stat-card__amount {
    font-weight: 700;
    color: var(--color-text);
}

@media (max-width: 359px) {
    .dashboard-stat-card {
        flex-direction: column;
        align-items: center;
        justify-content: center;
        text-align: center;
    }

    .dashboard-stat-card__icon {
        align-self: center;
    }
}

.dashboard-quick-actions {
    background: var(--color-card);
    padding: clamp(16px, 3vw, 20px);
    border-radius: var(--radius-lg);
    border: 1px solid var(--color-border);
    box-shadow: var(--shadow-soft);
    margin-top: auto;
    margin-bottom: 24px;
    width: 100%;
    max-width: calc(100% - clamp(28px, 7vw, 72px));
    margin-left: auto;
    margin-right: auto;
    min-width: 0;
    box-sizing: border-box;
}

.dashboard-quick-actions h2 {
    font-size: clamp(1rem, 2.2vw, 1.15rem);
    font-weight: 700;
    margin: 0 0 14px 0;
    color: var(--color-text);
}

.quick-actions-grid {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    width: 100%;
}

.quick-actions-row {
    display: grid;
    gap: 10px;
    width: 100%;
}

.quick-actions-row--4,
.quick-actions-row--3 {
    grid-template-columns: 1fr;
}

@media (min-width: 480px) {
    .quick-actions-row--4 {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .quick-actions-row--3 {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

@media (min-width: 768px) {
    .quick-actions-row--4 {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }

    .quick-actions-row--3 {
        grid-template-columns: repeat(3, minmax(0, 1fr));
        width: 75%;
        max-width: 100%;
        margin-left: auto;
        margin-right: auto;
    }
}

.quick-actions-grid .btn {
    margin: 0;
    width: 100%;
    text-align: center;
    box-sizing: border-box;
    border-color: #D1D5DB;
}

@keyframes dashboard-card-in {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@media (max-width: 900px) {
    .dashboard-layout {
        min-height: auto;
    }
}

@media (prefers-reduced-motion: reduce) {
    .dashboard-stat-card {
        animation: none;
    }
}

/* ========== TABLES ========== */
.table-responsive {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    background: var(--color-card);
    border-radius: var(--radius-lg);
    border: 1px solid var(--color-border);
    box-shadow: var(--shadow-soft);
    margin-bottom: 16px;
}

.table {
    width: 100%;
    min-width: 600px;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.table th,
.table td {
    padding: 12px 14px;
    text-align: left;
    border-bottom: 1px solid var(--color-border);
}

.table th {
    background: var(--color-light-violet);
    color: var(--color-text);
    font-weight: 600;
    white-space: nowrap;
}

.table tbody tr:hover {
    background: var(--color-light-violet);
}

.table tbody tr:last-child td {
    border-bottom: none;
}

/* Products → Product catalog: shrink Product Code column and tighten gutter before Weight(Kg) */
.products-catalog-table th:nth-child(3),
.products-catalog-table td:nth-child(3) {
    width: 1%;
    white-space: nowrap;
    padding: 12px 6px 12px 14px;
}

.products-catalog-table th:nth-child(4),
.products-catalog-table td:nth-child(4) {
    padding: 12px 14px 12px 6px;
}

/* Product catalog: Quantity(Pcs) — right-aligned digits inset from column edge (before Amount) */
.table.products-catalog-table tbody td:nth-child(6) {
    padding-top: 12px;
    padding-bottom: 12px;
    padding-left: 14px;
    padding-right: 3rem;
}

/* Customers list: Edit + Delete stay on one row with consistent spacing */
.customers-table-actions {
    vertical-align: middle;
}

.customers-row-actions {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: 8px;
}

.customers-row-actions .btn {
    flex-shrink: 0;
}

/* Bill list: View+Print on first row, Edit+Delete on second (aligned when customer/state wraps) */
.bill-row-actions {
    vertical-align: middle;
}

.bill-row-actions-inner {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
}

.bill-row-actions-row {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: 6px;
}

.bill-row-actions-delete-form {
    display: inline-flex;
    margin: 0;
}

/* Bill page row action button colors */
.bill-row-actions .btn.bill-edit-btn {
    background: #f59e0b;
    border-color: #f59e0b;
    color: #111827;
}

.bill-row-actions .btn.bill-edit-btn:hover {
    background: #d97706;
    border-color: #d97706;
    color: #111827;
}

.bill-row-actions .btn.bill-delete-btn {
    background: #dc2626;
    border-color: #dc2626;
    color: #ffffff;
}

.bill-row-actions .btn.bill-delete-btn:hover {
    background: #b91c1c;
    border-color: #b91c1c;
    color: #ffffff;
}

.bill-row-actions .btn.bill-view-btn {
    background: #2563eb;
    border-color: #2563eb;
    color: #ffffff;
}

.bill-row-actions .btn.bill-view-btn:hover {
    background: #1d4ed8;
    border-color: #1d4ed8;
    color: #ffffff;
}

.bill-row-actions .btn.bill-print-btn {
    background: #6b7280;
    border-color: #6b7280;
    color: #ffffff;
}

.bill-row-actions .btn.bill-print-btn:hover {
    background: #4b5563;
    border-color: #4b5563;
    color: #ffffff;
}

.table tfoot th,
.table tfoot td {
    background: var(--color-light-violet);
    font-weight: 600;
    border-top: 2px solid var(--color-border);
    padding: 12px 14px;
}

.text-center {
    text-align: center;
}

.text-right {
    text-align: right;
}

/* `.table th, .table td { text-align: left }` wins over single-class utilities; raise specificity for cells. */
.table th.text-center,
.table td.text-center {
    text-align: center;
}

.table th.text-right,
.table td.text-right {
    text-align: right;
}

.text-nowrap {
    white-space: nowrap;
}

/* Bill list: wide grid scrolls horizontally on small viewports */
.table-responsive--history-bills {
    max-width: 100%;
}

.history-bills-table {
    min-width: 1000px;
    width: 100%;
    table-layout: fixed;
}

/* Compact serial column */
.history-bills-table .history-bills-col-sno {
    width: 3rem;
    max-width: 3rem;
    min-width: 3rem;
    padding-left: 6px;
    padding-right: 6px;
    text-align: center;
    box-sizing: border-box;
}

.history-bills-table th.history-bills-col-sno {
    white-space: nowrap;
}

/* Narrower customer column frees horizontal space for Actions */
.history-bills-table .history-bills-col-customer {
    width: 15%;
    max-width: 200px;
    min-width: 0;
    word-break: break-word;
    overflow-wrap: anywhere;
}

.history-bills-table .history-bills-col-actions {
    width: 210px;
    min-width: 210px;
    box-sizing: border-box;
}

/* ========== PAGINATION ========== */
.pagination {
    margin-top: 16px;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.pagination a {
    display: inline-block;
    padding: 6px 12px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    text-decoration: none;
    font-size: 0.85rem;
    color: var(--color-text);
    background: var(--color-card);
    transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.pagination a:hover {
    background: var(--color-light-violet);
    border-color: var(--color-primary);
    color: var(--color-primary);
}

.pagination a.active {
    background: var(--color-primary);
    color: var(--color-card);
    border-color: var(--color-primary);
}

/* ========== SEARCH FORM ========== */
.search-form {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 10px;
    margin-bottom: 20px;
    padding: 16px;
    background: var(--color-card);
    border-radius: var(--radius-lg);
    border: 1px solid var(--color-border);
    box-shadow: var(--shadow-soft);
}

.search-form input[type="text"],
.search-form input[type="date"] {
    padding: 8px 12px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    font-size: 0.9rem;
    min-width: 160px;
}

.search-form input:focus {
    outline: none;
    border-color: var(--color-primary);
}

.search-form .btn {
    margin: 0;
}

/* ========== BILL FORM ========== */
.bill-form {
    max-width: 1200px;
}

.bill-form .bill-header-section,
.bill-form .bill-totals-section {
    margin-bottom: 20px;
}

.bill-header-section {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 16px;
    padding: 20px;
    background: var(--color-card);
    border-radius: var(--radius-lg);
    border: 1px solid var(--color-border);
    box-shadow: var(--shadow-soft);
}

.bill-customer-section {
    margin-bottom: 20px;
    padding: 20px;
    background: var(--color-card);
    border-radius: var(--radius-lg);
    border: 1px solid var(--color-border);
    box-shadow: var(--shadow-soft);
}

.bill-customer-section h3 {
    margin: 0 0 14px 0;
    font-size: 1rem;
    color: var(--color-text);
}

.bill-items-section {
    margin-bottom: 20px;
}

.bill-items-section h3 {
    margin: 0 0 12px 0;
    font-size: 1rem;
    color: var(--color-text);
}

.bill-items-section .table-responsive {
    margin-bottom: 0;
}

/* Stable column widths when toggling catalog dropdown vs packed native select */
#bill-form .bill-items-table {
    table-layout: fixed;
    min-width: 39rem;
}

/* No row hover tint on bill line items (global .table tbody tr:hover does not apply here) */
#bill-form .bill-items-table tbody tr:hover {
    background: transparent;
}

#bill-form .bill-items-table th.bill-col-desc,
#bill-form .bill-items-table td.bill-line-desc-cell {
    width: 25%;
    min-width: 12.75rem;
    box-sizing: border-box;
    vertical-align: middle;
}

#bill-form .bill-items-table thead th:first-child,
#bill-form .bill-items-table tbody > tr > td:first-child {
    width: 2.75rem;
    text-align: center;
}

.bill-items-table th,
.bill-items-table td {
    padding: 8px 10px;
}

.bill-items-table select,
.bill-items-table input {
    width: 100%;
    min-width: 0;
    padding: 6px 8px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
}

.bill-items-tfoot {
    background: #f8fafc;
}

.bill-items-tfoot .bill-summary-row td {
    vertical-align: middle;
    border-top: 1px solid var(--color-border);
}

.bill-items-tfoot .bill-summary-total-row td {
    border-top-width: 2px;
}

.bill-items-tfoot .bill-summary-label {
    text-align: right;
    font-weight: 500;
    padding-right: 12px;
}

.bill-items-tfoot .bill-summary-amount-cell {
    min-width: 6.5rem;
}

.bill-items-tfoot .bill-summary-readonly {
    background: #eef2f7;
    font-weight: 600;
    text-align: right;
}

/* Bill line product pickers — distinct from plain table inputs, theme-aligned */
#bill-form {
    --bill-dropdown-surface: #faf8ff;
    --bill-dropdown-surface-hover: #f3effe;
    --bill-dropdown-surface-open: #ede9fe;
    --bill-dropdown-border: #ddd6fe;
    --bill-dropdown-border-hover: #c4b5fd;
    --bill-dropdown-menu-bg: #ffffff;
    --bill-dropdown-menu-divider: #ede9fe;
    --bill-dropdown-option-hover: #f5f3ff;
    --bill-dropdown-chevron: #6d28d9;
    --bill-dropdown-shadow: 0 1px 2px rgba(124, 58, 237, 0.07);
    --bill-dropdown-shadow-menu: 0 10px 28px rgba(91, 33, 182, 0.12), 0 2px 8px rgba(17, 24, 39, 0.06);
}

/* Bill product custom dropdown: fixed overlay list with scroll */
#bill-form .bill-product-dropdown {
    position: relative;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

#bill-form .bill-product-select {
    position: absolute;
    opacity: 0;
    pointer-events: none;
    width: 0;
    height: 0;
}

#bill-form .bill-product-trigger {
    width: 100%;
    min-height: 34px;
    padding: 6px 1.75rem 6px 10px;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    text-align: left;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    border: 1px solid var(--bill-dropdown-border);
    border-radius: var(--radius-sm);
    background: var(--bill-dropdown-surface);
    color: var(--color-text);
    font-size: 0.85rem;
    cursor: pointer;
    position: relative;
    box-sizing: border-box;
    box-shadow: var(--bill-dropdown-shadow);
    transition: background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

#bill-form .bill-product-search-input {
    cursor: text;
    padding: 6px 10px;
}

#bill-form .bill-product-search-input::placeholder {
    color: var(--color-text-muted);
}

#bill-form .bill-product-search-input:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: var(--bill-dropdown-shadow), 0 0 0 2px rgba(124, 58, 237, 0.22);
    background: var(--bill-dropdown-surface-open);
}

#bill-form .bill-product-trigger:hover:not(:disabled) {
    background: var(--bill-dropdown-surface-hover);
    border-color: var(--bill-dropdown-border-hover);
}

#bill-form .bill-product-trigger:focus-visible {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: var(--bill-dropdown-shadow), 0 0 0 2px rgba(124, 58, 237, 0.22);
}

#bill-form .bill-product-dropdown:has(.bill-product-menu:not(.hidden)) .bill-product-trigger {
    background: var(--bill-dropdown-surface-open);
    border-color: var(--color-primary);
    box-shadow: var(--bill-dropdown-shadow), 0 0 0 1px rgba(124, 58, 237, 0.12);
}

#bill-form .bill-product-trigger::after {
    content: "";
    position: absolute;
    right: 10px;
    top: 50%;
    width: 7px;
    height: 7px;
    border-right: 2px solid var(--bill-dropdown-chevron);
    border-bottom: 2px solid var(--bill-dropdown-chevron);
    transform: translateY(-50%) rotate(45deg);
    pointer-events: none;
    opacity: 0.88;
}

#bill-form .bill-product-menu {
    position: absolute;
    top: calc(100% + 2px);
    left: 0;
    right: 0;
    max-height: 220px;
    overflow-y: auto;
    background: var(--bill-dropdown-menu-bg);
    border: 1px solid var(--bill-dropdown-border);
    border-radius: var(--radius-sm);
    box-shadow: var(--bill-dropdown-shadow-menu);
    z-index: 9999;
}

#bill-form .bill-product-menu.hidden {
    display: none;
}

#bill-form .bill-product-option {
    display: block;
    width: 100%;
    border: 0;
    border-bottom: 1px solid var(--bill-dropdown-menu-divider);
    background: var(--bill-dropdown-menu-bg);
    color: var(--color-text);
    text-align: left;
    padding: 8px 10px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: background 0.12s ease;
}

#bill-form .bill-product-option:last-child {
    border-bottom: 0;
}

#bill-form .bill-product-option:hover,
#bill-form .bill-product-option.is-selected {
    background: var(--bill-dropdown-option-hover);
}

#bill-form .bill-customer-search {
    position: relative;
    width: 100%;
}

#bill-form .bill-customer-native-select {
    position: absolute;
    opacity: 0;
    pointer-events: none;
    width: 0;
    height: 0;
}

#bill-form .bill-customer-search-input {
    width: 100%;
    min-height: 34px;
    padding: 6px 10px;
    border: 1px solid var(--bill-dropdown-border);
    border-radius: var(--radius-sm);
    background: var(--bill-dropdown-surface);
    color: var(--color-text);
    font-size: 0.85rem;
    box-shadow: var(--bill-dropdown-shadow);
    transition: background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

#bill-form .bill-customer-search-input:hover {
    background: var(--bill-dropdown-surface-hover);
    border-color: var(--bill-dropdown-border-hover);
}

#bill-form .bill-customer-search-input:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: var(--bill-dropdown-shadow), 0 0 0 2px rgba(124, 58, 237, 0.22);
    background: var(--bill-dropdown-surface-open);
}

#bill-form .bill-customer-search-menu {
    position: absolute;
    top: calc(100% + 2px);
    left: 0;
    right: 0;
    max-height: 220px;
    overflow-y: auto;
    background: var(--bill-dropdown-menu-bg);
    border: 1px solid var(--bill-dropdown-border);
    border-radius: var(--radius-sm);
    box-shadow: var(--bill-dropdown-shadow-menu);
    z-index: 9999;
}

#bill-form .bill-customer-search-menu.hidden {
    display: none;
}

#bill-form .bill-customer-search-option {
    display: block;
    width: 100%;
    border: 0;
    border-bottom: 1px solid var(--bill-dropdown-menu-divider);
    background: var(--bill-dropdown-menu-bg);
    color: var(--color-text);
    text-align: left;
    padding: 8px 10px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: background 0.12s ease;
}

#bill-form .bill-customer-search-option:last-child {
    border-bottom: 0;
}

#bill-form .bill-customer-search-option:hover,
#bill-form .bill-customer-search-option.is-selected {
    background: var(--bill-dropdown-option-hover);
}

#bill-form .bill-customer-search-empty {
    padding: 8px 10px;
    color: var(--color-text-muted);
    font-size: 0.82rem;
}

#bill-form .bill-col-packed {
    width: 4.35rem;
    min-width: 4.35rem;
    max-width: 4.35rem;
    vertical-align: middle;
    padding-left: 8px;
    padding-right: 8px;
    box-sizing: border-box;
    text-align: center;
}

#bill-form .bill-from-finished-cb {
    width: 1.1rem;
    height: 1.1rem;
    cursor: pointer;
    display: block;
    margin-left: auto;
    margin-right: auto;
}

#bill-form .bill-line-desc-cell .bill-catalog-wrap {
    width: 100%;
    min-width: 0;
    box-sizing: border-box;
}

/* Same chevron as .bill-product-trigger; native select arrow hidden for identical look */
#bill-form .bill-line-desc-cell .bill-finished-wrap {
    width: 100%;
    min-width: 0;
    box-sizing: border-box;
    position: relative;
}

/* Chevron comes from .bill-product-trigger::after once JS builds the custom dropdown */
#bill-form .bill-finished-wrap:not(:has(.bill-product-dropdown))::after {
    content: "";
    position: absolute;
    right: 10px;
    top: 50%;
    width: 7px;
    height: 7px;
    border-right: 2px solid var(--bill-dropdown-chevron);
    border-bottom: 2px solid var(--bill-dropdown-chevron);
    transform: translateY(-50%) rotate(45deg);
    pointer-events: none;
    opacity: 0.88;
}

#bill-form .bill-finished-select {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    min-height: 34px;
    padding: 6px 1.75rem;
    font-size: 0.85rem;
    line-height: 1.35;
    text-align: left;
    text-align-last: left;
    -moz-text-align-last: left;
    border: 1px solid var(--bill-dropdown-border);
    border-radius: var(--radius-sm);
    background: var(--bill-dropdown-surface);
    color: var(--color-text);
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    box-shadow: var(--bill-dropdown-shadow);
    transition: background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

#bill-form .bill-finished-select:hover:not(:disabled) {
    background: var(--bill-dropdown-surface-hover);
    border-color: var(--bill-dropdown-border-hover);
}

#bill-form .bill-finished-select:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: var(--bill-dropdown-shadow), 0 0 0 2px rgba(124, 58, 237, 0.22);
}

#bill-form .bill-finished-select:disabled {
    opacity: 0.55;
    cursor: not-allowed;
    background: var(--color-card);
    border-color: var(--color-border);
    box-shadow: none;
}

#bill-form .bill-finished-select::-ms-expand {
    display: none;
}

.bill-totals-section {
    padding: 20px;
    background: var(--color-card);
    border-radius: var(--radius-lg);
    border: 1px solid var(--color-border);
    box-shadow: var(--shadow-soft);
}

.bill-totals-section .form-grid {
    margin-bottom: 12px;
}

.customer-preview {
    font-size: 0.85rem;
    color: var(--color-text-muted);
    margin-top: 8px;
}

.small-note {
    font-size: 0.8rem;
    color: var(--color-text-muted);
    margin: 12px 0 0 0;
    line-height: 1.4;
}

/* ========== BILL VIEW (History detail) ========== */
.bill-view {
    background: var(--color-card);
    padding: 24px;
    border-radius: var(--radius-lg);
    border: 1px solid var(--color-border);
    box-shadow: var(--shadow-soft);
}

.bill-view h3 {
    margin: 20px 0 12px 0;
    font-size: 1rem;
    color: var(--color-text);
}

.bill-view h3:first-child {
    margin-top: 0;
}

.bill-view p {
    margin: 6px 0;
    font-size: 0.9rem;
}

.bill-view-summary {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 20px;
    margin-bottom: 8px;
}

.bill-view-summary-card {
    flex: 1 1 320px;
}

.bill-view-summary-card.bill-info {
    margin-left: auto;
    padding-left: 20px;
}

.bill-view-summary-card h3 {
    margin-top: 0;
}

/* ========== INVOICE (screen UI only; print unchanged) ========== */
@media screen {
    .invoice-print-wrapper {
        padding: 20px;
        max-width: 900px;
        margin: 0 auto;
    }

    /* Show original + duplicate(s) on screen so layout matches print */
    .history-bill-print-wrapper .bill-preview-copy,
    .history-bill-print-wrapper .bill-preview-original {
        display: block;
    }

    .history-bill-print-wrapper.invoice-a5 .invoice-sheet {
        height: 200mm;
        min-height: 200mm;
    }

    .history-bill-print-wrapper .invoice-title-top-row {
        display: grid;
        grid-template-columns: 1fr auto 1fr;
        align-items: start;
        column-gap: 8px;
        width: 100%;
    }

    .history-bill-print-wrapper .invoice-title-left-meta {
        text-align: left;
        font-size: 0.78rem;
        line-height: 1.25;
        margin: 0;
        min-width: 0;
    }

    .history-bill-print-wrapper .invoice-title-center-tagline {
        justify-self: center;
        text-align: center;
        font-size: 0.9rem;
        font-weight: 700;
        line-height: 1.25;
        white-space: nowrap;
        font-family: "Nirmala UI", "Latha", "Vijaya", "Noto Sans Tamil", sans-serif;
    }

    .history-bill-print-wrapper .invoice-title-top-row > .invoice-print-meta {
        justify-self: end;
        text-align: right;
        min-width: 0;
    }

    .history-bill-print-wrapper .invoice-meta-block {
        border: 0 !important;
    }

    .history-bill-print-wrapper .invoice-meta-table td {
        border: 0 !important;
    }

    .history-bill-print-wrapper .invoice-footer-note {
        border: 0 !important;
    }

    .history-bill-print-wrapper .invoice-signature-section {
        border-bottom: 0 !important;
    }

    .history-bill-print-wrapper .amount-chargeable-line {
        white-space: nowrap;
    }

    .history-bill-print-wrapper .bill-header-label {
        display: inline-block;
        min-width: 64px;
        white-space: nowrap;
    }

    .history-bill-print-wrapper .bill-meta-label {
        display: inline-block;
        min-width: 48px;
        white-space: nowrap;
    }

    .history-bill-print-wrapper .invoice-meta-table td {
        white-space: nowrap;
    }

    .history-bill-print-wrapper .history-bill-bottom-join-line {
        border-top: 0;
        height: 0;
    }

    .history-bill-print-wrapper .invoice-company-text > .invoice-company-name {
        margin-bottom: 1em;
    }

    .history-bill-print-wrapper .invoice-items-table tfoot tr.invoice-summary-row td:nth-child(4) {
        text-align: center !important;
    }

    .invoice-print-wrapper button,
    .invoice-print-wrapper .btn {
        margin-bottom: 16px;
    }

    .invoice-copy {
        page-break-after: always;
        border-bottom: 1px dashed var(--color-text-muted);
        margin-bottom: 16px;
        padding-bottom: 16px;
    }

    .copy-label {
        text-align: right;
        font-weight: 700;
        margin-bottom: 6px;
        font-size: 14px;
        color: var(--color-text);
    }

    .invoice-header,
    .invoice-details-table,
    .invoice-items-table,
    .invoice-footer {
        width: 100%;
        border-collapse: collapse;
    }

    .invoice-brand {
        display: flex;
        align-items: flex-start;
        gap: 10px;
    }

    .invoice-logo {
        width: 64px;
        height: 64px;
        object-fit: contain;
        border: 1px solid var(--color-border);
        border-radius: var(--radius-sm);
        background: #fff;
    }

    .invoice-items-table th,
    .invoice-items-table td {
        border: 1px solid var(--color-text);
        padding: 4px 6px;
        font-size: 10px;
    }

    .history-bill-print-wrapper.invoice-a5 .invoice-items-table th,
    .history-bill-print-wrapper.invoice-a5 .invoice-items-table td {
        font-size: 11px;
    }

    .invoice-footer td {
        padding: 6px;
    }

    .invoice-a5 .invoice-sheet {
        background: #fff;
        border: 0;
        margin-bottom: 14px;
        padding: 0;
    }

    .invoice-a5 .invoice-title-block,
    .invoice-a5 .invoice-header-grid,
    .invoice-a5 .invoice-buyer-block,
    .invoice-a5 .invoice-items-grow,
    .invoice-a5 .invoice-items-table,
    .invoice-a5 .invoice-bank-section,
    .invoice-a5 .invoice-signature-section,
    .invoice-a5 .invoice-footer-note {
        width: 100%;
    }

    .invoice-a5 .invoice-print-meta {
        text-align: right;
        font-size: 0.78rem;
        line-height: 1.25;
        margin-bottom: 4px;
    }

    .invoice-a5 .invoice-print-meta strong {
        font-weight: 700;
    }

    .invoice-a5 .invoice-items-table {
        table-layout: fixed;
    }

    /* Match print.css history bill column widths on screen (History → Print preview) */
    .history-bill-print-wrapper.invoice-a5 .invoice-items-table .col-desc { width: 42%; }
    .history-bill-print-wrapper.invoice-a5 .invoice-items-table .col-qty { width: 13%; }
    .history-bill-print-wrapper.invoice-a5 .invoice-items-table .col-per { width: 13%; }

    .invoice-a5 .text-right {
        text-align: right;
    }

    .invoice-a5 .text-center {
        text-align: center;
    }
}

/* ========== UTILITY ========== */
.hidden {
    display: none !important;
}

/* Form grid 3-column on wide screens */
@media (min-width: 1200px) {
    .form-grid.form-grid-3 {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}
