:root {
  --orange: #f47920; --green: #3fbfa8; --ok: #2f8f3a; --blue: #4b67dd; --purple: #a561e6; --red: #d93a3a; --amber: #b86e00;
  --ink: #1a1a1a; --mute: #6b6f7b; --line: #e7e7ee; --bg: #f3f2f6; --card: #fff; --side: 236px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; font: 14px/1.45 Inter, "Segoe UI", Roboto, Arial, sans-serif; color: var(--ink); background: linear-gradient(135deg, #f4f2ec 0%, #f2f1f5 45%, #e9e6f5 100%) fixed; min-height: 100vh; }
a { color: var(--blue); text-decoration: none; }
h1 { font-size: 26px; font-weight: 600; margin: 0; }
h1 span { color: #9a9ca6; font-weight: 400; margin-left: 12px; }
h2 { font-size: 16px; margin: 22px 0 10px; }
h3 { font-size: 15px; margin: 0 0 10px; }
button, input, select, textarea { font: inherit; color: inherit; }
button, select, [data-row] { cursor: pointer; }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
.spacer { flex: 1; }
.red { color: var(--red) !important; }

/* Khung */
#side { position: fixed; inset: 0 auto 0 0; width: var(--side); background: var(--card); border-right: 1px solid var(--line); display: flex; flex-direction: column; z-index: 30; overflow-y: auto; }
.brand { display: flex; gap: 10px; align-items: center; padding: 16px; }
.brand small, .me small { display: block; color: var(--mute); }
.logo { background: var(--orange); color: #fff; font-weight: 800; border-radius: 10px; padding: 9px 7px; font-size: 14px; letter-spacing: .5px; border-bottom: 4px solid #4db848; }
.brand.big { padding: 0 0 18px; font-size: 17px; }
#side nav { flex: 1; padding: 0 10px; }
#side nav a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px; color: #43464f; }
#side nav a:hover { background: #f5f5fa; }
#side nav a.on { background: #eef0fd; color: var(--blue); font-weight: 600; }
#side nav em { margin-left: auto; background: var(--red); color: #fff; border-radius: 20px; font-style: normal; font-size: 11px; padding: 1px 7px; }
.me { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; flex-direction: column; align-items: flex-start; gap: 3px; }
main { margin-left: var(--side); padding: 22px 28px 60px; max-width: 1600px; }
#bottom, #veil { display: none; }

.page-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.actions.right { display: flex; justify-content: flex-end; margin-bottom: 10px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; margin-bottom: 14px; }
.card.pad { padding: 18px; }
.btn { border: 1px solid #d5d6e0; background: #fff; border-radius: 8px; padding: 8px 15px; display: inline-block; }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; font-weight: 600; }
.btn.danger { color: var(--red); border-color: #efc2c2; }
.btn:disabled { opacity: .6; }
.link { background: none; border: 0; padding: 2px 0; color: var(--blue); }
.icon-btn { border: 1px solid #d5d6e0; background: #fff; border-radius: 7px; min-width: 32px; height: 32px; }

.filters { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; align-items: center; }
.chip { border: 1px solid transparent; background: transparent; border-radius: 8px; padding: 7px 8px; color: var(--blue); max-width: 240px; }
.chip:hover { border-color: #d5d6e0; background: #fff; }
.chip.search { background: #fff; border-color: #d5d6e0; color: var(--ink); min-width: 240px; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; margin-bottom: 14px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-left: 4px solid var(--blue); border-radius: 10px; padding: 11px 14px; color: var(--ink); display: flex; flex-direction: column; }
.kpi span, .kpi small { color: var(--mute); }
.kpi b { font-size: 21px; }
.kpi.warn { border-left-color: var(--orange); }
.kpi.bad { border-left-color: var(--red); }
.kpi.bad b { color: var(--red); }

/* Thanh công cụ dòng thời gian */
.tl-bar { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; padding: 11px 18px; border-bottom: 1px solid var(--line); }
.pager { display: flex; align-items: center; gap: 8px; color: var(--mute); }
.pager span { min-width: 128px; text-align: center; }
.seg { display: inline-flex; background: #ededf2; border-radius: 7px; overflow: hidden; }
.seg button { border: 0; background: none; padding: 7px 14px; }
.seg button.on { background: var(--blue); color: #fff; }
.round { width: 34px; height: 34px; border-radius: 50%; border: 1px solid #d5d6e0; background: #fff; display: grid; place-items: center; }
.round.on { background: var(--blue); color: #fff; border-color: var(--blue); }
.switch { display: flex; align-items: center; gap: 8px; color: var(--mute); cursor: pointer; }
.switch input { position: absolute; opacity: 0; }
.switch span { width: 34px; height: 19px; border-radius: 20px; background: #c9cad4; position: relative; transition: .2s; }
.switch span::after { content: ""; position: absolute; width: 15px; height: 15px; border-radius: 50%; background: #fff; top: 2px; left: 2px; transition: .2s; }
.switch input:checked + span { background: var(--blue); }
.switch input:checked + span::after { left: 17px; }
.switch input:focus-visible + span { outline: 2px solid var(--blue); outline-offset: 2px; }

/* Dòng thời gian */
.gantt { overflow-x: auto; }
.g-inner { min-width: 900px; --gs: 270px; }
.g-head, .g-row { display: grid; grid-template-columns: var(--gs) 1fr; }
.g-head { height: 62px; border-bottom: 1px solid var(--line); }
.g-side { padding: 0 16px; display: flex; align-items: center; gap: 12px; border-right: 1px solid var(--line); position: sticky; left: 0; background: #fff; z-index: 3; min-width: 0; }
.g-head .g-track, .g-row .g-track { position: relative; margin-right: 14px; }
.sort { border: 1px solid #d5d6e0; border-radius: 7px; padding-left: 9px; color: var(--mute); }
.sort select { border: 0; background: none; padding: 6px; }
.g-month { position: absolute; top: 9px; padding-left: 6px; color: var(--mute); white-space: nowrap; }
.g-day { position: absolute; top: 33px; transform: translateX(-50%); color: var(--mute); font-size: 13px; }
.g-day.today { background: var(--orange); color: #fff; border-radius: 12px; padding: 0 6px; }
.g-body { position: relative; min-height: 120px; }
.g-bg { position: absolute; top: 0; bottom: 0; left: var(--gs); right: 14px; }
.g-bg i { position: absolute; top: 0; bottom: 0; background: #f5f5f8; }
.g-bg b { position: absolute; top: 0; bottom: 0; width: 2px; margin-left: -1px; background: var(--orange); opacity: .35; }
.g-row { height: 66px; position: relative; color: var(--ink); --c: var(--blue); }
.g-row.in { --c: var(--purple); }
.g-row.late { --c: var(--red); }
.g-row:hover .g-side { background: #f7f8ff; }
.c-icon { flex: none; width: 38px; height: 38px; border-radius: 9px; background: #23252b; color: #fff; display: grid; place-items: center; }
.c-text { min-width: 0; display: flex; flex-direction: column; line-height: 1.3; }
.c-text b { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.c-text span { color: var(--blue); }
.c-text small { color: var(--mute); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.g-line { position: absolute; top: 50%; margin-top: -1.5px; height: 3px; background: var(--c); }
.g-line.dotted { background: none; height: 0; border-top: 3px dotted var(--c); }
.g-mark { position: absolute; top: 50%; width: 24px; height: 24px; margin: -12px 0 0 -12px; border-radius: 50%; display: grid; place-items: center; color: #fff; z-index: 2; }
.g-mark.clock { background: var(--c); }
.g-mark.check { background: var(--green); }
.g-mark.edge { margin-left: 0; }
.g-mark svg { width: 20px; height: 20px; }
.g-dot { position: absolute; top: 50%; width: 11px; height: 11px; margin: -5.5px 0 0 -5.5px; border-radius: 50%; background: #fff; border: 3px solid var(--c); z-index: 1; }
.g-dot.late { border-color: var(--red); }
.legend { display: flex; gap: 18px; flex-wrap: wrap; padding: 10px 18px; border-top: 1px solid var(--line); color: var(--mute); font-size: 12px; }
.legend span { display: flex; align-items: center; gap: 6px; }
.legend .l { width: 18px; height: 3px; background: var(--blue); }
.legend .l.in { background: var(--purple); }
.legend .l.late { background: var(--red); }
.legend em { width: 18px; height: 18px; border-radius: 50%; color: #fff; display: grid; place-items: center; }
.legend em svg { width: 15px; height: 15px; }
.legend em.clock { background: var(--blue); }
.legend em.check { background: var(--green); }
.today-key { width: 3px; height: 15px; background: var(--orange); }
#tip { position: fixed; z-index: 100; background: #23252b; color: #fff; padding: 8px 11px; border-radius: 8px; white-space: pre-line; font-size: 12px; max-width: 290px; pointer-events: none; }

/* Bảng */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-weight: 600; font-size: 12px; color: var(--mute); background: #fafafc; padding: 10px 14px; white-space: nowrap; }
td { padding: 11px 14px; border-top: 1px solid var(--line); vertical-align: top; }
td small { display: block; color: var(--mute); margin-top: 2px; }
td.wide { min-width: 220px; }
tr[data-row]:hover { background: #f7f8ff; }
.num { white-space: nowrap; font-variant-numeric: tabular-nums; }
.clip { display: block; max-width: 360px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.badge { display: inline-block; font-size: 11.5px; font-weight: 600; padding: 2px 8px; border-radius: 20px; background: #eeeef3; color: #55586a; white-space: nowrap; }
.badge.ok { background: #e5f5e4; color: var(--ok); }
.badge.warn { background: #fff0dc; color: var(--amber); }
.badge.bad { background: #fde6e6; color: var(--red); }
.badge.info { background: #e8ecfd; color: var(--blue); }
.bar { display: inline-block; width: 70px; height: 6px; background: #e7e7ee; border-radius: 4px; overflow: hidden; vertical-align: middle; }
.bar i { display: block; height: 100%; background: var(--green); }
.empty { padding: 36px; text-align: center; color: var(--mute); }
.note { color: var(--mute); }

/* Cảnh báo, chi tiết */
.alerts { list-style: none; padding: 0; margin: 0; display: grid; gap: 9px; }
.alerts li { background: #fff; border: 1px solid var(--line); border-left: 4px solid var(--blue); border-radius: 10px; }
.alerts li.bad { border-left-color: var(--red); }
.alerts li.warn { border-left-color: var(--orange); }
.alerts a { display: block; padding: 11px 15px; color: var(--ink); }
.alerts b { display: block; margin-top: 5px; }
.alerts p { margin: 2px 0; }
.alerts small { color: var(--mute); }
.back { display: inline-block; margin-bottom: 8px; }
.sub { margin: -6px 0 14px; color: var(--mute); }
.tabs { display: flex; gap: 4px; overflow-x: auto; border-bottom: 1px solid #dcdce6; margin-bottom: 16px; }
.tabs a { padding: 9px 12px; color: var(--mute); white-space: nowrap; border-bottom: 3px solid transparent; }
.tabs a.on { color: var(--blue); border-color: var(--blue); font-weight: 600; }
.cols { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); gap: 18px; align-items: start; }
.cols h2 { margin-top: 0; }
dl { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 13px; margin: 0 0 12px; }
dt { color: var(--mute); font-size: 12px; }
dd { margin: 0; overflow-wrap: anywhere; }
.upload { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }

/* Biểu mẫu */
.form { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; align-content: start; }
.form.one { grid-template-columns: 1fr; }
.form .full { grid-column: 1 / -1; }
.form label { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; font-weight: 600; color: #4d4f5a; min-width: 0; }
input:not([type=checkbox]), select, textarea { border: 1px solid #cfd0da; border-radius: 8px; padding: 8px 10px; background: #fff; font-weight: 400; max-width: 100%; }
.chip:not(.search) { border-color: transparent; background: transparent; }
.sort select { border: 0; }
.form-actions { display: flex; gap: 10px; align-items: end; }
.form-error { color: var(--red); margin: 0; }
dialog { border: 0; border-radius: 14px; padding: 0; width: min(680px, calc(100vw - 20px)); max-height: 92vh; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(20, 20, 35, .45); }
.dlg-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: #fff; z-index: 2; }
.dlg-head h3 { margin: 0; }
.dlg-body { padding: 18px; }
.secret { font: 700 20px ui-monospace, Consolas, monospace; background: #f3f3f8; padding: 12px; border-radius: 8px; user-select: all; text-align: center; }
.toast { position: fixed; right: 18px; bottom: 80px; background: #23252b; color: #fff; padding: 11px 18px; border-radius: 9px; z-index: 200; max-width: calc(100vw - 36px); }
.toast.bad { background: var(--red); }
.login { min-height: 100vh; display: grid; place-items: center; padding: 18px; }
.login .card { width: min(380px, 100%); }
.login h1 { font-size: 20px; margin-bottom: 16px; }

/* Điện thoại, máy tính bảng */
@media (max-width: 960px) {
  .cols { grid-template-columns: 1fr; }
  #side { transform: translateX(-100%); transition: transform .2s; bottom: 0; }
  body.menu #side { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.2); }
  body.menu #veil { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 25; }
  main { margin: 0; padding: 14px 12px calc(86px + env(safe-area-inset-bottom)); }
  #bottom { display: flex; position: fixed; inset: auto 0 0; background: #fff; border-top: 1px solid var(--line); z-index: 20; padding-bottom: env(safe-area-inset-bottom); }
  #bottom a, #bottom button { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 2px; font-size: 11px; color: var(--mute); background: none; border: 0; }
  #bottom a.on { color: var(--blue); font-weight: 600; }
  #side { z-index: 30; }
}
@media (max-width: 640px) {
  h1 { font-size: 20px; }
  h1 span { display: block; margin: 0; font-size: 15px; }
  input, select, textarea { font-size: 16px !important; }
  .form { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: 1fr 1fr; }
  .kpi b { font-size: 17px; }
  .chip.search { min-width: 100%; }
  .tl-bar { padding: 10px; gap: 10px; }
  .g-inner { min-width: 1000px; --gs: 150px; }
  .c-icon { display: none; }
  .g-side { padding: 0 8px; }
  .sort select { width: 100px; }
  table, tbody, tr, td { display: block; width: 100%; }
  thead { display: none; }
  tr { border-top: 1px solid var(--line); padding: 8px 0; }
  td { border: 0; padding: 3px 12px; display: grid; grid-template-columns: 110px minmax(0, 1fr); gap: 0 8px; }
  td::before { content: attr(data-label); color: var(--mute); font-size: 12px; grid-column: 1; grid-row: 1 / span 3; }
  td > * { grid-column: 2; justify-self: start; }
  td.wide { min-width: 0; }
}
@media (max-width: 640px) {
  .filters .chip:not(.search) { flex: 1 1 45%; max-width: none; min-width: 0; background: #fff; border-color: #d5d6e0; }
}
