/* =====================================================================
   FFA-RTS · Web quản trị — CSS viết tay (không dùng framework)
   Màu chủ đạo: xanh đậm #1F3864 · xanh #2E5C8A · đỏ nhấn #C00000
   Nền xám nhạt #F5F7FA. Font hệ thống. Dùng được trên màn hình nhỏ.
   ===================================================================== */

:root {
  --navy: #1F3864;
  --blue: #2E5C8A;
  --blue-soft: #E8EEF6;
  --red: #C00000;
  --bg: #F5F7FA;
  --card: #FFFFFF;
  --line: #DFE4EC;
  --text: #1B2432;
  --muted: #6B7688;
  --green: #2E7D32;
  --orange: #E68A00;
  --yellow: #C9A227;
  --grey: #8A93A3;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(31, 56, 100, .06), 0 4px 14px rgba(31, 56, 100, .07);
  --sidebar-w: 232px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  font-size: 14px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
}

a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; font-weight: 700; }
b, .strong { font-weight: 600; }
.dim { color: var(--muted); font-size: 12.5px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; }
.grow { flex: 1 1 auto; }
.text-danger { color: var(--red); font-weight: 600; }
.empty { color: var(--muted); padding: 18px 4px; text-align: center; }
.note {
  color: var(--muted); font-size: 12.5px; margin: 4px 2px 24px;
  border-left: 3px solid var(--line); padding-left: 10px;
}

/* ------------------------------------------------------------ BỐ CỤC */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--navy);
  color: #DCE4F0;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 40;
}

.brand { display: flex; gap: 10px; align-items: center; padding: 16px 14px; }
.brand-mark {
  width: 38px; height: 38px; border-radius: 9px;
  background: #FFFFFF; color: var(--navy);
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; letter-spacing: .5px; font-size: 13px;
}
.brand-mark.lg { width: 52px; height: 52px; font-size: 16px; background: var(--navy); color: #fff; }
.brand-name { font-weight: 700; color: #fff; }
.brand-sub { font-size: 11.5px; color: #A9BAD6; }

.nav { flex: 1 1 auto; padding: 6px 8px 16px; overflow-y: auto; }
.nav-title {
  font-size: 10.5px; letter-spacing: .12em; text-transform: uppercase;
  color: #8FA3C6; margin: 14px 8px 6px;
}
.nav-item {
  display: flex; align-items: center; gap: 9px;
  padding: 9px 10px; border-radius: 8px;
  color: #DCE4F0; font-size: 13.5px;
}
.nav-item:hover { background: rgba(255, 255, 255, .09); text-decoration: none; }
.nav-item.active { background: var(--blue); color: #fff; font-weight: 600; }
.nav-item .ico { width: 16px; text-align: center; opacity: .85; }
.badge-num {
  margin-left: auto; background: var(--red); color: #fff;
  border-radius: 10px; padding: 1px 7px; font-size: 11.5px; font-weight: 700;
}
.sidebar-foot {
  padding: 12px 14px; font-size: 11.5px; color: #93A6C7;
  border-top: 1px solid rgba(255, 255, 255, .12);
}

.main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px; background: #fff; border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.topbar-title { font-weight: 700; color: var(--navy); font-size: 15px; }
.burger { display: none; font-size: 20px; cursor: pointer; padding: 2px 8px; }

.userbox { display: flex; align-items: center; gap: 8px; }
.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--blue); color: #fff; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.avatar.lg { width: 52px; height: 52px; font-size: 20px; }
.user-name { font-weight: 600; font-size: 13px; }
.user-role { font-size: 11.5px; color: var(--muted); }

.content { padding: 16px; max-width: 1560px; width: 100%; }

.nav-toggle { display: none; }
.nav-scrim { display: none; }

/* -------------------------------------------------------------- THẺ */
.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  margin-bottom: 16px; overflow: hidden;
}
.card-head {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 12px 14px; border-bottom: 1px solid var(--line); background: #FBFCFE;
}
.card-head h2 { font-size: 14.5px; color: var(--navy); }
.card-head .link { margin-left: auto; font-size: 13px; }
.card-head .dim { margin-left: auto; }
.card-foot { padding: 10px 14px; border-top: 1px solid var(--line); display: flex; gap: 8px; flex-wrap: wrap; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }

/* ------------------------------------------- ƯU TIÊN NGOẠI LỆ (đầu trang) */
.headline {
  background: linear-gradient(100deg, var(--navy), var(--blue));
  color: #fff; border-radius: var(--radius); padding: 20px 22px;
  margin-bottom: 16px; box-shadow: var(--shadow);
}
.headline h1 { font-size: 26px; line-height: 1.25; font-weight: 700; }
.headline h1 b { color: #FFD54F; font-size: 30px; }
.headline p { margin: 8px 0 0; color: #D7E1F1; font-size: 13.5px; }
.headline.headline-ok { background: linear-gradient(100deg, #24603E, #2E7D32); }
.headline.headline-ok h1 b { color: #FFF; }
.headline .tag { margin-right: 6px; }

/* ------------------------------------------------------- THẺ CHỈ SỐ */
.stat-row {
  display: grid; gap: 12px; margin-bottom: 16px;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}
.stat {
  background: #fff; border: 1px solid var(--line); border-left: 4px solid var(--blue);
  border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow);
}
.stat-num { font-size: 24px; font-weight: 700; color: var(--navy); line-height: 1.2; }
.stat-lb { font-size: 12.5px; color: var(--muted); }
.stat.stat-warn { border-left-color: var(--orange); }
.stat.stat-warn .stat-num { color: var(--orange); }
.stat.stat-danger { border-left-color: var(--red); }
.stat.stat-danger .stat-num { color: var(--red); }

/* ------------------------------------------------------------- NÚT */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: #fff; color: var(--navy);
  border-radius: 8px; padding: 7px 12px; font-size: 13px; font-weight: 600;
  cursor: pointer; font-family: inherit; white-space: nowrap;
}
.btn:hover { background: var(--blue-soft); text-decoration: none; }
.btn-sm { padding: 5px 10px; font-size: 12.5px; }
.btn-primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn-primary:hover { background: var(--navy); border-color: var(--navy); }
.btn-danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn-danger:hover { background: #9A0000; }
.btn-ghost { background: transparent; }
.btn-block { width: 100%; padding: 11px; font-size: 14.5px; }
.btn-link {
  background: none; border: none; padding: 0; font-size: 12.5px;
  color: var(--blue); cursor: pointer; text-decoration: underline; font-family: inherit;
}

/* ----------------------------------------------------------- BỘ LỌC */
.filters {
  display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap;
  padding: 12px 14px;
}
.field { display: flex; flex-direction: column; gap: 4px; }
.field > span { font-size: 11.5px; color: var(--muted); font-weight: 600; }
.field.inline { min-width: 130px; }
.field.grow-field { flex: 1 1 260px; }
input[type="text"], input[type="search"], input[type="password"],
input[type="date"], input[type="month"], select {
  border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px;
  font-size: 13.5px; font-family: inherit; background: #fff; color: var(--text);
  min-height: 34px; max-width: 100%;
}
input:focus, select:focus { outline: 2px solid var(--blue-soft); border-color: var(--blue); }
.inline-form { display: inline-flex; margin: 0; }

/* ---------------------------------------------------------- BẢNG DỮ LIỆU */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th, .table td {
  padding: 9px 10px; text-align: left; vertical-align: top;
  border-bottom: 1px solid var(--line);
}
.table thead th {
  background: #F2F5F9; color: var(--navy); font-size: 11.5px;
  text-transform: uppercase; letter-spacing: .04em; white-space: nowrap;
  position: sticky; top: 0; z-index: 2;
}
.table tbody tr:hover { background: #F8FAFD; }
.table .num { text-align: right; white-space: nowrap; }
.table .col-action { white-space: nowrap; }
.table tr.row-off { opacity: .55; }
.table tr.row-done { background: #FAFBFC; }

/* --------------------------------------------------------- NHÃN, CỜ */
.tag {
  display: inline-block; border-radius: 999px; padding: 2px 9px;
  font-size: 11.5px; font-weight: 700; white-space: nowrap; border: 1px solid transparent;
}
.tag.sev-critical { background: #FBE3E3; color: var(--red); border-color: #F3C2C2; }
.tag.sev-high     { background: #FDEEDD; color: #B35B00; border-color: #F6D7B4; }
.tag.sev-medium   { background: #FDF6D9; color: #8A6D1F; border-color: #F0E3AF; }
.tag.sev-low      { background: #EEF0F4; color: #59616F; border-color: #DFE3EA; }
.tag.done         { background: #E4F1E6; color: var(--green); border-color: #C7E2CC; }
a.tag:hover { text-decoration: none; filter: brightness(.96); }

.rule {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: #EFF2F7; border: 1px solid var(--line); border-radius: 5px;
  padding: 1px 6px; font-size: 11.5px; color: var(--navy);
}

/* Điểm tin cậy: >=85 xanh lá · 70–84 vàng · 50–69 cam · <50 đỏ */
.score {
  display: inline-block; min-width: 38px; text-align: center;
  border-radius: 7px; padding: 3px 8px; font-weight: 700; font-size: 13px;
}
.score.sc-good { background: #E4F1E6; color: var(--green); }
.score.sc-warn { background: #FDF6D9; color: #8A6D1F; }
.score.sc-bad  { background: #FDEEDD; color: #B35B00; }
.score.sc-crit { background: #FBE3E3; color: var(--red); }
.score.sc-na   { background: #EEF0F4; color: var(--muted); }

.score-big {
  font-size: 40px; font-weight: 800; line-height: 1;
  border-radius: 12px; padding: 10px 18px; display: inline-block;
}
.score-big.sc-good { background: #E4F1E6; color: var(--green); }
.score-big.sc-warn { background: #FDF6D9; color: #8A6D1F; }
.score-big.sc-bad  { background: #FDEEDD; color: #B35B00; }
.score-big.sc-crit { background: #FBE3E3; color: var(--red); }
.score-big.sc-na   { background: #EEF0F4; color: var(--muted); }

.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
.dot.on { background: var(--green); }
.dot.off { background: var(--grey); }

/* -------------------------------------------------- DANH SÁCH CẢNH BÁO */
.alert-list, .plain-list { list-style: none; margin: 0; padding: 0; }
.alert-item {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 11px 14px; border-bottom: 1px solid var(--line);
  border-left: 4px solid var(--grey);
}
.alert-item.sev-critical { border-left-color: var(--red); }
.alert-item.sev-high     { border-left-color: var(--orange); }
.alert-item.sev-medium   { border-left-color: var(--yellow); }
.alert-item.sev-low      { border-left-color: var(--grey); }
.alert-main { flex: 1 1 auto; min-width: 0; }
.alert-top { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.alert-top .time { color: var(--muted); font-size: 12px; margin-left: auto; }
.alert-title { font-weight: 600; margin-top: 3px; }
.alert-sub { font-size: 12.5px; color: var(--muted); }

.evidence { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.ev {
  background: #F4F6FA; border: 1px solid var(--line); border-radius: 6px;
  padding: 2px 7px; font-size: 11.5px; color: #475061;
}
.ev b { color: var(--navy); font-weight: 600; }

.resolve-form { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin: 0 0 4px; }
.resolve-form input { min-width: 150px; }
.resolved-note {
  margin-top: 6px; font-size: 12px; color: var(--green);
  background: #F1F8F2; border-radius: 6px; padding: 4px 8px;
}

.plain-list li {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
  padding: 8px 14px; border-bottom: 1px solid var(--line);
}

/* ----------------------------------------------------------- BẢN ĐỒ */
.map { width: 100%; height: 360px; background: #E9EDF3; }
.map-lg { height: 420px; }
.map-xl { height: 560px; }
.map-off { display: flex; align-items: center; justify-content: center; }
.map-off-msg { color: var(--muted); text-align: center; font-size: 13px; padding: 20px; }
.leaflet-container { font: inherit; }

.pin-icon span {
  display: flex; align-items: center; justify-content: center;
  width: 22px; height: 22px; border-radius: 5px; color: #fff;
  font-size: 11px; font-weight: 700; border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .35);
}

.legend { margin-left: auto; display: flex; gap: 12px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 4px; vertical-align: -2px; }
.lg-line  { background: var(--blue); height: 4px !important; border-radius: 2px; }
.lg-stop  { background: #2E7D32; border-radius: 50%; }
.lg-visit { background: #7B2FBF; }
.lg-att   { background: var(--navy); }

.slider-bar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 10px 14px; border-top: 1px solid var(--line); background: #FBFCFE;
}
.slider-bar input[type="range"] { flex: 1 1 240px; accent-color: var(--blue); }
.slider-info { font-size: 12.5px; color: var(--navy); font-weight: 600; min-width: 200px; }

/* ------------------------------------------------ TRANG LỘ TRÌNH NGÀY */
.day-head { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; padding: 14px; }
.day-emp { display: flex; gap: 12px; align-items: center; flex: 1 1 320px; }
.day-emp h1 { font-size: 20px; color: var(--navy); }
.day-score { text-align: center; }

.day-grid { display: grid; grid-template-columns: 380px 1fr; gap: 16px; align-items: start; }
.timeline-card { max-height: 760px; overflow: auto; }

.timeline { list-style: none; margin: 0; padding: 8px 14px 14px 8px; }
.tl-item { position: relative; padding: 0 0 16px 24px; border-left: 2px solid var(--line); }
.tl-item:last-child { border-left-color: transparent; padding-bottom: 4px; }
.tl-dot {
  position: absolute; left: -7px; top: 3px; width: 12px; height: 12px;
  border-radius: 50%; background: var(--blue); border: 2px solid #fff;
  box-shadow: 0 0 0 1px var(--line);
}
.tl-checkin  .tl-dot { background: var(--navy); }
.tl-checkout .tl-dot { background: var(--red); }
.tl-visit    .tl-dot { background: #7B2FBF; }
.tl-time { font-weight: 700; color: var(--navy); font-size: 13px; }
.tl-title { font-weight: 600; }
.tl-sub { font-size: 12.5px; }

.thumbs { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.thumbs img {
  width: 68px; height: 68px; object-fit: cover; border-radius: 7px;
  border: 1px solid var(--line); background: #EEF1F5;
}

/* --------------------------------------------------------- BẢNG CÔNG */
.table-timesheet th, .table-timesheet td { padding: 6px 8px; }
.table-timesheet .day-col { text-align: center; min-width: 46px; font-size: 11.5px; padding: 4px 2px; }
.table-timesheet .day-col.weekend { background: #F2F4F8; }
.table-timesheet .day-col.late { background: #FDF6D9; font-weight: 700; }
.table-timesheet .day-col.has-alert { box-shadow: inset 0 -3px 0 var(--red); }
.table-timesheet .sticky-col {
  position: sticky; left: 0; background: #fff; z-index: 1; min-width: 190px;
  border-right: 1px solid var(--line);
}
.table-timesheet thead .sticky-col { background: #F2F5F9; z-index: 3; }

.pager { display: flex; gap: 10px; align-items: center; justify-content: center; padding: 12px; }

/* ------------------------------------------------------- ĐĂNG NHẬP */
.login-body {
  background: linear-gradient(140deg, var(--navy), var(--blue) 60%, #47739F);
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
}
.login-wrap { width: 100%; max-width: 400px; padding: 20px; }
.login-card {
  background: #fff; border-radius: 14px; padding: 24px;
  box-shadow: 0 12px 40px rgba(10, 24, 50, .35); display: flex;
  flex-direction: column; gap: 14px;
}
.login-brand { display: flex; align-items: center; gap: 12px; }
.login-title { font-size: 19px; font-weight: 800; color: var(--navy); }
.login-sub { font-size: 12px; color: var(--muted); }
.login-note { font-size: 11.5px; color: var(--muted); margin: 0; }
.login-note.dim { color: #97A0B0; }
.login-foot { text-align: center; color: #C8D4E6; font-size: 12px; margin-top: 14px; }
.alert-box {
  border-radius: 8px; padding: 9px 12px; font-size: 13px;
  background: #FBE3E3; color: var(--red); border: 1px solid #F3C2C2;
}

/* ------------------------------------------------------ MÀN HÌNH NHỎ */
@media (max-width: 1100px) {
  .day-grid { grid-template-columns: 1fr; }
  .grid-2 { grid-template-columns: 1fr; }
  .timeline-card { max-height: none; }
}

@media (max-width: 820px) {
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0;
    transform: translateX(-100%); transition: transform .18s ease-out;
  }
  .nav-toggle:checked ~ .layout .sidebar { transform: translateX(0); }
  .nav-toggle:checked ~ .nav-scrim {
    display: block; position: fixed; inset: 0;
    background: rgba(16, 26, 45, .45); z-index: 35;
  }
  .burger { display: inline-block; }
  .content { padding: 12px; }
  .headline { padding: 16px; }
  .headline h1 { font-size: 20px; }
  .headline h1 b { font-size: 24px; }
  .user-meta { display: none; }
  .map-xl { height: 380px; }
  .stat-num { font-size: 20px; }
}

@media print {
  .sidebar, .topbar, .filters, .btn, .slider-bar { display: none !important; }
  .card { break-inside: avoid; box-shadow: none; }
  body { background: #fff; }
}
