/* Device detail — drill-down từ "Hoạt động nâng cao" của bảng Kiểm soát vận hành.
   Dùng token trong smartlite-shared.css, load file này sau. */

.device-detail-page {
  height: 100dvh;
  overflow: hidden;
}
.dd-shell {
  height: 100dvh;
  display: grid;
  grid-template-rows: 52px minmax(0, 1fr);
  background: var(--bg);
}

/* ── Thanh trên: quay lại + 4 tab ── */
.dd-topbar {
  display: grid;
  grid-template-columns: minmax(150px, 1fr) auto minmax(150px, 1fr);
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.dd-back {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  justify-self: start;
  color: var(--accent);
  font-size: 14px;
  font-weight: 500;
  padding: 6px 2px;
  border-radius: var(--radius);
}
.dd-back:hover { text-decoration: underline; }
.dd-back-chev {
  width: 8px;
  height: 8px;
  border-left: 1.6px solid currentColor;
  border-bottom: 1.6px solid currentColor;
  transform: rotate(45deg);
}
.dd-tabs { display: inline-flex; gap: 4px; }
.dd-tab {
  height: 51px;
  padding: 0 18px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--ink-soft);
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
}
.dd-tab:hover { color: var(--accent); }
.dd-tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.dd-topbar-end { justify-self: end; display: inline-flex; align-items: center; gap: 8px; }

/* ── Vùng nội dung ── */
.dd-main { min-height: 0; overflow: auto; padding: 12px 16px 20px; }
.dd-view { display: none; }
.dd-view.is-active { display: block; }
.dd-pane { display: none; }
.dd-pane.is-active { display: block; }

.dd-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 12px;
  overflow: hidden;
}
.dd-section-title {
  margin: 0;
  padding: 12px 16px;
  background: #eef2f5;
  border-bottom: 1px solid var(--line);
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

/* ── Hero thiết bị ── */
.dd-hero {
  display: grid;
  grid-template-columns: 132px minmax(0, 1fr);
  gap: 20px;
  padding: 16px;
  align-items: start;
}
.dd-hero-photo {
  width: 132px;
  height: 132px;
  display: grid;
  place-items: center;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--soft-2);
  overflow: hidden;
}
.dd-hero-photo img { width: 100%; height: 100%; object-fit: contain; display: block; }
.dd-hero-body { min-width: 0; display: grid; gap: 14px; align-content: start; }
.dd-hero-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.dd-hero-head h1 { font-size: 22px; line-height: 1.2; letter-spacing: -0.01em; font-weight: 700; }
.dd-hero-stats { display: flex; gap: 56px; flex-wrap: wrap; }
.dd-stat { display: grid; gap: 6px; }
.dd-stat strong {
  font-size: 20px;
  line-height: 1;
  font-weight: 700;
  color: var(--success);
  font-variant-numeric: tabular-nums;
}
.dd-stat span { color: var(--ink-soft); font-size: 13px; }
.dd-hero-meta { display: flex; gap: 40px; flex-wrap: wrap; color: var(--muted); font-size: 13px; }
.dd-hero-meta b { color: var(--fg); font-weight: 500; margin-left: 8px; }

/* ── Form thông tin cơ bản ── */
.dd-form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(330px, 1fr));
  gap: 16px 24px;
  padding: 22px 16px;
}
.dd-field {
  display: grid;
  grid-template-columns: minmax(120px, 168px) minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  min-width: 0;
}
.dd-field > span:first-child {
  color: var(--ink-soft);
  font-size: 13px;
  text-align: right;
}
.dd-input {
  width: 100%;
  min-width: 0;
  height: 34px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--soft-2);
  color: var(--fg);
  font-size: 13px;
  text-overflow: ellipsis;
}
.dd-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--blue-soft); }
.dd-select { background: var(--surface); cursor: pointer; }
.dd-pair { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; min-width: 0; }
.dd-input-unit { display: flex; align-items: center; padding: 0; background: var(--soft-2); }
.dd-input-unit input {
  flex: 1;
  min-width: 0;
  height: 32px;
  border: 0;
  background: none;
  padding: 0 10px;
  font-size: 13px;
  color: var(--fg);
}
.dd-input-unit input:focus { outline: none; }
.dd-input-unit em { padding: 0 10px; color: var(--muted); font-size: 12px; font-style: normal; }
.dd-chip {
  justify-self: start;
  max-width: 100%;
  min-height: 32px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--soft-2);
  color: var(--fg);
  font-size: 13px;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.dd-chip:hover { color: var(--accent); border-color: var(--blue-mid); background: var(--info-soft); }

/* ── Lưới khóa/giá trị (nền tảng, sản phẩm, tài sản) ── */
.dd-kv-table {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  border-top: 1px solid var(--line);
}
.dd-kv {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr);
  min-width: 0;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}
.dd-kv:nth-child(3n) { border-right: 0; }
.dd-kv-key,
.dd-kv-val {
  min-width: 0;
  padding: 8px 12px;
  font-size: 13px;
  line-height: 1.35;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.dd-kv-key { color: var(--ink-soft); border-right: 1px solid var(--line); }
.dd-kv-val { color: var(--fg); }
.dd-kv-val.dd-num { font-variant-numeric: tabular-nums; }

/* ── Sub-tab ── */
.dd-subtabs {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
  border-bottom: 1px solid var(--line);
}
.dd-subtab {
  height: 36px;
  padding: 0 12px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--ink-soft);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
}
.dd-subtab:hover { color: var(--accent); }
.dd-subtab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

.dd-scroll-tabs {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 6px;
  margin-bottom: 12px;
  border-bottom: 1px solid var(--line);
}
.dd-scroll-track { display: flex; gap: 22px; overflow: hidden; }
.dd-scroll-arrow {
  width: 24px;
  height: 34px;
  display: grid;
  place-items: center;
  border: 0;
  background: transparent;
  color: var(--muted);
}
.dd-scroll-arrow:hover { color: var(--accent); }

/* ── Bố cục quy tắc: rail trái + bảng ── */
.dd-rule-layout {
  display: grid;
  grid-template-columns: 180px minmax(0, 1fr);
  gap: 12px;
  align-items: start;
}
.dd-rule-rail {
  display: grid;
  gap: 10px;
  align-content: start;
  padding: 12px;
  min-height: 420px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.dd-rail-btn {
  min-height: 38px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--fg);
  font-size: 13px;
  text-align: left;
}
.dd-rail-btn:hover { border-color: var(--blue-mid); color: var(--accent); }
.dd-rail-btn.active { border-color: var(--accent); color: var(--accent); font-weight: 600; box-shadow: 0 0 0 3px var(--blue-soft); }
.dd-rule-body { min-width: 0; }

/* ── Toolbar bảng ── */
.dd-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-bottom: 0;
  border-radius: var(--radius) var(--radius) 0 0;
}
.dd-toolbar .btn { height: 32px; padding: 0 12px; font-size: 12px; }
.dd-toolbar-divider { width: 1px; height: 22px; background: var(--line); }
.dd-toolbar-actions { display: inline-flex; align-items: center; gap: 8px; margin-left: auto; flex-wrap: wrap; }
.dd-btn-danger { color: var(--error); border-color: #ffccc7; background: var(--error-soft); }
.dd-btn-danger:hover { border-color: var(--error); }

.dd-search { position: relative; display: inline-flex; align-items: center; }
.dd-search .input {
  width: clamp(150px, 15vw, 200px);
  height: 32px;
  padding-left: 32px;
  font-size: 13px;
}
.dd-search .ops-search-icon { position: absolute; left: 11px; pointer-events: none; }

.dd-range { position: relative; display: inline-flex; align-items: center; }
.dd-range-input {
  width: 258px;
  height: 32px;
  padding: 0 30px 0 32px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--fg);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}
.dd-range-input:hover { border-color: var(--blue-mid); }
.dd-range-end { margin-left: auto; }
.dd-range-end .dd-range-input { width: 236px; text-align: center; padding-right: 12px; }
.dd-range-icon {
  position: absolute;
  left: 11px;
  width: 13px;
  height: 13px;
  border: 1.4px solid var(--muted);
  border-radius: 2px;
  pointer-events: none;
}
.dd-range-icon::before {
  content: "";
  position: absolute;
  left: -1.4px;
  right: -1.4px;
  top: 1px;
  height: 3px;
  background: var(--muted);
}
.dd-range-clear { position: absolute; right: 10px; color: var(--muted); font-size: 12px; pointer-events: none; }

.dd-grain {
  display: grid;
  grid-auto-rows: auto;
  gap: 0;
  padding: 2px 4px;
  border-radius: 6px;
  background: var(--soft-2);
}
.dd-grain button {
  min-height: 18px;
  padding: 0 8px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  text-align: left;
}
.dd-grain button:hover { color: var(--accent); }
.dd-grain button.active { color: var(--accent); font-weight: 700; }
.dd-stepper { display: inline-grid; gap: 2px; }
.dd-stepper button {
  width: 22px;
  height: 16px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--surface);
  color: var(--muted);
}
.dd-stepper button:hover { color: var(--accent); border-color: var(--blue-mid); }
.dd-step-chev {
  width: 5px;
  height: 5px;
  border-left: 1.4px solid currentColor;
  border-bottom: 1.4px solid currentColor;
}
.dd-step-chev.prev { transform: rotate(45deg); }
.dd-step-chev.next { transform: rotate(-135deg); }

/* ── Bảng ── */
.dd-table-wrap {
  overflow: auto;
  max-height: calc(100dvh - 300px);
  background: var(--surface);
  border: 1px solid var(--line);
}
.dd-table { width: 100%; border-collapse: collapse; }
.dd-table-alerts { min-width: 1720px; }
.dd-table-workorders { min-width: 1480px; }
.dd-table-logs { min-width: 1620px; }
.dd-table-rules { min-width: 1080px; }
.dd-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  height: 42px;
  padding: 0 12px;
  border-bottom: 1px solid var(--line);
  background: var(--soft);
  color: var(--fg);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: none;
  text-align: left;
  white-space: nowrap;
}
.dd-table tbody td {
  height: 46px;
  padding: 0 12px;
  border-bottom: 1px solid var(--line);
  color: var(--fg);
  font-size: 13px;
  white-space: nowrap;
}
.dd-table tbody tr:hover { background: var(--info-soft); }
.dd-table tbody tr.is-alert { background: var(--error-soft); }
.dd-table tbody tr.is-alert:hover { background: color-mix(in srgb, var(--error-soft) 70%, var(--error) 30%); }
.dd-table tbody tr.is-hidden { display: none; }
.dd-table .col-check { width: 44px; text-align: center; }
.dd-table .col-check input { width: 15px; height: 15px; accent-color: var(--accent); }
.dd-table .dd-num { font-variant-numeric: tabular-nums; }
.dd-table .dd-empty { color: var(--muted); }
.dd-table .dd-truncate { max-width: 280px; overflow: hidden; text-overflow: ellipsis; }
.dd-empty-row td {
  height: 220px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

.dd-state {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
}
.dd-state::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}
.dd-state.success { color: #389e0d; }
.dd-state.warning { color: #d48806; }
.dd-state.error { color: #cf1322; }
.dd-state.processing { color: #531dab; }
.dd-state.disabled { color: var(--muted); }
html[data-theme-style="dark"] .dd-state.success,
html[data-theme-style="dark-soft"] .dd-state.success { color: #95de64; }
html[data-theme-style="dark"] .dd-state.warning,
html[data-theme-style="dark-soft"] .dd-state.warning { color: #ffd666; }
html[data-theme-style="dark"] .dd-state.error,
html[data-theme-style="dark-soft"] .dd-state.error { color: #ff7875; }
html[data-theme-style="dark"] .dd-state.processing,
html[data-theme-style="dark-soft"] .dd-state.processing { color: #b37feb; }

/* ── Chân bảng ── */
.dd-table-foot {
  min-height: 48px;
  padding: 8px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  background: var(--surface);
  border: 1px solid var(--line);
  border-top: 0;
  border-radius: 0 0 var(--radius) var(--radius);
  color: var(--ink-soft);
  font-size: 12px;
}
.dd-pager { display: inline-flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.dd-page-size .select { width: auto; min-width: 96px; height: 30px; font-size: 12px; }
.dd-pager .pagination { padding: 0; gap: 4px; display: inline-flex; align-items: center; }
.dd-pager .btn { min-width: 30px; min-height: 30px; height: 30px; padding: 0 8px; font-size: 12px; }
.dd-pager .page-num.is-current { color: var(--surface); background: var(--accent); border-color: var(--accent); font-weight: 700; }
.dd-goto { display: inline-flex; align-items: center; gap: 6px; }
.dd-goto .input { width: 56px; height: 30px; padding: 0 8px; font-size: 12px; text-align: center; }

@media (max-width: 1180px) {
  .dd-topbar { grid-template-columns: auto minmax(0, 1fr); row-gap: 0; }
  .dd-topbar-end { display: none; }
  .dd-tabs { overflow: auto; }
  .dd-kv-table { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dd-kv:nth-child(3n) { border-right: 1px solid var(--line); }
  .dd-kv:nth-child(2n) { border-right: 0; }
  .dd-rule-layout { grid-template-columns: minmax(0, 1fr); }
  .dd-rule-rail { min-height: 0; grid-auto-flow: column; justify-content: start; }
}
@media (max-width: 720px) {
  .dd-hero { grid-template-columns: minmax(0, 1fr); }
  .dd-kv-table { grid-template-columns: minmax(0, 1fr); }
  .dd-kv { border-right: 0; }
  .dd-kv:nth-child(3n) { border-right: 0; }
  .dd-field { grid-template-columns: minmax(0, 1fr); }
  .dd-field > span:first-child { text-align: left; }
}
