/* Card Styles - Flat Enterprise Look */
.card {
    background-color: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    margin-bottom: var(--sp-6);
    overflow: hidden;
    transition: var(--transition);
    max-width: 100%; /* Important for mobile */
}

.card-header {
    padding: var(--sp-4) var(--sp-6);
    border-bottom: 1px solid var(--border);
    background-color: var(--card-bg-alt);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.card-title {
    font-size: 1.1em;
    font-weight: 700;
    margin: 0;
    color: var(--primary);
}

.card-body {
    padding: var(--sp-6);
}

/* Button Styles */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: var(--sp-2) var(--sp-6);
    font-family: var(--font-urdu);
    font-weight: 600;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
    border: 1px solid transparent;
    gap: var(--sp-2);
    font-size: 0.95em;
    min-height: 54px;
}

.btn-primary {
    background-color: var(--primary);
    color: var(--text-on-primary);
}

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

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

.btn-accent:hover {
    background-color: #c99839;
}

.btn-outline {
    background-color: transparent;
    border-color: var(--border);
    color: var(--text-muted);
}

.btn-outline:hover {
    border-color: var(--primary);
    color: var(--primary);
}

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

.btn-danger:hover {
    opacity: 0.9;
}

.btn-sm {
    padding: 0 16px;
    font-size: 0.85em;
    min-height: 36px;
}

.btn-lg {
    padding: 12px 32px;
    font-size: 1.1em;
    min-height: 56px;
}

/* Form Controls */
.form-group {
    margin-bottom: var(--sp-4);
}

.form-label {
    display: block;
    margin-bottom: var(--sp-1);
    font-weight: 700;
    color: var(--primary);
    font-size: 0.9em;
}

.form-control {
    width: 100%;
    padding: var(--sp-2) var(--sp-3);
    font-family: var(--font-urdu);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background-color: #fff;
    transition: var(--transition);
    font-size: 1em;
    color: var(--text);
    min-height: 54px;
}

.form-control:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(212, 168, 67, 0.2);
}

.form-control[readonly] {
    background-color: var(--card-bg-alt);
    cursor: not-allowed;
}

/* Number Input Text Align */
input[type="number"] {
    text-align: left;
    direction: ltr; /* Digits are read LTR even in RTL layout */
}

/* Select2 Custom Theme Override - Simplified Placeholder */
.select2-container--default .select2-selection--single {
    height: 54px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
}

.select2-container--default .select2-selection--single .select2-selection__rendered {
    color: var(--text);
    padding-right: var(--sp-3);
    padding-left: 20px;
}

/* Tables */
.table-responsive {
    width: 100%;
    margin-bottom: var(--sp-4);
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    display: block;
    position: relative;
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
}

.table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: var(--sp-4);
    background-color: var(--card-bg);
}

.table th {
    background-color: var(--primary);
    color: var(--text-on-primary);
    text-align: right;
    padding: var(--sp-3) var(--sp-4);
    font-weight: 700;
    white-space: nowrap; /* Prevent headers from wrapping, force table to be wider for scrolling */
    position: sticky;
    top: 0;
}

.table td {
    padding: var(--sp-3) var(--sp-4);
    border-bottom: 1px solid var(--border-light);
}

.table tr:nth-child(even) {
    background-color: var(--card-bg-alt);
}

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

/* Toggle Buttons (Radio Groups) */
.toggle-group {
    display: flex;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.toggle-btn {
    flex: 1;
    text-align: center;
    padding: var(--sp-2) var(--sp-4);
    background-color: #fff;
    cursor: pointer;
    font-weight: 600;
    transition: var(--transition);
    border: none;
}

.toggle-btn.active {
    background-color: var(--primary);
    color: #fff;
}

.toggle-btn:not(:first-child) {
    border-right: 1px solid var(--border);
}

/* Alert Boxes (for Purchase/Sale alerts) */
.alert-box {
    padding: var(--sp-3) var(--sp-4);
    border-radius: var(--radius-sm);
    background-color: var(--accent-light);
    border: 1px solid var(--accent);
    color: var(--primary);
    margin-bottom: var(--sp-4);
    display: none;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}
/* Highlight Field for Focus */
.highlight-field {
    border-color: var(--accent) !important;
    border-width: 2px !important;
    background-color: #fffdf5 !important;
    box-shadow: 0 0 8px rgba(212, 168, 67, 0.2) !important;
}

/* Disabled Permission Styling */
.disabled-permission {
    opacity: 0.5 !important;
    cursor: not-allowed !important;
    pointer-events: none !important;
    filter: grayscale(1);
}

/* Payment Settlement area */
.payment-settlement-block {
    background-color: #fdfdfd;
    padding: var(--sp-6);
    border-radius: var(--radius-md) var(--radius-md) 0 0;
    border: 1px solid var(--border);
    border-bottom: 2px solid var(--primary);
    box-shadow: 0 -5px 15px rgba(0,0,0,0.02);
    margin-top: var(--sp-8);
}

.payment-settlement-block .form-group {
    margin-bottom: 0;
}

.payment-settlement-block .text-sm {
    font-size: 0.9em !important;
    color: var(--primary);
    font-weight: 700;
}

.payment-settlement-block .form-control {
    background-color: #fff;
    border: 1px solid var(--border);
    font-weight: 700;
    height: 42px;
}

#remainingBalance {
    background-color: #f0f7ff;
    color: var(--primary);
}

.select2-sm + .select2-container .select2-selection--single {
    height: 42px !important;
    border: 1px solid var(--border);
}

.select2-sm + .select2-container .select2-selection__rendered {
    line-height: 40px !important;
}

.select2-sm + .select2-container .select2-selection__rendered {
    line-height: 30px !important;
}

.footer-amount-row {
    padding: var(--sp-2) 0;
    border-bottom: 2px solid var(--border-light);
}
@media (max-width: 768px) {
    .card-header {
        flex-direction: column;
        align-items: flex-start;
        gap: var(--sp-2);
    }
    
    .card-body {
        padding: var(--sp-3) !important;
        overflow-x: auto; /* Allow card body to scroll if needed as a fallback */
    }
    
    .table {
        min-width: 650px !important; /* Slightly wider to ensure clarity */
    }
    
    .table th, .table td {
        padding: var(--sp-4) var(--sp-3);
    }
}
/* Modal System */
.modal {
    display: none;
    position: fixed;
    z-index: 9999;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.modal-content {
    background-color: #fff;
    margin: 5% auto;
    padding: 0;
    border-radius: var(--radius-md);
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
    width: 90%;
    max-width: 800px;
    animation: modalScale 0.3s ease-out;
}

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

.modal-header {
    padding: var(--sp-4) var(--sp-6);
    border-bottom: 2px solid var(--primary);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg);
}

.modal-title {
    margin: 0;
    color: var(--primary);
}

.close-modal {
    font-size: 28px;
    font-weight: bold;
    color: var(--text-muted);
    cursor: pointer;
    transition: var(--transition);
}

.close-modal:hover {
    color: var(--danger);
}

.modal-body {
    padding: var(--sp-6);
    max-height: 80vh;
    overflow-y: auto;
}

/* Print Overrides for Modals */
@media print {
    .modal {
        position: relative !important;
        background: none !important;
        display: block !important;
    }
    .modal-content {
        box-shadow: none !important;
        margin: 0 !important;
        width: 100% !important;
    }
    .no-print {
        display: none !important;
    }
}
