:root {
    color-scheme: light;
    --bg: #f4f5f1;
    --surface: #fff;
    --ink: #1d251c;
    --muted: #5d6659;
    --line: #e1e5db;
    --accent: #d6ed7a;
    --green: #315d28;
    --green-bg: #eef6e7;
    --amber: #80590a;
    --amber-bg: #fff4db;
    --red: #a02524;
    --red-bg: #fff0ed;
    font-family: Inter, 'Segoe UI', sans-serif;
    font-size: 14px;
    font-synthesis: none;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--ink); }
button { font: inherit; cursor: pointer; }
a { color: var(--green); text-underline-offset: .23em; }
:focus-visible { outline: 2px solid #64842a; outline-offset: 3px; }

.topbar { background: var(--surface); border-bottom: 1px solid var(--line); }
.topbar-inner, .page { width: min(1200px, calc(100% - 64px)); margin-inline: auto; }
.topbar-inner { min-height: 72px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand strong { display: block; font-size: 1.34rem; font-weight: 800; letter-spacing: -.055em; }
.brand span:not(.brand-mark) { color: var(--muted); display: block; font-size: .73rem; margin-top: 2px; }
.brand-mark { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 12px; background: #243021; }
.brand-mark i { width: 21px; height: 23px; background: var(--accent); clip-path: polygon(50% 0, 95% 17%, 95% 58%, 83% 76%, 50% 100%, 17% 76%, 5% 58%, 5% 17%); display: grid; place-items: center; }
.brand-mark i::after { content: ''; width: 10px; height: 6px; border: solid #263421; border-width: 0 0 2px 2px; transform: translateY(-1px) rotate(-45deg); }

.chip { display: inline-flex; align-items: center; gap: 7px; width: fit-content; min-height: 27px; padding: 4px 10px; border: 1px solid #e7eae3; border-radius: 30px; color: var(--muted); background: #f4f5f1; white-space: nowrap; font-size: .74rem; font-weight: 650; }
.chip::before { content: ''; width: 6px; height: 6px; border-radius: 50%; flex: none; background: #899385; }
.chip[data-state='online'] { border-color: #dcead4; background: var(--green-bg); color: var(--green); }
.chip[data-state='online']::before { background: #578b44; }
.chip[data-state='error'] { border-color: #f5d7d3; background: var(--red-bg); color: var(--red); }
.chip[data-state='error']::before { background: #cb5551; }
.chip[data-state='offline'] { border-color: #eee3d4; background: #faf4ea; color: #795921; }
.chip[data-state='offline']::before { background: #b68a46; }

.page { padding-block: 34px 45px; }
.page-heading { display: flex; justify-content: space-between; align-items: end; gap: 20px; margin-bottom: 25px; }
h1, h2, h3, p { margin: 0; }
h1 { font-size: clamp(2.12rem, 4vw, 3rem); line-height: 1.07; font-weight: 800; letter-spacing: -.068em; }
.page-heading p { color: var(--muted); margin-top: 10px; line-height: 1.55; }
.update-time { text-align: right; flex: none; }
.update-time span, .update-time strong { display: block; }
.update-time span { color: var(--muted); font-size: .75rem; margin-bottom: 6px; }
.update-time strong { font-variant-numeric: tabular-nums; font-weight: 650; }

.overview { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); border: 1px solid var(--line); border-radius: 15px; background: var(--surface); margin-bottom: 29px; }
.overview-item { min-width: 0; min-height: 77px; padding: 14px 20px; display: flex; align-items: center; gap: 12px; }
.overview-item + .overview-item { border-left: 1px solid var(--line); }
.overview-item div > span, .overview-item strong { display: block; }
.overview-item div > span { font-size: .77rem; color: var(--muted); margin-bottom: 5px; }
.overview-item strong { font-size: .99rem; font-weight: 750; }
[data-tone='good'] { color: var(--green); }
[data-tone='warn'] { color: var(--amber); }
[data-tone='bad'] { color: var(--red); }
.overview-icon { width: 37px; height: 37px; flex: none; display: flex; align-items: center; justify-content: center; border-radius: 10px; color: #4c623e; background: #edf2e8; }
.signal { align-items: end; gap: 2px; padding-bottom: 12px; }
.signal i { width: 3px; height: 5px; border-radius: 1px; background: currentColor; }
.signal i:nth-child(2) { height: 9px; }
.signal i:nth-child(3) { height: 13px; }
.buckle::before { content: ''; width: 15px; height: 12px; border: 2px solid currentColor; border-radius: 4px; }
.buckle::after { content: ''; width: 6px; height: 2px; margin-left: -8px; background: currentColor; }
.alert-icon { font-size: .88rem; font-weight: 800; position: relative; }
.alert-icon::before { content: ''; position: absolute; inset: 10px; border-radius: 50%; border: 1.5px solid currentColor; }

.fall-alert { position: sticky; top: 10px; z-index: 500; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 18px; margin-bottom: 16px; border: 1px solid #efc0ba; border-left: 4px solid #b73734; border-radius: 12px; background: var(--red-bg); color: var(--red); box-shadow: 0 3px 14px #4e241c1a; }
.fall-alert strong { font-size: 1.08rem; }
.fall-alert p { margin-top: 5px; font-size: .86rem; color: #7d3430; }
.fall-alert button { padding: 6px 11px; border: 1px solid #e9b7b1; border-radius: 7px; color: inherit; background: #fff9f7; }
.fall-alert button:hover { background: #ffe5df; }

.section-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
h2 { font-size: 1.3rem; font-weight: 750; letter-spacing: -.033em; }
.section-heading > span, .panel-heading > span:not(.chip) { font-size: .78rem; color: var(--muted); }
.device-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.panel { min-width: 0; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); box-shadow: 0 2px 5px #2d392607; }
.device-card[data-alert='true'] { border-color: #e7a19a; }
.device-header { padding: 15px 16px 13px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.device-header h3 { font-size: 1.21rem; font-weight: 750; letter-spacing: -.04em; }
.device-meta { display: block; color: var(--muted); font-size: .75rem; margin-top: 3px; }
.viewport { position: relative; isolation: isolate; overflow: hidden; height: clamp(218px, 25vw, 310px); margin-inline: 10px; border-radius: 10px; border: 1px solid #333f2d; background: radial-gradient(ellipse at 53% 45%, #3e4b2d, #293326 58%, #202820); }
.viewport canvas { width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; }
.viewport canvas:active { cursor: grabbing; }
.viewport-status { position: absolute; top: 12px; left: 12px; max-width: calc(100% - 62px); pointer-events: none; color: #eef3e6; background: #19211dde; border: 1px solid #8090736b; border-radius: 6px; padding: 5px 8px; font-size: .73rem; }
.reset-view { position: absolute; top: 10px; right: 10px; width: 31px; height: 31px; padding: 0; border: 1px solid #84977587; border-radius: 7px; background: #202a20d9; color: #eef3e6; font-size: 1.32rem; line-height: 1; }
.reset-view:hover { background: #415037; }
.reset-view:focus-visible { outline-color: var(--accent); }

.orientation-readings { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); margin: 0; padding: 15px 8px; }
.orientation-readings div { padding: 0 10px; }
.orientation-readings div + div { border-left: 1px solid var(--line); }
dt { color: var(--muted); font-size: .76rem; }
dt small { color: #778472; font-size: .66rem; margin-left: 2px; }
dd { margin: 0; font-variant-numeric: tabular-nums; }
.orientation-readings dd { margin-top: 5px; font-size: clamp(1rem, 2vw, 1.43rem); font-weight: 750; letter-spacing: -.045em; }
.sensor-footer { display: flex; gap: 10px 20px; flex-wrap: wrap; margin: 0; padding: 12px 17px; border-top: 1px solid var(--line); background: #fafbf8; border-radius: 0 0 16px 16px; }
.sensor-footer div { display: flex; align-items: baseline; gap: 6px; }
.sensor-footer dd { font-size: .78rem; font-weight: 650; white-space: nowrap; }

.detail-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.58fr); gap: 18px; align-items: start; margin-top: 20px; }
.panel-heading { min-height: 58px; padding: 12px 16px; display: flex; justify-content: space-between; align-items: center; gap: 10px; border-bottom: 1px solid var(--line); }
.map-stage { position: relative; min-height: 205px; border-radius: 0 0 16px 16px; overflow: hidden; background: #eef1e9; }
.location-panel:has(.location-footer:not([hidden])) .map-stage { border-radius: 0; }
#map { position: absolute; inset: 0; }
.map-placeholder { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 7px; padding: 10px; text-align: center; background: linear-gradient(39deg, transparent 45%, #f6f8f3 45% 49%, transparent 49%) 0 0 / 150px 95px, linear-gradient(115deg, transparent 47%, #f7f9f4 47% 52%, transparent 52%) 0 0 / 111px 150px; }
.map-placeholder span:last-child { color: var(--muted); font-size: .77rem; }
.map-pin { display: grid; place-items: center; width: 23px; height: 23px; margin: 0 0 6px; border: 2px solid #697d58; border-radius: 50% 50% 50% 3px; background: #e4ecdc; transform: rotate(-45deg); }
.map-pin::after { content: ''; width: 6px; height: 6px; background: #697d58; border-radius: 50%; }
.location-footer { padding: 13px 16px; display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px; }
.location-footer div > * { display: block; }
.location-footer strong, .location-footer a { font-size: .8rem; font-weight: 650; }
.location-footer span { margin-top: 4px; font-size: .73rem; color: var(--muted); }

.table-wrap { overflow: auto; max-height: 365px; border-radius: 0 0 16px 16px; }
table { width: 100%; min-width: 690px; border-collapse: collapse; font-size: .77rem; }
th, td { text-align: left; border-bottom: 1px solid var(--line); padding: 11px 12px; white-space: nowrap; }
th { position: sticky; top: 0; z-index: 1; background: #f8f9f6; color: var(--muted); font-size: .74rem; font-weight: 650; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #f8f9f6; }
.table-empty { height: 76px; color: var(--muted); }
.event-name { font-weight: 650; }

@media (max-width: 875px) {
    .topbar-inner, .page { width: calc(100% - 36px); }
    .detail-grid { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 625px) {
    .topbar-inner, .page { width: calc(100% - 28px); }
    .topbar-inner { min-height: 63px; }
    .brand { gap: 8px; }
    .brand-mark { width: 35px; height: 35px; }
    .brand span:not(.brand-mark) { font-size: .66rem; }
    .page { padding-top: 25px; }
    .page-heading { align-items: start; flex-direction: column; gap: 13px; margin-bottom: 17px; }
    .update-time { display: flex; align-items: baseline; gap: 6px; text-align: left; }
    .update-time span { margin: 0; }
    .update-time strong { font-size: .8rem; }
    .overview { grid-template-columns: 1fr; margin-bottom: 23px; }
    .overview-item { min-height: 56px; padding: 8px 12px; }
    .overview-item + .overview-item { border-left: none; border-top: 1px solid var(--line); }
    .overview-item div > span { margin-bottom: 2px; }
    .overview-icon { width: 32px; height: 32px; }
    .signal { padding-bottom: 10px; }
    .alert-icon::before { inset: 8px; }
    .device-grid { grid-template-columns: minmax(0, 1fr); gap: 12px; }
    .viewport { height: clamp(225px, 59vw, 305px); }
    .orientation-readings dd { font-size: 1.28rem; }
    .section-heading { flex-wrap: wrap; gap: 4px 10px; }
    .fall-alert { padding: 11px 12px; }
}

/* Nón thực tế: nền trung tính làm rõ vỏ đen và hộp điện tử. */
#helmet-card .viewport { background: radial-gradient(ellipse at 48% 36%, #626b73, #38434b 62%, #242e36); border-color: #48545e; }
.buckle-overlay { position: absolute; bottom: 12px; left: 12px; z-index: 2; pointer-events: none; box-shadow: 0 3px 12px #0003; }
.buckle-overlay[data-state="online"] { color: #d4ffe8; background: #123f32ed; border-color: #4da17d; }
.buckle-overlay[data-state="warning"] { color: #ffe6be; background: #523419ed; border-color: #c08b48; }
.buckle-overlay[data-state="pending"] { color: #e1e6eb; background: #28323aeb; border-color: #77828c; }
.journey-panel{margin:28px 0;overflow:hidden}.journey-speed{display:flex;align-items:center;gap:40px;padding:20px 24px;border-bottom:1px solid #e5e7e2}.journey-speed div{display:grid;gap:8px}.journey-speed span{font-size:13px;color:#65716a}.journey-speed strong{font-size:28px}.journey-speed p{margin-left:auto}.journey-speed [data-over=true]{color:#b42318}.journey-controls{display:flex;flex-wrap:wrap;align-items:end;gap:14px;padding:18px 24px}.journey-controls label{display:grid;gap:8px;font-size:12px;color:#526158}.journey-controls input,.journey-controls select,.journey-controls button{font:inherit;min-height:40px;border:1px solid #cdd5ce;border-radius:7px;padding:8px 12px;background:#fff;color:#24362b}.journey-controls button{background:#245d42;color:white;cursor:pointer}.journey-controls button:disabled{opacity:.5}.journey-controls .check-label{display:flex;align-items:center;min-height:40px}.journey-controls input[type=checkbox]{min-height:0;width:18px;height:18px}.journey-note{font-size:13px;color:#65716a;line-height:1.6;padding:0 24px}#journey-map{height:380px;background:#edf0eb;isolation:isolate}.journey-stops{display:grid;grid-template-columns:repeat(auto-fit,minmax(230px,1fr));gap:12px;padding:18px 24px}.stop-card{border:1px solid #e1e6df;border-radius:8px;padding:14px;font-size:13px;line-height:1.7}.stop-card strong{display:block}.stop-card button{margin-top:8px;cursor:pointer;background:none;color:#245d42;border:0;padding:0;text-decoration:underline}.journey-settings{border-top:1px solid #e1e6df;padding:20px 0}.journey-settings summary{cursor:pointer;font-weight:650;padding:0 24px}.journey-settings>p:not(.journey-note){padding:0 24px;font-size:13px}#settings-message[data-error=true]{color:#b42318}@media(max-width:640px){.journey-speed{gap:18px;flex-wrap:wrap}.journey-speed p{width:100%;margin:0}.journey-controls label{flex:1;min-width:140px}.journey-controls button{flex:1}.journey-speed strong{font-size:24px}#journey-map{height:320px}}
