/* =================================================================
   Modern entry-form layer (master/detail data-entry pages).
   Used by Sale, Purchase, Damage, Opening Stock. Keeps every legacy
   element ID — these classes are additive, not a replacement.
   ================================================================= */

:root {
    --ef-bg:        #f6f7fb;
    --ef-surface:   #ffffff;
    --ef-border:    #e5e7eb;
    --ef-border-soft: #eef0f5;
    --ef-text:      #0f172a;
    --ef-text-muted:#64748b;
    --ef-accent:    #6366f1;     /* default tone, overridden per page */
    --ef-accent-soft: rgba(99,102,241,.10);
    --ef-radius:    14px;
    --ef-radius-sm: 10px;
    --ef-shadow:    0 1px 2px rgba(15,23,42,.04), 0 4px 12px rgba(15,23,42,.04);
    --ef-shadow-lg: 0 1px 2px rgba(15,23,42,.04), 0 12px 32px rgba(15,23,42,.06);
}

/* Tone variants — set on the .entry-page wrapper */
.entry-page--sale     { --ef-accent: #0ea5e9; --ef-accent-soft: rgba(14,165,233,.10); }
.entry-page--purchase { --ef-accent: #f97316; --ef-accent-soft: rgba(249,115,22,.10); }
.entry-page--damage   { --ef-accent: #ef4444; --ef-accent-soft: rgba(239,68,68,.10); }
.entry-page--opening  { --ef-accent: #6366f1; --ef-accent-soft: rgba(99,102,241,.10); }

.entry-page {
    max-width: 1280px;
    margin: 0 auto;
    padding: 8px 4px 80px;
    color: var(--ef-text);
}

/* ---------- Page header ---------- */
.entry-page-head {
    display: flex; align-items: center; justify-content: space-between;
    gap: 16px;
    background: linear-gradient(135deg, var(--ef-accent-soft) 0%, transparent 80%);
    border: 1px solid var(--ef-border-soft);
    border-radius: var(--ef-radius);
    padding: 18px 22px;
    margin-bottom: 18px;
}
.entry-page-title {
    margin: 0;
    font-size: 1.25rem; font-weight: 700; letter-spacing: -.01em;
    color: var(--ef-text);
    display: flex; align-items: center; gap: 12px;
}
.entry-page-title .ef-icon {
    width: 36px; height: 36px;
    background: var(--ef-accent);
    color: #fff;
    border-radius: 10px;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 1rem;
    box-shadow: 0 4px 10px var(--ef-accent-soft);
}
.entry-page-sub {
    margin: 4px 0 0 48px;
    font-size: .85rem; color: var(--ef-text-muted);
}
.entry-page-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ---------- Section cards ---------- */
.entry-section {
    background: var(--ef-surface);
    border: 1px solid var(--ef-border);
    border-radius: var(--ef-radius);
    box-shadow: var(--ef-shadow);
    margin-bottom: 16px;
    overflow: hidden;
}
.entry-section-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 14px 20px;
    border-bottom: 1px solid var(--ef-border-soft);
    background: linear-gradient(180deg, #fafbff 0%, #fff 100%);
    gap: 12px;
}
.entry-section-title {
    margin: 0;
    font-size: .95rem; font-weight: 600; color: var(--ef-text);
    display: flex; align-items: center; gap: 8px;
}
.entry-section-title i {
    color: var(--ef-accent);
    background: var(--ef-accent-soft);
    width: 26px; height: 26px;
    border-radius: 8px;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: .78rem;
}
.entry-section-sub {
    margin: 0;
    font-size: .76rem; color: var(--ef-text-muted);
    text-transform: uppercase; letter-spacing: .4px; font-weight: 600;
}
.entry-section-body { padding: 20px 22px 22px; }

/* ---------- Form grid ---------- */
.ef-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px 24px;
}
.ef-grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.ef-grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 768px) {
    .ef-grid, .ef-grid-3, .ef-grid-4 { grid-template-columns: 1fr; }
}
.ef-col-span-2 { grid-column: span 2; }
.ef-col-span-full { grid-column: 1 / -1; }

/* ---------- Field ---------- */
.ef-field { display: flex; flex-direction: column; gap: 6px; }
.ef-field-label {
    font-size: .78rem; font-weight: 600;
    color: var(--ef-text);
    letter-spacing: .1px;
    margin: 0;
}
.ef-field-label .ef-required { color: #ef4444; margin-left: 2px; }
.ef-field-hint {
    font-size: .72rem; color: var(--ef-text-muted); margin-top: 2px;
}
.ef-field .form-control,
.ef-field select.form-control,
.ef-field input.form-control {
    border: 1px solid var(--ef-border);
    border-radius: var(--ef-radius-sm);
    padding: 9px 12px;
    font-size: .88rem;
    background: #fff;
    color: var(--ef-text);
    transition: border-color .15s ease, box-shadow .15s ease, background-color .15s ease;
    box-shadow: 0 1px 2px rgba(15,23,42,.02);
}
.ef-field .form-control:focus {
    border-color: var(--ef-accent);
    box-shadow: 0 0 0 3px var(--ef-accent-soft);
    outline: none;
}
.ef-field .form-control[readonly] { background: #f8fafc; color: #475569; cursor: not-allowed; }
.ef-field .form-control[disabled] { background: #f1f5f9; color: #94a3b8; }

/* Inline icon for fields (optional .ef-input-with-icon wrapper) */
.ef-input-with-icon { position: relative; }
.ef-input-with-icon > i {
    position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
    color: var(--ef-text-muted); font-size: .85rem; pointer-events: none;
}
.ef-input-with-icon input.form-control { padding-left: 34px; }

/* ---------- Line-item table ---------- */
.ef-line-table-wrap { overflow-x: auto; padding: 0 6px; }
.ef-line-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    margin: 0;
    font-size: .85rem;
}
.ef-line-table thead tr {
    background: linear-gradient(180deg, var(--ef-accent-soft) 0%, transparent 100%);
}
.ef-line-table thead th {
    text-align: left;
    font-size: .72rem; font-weight: 700; letter-spacing: .4px;
    text-transform: uppercase;
    color: var(--ef-accent);
    padding: 10px 10px;
    border-bottom: 2px solid var(--ef-accent-soft);
}
.ef-line-table thead th.text-end { text-align: right; }
.ef-line-table thead th.text-center { text-align: center; }
.ef-line-table tbody tr {
    transition: background-color .12s ease;
}
.ef-line-table tbody tr:hover { background: #fafbff; }
.ef-line-table tbody td {
    padding: 8px 10px;
    border-bottom: 1px solid var(--ef-border-soft);
    vertical-align: middle;
}
.ef-line-table tbody td.text-end { text-align: right; }
.ef-line-table tbody td.text-center { text-align: center; }
.ef-line-table tbody td input.form-control,
.ef-line-table tbody td select.form-control {
    padding: 6px 10px;
    font-size: .85rem;
    border-radius: 8px;
}
.ef-line-table tbody td input[type=number] { text-align: right; }
.ef-line-table tfoot td { padding: 12px 10px; }

/* Add-row button (modern soft pill) */
.ef-add-row {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 8px 14px;
    background: var(--ef-accent-soft);
    color: var(--ef-accent);
    border: 1px dashed var(--ef-accent);
    border-radius: 999px;
    font-size: .82rem; font-weight: 600;
    cursor: pointer;
    transition: background-color .15s ease, transform .15s ease;
    text-decoration: none;
}
.ef-add-row:hover { background: var(--ef-accent); color: #fff; transform: translateY(-1px); }
.ef-add-row i { font-size: .85rem; }

/* Remove-row button inside table */
.ef-line-remove {
    width: 28px; height: 28px;
    border-radius: 8px;
    display: inline-flex; align-items: center; justify-content: center;
    color: #94a3b8;
    background: transparent;
    border: 1px solid transparent;
    cursor: pointer;
    transition: all .15s ease;
}
.ef-line-remove:hover { color: #ef4444; background: rgba(239,68,68,.08); border-color: rgba(239,68,68,.18); }

/* ---------- Summary panel (for sale / purchase totals) ---------- */
.ef-summary {
    margin-top: 16px;
    margin-left: auto;
    width: 100%;
    max-width: 360px;
    background: linear-gradient(180deg, #fafbff 0%, #fff 100%);
    border: 1px solid var(--ef-border);
    border-radius: var(--ef-radius);
    padding: 14px 18px;
    box-shadow: var(--ef-shadow);
}
.ef-summary-row {
    display: flex; align-items: center; justify-content: space-between;
    padding: 6px 0;
    font-size: .88rem;
    border-bottom: 1px dashed var(--ef-border-soft);
}
.ef-summary-row:last-child { border-bottom: 0; }
.ef-summary-row .ef-summary-label { color: var(--ef-text-muted); font-weight: 500; }
.ef-summary-row .ef-summary-value { font-weight: 600; color: var(--ef-text); }
.ef-summary-row.is-net    .ef-summary-value { font-size: 1.05rem; color: var(--ef-accent); font-weight: 700; }
.ef-summary-row.is-due    .ef-summary-value { color: #dc2626; font-weight: 700; }
.ef-summary-row.is-paid   .ef-summary-value { color: #16a34a; }
.ef-summary-row .ef-summary-input {
    width: 130px;
    text-align: right;
    border: 1px solid var(--ef-border);
    border-radius: 8px;
    padding: 5px 10px;
    font-size: .88rem;
    font-weight: 600;
    background: #fff;
    transition: border-color .15s ease, box-shadow .15s ease;
}
.ef-summary-row .ef-summary-input:focus {
    border-color: var(--ef-accent);
    box-shadow: 0 0 0 3px var(--ef-accent-soft);
    outline: none;
}

/* ---------- Action buttons ---------- */
.ef-btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 9px 18px;
    border: 1px solid transparent;
    border-radius: 10px;
    font-size: .85rem; font-weight: 600;
    cursor: pointer;
    transition: background-color .15s ease, transform .12s ease, box-shadow .15s ease;
    text-decoration: none;
}
.ef-btn-primary {
    background: var(--ef-accent);
    color: #fff;
    box-shadow: 0 6px 14px var(--ef-accent-soft);
}
.ef-btn-primary:hover { transform: translateY(-1px); filter: brightness(1.05); color: #fff; }
.ef-btn-ghost {
    background: #fff;
    color: var(--ef-text);
    border-color: var(--ef-border);
}
.ef-btn-ghost:hover { background: #f8fafc; }
.ef-btn i { font-size: .85rem; }

/* ---------- Footer (sticky save bar — optional) ---------- */
.ef-footer {
    position: sticky; bottom: 8px;
    margin-top: 18px;
    background: rgba(255,255,255,.92);
    backdrop-filter: blur(6px);
    border: 1px solid var(--ef-border);
    border-radius: var(--ef-radius);
    padding: 12px 18px;
    display: flex; align-items: center; justify-content: flex-end; gap: 8px;
    box-shadow: var(--ef-shadow-lg);
    z-index: 5;
}
.ef-footer-meta { margin-right: auto; font-size: .8rem; color: var(--ef-text-muted); }

/* ---------- Select2 v4 polish (matches the modern field look) ---------- */
.ef-field .select2-container--default .select2-selection--single,
.entry-section .select2-container--default .select2-selection--single,
.ef-line-table .select2-container--default .select2-selection--single {
    height: auto;
    min-height: 38px;
    border: 1px solid var(--ef-border);
    border-radius: var(--ef-radius-sm);
    background: #fff;
    box-shadow: 0 1px 2px rgba(15,23,42,.02);
    padding: 4px 6px;
    transition: border-color .15s ease, box-shadow .15s ease;
}
.ef-field .select2-container--default.select2-container--focus .select2-selection--single,
.entry-section .select2-container--default.select2-container--focus .select2-selection--single {
    border-color: var(--ef-accent);
    box-shadow: 0 0 0 3px var(--ef-accent-soft);
}
.ef-field .select2-container--default .select2-selection--single .select2-selection__rendered,
.entry-section .select2-container--default .select2-selection--single .select2-selection__rendered {
    line-height: 28px;
    color: var(--ef-text);
    padding-left: 6px; padding-right: 24px;
}
.ef-field .select2-container--default .select2-selection--single .select2-selection__arrow,
.entry-section .select2-container--default .select2-selection--single .select2-selection__arrow {
    height: 36px;
}
.ef-line-table .select2-container--default .select2-selection--single { min-height: 32px; }
.ef-line-table .select2-container--default .select2-selection--single .select2-selection__rendered { line-height: 24px; font-size: .85rem; }
.ef-line-table .select2-container--default .select2-selection--single .select2-selection__arrow { height: 30px; }
.select2-container--default .select2-results__option--highlighted[aria-selected] {
    background: var(--ef-accent) !important;
}
.select2-container .select2-search--inline .select2-search__field { font-size: .88rem; }

/* ---------- Mobile tweaks ---------- */
@media (max-width: 768px) {
    .entry-page-head { flex-direction: column; align-items: flex-start; }
    .entry-page-actions { width: 100%; }
    .ef-footer { flex-wrap: wrap; }
    .ef-summary { max-width: 100%; }
}
