:root {
  --bg: #f5f2ec;
  --card: #ffffff;
  --text: #1a1a1a;
  --muted: #6b6b6b;
  --gold: #b8954a;
  --dark: #111111;
  --red: #c62828;
  --red-bg: #fdecea;
  --green: #2e7d32;
  --line: #e4ded3;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { font-size: 19px; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  line-height: 1.4;
}
.hidden { display: none !important; }
h1, h2, h3 { margin: 0 0 .6rem; }
h2 { font-size: 1.4rem; }
h3 { font-size: 1.1rem; }

/* Nut */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  min-height: 52px; padding: .6rem 1.1rem; border: 1px solid var(--line); border-radius: 14px;
  background: #fff; color: var(--text); font-size: 1rem; font-weight: 600; text-decoration: none; cursor: pointer;
}
.btn.primary { background: var(--dark); color: #fff; border-color: var(--dark); }
.btn.big { width: 100%; min-height: 60px; font-size: 1.15rem; }
.btn.block { width: 100%; margin-bottom: .6rem; }
.btn.small { min-height: 44px; padding: .4rem 1rem; }
.btn.danger { color: var(--red); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.icon { min-height: 52px; min-width: 52px; font-size: 1.5rem; padding: 0; background: transparent; border: 0; color: #fff; }

/* Form */
label { display: block; margin-bottom: .9rem; font-weight: 600; }
.label { font-weight: 600; margin-bottom: .4rem; }
input, select {
  display: block; width: 100%; margin-top: .35rem; min-height: 54px; padding: .5rem .8rem;
  font-size: 1.05rem; border: 1px solid #cfc7b8; border-radius: 12px; background: #fff; color: var(--text);
  -webkit-appearance: none; appearance: none;
}
select { background-image: linear-gradient(45deg, transparent 50%, #666 50%), linear-gradient(135deg, #666 50%, transparent 50%);
  background-position: calc(100% - 22px) 50%, calc(100% - 16px) 50%; background-size: 6px 6px; background-repeat: no-repeat; padding-right: 2.4rem; }
label.check { display: flex; align-items: center; gap: .6rem; }
label.check input { width: 28px; min-height: 28px; height: 28px; margin: 0; -webkit-appearance: checkbox; appearance: checkbox; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: .7rem; }
.err { color: var(--red); min-height: 1.2em; margin: .2rem 0 .6rem; font-weight: 600; }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: .4rem; margin-bottom: 1rem; }
.seg button { min-height: 52px; border: 1px solid #cfc7b8; background: #fff; border-radius: 12px; font-size: .95rem; font-weight: 600; color: var(--text); }
.seg button.active { background: var(--dark); color: #fff; border-color: var(--dark); }

/* Dang nhap */
#login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.login-box { width: 100%; max-width: 420px; text-align: center; }
.login-box form { text-align: left; margin-top: 1rem; }
.logo { width: 96px; height: 96px; border-radius: 22px; }
.login-box h1 { font-size: 1.6rem; margin-top: .6rem; }
.link { display: inline-block; margin-top: 1.2rem; color: var(--text); font-weight: 600; padding: .6rem; }

/* Man hinh chinh */
#main { padding-bottom: calc(150px + env(safe-area-inset-bottom)); }
.top {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between;
  background: var(--dark); color: #fff; padding: calc(8px + env(safe-area-inset-top)) 16px 8px;
}
.hello { font-size: 1.05rem; font-weight: 600; }
.hello small { display: block; color: var(--gold); font-weight: 700; letter-spacing: .08em; font-size: .75rem; }
.pushbar { display: flex; align-items: center; justify-content: space-between; gap: .6rem; background: #fff6df; padding: .6rem 16px; border-bottom: 1px solid var(--line); font-weight: 600; }
.filter { padding: .6rem 16px 0; }
.filter select { margin: 0; }
#view { padding: 12px 16px; max-width: 720px; margin: 0 auto; }
.empty { text-align: center; color: var(--muted); padding: 3rem 1rem; font-size: 1.1rem; }
.group-title { font-weight: 700; color: var(--muted); margin: 1rem 0 .5rem; font-size: .9rem; text-transform: uppercase; letter-spacing: .04em; }

/* The viec */
.task {
  display: flex; align-items: center; gap: .8rem; background: var(--card); border: 1px solid var(--line);
  border-radius: 16px; padding: .8rem .8rem .8rem 1rem; margin-bottom: .7rem;
}
.task .info { flex: 1; min-width: 0; }
.task .title { font-size: 1.1rem; font-weight: 700; word-wrap: break-word; }
.task .meta { color: var(--muted); font-size: .9rem; margin-top: .2rem; }
.task .meta b { color: var(--text); }
.task.overdue { background: var(--red-bg); border-color: #f2b8b5; }
.task.overdue .title, .task.overdue .when { color: var(--red); }
.task .when.late { color: var(--red); font-weight: 700; }
.donebtn {
  flex: none; width: 72px; height: 72px; border-radius: 50%; border: 3px solid var(--green); background: #fff;
  color: var(--green); font-size: .8rem; font-weight: 800; line-height: 1.1; cursor: pointer;
}
.donebtn:active { background: var(--green); color: #fff; }
.task.done .title { text-decoration: line-through; color: var(--muted); }
.task .mini { flex: none; display: flex; flex-direction: column; gap: .3rem; }
.task .mini .btn { min-height: 44px; font-size: .85rem; padding: .3rem .7rem; }
.tag { display: inline-block; font-size: .75rem; font-weight: 700; padding: .1rem .5rem; border-radius: 99px; background: #efe7d6; color: #6d5523; margin-left: .3rem; }
.tag.red { background: var(--red); color: #fff; }

/* Tong hop */
.periods { display: grid; grid-template-columns: repeat(3, 1fr); gap: .4rem; margin-bottom: .7rem; }
.datenav { display: grid; grid-template-columns: 56px 1fr 56px; gap: .4rem; align-items: center; margin-bottom: .4rem; }
.datenav .btn { padding: 0; font-size: 1.4rem; }
.range { text-align: center; font-weight: 700; margin-bottom: 1rem; }
.stat { background: #fff; border: 1px solid var(--line); border-radius: 16px; padding: .8rem 1rem; margin-bottom: .7rem; }
.stat.total { background: var(--dark); color: #fff; border-color: var(--dark); }
.stat .name { font-weight: 700; font-size: 1.1rem; margin-bottom: .5rem; }
.nums { display: grid; grid-template-columns: repeat(3, 1fr); text-align: center; gap: .4rem; }
.nums div { background: rgba(0,0,0,.04); border-radius: 12px; padding: .4rem .2rem; }
.stat.total .nums div { background: rgba(255,255,255,.1); }
.nums b { display: block; font-size: 1.6rem; }
.nums span { font-size: .8rem; }
.nums .ok b { color: var(--green); }
.nums .bad b { color: var(--red); }
.stat.total .nums .ok b { color: #7ed187; }
.stat.total .nums .bad b { color: #ff8a80; }
.substat { font-size: .82rem; color: var(--muted); margin-top: .4rem; }
.stat.total .substat { color: #bbb; }

/* FAB + tabs */
.fab {
  position: fixed; right: 16px; bottom: calc(84px + env(safe-area-inset-bottom)); z-index: 6;
  min-height: 60px; padding: 0 1.4rem; border: 0; border-radius: 30px; background: var(--gold); color: #fff;
  font-size: 1.1rem; font-weight: 800; box-shadow: 0 6px 18px rgba(0,0,0,.25);
}
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; display: grid; grid-template-columns: repeat(3, 1fr);
  background: #fff; border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
.tabs button { min-height: 68px; border: 0; background: transparent; font-size: 1.02rem; font-weight: 700; color: var(--muted); border-top: 4px solid transparent; }
.tabs button.active { color: var(--dark); border-top-color: var(--gold); }

/* Sheet */
.sheet { position: fixed; inset: 0; z-index: 20; background: rgba(0,0,0,.45); display: flex; align-items: flex-end; justify-content: center; }
.sheet-body {
  width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto; background: var(--bg);
  border-radius: 22px 22px 0 0; padding: 20px 16px calc(16px + env(safe-area-inset-bottom));
}
.sheet-body.tall { min-height: 70vh; }
.card { background: #fff; border: 1px solid var(--line); border-radius: 16px; padding: 1rem; margin: 1rem 0; }
.staff { display: flex; align-items: center; gap: .6rem; background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: .7rem .8rem; margin-bottom: .5rem; }
.staff .info { flex: 1; min-width: 0; }
.staff .info small { color: var(--muted); display: block; }
.staff.locked { opacity: .55; }
.staff .btn { min-height: 44px; font-size: .85rem; padding: .3rem .6rem; }

.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(160px + env(safe-area-inset-bottom)); z-index: 30;
  background: var(--dark); color: #fff; padding: .9rem 1rem; border-radius: 14px; text-align: center; font-weight: 600;
}
