/* ============================================================
   Mandi Management System - Desktop App Stylesheet
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&family=Noto+Sans+Arabic:wght@300;400;500;600;700;800&display=swap');

*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --primary:       #1a6b3a;
    --primary-dark:  #134d2b;
    --primary-light: #e8f5ee;
    --accent:        #f0a500;
    --accent-dark:   #c98900;
    --danger:        #dc2626;
    --danger-light:  #fee2e2;
    --warning:       #d97706;
    --warning-light: #fef3c7;
    --success:       #059669;
    --success-light: #d1fae5;
    --text:          #1f2937;
    --text-muted:    #6b7280;
    --text-light:    #9ca3af;
    --border:        #e5e7eb;
    --bg:            #f3f4f6;
    --white:         #ffffff;
    --shadow-sm:     0 1px 3px rgba(0,0,0,0.08);
    --shadow:        0 4px 12px rgba(0,0,0,0.10);
    --shadow-lg:     0 10px 30px rgba(0,0,0,0.14);
    --radius:        12px;
    --radius-sm:     8px;
    --radius-lg:     20px;
    --sidebar-w:     240px;
    --header-h:      64px;
}

html, body {
    height: 100%;
    font-family: 'Inter', 'Noto Sans Arabic', sans-serif;
    font-size: 14px;
    color: var(--text);
    background: var(--bg);
    overflow: hidden;
    user-select: none;
    -webkit-user-select: none;
}

/* ── SCROLLBAR ── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-light); }

/* ============================================================
   LICENSE SCREEN
   ============================================================ */
#license-screen {
    position: fixed;
    inset: 0;
    background: linear-gradient(135deg, #0f4024 0%, #1a6b3a 50%, #256b50 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    transition: opacity 0.4s ease;
}

#license-screen.hidden {
    opacity: 0;
    pointer-events: none;
}

.license-box {
    background: var(--white);
    border-radius: var(--radius-lg);
    padding: 48px 44px;
    width: 420px;
    max-width: 90vw;
    box-shadow: var(--shadow-lg);
    text-align: center;
}

.license-logo {
    width: 72px;
    height: 72px;
    background: var(--primary-light);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 20px;
    font-size: 32px;
}

.license-box h1 {
    font-size: 22px;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 4px;
}

.license-box .subtitle {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 32px;
}

.license-input-wrap {
    position: relative;
    margin-bottom: 16px;
}

.license-input-wrap input {
    width: 100%;
    padding: 14px 18px;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    font-size: 14px;
    font-family: 'Inter', monospace;
    letter-spacing: 0.04em;
    text-align: center;
    outline: none;
    transition: border-color 0.2s;
    color: var(--text);
    background: var(--bg);
}

.license-input-wrap input:focus {
    border-color: var(--primary);
    background: var(--white);
}

.license-input-wrap input.error {
    border-color: var(--danger);
    background: var(--danger-light);
}

.license-input-wrap input.success {
    border-color: var(--success);
    background: var(--success-light);
}

#license-status {
    min-height: 20px;
    font-size: 13px;
    margin-bottom: 16px;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    transition: all 0.2s;
}

#license-status.error {
    background: var(--danger-light);
    color: var(--danger);
}

#license-status.warning {
    background: var(--warning-light);
    color: var(--warning);
}

#license-status.success {
    background: var(--success-light);
    color: var(--success);
}

#license-status.info {
    background: var(--primary-light);
    color: var(--primary);
}

#license-status:empty {
    padding: 0;
    background: transparent;
}

.license-developer {
    margin: -2px 0 14px;
    color: var(--text-muted);
    line-height: 1.25;
}

.license-developer span {
    display: block;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0;
}

.license-developer strong {
    display: block;
    margin-top: 3px;
    color: var(--primary);
    font-size: 13px;
    font-weight: 700;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 24px;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    outline: none;
    transition: all 0.2s;
    text-decoration: none;
    white-space: nowrap;
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--primary);
    color: var(--white);
    width: 100%;
}

.btn-primary:hover:not(:disabled) {
    background: var(--primary-dark);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(26, 107, 58, 0.35);
}

.btn-primary:active:not(:disabled) {
    transform: translateY(0);
}

.btn-secondary {
    background: var(--bg);
    color: var(--text);
    border: 1.5px solid var(--border);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--border);
}

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

.btn-danger:hover:not(:disabled) {
    background: #b91c1c;
}

.btn-accent {
    background: var(--accent);
    color: var(--white);
}

.btn-accent:hover:not(:disabled) {
    background: var(--accent-dark);
}

.btn-icon {
    padding: 8px;
    border-radius: var(--radius-sm);
    background: transparent;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
}

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

.btn-sm {
    padding: 7px 14px;
    font-size: 13px;
}

.spinner {
    width: 18px;
    height: 18px;
    border: 2px solid rgba(255,255,255,0.4);
    border-top-color: var(--white);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    display: inline-block;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.license-footer {
    margin-top: 24px;
    font-size: 12px;
    color: var(--text-light);
}

/* ============================================================
   MAIN APP LAYOUT
   ============================================================ */
#app {
    display: flex;
    height: 100vh;
    overflow: hidden;
    opacity: 0;
    transition: opacity 0.4s ease;
}

#app.visible {
    opacity: 1;
}

/* ── SIDEBAR ── */
.sidebar {
    width: var(--sidebar-w);
    background: var(--primary-dark);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    height: 100vh;
    overflow: hidden;
}

.sidebar-brand {
    padding: 20px 20px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.sidebar-brand-icon {
    width: 38px;
    height: 38px;
    background: var(--accent);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
}

.sidebar-brand-text h2 {
    font-size: 17px;
    font-weight: 700;
    color: var(--white);
    line-height: 1.2;
}

.sidebar-brand-text span {
    font-size: 12px;
    color: rgba(255,255,255,0.5);
}

.sidebar-nav {
    padding: 16px 12px;
    flex: 1;
    overflow-y: auto;
}

.nav-section-label {
    font-size: 12.5px;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: rgba(255,255,255,0.35);
    padding: 4px 8px 8px;
    margin-top: 8px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    color: rgba(255,255,255,0.65);
    font-size: 15.5px;
    font-weight: 500;
    transition: all 0.15s;
    margin-bottom: 2px;
    border: none;
    background: transparent;
    width: 100%;
    text-align: left;
}

.nav-item svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.nav-item:hover {
    background: rgba(255,255,255,0.08);
    color: var(--white);
}

.nav-item.active {
    background: rgba(255,255,255,0.14);
    color: var(--white);
    font-weight: 600;
}

.nav-item.active .nav-dot {
    display: block;
}

.nav-dot {
    width: 6px;
    height: 6px;
    background: var(--accent);
    border-radius: 50%;
    margin-left: auto;
    display: none;
}

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

.user-badge {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: rgba(255,255,255,0.07);
    border-radius: var(--radius-sm);
}

.user-avatar {
    width: 32px;
    height: 32px;
    background: var(--accent);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 700;
    color: var(--primary-dark);
    flex-shrink: 0;
}

.user-info { flex: 1; min-width: 0; }
.user-info .user-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--white);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.user-info .user-plan {
    font-size: 11px;
    color: rgba(255,255,255,0.45);
}

.offline-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 11px;
    font-weight: 600;
    padding: 3px 8px;
    border-radius: 99px;
    background: var(--warning-light);
    color: var(--warning);
    margin-top: 6px;
    margin-left: 12px;
}

.offline-badge.online {
    background: var(--success-light);
    color: var(--success);
}

.offline-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
}

/* ── MAIN CONTENT ── */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.topbar {
    height: var(--header-h);
    background: var(--white);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 24px;
    gap: 16px;
    flex-shrink: 0;
}

.topbar-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--text);
    flex: 1;
}

.topbar-date {
    font-size: 13px;
    color: var(--text-muted);
}

.content-area {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
}

/* ── PAGES ── */
.page { display: none; }
.page.active { display: block; }

/* ── CARDS ── */
.card {
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}

.card-header {
    padding: 18px 20px 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.card-title {
    font-size: 15px;
    font-weight: 700;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 8px;
}

.card-title svg {
    width: 18px;
    height: 18px;
    color: var(--primary);
}

.card-body { padding: 20px; }

/* ── STAT CARDS ── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px 20px;
    box-shadow: var(--shadow-sm);
}

.stat-card-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.stat-card-icon {
    width: 42px;
    height: 42px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
}

.stat-card-icon.green { background: var(--primary-light); }
.stat-card-icon.amber { background: var(--warning-light); }
.stat-card-icon.blue  { background: #dbeafe; }
.stat-card-icon.purple{ background: #ede9fe; }

.stat-card-change {
    font-size: 12px;
    font-weight: 600;
    padding: 3px 8px;
    border-radius: 99px;
}
.stat-card-change.up   { background: var(--success-light); color: var(--success); }
.stat-card-change.down { background: var(--danger-light); color: var(--danger); }

.stat-card-label {
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 500;
    margin-bottom: 4px;
}

.stat-card-value {
    font-size: 26px;
    font-weight: 800;
    color: var(--text);
    line-height: 1.1;
}

/* ── FORM ── */
.form-grid {
    display: grid;
    gap: 16px;
}

.form-grid-2 { grid-template-columns: 1fr 1fr; }
.form-grid-3 { grid-template-columns: 1fr 1fr 1fr; }
.form-grid-4 { grid-template-columns: 1fr 1fr 1fr 1fr; }

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

.form-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    display: flex;
    align-items: center;
    gap: 6px;
}

.opt {
    font-size: 10px;
    font-weight: 500;
    color: var(--text-light);
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 1px 5px;
    text-transform: none;
    letter-spacing: 0;
    line-height: 1.4;
    flex-shrink: 0;
}

.form-control {
    padding: 10px 14px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-family: 'Inter', sans-serif;
    color: var(--text);
    background: var(--bg);
    outline: none;
    transition: border-color 0.2s, background 0.2s;
    width: 100%;
}

.form-control:focus {
    border-color: var(--primary);
    background: var(--white);
}

.form-control.large {
    font-size: 18px;
    font-weight: 700;
    padding: 12px 16px;
}

select.form-control {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
}

.calc-result {
    background: var(--primary-light);
    border: 1.5px solid var(--primary);
    border-radius: var(--radius-sm);
    padding: 12px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.calc-result-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--primary);
}

.calc-result-value {
    font-size: 22px;
    font-weight: 800;
    color: var(--primary);
}

.custom-fields-panel {
    margin-top: 14px;
    padding: 14px;
    border: 1.5px dashed var(--border);
    border-radius: var(--radius-sm);
    background: #fbfdfb;
}

.custom-fields-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
}

.custom-fields-title {
    font-size: 13px;
    font-weight: 700;
    color: var(--text);
}

.custom-fields-subtitle {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 2px;
}

.custom-fields-list {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    margin-top: 12px;
}

.custom-field-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 150px auto;
    gap: 8px;
    align-items: end;
}

.custom-field-remove {
    width: 38px;
    height: 38px;
    padding: 0;
    justify-content: center;
}

.custom-fields-empty {
    grid-column: 1 / -1;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-size: 12px;
    background: var(--white);
}

/* ── TABLE ── */
.invoice-items-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 12px;
}

.invoice-items-list {
    display: flex;
    flex-direction: column;
    gap: 7px;
    margin-top: 10px;
}

.invoice-item-row {
    display: grid;
    grid-template-columns: minmax(130px, 1fr) 90px 115px 125px 34px;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg);
    font-size: 12px;
}

.invoice-item-row strong { font-size: 13px; }
.invoice-item-amount { text-align: right; font-weight: 700; }
.invoice-item-remove {
    width: 30px;
    height: 30px;
    border: 0;
    background: transparent;
    color: var(--danger);
    cursor: pointer;
    font-size: 17px;
}

@media (max-width: 720px) {
    .invoice-items-actions { align-items: flex-start; flex-direction: column; }
    .invoice-item-row { grid-template-columns: 1fr 1fr; }
    .invoice-item-row strong { grid-column: 1 / -1; }
    .invoice-item-amount { text-align: left; }
}

.table-wrap {
    overflow-x: auto;
    overflow-y: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13.5px;
}

thead th {
    background: var(--bg);
    padding: 10px 14px;
    text-align: left;
    font-size: 11px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
    position: sticky;
    top: 0;
    z-index: 1;
}

tbody tr {
    border-bottom: 1px solid var(--border);
    transition: background 0.12s;
}

tbody tr:hover { background: var(--bg); }
tbody tr:last-child { border-bottom: none; }

tbody td {
    padding: 11px 14px;
    color: var(--text);
    white-space: nowrap;
}

.cell-muted { color: var(--text-muted); font-size: 12px; }

/* ── BADGE ── */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 9px;
    border-radius: 99px;
    font-size: 11px;
    font-weight: 600;
}

.badge-green  { background: var(--success-light); color: var(--success); }
.badge-amber  { background: var(--warning-light); color: var(--warning); }
.badge-red    { background: var(--danger-light); color: var(--danger); }
.badge-blue   { background: #dbeafe; color: #1d4ed8; }
.badge-orange { background: #ffedd5; color: #c2410c; }
.badge-gray   { background: var(--border); color: var(--text-muted); }

/* ── EMPTY STATE ── */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 48px 24px;
    color: var(--text-muted);
    gap: 12px;
}

.empty-state svg {
    width: 48px;
    height: 48px;
    color: var(--border);
}

.empty-state p {
    font-size: 14px;
    font-weight: 500;
}

/* ── SEARCH & FILTERS ── */
.filter-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.search-wrap {
    position: relative;
    flex: 1;
    min-width: 180px;
}

.search-wrap svg {
    position: absolute;
    left: 11px;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    color: var(--text-muted);
    pointer-events: none;
}

.search-input {
    width: 100%;
    padding: 9px 14px 9px 34px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 13.5px;
    font-family: 'Inter', sans-serif;
    outline: none;
    background: var(--bg);
    color: var(--text);
    transition: border-color 0.2s;
}

.search-input:focus {
    border-color: var(--primary);
    background: var(--white);
}

/* ── TOAST NOTIFICATION ── */
.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 99999;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toast {
    background: var(--text);
    color: var(--white);
    padding: 12px 18px;
    border-radius: var(--radius);
    font-size: 13.5px;
    font-weight: 500;
    max-width: 340px;
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    gap: 10px;
    animation: slideUp 0.3s ease forwards;
}

.toast.success { background: var(--success); }
.toast.error   { background: var(--danger); }
.toast.warning { background: var(--warning); }
.toast svg { width: 18px; height: 18px; flex-shrink: 0; }

@keyframes slideUp {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: translateY(0); }
}

@keyframes fadeOut {
    from { opacity: 1; }
    to   { opacity: 0; transform: translateY(-8px); }
}

/* ── MODAL ── */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(2px);
}

.modal-backdrop.hidden { display: none; }

.modal {
    background: var(--white);
    border-radius: var(--radius-lg);
    width: 500px;
    max-width: 92vw;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    animation: zoomIn 0.2s ease forwards;
}

@keyframes zoomIn {
    from { opacity: 0; transform: scale(0.95); }
    to   { opacity: 1; transform: scale(1); }
}

.modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--text);
}

.modal-body { padding: 24px; }

.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

/* ── RECEIPT PREVIEW ── */
.receipt-box {
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    padding: 20px;
    background: #fffbf0;
    font-family: 'Courier New', monospace;
    font-size: 13px;
    line-height: 1.6;
    white-space: pre-wrap;
}

/* ── SYNC INDICATOR ── */
.sync-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--text-muted);
    padding: 4px 10px;
    background: var(--bg);
    border-radius: 99px;
    border: 1px solid var(--border);
}

.sync-indicator.syncing .sync-icon {
    animation: spin 1s linear infinite;
}

.sync-icon { width: 14px; height: 14px; }

/* ── SUMMARY SECTION ── */
.summary-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 24px;
}

/* ── MISC ── */
.divider { height: 1px; background: var(--border); margin: 16px 0; }

.text-right { text-align: right; }
.text-center { text-align: center; }
.font-bold { font-weight: 700; }
.font-mono { font-family: 'Courier New', monospace; }
.text-green { color: var(--success); }
.text-red { color: var(--danger); }
.text-muted { color: var(--text-muted); }
.text-sm { font-size: 12px; }
.text-lg { font-size: 16px; }
.text-xl { font-size: 20px; }
.mt-4 { margin-top: 16px; }
.mb-4 { margin-bottom: 16px; }
.gap-2 { gap: 8px; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }

/* ── RESPONSIVE ADJUSTMENTS ── */
@media (max-width: 900px) {
    .stats-grid { grid-template-columns: 1fr 1fr; }
    .form-grid-4 { grid-template-columns: 1fr 1fr; }
}

/* ── STAT CHIPS (topbar) ── */
.stat-chip {
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 5px 12px;
    font-size: 12px;
    color: var(--text-muted);
    white-space: nowrap;
}
.stat-chip-label { font-weight: 600; color: var(--text-muted); }
.stat-chip-value { font-weight: 700; color: var(--text); }
.stat-chip-money { font-weight: 700; color: var(--primary); border-color: var(--primary-light); background: var(--primary-bg); }
.sync-chip {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 11px;
    color: var(--text-muted);
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 5px 10px;
    white-space: nowrap;
}

/* ── PAYMENT TYPE SELECTOR ── */
.payment-type-group {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}
.payment-type-option {
    position: relative;
    cursor: pointer;
}
.payment-type-option input[type="radio"] {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}
.payment-type-card {
    border: 2px solid var(--border);
    border-radius: 10px;
    padding: 14px 12px;
    text-align: center;
    background: var(--bg);
    transition: all 0.15s;
    cursor: pointer;
}
.payment-type-card:hover {
    border-color: var(--primary-light);
    background: var(--primary-bg);
}
.payment-type-option input:checked + .payment-type-card {
    border-color: var(--primary);
    background: var(--primary-bg);
    box-shadow: 0 0 0 3px rgba(21,128,61,0.1);
}
.payment-type-icon { font-size: 22px; margin-bottom: 6px; }
.payment-type-label { font-weight: 700; font-size: 13px; color: var(--text); }
.payment-type-sub { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

/* ── CUSTOMER DETAIL MODAL ── */
.detail-stat-value { font-size: 20px; font-weight: 800; color: var(--text); }

/* ── BADGE VARIANTS ── */
.badge-green { background: #dcfce7; color: #15803d; }
.badge-red   { background: #fee2e2; color: #dc2626; }
.badge-amber { background: #fef9c3; color: #92400e; }
.badge-blue  { background: #dbeafe; color: #1d4ed8; }

/* ── BTN ACCENT (for payment button in detail modal) ── */
.btn-accent {
    background: var(--primary-bg);
    color: var(--primary);
    border: 1.5px solid var(--primary-light);
    border-radius: 8px;
    padding: 8px 16px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
}
.btn-accent:hover {
    background: var(--primary-light);
    color: var(--white);
}

/* ── LEDGER TABLE (in customer detail modal) ── */
.ledger-entry-row { border-bottom: 1px solid var(--border); }

.ledger-detail-modal {
    width: min(1440px, 98vw);
    max-width: 98vw;
}

.ledger-table-wrap {
    max-height: calc(90vh - 320px);
    min-height: 240px;
    overflow: auto;
}

.ledger-detail-table {
    min-width: 1380px;
    table-layout: auto;
}

.ledger-detail-table th,
.ledger-detail-table td {
    border-right: 1px solid var(--border);
    vertical-align: top;
}

.ledger-detail-table th:last-child,
.ledger-detail-table td:last-child { border-right: 0; }
.ledger-detail-table td { white-space: nowrap; }
.ledger-detail-table td:nth-child(3) { min-width: 150px; white-space: normal; }
.ledger-detail-table td:nth-child(12) { min-width: 145px; }
.ledger-cell-line + .ledger-cell-line { border-top: 1px solid var(--border); margin-top: 5px; padding-top: 5px; }
.ledger-type-cell { font-weight: 700; color: var(--primary); }
.ledger-note { margin-top: 5px; font-size: 11px; color: var(--text-muted); white-space: normal; }

.farmer-goods-status { padding: 12px 16px; background: #f7f9fb; border-bottom: 1px solid var(--border); }
.farmer-goods-heading { margin-bottom: 8px; color: var(--primary); font-size: 12px; font-weight: 800; text-transform: uppercase; }
.farmer-goods-cards { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.farmer-goods-card { min-height: 58px; padding: 9px 11px; background: #fff; border: 1px solid #dbe3ea; border-left: 4px solid #64748b; border-radius: 5px; }
.farmer-goods-card span { display: block; margin-bottom: 4px; color: var(--text-muted); font-size: 10px; font-weight: 700; text-transform: uppercase; }
.farmer-goods-card strong { display: block; color: #1f2937; font-size: 13px; line-height: 1.35; overflow-wrap: anywhere; }
.farmer-goods-card.status-blue { border-left-color: #2563eb; }
.farmer-goods-card.status-orange { border-left-color: #ea580c; }
.farmer-goods-card.status-green { border-left-color: #059669; }
.farmer-goods-table-wrap { margin-top: 8px; max-height: 150px; border: 1px solid #dbe3ea; background: #fff; }
.farmer-goods-table { min-width: 680px; font-size: 12px; }
.farmer-goods-table th { padding: 7px 10px; font-size: 10px; }
.farmer-goods-table td { padding: 7px 10px; border-right: 1px solid var(--border); }
.farmer-goods-table td:last-child { border-right: 0; }

@media (max-width: 720px) {
    .farmer-goods-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* ── BADGE EXTRA VARIANTS ── */
.badge-orange { background: #ffedd5; color: #c2410c; }
.badge-purple { background: #ede9fe; color: #6d28d9; }

/* ── ENTRY TYPE SELECTOR ── */
.entry-section-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--primary);
    margin-bottom: 10px;
    padding: 6px 0 6px 2px;
    border-bottom: 2px solid var(--primary-light);
}

.entry-type-card {
    display: flex;
    align-items: center;
    gap: 14px;
    width: 100%;
    background: var(--white);
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 14px 16px;
    margin-bottom: 10px;
    cursor: pointer;
    text-align: left;
    transition: all 0.15s;
    box-shadow: var(--shadow-sm);
}
.entry-type-card:hover {
    border-color: var(--primary);
    box-shadow: 0 4px 14px rgba(26,107,58,0.12);
    transform: translateY(-1px);
}
.entry-type-icon {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
}
.entry-type-body { flex: 1; min-width: 0; }
.entry-type-name {
    font-size: 14px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 2px;
}
.entry-type-desc {
    font-size: 11px;
    color: var(--text-muted);
    line-height: 1.4;
}
.entry-urdu {
    font-size: 13px;
    color: var(--text-muted);
    font-weight: 500;
    margin-left: 6px;
    direction: rtl;
}

/* ── ENTRY FORM HEADER ── */
.entry-form-header {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 12px 16px;
    background: var(--white);
    border-radius: var(--radius-sm);
    border: 1.5px solid var(--border);
    margin-bottom: 4px;
    box-shadow: var(--shadow-sm);
}

/* ── TEXT COLORS ── */
.text-orange-600 { color: #ea580c; }
.text-red-600    { color: #dc2626; }
.text-green-600  { color: #16a34a; }

/* ── KHATA MODE TOGGLE BUTTONS ── */
.khata-mode-btn {
    padding: 7px 16px;
    border-radius: 8px;
    border: 1.5px solid var(--border);
    background: var(--bg);
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
    font-family: inherit;
}
.khata-mode-btn:hover {
    border-color: var(--primary-light);
    color: var(--primary);
}
.khata-mode-btn.active {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
}

/* ── RECEIPT PAPER (in modal preview) ── */
.rp-paper {
    background: white;
    max-width: 560px;
    margin: 20px auto;
    border-radius: 16px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.10);
    overflow: hidden;
}
.rp-header {
    text-align: center;
    padding: 22px 22px 14px;
    background: linear-gradient(135deg, #0f4024, #1a6b3a);
    color: white;
}
.rp-logo { font-size: 30px; margin-bottom: 5px; }
.rp-mandi { font-size: 18px; font-weight: 800; letter-spacing: 0.05em; }
.rp-tagline { font-size: 11px; opacity: 0.7; margin-top: 2px; }
.rp-dots { color: rgba(255,255,255,0.25); margin: 10px 0 0; letter-spacing: 2px; font-size: 11px; }
.rp-type-badge {
    display: inline-block;
    padding: 5px 14px;
    border-radius: 99px;
    font-size: 12px;
    font-weight: 700;
    border: 1.5px solid;
    margin-top: 10px;
}
.rp-customer {
    text-align: center;
    padding: 13px 22px;
    border-bottom: 1px solid #f3f4f6;
}
.rp-customer-label {
    font-size: 13px;
    font-weight: 700;
    color: #374151;
    margin-bottom: 5px;
}
.rp-customer-name {
    font-size: 15px;
    font-weight: 500;
    color: #9ca3af;
}
.rp-section { padding: 12px 22px; }
.rp-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 5px 0;
    font-size: 13px;
    border-bottom: 1px solid #f9fafb;
}
.rp-row:last-child { border-bottom: none; }
.rp-row-subtotal {
    border-top: 1px solid #e5e7eb !important;
    padding-top: 8px !important;
    margin-top: 4px;
}
.rp-label { color: #6b7280; font-size: 12.5px; }
.rp-value { font-weight: 600; color: #1f2937; }
.rp-divider { height: 1px; background: #f3f4f6; margin: 0 22px; }
.rp-grand {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 11px 22px;
    background: #1a6b3a;
    color: white;
    font-size: 14px;
    font-weight: 800;
    margin-top: 4px;
}
.rp-notes {
    padding: 9px 22px;
    background: #fffbf0;
    font-size: 12px;
    color: #6b7280;
    border-top: 1px solid #fde68a;
}
.rp-footer {
    text-align: center;
    padding: 12px 22px;
    background: #f9fafb;
    border-top: 1px solid #f3f4f6;
}
.rp-powered { font-size: 11px; color: #9ca3af; font-weight: 500; }

.rp-entry-boxes {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
}
.rp-entry-boxes .rp-row {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: center;
    gap: 4px;
    min-height: 58px;
    padding: 9px 11px;
    border: 1px solid #dbe3ea;
    border-radius: 5px;
    background: #fff;
}
.rp-entry-boxes .rp-label { font-size: 10px; font-weight: 700; text-transform: uppercase; }
.rp-entry-boxes .rp-value { font-size: 13px; overflow-wrap: anywhere; }
.rp-entry-boxes .rp-grand,
.rp-entry-boxes .rp-items-table-wrap { grid-column: 1 / -1; }
.rp-items-table-wrap { overflow-x: auto; border: 1px solid #dbe3ea; border-radius: 5px; }
.rp-items-table { width: 100%; min-width: 500px; border-collapse: collapse; font-size: 11px; }
.rp-items-table th { padding: 7px; text-align: left; background: #f3f4f6; border-bottom: 1px solid #dbe3ea; }
.rp-items-table td { padding: 7px; border-right: 1px solid #e5e7eb; border-bottom: 1px solid #e5e7eb; }
.rp-items-table th:last-child,
.rp-items-table td:last-child { border-right: 0; }

@media (max-width: 520px) {
    .rp-paper { margin: 10px auto; border-radius: 8px; }
    .rp-entry-boxes { grid-template-columns: repeat(2, minmax(0, 1fr)); padding: 10px 12px; gap: 6px; }
}

/* ── RECEIPT MODAL BG ── */
#receipt-content-area {
    padding-bottom: 12px;
}

/* ── FONT-SEMIBOLD util ── */
.font-semibold { font-weight: 600; }

/* ── RECEIPT CUSTOMER SUB-INFO (phone, address) ── */
.rp-customer-sub {
    font-size: 12px;
    color: #6b7280;
    margin-top: 3px;
}

/* ============================================================
   Stock & Check Pages
   ============================================================ */
.stock-stats, .check-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 16px; margin-bottom: 20px; }
.stock-stats .stat-card, .check-stats .stat-card { padding: 16px; border-radius: var(--radius); background: var(--white); border: 1px solid var(--border); box-shadow: var(--shadow-sm); text-align: center; }
.stock-stats .stat-card .stat-value, .check-stats .stat-card .stat-value { font-size: 28px; font-weight: 700; color: var(--primary); }
.stock-stats .stat-card .stat-label, .check-stats .stat-card .stat-label { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; margin-top: 4px; }
.stat-card.stat-warning .stat-value { color: var(--warning); }
.stat-card.stat-danger .stat-value  { color: var(--danger); }
.stat-card.stat-success .stat-value { color: var(--success); }

/* Stock qty indicators */
.stock-qty-zero { color: var(--danger); font-weight: 600; }
.stock-qty-low  { color: var(--warning); font-weight: 600; }
.stock-qty-ok   { color: var(--success); font-weight: 600; }

/* Check status badges */
.badge-pending   { background: #fef3c7; color: #92400e; }
.badge-cleared   { background: #d1fae5; color: #065f46; }
.badge-bounced   { background: #fee2e2; color: #991b1b; }
.badge-cancelled { background: #f3f4f6; color: #6b7280; }
.badge-received  { background: #dbeafe; color: #1d4ed8; }
.badge-issued    { background: #fce7f3; color: #9d174d; }

/* PIN modal */
.pin-inputs { display: flex; gap: 12px; justify-content: center; margin: 24px 0; }
.pin-digit {
    width: 52px; height: 58px; text-align: center; font-size: 24px;
    font-weight: 700; border: 2px solid var(--border); border-radius: var(--radius-sm);
    background: var(--white); transition: border-color 0.2s; font-family: 'Inter', sans-serif;
}
.pin-digit:focus { border-color: var(--primary); outline: none; box-shadow: 0 0 0 3px rgba(26,107,58,0.15); }
.shake { animation: shake 0.5s; }
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20%, 60% { transform: translateX(-8px); }
    40%, 80% { transform: translateX(8px); }
}

/* Additional charges in entry form */
.form-section { margin-top: 16px; padding-top: 16px; border-top: 1px dashed var(--border); }
.form-section-title { font-size: 13px; font-weight: 600; text-transform: uppercase; color: var(--text-muted); letter-spacing: 0.5px; margin-bottom: 12px; }

/* Danger outline button */
.btn-danger-outline {
    background: transparent; color: var(--danger); border: 1.5px solid var(--danger);
    padding: 6px 12px; font-size: 13px;
}
.btn-danger-outline:hover { background: var(--danger-light); }

/* Helper text */
.helper-text { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.helper-text.warning { color: var(--warning); }
.helper-text.danger  { color: var(--danger); }

/* Unit badge */
.unit-badge { display: inline-block; padding: 2px 8px; background: var(--primary-light); color: var(--primary); border-radius: 4px; font-size: 12px; font-weight: 600; margin-left: 4px; }

/* ── SEARCHABLE SELECT ── */
.searchable-select-wrap {
    position: relative;
    user-select: none;
}

.searchable-select-input {
    width: 100%;
    cursor: text;
}

.searchable-select-dropdown {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background: var(--white);
    border: 1.5px solid var(--primary);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
    z-index: 9000;
    max-height: 220px;
    overflow-y: auto;
}

.ss-item {
    padding: 9px 14px;
    font-size: 13.5px;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    transition: background 0.1s;
    display: flex;
    align-items: center;
    gap: 8px;
}

.ss-item:last-child { border-bottom: none; }
.ss-item:hover, .ss-item.highlighted { background: var(--primary-light); color: var(--primary); }

.ss-empty {
    padding: 10px 14px;
    font-size: 13px;
    color: var(--text-muted);
    text-align: center;
}

.ss-role-badge {
    font-size: 10px;
    font-weight: 600;
    padding: 1px 6px;
    border-radius: 99px;
    background: var(--border);
    color: var(--text-muted);
    margin-left: auto;
}
.ss-role-farmer { background: #e8f5ee; color: #1a6b3a; }
.ss-role-buyer  { background: #dbeafe; color: #1d4ed8; }

/* ── ROZNAMCHA TABS ─────────────────────────────────────────── */
.roz-tab { transition: all 0.2s; }
.roz-tab.active {
    background: var(--primary) !important;
    color: #fff !important;
    border-color: var(--primary) !important;
}

@media print {
    .sidebar, .topbar, .btn-row, .roz-tab, button, select, input[type="date"] { display: none !important; }
    .page { display: block !important; }
    #page-roznamcha { display: block !important; }
}

/* Ensure Customer Detail/Ledger page occupies full width */
#page-customer-detail {
    width: 100% !important;
    max-width: 100% !important;
}
#page-customer-detail .card {
    width: 100% !important;
    max-width: 100% !important;
}

/* Language Switching hiding logic */
body.lang-en .lang-sd, body.lang-en .lang-ur { display: none !important; }
body.lang-sd .lang-en, body.lang-sd .lang-ur { display: none !important; }
body.lang-ur .lang-en, body.lang-ur .lang-sd { display: none !important; }
