:root {
    --primary-color: #025102;
    --primary-dark: #013b01;
    --primary-light: #e6f0e6;
    --accent-color: #b8860b;
    --text-color: #1f2a1f;
    --text-muted: #5c6b5c;
    --border-color: #dbe3db;
    --bg-color: #f4f7f4;
    --card-bg: #ffffff;
    --danger-color: #b3261e;
    --success-color: #1e7a34;
    --info-color: #1565a3;
    --sidebar-width: 250px;
    --radius: 8px;
    --font: 'Segoe UI', Roboto, Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: var(--font);
    background: var(--bg-color);
    color: var(--text-color);
    font-size: 14px;
    /* Casual deterrent only, applied app-wide per request - see assets/js/site-security.js
       for what this can and can't actually do. Form fields are explicitly exempted below
       so staff can still type into and select text within them normally. */
    -webkit-user-select: none;
    user-select: none;
}
body input, body textarea, body select {
    -webkit-user-select: text;
    user-select: text;
}

a { color: var(--primary-color); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Layout ---------- */
.app-shell { display: flex; min-height: 100vh; }

.app-sidebar {
    width: var(--sidebar-width);
    background: var(--primary-dark);
    color: #fff;
    flex-shrink: 0;
    transition: margin-left .2s ease;
}
.sidebar-brand {
    display: flex; align-items: center; gap: .6rem;
    padding: 1.1rem 1rem; font-weight: 600; font-size: 1.05rem;
    border-bottom: 1px solid rgba(255,255,255,.15);
}
.brand-mark {
    background: var(--accent-color); color: #fff; width: 32px; height: 32px;
    display: flex; align-items: center; justify-content: center; border-radius: 6px; font-weight: 700;
}
.sidebar-nav { display: flex; flex-direction: column; padding: .75rem 0; }
.sidebar-nav a {
    color: #dce8dc; padding: .55rem 1.1rem; display: block;
}
.sidebar-nav a:hover, .sidebar-nav a.active { background: var(--primary-color); color: #fff; text-decoration: none; }
.nav-group-title {
    color: #9db89d; text-transform: uppercase; font-size: .7rem; letter-spacing: .05em;
    padding: .9rem 1.1rem .25rem;
}

.app-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.app-topbar {
    background: var(--card-bg); border-bottom: 1px solid var(--border-color);
    padding: .8rem 1.25rem; display: flex; align-items: center; gap: 1rem;
}
.topbar-title { margin: 0; font-size: 1.15rem; flex: 1; }
.topbar-user { display: flex; align-items: center; gap: .9rem; color: var(--text-muted); }
.topbar-bell { position: relative; display: flex; align-items: center; color: var(--text-muted); }
.topbar-bell:hover { color: var(--primary-color); }
.topbar-bell-badge {
    position: absolute; top: -7px; right: -9px; background: var(--danger-color); color: #fff;
    font-size: .65rem; font-weight: 700; line-height: 1; padding: .2rem .35rem; border-radius: 999px;
    min-width: 1.1rem; text-align: center;
}
.sidebar-toggle { display: none; background: none; border: none; font-size: 1.3rem; cursor: pointer; }

.app-content { padding: 1.25rem; flex: 1; }
.app-footer-credit {
    text-align: center; padding: .9rem 1rem; color: var(--text-muted); font-size: .78rem;
    border-top: 1px solid var(--border-color); background: var(--card-bg);
}
.app-footer-credit strong { color: var(--primary-dark); }

/* ---------- Cards / stats ---------- */
.card {
    background: var(--card-bg); border: 1px solid var(--border-color); border-radius: var(--radius);
    padding: 1.25rem; margin-bottom: 1.25rem;
}
.stat-grid {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 1rem; margin-bottom: 1.5rem;
}
.stat-card {
    background: var(--card-bg); border: 1px solid var(--border-color); border-left: 4px solid var(--primary-color);
    border-radius: var(--radius); padding: 1rem; display: flex; flex-direction: column; gap: .35rem;
}
.stat-label { color: var(--text-muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; }
.stat-value { font-size: 1.5rem; font-weight: 700; color: var(--primary-dark); }
.stat-value-sub { display: block; font-size: .8rem; font-weight: 600; color: var(--text-muted); margin-top: .1rem; }

/* Utility: right-align a numeric column's header and cells in a plain report table. */
.text-right { text-align: right; }

/* ---------- Dashboard ---------- */
.dash-welcome { display: flex; justify-content: space-between; align-items: flex-end; margin-bottom: 1.25rem; }
.dash-welcome-title { margin: 0; font-size: 1.4rem; color: var(--primary-dark); }
.dash-welcome-sub { margin: .2rem 0 0; color: var(--text-muted); font-size: .88rem; }

.dash-quick-actions { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: .9rem; margin-bottom: 1.5rem; }
.dash-quick-tile {
    display: flex; align-items: center; gap: .75rem; background: var(--primary-color); color: #fff;
    border-radius: var(--radius); padding: 1rem 1.1rem; font-weight: 600; font-size: .92rem; transition: transform .12s ease, background .12s ease;
}
.dash-quick-tile:hover { background: var(--primary-dark); text-decoration: none; transform: translateY(-1px); }
.dash-quick-tile-secondary { background: var(--card-bg); color: var(--primary-dark); border: 1px solid var(--border-color); }
.dash-quick-tile-secondary:hover { background: var(--primary-light); }
.dash-quick-icon { display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.dash-quick-icon svg { width: 22px; height: 22px; }

.dash-panel-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 1.25rem; margin-bottom: 1.25rem; }
.dash-chart-card { margin-bottom: 0; }
.dash-chart-card h2 { margin: 0 0 .5rem; font-size: 1.02rem; color: var(--primary-dark); }
.dash-chart-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: .5rem; }
.dash-chart-header h2 { margin: 0; }
.dash-year-filter select { padding: .3rem .5rem; font-size: .8rem; width: auto; }
.dash-chart-svg { width: 100%; height: auto; display: block; }
.dash-chart-caption { color: var(--text-muted); font-size: .76rem; margin: .6rem 0 0; }

.dash-donut-wrap { display: flex; align-items: center; gap: 1.25rem; flex-wrap: wrap; }
.dash-donut-svg { width: 140px; height: 140px; flex-shrink: 0; }
.dash-legend { display: flex; flex-direction: column; gap: .4rem; font-size: .84rem; }
.dash-legend-item { display: flex; align-items: center; gap: .5rem; }
.dash-legend-swatch { width: 11px; height: 11px; border-radius: 3px; display: inline-block; flex-shrink: 0; }
.dash-legend-pct { color: var(--text-muted); font-size: .78rem; }

.dash-bank-bars { display: flex; flex-direction: column; gap: .6rem; }
.dash-bank-row { display: grid; grid-template-columns: 110px 1fr 28px; align-items: center; gap: .6rem; font-size: .82rem; }
.dash-bank-name { color: var(--text-color); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dash-bank-bar-track { background: var(--primary-light); border-radius: 999px; height: 10px; overflow: hidden; }
.dash-bank-bar-fill { background: var(--primary-color); height: 100%; border-radius: 999px; }
.dash-bank-count { text-align: right; font-weight: 700; color: var(--primary-dark); }

/* ---------- Forms ---------- */
form label { display: block; margin: .6rem 0 .25rem; font-weight: 600; font-size: .85rem; }
input[type=text], input[type=password], input[type=number], input[type=date],
input[type=email], input[type=tel], select, textarea {
    width: 100%; padding: .55rem .7rem; border: 1px solid var(--border-color); border-radius: 6px;
    font-family: var(--font); font-size: .9rem; background: #fff; color: var(--text-color);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary-color); outline-offset: 1px; }
.field-error { color: var(--danger-color); font-size: .78rem; margin-top: .2rem; }

.form-row { display: flex; gap: 1rem; flex-wrap: wrap; }
.form-row > div { flex: 1; min-width: 200px; }

/* ---------- Buttons ---------- */
.btn {
    display: inline-block; padding: .55rem 1.1rem; border-radius: 6px; border: none;
    background: var(--primary-color); color: #fff; cursor: pointer; font-size: .88rem; font-weight: 600;
}
.btn:hover { background: var(--primary-dark); text-decoration: none; }
.btn:disabled { opacity: .6; cursor: not-allowed; }
.btn-secondary { background: #6b7d6b; }
.btn-danger { background: var(--danger-color); }
.btn-small { padding: .3rem .65rem; font-size: .78rem; }
.btn-block { width: 100%; margin-top: 1rem; }
.btn-link { background: none; color: var(--primary-color); padding: 0; font-weight: 600; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; background: var(--card-bg); }
thead th {
    background: var(--primary-light); text-align: left; padding: .6rem .75rem; font-size: .78rem;
    text-transform: uppercase; letter-spacing: .03em; color: var(--primary-dark); border-bottom: 2px solid var(--border-color);
}
tbody td { padding: .6rem .75rem; border-bottom: 1px solid var(--border-color); }
tbody tr:hover { background: #fafcfa; }
.badge { padding: .2rem .55rem; border-radius: 999px; font-size: .72rem; font-weight: 600; }
.badge-active { background: #e2f3e5; color: var(--success-color); }
.badge-inactive { background: #f5e2e0; color: var(--danger-color); }
.badge-info { background: #fbf1e0; color: #8a5a00; }

/* ---------- Alerts / toasts ---------- */
.alert { padding: .7rem 1rem; border-radius: 6px; margin-bottom: 1rem; font-size: .88rem; }
.alert-success { background: #e2f3e5; color: var(--success-color); border: 1px solid #b7ddbe; }
.alert-error { background: #fbe6e4; color: var(--danger-color); border: 1px solid #edb9b4; }
.alert-info { background: #e3f0fb; color: var(--info-color); border: 1px solid #b9d7ee; }

#toastHost { position: fixed; top: 1rem; right: 1rem; z-index: 999; display: flex; flex-direction: column; gap: .5rem; }
.toast { background: var(--text-color); color: #fff; padding: .6rem 1rem; border-radius: 6px; opacity: .95; }

/* ---------- Modal ---------- */
.modal-backdrop {
    display: none; position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 900;
    align-items: center; justify-content: center;
}
.modal-backdrop.open { display: flex; }
.modal-box {
    background: #fff; border-radius: var(--radius); width: 100%; max-width: 520px; max-height: 90vh; overflow-y: auto;
    padding: 1.25rem 1.5rem;
}
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: .5rem; }
.modal-close { background: none; border: none; font-size: 1.2rem; cursor: pointer; }

/* ---------- Filters ---------- */
.filter-bar { display: flex; gap: .75rem; flex-wrap: wrap; align-items: flex-end; margin-bottom: 1rem; }
.filter-bar > div { min-width: 160px; }
.filter-bar label { margin: 0 0 .25rem; }

/* ---------- Pagination ---------- */
.pagination { display: flex; gap: .35rem; margin-top: 1rem; list-style: none; padding: 0; }
.pagination a, .pagination span {
    padding: .35rem .7rem; border: 1px solid var(--border-color); border-radius: 6px; color: var(--text-color);
}
.pagination .active { background: var(--primary-color); color: #fff; border-color: var(--primary-color); }

/* ---------- Login ---------- */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: var(--primary-dark); }
.login-card { background: #fff; padding: 2rem; border-radius: var(--radius); width: 100%; max-width: 380px; }
.login-logo { display: flex; justify-content: center; margin-bottom: 1rem; }
.login-logo img { max-height: 80px; max-width: 100%; object-fit: contain; }
.login-title { text-align: center; color: var(--primary-dark); margin-bottom: 1rem; }

/* ---------- Autocomplete ---------- */
.autocomplete-wrap { position: relative; }
.autocomplete-list {
    position: absolute; top: 100%; left: 0; right: 0; z-index: 60;
    background: #fff; border: 1px solid var(--border-color); border-radius: 6px;
    max-height: 260px; overflow-y: auto; box-shadow: 0 6px 16px rgba(0,0,0,.1); margin-top: 2px;
}
.autocomplete-item { padding: .5rem .75rem; cursor: pointer; border-bottom: 1px solid var(--border-color); font-size: .88rem; }
.autocomplete-item:last-child { border-bottom: none; }
.autocomplete-item:hover { background: var(--primary-light); }
.autocomplete-item small { display: block; color: var(--text-muted); font-size: .74rem; margin-top: .1rem; }
.autocomplete-empty { padding: .6rem .75rem; color: var(--text-muted); font-size: .85rem; }

/* ---------- Items table (valuation forms) ---------- */
.items-table input, .items-table select {
    padding: .4rem .5rem; font-size: .85rem; min-width: 70px;
}
.items-table th, .items-table td { padding: .4rem .5rem; }
.items-table .col-name { min-width: 150px; }
.items-table input[readonly] { background: #f4f7f4; color: var(--text-muted); }
.items-table .btn-remove-row { background: var(--danger-color); color: #fff; border: none; border-radius: 4px; padding: .3rem .55rem; cursor: pointer; }
.field-invalid { border-color: var(--danger-color) !important; background: #fbe6e4 !important; }
.row-has-error td { background: #fdf0ef; }
.row-error-msg td { border-bottom: 1px solid var(--border-color); padding-top: 0; }
.row-error-msg .field-error { margin: 0 0 .5rem; }
.formula-note { font-size: .8rem; color: var(--text-muted); margin: .4rem 0 .8rem; }

/* ---------- Numeric alignment (add/edit/view/print) ---------- */
/* Every numeric input (weights, rates, amounts, pieces, sanction, fees, rate of pure gold, etc.)
   uses type="number", so this single rule covers all of them across every form. */
input[type="number"] { text-align: right; }
/* Computed/readonly fields in the dynamic items tables are type="text" (not "number") since they're
   never submitted for parsing as a number - align them to match. */
.js-net, .js-mamt, .js-bamt, .js-amt { text-align: right; }
/* Sr column in the dynamic add/edit items table (plain text, not an input). */
.items-table tbody td:first-child { text-align: right; }
/* Column headers in the dynamic add/edit items table: everything except Hu Id (2) and
   Item Name (3) is a numeric column, so its header right-aligns to match the data beneath it. */
.items-table thead th:not(:nth-child(2)):not(:nth-child(3)) { text-align: right; }
/* Read-only items tables (view.php / print.php for both valuation types) share this class.
   Column 2 (Hu Id) and column 3 (Item Name) are text; everything else (Sr, Pieces, weights,
   purity/carat, rates, amounts) is numeric and right-aligned. */
.items-view-table td:not(:nth-child(2)):not(:nth-child(3)) { text-align: right; }
.items-view-table thead th:not(:nth-child(2)):not(:nth-child(3)) { text-align: right; }
/* Print tables (bank_gold_loan/print.php, form_08a/print.php) omit the Hu Id column entirely,
   so only column 2 (Item Name) is text - everything else is numeric and right-aligned. */
.items-print-table td:not(:nth-child(2)) { text-align: right; }
.items-print-table thead th:not(:nth-child(2)) { text-align: right; }
/* The footer row's first cell uses colspan="2" (spanning Sr + Item), which shifts the Pieces/Nos.
   total to be the DOM's 2nd <td> - incorrectly matching the ":not(:nth-child(2))" exclusion meant
   for the Item text column above. This override restores right-alignment for that total cell. */
.items-print-table tfoot td:nth-child(2) { text-align: right; }
/* Every column total in the footer of every jewellery items table is right-aligned; only the
   leading "Total Items" label cell (the one that spans several columns) stays left. */
.items-table tfoot td, .items-view-table tfoot td, .items-print-table tfoot td { text-align: right; white-space: nowrap; }
.items-table tfoot td:first-child, .items-view-table tfoot td:first-child, .items-print-table tfoot td:first-child { text-align: left; }

.totals-row { display: flex; gap: 2rem; flex-wrap: wrap; margin-top: 1rem; padding-top: 1rem; border-top: 1px solid var(--border-color); }
.totals-row .total-item { display: flex; flex-direction: column; gap: .2rem; }
.totals-row .total-label { font-size: .78rem; color: var(--text-muted); text-transform: uppercase; }
.totals-row .total-value { font-size: 1.1rem; font-weight: 700; color: var(--primary-dark); }

/* ---------- View (read-only valuation) ---------- */
.view-section-title {
    font-size: .85rem; text-transform: uppercase; letter-spacing: .04em; color: var(--primary-dark);
    border-bottom: 2px solid var(--primary-light); padding-bottom: .3rem; margin: 1.25rem 0 .75rem;
}
.view-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: .8rem 1.5rem; }
.view-field-label { font-size: .74rem; color: var(--text-muted); text-transform: uppercase; }
.view-field-value { font-size: .92rem; font-weight: 600; }

/* ---------- Icon buttons ---------- */
.icon-btn {
    display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 30px;
    border-radius: 6px; border: 1px solid var(--border-color); background: #fff; cursor: pointer;
    color: var(--text-color); vertical-align: middle;
}
.icon-btn svg { width: 16px; height: 16px; }
.icon-btn:hover { background: var(--primary-light); text-decoration: none; }
.icon-btn.icon-danger:hover { background: #fbe6e4; color: var(--danger-color); border-color: #edb9b4; }
.icon-btn-group { display: inline-flex; gap: .35rem; }

/* Default size for any inline icon_svg() output used outside .icon-btn (e.g. inside a normal
   .btn like "Print" or "+ New Valuation"). Without this, an un-sized inline <svg> renders at
   the browser default (huge). .icon-btn svg above is more specific and still wins at 16px there. */
.icon-inline { width: 18px; height: 18px; vertical-align: -4px; margin-right: 2px; }

/* ---------- Document upload / camera capture ---------- */
.doc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 1rem; margin: .75rem 0 1.5rem; }
.doc-card { border: 1px solid var(--border-color); border-radius: var(--radius); padding: .75rem; position: relative; background: #fff; }
.doc-thumb { display: block; width: 100%; height: 130px; object-fit: cover; border-radius: 6px; background: var(--primary-light); }
.doc-thumb-icon { display: flex; align-items: center; justify-content: center; color: var(--primary-dark); }
.doc-thumb-icon svg { width: 48px; height: 48px; }
.doc-meta { margin-top: .5rem; }
.doc-name { font-weight: 600; font-size: .85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.doc-sub { font-size: .75rem; color: var(--text-muted); }
.doc-card form { position: absolute; top: .5rem; right: .5rem; }

.doc-method-tabs { display: flex; gap: .5rem; margin: .5rem 0 1rem; }
.doc-pane { margin-bottom: 1rem; }
.doc-preview { margin-top: .6rem; }
.doc-preview-img { max-width: 240px; max-height: 240px; border-radius: 6px; border: 1px solid var(--border-color); }
.camera-video { width: 100%; max-width: 420px; border-radius: 6px; border: 1px solid var(--border-color); background: #000; display: block; }
.doc-camera-controls { display: flex; gap: .5rem; margin-top: .6rem; }

/* ---------- Settings branding preview ---------- */
.branding-preview { display: flex; align-items: center; gap: .75rem; margin: .5rem 0; }
.branding-preview img { max-width: 100px; max-height: 70px; object-fit: contain; border: 1px solid var(--border-color); border-radius: 6px; padding: .25rem; background: #fff; }
.branding-remove { font-size: .78rem; color: var(--danger-color); display: flex; align-items: center; gap: .35rem; }

/* ---------- Print / letterhead ---------- */
.letterhead-flex {
    display: flex; align-items: center; justify-content: space-between; gap: 1rem;
    border-bottom: 2px solid var(--primary-dark); padding-bottom: .75rem; margin-bottom: 1rem;
}
.letterhead-flex .letterhead-logo,
.letterhead-flex .letterhead-qr {
    flex: 0 0 auto; width: 100px; display: flex; align-items: center;
}
.letterhead-flex .letterhead-logo { justify-content: flex-start; }
.letterhead-flex .letterhead-qr { justify-content: flex-end; }
.letterhead-flex .letterhead-logo img,
.letterhead-flex .letterhead-qr img { max-width: 90px; max-height: 80px; object-fit: contain; }
.letterhead-flex .letterhead-center { flex: 1; text-align: center; }
.letterhead-flex .company-name { font-size: 1.3rem; font-weight: 700; color: var(--primary-dark); }
.letterhead-flex .company-details { font-size: .82rem; color: var(--text-muted); }

/* Blank space reserved at the top of a "Without Letterpad" printout, for offices that print
   onto pre-printed letterhead stationery and need the top of the page left clear. */
.print-blank-space { height: 6cm; }
.print-title { text-align: center; font-size: 1.05rem; font-weight: 700; margin: 1rem 0; text-transform: uppercase; letter-spacing: .04em; }
.signature-line { margin-top: 3rem; display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; }
.signature-line .valuer-name-block { font-weight: 600; }
.signature-line .signature-block { text-align: right; }
.signature-line .sig-space { height: 50px; }
.print-toolbar { margin-bottom: 1rem; display: flex; gap: .5rem; }

/* ---------- Responsive ---------- */
@media (max-width: 880px) {
    .app-sidebar { position: fixed; left: 0; top: 0; bottom: 0; z-index: 800; margin-left: calc(-1 * var(--sidebar-width)); }
    .app-sidebar.open { margin-left: 0; }
    .sidebar-toggle { display: block; }
}

/* Bank Gold Loan print signature row */
.bgl-sign-row { margin-top: 3rem; display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; }
.bgl-sign-col { width: 45%; }
.bgl-sign-left { text-align: left; }
.bgl-sign-right { text-align: right; }
.bgl-sign-name { font-weight: 600; margin-bottom: 40px; }
.bgl-sign-label { border-top: 1px solid #000; padding-top: .2rem; }
