:root {
  --bg: #f6f7fb;
  --panel: #ffffff;
  --panel-soft: #fbfcff;
  --text: #202638;
  --muted: #65708a;
  --border: #d9deea;
  --border-strong: #bcc5d6;
  --primary: #27428f;
  --primary-soft: #e9eefb;
  --danger: #d96810;
  --danger-soft: #fff0e3;
  --success: #16734c;
  --shadow: 0 12px 34px rgba(38, 47, 77, 0.08);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body.client-body {
  margin: 0;
  min-height: 100dvh;
  min-width: 320px;
  overflow-x: hidden;
  color: var(--text);
  background: var(--bg);
  font-family: "Segoe UI", Arial, sans-serif;
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
}

button {
  touch-action: manipulation;
}

.client-shell {
  min-height: 100vh;
  min-height: 100dvh;
  /* padding: 26px clamp(18px, 3vw, 42px); */
}

.client-app-header {
  padding: 5px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 3px;
}

.client-topbar {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  grid-template-areas: "brand title actions";
  align-items: center;
  gap: 12px;
  width: 100%;
}

.client-header-title {
  grid-area: title;
  margin: 0;
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: center;
  font-size: clamp(18px, 2.1vw, 30px);
  font-weight: 800;
  line-height: 1.2;
  letter-spacing: 0.02em;
  color: red;
}

.client-topbar-actions {
  grid-area: actions;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  justify-self: end;
}

.client-online-indicator {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  min-width: 42px;
  border-radius: 10px;
  border: 1px solid var(--border-strong);
  box-sizing: border-box;
}

.client-online-indicator__icon {
  display: block;
  flex-shrink: 0;
}

.client-online-indicator--online {
  color: var(--success);
  background: #eaf8f0;
  border-color: #b7e4c8;
}

.client-online-indicator--offline {
  color: #a15d00;
  background: #fff4e5;
  border-color: #f4d489;
}

.client-header-settings-button {
  flex-shrink: 0;
  width: 42px;
  height: 42px;
  min-width: 42px;
  padding: 0;
  border-radius: 10px;
  border-color: var(--border-strong);
}

.client-header-settings-button__icon {
  display: block;
  margin: 0 auto;
}

.client-header-fullscreen-button {
  position: relative;
}

.client-header-fullscreen-button__collapse {
  display: none;
}

.client-header-fullscreen-button--fullscreen .client-header-fullscreen-button__expand {
  display: none;
}

.client-header-fullscreen-button--fullscreen .client-header-fullscreen-button__collapse {
  display: block;
}

.client-header-fullscreen-button__layer {
  display: block;
  margin: 0 auto;
}

.client-brand {
  grid-area: brand;
  display: flex;
  align-items: center;
  min-width: 0;
  flex-shrink: 0;
}

.client-brand__logo {
  display: block;
  height: 40px;
  width: auto;
  max-width: min(320px, 52vw);
  object-fit: contain;
}

@media (max-width: 900px) {
  .client-topbar {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "brand actions"
      "title title";
    gap: 10px;
  }

  .client-header-title {
    font-size: clamp(17px, 4.5vw, 24px);
  }
}

.status-strip {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 14px;
}

.state-pill,
.device-badge {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--panel);
  padding: 0 12px;
  color: var(--text);
  white-space: nowrap;
  font-size: 13px;
}

.toolbar-button {
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--panel);
  padding: 0 14px;
  color: var(--text);
  white-space: nowrap;
  cursor: pointer;
  transition: border-color 0.15s ease, transform 0.15s ease, background 0.15s ease, color 0.15s ease;
}

.topbar-icon-button {
  height: 38px;
  border-radius: 4px;
  padding: 0 14px;
  gap: 8px;
  font-weight: 650;
  border-color: var(--border-strong);
}

.topbar-icon-button__icon {
  flex-shrink: 0;
  display: block;
}

.state-pill {
  font-weight: 780;
  letter-spacing: 0.02em;
}

.state-ok {
  color: var(--success);
  background: #eaf8f0;
  border-color: #b7e4c8;
}

.state-warn {
  color: #a15d00;
  background: #fff4d8;
  border-color: #f4d489;
}

.device-badge.approved {
  color: var(--success);
  border-color: #b7e4c8;
  background: #f3fbf6;
}

.square-tool-button {
  min-width: 112px;
  height: 44px;
  border-radius: 6px;
  padding: 0 12px;
  font-weight: 700;
}

.square-tool-button--with-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-color: var(--border-strong);
}

.square-tool-button__icon {
  flex-shrink: 0;
  display: block;
}

.toolbar-button:hover {
  border-color: var(--border-strong);
  background: var(--panel-soft);
}

.topbar-icon-button:hover {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary);
}

.toolbar-button:active,
.primary-action:active,
.danger-action:active {
  transform: translateY(1px);
}

.tablet-grid {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  gap: 3px;
  align-items: start;
}

.input-panel {
  position: sticky;
  top: 20px;
  display: grid;
  gap: 3px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 5px;
}

.field-block {
  display: grid;
  gap: 3px;
}

.field-block--product-customer > .product-select-inner {
  min-width: 0;
}

.client-product-field-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.client-customer-picker-btn {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
}

.client-selected-customer-line {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  padding: 2px 0 4px;
  line-height: 1.3;
}

.client-product-select-placeholder {
  margin: 0;
  font-size: 14px;
  color: var(--muted);
  padding: 8px 0;
  min-height: 44px;
  display: flex;
  align-items: center;
}

.customer-picker-modal-body .customer-picker-filter {
  margin-bottom: 4px;
}

.customer-picker-list {
  max-height: min(62vh, 440px);
  overflow-y: auto;
}

.customer-picker-row {
  text-align: left;
  cursor: pointer;
  border-radius: 8px !important;
  padding: 10px 12px;
}

.customer-picker-row__main strong {
  display: block;
  font-size: 15px;
}

.customer-picker-row__sub {
  font-size: 13px;
  color: var(--muted);
}

.field-block--product-customer .client-product-field-label-row > span:first-child {
  color: var(--muted);
  font-size: 14px;
}

.client-hidden {
  display: none !important;
}

.field-block > span,
.stats-title,
.result-note {
  color: var(--muted);
  font-size: 14px;
}

.field-block select,
.field-block input,
.search-box input,
.tool-select,
.device-card input,
.device-card select {
  width: 100%;
  height: 44px;
  color: var(--text);
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0 12px;
  outline: none;
}

.field-block select:focus,
.field-block input:focus,
.search-box input:focus,
.tool-select:focus,
.device-card input:focus,
.device-card select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(39, 66, 143, 0.12);
}

.device-card input.locked-input,
.device-card input[readonly] {
  color: #596173;
  background: #f3f6fb;
  cursor: default;
}

.qty-segment {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  overflow: hidden;
  height: 44px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-soft);
  flex: 1;
  min-width: 0;
}

.qty-cumulative-line {
  display: flex;
  align-items: stretch;
  gap: 8px;
}

.qty-cumulative-input-wrap {
  flex: 0 0 auto;
}

.qty-cumulative-input.form-control {
  width: 100px;
  min-width: 88px;
  height: 44px;
}

.field-block--qty-merge > span {
  margin-bottom: 4px;
  display: block;
}

.qty-option {
  border: 0;
  border-right: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  font-weight: 700;
}

.qty-option:last-child {
  border-right: 0;
}

.qty-option.active {
  color: var(--primary);
  background: var(--primary-soft);
}

.action-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.primary-action,
.danger-action {
  height: 48px;
  border: 0;
  border-radius: 8px;
  color: #fff;
  font-weight: 780;
  cursor: pointer;
  box-shadow: 0 12px 20px rgba(36, 50, 100, 0.12);
}

.primary-action {
  background: var(--primary);
}

.danger-action {
  background: var(--danger);
}

.screen-note {
  min-height: 38px;
  display: flex;
  align-items: center;
  color: var(--muted);
  background: var(--panel-soft);
  border: 1px dashed var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 13px;
}

.stats-panel {
  order: 1;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
}

.stats-grid div {
  min-height: 52px;
  padding: 6px 8px;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

.stats-grid div:nth-child(2n) {
  border-right: 0;
}

.stats-grid div:nth-last-child(-n + 2) {
  border-bottom: 0;
}

.stats-grid span {
  display: block;
  color: var(--muted);
  font-size: 11px;
}

.stats-grid strong {
  display: block;
  margin-top: 4px;
  font-size: 17px;
  line-height: 1.1;
}

.stats-panel-footer {
  padding: 6px 8px;
  border-top: 1px solid var(--border);
  background: var(--panel-soft);
}

.stats-panel-footer .cumulative-detail-button {
  width: 100%;
  height: 32px;
  min-height: 32px;
  padding: 0 10px;
  font-size: 12px;
  font-weight: 650;
  justify-content: center;
  border-radius: 6px;
}

.cumulative-panel {
  order: 2;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
}

.cumulative-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 150px;
  gap: 10px;
  align-items: center;
  padding: 12px;
  border-bottom: 1px solid var(--border);
  background: var(--panel-soft);
}

.cumulative-head span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.cumulative-head strong {
  display: block;
  margin-top: 3px;
  color: var(--primary);
  font-size: 22px;
}

.cumulative-head select {
  height: 38px;
  font-size: 13px;
}

.cumulative-head--compact {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.cumulative-detail-button {
  flex: 0 0 auto;
}

.cumulative-table-wrap--compact {
  max-height: 220px;
}

.cumulative-table--compact .cumulative-code-cell {
  min-width: 0;
}

.cumulative-table--compact .cumulative-code-cell strong {
  display: inline-block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: bottom;
}

.cumulative-modal-toolbar.cumulative-detail-filter-bar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr));
  align-items: end;
}

.cumulative-detail-filter-bar {
  gap: 10px 12px;
  width: 100%;
}

.cumulative-detail-filter__label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 4px;
}

.cumulative-detail-table th:nth-child(5),
.cumulative-detail-table th:nth-child(6),
.cumulative-detail-table th:nth-child(7),
.cumulative-detail-table td:nth-child(5),
.cumulative-detail-table td:nth-child(6),
.cumulative-detail-table td:nth-child(7),
.cumulative-detail-table tfoot th:nth-last-child(-n + 3) {
  text-align: right;
  white-space: nowrap;
}

.cumulative-detail-table th:nth-child(1),
.cumulative-detail-table th:nth-child(2),
.cumulative-detail-table th:nth-child(3),
.cumulative-detail-table th:nth-child(4),
.cumulative-detail-table td:nth-child(1),
.cumulative-detail-table td:nth-child(2),
.cumulative-detail-table td:nth-child(3),
.cumulative-detail-table td:nth-child(4) {
  text-align: left;
}

.cumulative-detail-table tfoot th:first-child {
  text-align: left;
}

.cumulative-modal-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.cumulative-modal-filter .form-select {
  min-width: 12rem;
  max-width: 100%;
}

.cumulative-empty {
  padding: 14px;
  color: var(--muted);
  background: var(--panel-soft);
  border: 1px dashed var(--border);
  border-radius: 8px;
}

.cumulative-table-wrap {
  max-height: 220px;
  overflow: auto;
}

.modal-body .cumulative-table-wrap {
  max-height: min(62vh, 560px);
}

.cumulative-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.cumulative-table th,
.cumulative-table td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.cumulative-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  color: var(--muted);
  background: #fff;
  font-weight: 700;
}

.cumulative-table tbody tr {
  cursor: pointer;
}

.cumulative-table tbody tr:hover {
  background: var(--primary-soft);
}

.cumulative-table tbody tr.selected {
  background: #f7f9ff;
}

.cumulative-table tfoot th {
  position: sticky;
  bottom: 0;
  z-index: 1;
  padding: 10px;
  color: var(--primary);
  background: #f7f9ff;
  border-top: 2px solid var(--primary);
  border-bottom: 0;
  font-weight: 800;
}

.cumulative-table td:first-child {
  width: 54px;
  white-space: nowrap;
}

.cumulative-detail-table td:first-child {
  width: auto;
  min-width: 4.5rem;
  max-width: 10rem;
}

.cumulative-table .numeric-cell {
  width: 74px;
  color: var(--primary);
  font-weight: 800;
  text-align: right;
  white-space: nowrap;
}

.cumulative-table td span {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  line-height: 1.25;
}

.cumulative-defect-cell {
  min-width: 150px;
}

.cumulative-defect-line {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: end;
}

.cumulative-defect-line span {
  min-width: 0;
}

.cumulative-defect-line small {
  color: var(--danger);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.defect-workspace {
  min-width: 0;
}

.quick-filters-strip {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 0;
}

.quick-filters-scroll {
  flex: 1 1 auto;
  min-width: 0;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 4px 0;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}

.quick-filters-scroll .quick-filters {
  display: flex;
  flex-wrap: nowrap;
  gap: 8px;
  padding: 0;
  min-height: 36px;
  align-items: center;
}

.quick-filters-float {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  align-self: center;
}

.quick-filters-float .square-tool-button {
  white-space: nowrap;
  flex-shrink: 0;
}

.filter-chip {
  height: 36px;
  flex: 0 0 auto;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--panel);
  color: var(--muted);
  padding: 0 14px;
  cursor: pointer;
}

.filter-chip.active {
  color: var(--primary);
  border-color: var(--primary);
  background: var(--primary-soft);
}

.defect-grid {
  --defect-grid-gap: 3px;
  --qc-defect-card-h: 88px;
  --qc-defect-arrange-card-h: 118px;
  --qc-defect-arrange-grid-max-h: calc(5 * var(--qc-defect-arrange-card-h) + 4 * var(--defect-grid-gap));
  --qc-defect-horizontal-card-h: var(--qc-defect-card-h);
  --qc-picker-card-h: 44px;
  --qc-picker-grid-max-h: calc(var(--qc-defect-grid-max-h) * 0.5);
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(168px, 1fr));
  grid-auto-rows: minmax(var(--qc-defect-card-h), auto);
  gap: var(--defect-grid-gap);
  align-content: start;
  padding: 2px 0 14px;
  /* Hiển thị tối đa 5 hàng ô; các thẻ phía sau cuộn dọc */
  max-height: var(--qc-defect-grid-max-h);
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-color: #8b94aa transparent;
}

.defect-grid.arrange-mode {
  --qc-defect-horizontal-card-h: var(--qc-defect-arrange-card-h);
  grid-auto-rows: minmax(var(--qc-defect-arrange-card-h), auto);
  max-height: var(--qc-defect-arrange-grid-max-h);
}

.client-picker-modal-grid-area:has(.defect-grid--horizontal) {
  overflow-y: hidden;
}

/* Chọn mã hàng / chuyền: thẻ ~50% so với lưới lỗi; modal có chiều cao flex rõ ràng */
.client-picker-modal-grid-area {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.client-picker-grid {
  --picker-card-h: var(--qc-picker-card-h);
  --picker-card-minw: 84px;
  grid-template-columns: repeat(auto-fill, minmax(var(--picker-card-minw), 1fr));
  grid-auto-rows: minmax(var(--picker-card-h), auto);
  max-height: var(--qc-picker-grid-max-h);
}

.client-picker-grid .defect-card.client-picker-card {
  height: var(--picker-card-h);
  min-height: var(--picker-card-h);
  padding: 4px 6px 5px;
  gap: 2px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
}

.client-picker-grid .defect-card.client-picker-card .defect-name {
  font-size: 0.8125rem;
  font-weight: 700;
  line-height: 1.15;
  margin: 0;
  text-align: center;
}

/* Chế độ cuộn ngang: 5 hàng / cột rồi sang cột tiếp theo (giống lưới lỗi) */
.client-picker-grid.defect-grid--horizontal {
  flex: 1 1 auto;
  min-height: 0;
  height: 100%;
  max-height: none;
  grid-template-columns: none !important;
  grid-auto-columns: var(--picker-card-minw) !important;
  grid-template-rows: repeat(5, minmax(var(--picker-card-h), 1fr)) !important;
  grid-auto-flow: column !important;
  align-content: stretch;
  overflow-x: auto !important;
  overflow-y: hidden !important;
  -webkit-overflow-scrolling: touch;
}

.client-picker-grid.defect-grid--horizontal .defect-card.client-picker-card {
  height: 100%;
  min-height: var(--picker-card-h);
  align-self: stretch;
}

.defect-card {
  position: relative;
  display: grid;
  grid-template-rows: auto auto;
  align-content: start;
  gap: 3px;
  height: var(--qc-defect-card-h);
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  padding: 5px 8px 8px;
  cursor: pointer;
  user-select: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease, opacity 0.15s ease, transform 0.15s ease;
}

.defect-grid.arrange-mode .defect-card {
  cursor: grab;
}

.defect-grid.arrange-mode .defect-card:active {
  cursor: grabbing;
}

/* Coarse / narrow view: pointer drag is used instead of native Html5 drag. */
@media (max-width: 980px), (pointer: coarse) {
  .defect-grid.arrange-mode .defect-card {
    touch-action: none;
    -webkit-user-drag: none;
  }

  .defect-grid.drag-active {
    touch-action: none;
  }

  .defect-grid.drag-active .defect-card {
    touch-action: none;
  }
}

.defect-card:hover,
.defect-card.selected {
  border-color: var(--primary);
  box-shadow: 0 8px 18px rgba(39, 66, 143, 0.12);
}

.defect-card.selected {
  background: #f7f9ff;
}

.defect-card.dragging {
  opacity: 0.48;
  transform: scale(0.98);
}

.defect-card.drag-over {
  border-color: var(--primary);
  background: #eef3ff;
  box-shadow: inset 0 0 0 2px rgba(61, 90, 254, 0.18);
}

.defect-grid.arrange-mode.drag-active .defect-card {
  cursor: grabbing;
}

.square-tool-button.defect-arrange-toggle--on {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary);
}

.defect-card--arrange {
  height: auto;
  min-height: var(--qc-defect-arrange-card-h);
  padding-bottom: 36px;
  padding-top: 5px;
}

.defect-shift-row {
  position: absolute;
  bottom: 6px;
  left: 6px;
  right: 6px;
  display: flex;
  gap: 6px;
  pointer-events: auto;
}

.defect-shift-btn {
  flex: 1;
  min-width: 0;
  height: 28px;
  margin: 0;
  padding: 0 4px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel-soft);
  color: var(--text);
  font-size: 16px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  user-select: none;
}

.defect-shift-btn:hover:not(:disabled) {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary);
}

.defect-shift-btn:disabled {
  opacity: 0.35;
  cursor: default;
}

.defect-shift-btn:active:not(:disabled) {
  transform: translateY(1px);
}

.defect-meta {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  min-width: 0;
}

.defect-meta > span:first-child {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: 1.22;
}

.defect-count {
  flex-shrink: 0;
  margin-left: auto;
  min-width: 22px;
  height: 22px;
  display: inline-flex;
  justify-content: center;
  align-items: center;
  align-self: flex-start;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 800;
  line-height: 1;
}

.favorite-button {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: #8b94aa;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
  margin: 0;
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  /* Glyph căn giữa trong ô 40px nhìn thấp hơn dòng chữ ~13px — nâng nhẹ để trùng hàng */
  transform: translateY(-7px);
}

.favorite-button.active {
  color: #eab308;
  background: transparent;
}

.defect-name {
  margin: 0;
  padding: 0;
  font-size: 15px;
  line-height: 1.2;
  font-weight: 730;
}

.sync-errors {
  margin-top: 8px;
  white-space: pre-wrap;
  color: #994b2a;
}

.client-settings-modal-body {
  padding-top: 12px;
}

.client-settings-rows {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 16px;
}

.client-settings-row {
  display: grid;
  grid-template-columns: minmax(8.5rem, 10.25rem) minmax(7.5rem, 1fr);
  gap: 12px;
  align-items: center;
  font-size: 14px;
}

.client-settings-row__label {
  color: var(--muted);
  line-height: 1.35;
}

.client-settings-row__value {
  font-weight: 700;
  color: var(--text);
  min-width: 7.5rem;
  white-space: nowrap;
}

.client-settings-row--device {
  align-items: start;
}

.client-settings-device-meta {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.device-badge.device-badge--settings {
  justify-self: start;
  white-space: normal;
  word-break: break-word;
  text-align: left;
  max-width: 100%;
  height: auto;
  min-height: 38px;
}

.client-settings-device-company {
  font-size: 12px;
  line-height: 1.4;
  color: var(--muted);
  word-break: break-word;
}

.client-settings-lock-section {
  border-top: 1px solid var(--border);
  padding: 14px 0 16px;
  display: grid;
  gap: 10px;
  margin-bottom: 8px;
}

.client-settings-lock-status {
  margin: 0;
  font-size: 13px;
  line-height: 1.45;
  color: var(--muted);
}

.client-settings-lock-toggle {
  width: 100%;
  justify-content: center;
}

.client-settings-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 18px;
}

.client-settings-actions .toolbar-button {
  flex: 1 1 auto;
  min-width: min(280px, 100%);
}

.client-settings-sync-errors-section {
  border-top: 1px solid var(--border);
  padding-top: 14px;
}

.client-settings-sync-errors-title {
  margin: 0 0 6px;
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
}

.device-panel {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(24, 31, 49, 0.36);
  z-index: 20;
}

.device-panel.open {
  display: flex;
}

.device-card {
  position: relative;
  width: min(100%, calc(100vw - 48px));
  max-width: 1040px;
  display: grid;
  gap: 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 24px 80px rgba(20, 27, 45, 0.2);
  padding: 22px;
}

.device-card-header {
  padding-right: 40px;
}

.device-card-body {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  align-items: stretch;
}

.device-card-body > label {
  min-width: 0;
}

.device-card-body.device-card-body--qr {
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
}

.device-camera-column {
  display: grid;
  gap: 8px;
  min-width: 0;
  align-content: start;
}

.device-control-column {
  display: grid;
  gap: 14px;
  min-width: 0;
  align-content: start;
}

.qr-scanner-video {
  width: 100%;
  aspect-ratio: 4 / 3;
  min-height: 240px;
  max-height: min(56vh, 430px);
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #111827;
  object-fit: cover;
}

.qr-scanner-status {
  color: var(--muted);
  font-size: 12px;
}

@media (min-width: 760px) {
  .device-card-body.device-card-body--qr {
    grid-template-columns: minmax(0, 1.3fr) minmax(260px, 0.7fr);
    align-items: start;
  }

  .device-control-column {
    padding-top: 2px;
  }
}

/* Cột đều nhau, lấp đầy hàng — không chừa ô trống */
@media (min-width: 560px) {
  .device-card-body {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px 14px;
  }

  .device-card-line-row {
    grid-column: 1 / -1;
  }
}

@media (min-width: 800px) {
  .device-card-body {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px 14px;
  }
}

.device-card-line-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px 14px;
  align-items: end;
  min-width: 0;
}

.device-card-line-row > label {
  min-width: 0;
}

@media (min-width: 600px) {
  .device-card-line-row {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

.device-location-note--field {
  display: grid;
  gap: 8px;
  align-content: end;
  padding-bottom: 2px;
  min-height: 44px;
  min-width: 0;
}

.device-location-note--field:empty {
  min-height: 0;
  padding-bottom: 0;
}

.device-close-button {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}

.device-close-button:hover {
  color: var(--text);
  border-color: var(--border-strong);
  background: var(--panel-soft);
}

.device-card h2 {
  margin: 0;
  font-size: 22px;
  font-weight: 780;
}

.device-card p {
  margin: 6px 0 0;
  color: var(--muted);
}

.device-card label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.device-location-note {
  min-height: 20px;
  color: var(--muted);
  font-size: 12px;
}

.device-message {
  min-height: 24px;
  color: var(--success);
  font-weight: 650;
}

.device-message.error {
  color: #a33c20;
}

.client-lock-overlay {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(8, 10, 18, 0.55);
  backdrop-filter: blur(28px) saturate(140%);
  -webkit-backdrop-filter: blur(28px) saturate(140%);
  z-index: 30;
}

.client-lock-overlay.open {
  display: flex;
}

.client-lock-card {
  width: min(100%, 460px);
  display: grid;
  gap: 18px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 16px;
  background: linear-gradient(180deg, #18233e 0%, #10192d 100%);
  box-shadow: 0 32px 84px rgba(8, 12, 20, 0.42);
  color: #eef4ff;
  padding: 24px;
}

.client-lock-card__header h2 {
  margin: 0;
  font-size: 26px;
  font-weight: 800;
}

.client-lock-card__header p {
  margin: 10px 0 0;
  color: rgba(238, 244, 255, 0.72);
  line-height: 1.5;
}

.client-lock-card__body {
  display: grid;
  gap: 14px;
}

.client-lock-device {
  display: grid;
  gap: 4px;
  padding: 12px 14px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.06);
}

.client-lock-device span,
.client-lock-field span {
  font-size: 13px;
  color: rgba(238, 244, 255, 0.7);
}

.client-lock-device strong {
  font-size: 16px;
  font-weight: 700;
}

.client-lock-field {
  display: grid;
  gap: 8px;
}

.client-lock-field input {
  height: 46px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

.client-lock-field input:focus {
  border-color: #89a8ff;
  box-shadow: 0 0 0 3px rgba(137, 168, 255, 0.2);
}

.client-lock-message {
  min-height: 22px;
  font-size: 13px;
  color: #ffd6a5;
}

.client-lock-message.error {
  color: #ffb8a7;
}

.client-lock-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.recovery-box {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  align-items: end;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel-soft);
}

.device-recover-button {
  height: 44px;
  min-width: 108px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 18px;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  background: var(--panel);
  color: var(--text);
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.15s ease;
  box-shadow: none;
}

.device-recover-button:hover {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary);
}

.device-recover-button:active {
  transform: translateY(1px);
}

.device-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  align-items: stretch;
}

.device-control-column .device-actions {
  grid-template-columns: 1fr;
}

.device-actions .primary-action,
.device-actions .toolbar-button {
  min-width: 0;
  width: 100%;
  height: 44px;
  border-radius: 8px;
  box-shadow: none;
}

.device-cache-button {
  color: var(--muted);
}

@media (max-width: 980px) {
  .tablet-grid {
    grid-template-columns: 1fr;
  }

  .input-panel {
    position: static;
  }
}

@media (max-width: 620px) {
  .client-shell {
    padding: 16px;
  }

  .device-panel {
    padding: 12px;
    align-items: flex-start;
    overflow-y: auto;
  }

  .device-card {
    width: 100%;
    max-width: none;
    padding: 18px;
  }

  .qr-scanner-video {
    min-height: 180px;
    max-height: 320px;
  }

  .device-card-header {
    padding-right: 36px;
  }

  .recovery-box {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .device-recover-button {
    width: 100%;
    min-width: 0;
  }

  .device-actions {
    grid-template-columns: 1fr;
  }

  .action-row {
    grid-template-columns: 1fr;
  }

  .cumulative-head {
    grid-template-columns: 1fr;
  }

  .defect-grid {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    --defect-grid-gap: 8px;
    gap: var(--defect-grid-gap);
  }

  .client-picker-grid {
    --picker-card-minw: 70px;
  }
}
