@font-face {
  font-family: "Kantumruy Pro";
  src: url("../fonts/KantumruyPro.ttf") format("truetype");
  font-weight: 100 700;
  font-style: normal;
  font-display: block;
}

:root {
  --brand: #e0242f;
  --brand-dark: #b81b25;
  --brand-soft: #fdecee;
  --bg: #f6f7fb;
  --white: #fff;
  --ink: #1e293b;
  --ink-2: #334155;
  --muted: #64748b;
  --muted-2: #94a3b8;
  --line: #e2e8f0;
  --line-2: #f1f5f9;
  --soft: #f8fafc;
  --red: #dc2626;
  --red-bg: #fef2f2;
  --green: #059669;
  --green-bg: #ecfdf5;
  --amber: #b45309;
  --amber-bg: #fffbeb;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 4px 14px rgba(15, 23, 42, .05);
  --sidebar: 264px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: "Kantumruy Pro", "Noto Sans Khmer", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 15.5px;
  line-height: 1.6;
  color: var(--ink);
  background: var(--bg);
}
a { color: var(--ink); }
h1, h2, h3 { line-height: 1.35; margin: 0 0 .6em; color: var(--ink); }
h1 { font-size: 1.55rem; font-weight: 700; }
h2 { font-size: 1.12rem; font-weight: 600; }
h3 { font-size: 1rem; font-weight: 600; }
[x-cloak] { display: none !important; }
.ic { width: 20px; height: 20px; flex: none; }

/* ===== Shell: sidebar + topbar ===== */
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar); background: var(--white);
  border-right: 1px solid var(--line); z-index: 60; display: flex; flex-direction: column;
  transition: transform .2s ease;
}
.logo { display: flex; flex-direction: column; align-items: flex-start; padding: 22px 26px 18px; border-bottom: 1px solid var(--line); text-decoration: none; }
.logo .l1 { font-weight: 800; font-size: 1.45rem; letter-spacing: .02em; color: var(--brand); line-height: 1.1; font-family: system-ui, -apple-system, "Segoe UI", sans-serif; }
.logo .l2 { font-size: .72rem; font-weight: 700; letter-spacing: .28em; color: var(--brand); margin-left: 2px; position: relative; padding: 0 0 4px; }
.logo .l2::after { content: ""; position: absolute; left: -14px; right: -14px; bottom: 0; height: 2px; border-radius: 50%; background: var(--brand); opacity: .8; }
.side-nav { padding: 14px 12px; overflow-y: auto; flex: 1; }
.side-nav .group { font-size: .74rem; color: var(--muted-2); padding: 14px 14px 6px; letter-spacing: .04em; }
.side-nav a {
  display: flex; align-items: center; gap: 14px; padding: 11px 14px; border-radius: 10px;
  color: var(--ink-2); text-decoration: none; font-weight: 500; margin-bottom: 2px;
}
.side-nav a .ic { color: var(--brand); }
.side-nav a:hover { background: var(--soft); }
.side-nav a.active { background: var(--brand-soft); color: var(--ink); font-weight: 600; }
.side-nav a.new { background: var(--brand); color: #fff; justify-content: center; font-weight: 600; margin-bottom: 10px; box-shadow: 0 6px 16px rgba(224, 36, 47, .25); }
.side-nav a.new .ic { color: #fff; }
.side-nav a.new:hover { background: var(--brand-dark); }
.side-foot { padding: 14px 20px; border-top: 1px solid var(--line); font-size: .78rem; color: var(--muted-2); }

.main { margin-left: var(--sidebar); min-height: 100vh; transition: margin .2s ease; }
.topbar {
  position: sticky; top: 0; z-index: 40; height: 72px; background: rgba(255,255,255,.92); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 14px; padding: 0 28px;
}
.icon-btn { background: none; border: 0; color: var(--brand); cursor: pointer; padding: 8px; border-radius: 10px; display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }
.icon-btn:hover { background: var(--brand-soft); }
.icon-btn .ic { width: 22px; height: 22px; }
.topbar .date { color: var(--muted); }
.topbar .spacer { flex: 1; }
.avatar { width: 40px; height: 40px; border-radius: 50%; background: var(--ink); color: #fff; display: inline-flex; align-items: center; justify-content: center; font-weight: 700; border: 0; cursor: pointer; font: inherit; font-weight: 700; }
.dropdown { position: relative; }
.dropdown-menu { position: absolute; right: 0; top: 50px; background: var(--white); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 12px 32px rgba(15,23,42,.12); min-width: 230px; padding: 8px; z-index: 80; }
.dropdown-menu .who { padding: 8px 12px 10px; border-bottom: 1px solid var(--line-2); margin-bottom: 6px; }
.dropdown-menu .who b { display: block; }
.dropdown-menu a, .dropdown-menu button { display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 12px; border-radius: 8px; text-decoration: none; color: var(--ink-2); background: none; border: 0; font: inherit; cursor: pointer; text-align: left; }
.dropdown-menu a:hover, .dropdown-menu button:hover { background: var(--soft); }
.dropdown-menu .ic { width: 18px; height: 18px; color: var(--muted); }
.side-backdrop { display: none; }

body.side-closed .sidebar { transform: translateX(-100%); }
body.side-closed .main { margin-left: 0; }
@media (max-width: 1024px) {
  .sidebar { transform: translateX(-100%); box-shadow: 0 0 40px rgba(0,0,0,.15); }
  .main { margin-left: 0; }
  body.side-open .sidebar { transform: none; }
  body.side-open .side-backdrop { display: block; position: fixed; inset: 0; background: rgba(15,23,42,.35); z-index: 55; }
  .topbar { padding: 0 16px; height: 64px; }
}

.container { max-width: 1400px; margin: 0 auto; padding: 28px 28px 70px; }
@media (max-width: 640px) { .container { padding: 18px 16px 60px; } .topbar .date { display: none; } }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head h1 { margin: 0; }

/* ===== Cards / stats ===== */
.card { background: var(--white); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; margin-bottom: 18px; box-shadow: var(--shadow); }
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
.card-flat { background: transparent; border: 0; box-shadow: none; padding: 0; }
.grid { display: grid; gap: 18px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 1100px) { .grid-3, .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 640px) { .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; } }

.stat { background: var(--white); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow); display: flex; align-items: center; gap: 18px; min-height: 120px; }
.stat-icon { width: 56px; height: 56px; border-radius: 14px; display: inline-flex; align-items: center; justify-content: center; flex: none; }
.stat-icon .ic { width: 24px; height: 24px; }
.stat .label { color: var(--muted); font-size: .95rem; }
.stat .value { font-size: 1.45rem; font-weight: 700; line-height: 1.3; color: var(--ink); }
.stat .sub { color: var(--muted-2); font-size: .82rem; }
.tone-purple { background: #f3f0ff; color: #7c3aed; }
.tone-green { background: #ecfdf5; color: #059669; }
.tone-orange { background: #fff4ec; color: #ea580c; }
.tone-red { background: var(--brand-soft); color: var(--brand); }
.tone-yellow { background: #fffbeb; color: #d97706; }
.tone-blue { background: #eff6ff; color: #2563eb; }
.tone-teal { background: #f0fdfa; color: #0d9488; }
.card-title { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.card-title h2 { margin: 0; }
.card-title .ic { color: var(--brand); }

.hero-btn { display: flex; align-items: center; justify-content: center; gap: 12px; padding: 22px; border-radius: var(--radius); background: var(--brand); color: #fff; text-decoration: none; font-size: 1.25rem; font-weight: 700; box-shadow: 0 10px 24px rgba(224,36,47,.25); margin-bottom: 18px; }
.hero-btn:hover { background: var(--brand-dark); }
.hero-btn .ic { width: 26px; height: 26px; }
.welcome { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 22px; }
.welcome h1 { margin: 0; font-size: 1.7rem; }

/* ===== Forms ===== */
label { display: block; font-weight: 500; margin-bottom: 6px; font-size: .93rem; color: var(--ink-2); }
.req::after { content: " *"; color: var(--brand); }
input[type=text], input[type=password], input[type=number], input[type=date], input[type=search], input[type=tel], input[type=file], select, textarea {
  width: 100%; font: inherit; font-size: 16px; padding: 10px 14px; min-height: 46px;
  border: 1px solid #cbd5e1; border-radius: 10px; background: var(--white); color: var(--ink);
  transition: border-color .15s, box-shadow .15s;
}
select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; background-size: 18px; padding-right: 38px; }
textarea { min-height: 84px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(224, 36, 47, .12); }
.field { margin-bottom: 16px; }
.hint { color: var(--muted); font-size: .84rem; margin-top: 4px; }
.error { color: var(--red); font-size: .87rem; margin-top: 4px; }
.error:empty { display: none; }
.is-invalid { border-color: var(--red) !important; background: var(--red-bg) !important; }
.check { display: inline-flex; align-items: center; gap: 8px; font-weight: 400; cursor: pointer; padding: 7px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--white); margin: 0 6px 6px 0; min-height: 42px; user-select: none; color: var(--ink-2); }
.check input { width: 19px; height: 19px; accent-color: var(--brand); margin: 0; }
.check:has(input:checked) { border-color: var(--brand); background: var(--brand-soft); color: var(--ink); }
.inline-form { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.inline-form .field { margin-bottom: 0; }
.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; align-items: end; }
.filters .field { margin: 0; }

/* ===== Buttons ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap;
  min-height: 44px; padding: 9px 18px; border-radius: 10px;
  border: 1px solid var(--brand); background: var(--brand); color: var(--white);
  transition: background .15s, box-shadow .15s;
}
.btn:hover { background: var(--brand-dark); border-color: var(--brand-dark); }
.btn .ic { width: 18px; height: 18px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-outline { background: var(--white); color: var(--ink-2); border-color: var(--line); box-shadow: 0 1px 2px rgba(15,23,42,.04); }
.btn-outline:hover { background: var(--soft); border-color: #cbd5e1; }
.btn-dark { background: var(--ink); border-color: var(--ink); }
.btn-dark:hover { background: #0f172a; border-color: #0f172a; }
.btn-danger { background: var(--white); color: var(--red); border-color: #fecaca; }
.btn-danger:hover { background: var(--red-bg); border-color: var(--red); }
.modal .btn-danger { background: var(--red); color: #fff; border-color: var(--red); }
.btn-sm { min-height: 34px; padding: 5px 12px; font-size: .88rem; border-radius: 8px; }
.btn-lg { min-height: 54px; padding: 12px 24px; font-size: 1.05rem; }
.btn-block { width: 100%; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ===== Tables ===== */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.card.table-wrap { padding: 0; }
table { width: 100%; border-collapse: collapse; background: var(--white); }
th, td { padding: 12px 16px; border-bottom: 1px solid var(--line-2); text-align: left; vertical-align: top; }
th { background: var(--soft); font-size: .84rem; color: var(--muted); font-weight: 600; white-space: nowrap; border-bottom: 1px solid var(--line); }
td.num, th.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
tbody tr:hover td { background: #fcfcfd; }
tbody tr:last-child td { border-bottom: 0; }
tfoot td { font-weight: 700; background: var(--soft); border-top: 1px solid var(--line); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .9em; }
.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }
td a { color: var(--ink); font-weight: 500; text-decoration: none; }
td a:hover { color: var(--brand); }

/* ===== Alerts / badges ===== */
.alert { padding: 12px 16px; border-radius: 12px; margin-bottom: 18px; border: 1px solid; }
.alert-success { background: var(--green-bg); border-color: #a7f3d0; color: #047857; }
.alert-error { background: var(--red-bg); border-color: #fecaca; color: var(--red); }
.alert-warn { background: var(--amber-bg); border-color: #fde68a; color: var(--amber); }
.badge { display: inline-block; padding: 2px 10px; border-radius: 99px; font-size: .78rem; font-weight: 600; background: var(--line-2); color: var(--ink-2); white-space: nowrap; }
.badge-dark { background: var(--ink); color: var(--white); }
.badge-red { background: var(--red-bg); color: var(--red); }
.badge-green { background: var(--green-bg); color: var(--green); }
.badge-brand { background: var(--brand-soft); color: var(--brand); }

/* ===== Pagination ===== */
.pagination { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 16px; align-items: center; }
.pagination a, .pagination span { padding: 7px 13px; border: 1px solid var(--line); border-radius: 10px; background: var(--white); text-decoration: none; min-width: 40px; text-align: center; }
.pagination a:hover { border-color: var(--brand); color: var(--brand); }
.pagination .active { background: var(--brand); color: var(--white); border-color: var(--brand); }
.pagination .disabled { color: #cbd5e1; }

/* ===== Modal ===== */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); z-index: 100; display: flex; align-items: flex-start; justify-content: center; padding: 40px 12px; overflow-y: auto; }
.modal { background: var(--white); border-radius: 18px; width: 100%; max-width: 660px; padding: 24px; box-shadow: 0 24px 60px rgba(15,23,42,.25); }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.modal-head h2 { margin: 0; }
.close-x { background: var(--soft); border: 0; font-size: 1.4rem; cursor: pointer; line-height: 1; width: 36px; height: 36px; border-radius: 50%; color: var(--muted); }

/* ===== Picker ===== */
.picker { position: relative; }
.picker-list { position: absolute; left: 0; right: 0; top: 100%; z-index: 30; background: var(--white); border: 1px solid var(--line); border-radius: 12px; margin-top: 6px; max-height: 340px; overflow-y: auto; box-shadow: 0 16px 36px rgba(15,23,42,.14); padding: 6px; }
.picker-list button { display: block; width: 100%; text-align: left; padding: 10px 14px; border: 0; border-radius: 8px; background: var(--white); font: inherit; cursor: pointer; }
.picker-list button:hover, .picker-list button.hl { background: var(--brand-soft); }

/* ===== POS ===== */
.step { display: inline-flex; width: 28px; height: 28px; border-radius: 50%; background: var(--brand); color: #fff; align-items: center; justify-content: center; font-size: .9rem; font-weight: 700; margin-right: 8px; }
.pos-customer { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.pos-customer .picker { flex: 1; min-width: 240px; }
.selected-customer { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 14px 18px; border: 1px solid #fecdd3; border-radius: 12px; background: var(--brand-soft); flex-wrap: wrap; }
.selected-customer .name { font-size: 1.12rem; font-weight: 700; }
.item-card { border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin: 18px 0; background: var(--white); position: relative; box-shadow: var(--shadow); }
.item-card.dup { border: 2px solid var(--red); }
.item-no { position: absolute; top: -12px; left: 18px; background: var(--ink); color: var(--white); border-radius: 99px; padding: 1px 12px; font-weight: 700; font-size: .85rem; }
.item-grid { display: grid; gap: 14px; grid-template-columns: repeat(4, minmax(0, 1fr)); }
.item-grid .span-2 { grid-column: span 2; }
@media (max-width: 900px) { .item-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 520px) { .item-grid { grid-template-columns: 1fr; } .item-grid .span-2 { grid-column: auto; } }
.grade-group { display: flex; gap: 8px; }
.grade-group button { flex: 1; min-height: 46px; font: inherit; font-weight: 700; font-size: 1.05rem; border: 1px solid #cbd5e1; border-radius: 10px; background: var(--white); cursor: pointer; color: var(--ink-2); }
.grade-group button.on { background: var(--brand); color: var(--white); border-color: var(--brand); }
.dup-warning { background: var(--red); color: var(--white); padding: 12px 16px; border-radius: 10px; margin-top: 10px; }
.dup-warning a { color: var(--white); font-weight: 700; }
.imei-warn { background: var(--amber-bg); color: var(--amber); border: 1px solid #fde68a; padding: 10px 14px; border-radius: 10px; margin-top: 8px; font-size: .9rem; }
.price-input { font-size: 1.25rem !important; font-weight: 700; }
.pos-footer { position: sticky; bottom: 0; background: rgba(255,255,255,.96); backdrop-filter: blur(8px); border-top: 1px solid var(--line); padding: 14px 28px; margin: 0 -28px; z-index: 20; box-shadow: 0 -8px 24px rgba(15,23,42,.06); }
@media (max-width: 640px) { .pos-footer { margin: 0 -16px; padding: 12px 16px; } }
.pos-total { display: flex; gap: 16px; align-items: baseline; flex-wrap: wrap; }
.pos-total .usd { font-size: 1.9rem; font-weight: 800; color: var(--ink); }
.pos-total .khr { font-size: 1.08rem; color: var(--muted); }
.pay-group { display: flex; gap: 8px; flex-wrap: wrap; }
.pay-group button { min-height: 46px; padding: 8px 18px; font: inherit; border: 1px solid #cbd5e1; border-radius: 10px; background: var(--white); cursor: pointer; color: var(--ink-2); }
.pay-group button.on { background: var(--brand); color: var(--white); border-color: var(--brand); font-weight: 600; }

/* ===== Login ===== */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; background: radial-gradient(circle at 20% 10%, #fde8ea 0, transparent 40%), var(--bg); }
.login-box { background: var(--white); width: 100%; max-width: 420px; border-radius: 20px; padding: 34px 30px; border: 1px solid var(--line); box-shadow: 0 20px 50px rgba(15,23,42,.08); }
.login-box .logo { align-items: center; border: 0; padding: 0 0 6px; }

dl.info { display: grid; grid-template-columns: max-content 1fr; gap: 8px 18px; margin: 0; }
dl.info dt { color: var(--muted); }
dl.info dd { margin: 0; font-weight: 500; }
.diff { font-size: .82rem; max-width: 520px; white-space: pre-wrap; word-break: break-word; margin: 0; font-family: ui-monospace, Menlo, monospace; background: var(--soft); padding: 8px 10px; border-radius: 8px; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 16px; background: var(--white); border: 1px solid var(--line); border-radius: 12px; padding: 6px; box-shadow: var(--shadow); width: fit-content; max-width: 100%; }
.tabs a { padding: 8px 16px; border-radius: 8px; text-decoration: none; color: var(--ink-2); font-weight: 500; }
.tabs a.on { background: var(--brand); color: #fff; }
.tabs a:not(.on):hover { background: var(--soft); }
.list-row { display: flex; justify-content: space-between; align-items: center; padding: 10px 6px; border-bottom: 1px solid var(--line-2); }
.list-row a { text-decoration: none; }
.list-row.on a { color: var(--brand); font-weight: 700; }

@media print {
  .no-print, .sidebar, .topbar, .pagination, .filters-card, .tabs { display: none !important; }
  .main { margin: 0 !important; }
  body { background: #fff; font-size: 11pt; }
  .container { padding: 0; max-width: none; }
  .card, .stat { border: 1px solid #ddd; box-shadow: none; }
  .card.table-wrap { border: 0; }
  th { background: #eee !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  table { font-size: 10pt; }
}

/* ===== Condition chips (POS) ===== */
.cond-wrap { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-top: 16px; }
.cond-wrap .cond-group:first-child, .cond-wrap .cond-group:nth-child(4) { grid-column: span 2; }
@media (max-width: 900px) { .cond-wrap { grid-template-columns: 1fr; } .cond-wrap .cond-group { grid-column: auto !important; } }
.cond-group { border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; background: var(--soft); min-width: 0; }
.cond-title { font-weight: 600; font-size: .93rem; margin-bottom: 8px; color: var(--ink); }
.cond-title .muted { font-weight: 400; font-size: .8rem; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  font: inherit; font-size: .95rem; min-height: 44px; padding: 8px 16px; border-radius: 999px; cursor: pointer;
  border: 1px solid #cbd5e1; background: var(--white); color: var(--ink-2); max-width: 100%; overflow-wrap: anywhere; text-align: center;
  transition: background .12s, border-color .12s, color .12s;
}
.chip:hover { border-color: var(--brand); }
.chip.on { background: var(--brand-soft); border-color: var(--brand); color: var(--brand-dark); font-weight: 600; }
.chip.on::before { content: "✓ "; }
.dup-cond { font-size: .88rem; opacity: .95; margin: 2px 0 4px 14px; }
.cond-line { font-size: .86rem; color: var(--muted); margin-top: 4px; }
.cond-line b { color: var(--ink-2); font-weight: 600; }
