:root {
  --bg: #f2f4f8; --card: #fff; --text: #1a2330; --muted: #677485; --line: #e3e8ee;
  --primary: #1565c0; --primary-dark: #0d4f9e; --green: #18803b; --green-bg: #e5f5ea; --red: #c62828; --red-bg: #fdecea;
  --orange: #a65800; --orange-bg: #fff3df; --radius: 16px;
  --safe-b: env(safe-area-inset-bottom, 0px); --tabbar-h: 64px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; background: var(--bg); color: var(--text); font-size: 17px; line-height: 1.45; }
body.no-scroll { overflow: hidden; }
body.loading { cursor: progress; }
body.loading .punch-btn, body.loading .punch-btn-alt { opacity: .6; pointer-events: none; }
a { color: var(--primary); }
[hidden] { display: none !important; }
.small { font-size: 13px; }
.muted { color: var(--muted); font-size: 15px; }

/* ---------- Thanh trên ---------- */
.topbar { background: var(--primary); color: #fff; padding: 10px 14px; padding-top: calc(10px + env(safe-area-inset-top, 0px)); display: flex; align-items: center; gap: 10px; position: sticky; top: 0; z-index: 20; }
.topbar .brand { font-weight: 700; color: #fff; text-decoration: none; margin-right: auto; display: flex; align-items: center; gap: 8px; font-size: 17px; min-width: 0; }
.topbar .brand span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .logo { width: 28px; height: 28px; border-radius: 7px; }
.topbar .who { font-size: 14px; opacity: .9; }
.topbar form { margin: 0; }
.topbar button { background: transparent; color: #fff; border: 1px solid rgba(255,255,255,.6); border-radius: 8px; padding: 5px 10px; font-size: 14px; cursor: pointer; }
nav.menu { background: #fff; border-bottom: 1px solid var(--line); display: flex; overflow-x: auto; white-space: nowrap; }
nav.menu a { padding: 12px 14px; text-decoration: none; color: var(--text); font-size: 15px; border-bottom: 3px solid transparent; }
nav.menu a.active { border-bottom-color: var(--primary); color: var(--primary); font-weight: 600; }

/* ---------- Thanh menu dưới (điện thoại) ---------- */
.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); box-shadow: 0 -2px 10px rgba(0,0,0,.05); }
.tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; height: var(--tabbar-h); text-decoration: none; color: var(--muted); font-size: 12px; font-weight: 500; }
.tabbar a .ic { font-size: 23px; line-height: 1; position: relative; filter: grayscale(1); opacity: .75; }
.tabbar a.active { color: var(--primary); font-weight: 700; }
.tabbar a.active .ic { filter: none; opacity: 1; }
.tabbar .badge { position: absolute; top: -6px; right: -14px; font-size: 11px; min-width: 18px; line-height: 18px; filter: none; }
body.has-tabbar main { padding-bottom: calc(var(--tabbar-h) + var(--safe-b) + 24px); }
.desktop-only { display: none !important; }
@media (min-width: 900px) {
  .desktop-only { display: flex !important; }
  nav.menu.desktop-only { display: flex !important; }
  .mobile-only { display: none !important; }
  body.has-tabbar main { padding-bottom: 40px; }
}

.badge { display: inline-block; min-width: 20px; padding: 0 6px; border-radius: 10px; background: var(--red); color: #fff; font-size: 12px; text-align: center; line-height: 20px; font-weight: 700; }
main { max-width: 1100px; margin: 0 auto; padding: 14px 12px 40px; }
main.narrow { max-width: 520px; }
h1 { font-size: 22px; margin: 4px 0 14px; }
h2 { font-size: 18px; margin: 20px 0 10px; }
.card { background: var(--card); border-radius: var(--radius); padding: 16px; box-shadow: 0 1px 3px rgba(0,0,0,.06); margin-bottom: 12px; }
.alert { padding: 13px 15px; border-radius: 12px; margin-bottom: 12px; font-weight: 500; }
.alert.ok { background: var(--green-bg); color: var(--green); }
.alert.error { background: var(--red-bg); color: var(--red); }
.alert.warn { background: var(--orange-bg); color: var(--orange); }

/* ---------- Biểu mẫu ---------- */
label { display: block; font-weight: 600; margin: 12px 0 5px; font-size: 15px; }
input[type=text], input[type=password], input[type=number], input[type=date], input[type=month], input[type=time], select, textarea {
  width: 100%; min-height: 48px; padding: 11px 13px; border: 1px solid #c6cfd9; border-radius: 10px; font-size: 17px; background: #fff; font-family: inherit; color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 3px solid rgba(21,101,192,.25); border-color: var(--primary); }
textarea { min-height: 130px; }
.check { display: flex; align-items: center; gap: 10px; font-weight: normal; margin: 14px 0; min-height: 32px; }
.check input { width: 24px; height: 24px; flex: 0 0 auto; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 0; border-radius: 12px; min-height: 48px; padding: 10px 18px; font-size: 17px; font-weight: 600; cursor: pointer; background: var(--primary); color: #fff; text-decoration: none; font-family: inherit; }
.btn:active { transform: scale(.98); }
.btn.block { display: flex; width: 100%; }
.btn.secondary { background: #e7ecf2; color: var(--text); }
.btn.danger { background: var(--red); }
.btn.green { background: var(--green); }
.btn.small { min-height: 38px; padding: 6px 12px; font-size: 15px; }
.btn.big { min-height: 56px; font-size: 18px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.row > * { flex: 1 1 140px; }
.row > .auto { flex: 0 0 auto; }
.row-btns { display: flex; gap: 8px; margin-top: 10px; }

/* ---------- Đăng nhập ---------- */
.login-logo { text-align: center; margin: 18px 0 14px; font-weight: 700; font-size: 20px; color: var(--primary); }
.login-logo img { width: 72px; height: 72px; border-radius: 18px; box-shadow: 0 4px 14px rgba(21,101,192,.3); display: block; margin: 0 auto 8px; }

/* ---------- Chấm công ---------- */
.punch-card { background: #fff; border-radius: 22px; padding: 18px 16px 16px; text-align: center; box-shadow: 0 2px 10px rgba(0,0,0,.06); }
.punch-card .hello { font-size: 18px; }
.punch-card .clock { font-size: 56px; font-weight: 800; letter-spacing: 1px; font-variant-numeric: tabular-nums; line-height: 1.1; margin: 6px 0 10px; }
.state-chip { display: inline-block; padding: 6px 14px; border-radius: 20px; font-weight: 600; font-size: 15px; }
.state-chip.in { background: var(--green-bg); color: var(--green); }
.state-chip.off { background: #edf1f5; color: var(--muted); }
.net { margin: 14px 0 4px; font-size: 15px; border-radius: 12px; padding: 10px; }
.net.ok { color: var(--green); }
.net.bad { background: var(--red-bg); color: var(--red); }
.punch-btn { display: block; width: 100%; border: 0; border-radius: 20px; padding: 0; height: 120px; margin-top: 14px; font-size: 30px; font-weight: 800; letter-spacing: 1px; color: #fff; cursor: pointer; font-family: inherit; box-shadow: 0 6px 16px rgba(0,0,0,.15); }
.punch-btn.in { background: linear-gradient(180deg, #22a04c, var(--green)); }
.punch-btn.out { background: linear-gradient(180deg, #e04141, var(--red)); }
.punch-btn:active { transform: scale(.97); }
.punch-btn:disabled { background: #b8c1cc; box-shadow: none; }
.punch-btn-alt { display: block; width: 100%; margin-top: 10px; background: none; border: 1px solid #c6cfd9; border-radius: 14px; min-height: 48px; font-size: 16px; color: var(--muted); font-family: inherit; cursor: pointer; }
.punch-btn-alt:disabled { opacity: .5; }
.install-banner { background: #e8f1fc; box-shadow: none; font-size: 15px; }
.timeline { background: #fff; border-radius: var(--radius); overflow: hidden; box-shadow: 0 1px 3px rgba(0,0,0,.06); }
.tl-item { display: flex; justify-content: space-between; align-items: center; padding: 13px 15px; border-bottom: 1px solid var(--line); gap: 8px; }
.tl-item:last-child { border-bottom: 0; }
.tl-times { font-size: 18px; font-variant-numeric: tabular-nums; }
.tl-meta { display: flex; gap: 8px; align-items: center; color: var(--muted); font-size: 14px; }

/* ---------- Tấm trượt từ đáy (xác nhận) ---------- */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(15,25,40,.5); z-index: 50; display: flex; align-items: flex-end; justify-content: center; animation: fade .15s; }
.sheet { background: #fff; width: 100%; max-width: 520px; border-radius: 22px 22px 0 0; padding: 22px 18px calc(18px + var(--safe-b)); text-align: center; animation: up .2s ease-out; }
.sheet h2 { margin: 6px 0 4px; font-size: 24px; }
.sheet .punch-btn { height: 76px; font-size: 22px; margin: 18px 0 10px; }
.sheet-icon { width: 64px; height: 64px; border-radius: 50%; margin: 0 auto; display: flex; align-items: center; justify-content: center; font-size: 30px; }
.sheet-icon.out { background: var(--red-bg); color: var(--red); }
.steps-list { text-align: left; font-size: 17px; line-height: 1.9; padding-left: 24px; }
.ios-share { display: inline-block; border: 1px solid #9aa5b1; border-radius: 6px; padding: 0 6px; font-size: 14px; }
@keyframes up { from { transform: translateY(100%); } to { transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop { 0% { transform: scale(.4); opacity: 0; } 70% { transform: scale(1.1); } 100% { transform: scale(1); opacity: 1; } }

/* ---------- Màn hình kết quả ---------- */
.result-overlay { position: fixed; inset: 0; z-index: 60; display: flex; align-items: center; justify-content: center; padding: 24px; animation: fade .15s; }
.result-overlay.ok { background: var(--green); }
.result-overlay.error { background: var(--red); }
.result-overlay.warn { background: #c27400; }
.result-box { color: #fff; text-align: center; width: 100%; max-width: 420px; }
.result-icon { width: 120px; height: 120px; border-radius: 50%; background: rgba(255,255,255,.22); margin: 0 auto 18px; display: flex; align-items: center; justify-content: center; font-size: 70px; font-weight: 800; animation: pop .35s ease-out; }
.result-title { font-size: 30px; font-weight: 800; }
.result-big { font-size: 64px; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1.1; margin: 4px 0; }
.result-text { font-size: 18px; opacity: .95; margin: 8px 0 28px; }
.result-box .btn { background: #fff; color: var(--text); min-height: 56px; font-size: 19px; }

/* ---------- Bảng (máy tính) ---------- */
table { width: 100%; border-collapse: collapse; background: #fff; }
th, td { padding: 9px 9px; border-bottom: 1px solid var(--line); text-align: left; font-size: 14px; vertical-align: middle; }
th { background: #f0f3f7; font-weight: 600; white-space: nowrap; }
td.num, th.num { text-align: right; }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: var(--radius); box-shadow: 0 1px 3px rgba(0,0,0,.06); margin-bottom: 14px; }
.tag { display: inline-block; padding: 3px 9px; border-radius: 10px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.tag.open { background: #e3f0ff; color: var(--primary); }
.tag.pending { background: var(--orange-bg); color: var(--orange); }
.tag.approved { background: var(--green-bg); color: var(--green); }
.tag.rejected { background: #eceff1; color: var(--muted); }
.tag.off { background: var(--red-bg); color: var(--red); }
.raw { font-variant-numeric: tabular-nums; }

/* ---------- Duyệt công (thẻ) ---------- */
.approve-head { margin-bottom: 12px; }
.date-nav { margin: 0; }
.dep-select { margin-bottom: 8px; font-weight: 600; }
.dep-name { font-weight: 700; font-size: 18px; margin-bottom: 8px; }
.date-row { display: flex; align-items: stretch; gap: 8px; }
.nav-arrow { flex: 0 0 52px; display: flex; align-items: center; justify-content: center; background: #fff; border-radius: 12px; font-size: 30px; text-decoration: none; color: var(--primary); box-shadow: 0 1px 3px rgba(0,0,0,.06); min-height: 52px; }
.date-pick { flex: 1; position: relative; background: #fff; border-radius: 12px; display: flex; align-items: center; justify-content: center; font-weight: 700; margin: 0; box-shadow: 0 1px 3px rgba(0,0,0,.06); min-height: 52px; font-size: 16px; }
.date-pick input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; }
.month-nav { margin-bottom: 12px; }
.chips { display: flex; flex-wrap: nowrap; overflow-x: auto; gap: 6px; margin-top: 10px; align-items: center; padding-bottom: 2px; }
.chips a { padding: 7px 12px; border-radius: 16px; background: var(--orange-bg); color: var(--orange); text-decoration: none; font-size: 14px; font-weight: 600; white-space: nowrap; }
.chips a.cur { outline: 2px solid var(--orange); }
.chips .muted { white-space: nowrap; font-size: 14px; }
.emp-card { background: #fff; border-radius: var(--radius); box-shadow: 0 1px 3px rgba(0,0,0,.06); margin-bottom: 12px; overflow: hidden; }
.emp-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 12px 14px; background: #f6f8fb; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.emp-total { font-size: 14px; color: var(--green); }
.shift-card { padding: 12px 14px 14px; border-bottom: 1px solid var(--line); border-left: 4px solid transparent; }
.shift-card:last-child { border-bottom: 0; }
.shift-card.status-pending, .shift-card.status-open { border-left-color: #f0a030; }
.shift-card.status-approved { border-left-color: var(--green); }
.shift-card.status-rejected { opacity: .65; }
.shift-card.changed { background: #fffbea; }
.shift-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; font-size: 15px; }
.hint { font-size: 14px; border-radius: 8px; padding: 6px 10px; margin-top: 8px; }
.hint.warn { background: var(--orange-bg); color: var(--orange); }
.time-edit { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px; margin-top: 10px; }
.te { min-width: 0; }
.te-label { font-size: 13px; color: var(--muted); font-weight: 600; margin-bottom: 4px; }
.te.dur { grid-column: 1 / -1; display: flex; align-items: baseline; gap: 8px; }
.dur-val { font-size: 18px; font-weight: 700; color: var(--primary); }
.stepper { display: flex; align-items: stretch; border: 1px solid #c6cfd9; border-radius: 12px; overflow: hidden; background: #fff; }
.stepper button { flex: 0 0 38px; border: 0; background: #edf1f6; font-size: 24px; font-weight: 700; color: var(--primary); cursor: pointer; padding: 0; }
.stepper button:active { background: #d8e2ee; }
.stepper input[type=time] { border: 0; border-radius: 0; text-align: center; padding: 6px 2px; min-height: 50px; font-size: 19px; font-weight: 700; min-width: 0; width: 100%; flex: 1 1 auto; -webkit-appearance: none; appearance: none; }
.stepper input[type=time]::-webkit-calendar-picker-indicator { display: none; }
.shift-card .note { margin-top: 10px; min-height: 42px; font-size: 15px; padding: 8px 12px; }
.shift-actions { display: flex; gap: 8px; margin-top: 10px; }
.shift-actions .btn.big { flex: 1; }
.sticky-action { position: sticky; bottom: calc(var(--tabbar-h) + var(--safe-b) + 8px); z-index: 10; padding-top: 4px; }
.sticky-action .btn { box-shadow: 0 6px 18px rgba(24,128,59,.35); }
@media (min-width: 900px) {
  .sticky-action { bottom: 12px; }
  .time-edit { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1fr); }
  .te.dur { grid-column: auto; display: block; }
}

/* ---------- Lịch sử theo ngày ---------- */
.day-card { background: #fff; border-radius: var(--radius); box-shadow: 0 1px 3px rgba(0,0,0,.06); margin-bottom: 10px; overflow: hidden; }
.day-head { display: flex; justify-content: space-between; align-items: center; padding: 11px 14px; background: #f6f8fb; border-bottom: 1px solid var(--line); gap: 8px; }
.day-total .ot { color: var(--orange); font-size: 14px; font-weight: 700; }
.day-shift { display: flex; justify-content: space-between; align-items: center; padding: 11px 14px; border-bottom: 1px solid var(--line); gap: 10px; font-variant-numeric: tabular-nums; }
.day-shift:last-child { border-bottom: 0; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(100px, 1fr)); gap: 10px; margin-bottom: 12px; }
.stat { background: #fff; border-radius: var(--radius); padding: 13px; box-shadow: 0 1px 3px rgba(0,0,0,.06); }
.stat .v { font-size: 26px; font-weight: 800; }
.stat .k { color: var(--muted); font-size: 13px; }

/* ---------- Trang Tài khoản / Thêm ---------- */
.profile { display: flex; gap: 14px; align-items: center; }
.profile .avatar { width: 56px; height: 56px; border-radius: 50%; background: var(--primary); color: #fff; font-size: 24px; font-weight: 700; display: flex; align-items: center; justify-content: center; flex: 0 0 auto; }
.profile .name { font-weight: 700; font-size: 19px; }
.list { background: #fff; border-radius: var(--radius); overflow: hidden; box-shadow: 0 1px 3px rgba(0,0,0,.06); margin-bottom: 12px; }
.list a { display: flex; align-items: center; gap: 14px; padding: 0 16px; min-height: 56px; text-decoration: none; color: var(--text); border-bottom: 1px solid var(--line); font-size: 17px; }
.list a:last-child { border-bottom: 0; }
.list a:active { background: #f2f5f9; }
.list .ic { width: 26px; text-align: center; font-size: 20px; }
.list .chev { margin-left: auto; color: #b0bac6; font-size: 24px; }

.kv { display: grid; grid-template-columns: 1fr auto; gap: 0; }
.kv div { padding: 11px 0; border-bottom: 1px solid var(--line); }
.kv div:nth-child(even) { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
code { background: #eef2f6; padding: 1px 6px; border-radius: 5px; font-size: 14px; }
details summary { cursor: pointer; font-weight: 600; padding: 6px 0; min-height: 32px; }
@media print { .topbar, nav.menu, .tabbar, .no-print { display: none !important; } body { background: #fff; } }
