:root {
  --bg: #f4f6f9;
  --card: #fff;
  --line: #dde2ea;
  --text: #1c2330;
  --muted: #667085;
  --brand: #1f6feb;
  --ok: #1a7f37;
  --warn: #b76e00;
  --err: #c62828;
  font-family: "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 15px;
  color: var(--text);
  background: var(--bg);
}
* { box-sizing: border-box; }
body { margin: 0; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

header.top {
  display: flex; align-items: center; gap: 24px;
  background: #13284b; color: #fff; padding: 0 20px; height: 52px;
}
header.top .brand { font-weight: 700; font-size: 17px; color: #fff; white-space: nowrap; }
header.top nav { display: flex; gap: 4px; flex: 1; }
header.top nav a { color: #c9d6ec; padding: 15px 12px; }
header.top nav a.on, header.top nav a:hover { color: #fff; background: #1f3a68; text-decoration: none; }
header.top .me { display: flex; align-items: center; gap: 12px; font-size: 14px; color: #c9d6ec; white-space: nowrap; }
header.top .me a, header.top .me button { color: #fff; }

/* Chuyển ngôn ngữ VI / EN */
.lang-toggle {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 8px; border-radius: 999px; background: #1a335c;
  color: #c9d6ec; text-decoration: none; font-size: 12px; font-weight: 700;
  letter-spacing: 0.02em; border: 1px solid #2a4a7a;
}
.lang-toggle:hover { color: #fff; text-decoration: none; background: #214072; }
.lang-toggle .lang-opt { opacity: 0.55; min-width: 18px; text-align: center; }
.lang-toggle:not(.is-en) .lang-opt.left,
.lang-toggle.is-en .lang-opt.right { opacity: 1; color: #fff; }
.lang-track {
  position: relative; width: 34px; height: 18px; border-radius: 999px;
  background: #0d1f3a; border: 1px solid #3a5a8a; flex-shrink: 0;
}
.lang-knob {
  position: absolute; top: 1px; left: 2px; width: 14px; height: 14px;
  border-radius: 50%; background: #fff; transition: left 0.15s ease;
  box-shadow: 0 1px 2px rgba(0,0,0,0.25);
}
.lang-toggle.is-en .lang-knob { left: 16px; background: #6ea8fe; }
.bare-lang {
  position: absolute; top: 14px; right: 18px; z-index: 2;
}
body { position: relative; }

main { max-width: 1280px; margin: 0 auto; padding: 20px; }
nav.subnav { display: flex; flex-wrap: wrap; gap: 2px; border-bottom: 1px solid var(--line); margin: -6px 0 16px; }
nav.subnav a { padding: 8px 14px; color: var(--muted); border-bottom: 3px solid transparent; }
nav.subnav a.on { color: var(--text); border-bottom-color: var(--brand); font-weight: 600; }
nav.subnav a:hover { color: var(--text); text-decoration: none; }
input[type=time] { font: inherit; padding: 6px 8px; border: 1px solid #c3cad6; border-radius: 6px; }
select[multiple] { padding: 4px; }
button:disabled { opacity: 0.4; cursor: default; }
h1 { font-size: 22px; margin: 4px 0 16px; }
h2 { font-size: 17px; margin: 0 0 12px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 16px 18px; margin-bottom: 16px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 14px 16px; }
a.stat { color: inherit; }
a.stat:hover { border-color: var(--brand); text-decoration: none; }
.stat .n { font-size: 30px; font-weight: 700; }
.stat .l { color: var(--muted); }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 900px) { .cols { grid-template-columns: 1fr; } }

table { width: 100%; border-collapse: collapse; background: var(--card); }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { background: #eef2f7; font-weight: 600; font-size: 14px; position: sticky; top: 0; }
tr:hover td { background: #f8fafc; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
.mono { font-family: Consolas, "Courier New", monospace; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

.tag { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12.5px; background: #e7ecf3; margin: 1px 2px 1px 0; }
.tag.ok { background: #dcf3e2; color: var(--ok); }
.tag.err { background: #fde3e3; color: var(--err); }
.tag.warn { background: #fff1d6; color: var(--warn); }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: #b8c0cc; margin-right: 6px; }
.dot.on { background: #22a447; }
.dot.off { background: var(--err); }

form.inline { display: inline; }
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; margin-bottom: 12px; }
label { display: block; font-weight: 600; font-size: 14px; margin-bottom: 4px; }
.field { margin-bottom: 12px; }
.hint { color: var(--muted); font-size: 13px; margin-top: 3px; }
input[type=text], input[type=password], input[type=search], select, textarea {
  font: inherit; padding: 7px 9px; border: 1px solid #c3cad6; border-radius: 6px; background: #fff; min-width: 180px;
}
input:focus, select:focus { outline: 2px solid #9cc0ff; border-color: var(--brand); }
input.wide, select.wide { width: 100%; }
.checks { display: flex; flex-wrap: wrap; gap: 6px 16px; }
.checks label { font-weight: 400; display: flex; gap: 6px; align-items: center; margin: 0; }

button, .btn {
  font: inherit; padding: 7px 14px; border-radius: 6px; border: 1px solid #c3cad6; background: #fff; color: var(--text); cursor: pointer;
  display: inline-block;
}
button.primary, .btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
button.danger { color: var(--err); border-color: #e6a5a5; }
button.link { border: 0; background: none; padding: 0; color: var(--brand); }
button:hover, .btn:hover { filter: brightness(0.96); text-decoration: none; }

.alert { padding: 10px 14px; border-radius: 6px; margin-bottom: 14px; border: 1px solid; }
.alert.ok { background: #e9f7ee; border-color: #a6dbb6; color: #0f5323; }
.alert.err { background: #fdecec; border-color: #f0b4b4; color: #8a1c1c; }
.alert.info { background: #eaf2ff; border-color: #b6cdf5; color: #173d7a; }
#toast:empty { display: none; }

.login { max-width: 380px; margin: 9vh auto; }
.login h1 { text-align: center; }
.temp-pw { font-size: 22px; font-weight: 700; letter-spacing: 2px; }
.uid-show { font-family: Consolas, monospace; margin-top: 4px; color: var(--ok); }
.uid-show.bad { color: var(--err); }
.scan { font-size: 18px; padding: 10px; width: 100%; }

/* Dashboard báo cáo tuần */
.dash-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 12px; align-items: end; margin-bottom: 8px; }
.dash-head h1 { margin-bottom: 4px; }
.dash-kpi .stat .n { font-size: 26px; }
.dash-charts { margin-bottom: 0; }
.chart-wrap { position: relative; height: 280px; }
.chart-wrap.tall { height: 360px; }
.table-wrap { overflow: auto; max-height: 420px; }
@media (max-width: 900px) {
  .chart-wrap, .chart-wrap.tall { height: 300px; }
}

/* Bản đồ xưởng đúc */
.fmap-page { max-width: none; }
main:has(.fmap-page) { max-width: none; padding: 16px 20px 24px; }
.fmap-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 12px; align-items: end; margin-bottom: 8px; }
.fmap-head h1 { margin-bottom: 4px; }
.fmap-counts { display: flex; flex-wrap: wrap; gap: 8px; }
.fmap-legend { display: flex; flex-wrap: wrap; gap: 14px; align-items: center; margin-bottom: 12px; font-size: 13px; color: var(--muted); }
.fmap-leg { display: inline-flex; align-items: center; gap: 6px; }
.fmap-leg i.fmap-lamp { position: static; width: 10px; height: 10px; border-radius: 50%; display: inline-block; box-shadow: none; }
.fmap-leg i.fmap-lamp.status-run { background: #1a7f37; }
.fmap-leg i.fmap-lamp.status-stop { background: #e67e22; }
.fmap-leg i.fmap-lamp.status-down { background: #c62828; }
.fmap-wrap { display: grid; grid-template-columns: 1fr minmax(260px, 320px); gap: 14px; align-items: start; }
@media (max-width: 960px) { .fmap-wrap { grid-template-columns: 1fr; } }
.fmap-scroll {
  overflow-x: hidden; overflow-y: auto;
  max-height: calc(100vh - 170px);
  border: 1px solid var(--line); border-radius: 8px; background: #f0f3f7;
  padding: 10px;
}
.fmap-floor {
  position: relative;
  width: 100%;
  height: auto;
  background: #f7f9fc;
  background-image:
    linear-gradient(#e4e9f0 1px, transparent 1px),
    linear-gradient(90deg, #e4e9f0 1px, transparent 1px);
  background-size: 5% 3.5%;
  border: 1px solid #d5dde8; border-radius: 6px;
}
.fmap-spine {
  position: absolute; top: 0; bottom: 0; background: rgba(0, 176, 80, 0.08);
  pointer-events: none; z-index: 0;
}
.fmap-pillar {
  position: absolute; z-index: 1;
  background: #00b050; color: #fff; border-radius: 4px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px; box-shadow: inset 0 0 0 1px rgba(0,0,0,0.1);
  pointer-events: none;
}
/* Chip máy gọn — scale theo kích thước bản đồ */
.fmap-m {
  position: absolute; z-index: 2;
  transform: translate(-50%, -50%);
  display: inline-flex; flex-direction: row; align-items: center; gap: 2px;
  max-width: 9%; min-width: 0;
  padding: 1px 5px 1px 3px; border: 1px solid #c5ced9; border-radius: 999px;
  background: #fff; color: #2c3642; cursor: pointer; font: inherit;
  box-shadow: 0 1px 2px rgba(0,0,0,0.05);
  white-space: nowrap;
  font-size: clamp(8px, 0.85vw, 11px);
}
.fmap-m:hover, .fmap-m.is-on {
  border-color: var(--brand); z-index: 5;
  box-shadow: 0 0 0 2px rgba(31,111,235,0.28);
}
.fmap-ico { width: 1.1em; height: 1.1em; flex-shrink: 0; color: #445; display: block; }
.fmap-ico svg { width: 100%; height: 100%; display: block; }
.fmap-name {
  line-height: 1.15; font-weight: 650;
  overflow: hidden; text-overflow: ellipsis; max-width: 4.5em;
}
.fmap-lamp {
  width: 0.65em; height: 0.65em; border-radius: 50%; flex-shrink: 0; order: -1;
  background: #98a2b3; box-shadow: 0 0 0 1px #fff;
}
.fmap-pillar span { font-size: clamp(10px, 1.1vw, 14px); }
.fmap-m.status-run .fmap-lamp { background: #1a7f37; box-shadow: 0 0 0 1px #fff, 0 0 5px #1a7f37; }
.fmap-m.status-stop .fmap-lamp { background: #e67e22; box-shadow: 0 0 0 1px #fff, 0 0 5px #e67e22; }
.fmap-m.status-down .fmap-lamp { background: #c62828; box-shadow: 0 0 0 1px #fff, 0 0 5px #c62828; }
.fmap-panel {
  background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 14px 16px;
  position: sticky; top: 12px;
}
.fmap-panel[hidden] { display: none !important; }
.fmap-panel-h { display: flex; justify-content: space-between; align-items: start; gap: 8px; }
.fmap-panel-h h2 { margin: 0; font-size: 18px; }
.fmap-dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; margin: 12px 0; font-size: 14px; }
.fmap-dl dt { color: var(--muted); }
.fmap-dl dd { margin: 0; font-weight: 600; }
.fmap-panel h3 { font-size: 14px; margin: 12px 0 6px; }
.fmap-kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.fmap-kpis .stat { padding: 10px; }
.fmap-kpis .stat .n { font-size: 18px; }
