:root {
  color-scheme: light;
  --ink: #102a43;
  --muted: #627d98;
  --paper: #f3f6f5;
  --card: #fff;
  --accent: #1f7a6b;
  --accent-light: #d9eee9;
  --warm: #f6c85f;
  --danger: #b42318;
  --font-sans: Inter, "Noto Sans Khmer", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-family: var(--font-sans);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { background: var(--paper); }
body { margin: 0; min-height: 100vh; background: var(--paper); color: var(--ink); overscroll-behavior-y: none; }
button, input, select { min-height: 44px; font: inherit; }
button { touch-action: manipulation; }
.hidden { display: none !important; }
.khmer-text, :lang(km) { font-family: "Noto Sans Khmer", var(--font-sans) !important; }
.muted { color: var(--muted); line-height: 1.45; }
.eyebrow { margin: 0 0 .3rem; color: var(--accent); font-size: .68rem; font-weight: 800; letter-spacing: .13em; text-transform: uppercase; }

.login-screen { min-height: 100dvh; display: grid; align-items: center; padding: max(1.25rem, env(safe-area-inset-top)) 1rem max(1.25rem, env(safe-area-inset-bottom)); background: radial-gradient(circle at 90% 5%, #d9eee9, transparent 38%), var(--paper); }
.login-card { width: 100%; padding: 1.6rem; border-radius: 26px; background: var(--card); box-shadow: 0 22px 60px rgba(16, 42, 67, .12); }
.login-card h1 { margin: 0; font-family: var(--font-sans); font-size: 2.15rem; line-height: 1.02; }
.brand-mark { display: grid; place-items: center; width: 50px; height: 50px; margin-bottom: 1.3rem; border-radius: 15px; background: var(--ink); color: #fff; font-weight: 900; }
label { display: block; margin-top: .9rem; color: var(--muted); font-size: .8rem; font-weight: 700; }
input { width: 100%; margin-top: .35rem; padding: .85rem .95rem; border: 1px solid #bcccdc; border-radius: 12px; outline: none; color: var(--ink); font-size: 16px; }
input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-light); }
.password-field { position: relative; display: block; }
.password-field input { padding-right: 3.15rem; }
.login-card .password-toggle { position: absolute; top: 50%; right: .35rem; width: 42px; min-height: 42px; margin: 0; padding: 0; border-radius: 10px; background: transparent; color: var(--muted); transform: translateY(-42%); }
.password-toggle .app-icon { width: 20px; height: 20px; }
.password-toggle[aria-pressed="true"] { color: var(--accent); }
.login-card button { width: 100%; margin-top: .7rem; padding: .9rem; border: 0; border-radius: 12px; background: var(--accent); color: #fff; font-weight: 800; }
.error { min-height: 1.1rem; margin: .55rem 0 0; color: var(--danger); font-size: .78rem; }

.app { width: 100%; padding: max(1rem, env(safe-area-inset-top)) .9rem calc(6.5rem + env(safe-area-inset-bottom)); }
.pull-refresh { position: fixed; z-index: 4; top: max(.45rem, env(safe-area-inset-top)); left: 50%; display: flex; gap: .45rem; align-items: center; padding: .45rem .75rem; border-radius: 999px; background: var(--ink); color: #fff; font-size: .68rem; font-weight: 700; opacity: 0; pointer-events: none; transform: translate(-50%, -150%); transition: opacity .18s ease, transform .18s ease; }
.pull-refresh.visible { opacity: 1; }
.pull-refresh.refreshing { opacity: 1; transform: translate(-50%, 0) !important; }
.pull-refresh-spinner { width: 14px; height: 14px; border: 2px solid rgba(255,255,255,.35); border-top-color: #fff; border-radius: 50%; }
.pull-refresh.refreshing .pull-refresh-spinner { animation: pull-spin .7s linear infinite; }
@keyframes pull-spin { to { transform: rotate(360deg); } }
.swipe-back-indicator { position: fixed; z-index: 12; top: 50%; left: .45rem; display: grid; place-items: center; width: 42px; height: 42px; border-radius: 50%; background: rgba(16,42,67,.92); color: #fff; font-size: 1.2rem; opacity: 0; pointer-events: none; transform: translate(-130%, -50%) scale(.8); transition: opacity .15s ease, transform .15s ease; }
.swipe-back-indicator.visible { opacity: 1; }
.swipe-back-indicator.ready { background: var(--accent); transform: translate(0, -50%) scale(1.08) !important; }
#detail-view.swiping-back { transition: none; will-change: transform, opacity; }
#detail-view.swipe-reset { transition: transform .2s ease, opacity .2s ease; }
header { display: flex; align-items: center; justify-content: space-between; margin: .2rem .15rem 1rem; }
header h1 { max-width: 270px; margin: 0; overflow: hidden; font-family: var(--font-sans); font-size: 1.7rem; text-overflow: ellipsis; white-space: nowrap; }
.page-period { margin: .18rem 0 0; color: var(--muted); font-size: .78rem; font-weight: 700; }
.icon-button { width: 44px; min-width: 44px; border: 0; border-radius: 50%; background: var(--card); color: var(--ink); font-size: 1.15rem; box-shadow: 0 5px 18px rgba(16, 42, 67, .08); }
.section-head { display: flex; align-items: end; justify-content: space-between; margin: 0 .1rem .7rem; }
.section-head h2 { margin: 0; font-family: var(--font-sans); font-size: 1.35rem; }
.text-button { border: 0; background: transparent; color: var(--accent); font-size: .78rem; font-weight: 800; }
.view-tabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: .35rem; margin-bottom: 1rem; padding: .35rem; border-radius: 15px; background: #e1e8e6; }
.view-tabs button { position: relative; z-index: 1; min-height: 40px; border: 0; border-radius: 11px; background: transparent; color: var(--muted); font-size: .75rem; font-weight: 800; }
.view-tabs button.active { color: var(--accent); }
.draggable-nav { position: relative; touch-action: pan-y; user-select: none; }
.draggable-nav .active-slider { position: absolute; z-index: 0; top: .35rem; bottom: .35rem; left: 0; width: var(--slider-width, 0); border-radius: 11px; background: var(--card); box-shadow: 0 3px 10px rgba(16,42,67,.08); pointer-events: none; transform: translateX(var(--slider-x, 0)) scaleX(var(--slider-scale-x, 1)) scaleY(var(--slider-scale-y, 1)); transition: transform .28s cubic-bezier(.2,.9,.25,1.15), width .24s ease; transform-origin: center; }
.draggable-nav.dragging .active-slider { transition: none; }
.draggable-nav.morph-settle .active-slider { animation: slider-settle .34s cubic-bezier(.2,.9,.25,1.2); }
@keyframes slider-settle {
  0% { filter: brightness(1.04); }
  45% { transform: translateX(var(--slider-x, 0)) scaleX(.96) scaleY(1.05); }
  75% { transform: translateX(var(--slider-x, 0)) scaleX(1.025) scaleY(.985); }
  100% { filter: brightness(1); transform: translateX(var(--slider-x, 0)) scaleX(1) scaleY(1); }
}
.filter-panel { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .55rem; margin-bottom: .8rem; padding: .75rem; border-radius: 16px; background: var(--card); }
.filter-panel .filter-wide { grid-column: 1 / -1; }
.filter-panel label { min-width: 0; margin: 0; font-size: .68rem; }
.filter-panel select { width: 100%; margin-top: .3rem; padding: .55rem .65rem; border: 1px solid #d5dfdc; border-radius: 10px; outline: none; background: var(--paper); color: var(--ink); font-size: .78rem; }
.filter-panel input { width: 100%; margin-top: .3rem; padding: .55rem .65rem; border: 1px solid #d5dfdc; border-radius: 10px; outline: none; background: var(--paper); color: var(--ink); font-size: .78rem; }
.filter-panel select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-light); }
.activity-list { display: grid; gap: .55rem; }
.list-loader { display: flex; gap: .5rem; align-items: center; justify-content: center; min-height: 54px; color: var(--muted); font-size: .72rem; font-weight: 700; }
.list-loader .pull-refresh-spinner { border-color: rgba(31,122,107,.22); border-top-color: var(--accent); animation: pull-spin .7s linear infinite; }
.list-sentinel { height: 1px; }
.activity { display: grid; grid-template-columns: 40px minmax(0, 1fr) auto; gap: .7rem; align-items: center; width: 100%; min-height: 68px; padding: .82rem; border: 0; border-radius: 16px; background: var(--card); color: var(--ink); text-align: left; }
.order-row:active { transform: scale(.99); background: #f9fbfa; }
.activity-icon { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 12px; background: var(--accent-light); color: var(--accent); font-weight: 900; }
.app-icon { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.activity h3 { margin: 0 0 .18rem; overflow: hidden; font-size: .84rem; text-overflow: ellipsis; white-space: nowrap; }
.activity p { margin: 0; overflow: hidden; color: var(--muted); font-size: .65rem; text-overflow: ellipsis; white-space: nowrap; }
.activity > strong { max-width: 95px; overflow: hidden; font-size: .8rem; text-overflow: ellipsis; white-space: nowrap; }
.payment-row { cursor: default; }
.month-total-card { margin-bottom: 1.5rem; padding: 1rem; border-radius: 20px; background: var(--ink); color: #fff; box-shadow: 0 12px 30px rgba(16, 42, 67, .2); }
.month-total-card .eyebrow { color: var(--warm); font-size: 1rem; letter-spacing: .04em; line-height: 1.45; text-transform: none; }
.month-total-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .55rem; }
.month-total-grid div { min-width: 0; padding: .7rem; border-radius: 12px; background: rgba(255,255,255,.1); }
.month-total-grid div.primary { grid-column: 1 / -1; background: rgba(246, 200, 95, .18); }
.month-total-grid span { display: block; color: #bcccdc; font-size: .62rem; }
.month-total-grid strong { display: block; margin-top: .3rem; overflow: hidden; font-family: var(--font-sans); font-size: 1rem; text-overflow: ellipsis; white-space: nowrap; }
.month-total-grid .primary strong { color: var(--warm); font-size: 1.35rem; }
.dashboard-no-data { padding: 2.2rem 1rem; color: #bcccdc; font-size: .95rem; font-weight: 800; text-align: center; }
.dashboard-period-filter { display: grid; grid-template-columns: 1.25fr .75fr; gap: .55rem; margin-bottom: .8rem; padding: .75rem; border-radius: 16px; background: var(--card); box-shadow: 0 5px 18px rgba(16,42,67,.05); }
.dashboard-period-filter label { margin: 0; color: var(--muted); font-size: .68rem; font-weight: 800; }
.dashboard-period-filter select { width: 100%; margin-top: .3rem; padding: .55rem .65rem; border: 1px solid #d5dfdc; border-radius: 10px; outline: none; background: var(--paper); color: var(--ink); font-size: .82rem; }
.dashboard-period-filter select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-light); }
.dashboard-tabs { display: grid; grid-template-columns: repeat(2, 1fr); gap: .35rem; margin-bottom: 1rem; padding: .35rem; border-radius: 15px; background: #e1e8e6; }
.dashboard-tabs.single-tab { display: none; }
.access-hidden { display: none !important; }
.dashboard-tabs button { position: relative; z-index: 1; min-height: 42px; border: 0; border-radius: 11px; background: transparent; color: var(--muted); font-size: .8rem; font-weight: 800; }
.dashboard-tabs button.active { color: var(--accent); }
.dashboard-grid { display: grid; gap: .65rem; }
.dashboard-card { overflow: hidden; padding: 1rem; border: 1px solid rgba(31,122,107,.08); border-radius: 20px; background: linear-gradient(145deg, #fff 0%, #fbfdfc 100%); box-shadow: 0 8px 24px rgba(16,42,67,.07); }
.dashboard-card-head { display: flex; gap: .8rem; align-items: center; justify-content: space-between; }
.dashboard-card-kicker { margin: 0 0 .22rem; color: var(--accent); font-size: .68rem; font-weight: 800; }
.dashboard-card h3 { max-width: 220px; margin: 0; overflow: hidden; font-family: var(--font-sans); font-size: 1.16rem; text-overflow: ellipsis; white-space: nowrap; }
.revenue-chart { display: grid; flex: 0 0 78px; place-items: center; width: 78px; height: 78px; border-radius: 50%; background: conic-gradient(#4aa89a calc(var(--payment-percent) * 1%), #f2a66f 0); box-shadow: 0 5px 14px rgba(35,105,94,.14), inset 0 0 0 1px rgba(16,42,67,.035); transform: rotate(-90deg); }
.revenue-chart > div { display: grid; place-items: center; width: 46px; height: 46px; border-radius: 50%; background: var(--card); box-shadow: inset 0 0 0 1px rgba(16,42,67,.035); }
.dashboard-balance { display: flex; gap: .65rem; align-items: center; justify-content: space-between; margin-top: .8rem; padding: .75rem .8rem; border-radius: 13px; background: #fff2ef; }
.dashboard-balance span { max-width: 62%; color: #8f3129; font-size: .75rem; font-weight: 800; line-height: 1.4; }
.dashboard-balance strong { flex: 0 0 auto; font-size: 1.08rem; }
.dashboard-monthly { display: grid; gap: .5rem; margin-top: .55rem; }
.monthly-metric { display: flex; gap: .65rem; align-items: center; justify-content: space-between; padding: .7rem .8rem; border-radius: 13px; background: var(--paper); }
.monthly-metric span { display: flex; gap: .42rem; align-items: center; color: var(--muted); font-size: .75rem; font-weight: 800; line-height: 1.35; }
.monthly-metric i { flex: 0 0 8px; width: 8px; height: 8px; border-radius: 50%; }
.monthly-metric strong { flex: 0 0 auto; font-size: 1.03rem; }
.revenue-metric i { background: #f2a66f; }
.payment-metric i { background: #4aa89a; }
.dashboard-card .danger-value { color: var(--danger); }
.dashboard-card .accent-value { color: var(--accent); }
.order-status { display: inline-block; margin-top: .3rem; padding: .15rem .4rem; border-radius: 999px; background: #e8eef3; color: var(--muted); font-size: .58rem; font-weight: 800; text-transform: capitalize; }
.badge-row { display: flex; gap: .3rem; align-items: center; }
.pending-badge { display: inline-block; padding: .15rem .4rem; border-radius: 999px; background: #fff6dc; color: #7a5b12; font-size: .58rem; font-weight: 800; text-transform: uppercase; }
.status-paid { background: var(--accent-light); color: var(--accent); }
.status-voided { background: #fff0ee; color: var(--danger); }
.status-deducted { background: #fff6dc; color: #7a5b12; }
.order-summary { padding: 1.15rem; border-radius: 20px; background: var(--ink); color: #fff; box-shadow: 0 12px 30px rgba(16, 42, 67, .18); }
.summary-heading { display: flex; gap: .8rem; align-items: start; justify-content: space-between; }
.summary-label { display: flex; align-items: center; justify-content: space-between; }
.summary-label .eyebrow { margin: 0; }
.summary-heading h2 { margin: 0; font-family: var(--font-sans); font-size: 1.5rem; }
.summary-heading strong { white-space: nowrap; color: var(--warm); }
.customer-summary-title { margin: 0; color: var(--accent); font-size: 1.05rem; font-weight: 800; line-height: 1.45; }
.summary-phone { margin: .28rem 0 0; color: #bcccdc; font-size: .72rem; }
.summary-amount { display: grid; gap: .2rem; justify-items: end; text-align: right; }
.summary-heading .summary-amount-label { color: #9fb3c8; font-size: .65rem; font-weight: 800; }
.order-summary dl, .profile-card dl { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .7rem; margin: 1rem 0 0; }
.order-summary dl div { padding-top: .65rem; border-top: 1px solid rgba(255,255,255,.12); }
dt { color: var(--muted); font-size: .65rem; font-weight: 700; text-transform: uppercase; }
.order-summary dt { color: #9fb3c8; }
dd { margin: .2rem 0 0; overflow-wrap: anywhere; font-size: .78rem; font-weight: 700; }
.detail-tabs { display: flex; gap: .35rem; overflow-x: auto; margin: 1rem 0 .7rem; padding-bottom: .15rem; scrollbar-width: none; }
.detail-tabs::-webkit-scrollbar { display: none; }
.detail-tabs button { flex: 1 0 auto; min-height: 40px; padding: .55rem .8rem; border: 0; border-radius: 12px; background: var(--card); color: var(--muted); font-size: .72rem; font-weight: 800; }
.detail-tabs button.active { background: var(--accent); color: #fff; }
.detail-content { display: grid; gap: .55rem; }
.detail-card { padding: .9rem; border-radius: 16px; background: var(--card); }
.customer-order-row { width: 100%; border: 0; color: var(--ink); text-align: left; }
.detail-card-head { display: flex; gap: .7rem; align-items: start; justify-content: space-between; }
.card-value { display: grid; gap: .3rem; justify-items: end; }
.detail-card h3 { margin: 0; font-size: .86rem; }
.detail-card strong { white-space: nowrap; font-size: .82rem; }
.detail-card p { margin: .35rem 0 0; color: var(--muted); font-size: .7rem; }
.detail-card small { display: block; margin-top: .55rem; padding-top: .55rem; border-top: 1px solid #e7ecea; color: var(--ink); line-height: 1.4; }
.image-row { cursor: pointer; }
.image-row:active { transform: scale(.99); }
.image-hint { display: block; margin-top: .55rem; color: var(--accent); font-size: .65rem; font-weight: 800; }
.image-viewer { width: min(94vw, 700px); max-width: none; padding: 0; border: 0; border-radius: 18px; overflow: hidden; background: #07131d; color: #fff; }
.image-viewer::backdrop { background: rgba(3, 12, 18, .86); backdrop-filter: blur(5px); }
.image-viewer img { display: block; width: 100%; max-height: 82vh; object-fit: contain; background: #07131d; }
.image-viewer p { margin: 0; padding: .8rem 3.5rem .9rem 1rem; font-size: .75rem; }
.image-close { position: absolute; z-index: 1; top: .65rem; right: .65rem; width: 42px; min-height: 42px; border: 0; border-radius: 50%; background: rgba(0,0,0,.62); color: #fff; font-size: 1.45rem; }
.order-items-viewer { width: min(92vw, 560px); max-width: none; max-height: 88vh; padding: 0; border: 0; border-radius: 20px; overflow: hidden; background: var(--paper); color: var(--ink); }
.order-items-viewer::backdrop { background: rgba(3, 12, 18, .72); backdrop-filter: blur(4px); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 1rem; background: var(--card); border-bottom: 1px solid #e2e8e6; }
.modal-head h2 { margin: 0; font-family: var(--font-sans); font-size: 1.15rem; }
.order-items-label { font-size: 1rem; letter-spacing: .04em; line-height: 1.45; text-transform: none; }
.modal-close { width: 42px; min-width: 42px; min-height: 42px; border: 0; border-radius: 50%; background: var(--paper); color: var(--ink); font-size: 1.4rem; }
.modal-content { display: grid; gap: .55rem; max-height: calc(88vh - 76px); padding: .8rem; overflow-y: auto; }
.status-pill { padding: .25rem .5rem; border-radius: 999px; background: var(--accent-light); color: var(--accent); font-size: .65rem; font-weight: 800; }
.scope-note { margin: 0 0 .65rem; padding: .7rem .8rem; border-radius: 12px; background: #fff6dc; color: #7a5b12; font-size: .7rem; }
.profile-card { padding: 1.4rem; border-radius: 24px; background: var(--card); text-align: center; box-shadow: 0 12px 34px rgba(16, 42, 67, .08); }
.profile-initial { display: grid; place-items: center; width: 72px; height: 72px; margin: 0 auto 1rem; border-radius: 24px; background: var(--ink); color: #fff; font-family: var(--font-sans); font-size: 2rem; }
.profile-card h2 { margin: 0; font-family: var(--font-sans); font-size: 1.7rem; }
.profile-card dl { margin-top: 1.4rem; text-align: left; }
.profile-card dl div { padding: .8rem; border-radius: 12px; background: var(--paper); }
.danger-button { width: 100%; margin-top: 1.2rem; border: 0; border-radius: 12px; background: #fff0ee; color: var(--danger); font-weight: 800; }
.empty { padding: 2rem 1rem; text-align: center; color: var(--muted); font-size: .85rem; }
.bottom-nav { position: fixed; z-index: 5; right: .8rem; bottom: max(.8rem, env(safe-area-inset-bottom)); left: .8rem; display: grid; grid-template-columns: repeat(4, 1fr); padding: .4rem; border-radius: 21px; background: rgba(16, 42, 67, .97); box-shadow: 0 15px 38px rgba(16, 42, 67, .32); backdrop-filter: blur(14px); }
.bottom-nav.sale-nav { grid-template-columns: repeat(3, 1fr); }
.bottom-nav .active-slider { top: .4rem; bottom: .4rem; border-radius: 15px; background: rgba(255,255,255,.12); box-shadow: none; }
.bottom-nav button { position: relative; z-index: 1; display: grid; gap: .15rem; place-items: center; min-height: 51px; padding: .35rem; border: 0; border-radius: 15px; background: transparent; color: #9fb3c8; font-size: .61rem; }
.bottom-nav .nav-icon { display: grid; place-items: center; }
.bottom-nav .app-icon { width: 20px; height: 20px; }
.bottom-nav button.active { color: #fff; }

@media (prefers-reduced-motion: reduce) {
  .draggable-nav .active-slider { transition: none; }
  .draggable-nav.morph-settle .active-slider { animation: none; }
}

@media (min-width: 500px) {
  body { background: #e5eae8; }
  .app, .login-card { max-width: 430px; margin-inline: auto; }
  .app { min-height: 100vh; background: var(--paper); }
  .bottom-nav { width: 404px; margin-inline: auto; }
}
