/* ====== Reset & biến màu ====== */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --bg: #f5f7fb;
  --surface: #ffffff;
  --border: #e5e7eb;
  --text: #1f2937;
  --muted: #6b7280;
  --success: #16a34a;
  --danger: #dc2626;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.08);
  --radius: 10px;
}

html,
body {
  height: 100%;
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
    Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

/* ====== Navbar ====== */
.navbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
  padding: 0 24px;
  height: 60px;
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
  z-index: 100;
}

.navbar-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 16px;
}
.logo {
  font-size: 22px;
}
.brand-name {
  color: var(--primary);
}

.menu {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.menu-item {
  background: transparent;
  border: none;
  padding: 8px 14px;
  font-size: 14px;
  color: var(--text);
  cursor: pointer;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition:
    background 0.15s,
    color 0.15s;
}
.menu-item:hover {
  background: #eef2ff;
  color: var(--primary);
}
.menu-item.active {
  background: var(--primary);
  color: #fff;
}
.menu-item .icon {
  font-size: 15px;
}

/* ====== Main ====== */
.main {
  width: 100%;
  padding: 16px 20px;
}

/* ====== Toolbar ====== */
.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--surface);
  padding: 16px 20px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 12px;
}
.toolbar-left {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.page-title {
  font-size: 18px;
  font-weight: 600;
}
.file-info {
  font-size: 13px;
  color: var(--muted);
}
.toolbar-right {
  display: flex;
  gap: 10px;
  align-items: center;
}

.search {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  width: 220px;
  outline: none;
  transition:
    border 0.15s,
    box-shadow 0.15s;
}
.search:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition:
    background 0.15s,
    transform 0.05s;
  user-select: none;
}
.btn:active {
  transform: translateY(1px);
}
.btn-primary {
  background: var(--primary);
  color: #fff;
}
.btn-primary:hover {
  background: var(--primary-hover);
}

/* ====== Dropzone ====== */
.dropzone {
  background: var(--surface);
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 50px 20px;
  text-align: center;
  transition:
    background 0.15s,
    border-color 0.15s;
  cursor: pointer;
}
.dropzone:hover,
.dropzone.dragover {
  border-color: var(--primary);
  background: #eff6ff;
}
.dropzone-icon {
  font-size: 56px;
  margin-bottom: 12px;
}
.dropzone-text {
  font-size: 16px;
  line-height: 1.6;
}
.muted {
  color: var(--muted);
}
.small {
  font-size: 12px;
  margin-top: 6px;
}

/* ====== Viewer ====== */
.viewer {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.viewer.hidden {
  display: none;
}
.dropzone.hidden {
  display: none;
}

.sheet-tabs {
  display: flex;
  gap: 2px;
  padding: 8px 8px 0;
  border-bottom: 1px solid var(--border);
  background: #fafbfc;
  overflow-x: auto;
}
.sheet-tab {
  padding: 8px 16px;
  background: transparent;
  border: none;
  border-radius: 6px 6px 0 0;
  cursor: pointer;
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
}
.sheet-tab:hover {
  background: #eef2ff;
  color: var(--primary);
}
.sheet-tab.active {
  background: var(--surface);
  color: var(--primary);
  font-weight: 600;
  border: 1px solid var(--border);
  border-bottom: 1px solid var(--surface);
  margin-bottom: -1px;
}

.table-wrap {
  overflow: auto;
  max-height: calc(100vh - 220px);
}
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.data-table thead th {
  position: sticky;
  top: 0;
  background: #f3f4f6;
  color: var(--text);
  font-weight: 600;
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  white-space: nowrap;
  z-index: 1;
}
.data-table tbody td {
  padding: 8px 12px;
  border-bottom: 1px solid #f1f3f5;
  border-right: 1px solid #f1f3f5;
  white-space: nowrap;
}
.data-table tbody tr:hover {
  background: #f9fafb;
}
.data-table tbody tr:nth-child(even) {
  background: #fafbfc;
}
.data-table tbody tr:nth-child(even):hover {
  background: #f3f4f6;
}
.col-right {
  text-align: right;
}
.col-service-name {
  max-width: 280px;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
}
/* ====== Click-to-edit ====== */
.editable-cell {
  cursor: pointer;
  position: relative;
}
.editable-cell:hover {
  background: #eef2ff !important;
  outline: 1px solid #a5b4fc;
  outline-offset: -1px;
}
.cell-editor {
  width: 100%;
  min-width: 80px;
  padding: 3px 6px;
  border: 2px solid var(--primary);
  border-radius: 4px;
  font-size: 13px;
  font-family: inherit;
  background: #fff;
  color: var(--text);
  outline: none;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.row-num {
  background: #f3f4f6 !important;
  color: var(--muted);
  text-align: center;
  font-weight: 500;
  position: sticky;
  left: 0;
}

.status-bar {
  display: flex;
  gap: 16px;
  padding: 8px 16px;
  background: #fafbfc;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--muted);
}

/* ====== Misa Setup Form ====== */
.misa-setup-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.misa-form-row {
  display: grid;
  grid-template-columns: 220px 1fr;
  align-items: center;
  gap: 8px;
}
.misa-section-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--primary);
  border-bottom: 1px solid var(--border);
  padding-bottom: 4px;
  margin-top: 6px;
}
.misa-sheet-status {
  font-size: 12px;
  padding: 3px 8px;
  border-radius: 4px;
  white-space: nowrap;
}
.misa-sheet-status.loading {
  color: #888;
}
.misa-sheet-status.success {
  color: var(--success);
}
.misa-sheet-status.error {
  color: var(--danger);
}
.footer-center {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
}

/* ====== Toast ====== */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--text);
  color: #fff;
  padding: 12px 18px;
  border-radius: 8px;
  box-shadow: var(--shadow-lg);
  font-size: 14px;
  opacity: 0;
  transform: translateY(20px);
  transition:
    opacity 0.25s,
    transform 0.25s;
  pointer-events: none;
  z-index: 200;
}
.toast.show {
  opacity: 1;
  transform: translateY(0);
}
.toast.success {
  background: var(--success);
}
.toast.error {
  background: var(--danger);
}

/* ====== Responsive ====== */
@media (max-width: 768px) {
  .navbar {
    flex-direction: column;
    height: auto;
    padding: 12px;
    gap: 10px;
  }
  .menu {
    justify-content: center;
  }
  .toolbar {
    flex-direction: column;
    align-items: stretch;
  }
  .toolbar-right {
    flex-direction: column;
  }
  .search {
    width: 100%;
  }
}

/* ====== Modal ====== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 300;
  padding: 16px;
}
.modal-overlay.hidden {
  display: none;
}
.modal {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 600px;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  animation: modalIn 0.18s ease;
}
@keyframes modalIn {
  from {
    opacity: 0;
    transform: translateY(-12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 {
  font-size: 16px;
  font-weight: 600;
}
.modal-close {
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  color: var(--muted);
  padding: 4px 8px;
  border-radius: 6px;
  line-height: 1;
}
.modal-close:hover {
  background: #f3f4f6;
  color: var(--text);
}
.modal-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.modal-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
}
.footer-left {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.footer-right {
  display: flex;
  gap: 8px;
}

/* ====== Form helpers ====== */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.form-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}
.form-label.sm {
  font-size: 12px;
  color: var(--muted);
  font-weight: 500;
}
.form-select,
.form-input {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  outline: none;
  transition:
    border 0.15s,
    box-shadow 0.15s;
  background: var(--surface);
  color: var(--text);
}
.form-select:focus,
.form-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}
.btn-ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-ghost:hover {
  background: var(--bg);
}
.btn-outline {
  background: transparent;
  color: var(--primary);
  border: 1px solid var(--primary);
}
.btn-outline:hover {
  background: #eff6ff;
}
.btn-sm {
  padding: 5px 10px;
  font-size: 13px;
}

/* ====== Bundle rules ====== */
.bundle-rules-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.bundle-rules-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.bundle-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.bundle-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: #f3f4f6;
  border-bottom: 1px solid var(--border);
}
.bundle-card-title {
  font-weight: 600;
  font-size: 13px;
}
.bundle-card-body {
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.btn-icon {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 16px;
  padding: 4px 6px;
  border-radius: 6px;
  transition: background 0.15s;
  line-height: 1;
}
.btn-icon:hover {
  background: #fee2e2;
}
.service-checkboxes {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 200px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  background: var(--bg);
}
.check-item {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 13px;
  padding: 3px 0;
  border-radius: 4px;
}
.check-item input[type="checkbox"] {
  accent-color: var(--primary);
  width: 14px;
  height: 14px;
  cursor: pointer;
  flex-shrink: 0;
}
.check-item:hover span {
  color: var(--primary);
}
.empty-rules {
  padding: 16px 0;
  text-align: center;
}

/* ====== Tag input (dịch vụ trong gói) ====== */
.service-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 38px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  align-items: center;
}
.service-tag {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  background: #dbeafe;
  color: #1e40af;
  border-radius: 20px;
  padding: 3px 6px 3px 10px;
  font-size: 12px;
  font-weight: 500;
  line-height: 1.4;
}
.tag-remove {
  background: none;
  border: none;
  cursor: pointer;
  color: #60a5fa;
  font-size: 16px;
  padding: 0 3px;
  line-height: 1;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
}
.tag-remove:hover {
  background: #bfdbfe;
  color: #1d4ed8;
}
.tag-input-row {
  display: flex;
  gap: 6px;
  margin-top: 6px;
}
.tag-input-row .form-input {
  flex: 1;
  font-size: 13px;
}
.no-tags {
  font-style: italic;
  font-size: 12px;
}

/* ====== Service modal ====== */
.modal-wide {
  max-width: 760px;
}
.service-modal-toolbar {
  margin-bottom: 4px;
}
.service-table-wrap {
  overflow: auto;
  max-height: 52vh;
  border: 1px solid var(--border);
  border-radius: 8px;
}
.service-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.service-table thead th {
  position: sticky;
  top: 0;
  background: #f3f4f6;
  color: var(--text);
  font-weight: 600;
  text-align: left;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  z-index: 1;
}
.service-table tbody td {
  padding: 8px 14px;
  border-bottom: 1px solid #f1f3f5;
  white-space: nowrap;
}
.service-table tbody tr:hover {
  background: #f0f4ff;
}
.service-table tbody tr:nth-child(even) {
  background: #fafbfc;
}
.service-table tbody tr:nth-child(even):hover {
  background: #f0f4ff;
}
.service-table .col-price {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.service-table .col-code {
  font-family: monospace;
  color: var(--primary);
  font-weight: 600;
}
.service-search {
  width: 100%;
}
.service-loading {
  text-align: center;
  padding: 24px;
}
.service-count {
  text-align: right;
  margin-top: 4px;
}
.service-error {
  color: var(--danger);
}

/* ====== Split bar (inline) ====== */
.split-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: #f0f4ff;
  border-bottom: 1px solid #c7d7f8;
  flex-wrap: wrap;
  gap: 8px;
}
.split-bar.hidden {
  display: none;
}

/* ====== Split service result modal ====== */
.modal-fullscreen {
  max-width: 95vw;
  max-height: 92vh;
}
.split-table-wrap {
  max-height: 58vh;
}
.split-summary {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.split-stat {
  padding: 5px 14px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}
.split-stat-total {
  background: #eff6ff;
  color: #1d4ed8;
}
.split-stat-ok {
  background: #f0fdf4;
  color: #16a34a;
}
.split-stat-warn {
  background: #fef2f2;
  color: #dc2626;
}
.split-stat-customer {
  background: #f0f9ff;
  color: #0369a1;
}
.split-stat-money {
  background: #fefce8;
  color: #92400e;
}
.split-stat-disc {
  background: #fdf4ff;
  color: #7e22ce;
}
.split-row-unmatched td {
  background: #fef2f2 !important;
  color: #b91c1c !important;
}
.row-unitprice-mismatch td {
  background: #fee2e2 !important;
  color: #991b1b !important;
}
}

/* Đường kẻ phân nhóm gói trong bảng Setup tách gói */
.goi-kham-group-start td {
  border-top: 2px solid #a5b4fc !important;
}

/* ====== Card layout - Setup tách gói ====== */
.goi-cards-grid {
  padding: 4px 2px;
}

.goi-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.goi-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: linear-gradient(135deg, #eff6ff 0%, #eef2ff 100%);
  border-bottom: 1px solid #c7d2fe;
  gap: 8px;
}

.goi-card-code {
  font-weight: 700;
  font-size: 13px;
  color: var(--primary);
  display: block;
}

.goi-card-name {
  font-size: 12px;
  color: var(--muted);
  display: block;
  margin-top: 2px;
}

.goi-card-badge {
  background: var(--primary);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 20px;
  white-space: nowrap;
  flex-shrink: 0;
}

.goi-card-badges {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.goi-card-total {
  font-size: 12px;
  font-weight: 700;
  color: var(--primary);
  background: #dbeafe;
  padding: 3px 10px;
  border-radius: 20px;
  white-space: nowrap;
}

.goi-card-body {
  padding: 0;
}

.goi-inner-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.goi-inner-table thead th {
  background: #f9fafb;
  padding: 6px 10px;
  text-align: left;
  font-weight: 600;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.goi-inner-table tbody td {
  padding: 6px 10px;
  border-bottom: 1px solid #f1f3f5;
  color: var(--text);
}

.goi-inner-table tbody tr:last-child td {
  border-bottom: none;
}

.goi-inner-table tbody tr:hover td {
  background: #f5f7ff;
}

.goi-row-highlight td {
  background: #fefce8 !important;
  font-weight: 600;
}

.goi-total-row td {
  background: #eff6ff !important;
  border-top: 2px solid #bfdbfe !important;
  font-weight: 700;
  color: var(--text);
  padding: 7px 10px;
}

.goi-total-price {
  color: var(--primary) !important;
  font-size: 13px;
}

/* % Discount column */
.discount-pct-col {
  text-align: right;
  font-weight: 600;
  min-width: 90px;
}
th.discount-pct-col {
  background: #fffbeb;
  color: #92400e;
}
.discount-warn {
  background: #fef2f2 !important;
  color: #b91c1c !important;
  font-weight: 700;
}
