:root {
  /* Nhận diện Hamec (giống lichlamviec.hamec.vn) */
  --brand: #3e7b1d; --brand-2: #4a8f22; --brand-soft: #eaf3e2; --brand-ink: #1d4d1f; --accent: #e31e25;
  --bg: #f5f7f2; --surface: #ffffff; --surface-2: #f7f9f4; --border: #e1e8da; --border-2: #cdd8c4;
  --text: #1a2614; --muted: #5f6d57; --faint: #93a08a;
  --warn: #b45309; --warn-bg: #fff4e0; --danger: #c0392b; --danger-bg: #fdecea; --ok: #15803d; --ok-bg: #e5f6ea; --info: #1d4ed8; --info-bg: #e8effd;
  --shadow: 0 1px 2px rgba(16, 40, 28, .05), 0 4px 16px rgba(16, 40, 28, .05);
  --r: 14px; --r-s: 9px;
  --tab-h: 62px;
  color-scheme: light;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.5 'Be Vietnam Pro', system-ui, -apple-system, 'Segoe UI', sans-serif; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 21px; font-weight: 700; letter-spacing: -.01em; }
h2 { font-size: 17px; font-weight: 600; }
h3 { font-size: 15px; font-weight: 600; }
p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
.muted { color: var(--muted); } .faint { color: var(--faint); }
.small { font-size: 13px; } .xs { font-size: 12px; }
.row { display: flex; align-items: center; } .grow { flex: 1; min-width: 0; }
.gap-s { gap: 6px; } .gap { gap: 12px; }
.stack { display: flex; flex-direction: column; gap: 12px; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.ic { flex: none; }

.loading { display: flex; gap: 10px; align-items: center; justify-content: center; padding: 48px; color: var(--muted); }
.spin { width: 18px; height: 18px; border: 2px solid var(--border-2); border-top-color: var(--brand); border-radius: 50%; animation: spin .7s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Nút & ô nhập ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 16px; border-radius: 11px; border: 1px solid var(--border-2); background: var(--surface); font-weight: 600; cursor: pointer; text-decoration: none; transition: background .15s; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--brand-2); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn-block { width: 100%; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 13px; font-weight: 600; color: var(--muted); }
.input { height: 46px; padding: 0 14px; border-radius: 11px; border: 1px solid var(--border-2); background: var(--surface); width: 100%; font-size: 16px; }
.input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.msg { padding: 10px 12px; border-radius: var(--r-s); font-size: 14px; }
.msg.err { background: var(--danger-bg); color: var(--danger); }
.msg.ok { background: var(--ok-bg); color: var(--ok); }
.msg.info { background: var(--info-bg); color: var(--info); }

/* ---------- Đăng nhập ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border); border-radius: 18px; box-shadow: var(--shadow); padding: 26px 20px; }
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; }
.login-brand img { width: 48px; height: 48px; }
.seg { display: grid; grid-template-columns: 1fr 1fr; background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: 4px; margin-bottom: 16px; }
.seg button { border: 0; background: transparent; border-radius: 9px; min-height: 38px; font-weight: 600; color: var(--muted); cursor: pointer; }
.seg button.on { background: var(--surface); color: var(--brand-ink); box-shadow: var(--shadow); }

/* ---------- Khung app ---------- */
.top { position: sticky; top: 0; z-index: 20; background: rgba(245, 247, 242, .92); backdrop-filter: blur(8px); border-bottom: 1px solid var(--border); padding: calc(10px + env(safe-area-inset-top)) 16px 10px; display: flex; align-items: center; gap: 10px; }
.top img { width: 30px; height: 30px; }
.top .who { line-height: 1.2; min-width: 0; }
.top .who b { display: block; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top .who small { color: var(--muted); font-size: 12px; }
.main { padding: 16px 16px calc(var(--tab-h) + 24px + env(safe-area-inset-bottom)); max-width: 760px; margin: 0 auto; }
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; background: var(--surface); border-top: 1px solid var(--border); display: grid; grid-template-columns: repeat(5, 1fr); padding-bottom: env(safe-area-inset-bottom); }
.tabbar a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; height: var(--tab-h); color: var(--faint); text-decoration: none; font-size: 11.5px; font-weight: 600; }
.tabbar a.on { color: var(--brand); }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); box-shadow: var(--shadow); padding: 16px; }
.page-head { margin-bottom: 14px; }
.page-head p { margin-top: 3px; }
.list { display: flex; flex-direction: column; }
.list a, .list .item { display: flex; align-items: center; gap: 12px; padding: 14px 4px; border-bottom: 1px solid var(--border); text-decoration: none; color: inherit; }
.list a:last-child, .list .item:last-child { border-bottom: 0; }
.chip { display: inline-flex; align-items: center; height: 24px; padding: 0 9px; border-radius: 99px; background: var(--brand-soft); color: var(--brand-ink); font-size: 12px; font-weight: 600; }
.chip.warn { background: var(--warn-bg); color: var(--warn); }
.soon { text-align: center; padding: 36px 16px; display: flex; flex-direction: column; gap: 10px; align-items: center; }
.soon .badge { width: 56px; height: 56px; border-radius: 16px; background: var(--brand-soft); color: var(--brand); display: grid; place-items: center; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 14px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; font-weight: 500; text-align: right; }

/* Màn hình rộng: thanh điều hướng thành cột trái */
/* Thanh bên máy tính — ẩn trên điện thoại */
.sidebar { display: none; }
.cols { display: grid; gap: 14px; }
@media (min-width: 1024px) {
  :root { --side: 248px; }
  .top, .tabbar { display: none; }
  .sidebar { display: flex; flex-direction: column; position: fixed; inset: 0 auto 0 0; width: var(--side); background: var(--surface); border-right: 1px solid var(--border); padding: 18px 12px 14px; z-index: 30; }
  .brand { display: flex; gap: 10px; align-items: center; padding: 2px 8px 18px; color: var(--text); text-decoration: none; }
  .brand img { width: 40px; height: 40px; }
  .brand b { display: block; font-size: 16px; color: var(--brand-ink); } .brand small { color: var(--muted); font-size: 12px; }
  .side-nav { display: flex; flex-direction: column; gap: 2px; flex: 1; overflow: auto; }
  .side-nav a { display: flex; align-items: center; gap: 11px; height: 42px; padding: 0 12px; border-radius: 10px; color: var(--muted); text-decoration: none; font-weight: 600; font-size: 14.5px; }
  .side-nav a:hover { background: var(--surface-2); color: var(--text); }
  .side-nav a.on { background: var(--brand-soft); color: var(--brand-ink); box-shadow: inset 3px 0 0 var(--brand); }
  .nav-sep { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--faint); padding: 16px 12px 4px; font-weight: 700; }
  .side-foot { border-top: 1px solid var(--border); padding-top: 12px; display: flex; align-items: center; gap: 6px; }
  .side-foot .me { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; padding: 6px 8px; border-radius: 10px; color: var(--text); text-decoration: none; }
  .side-foot .me:hover, .side-foot .me.on { background: var(--surface-2); }
  .side-foot .me b { display: block; font-size: 13.5px; line-height: 1.25; }
  .side-foot .me small { display: block; color: var(--muted); font-size: 11.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .avatar { flex: none; width: 34px; height: 34px; border-radius: 50%; background: var(--brand-soft); color: var(--brand-ink); display: grid; place-items: center; font-weight: 700; }
  .main { margin: 0 0 0 var(--side); padding: 28px 40px 48px; max-width: calc(1120px + var(--side)); }
  .cols { grid-template-columns: 1fr 1fr; align-items: start; }
  .stats { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)) !important; }
}
}

/* ---------- Màn hình dữ liệu ---------- */
.btn-icon { width: 40px; min-height: 40px; padding: 0; font-size: 22px; line-height: 1; }
.month-nav { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.month-nav b { font-size: 16px; }
.seg-s { margin: 0; }
.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.stat { display: flex; flex-direction: column; gap: 2px; padding: 14px; text-decoration: none; color: inherit; min-width: 0; }
.stat small { color: var(--muted); font-size: 12.5px; font-weight: 500; }
.stat b { font-size: 20px; font-weight: 700; letter-spacing: -.01em; overflow-wrap: anywhere; }
.card > h3 { margin-bottom: 10px; }
.card > .row h3 { margin-bottom: 0; }
.card > .row { margin-bottom: 10px; }
.shift { display: flex; gap: 10px; padding: 8px 10px; border-radius: 10px; background: var(--brand-soft); border-left: 3px solid var(--brand); min-width: 0; flex: 1; }
.shift + .shift { margin-top: 6px; }
.shift.off { background: var(--surface-2); border-left-color: var(--faint); color: var(--muted); }
.stack-s { display: flex; flex-direction: column; gap: 6px; }
.date-badge { flex: none; width: 46px; text-align: center; font-weight: 700; font-size: 14px; line-height: 1.15; }
.date-badge small { display: block; font-size: 11px; color: var(--muted); font-weight: 600; }
.card .row.gap + .row.gap { margin-top: 8px; }
.item.day.today .date-badge { color: var(--brand); }
.empty-s { padding: 8px 0; }
.chip.bad { background: var(--danger-bg); color: var(--danger); }
.seg-4 { grid-template-columns: repeat(4, 1fr); }
.seg-4 button { font-size: 13px; padding: 0 2px; }
.chip.grey { background: var(--surface-2); color: var(--muted); }
.hi { color: var(--danger); font-weight: 600; }
.msg.info a { color: inherit; }

/* Lịch tháng */
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; padding: 10px; }
.cal-h { text-align: center; font-size: 11.5px; font-weight: 600; color: var(--muted); padding: 2px 0 4px; }
.cal-cell { aspect-ratio: 1; border: 1px solid transparent; border-radius: 10px; background: var(--surface-2); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-weight: 600; cursor: pointer; padding: 0; }
.cal-cell.out { opacity: .35; }
.cal-cell.today span { color: var(--brand); }
.cal-cell.sel { border-color: var(--brand); background: var(--brand-soft); }
.dot { display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--brand); }
.dot.off { background: var(--faint); }
.legend { display: flex; align-items: center; gap: 6px; }
.legend .dot + * { margin-right: 10px; }

/* Bảng công */
.table-wrap { overflow-x: auto; margin: 0 -4px; }
.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; font-variant-numeric: tabular-nums; }
.tbl th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 6px 4px; border-bottom: 1px solid var(--border); }
.tbl td { padding: 8px 4px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.tbl tr:last-child td { border-bottom: 0; }

/* Phiếu lương */
.pay { padding: 0; overflow: hidden; }
.pay-head { width: 100%; display: flex; align-items: center; gap: 10px; padding: 16px; border: 0; background: none; cursor: pointer; text-align: left; font-size: 15px; }
.pay-head:disabled { cursor: default; color: var(--muted); }
.pay-detail:not(:empty) { padding: 0 16px 16px; display: flex; flex-direction: column; gap: 8px; border-top: 1px solid var(--border); padding-top: 14px; }
.pay-detail h3 { margin-top: 6px; }
.pay-net { display: flex; flex-direction: column; } .pay-net small { color: var(--muted); }
.pay-net .amt { font-size: 26px; font-weight: 700; color: var(--brand-ink); }
.pay-split { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.pay-split > div { background: var(--surface-2); border-radius: 10px; padding: 10px; display: flex; flex-direction: column; font-weight: 600; }
.pay-split small { color: var(--muted); font-weight: 500; font-size: 12px; }
.pay-row { display: flex; justify-content: space-between; gap: 12px; font-size: 14px; font-variant-numeric: tabular-nums; }
.pay-row.total { border-top: 1px dashed var(--border-2); padding-top: 6px; font-weight: 700; }
.amt .mask { display: none; letter-spacing: 2px; }
.masked .amt .real { display: none; }
.masked .amt .mask { display: inline; }

@media (min-width: 640px) { .stats { grid-template-columns: repeat(3, minmax(0, 1fr)); } }

/* Đơn từ: lọc theo loại + người đang giữ đơn */
.pills { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; margin: -4px 0 12px; scrollbar-width: none; }
.pills::-webkit-scrollbar { display: none; }
.pill { flex: none; border: 1px solid var(--border); background: var(--surface); color: var(--muted); border-radius: 99px; height: 32px; padding: 0 12px; font-weight: 600; font-size: 13px; cursor: pointer; }
.pill.on { background: var(--brand-soft); color: var(--brand-ink); border-color: transparent; }
.hold { color: var(--warn); margin-top: 2px; }

/* KPI phòng khám */
.kpi { display: flex; flex-direction: column; gap: 10px; text-decoration: none; color: inherit; }
.kpi h3 { margin: 0; }
.kpi-big { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.kpi-big b { font-size: 30px; line-height: 1; letter-spacing: -.02em; }
.kpi-bar { position: relative; height: 10px; border-radius: 99px; background: var(--surface-2); overflow: visible; }
.kpi-bar .fill { position: absolute; inset: 0 auto 0 0; border-radius: 99px; background: var(--brand); }
.kpi-bar .fill.behind { background: var(--warn); }
.kpi-bar .fill.none { background: var(--faint); }
.kpi-bar .mark { position: absolute; top: -4px; bottom: -4px; width: 2px; background: var(--text); border-radius: 2px; opacity: .55; }
.kpi-need { display: flex; flex-direction: column; gap: 2px; background: var(--brand-soft); border-radius: 12px; padding: 10px 12px; }
.kpi-need small { color: var(--brand-ink); font-weight: 600; }
.kpi-need b { font-size: 20px; color: var(--brand-ink); }
.kpi-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.kpi-grid small { display: block; color: var(--muted); font-size: 12px; }
.kpi-grid b { font-size: 14px; }
.kpi-days .bars { position: relative; height: 90px; display: flex; align-items: flex-end; gap: 3px; margin: 6px 0 4px; border-bottom: 1px solid var(--border); }
.kpi-days .b { flex: 1; min-width: 3px; max-width: 18px; background: var(--warn); opacity: .75; border-radius: 3px 3px 0 0; }
.kpi-days .b.up { background: var(--brand); opacity: 1; }
.kpi-days .goal { position: absolute; left: 0; right: 0; border-top: 1.5px dashed var(--muted); }
.kpi-link { gap: 12px; text-decoration: none; color: inherit; }
.kpi-list { display: grid; gap: 12px; }
@media (min-width: 1024px) { .kpi-list { grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; } }

/* Quản trị */
.seg-3 { grid-template-columns: repeat(3, 1fr); }
.tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.tags .chip { height: 20px; font-size: 11px; padding: 0 7px; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 16px; letter-spacing: .05em; user-select: all; }
.perm-row { display: flex; align-items: center; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--border); }
.perm-row:last-child { border-bottom: 0; }
.perm-group .nav-sep { padding: 10px 0 2px; display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--faint); font-weight: 700; }
.dot { flex: none; width: 9px; height: 9px; border-radius: 50%; background: var(--border); }
.dot.on { background: var(--ok); }
.input-s { width: auto; min-width: 118px; height: 36px; padding: 0 8px; font-size: 13px; }
.checks { display: flex; flex-wrap: wrap; gap: 8px 16px; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; }
.matrix th, .matrix td { white-space: nowrap; font-size: 12.5px; }
.matrix td:first-child { white-space: normal; min-width: 220px; }
.matrix td.c { text-align: center; color: var(--ok); font-weight: 700; }
.warn-t { color: var(--danger); }
.btn-s { min-height: 30px; height: 30px; padding: 0 10px; font-size: 12px; }
.matrix input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--brand); cursor: pointer; }
