/* ========== Reset đơn giản & base ========== */

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

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  font-size: 14px;
  color: #111827;
  background: #f3f4f6;
}

/* ========== App shell & layout chính ========== */

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

/* Header: tab chọn chế độ */

.app-header {
  padding: 10px 16px;
  background: #111827;
  color: #f9fafb;
}

.mode-tabs {
  display: inline-flex;
  background: #1f2937;
  border-radius: 999px;
  padding: 4px;
  gap: 4px;
}

.mode-tab {
  border: none;
  border-radius: 999px;
  padding: 4px 14px;
  font-size: 13px;
  cursor: pointer;
  background: transparent;
  color: #e5e7eb;
}

.mode-tab--active {
  background: #f9fafb;
  color: #111827;
}

/* Main layout: trái (khối 1-2-3), phải (khối 4) */

.app-main {
  padding: 12px 16px 20px;
  flex: 1;
}

.layout {
  display: grid;
  grid-template-columns: minmax(360px, 420px) minmax(0, 1fr);
  gap: 12px;
  align-items: stretch;
  height: calc(100vh - 80px);
}

.layout__left,
.layout__right {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ========== Block chung ========== */

.block {
  background: #f9fafb;
  border-radius: 16px;
  box-shadow: 0 10px 25px rgba(15, 23, 42, 0.08);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.block__header {
  padding: 8px 14px;
  border-bottom: 1px solid #e5e7eb;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.block__header h2 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
}

.block__header-right {
  font-size: 12px;
  color: #9ca3af;
}

.block__header-tabs {
  display: inline-flex;
  border-radius: 999px;
  background: #111827;
  padding: 2px;
  gap: 4px;
}

.block-tab {
  border: none;
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 12px;
  cursor: pointer;
  background: transparent;
  color: #e5e7eb;
}

.block-tab--active {
  background: #f9fafb;
  color: #111827;
}

.block__body {
  padding: 10px 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.block__hint {
  margin: 4px 0 0;
  font-size: 12px;
  color: #6b7280;
}

/* ========== Button chung ========== */

.btn {
  border-radius: 999px;
  padding: 6px 12px;
  border: none;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
}

.btn-primary {
  background: #2563eb;
  color: #f9fafb;
}

.btn-primary:hover {
  background: #1d4ed8;
}

.btn-secondary {
  background: #111827;
  color: #f9fafb;
}

.btn-secondary:hover {
  background: #020617;
}

.btn-accent {
  background: #10b981;
  color: #f9fafb;
}

.btn-accent:hover {
  background: #059669;
}

.btn-full {
  width: 100%;
  justify-content: center;
  display: flex;
  align-items: center;
}

/* ========== Khối 1: Danh sách mã đơn ========== */

.block--orders .block__body {
  gap: 10px;
}

.order-list {
  border-radius: 12px;
  border: 1px solid #e5e7eb;
  background: #ffffff;
  padding: 4px;
  max-height: 180px;
  overflow-y: auto;
}

.order-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 32px;
  align-items: center;
  gap: 6px;
  padding: 4px 6px;
  border-radius: 8px;
  cursor: pointer;
}

.order-row:hover {
  background: #f3f4f6;
}

.order-row--active {
  background: #e0f2fe;
  box-shadow: 0 0 0 1px rgba(37, 99, 235, 0.4);
}

.order-row__code-input {
  width: 100%;
  border-radius: 8px;
  border: 1px solid #d1d5db;
  padding: 4px 8px;
  font-size: 13px;
}

.order-row__code-input:focus {
  outline: none;
  border-color: #2563eb;
  box-shadow: 0 0 0 1px rgba(37, 99, 235, 0.35);
}

.order-row__do-check {
  display: flex;
  align-items: center;
  justify-content: center;
}

.order-row__do-checkbox {
  width: 16px;
  height: 16px;
}

/* ========== Khối 2: Sản phẩm ========== */

.block--products {
  position: relative;
  z-index: 30;
}

.block--products .block__body {
  gap: 10px;
}

.products-header-row {
  display: grid;
  /* X | mã + mũi tên | size | qty */
  grid-template-columns: 32px minmax(0, 1.8fr) 70px 60px;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  color: #6b7280;
  padding: 0 2px;
}

.products-header-col {
  white-space: nowrap;
}

.products-header-col--name {
  overflow: hidden;
  text-overflow: ellipsis;
}

.products-header-col--delete {
  text-align: center;
}

.products-list {
  border-radius: 12px;
  border: 1px solid #e5e7eb;
  background: #ffffff;
  padding: 4px;
  min-height: 150px;        /* cao hơn để chứa nhiều dòng */
  max-height: none;         /* không giới hạn, để dropdown không bị cắt */
  overflow-y: visible;      /* cho dropdown tràn ra */
}

.product-row {
  display: grid;
  /* X | mã + mũi tên | size | qty */
  grid-template-columns: 32px minmax(0, 1.8fr) 70px 60px;
  gap: 6px;
  align-items: center;
  padding: 4px 6px;
  border-radius: 8px;
  cursor: pointer;
}


.product-row:hover {
  background: #f3f4f6;
}

.product-row--active {
  background: #2596be;
  box-shadow: 0 0 0 1px rgba(37, 99, 235, 0.4);
}

.product-col {
  display: flex;
  align-items: center;
  gap: 4px;
}

/* Cột xóa sản phẩm */

.product-col--delete {
  display: flex;
  align-items: center;
  justify-content: center;
}

.product-delete-btn {
  width: 20px;
  height: 20px;
  border-radius: 999px;
  border: none;
  background: #fee2e2;
  color: #b91c1c;
  font-weight: 700;
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
}

.product-delete-btn:hover {
  background: #fecaca;
}

/* Combo tìm / chọn mã bộ hình */

/* Ô mã bộ hình nhìn như 2 cột: [input] [▼] */
.product-combobox {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 28px;   /* input | mũi tên */
  align-items: stretch;
  width: 100%;
  border-radius: 12px;
  border: 1px solid #d1d5db;
  background: #e5f2ff;
  padding: 0;                                   /* để viền gọn */
  height: 32px;
}

.product-combobox-input {
  border: none;
  background: transparent;
  padding: 4px 8px;
  font-size: 12px;
  width: 100%;
}

.product-combobox-input:focus {
  outline: none;
}

/* Cột mũi tên riêng nhưng vẫn nằm bên trong khung */
.product-combobox-toggle {
  border: none;
  border-left: 1px solid #d1d5db;
  background: transparent;
  padding: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  color: #111827;
}

/* Dropdown list */

.product-combobox-list {
  position: absolute;
  left: 0;
  right: 0;
  top: 100%;
  margin-top: 4px;
  background: #ffffff;
  border-radius: 8px;
  border: 1px solid #d1d5db;
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.16);
  max-height: 180px;
  overflow-y: auto;
  z-index: 999;
  display: none;
}

.product-combobox-list--open {
  display: block;
}

.product-combobox-option {
  padding: 4px 8px;
  font-size: 12px;
  cursor: pointer;
}

.product-combobox-option:hover {
  background: #e5f2ff;
}

.product-combobox-option--empty {
  color: #9ca3af;
  font-style: italic;
}

/* Cột kích thước */

.product-size-input {
  width: 100%;
  border-radius: 8px;
  border: 1px solid #d1d5db;
  padding: 4px 6px;
  font-size: 12px;
}

.product-size-input:focus {
  outline: none;
  border-color: #16a34a;
  box-shadow: 0 0 0 1px rgba(22, 163, 74, 0.35);
}

.product-size-suffix {
  font-size: 11px;
  color: #6b7280;
}

/* Cột số lượng */

.product-qty-input {
  width: 100%;
  border-radius: 8px;
  border: 1px solid #d1d5db;
  padding: 4px 6px;
  font-size: 12px;
}

.product-qty-input:focus {
  outline: none;
  border-color: #f97316;
  box-shadow: 0 0 0 1px rgba(249, 115, 22, 0.35);
}

/* ========== Khối 3: Nội dung in ========== */

/* ==== Khối 3: Rich text editor ==== */
.print-editor-wrapper {
  margin-top: 8px;
}

.print-editor {
  min-height: 160px;
  max-height: 260px;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid #d0d5dd;
  background-color: #ffffff;
  font-size: 16px;
  line-height: 1.4;
  overflow-y: auto;
  outline: none;
  white-space: normal;
}

/* Placeholder cho contenteditable */
.print-editor[contenteditable="true"]:empty:before {
  content: attr(data-placeholder);
  color: #98a2b3;
  pointer-events: none;
}

.print-text-hidden {
  display: none;
}

.block--print-content {
  position: relative;
  z-index: 10;
}

.block--print-content .block__body {
  padding: 12px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Phần 2: text area */

.print-row--text .field-label {
  display: block;
  margin-bottom: 4px;
}

.field-label {
  font-size: 13px;
  font-weight: 600;
  color: #111827;
}

.print-textarea {
  width: 100%;
  min-height: 70px;           /* giảm bớt chiều cao */
  border-radius: 12px;
  border: 1px solid #d1d5db;
  padding: 10px 12px;
  font-size: 14px;
  resize: vertical;
  background: #ffffff;
}

.print-textarea:focus {
  outline: none;
  border-color: #2563eb;
  box-shadow: 0 0 0 1px rgba(37, 99, 235, 0.25);
}

/* Editor WYSIWYG của khối 3 */
.print-editor {
  width: 100%;
  min-height: 130px;
  max-height: 220px;
  padding: 12px;
  border-radius: 10px;
  border: 1px solid #dde3ef;
  background-color: #ffffff;
  overflow-y: auto;
  outline: none;
  font-size: 14px;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  white-space: pre-wrap;
  word-break: break-word;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.print-editor:focus {
  border-color: #1a73e8;
  box-shadow: 0 0 0 1px rgba(26, 115, 232, 0.15);
}

/* Placeholder khi editor đang trống */
.print-editor:empty::before {
  content: attr(data-placeholder);
  color: #9ca3af;
  pointer-events: none;
}



/* Phần 3: Font chữ + kích thước (1 hàng, label bên trái) */

.print-row--font {
  display: flex;
  gap: 16px;
  align-items: center;
}

.print-field {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
}

.print-row--font .field-label {
  margin-bottom: 0;
  min-width: 72px;           /* đảm bảo chữ không đè lên input */
}

.print-field--size {
  max-width: 220px;
}

.print-select {
  width: 100%;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid #d1d5db;
  font-size: 14px;
  background: #ffffff;
}

.print-size-wrapper {
  display: flex;
  align-items: center;
  gap: 4px;
}

.print-size-input {
  width: 70px;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid #d1d5db;
  font-size: 14px;
  background: #ffffff;
}

/* mũi tên tăng / giảm size */

.print-size-arrows {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.size-arrow {
  width: 22px;
  height: 14px;
  border-radius: 4px;
  border: 1px solid #d1d5db;
  font-size: 10px;
  line-height: 1;
  padding: 0;
  cursor: pointer;
  background: #f3f4f6;
}

.size-arrow:hover {
  background: #e5e7eb;
}

.print-select:focus,
.print-size-input:focus {
  outline: none;
  border-color: #0ea5e9;
  box-shadow: 0 0 0 1px rgba(14, 165, 233, 0.3);
}

/* Phần 4: Căn chỉnh + Màu chữ (2 cột) */

.print-row--align-color {
  display: flex;
  gap: 12px;
}

/* Cột trái: Căn chỉnh */

.align-panel {
  flex: 0 0 45%;
  max-width: 45%;
  background: #e5e7eb;
  border-radius: 12px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.align-title {
  font-size: 13px;
  font-weight: 600;
}

/* Grid 2 hàng × 3 cột cho 6 icon */

.align-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.align-icon-button {
  border: none;
  border-radius: 8px;
  padding: 2px;
  background: #9ca3af;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.align-icon-button img {
  width: 28px;
  height: 28px;
  display: block;
}

/* Icon đang được chọn */

.align-icon-button--active-h,
.align-icon-button--active-v {
  background: #111827;
  box-shadow: 0 0 0 2px #f9fafb inset;
}

/* Cột phải: Màu chữ */

.color-panel {
  flex: 1;
  background: #e5e7eb;
  border-radius: 12px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.color-group__title {
  font-size: 13px;
  font-weight: 600;
}

.color-swatches {
  display: grid;
  grid-template-columns: repeat(5, 22px);
  gap: 4px;
}

.color-swatch {
  width: 22px;
  height: 22px;
  border-radius: 4px;
  border: 1px solid #d1d5db;
  background: var(--swatch-color, #000000);
  cursor: pointer;
}

.color-swatch--active {
  outline: 2px solid #111827;
  outline-offset: 1px;
}

/* Màu khác */

.color-custom {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  margin-top: 4px;
  padding: 2px 4px;
  border-radius: 8px;
}

.color-custom--active {
  background: #e0f2fe;
  box-shadow: 0 0 0 1px rgba(37, 99, 235, 0.35);
}

.color-picker {
  width: 32px;
  height: 22px;
  padding: 0;
  border-radius: 4px;
  border: 1px solid #d1d5db;
  cursor: pointer;
}

.color-hex-input {
  width: 90px;
  padding: 4px 6px;
  font-size: 12px;
  border-radius: 6px;
  border: 1px solid #d1d5db;
}

.color-hex-input--active {
  border-color: #0ea5e9;
  box-shadow: 0 0 0 1px rgba(14, 165, 233, 0.3);
}

/* ========== Khối 4: Preview bản in (tạm thời) ========== */

.block-preview-body {
  display: flex;
  flex-direction: column;
  gap: 10px;
  height: 100%;
}

.preview-canvas {
  flex: 1;
  border-radius: 12px;
  border: 2px dashed #d1d5db;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fefefe;
}

.preview-placeholder {
  font-size: 13px;
  color: #9ca3af;
}

.preview-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}
