/* ---------- Layout ---------- */
body {
    background: #f4f6f9;
    font-family: 'Kantumruy Pro', system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

/* Khmer script needs a little more line height */
html[lang="km"] body {
    line-height: 1.65;
}

.app-wrapper {
    display: flex;
    min-height: 100vh;
}

.app-main {
    flex: 1 1 auto;
    min-width: 0;
    padding: 1rem;
}

@media (min-width: 768px) {
    .sidebar {
        width: 240px;
        flex-shrink: 0;
        position: sticky;
        top: 0;
        height: 100vh;
        overflow-y: auto;
    }
    .app-main {
        padding: 1.5rem 2rem;
    }
}

.sidebar .nav-link {
    border-radius: .375rem;
    margin-bottom: 2px;
}
.sidebar .nav-link:hover {
    color: #fff !important;
    background: rgba(255, 255, 255, .08);
}

.page-title {
    font-size: 1.5rem;
    font-weight: 600;
    margin: 0;
}

.card {
    border: 0;
    box-shadow: 0 1px 3px rgba(0, 0, 0, .08);
}

/* ---------- KPI tiles ---------- */
.kpi .kpi-label {
    font-size: .8rem;
    text-transform: uppercase;
    letter-spacing: .03em;
    color: #6c757d;
}
.kpi .kpi-value {
    font-size: 1.6rem;
    font-weight: 600;
}
.kpi .kpi-icon {
    font-size: 1.8rem;
    opacity: .25;
}

/* ---------- Due date highlighting ---------- */
.due-soon,
tr.due-soon > td {
    background-color: #fdecec !important;
}
.overdue,
tr.overdue > td {
    background-color: #f8d4d4 !important;
}
.legend-swatch {
    display: inline-block;
    width: 14px;
    height: 14px;
    border-radius: 3px;
    vertical-align: -2px;
    border: 1px solid rgba(0, 0, 0, .1);
}

/* ---------- Order form ---------- */
.item-block .card-header {
    background: #f8f9fa;
}
.measure-grid .form-label {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

/* ---------- Measurement display ---------- */
.measure-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: .25rem .75rem;
    font-size: .875rem;
}
.measure-list span {
    color: #6c757d;
}

/* ---------- Order photos ---------- */
/* Board: design + finished buttons */
.photo-slots {
    display: flex;
    gap: .4rem;
}
.photo-slot {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: .15rem;
    width: 62px;
    padding: 0;
    border: 0;
    background: none;
    color: inherit;
    font-size: .7rem;
    line-height: 1.1;
}
.photo-slot-img {
    width: 48px;
    height: 48px;
    border-radius: .375rem;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #fff;
    border: 2px solid #dee2e6;
    color: #adb5bd;
    font-size: 1.1rem;
    transition: border-color .15s, transform .15s;
}
.photo-slot-design .photo-slot-img { border-color: #9ec5fe; }
.photo-slot-finished .photo-slot-img { border-color: #a3cfbb; }
.photo-slot.empty .photo-slot-img {
    border-style: dashed;
    border-color: #ced4da;
}
.photo-slot:hover .photo-slot-img,
.photo-slot:focus-visible .photo-slot-img {
    border-color: #0d6efd;
    color: #0d6efd;
    transform: scale(1.05);
}
.photo-slot-img img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.photo-slot-label {
    white-space: nowrap;
    color: #6c757d;
}
.photo-slot-label b {
    color: #212529;
}
/* List view: one column per photo type */
.photo-cell {
    width: 1%;
}
.photo-cell .photo-slot {
    width: auto;
    margin: 0 auto;
}

/* Photo panel (board window and order page) */
.photo-group {
    height: 100%;
    padding: .75rem;
    border-radius: .5rem;
    background: #f8f9fa;
    border-top: 3px solid #9ec5fe;
}
.photo-group-finished {
    border-top-color: #a3cfbb;
}
.photo-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
    gap: .5rem;
}
.photo-item {
    position: relative;
}
.photo-thumb {
    display: block;
    width: 100%;
    aspect-ratio: 1 / 1;
    padding: 0;
    border: 0;
    border-radius: .375rem;
    overflow: hidden;
    background: #e9ecef;
    cursor: zoom-in;
}
.photo-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform .2s;
}
.photo-thumb {
    position: relative;
}
.photo-thumb:hover img {
    transform: scale(1.05);
}
/* Magnifier: shows the photo opens bigger when clicked */
.photo-zoom {
    position: absolute;
    left: 4px;
    bottom: 4px;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, .55);
    color: #fff;
    font-size: .8rem;
    pointer-events: none;
}
.photo-thumb:hover .photo-zoom {
    background: #0d6efd;
}
.photo-delete-form {
    position: absolute;
    top: 4px;
    right: 4px;
}
.photo-delete {
    width: 28px;
    height: 28px;
    border: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, .9);
    color: #dc3545;
    font-size: .8rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, .25);
}
.photo-empty {
    text-align: center;
    padding: 1.5rem .5rem;
    border: 2px dashed #dee2e6;
    border-radius: .375rem;
    color: #adb5bd;
    font-size: .85rem;
}
.photo-empty .bi {
    font-size: 1.75rem;
}

/* Full-size viewer */
body.photo-viewer-open {
    overflow: hidden;
}
.photo-viewer {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, .92);
    outline: none;
}
.photo-viewer.show {
    display: flex;
}
.photo-viewer .pv-img {
    max-width: 100%;
    max-height: calc(100% - 3.5rem);
    object-fit: contain;
    user-select: none;
}
.photo-viewer .pv-bar {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: .75rem 1rem;
    color: #fff;
    font-size: .875rem;
}
.photo-viewer .pv-open {
    color: #fff;
    font-size: 1.1rem;
}
.photo-viewer .pv-btn {
    position: absolute;
    width: 44px;
    height: 44px;
    border: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, .15);
    color: #fff;
    font-size: 1.25rem;
}
.photo-viewer .pv-btn:hover {
    background: rgba(255, 255, 255, .3);
}
.photo-viewer .pv-close { top: 1rem; right: 1rem; }
.photo-viewer .pv-prev { left: 1rem; top: 50%; transform: translateY(-50%); }
.photo-viewer .pv-next { right: 1rem; top: 50%; transform: translateY(-50%); }
.photo-viewer.single .pv-prev,
.photo-viewer.single .pv-next {
    display: none;
}

/* ---------- Report: daily summary table ---------- */
.report-table {
    font-size: 1.05rem;
}
.report-table th,
.report-table td {
    padding: .75rem 1rem;
}
.report-table thead th {
    background: #f8f9fa;
}
.report-table tfoot td {
    background: #f1f3f5;
    font-size: 1.1rem;
}

/* ---------- Invoice ---------- */
.invoice-sheet {
    background: #fff;
    max-width: 850px;
    margin: 0 auto;
    padding: 2.5rem;
    box-shadow: 0 1px 6px rgba(0, 0, 0, .1);
}
/* Paper-style bilingual invoice. Change --inv-accent to recolour it (e.g. #6b4a2e for the logo brown). */
.inv {
    --inv-accent: #e67e22;
    --inv-accent-dark: #b85d0d;
    --inv-soft: #fdf2e6;
    --inv-red: #d0312d;
    --inv-gold: #b8860b;   /* shop name */
    position: relative;
    border: 2px solid var(--inv-accent);
    border-radius: 1rem;
    font-size: .95rem;
    color: #2b2b2b;
}
.inv .lbl-en {
    display: block;
    font-size: .68em;
    line-height: 1.1;
    font-weight: 600;
    letter-spacing: .02em;
}
.inv-head {
    padding-bottom: 1rem;
}
/* Row 1: logo + shop name as one block, on the left */
.inv-top {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    gap: 1.25rem;
    margin-bottom: .5rem;
}
/* Row 2: pick-up date + Facebook on the left, invoice number + contacts on the right */
.inv-sub {
    display: flex;
    justify-content: flex-start;
    align-items: flex-start;
    gap: 1.25rem;
}
.inv-sub .inv-dates {
    flex: 0 0 165px;   /* logo width */
}
.inv-logo {
    display: block;
    width: 165px;
    height: auto;
    flex-shrink: 0;
}
.inv-shop {
    text-align: center;
}
.inv-shop-km {
    font-size: 2.3rem;
    font-weight: 700;
    color: var(--inv-gold);
    line-height: 1.3;
}
.inv-shop-en {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--inv-gold);
    text-transform: uppercase;
    letter-spacing: .05em;
}
.inv-tagline {
    font-size: .85rem;
    margin-top: .2rem;
}
.inv-title {
    display: inline-block;
    margin-top: .4rem;
    color: var(--inv-red);
    font-weight: 700;
    font-size: 1.35rem;
    line-height: 1.2;
}
.inv-contact {
    font-size: .82rem;
    line-height: 1.6;
    text-align: left;
    flex: 0 0 241px;     /* same width as the Unit Price + Amount columns of the table (2 x 120px + border) */
    margin-left: auto;   /* right edge of the invoice */
}
/* Long Khmer address wraps under its pin icon */
.inv-address {
    display: flex;
    gap: .3rem;
    line-height: 1.45;
    margin-top: .2rem;
}
.inv-address .bi {
    flex-shrink: 0;
    margin-top: .15rem;
}
.inv-contact .bi {
    color: var(--inv-accent);
    margin-right: .2rem;
}
/* Telegram + phone icons, then the numbers */
.inv-phones {
    display: flex;
    align-items: center;
    gap: .35rem;
    margin-bottom: .2rem;
}
.inv-app {
    width: 26px;
    height: 26px;
    border-radius: 6px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: .9rem;
}
.inv-contact .inv-app .bi {
    color: #fff;
    margin: 0;
}
.inv-app-telegram {
    background: #229ed9;
}
.inv-app-phone {
    background: #25a244;
}
.inv-app-facebook {
    background: #1877f2;
}
.inv-app-fbpage {
    background: #f57c00;
}
/* Facebook account / page under the logo */
.inv-social {
    display: flex;
    align-items: center;
    gap: .35rem;
    margin-top: .25rem;
    font-weight: 600;
    white-space: nowrap;
}
.inv-social .inv-app {
    width: 20px;
    height: 20px;
    border-radius: 5px;
    font-size: .72rem;
}
.inv-social .inv-app .bi {
    color: #fff;
}
.inv-phone-list {
    display: flex;
    flex-direction: column;
    margin-left: .2rem;
    font-size: .95rem;
    line-height: 1.35;
    letter-spacing: .02em;
}
.inv-no {
    font-weight: 400;   /* label normal, the number itself bold */
    font-size: 1rem;
    margin-bottom: .2rem;
}
.inv-no span {
    color: var(--inv-red);
    font-weight: 700;
}
.inv-box {
    border: 1.5px solid var(--inv-accent);
    border-radius: .75rem;
    padding: .5rem 1rem;
    margin-bottom: 1rem;
}
.inv-field {
    display: flex;
    align-items: flex-end;
    gap: .75rem;
    padding: .2rem 0;
}
.inv-label {
    flex: 0 0 110px;
    color: var(--inv-accent-dark);
    font-weight: 600;
}
.inv-line {
    flex: 1;
    min-height: 1.6rem;
    border-bottom: 1.5px dotted #b9a58f;
    font-size: 1.05rem;
    font-weight: 500;
    padding-left: .25rem;
}
.inv-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    border: 1.5px solid var(--inv-accent);
    border-radius: .75rem;
    overflow: hidden;
    margin-bottom: 1rem;
}
.inv-table th {
    background: var(--inv-accent);
    color: #fff;
    font-weight: 600;
    text-align: center;
    padding: .4rem .5rem;
    line-height: 1.2;
}
.inv-table td {
    border-top: 1px solid #f0c9a0;
    padding: .45rem .6rem;
    height: 2.3rem;
}
.inv-table td + td,
.inv-table th + th {
    border-left: 1px solid #f0c9a0;
}
.inv-table .inv-c-no {
    width: 52px;
    text-align: center;
    background: var(--inv-soft);
    color: var(--inv-accent-dark);
    font-weight: 600;
}
.inv-table th.inv-c-no {
    background: var(--inv-accent);
    color: #fff;
}
.inv-c-qty {
    width: 90px;
    text-align: center;
}
.inv-c-money {
    width: 120px;
    text-align: right;
}
.inv-table th.inv-c-qty,
.inv-table th.inv-c-money {
    text-align: center;
}
.inv-desc {
    color: #6c757d;
    font-size: .88em;
}
/* Pick-up / fitting dates under the logo */
.inv-dates {
    margin-top: .4rem;
    font-size: .78rem;
    line-height: 1.45;
}
.inv-dates > div:not(.inv-desc) {
    white-space: nowrap;
}
.inv-dates .lbl-en {
    display: inline;
    font-size: .85em;
    color: #6c757d;
}
.inv-dates strong {
    color: var(--inv-red);
}
.inv-foot {
    display: grid;
    grid-template-columns: 1fr 300px;
    gap: 1.5rem;
    align-items: end;
}
.inv-date span {
    display: inline-block;
    min-width: 2.5rem;
    border-bottom: 1.5px dotted #b9a58f;
    text-align: center;
    font-weight: 600;
}
.inv-sign-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    margin-top: 3.5rem;
}
.inv-sign-box {
    border-top: 1px solid #555;
    padding-top: .25rem;
    text-align: center;
    font-size: .85rem;
}
.inv-totals {
    border: 1.5px solid var(--inv-accent);
    border-radius: .75rem;
    overflow: hidden;
}
.inv-trow {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: .35rem .75rem;
    border-top: 1px solid #f0c9a0;
}
.inv-trow:first-child {
    border-top: 0;
}
.inv-trow > span {
    color: #fff;
    background: var(--inv-accent);
    margin: -.35rem 0 -.35rem -.75rem;
    padding: .35rem .75rem;
    min-width: 130px;
    font-weight: 600;
    align-self: stretch;
    display: flex;
    flex-direction: column;
    justify-content: center;
}
.inv-trow > b {
    font-size: 1.15rem;
}
.inv-trow-sub > b {
    font-size: .95rem;
    font-weight: 500;
}
.inv-trow-balance > b {
    color: var(--inv-red);
    font-size: 1.3rem;
}
.inv-stamp {
    position: absolute;
    right: 3rem;
    top: 45%;
    transform: rotate(-14deg);
    border: 4px solid rgba(25, 135, 84, .75);
    color: rgba(25, 135, 84, .8);
    border-radius: .75rem;
    padding: .3rem 1.2rem;
    font-size: 1.6rem;
    font-weight: 800;
    text-align: center;
    line-height: 1.15;
    letter-spacing: .1em;
    pointer-events: none;
}
.inv-thanks {
    text-align: center;
    font-size: .82rem;
    color: #6c757d;
    margin: 1.25rem 0 0;
}
/* Phone screens only. A printed A4 page is narrower than this and must keep the desktop layout,
   and so must "Save as image" (it adds .inv-capture while taking the picture). */
@media screen and (max-width: 767.98px) {
    .inv:not(.inv-capture) {
        padding: 1rem;
    }
    .inv:not(.inv-capture) .inv-top,
    .inv:not(.inv-capture) .inv-sub {
        flex-wrap: wrap;
    }
    .inv:not(.inv-capture) .inv-logo {
        width: 120px;
    }
    .inv:not(.inv-capture) .inv-shop-km {
        font-size: 1.3rem;
    }
    .inv:not(.inv-capture) .inv-foot {
        grid-template-columns: 1fr;
    }
    .inv:not(.inv-capture) .inv-totals {
        order: -1;
    }
    .inv:not(.inv-capture) .inv-c-qty,
    .inv:not(.inv-capture) .inv-c-money {
        width: auto;
    }
    .inv:not(.inv-capture) .inv-table {
        font-size: .85rem;
    }
}
/* While "Save as image" takes the picture: fixed A4 width, no shadow */
.inv.inv-capture {
    width: 794px;
    max-width: none;
    margin: 0;
    box-shadow: none;
}

/* ---------- Print ---------- */
@media print {
    @page {
        size: A4;
        margin: 9mm;
    }
    body {
        background: #fff !important;
    }
    .sidebar,
    .navbar,
    .d-print-none,
    .btn,
    .alert {
        display: none !important;
    }
    .app-wrapper {
        display: block;
    }
    .app-main {
        padding: 0 !important;
    }
    .card,
    .invoice-sheet {
        box-shadow: none !important;
    }
    .invoice-sheet {
        padding: 6mm;
        max-width: none;
    }
    /* Keep the whole invoice on one A4 page */
    .inv-head {
        padding-bottom: .6rem;
    }
    .inv-box {
        margin-bottom: .7rem;
    }
    .inv-table td {
        height: 1.8rem;
        padding: .12rem .6rem;
    }
    .inv-sign-row {
        margin-top: 2rem;
    }
    .inv-box {
        padding: .3rem 1rem;
    }
    .inv-field {
        padding: .1rem 0;
    }
    .inv-trow {
        padding-top: .25rem;
        padding-bottom: .25rem;
    }
    .inv-thanks {
        margin-top: .75rem;
    }
    .inv,
    .inv *,
    .due-soon,
    .overdue {
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
    a {
        text-decoration: none;
        color: inherit;
    }
}

/* ---------- Sign-in page ---------- */
.auth-page {
    background: linear-gradient(135deg, #1f2937 0%, #374151 100%);
    min-height: 100vh;
}
.auth-wrap {
    max-width: 440px;
    margin: 0 auto;
    padding: 4rem 1rem 2rem;
}
.auth-wrap > .small {
    color: rgba(255, 255, 255, .7) !important;
}
.auth-card {
    border-radius: .75rem;
    box-shadow: 0 10px 30px rgba(0, 0, 0, .3);
}
/* ---------- Shop logo (assets/img/logo.png) ---------- */
.brand-logo {
    width: 44px;
    height: 44px;
    border-radius: .5rem;
    object-fit: cover;
    flex-shrink: 0;
}
.brand-logo-sm {
    width: 32px;
    height: 32px;
    border-radius: .375rem;
}
.brand-logo-sidebar {
    width: 140px;
    height: 140px;
    border-radius: .75rem;
}
.brand-logo-lg {
    width: 120px;
    height: 120px;
    border-radius: .75rem;
    box-shadow: 0 4px 12px rgba(0, 0, 0, .2);
}
