:root {
  --brand: #381011;
  --gold: #E9B93A;
  --gold-light: #F6D57A;
  --gold-soft: #F7EDD0;
  --wine: #6B1F27;
  --wine-ink: #4A1418;
  --bg: #FBF7EF;
  --card: #FFFFFF;
  --ink: #2A1A1B;
  --muted: #7A6A62;
  --line: #ECE2D2;
  --danger: #8E2320;
  --danger-line: #E7C2BE;
  --amber: #8A4B0F; --amber-bg: #FDEBD8;
  --red: #8E2320; --red-bg: #FBE3E1;
  --green: #1E5B34; --green-bg: #E3F1E7;
  --grey: #6B625C; --grey-bg: #EFEAE3;
  --skel: #F1E8DA; --sheen: #FFF6DD;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(56,16,17,.06), 0 4px 16px rgba(56,16,17,.06);
  --sidebar: 248px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Manrope', system-ui, -apple-system, 'Segoe UI', sans-serif;
  background: var(--bg); color: var(--ink);
  font-size: 15px; line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--wine); }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 22px; font-weight: 800; }
h2 { font-size: 17px; font-weight: 800; }
h3 { font-size: 15px; font-weight: 700; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.hidden { display: none !important; }

/* ---------- layout ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--brand); color: #fff;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; padding-top: calc(10px + env(safe-area-inset-top, 0px));
}
.topbar img { width: 38px; height: 38px; }
.topbar .title { font-weight: 800; font-size: 16px; color: var(--gold-light); letter-spacing: .2px; }
.topbar .sub { font-size: 12px; color: #E8D9C0; }
.topbar .grow { flex: 1; min-width: 0; }
.topbar .who { font-size: 13px; color: #F1E3C9; text-align: right; }

.shell { display: flex; min-height: 100vh; }
.sidebar { display: none; }
.main { flex: 1; min-width: 0; }
.page { padding: 16px; padding-bottom: calc(96px + var(--safe-b)); max-width: 1100px; margin: 0 auto; }
.page-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.page-head .grow { flex: 1; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  background: #fff; border-top: 1px solid var(--line);
  display: flex; padding-bottom: var(--safe-b);
}
.tabbar a {
  flex: 1; text-align: center; padding: 8px 2px 9px; text-decoration: none;
  color: var(--muted); font-size: 11.5px; font-weight: 700; position: relative;
}
.tabbar a svg { display: block; margin: 0 auto 2px; width: 24px; height: 24px; }
.tabbar a.on { color: var(--wine); }
.badge-dot {
  position: absolute; top: 4px; left: calc(50% + 6px);
  background: var(--danger); color: #fff; border-radius: 10px;
  font-size: 10.5px; min-width: 18px; padding: 1px 5px; line-height: 16px;
}

@media (min-width: 900px) {
  .sidebar {
    display: flex; flex-direction: column; width: var(--sidebar); flex-shrink: 0;
    background: var(--brand); color: #fff; position: sticky; top: 0; height: 100vh; padding: 20px 12px;
  }
  .sidebar .brand { display: flex; align-items: center; gap: 10px; padding: 0 8px 18px; }
  .sidebar .brand img { width: 48px; height: 48px; }
  .sidebar .brand .t { color: var(--gold-light); font-weight: 800; }
  .sidebar .brand .s { font-size: 12px; color: #E8D9C0; }
  .sidebar a {
    display: flex; align-items: center; gap: 10px; color: #F1E3C9; text-decoration: none;
    padding: 10px 12px; border-radius: 12px; font-weight: 700; position: relative;
  }
  .sidebar a svg { width: 20px; height: 20px; }
  .sidebar a:hover { background: rgba(255,255,255,.06); }
  .sidebar a.on { background: rgba(233,185,58,.16); color: var(--gold-light); }
  .sidebar .badge-dot { position: static; margin-left: auto; }
  .sidebar .foot { margin-top: auto; font-size: 13px; color: #E8D9C0; padding: 8px 12px; }
  .tabbar, .topbar.with-side { display: none; }
  .page { padding: 28px 32px 40px; }
}

/* ---------- cards & lists ---------- */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.card + .card { margin-top: 12px; }
.stack > * + * { margin-top: 12px; }
.grid2 { display: grid; grid-template-columns: 1fr; gap: 12px; }
@media (min-width: 700px) { .grid2 { grid-template-columns: 1fr 1fr; } }
.list { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.row {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px; border: 0; border-top: 1px solid var(--line);
  text-decoration: none; color: inherit; background: none; width: 100%; text-align: left; font: inherit;
}
.row:first-child { border-top: 0; }
button.row, a.row { cursor: pointer; }
button.row:active, a.row:active { background: #FDF9F1; }
.row .grow { flex: 1; min-width: 0; }
.row .name { font-weight: 700; }
.row .meta { font-size: 13px; color: var(--muted); }
.avatar {
  width: 38px; height: 38px; border-radius: 50%; flex-shrink: 0;
  background: var(--gold-soft); color: var(--wine-ink); display: grid; place-items: center; font-weight: 800;
}
.empty { text-align: center; padding: 28px 16px; color: var(--muted); }

/* ---------- pills ---------- */
.pill {
  display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; border-radius: 999px;
  font-size: 12.5px; font-weight: 700; white-space: nowrap;
}
.st-present { color: var(--green); background: var(--green-bg); }
.st-late, .st-half, .st-pending { color: var(--amber); background: var(--amber-bg); }
.st-absent { color: var(--red); background: var(--red-bg); }
.st-leave { color: var(--wine-ink); background: var(--gold-soft); }
.st-closed, .st-not_yet, .st-none, .st-upcoming { color: var(--grey); background: var(--grey-bg); }
.tag { white-space: nowrap; font-size: 11.5px; font-weight: 700; color: var(--wine); background: var(--gold-soft); border-radius: 6px; padding: 1px 6px; }

.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip-stat { background: var(--card); box-shadow: var(--shadow); border-radius: 14px; padding: 10px 14px; min-width: 92px; }
.chip-stat .n { font-size: 22px; font-weight: 800; }
.chip-stat .l { font-size: 12px; color: var(--muted); font-weight: 700; }
.chip-stat.green .n { color: var(--green); }
.chip-stat.amber .n { color: var(--amber); }
.chip-stat.red .n { color: var(--red); }

/* ---------- buttons & forms ---------- */
.btn {
  appearance: none; border: 0; border-radius: 12px; padding: 12px 18px; font: inherit; font-weight: 800;
  background: var(--wine); color: #fff; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  text-decoration: none; min-height: 46px;
}
.btn:active { background: var(--wine-ink); }
.btn svg { width: 20px; height: 20px; flex-shrink: 0; }
.btn[disabled] { opacity: .55; cursor: default; }
.btn.block { width: 100%; }
.btn.ghost { background: #fff; color: var(--wine); border: 1px solid var(--line); }
.btn.soft { background: var(--gold-soft); color: var(--wine-ink); }
.btn.danger { background: #fff; color: var(--danger); border: 1px solid var(--danger-line); }
.btn.small { padding: 7px 12px; min-height: 36px; font-size: 13.5px; border-radius: 10px; }
.btn.big { font-size: 18px; padding: 18px; min-height: 64px; border-radius: 16px; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-row > .btn { flex: 1; }

label.f { display: block; font-weight: 700; font-size: 13.5px; margin-bottom: 12px; }
label.f > span { display: block; margin-bottom: 5px; }
input, select, textarea {
  width: 100%; font: inherit; font-size: 16px; color: var(--ink); background: #fff;
  border: 1px solid var(--line); border-radius: 12px; padding: 11px 12px; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(233,185,58,.25); }
.check { display: flex; align-items: center; gap: 10px; font-weight: 600; margin-bottom: 12px; }
.check input { width: 20px; height: 20px; accent-color: var(--wine); }
.pin-input { letter-spacing: 10px; text-align: center; font-size: 22px; font-weight: 800; }
.err { color: var(--danger); font-weight: 700; font-size: 14px; margin: 6px 0 10px; }
.notice { background: var(--gold-soft); color: var(--wine-ink); border-radius: 12px; padding: 12px 14px; font-weight: 600; font-size: 14px; }
.notice.red { background: var(--red-bg); color: var(--red); }
.inline-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: flex; flex-direction: column; }
.login-band {
  background: var(--brand); color: #fff; text-align: center; padding: 36px 16px 56px;
  padding-top: calc(36px + env(safe-area-inset-top, 0px));
}
.login-band img { width: 112px; height: 112px; }
.login-band .t { color: var(--gold-light); font-weight: 800; font-size: 20px; margin-top: 8px; }
.login-band .s { color: #E8D9C0; font-size: 13px; }
.login-card { max-width: 420px; margin: -32px auto 24px; width: calc(100% - 32px); }

/* ---------- staff home ---------- */
.hero {
  background: linear-gradient(160deg, var(--brand), #4E1A1C); color: #fff; border-radius: 20px; padding: 18px;
  box-shadow: var(--shadow);
}
.hero .date { color: #E8D9C0; font-size: 13px; font-weight: 700; }
.hero .hi { color: var(--gold-light); font-size: 20px; font-weight: 800; margin: 2px 0 12px; }
.hero .times { display: flex; gap: 10px; margin-bottom: 14px; }
.hero .times > div { flex: 1; background: rgba(255,255,255,.07); border-radius: 12px; padding: 10px; }
.hero .times .k { font-size: 12px; color: #E8D9C0; font-weight: 700; }
.hero .times .v { font-size: 20px; font-weight: 800; }
.hero .btn { background: var(--gold); color: var(--brand); }
.hero .btn:active { background: var(--gold-light); }
.hero .pill { margin-bottom: 12px; }

/* ---------- calendar ---------- */
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal .dow { text-align: center; font-size: 11.5px; font-weight: 800; color: var(--muted); padding: 4px 0; }
.cal .d {
  aspect-ratio: 1 / 1; border-radius: 10px; display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-weight: 700; font-size: 14px; background: #fff; border: 1px solid var(--line); position: relative; padding: 0; color: inherit; font-family: inherit;
}
.cal .d.today { outline: 2px solid var(--gold); outline-offset: -1px; }
.cal .d .dot { width: 7px; height: 7px; border-radius: 50%; margin-top: 3px; }
.cal .d.present { background: var(--green-bg); border-color: transparent; color: var(--green); }
.cal .d.late, .cal .d.half, .cal .d.pending { background: var(--amber-bg); border-color: transparent; color: var(--amber); }
.cal .d.absent { background: var(--red-bg); border-color: transparent; color: var(--red); }
.cal .d.leave { background: var(--gold-soft); border-color: transparent; color: var(--wine-ink); }
.cal .d.closed { background: var(--grey-bg); border-color: transparent; color: var(--grey); }
.cal .d .lt { font-size: 9.5px; font-weight: 800; letter-spacing: .3px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.month-nav { display: flex; align-items: center; gap: 8px; }
.month-nav .lbl { font-weight: 800; min-width: 130px; text-align: center; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--line); background: #fff; cursor: pointer;
  display: grid; place-items: center; color: var(--wine); font-size: 18px; font-weight: 800; text-decoration: none;
}

/* ---------- table ---------- */
.table-wrap { overflow-x: auto; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); background: #FDFAF3; }
td.num, th.num { text-align: right; }
tr:last-child td { border-bottom: 0; }

/* ---------- scanner ---------- */
.scanner { position: fixed; inset: 0; background: #000; z-index: 60; display: flex; flex-direction: column; }
.scanner video { flex: 1; width: 100%; object-fit: cover; }
.scanner .frame {
  position: absolute; left: 50%; top: 42%; width: 64vmin; height: 64vmin; transform: translate(-50%, -50%);
  border: 3px solid var(--gold); border-radius: 22px; box-shadow: 0 0 0 100vmax rgba(0,0,0,.45);
}
.scanner .bar { position: absolute; left: 0; right: 0; bottom: 0; padding: 18px 16px calc(18px + var(--safe-b)); text-align: center; color: #fff; }
.scanner .bar p { margin: 0 0 12px; font-weight: 700; }

/* ---------- sheet / dialog ---------- */
.overlay { position: fixed; inset: 0; background: rgba(42,26,27,.45); z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.sheet {
  background: var(--bg); width: 100%; max-width: 520px; border-radius: 22px 22px 0 0; padding: 18px 16px calc(18px + var(--safe-b));
  max-height: 92vh; overflow-y: auto; animation: up .22s ease-out;
}
@media (min-width: 700px) { .overlay { align-items: center; } .sheet { border-radius: 22px; } }
@keyframes up { from { transform: translateY(30px); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet .sheet-head { display: flex; align-items: center; margin-bottom: 14px; }
.sheet .sheet-head h2 { flex: 1; }
.photo-preview { width: 100%; border-radius: 14px; display: block; margin-bottom: 12px; max-height: 320px; object-fit: cover; }

/* ---------- result ---------- */
.result { text-align: center; padding: 30px 16px; }
.result .tick { width: 92px; height: 92px; border-radius: 50%; display: grid; place-items: center; margin: 0 auto 14px; font-size: 46px; color: #fff; }
.result .tick.ok { background: #2F7A4A; }
.result .tick.warn { background: #C27A1E; }
.result .tick.bad { background: var(--danger); }
.result .big { font-size: 28px; font-weight: 800; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(84px + var(--safe-b)); transform: translateX(-50%); z-index: 80;
  background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 12px; font-weight: 700; font-size: 14px;
  max-width: calc(100% - 32px); box-shadow: var(--shadow);
}

/* ---------- loading: skeleton & progress thread ---------- */
.skel { background: var(--skel); border-radius: 12px; position: relative; overflow: hidden; }
.skel::after {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, var(--sheen), transparent);
  transform: translateX(-100%); animation: sheen 1.3s infinite;
}
@keyframes sheen { to { transform: translateX(100%); } }
.progress { position: fixed; top: 0; left: 0; right: 0; height: 3px; z-index: 90; pointer-events: none; overflow: hidden; }
.progress::before {
  content: ''; position: absolute; top: 0; height: 3px; width: 40%; left: -40%;
  background: linear-gradient(90deg, transparent, var(--gold), #FFF2C2, var(--gold), transparent);
  animation: thread 1s ease-in-out infinite;
}
@keyframes thread { to { left: 100%; } }
@media (prefers-reduced-motion: reduce) {
  .skel::after, .progress::before, .sheet { animation: none; }
}

/* ---------- print (QR poster) ---------- */
.qr-box { text-align: center; }
.qr-box svg { width: 220px; height: 220px; }
#print-area { display: none; }
@media print {
  body > *:not(#print-area) { display: none !important; }
  #print-area { display: block !important; text-align: center; padding-top: 40px; font-family: 'Manrope', sans-serif; color: #000; }
  #print-area img.logo { width: 120px; }
  #print-area svg { width: 360px; height: 360px; }
  #print-area h1 { font-size: 34px; margin: 10px 0; }
  #print-area p { font-size: 20px; }
}
