:root {
  --bg: #0b0f14;
  --bg2: #111620;
  --bg3: #181e28;
  --surface: #1c2333;
  --surface2: #222a3a;
  --border: rgba(255,255,255,0.07);
  --border2: rgba(255,255,255,0.12);
  --text: #e8edf5;
  --text2: #8a95a8;
  --text3: #505868;
  --blue: #3b82f6;
  --blue-dim: rgba(59,130,246,0.15);
  --cyan: #22d3ee;
  --cyan-dim: rgba(34,211,238,0.12);
  --teal: #14b8a6;
  --amber: #f59e0b;
  --amber-dim: rgba(245,158,11,0.15);
  --red: #ef4444;
  --red-dim: rgba(239,68,68,0.12);
  --green: #22c55e;
  --green-dim: rgba(34,197,94,0.12);
  --mono: 'IBM Plex Mono', monospace;
  --sans: 'DM Sans', sans-serif;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 14px; }
body { background: var(--bg); color: var(--text); font-family: var(--sans); min-height: 100vh; }

/* LAYOUT */
.app { display: grid; grid-template-columns: 220px 1fr; grid-template-rows: 52px 1fr; min-height: 100vh; }

/* TOPBAR */
.topbar {
  grid-column: 1/-1;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; padding: 0 20px; gap: 16px;
}
.sidebar-toggle {
  display: none;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: 1px solid var(--border2);
  background: var(--surface);
  color: var(--text);
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}
.sidebar-toggle svg { width: 16px; height: 16px; }
.logo { display: flex; align-items: center; gap: 10px; font-family: var(--mono); font-weight: 500; font-size: 15px; letter-spacing: 0.02em; color: var(--cyan); }
.logo-mark { width: 28px; height: 28px; border-radius: 6px; background: var(--cyan-dim); border: 1px solid rgba(34,211,238,0.3); display: flex; align-items: center; justify-content: center; }
.logo-mark svg { width: 16px; height: 16px; }
.topbar-divider { width: 1px; height: 24px; background: var(--border2); margin: 0 4px; }
.topbar-meta { font-size: 12px; color: var(--text3); font-family: var(--mono); }
.topbar-status { margin-left: auto; display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text2); }
.pulse { width: 7px; height: 7px; border-radius: 50%; background: var(--green); position: relative; }
.pulse::after { content:''; position: absolute; inset: -3px; border-radius: 50%; border: 1px solid var(--green); animation: pulse 2s infinite; }
@keyframes pulse { 0%,100%{opacity:0.8;transform:scale(1)} 50%{opacity:0;transform:scale(1.8)} }
.topbar-time { font-family: var(--mono); font-size: 12px; color: var(--text2); }

/* SIDEBAR */
.sidebar {
  background: var(--bg2);
  border-right: 1px solid var(--border);
  padding: 16px 0;
  display: flex; flex-direction: column; gap: 4px;
  overflow-y: auto;
  transition: transform 0.25s ease;
  z-index: 20;
}
.sidebar-section { padding: 8px 16px 4px; font-size: 10px; font-family: var(--mono); color: var(--text3); letter-spacing: 0.1em; text-transform: uppercase; }
.device-item {
  margin: 0 8px;
  padding: 9px 10px;
  border-radius: 8px;
  cursor: pointer;
  display: flex; align-items: center; gap: 9px;
  transition: background 0.15s;
  border: 1px solid transparent;
}
.device-item:hover { background: var(--surface); }
.device-item.active { background: var(--surface); border-color: var(--border2); }
.device-item.active.flow { border-left: 2px solid var(--blue); }
.device-item.active.level { border-left: 2px solid var(--cyan); }
.device-icon { width: 28px; height: 28px; border-radius: 6px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.device-icon.flow { background: var(--blue-dim); }
.device-icon.level { background: var(--cyan-dim); }
.device-icon svg { width: 14px; height: 14px; }
.device-info { flex: 1; min-width: 0; }
.device-name { font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.device-id { font-size: 10px; color: var(--text3); font-family: var(--mono); }
.device-dot { width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0; }
.dot-ok { background: var(--green); }
.dot-warn { background: var(--amber); }
.dot-off { background: var(--red); }
.device-actions { display: flex; gap: 4px; margin-left: auto; }
.device-action-btn {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text2);
  font-size: 11px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.device-action-btn:hover { background: var(--surface2); color: var(--text); }
.sidebar-add-wrap { padding: 10px 8px 0; }
.sidebar-add-btn {
  width: calc(100% - 0px);
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px dashed var(--border2);
  background: var(--surface);
  color: var(--text);
  font-family: var(--mono);
  font-size: 11px;
  cursor: pointer;
}
.sidebar-add-btn:hover { background: var(--surface2); }

/* MAIN */
.main { padding: 20px; overflow-y: auto; display: flex; flex-direction: column; gap: 16px; }
.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(11,15,20,0.65);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 15;
}
body.sidebar-open .sidebar-backdrop {
  opacity: 1;
  pointer-events: auto;
}
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(11,15,20,0.72);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 40;
}
.modal-backdrop.open { display: flex; }
.modal-card {
  width: min(100%, 620px);
  max-height: 90vh;
  overflow-y: auto;
  background: var(--bg2);
  border: 1px solid var(--border2);
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.35);
}
.modal-head {
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-title { font-size: 15px; font-weight: 600; }
.modal-close {
  width: 32px;
  height: 32px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: transparent;
  color: var(--text2);
  cursor: pointer;
}
.station-form {
  padding: 16px 18px 18px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group.full { grid-column: 1 / -1; }
.form-label { font-size: 11px; font-family: var(--mono); color: var(--text3); }

/* Custom dropdown "Loại máy đo" (có icon) */
.md-dropdown { position: relative; }
.md-trigger {
  display: flex; align-items: center; gap: 9px; width: 100%;
  padding: 10px 12px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; cursor: pointer; text-align: left;
}
.md-trigger:hover { border-color: var(--border2); }
.md-trigger-icon { display: inline-flex; color: var(--cyan); flex: none; }
.md-trigger-icon:empty { display: none; }
.md-trigger #sensorTypeText { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.md-caret { flex: none; color: var(--text3); transition: transform 0.15s; }
.md-dropdown.open .md-caret { transform: rotate(180deg); }
.md-menu {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 60;
  background: var(--surface2); border: 1px solid var(--border2); border-radius: 8px;
  padding: 4px; box-shadow: 0 12px 32px rgba(0,0,0,0.45);
}
.md-menu.hidden { display: none; }
.md-option {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px;
  border-radius: 6px; cursor: pointer; font-size: 13px; color: var(--text);
}
.md-option:hover { background: var(--surface); }
.md-option.selected { background: var(--cyan-dim); color: var(--cyan); }
.md-option svg { flex: none; color: var(--cyan); }

/* Ô công thức tự tính (chỉ đọc) */
.formula-readonly {
  background: var(--bg2) !important;
  color: var(--cyan) !important;
  font-family: var(--mono);
  cursor: default;
}
.formula-readonly:focus { outline: none; }
.form-input, .form-select {
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
}
.form-actions {
  grid-column: 1 / -1;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}
.form-btn {
  padding: 10px 14px;
  border-radius: 8px;
  border: 1px solid var(--border2);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}
.form-btn.primary {
  background: var(--blue);
  border-color: var(--blue);
  color: white;
}

/* TAB NAV */
.tab-nav { display: flex; gap: 4px; background: var(--bg2); border: 1px solid var(--border); border-radius: 10px; padding: 4px; width: fit-content; }
.tab-btn { padding: 6px 16px; border-radius: 7px; font-size: 13px; font-weight: 500; cursor: pointer; border: none; background: transparent; color: var(--text2); transition: all 0.15s; }
.tab-btn:hover { color: var(--text); }
.tab-btn.active-flow { background: var(--blue-dim); color: var(--blue); border: 1px solid rgba(59,130,246,0.25); }
.tab-btn.active-level { background: var(--cyan-dim); color: var(--cyan); border: 1px solid rgba(34,211,238,0.25); }

/* DEVICE HEADER */
.device-header { display: flex; align-items: flex-start; gap: 16px; }
.device-badge { display: flex; align-items: center; gap: 8px; }
.device-type-tag { font-size: 11px; font-family: var(--mono); padding: 3px 10px; border-radius: 99px; }
.tag-flow { background: var(--blue-dim); color: var(--blue); border: 1px solid rgba(59,130,246,0.25); }
.tag-level { background: var(--cyan-dim); color: var(--cyan); border: 1px solid rgba(34,211,238,0.25); }
.device-title { font-size: 20px; font-weight: 600; margin-top: 2px; }
.device-subtitle { font-size: 12px; color: var(--text2); font-family: var(--mono); }
.device-header-right { margin-left: auto; text-align: right; }
.device-coord { font-size: 11px; font-family: var(--mono); color: var(--text3); }

/* METRICS ROW */
.metrics { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.metric-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  position: relative; overflow: hidden;
}
.metric-card::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0; height: 2px;
}
.mc-flow::before { background: linear-gradient(90deg, var(--blue), transparent); }
.mc-level::before { background: linear-gradient(90deg, var(--cyan), transparent); }
.mc-warn::before { background: linear-gradient(90deg, var(--amber), transparent); }
.mc-danger::before { background: linear-gradient(90deg, var(--red), transparent); }
.metric-label { font-size: 11px; font-family: var(--mono); color: var(--text3); text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 8px; }
.metric-value { font-size: 26px; font-weight: 600; font-family: var(--mono); line-height: 1; }
.metric-unit { font-size: 13px; color: var(--text2); font-weight: 400; margin-left: 4px; }
.metric-sub { font-size: 11px; color: var(--text2); margin-top: 6px; }
.badge-status { display: inline-block; font-size: 10px; font-family: var(--mono); padding: 2px 8px; border-radius: 4px; margin-top: 6px; }
.bs-ok { background: var(--green-dim); color: var(--green); }
.bs-warn { background: var(--amber-dim); color: var(--amber); }
.bs-danger { background: var(--red-dim); color: var(--red); }

/* CHART PANELS */
.chart-row { display: grid; grid-template-columns: 1fr 300px; gap: 16px; }
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 18px;
}
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.panel-title { font-size: 13px; font-weight: 500; }
.panel-meta { font-size: 11px; font-family: var(--mono); color: var(--text3); }
.chart-wrap { position: relative; }
.legend-row { display: flex; gap: 14px; margin-bottom: 10px; flex-wrap: wrap; }
.legend-item { display: flex; align-items: center; gap: 5px; font-size: 11px; color: var(--text2); }
.legend-sq { width: 10px; height: 3px; border-radius: 2px; }
.legend-toggle { cursor: pointer; user-select: none; padding: 3px 8px; border-radius: 4px; border: 1px solid transparent; transition: opacity 0.2s, border-color 0.2s, background 0.2s; }
.legend-toggle:hover { background: rgba(255,255,255,0.06); border-color: rgba(255,255,255,0.1); }
.legend-toggle--hidden { opacity: 0.35; text-decoration: line-through; }
.legend-toggle--hidden .legend-sq { background: transparent !important; }

/* WATER VISUAL (mực nước) */
.water-vis { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; height: 100%; }
.tank-wrap { position: relative; width: 120px; height: 180px; }
.tank-outer {
  width: 120px; height: 180px;
  border: 2px solid var(--border2);
  border-radius: 8px 8px 4px 4px;
  position: relative; overflow: hidden;
  background: var(--bg3);
}
.tank-fill {
  position: absolute; bottom: 0; left: 0; right: 0;
  background: linear-gradient(to top, rgba(34,211,238,0.5), rgba(34,211,238,0.2));
  transition: height 0.8s cubic-bezier(0.4,0,0.2,1);
  border-top: 2px solid var(--cyan);
}
.tank-fill::after {
  content: ''; position: absolute; top: 0; left: 0; right: 0; height: 6px;
  background: rgba(34,211,238,0.4);
  animation: wave 2s linear infinite;
}
@keyframes wave { 0%{transform:translateX(0)} 100%{transform:translateX(20px)} }
.tank-lines { position: absolute; top: 0; left: 0; right: 0; bottom: 0; pointer-events: none; }
.tank-line { position: absolute; left: 0; right: 0; border-top: 1px dashed rgba(255,255,255,0.07); display: flex; align-items: center; }
.tank-line-lbl { font-size: 9px; font-family: var(--mono); color: var(--text3); padding: 0 4px; }
.tank-pct { font-size: 28px; font-weight: 600; font-family: var(--mono); color: var(--cyan); }
.tank-label { font-size: 11px; color: var(--text2); }
.level-readings { width: 100%; display: flex; flex-direction: column; gap: 6px; margin-top: 4px; }
.lr-row { display: flex; justify-content: space-between; font-size: 11px; }
.lr-label { color: var(--text3); font-family: var(--mono); }
.lr-val { color: var(--text); font-family: var(--mono); font-weight: 500; }

/* THRESHOLD BARS */
.threshold-section { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.th-row { display: flex; align-items: center; gap: 8px; font-size: 11px; }
.th-label { color: var(--text3); font-family: var(--mono); width: 70px; }
.th-bar-bg { flex: 1; height: 4px; background: var(--bg3); border-radius: 2px; overflow: hidden; }
.th-bar-fill { height: 100%; border-radius: 2px; }
.th-val { font-family: var(--mono); color: var(--text2); width: 40px; text-align: right; }

/* HOURLY HEATMAP */
.heatmap-row { display: flex; gap: 3px; }
.hm-cell {
  flex: 1; height: 32px; border-radius: 4px; display: flex; align-items: center;
  justify-content: center; font-size: 9px; font-family: var(--mono); color: rgba(255,255,255,0.4);
  cursor: default; transition: transform 0.1s;
  position: relative;
}
.hm-cell:hover { transform: scaleY(1.1); z-index: 1; }
.hm-labels { display: flex; gap: 3px; margin-top: 4px; }
.hm-lbl { flex: 1; text-align: center; font-size: 9px; font-family: var(--mono); color: var(--text3); }

/* ACTIVITY TABLE */
.table-section { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.table-head-row { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.table-title { font-size: 13px; font-weight: 500; }
.table-filter { display: flex; gap: 4px; }
.filter-btn { padding: 4px 12px; border-radius: 6px; font-size: 11px; font-family: var(--mono); border: 1px solid var(--border); background: transparent; color: var(--text2); cursor: pointer; transition: all 0.15s; }
.filter-btn:hover { background: var(--surface2); color: var(--text); }
.filter-btn.active { background: var(--surface2); color: var(--text); border-color: var(--border2); }
table { width: 100%; border-collapse: collapse; }
thead th { padding: 10px 18px; text-align: left; font-size: 10px; font-family: var(--mono); color: var(--text3); text-transform: uppercase; letter-spacing: 0.06em; border-bottom: 1px solid var(--border); font-weight: 400; }
tbody tr { border-bottom: 1px solid var(--border); transition: background 0.1s; }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--surface2); }
td { padding: 11px 18px; font-size: 12px; }
.td-device { display: flex; align-items: center; gap: 10px; }
.td-icon { width: 28px; height: 28px; border-radius: 6px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.td-name { font-weight: 500; font-size: 13px; }
.td-id { font-size: 10px; color: var(--text3); font-family: var(--mono); }
.td-mono { font-family: var(--mono); font-size: 12px; }
.td-val-flow { color: var(--blue); font-family: var(--mono); font-weight: 500; }
.td-val-level { color: var(--cyan); font-family: var(--mono); font-weight: 500; }
.status-pill { display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: 99px; font-size: 10px; font-family: var(--mono); }
.sp-ok { background: var(--green-dim); color: var(--green); }
.sp-warn { background: var(--amber-dim); color: var(--amber); }
.sp-off { background: rgba(80,88,104,0.2); color: var(--text3); }
.type-chip { font-size: 10px; font-family: var(--mono); padding: 2px 8px; border-radius: 4px; }
.tc-flow { background: var(--blue-dim); color: var(--blue); }
.tc-level { background: var(--cyan-dim); color: var(--cyan); }
.section-divider { grid-column: 1/-1; display: flex; align-items: center; gap: 10px; }
.div-label { font-size: 10px; font-family: var(--mono); color: var(--text3); text-transform: uppercase; letter-spacing: 0.08em; white-space: nowrap; }
.div-line { flex: 1; height: 1px; background: var(--border); }
.sidebar-spacer { height: 8px; }

/* MEASUREMENT TABLE */
.meas-section { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.meas-header { padding: 14px 18px; border-bottom: 1px solid var(--border); display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.meas-title-block {}
.meas-station { font-size: 15px; font-weight: 600; color: var(--text); }
.meas-sub { display: flex; align-items: center; gap: 10px; margin-top: 4px; flex-wrap: wrap; }
.meas-code { font-size: 11px; font-family: var(--mono); color: var(--text2); }
.meas-formula { font-size: 11px; font-family: var(--mono); background: var(--blue-dim); color: var(--blue); border: 1px solid rgba(59,130,246,0.2); padding: 2px 10px; border-radius: 4px; font-weight: 400; line-height: 1.2; }
.meas-controls { display: flex; align-items: center; gap: 6px; }
.meas-ctrl-btn { padding: 4px 12px; border-radius: 6px; font-size: 11px; font-family: var(--mono); border: 1px solid var(--border); background: transparent; color: var(--text2); cursor: pointer; transition: all 0.15s; }
.meas-ctrl-btn:hover { background: var(--surface2); color: var(--text); }
.meas-ctrl-btn.active { background: var(--surface2); color: var(--text); border-color: var(--border2); }

/* Download dữ liệu mực nước theo khoảng ngày (giữa header thẻ mực nước) */
.level-dl { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.level-dl-title { font-size: 10px; font-family: var(--mono); color: var(--text3); text-transform: uppercase; letter-spacing: 0.06em; }
.level-dl-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; justify-content: center; }
.level-dl-input { padding: 4px 8px; border-radius: 6px; font-size: 11px; font-family: var(--mono); border: 1px solid var(--border); background: var(--bg3); color: var(--text); cursor: pointer; color-scheme: dark; }
.level-dl-input:focus { outline: none; border-color: var(--cyan); }
.level-dl-sep { font-size: 12px; color: var(--text3); }
.level-dl-btn { display: inline-flex; align-items: center; gap: 5px; padding: 4px 12px; border-radius: 6px; font-size: 11px; font-family: var(--mono); border: 1px solid rgba(34,211,238,0.3); background: var(--cyan-dim); color: var(--cyan); cursor: pointer; transition: all 0.15s; }
.level-dl-btn:hover:not(:disabled) { background: rgba(34,211,238,0.2); border-color: var(--cyan); }
.level-dl-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.meas-table-wrap { overflow-x: auto; }
.meas-table { width: 100%; border-collapse: collapse; min-width: 900px; }
.meas-table thead tr:first-child th { padding: 8px 10px; font-size: 10px; font-family: var(--mono); color: var(--text3); text-transform: uppercase; letter-spacing: 0.06em; border-bottom: 1px solid var(--border); font-weight: 400; background: var(--bg3); text-align: center; }
.meas-table thead tr:first-child th:first-child { text-align: left; padding-left: 18px; }
.meas-table thead tr.subhead th { padding: 5px 10px; font-size: 9px; font-family: var(--mono); color: var(--text3); border-bottom: 1px solid var(--border); background: var(--bg2); text-align: center; font-weight: 400; }
.meas-table thead tr.subhead th:first-child { text-align: left; padding-left: 18px; }
.meas-table tbody tr { border-bottom: 1px solid var(--border); transition: background 0.1s; }
.meas-table tbody tr:last-child { border-bottom: none; }
.meas-table tbody tr:hover { background: var(--surface2); }
.meas-table td { padding: 0; font-size: 11px; text-align: center; }
.meas-table td:first-child { text-align: left; padding-left: 18px; font-family: var(--mono); color: var(--text2); font-size: 11px; white-space: nowrap; padding-right: 10px; }
.cell-group { display: flex; }
.cell-sub { flex: 1; padding: 9px 4px; font-family: var(--mono); font-size: 11px; border-right: 1px solid var(--border); }
.cell-sub:last-child { border-right: none; }
.cell-sub.v-val { color: var(--blue); font-weight: 500; }
.cell-vong { color: var(--text); }
.cell-time { color: var(--text2); }
.cell-ht { padding: 9px 14px; font-family: var(--mono); font-size: 12px; font-weight: 600; color: var(--cyan); white-space: nowrap; }
.cell-ht-warn { color: var(--amber); }
.cell-ht-danger { color: var(--red); }
.col-sep { border-left: 1px solid var(--border2) !important; }
.hour-tag { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; font-family: var(--mono); font-weight: 500; color: var(--text); }
.cur-row td { background: rgba(59,130,246,0.05) !important; }
.cur-row td:first-child { color: var(--blue) !important; }
.meas-cards {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px 18px 18px;
}
.meas-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  background: var(--bg2);
}
.meas-card.current {
  border-color: rgba(59,130,246,0.28);
  box-shadow: inset 0 0 0 1px rgba(59,130,246,0.12);
}
.meas-card-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}
.meas-card-table th,
.meas-card-table td {
  padding: 16px 14px;
  text-align: center;
  border-bottom: 1px solid var(--border);
}
.meas-card-table tr:last-child th,
.meas-card-table tr:last-child td {
  border-bottom: none;
}
.meas-card-table th {
  background: rgba(255,255,255,0.02);
  color: var(--text);
  font-weight: 600;
  font-size: 12px;
}
.meas-card-table th:first-child,
.meas-card-table td:first-child {
  width: 120px;
}
.meas-card-table td {
  font-family: var(--mono);
  font-size: 14px;
  color: var(--text);
}
.meas-card-time {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
}
.meas-row-label {
  font-family: var(--sans) !important;
  font-size: 13px !important;
  color: var(--text2) !important;
  font-weight: 500;
}
.meas-summary-cell {
  color: var(--cyan) !important;
  font-weight: 700;
  font-size: 16px !important;
}

/* LEVEL SUMMARY ROW */
.level-summary-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}
.level-summary-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 18px;
}
.level-summary-title {
  font-size: 12px;
  font-family: var(--mono);
  color: var(--text2);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 12px;
}
.level-summary-grid {
  display: flex;
  gap: 16px;
}
.level-summary-grid > div {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}
.level-summary-label {
  font-size: 10px;
  font-family: var(--mono);
  color: var(--text3);
  text-transform: uppercase;
}
.level-summary-val {
  font-size: 18px;
  font-weight: 600;
  font-family: var(--mono);
}

/* LEVEL DATA TABLE */
.level-table-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}
.level-table-header {
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.level-table-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}
.level-table-sub {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 4px;
  flex-wrap: wrap;
}
.level-table-wrap {
  overflow-x: auto;
  max-height: 520px;
  overflow-y: auto;
}
.level-data-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 700px;
}
.level-data-table thead th {
  padding: 10px 16px;
  text-align: center;
  font-size: 11px;
  font-family: var(--mono);
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--border);
  font-weight: 500;
  background: var(--bg3);
  position: sticky;
  top: 0;
  z-index: 1;
}
.level-data-table thead th:first-child,
.level-data-table thead th:nth-child(2) {
  text-align: left;
  padding-left: 18px;
}
.level-data-table tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
}
.level-data-table tbody tr:last-child { border-bottom: none; }
.level-data-table tbody tr:hover { background: var(--surface2); }
.level-data-table td {
  padding: 10px 16px;
  font-size: 12px;
  text-align: center;
}
.level-data-table td:first-child,
.level-data-table td:nth-child(2) {
  text-align: left;
  padding-left: 18px;
  color: var(--text2);
  white-space: nowrap;
}
.level-val-0 { color: var(--cyan) !important; font-weight: 500; }
.level-val-1 { color: var(--blue) !important; font-weight: 500; }
.level-val-2 { color: #a855f7 !important; font-weight: 500; }
.level-val-vol { color: var(--amber) !important; }
.level-row-latest td {
  background: rgba(34,211,238,0.05) !important;
}
.level-row-latest td:first-child {
  position: relative;
}
.level-row-latest td:first-child::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--cyan);
  border-radius: 0 2px 2px 0;
}

/* SCROLLBAR */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 2px; }

/* AUTH */
.topbar-auth { display: flex; align-items: center; gap: 8px; margin-left: 14px; }
.auth-greeting { font-size: 12px; color: var(--text2); white-space: nowrap; }
.auth-greeting b { color: var(--text); font-weight: 600; }
.auth-role-chip { font-size: 9px; font-family: var(--mono); text-transform: uppercase; letter-spacing: 0.06em; padding: 2px 7px; border-radius: 99px; white-space: nowrap; }
.auth-role-admin { background: var(--cyan-dim); color: var(--cyan); border: 1px solid rgba(34,211,238,0.25); }
.auth-role-viewer { background: rgba(80,88,104,0.2); color: var(--text2); border: 1px solid var(--border2); }
.auth-btn { padding: 6px 14px; border-radius: 8px; border: 1px solid var(--border2); background: var(--surface); color: var(--text); font: inherit; font-size: 12px; cursor: pointer; white-space: nowrap; }
.auth-btn:hover { background: var(--surface2); }
.auth-btn.primary { background: var(--cyan); border-color: var(--cyan); color: #06222a; font-weight: 600; }
.auth-tabs { display: flex; gap: 4px; padding: 14px 18px 0; }
.auth-tab { flex: 1; padding: 9px; border-radius: 8px; border: 1px solid var(--border); background: transparent; color: var(--text2); cursor: pointer; font: inherit; font-size: 13px; }
.auth-tab.active { background: var(--surface); color: var(--text); border-color: var(--border2); }
.auth-form { padding: 16px 18px 18px; display: flex; flex-direction: column; gap: 12px; }
.auth-error { font-size: 12px; color: var(--red); min-height: 14px; }
.auth-hint { font-size: 11px; color: var(--text3); text-align: center; font-family: var(--mono); }

/* DISABLED CONTROLS (chưa đăng nhập / không có quyền) */
.device-action-btn:disabled { opacity: 0.3; cursor: not-allowed; }
.device-action-btn:disabled:hover { background: transparent; color: var(--text2); }
.sidebar-add-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.sidebar-add-btn:disabled:hover { background: var(--surface); }

/* TELEGRAPH (máy điện báo) */
.device-icon.telegraph { background: var(--amber-dim); }
.device-item.active.telegraph { border-left: 2px solid var(--amber); }
.tag-telegraph { background: var(--amber-dim); color: var(--amber); border: 1px solid rgba(245,158,11,0.25); }

@media (max-width: 900px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: 52px 1fr;
  }
  .sidebar-toggle {
    display: inline-flex;
  }
  .topbar {
    padding: 0 14px;
    gap: 10px;
  }
  .topbar-meta,
  .topbar-divider,
  .topbar-status span:first-of-type,
  .auth-greeting,
  .auth-role-chip {
    display: none;
  }
  .sidebar {
    position: fixed;
    top: 52px;
    left: 0;
    bottom: 0;
    width: min(82vw, 300px);
    transform: translateX(-100%);
    box-shadow: 18px 0 40px rgba(0,0,0,0.35);
  }
  body.sidebar-open .sidebar {
    transform: translateX(0);
  }
  .main {
    padding: 14px;
  }
  .metrics,
  .chart-row,
  .level-summary-row {
    grid-template-columns: 1fr;
  }
  .device-header,
  .meas-header,
  .table-head-row {
    flex-direction: column;
    align-items: flex-start;
  }
  .meas-cards {
    padding: 12px;
  }
  .meas-card-table th,
  .meas-card-table td {
    padding: 12px 10px;
  }
  .meas-card-time {
    font-size: 18px;
  }
  .station-form {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .meas-cards {
    gap: 10px;
    padding: 10px;
  }
  .meas-table-wrap {
    overflow-x: hidden;
  }
  .meas-card-table {
    min-width: 100%;
    table-layout: fixed;
  }
  .meas-card-table th,
  .meas-card-table td {
    padding: 10px 4px;
    font-size: 11px;
    word-break: break-word;
  }
  .meas-card-table th:first-child,
  .meas-card-table td:first-child {
    width: 72px;
  }
  .meas-card-time {
    font-size: 15px;
    line-height: 1.2;
  }
  .meas-row-label {
    font-size: 11px !important;
    line-height: 1.2;
  }
  .meas-summary-cell {
    font-size: 13px !important;
  }
}
