:root {
  --brand: #d31e2d;
  --brand-hover: #b01824;
  --accent: var(--brand);
  --accent-hover: var(--brand-hover);
  --navy: #0c1d3a;
  --navy-light: #1a3a6b;
  --accent-soft: #fdecef;
  --sidebar-w: 212px;
  --content-max: 1280px;
  --bg: #eceef1;
  --surface: #fff;
  --header-bg: #f5f6f8;
  --table-head: #f0f1f3;
  --border: #d8dce2;
  --text: #333;
  --text-strong: #111;
  --text-muted: #666;
  --green: #2e7d32;
  --red: #c62828;
  --gray: #757575;
  --warn: #d97706;
  --radius: 6px;
  --shadow: 0 1px 3px rgba(0,0,0,0.06);
  --font: "Be Vietnam Pro", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", "Segoe UI Mono", Consolas, monospace;
  --text-base: 14px;
  --text-sm: 13px;
  --text-xs: 12px;
  --text-lg: 15px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: var(--text-base);
  line-height: 1.5;
}

.app-shell { display: flex; min-height: 100vh; }

/* Sidebar navy */
.sidebar {
  width: var(--sidebar-w);
  background: linear-gradient(180deg, var(--navy-light) 0%, var(--navy) 100%);
  position: fixed;
  inset: 0 auto 0 0;
  display: flex;
  flex-direction: column;
  z-index: 10;
}

.sidebar-brand {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  padding: 14px 12px 12px;
  border-bottom: 1px solid rgba(255,255,255,0.15);
}

.sidebar-logo {
  display: block;
  width: 100%;
  max-width: 168px;
  height: auto;
  background: #fff;
  border-radius: 8px;
  padding: 8px 10px;
}

.sidebar-product {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.55);
  padding-left: 2px;
}

.sidebar-nav { flex: 1; padding: 8px; }

.nav-link {
  display: block;
  width: 100%;
  border: none;
  background: transparent;
  color: rgba(255,255,255,0.9);
  text-align: left;
  padding: 8px 12px;
  font: inherit;
  font-size: var(--text-sm);
  cursor: pointer;
  border-radius: var(--radius);
}

.nav-link:hover { background: rgba(255,255,255,0.12); }
.nav-link.active { background: rgba(255,255,255,0.22); font-weight: 600; color: #fff; }

.sidebar-meta {
  padding: 10px 14px;
  border-top: 1px solid rgba(255,255,255,0.15);
  font-size: var(--text-xs);
  color: rgba(255,255,255,0.75);
}

.sidebar-footer {
  padding: 10px 14px 14px;
  border-top: 1px solid rgba(255,255,255,0.15);
  font-size: 11px;
  color: rgba(255,255,255,0.55);
  line-height: 1.45;
}

.sidebar-footer a {
  color: rgba(255,255,255,0.85);
  text-decoration: none;
  font-weight: 600;
}

.sidebar-footer a:hover {
  text-decoration: underline;
  color: #fff;
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  display: inline-block;
  margin-right: 4px;
  background: rgba(255,255,255,0.5);
}

.sidebar .status-dot.online { background: #a7f3d0; }
.sidebar .status-dot.offline { background: #fecaca; }

/* Workspace */
.workspace {
  flex: 1;
  margin-left: var(--sidebar-w);
  min-width: 0;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px 0 12px;
  height: 48px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.page-title {
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--text-strong);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: var(--text-sm);
}

.user-name { color: var(--text-muted); max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.session-chip { color: var(--text-muted); font-size: var(--text-xs); }
.session-chip.session-warn { color: var(--warn); }

/* Nội dung sát sidebar, rộng tối đa */
.app-content {
  width: 100%;
  max-width: var(--content-max);
  margin: 0;
  padding: 14px 20px 20px 12px;
}

.view { display: none; }
.view.active { display: block; }

/* Khối tìm kiếm — giống mẫu ERP */
.search-panel {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  flex-wrap: wrap;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 10px;
}

.panel-label {
  width: 100%;
  font-size: var(--text-sm);
  font-weight: 700;
  color: var(--text-strong);
  margin-bottom: 0;
}

.panel-hint {
  width: 100%;
  font-size: var(--text-xs);
  color: var(--text-muted);
  margin-bottom: 4px;
}

.search-fields {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 16px;
  flex: 1;
}

.claim-fields { margin-bottom: 0; }

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 140px;
  flex: 1;
  max-width: 240px;
}

.field label {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-muted);
}

.field-hint {
  font-size: var(--text-xs);
  color: var(--text-muted);
  margin-top: 4px;
}

.inline-toast {
  width: 100%;
  font-size: var(--text-sm);
  padding: 4px 0 0;
}

.inline-toast.success { color: var(--green); }
.inline-toast.error { color: var(--red); }

/* Khối danh sách */
.list-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.list-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.list-meta { font-size: var(--text-sm); color: var(--text-muted); }
.list-count { font-size: var(--text-xs); color: var(--text-muted); font-weight: 600; }

.pager {
  display: flex;
  align-items: center;
  gap: 2px;
}

.pager-btn {
  width: 28px;
  height: 28px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  color: var(--text);
}

.pager-btn:hover:not(:disabled) { background: var(--header-bg); }
.pager-btn:disabled { opacity: 0.35; cursor: not-allowed; }

.pager-num {
  min-width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-xs);
  font-weight: 600;
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-base);
}

.data-table thead th {
  text-align: left;
  padding: 8px 12px;
  font-size: var(--text-sm);
  font-weight: 700;
  color: var(--text-strong);
  background: var(--table-head);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-table tbody td {
  padding: 8px 12px;
  border-bottom: 1px solid #ebecef;
  vertical-align: middle;
  color: var(--text);
}

.data-table tbody tr:hover td { background: #fafafa; }
.data-table tbody tr:last-child td { border-bottom: none; }

.col-chevron { width: 32px; }

.data-table tbody tr.row-clickable { cursor: pointer; transition: background 0.12s; }
.data-table tbody tr.row-clickable:hover td { background: var(--accent-soft); }
.data-table tbody tr.row-clickable:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

.cell-name { font-weight: 600; color: var(--text-strong); }
.cell-chevron {
  width: 28px;
  text-align: right;
  color: var(--text-muted);
  font-size: 18px;
  line-height: 1;
}

/* —— Device detail —— */
.btn-back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 0;
  margin-bottom: 12px;
  border: none;
  background: none;
  font: inherit;
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--accent);
  cursor: pointer;
}

.btn-back:hover { color: var(--accent-hover); }
.btn-back-icon { font-size: 16px; line-height: 1; }

.detail-hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 16px 18px;
  margin-bottom: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.detail-hero-left {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.device-icon {
  width: 48px;
  height: 48px;
  flex-shrink: 0;
  border-radius: var(--radius);
  background: var(--accent-soft);
  border: 1px solid #f5c2c9;
  color: var(--accent-hover);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: -0.02em;
  display: flex;
  align-items: center;
  justify-content: center;
}

.detail-hero-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-strong);
  line-height: 1.25;
  margin-bottom: 2px;
}

.detail-hero-id {
  font-family: var(--mono);
  font-size: var(--text-sm);
  color: var(--text-muted);
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 12px;
}

.info-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
}

.info-card-wide { grid-column: 1 / -1; }

.info-card-title {
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid #ebecef;
}

.info-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  padding: 7px 0;
  font-size: var(--text-sm);
  border-bottom: 1px solid #f3f4f6;
}

.info-row:last-child { border-bottom: none; padding-bottom: 0; }
.info-row:first-of-type { padding-top: 0; }

.info-label {
  flex-shrink: 0;
  color: var(--text-muted);
  font-weight: 500;
  min-width: 72px;
}

.info-value {
  text-align: right;
  color: var(--text-strong);
  word-break: break-all;
}

.info-value code {
  font-size: var(--text-xs);
  background: var(--header-bg);
  padding: 2px 6px;
  border-radius: 3px;
  border: 1px solid var(--border);
}

.token-block {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-top: 4px;
  padding: 10px 12px;
  background: var(--header-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.token-block code {
  flex: 1;
  font-size: var(--text-xs);
  line-height: 1.5;
  word-break: break-all;
  background: none;
  border: none;
  padding: 0;
}

.detail-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.detail-bar .btn-outline,
.detail-bar .btn-search {
  min-height: 38px;
  padding: 8px 18px;
}

.claim-panel {
  margin-bottom: 10px;
}

.empty {
  text-align: center;
  color: var(--text-muted);
  padding: 32px 12px !important;
}

.cell-muted { color: var(--text-muted); font-size: var(--text-sm); }
.cell-msg { max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cell-error { max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--red); font-size: var(--text-sm); }
.cell-mono { font-family: var(--mono); font-size: var(--text-xs); }

.field-month { max-width: 160px; }
.field-month .input { min-width: 0; }

code { font-family: var(--mono); font-size: var(--text-sm); }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: var(--text-xs);
  font-weight: 600;
  background: #fff;
  border: 1px solid;
  white-space: nowrap;
}

.badge.success { color: var(--green); border-color: var(--green); }
.badge.error { color: var(--red); border-color: var(--red); }
.badge.pending { color: var(--gray); border-color: #aaa; }
.badge.online { color: var(--green); border-color: var(--green); }
.badge.offline { color: var(--gray); border-color: #bbb; }

/* Nút */
.btn {
  font: inherit;
  font-size: var(--text-base);
  cursor: pointer;
  border: none;
  border-radius: var(--radius);
}

.btn-search {
  padding: 7px 18px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  white-space: nowrap;
  min-height: 34px;
  font-size: var(--text-sm);
}

.btn-outline {
  padding: 5px 10px;
  background: #fff;
  border: 1px solid var(--border);
  color: var(--text);
  font-size: var(--text-sm);
}

.btn-text {
  padding: 4px 8px;
  background: transparent;
  color: var(--text-muted);
  font-size: var(--text-sm);
}

.input {
  width: 100%;
  min-width: 0;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font: inherit;
  font-size: var(--text-base);
  color: var(--text-strong);
  background: #fff;
}

.input.mono { font-family: var(--mono); font-size: var(--text-sm); }
.input:focus {
  outline: none;
  border-color: var(--accent);
}

.btn-search:hover { background: var(--accent-hover); }
.btn-outline:hover { border-color: var(--accent); color: var(--accent); }
.btn-text:hover { color: var(--accent); }
.btn-sm { font-size: var(--text-sm); }

.table-wrap { overflow-x: auto; }

.hidden { display: none !important; }

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal.hidden { display: none !important; }

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.35);
}

.modal-box {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 100%;
  max-width: 440px;
  max-height: 90vh;
  overflow: auto;
}

.modal-box.modal-form { max-width: 520px; }

.modal-box.modal-wide { max-width: 480px; }

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--header-bg);
}

.modal-header h3 { font-size: var(--text-lg); font-weight: 700; color: var(--text-strong); }
.modal-sub { font-size: var(--text-xs); color: var(--text-muted); font-family: var(--mono); margin-top: 2px; }
.modal-header-end { display: flex; align-items: center; gap: 8px; }

.modal-close {
  width: 26px;
  height: 26px;
  border: 1px solid var(--border);
  background: #fff;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  color: var(--text-muted);
}

.modal-body { padding: 14px 16px; }

.form-stack .field { margin-bottom: 14px; min-width: 0; max-width: none; }

.form-stack .field label {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text-strong);
  margin-bottom: 6px;
  display: block;
}

.form-stack .input {
  font-size: var(--text-base);
}

.input-template {
  font-size: 16px;
  line-height: 1.55;
  min-height: 88px;
  resize: vertical;
  padding: 10px 12px;
}

.form-stack .field-hint {
  margin-top: 6px;
  font-size: var(--text-sm);
}

.field-hint-over {
  color: var(--accent);
  font-weight: 600;
}

.info-value-template {
  font-size: var(--text-base);
  line-height: 1.5;
  text-align: left;
  white-space: pre-wrap;
  word-break: break-word;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}

.detail-section { margin-bottom: 14px; }
.detail-section-title { font-size: var(--text-xs); font-weight: 700; color: var(--text-muted); margin-bottom: 6px; }

.detail-row {
  display: grid;
  grid-template-columns: 96px 1fr;
  gap: 8px;
  padding: 8px 12px;
  font-size: var(--text-base);
  border-bottom: 1px solid #ebecef;
}

.detail-dl { border: 1px solid var(--border); border-radius: var(--radius); }

.detail-row:last-child { border-bottom: none; }
.detail-row dt { color: var(--text-muted); }
.detail-row dd { margin: 0; word-break: break-all; }

.token-card {
  display: flex;
  gap: 8px;
  padding: 8px 10px;
  background: var(--header-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.token-card code { flex: 1; word-break: break-all; font-size: var(--text-xs); background: none; }

.select { cursor: pointer; }

.check-table { width: 100%; font-size: var(--text-base); }
.check-table th {
  text-align: left;
  padding: 8px 12px;
  width: 42%;
  background: var(--table-head);
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
  font-weight: 600;
  font-size: var(--text-sm);
}
.check-table td { padding: 8px 12px; border-bottom: 1px solid #ebecef; }

@media (max-width: 768px) {
  .sidebar { position: relative; width: 100%; }
  .sidebar-nav { display: flex; gap: 4px; }
  .sidebar-meta { display: none; }
  .workspace { margin-left: 0; }
  .app-shell { flex-direction: column; }
  .app-content {
    width: 100%;
    padding: 12px 14px;
  }
  .search-panel { flex-direction: column; align-items: stretch; }
  .field { max-width: none; width: 100%; }
  .detail-grid { grid-template-columns: 1fr; }
  .detail-hero { padding: 14px; }
}
