/* ===================================================== */
/* ===================== RESET ========================== */
/* ===================================================== */

* {
  box-sizing: border-box;
  font-family: Arial, Helvetica, sans-serif;
}

body {
  margin: 0;
  background: #f4f6f8;
  color: #333;
  -webkit-font-smoothing: antialiased;
}

/* ===================================================== */
/* ===================== HEADER ========================= */
/* ===================================================== */

header {
  background: #2c7be5;
  color: #fff;
  padding: 14px 20px;
  font-size: 18px;
  font-weight: bold;
  text-align: center;
  position: relative;
}

.lang-switch {
  position: absolute;
  right: 20px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
}

.lang-flag-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border: 1px solid #9ec1f6;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.12);
  padding: 0;
  margin: 0;
}

.lang-flag-btn:hover {
  background: rgba(255, 255, 255, 0.2);
}

.lang-flag-btn.active {
  border-color: #ffffff;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.25);
}

.lang-icon {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  object-fit: cover;
  display: block;
}

/* ===================================================== */
/* ===================== LAYOUT ========================= */
/* ===================================================== */

.container {
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: 30px;
  padding: 30px;
  max-width: 1600px;
  margin: auto;
}

.left-panel,
.right-panel {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.left-panel {
  position: sticky;
  top: 20px;
  height: fit-content;
}

.right-panel {
  background: #ffffff;
  padding: 25px;
  border-radius: 12px;
  box-shadow: 0 6px 18px rgba(0,0,0,0.05);
}

/* ===================================================== */
/* ===================== CARD =========================== */
/* ===================================================== */

.card {
  background: #fff;
  border-radius: 10px;
  padding: 18px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}

.card h3 {
  margin-top: 0;
}

/* ===================================================== */
/* ===================== FORM =========================== */
/* ===================================================== */

label {
  font-size: 14px;
  font-weight: 600;
  margin-top: 12px;
  display: block;
}

input,
textarea {
  width: 100%;
  padding: 10px 12px;
  font-size: 14px;
  border-radius: 6px;
  border: 1px solid #ccc;
}

input:focus,
textarea:focus {
  outline: none;
  border-color: #2c7be5;
}

/* ===================================================== */
/* ===================== BUTTON ========================= */
/* ===================================================== */

button {
  margin-top: 12px;
  padding: 10px 16px;
  background: #2c7be5;
  color: #fff;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  transition: 0.2s ease;
}

button:hover {
  background: #1a68d1;
}

button:active {
  transform: scale(0.98);
}

.primary-btn {
  width: 100%;
  font-weight: 600;
}

.action-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}

.action-grid .primary-btn {
  margin-top: 0;
}

.primary-btn:focus-visible {
  outline: 2px solid #1a68d1;
  outline-offset: 2px;
}

.primary-btn.is-loading,
.primary-btn:disabled {
  opacity: 0.85;
  cursor: not-allowed;
  pointer-events: none;
}

.create-mode-block {
  border: 1px solid #dfe6ef;
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 10px;
}

.exp-manager-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 12px;
  width: 100%;
}

.exp-manager-tab {
  margin-top: 0;
  width: 100%;
  min-width: 0;
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  white-space: nowrap;
  border: 1px solid #b9cff4;
  background: #eaf2ff;
  color: #1a4ea0;
  font-weight: 700;
}

.exp-manager-tab:hover {
  background: #dce9ff;
}

.exp-manager-tab.active {
  border-color: #2c7be5;
  background: #2c7be5;
  color: #fff;
}

.exp-manager-tab:focus,
.exp-manager-tab:focus-visible {
  outline: none;
  box-shadow: none;
}

.exp-manager-panel {
  display: none;
  width: 100%;
  max-width: 100%;
}

.exp-manager-panel.active {
  display: block;
}

.post-create-only {
  display: none;
}

.post-create-only.is-visible {
  display: block;
}

.edit-mode-block {
  margin-bottom: 0;
  width: 100%;
  max-width: 100%;
}

#panel-edit-exp #edit-exp-id,
#panel-edit-exp #btn-edit-exp,
#panel-edit-exp #edit-status {
  width: 100%;
  max-width: 100%;
}

#panel-edit-exp #btn-edit-exp {
  width: auto;
}

.edit-status-row {
  margin-top: 8px;
  min-height: 20px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
}

.edit-status-icon {
  width: 20px;
  height: 20px;
  display: inline-block;
  text-align: center;
  font-weight: 700;
  font-size: 20px;
  line-height: 1;
}

.manual-sheet-row.edit-manual-row {
  grid-template-columns: 54px minmax(0, 1fr) minmax(0, 1fr) 20px 32px 32px;
  align-items: center;
  column-gap: 8px;
  row-gap: 0;
}

.edit-row-status-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  font-size: 16px;
  font-weight: 700;
  line-height: 1;
}

.edit-manual-row .manual-add-btn,
.edit-manual-row .manual-remove-btn {
  margin-top: 0;
  width: 32px;
  height: 32px;
  min-width: 32px;
  justify-self: center;
}

.edit-manual-row .manual-sheet-input {
  min-width: 0;
}

.mode-title {
  font-weight: 700;
  margin-bottom: 8px;
}

.create-exp-desc {
  color: #2c7be5;
  font-weight: 600;
}

.manual-sheet-grid {
  display: grid;
  gap: 8px;
  margin: 8px 0 12px;
}

.manual-sheet-row {
  display: grid;
  grid-template-columns: 54px minmax(180px, 1fr) minmax(180px, 1fr) 20px 36px 36px;
  align-items: center;
  gap: 8px;
}

.manual-row-status-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  font-size: 16px;
  font-weight: 700;
  line-height: 1;
}

.manual-sheet-code {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 38px;
  border: 1px solid #d7dce3;
  border-radius: 8px;
  background: #f6f8fb;
  color: #2e3b4b;
  font-weight: 700;
  font-size: 13px;
}

.manual-sheet-input {
  margin-top: 0;
  height: 38px;
}

.manual-sheet-empty {
  display: block;
}

.manual-add-btn {
  width: 36px;
  height: 36px;
  min-width: 36px;
  margin-top: 0;
  padding: 0;
  border-radius: 8px;
  border: 1px solid #8fb5f6;
  background: #eaf2ff;
  color: #1b5ac6;
  font-size: 20px;
  font-weight: 700;
  line-height: 1;
}

.manual-add-btn:hover {
  background: #dce9ff;
}

.manual-remove-btn {
  width: 36px;
  height: 36px;
  min-width: 36px;
  margin-top: 0;
  padding: 0;
  border-radius: 8px;
  border: 1px solid #f1afb3;
  background: #fff1f2;
  color: #c83a45;
  font-size: 20px;
  font-weight: 700;
  line-height: 1;
}

.manual-remove-btn:hover {
  background: #ffe3e5;
}

.manual-add-btn.hidden {
  visibility: hidden;
  pointer-events: none;
}

.manual-remove-btn.hidden {
  visibility: hidden;
  pointer-events: none;
}

.manual-template-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.template-download-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 0 14px;
  border-radius: 8px;
  background: #e9f8ee;
  border: 1px solid #88d6a0;
  color: #0f6b31;
  font-weight: 600;
  text-decoration: none;
}

.template-download-btn:hover {
  background: #d9f3e2;
}

.data-entry-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 10px;
}

.data-entry-toolbar input[type="file"] {
  flex: 1 1 260px;
  min-width: 220px;
}

.data-entry-toolbar button {
  width: auto;
  margin-top: 0;
}

.data-entry-status {
  min-height: 20px;
  margin-bottom: 10px;
  font-weight: 600;
  color: #6b7280;
}

.data-entry-status.typing {
  color: #3b82f6;
}

.data-entry-status.saving {
  color: #f59e0b;
}

.data-entry-status.success {
  color: #16a34a;
}

.data-entry-status.error {
  color: #dc2626;
}

.data-entry-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.data-entry-tab {
  margin-top: 0;
  width: auto;
  min-height: 36px;
  padding: 0 14px;
  border: 1px solid #b9cff4;
  border-radius: 8px;
  background: #eaf2ff;
  color: #1a4ea0;
  font-weight: 700;
}

.data-entry-tab.active {
  background: #2c7be5;
  border-color: #2c7be5;
  color: #fff;
}

.data-entry-panel {
  display: none;
}

.data-entry-panel.active {
  display: block;
}

.data-entry-table-scroll {
  width: 100%;
  overflow: auto;
  border: 1px solid #dbe2ec;
  border-radius: 8px;
}

.data-entry-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}

.data-entry-table th,
.data-entry-table td {
  border: 1px solid #e3e8ef;
  padding: 6px;
  vertical-align: middle;
}

.data-entry-table th:nth-child(2),
.data-entry-table td:nth-child(2) {
  min-width: 320px; /* Treatment (display order) */
}

.data-entry-table th:nth-child(3),
.data-entry-table td:nth-child(3) {
  min-width: 120px; /* Group (display order) */
}

.row-stt-col,
.row-stt-cell {
  width: 72px;
  min-width: 72px;
  text-align: center;
}

.row-stt-cell {
  background: #f8fafc;
  color: #334155;
  font-weight: 600;
}

.data-entry-table th {
  background: #f4f7fb;
  font-weight: 700;
  white-space: nowrap;
}

.data-entry-cell {
  width: 100%;
  margin: 0;
  border-radius: 6px;
  border: 1px solid #cfd7e3;
  padding: 8px 10px;
}

.data-entry-cell.readonly-cell {
  background: #f4f7fb;
  color: #425466;
  cursor: not-allowed;
}

.data-entry-cell.locked-cell {
  background: #f9fafb;
  color: #94a3b8;
  cursor: not-allowed;
}

.data-entry-cell.invalid-group-cell {
  border-color: #ef4444;
  background: #fff5f5;
}

.data-entry-history-wrap {
  margin-top: 12px;
  border: 1px solid #dbe2ec;
  border-radius: 8px;
  padding: 10px;
  background: #fafcff;
  max-height: none;
  overflow: visible;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.history-row-group {
  border: 1px solid #d5dee9;
  border-radius: 8px;
  background: #f8fbff;
  padding: 10px;
}

.history-row-title {
  font-weight: 700;
  color: #1e3a8a;
  margin-bottom: 8px;
}

.history-row-items {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.history-indicator-group {
  border: 1px dashed #cdd9e7;
  border-radius: 8px;
  padding: 8px;
  background: #ffffff;
}

.history-indicator-title {
  font-weight: 700;
  color: #0f4c81;
  margin-bottom: 8px;
}

.history-item {
  border: 1px solid #e3e8ef;
  border-radius: 6px;
  padding: 8px 10px;
  background: #fff;
}

.history-time {
  font-size: 12px;
  color: #64748b;
  margin-bottom: 4px;
}

.history-main {
  font-size: 14px;
}

.gps-btn {
  width: auto;
  margin-top: 8px;
  padding: 8px 12px;
  background: #eef4ff;
  color: #1a4ea0;
  border: 1px solid #bcd3ff;
  font-weight: 600;
}

.gps-btn:hover {
  background: #dfebff;
}

.gps-btn:disabled {
  opacity: 0.8;
  cursor: not-allowed;
}

/* ===================================================== */
/* ===================== TABLE ========================== */
/* ===================================================== */

.table-wrapper {
  width: 100%;
  overflow-x: auto;
}

.desc-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: auto;
  font-size: 14px;
  min-width: 600px;
}

.desc-table th,
.desc-table td {
  padding: 10px 14px;
  text-align: center;
}

.desc-table thead tr {
  border-top: 2px solid #000;
  border-bottom: 2px solid #000;
}

.desc-table tbody tr:last-child {
  border-bottom: 2px solid #000;
}

.desc-table td.mean-sd {
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* ===================================================== */
/* ===================== JOURNAL ======================== */
/* ===================================================== */

.journal-result {
  font-family: "Times New Roman", serif;
  line-height: 1.7;
  background: #fff;
  padding: 25px;
  margin-top: 20px;
}

/* ===================================================== */
/* ===================== IMAGE GRID ===================== */
/* ===================================================== */

.image-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.image-thumb-wrapper {
  position: relative;
  border-radius: 12px;
  overflow: hidden;
}

.image-thumb {
  width: 200px;
  height: 160px;
  object-fit: cover;
  border-radius: 12px;
  cursor: zoom-in;
  transition: 0.25s ease;
}

.image-thumb:hover {
  transform: scale(1.03);
}

.image-thumb.zoomed {
  width: 100%;
  height: auto;
  cursor: zoom-out;
}

/* ===================================================== */
/* ===================== DELETE BTN ===================== */
/* ===================================================== */

.delete-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: none;
  background: rgba(255,255,255,0.9);
  cursor: pointer;
  font-weight: bold;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: 0.2s ease;
}

.image-thumb-wrapper:hover .delete-btn {
  opacity: 1;
}

.delete-btn:hover {
  background: #ff4d4f;
  color: white;
}

/* ===================================================== */
/* ===================== CHART UI ======================= */
/* ===================================================== */

.chart-grid {
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.chart-card {
  background: #fff;
  padding: 18px;
  border-radius: 14px;
  box-shadow: 0 4px 14px rgba(0,0,0,0.05);
}

.chart-title {
  font-weight: 600;
  margin-bottom: 12px;
}

.chart-image {
  width: 100%;
  border-radius: 10px;
  cursor: zoom-in;
}

/* ===================================================== */
/* ===================== STATUS BOX ===================== */
/* ===================================================== */

.loading-box,
.error-box,
.warning-box {
  padding: 15px;
  border-radius: 8px;
  margin-top: 15px;
}

.loading-box { background: #eef4ff; }
.error-box { background: #ffe6e6; }
.warning-box { background: #fff5cc; }

/* ===================================================== */
/* ============== CORRELATION GUIDE ==================== */
/* ===================================================== */

#btn-show-correlation-guide {
  margin-top: 0;
}

#correlation-guide-container {
  margin-top: 14px;
}

.correlation-guide {
  background: transparent;
  border: none;
  border-radius: 0;
  padding: 0;
}

.correlation-guide h4 {
  margin: 0 0 12px;
  font-size: 18px;
}

.correlation-guide .method-box + .method-box {
  border-top: 1px solid #dbe4ee;
  margin-top: 14px;
  padding-top: 14px;
}

.correlation-guide .method-title {
  margin: 0 0 8px;
  font-size: 17px;
  font-weight: 700;
}

.correlation-guide p {
  margin: 8px 0;
}

.correlation-guide ul {
  margin: 0 0 8px 22px;
  padding: 0;
}

.correlation-guide li {
  margin-bottom: 6px;
}

.correlation-item {
  background: #ffffff;
  border: 1px solid #e3e8ef;
  border-radius: 10px;
  padding: 12px;
  margin-top: 12px;
}

.correlation-title {
  margin: 0 0 8px;
  font-weight: 700;
  font-size: 16px;
}

.correlation-reasons {
  margin: 8px 0 10px 20px;
}

/* ===================================================== */
/* ===================== MOBILE ========================= */
/* ===================================================== */

@media (max-width: 768px) {

  .container {
    grid-template-columns: 1fr;
    padding: 15px;
  }

  .left-panel {
    position: relative;
  }

  .right-panel {
    padding: 15px;
  }

  .lang-switch {
    position: static;
    transform: none;
    justify-content: center;
    margin-top: 8px;
  }

  button {
    width: 100%;
    font-size: 16px;
    padding: 14px;
  }

  .image-thumb {
    width: 100%;
    height: auto;
  }

  .chart-card {
    padding: 12px;
  }

  .chart-title {
    font-size: 14px;
  }

  .desc-table {
    font-size: 13px;
  }

  .manual-sheet-row {
    grid-template-columns: 44px 1fr 1fr 20px 32px 32px;
    gap: 6px;
  }

  .manual-sheet-row.edit-manual-row {
    grid-template-columns: 44px minmax(0, 1fr) minmax(0, 1fr) 20px 32px 32px;
    gap: 6px;
  }

  .manual-add-btn,
  .manual-remove-btn {
    width: 32px;
    height: 32px;
    min-width: 32px;
    font-size: 18px;
  }

}

/* ===================================================== */
/* ============ GROUP UPLOAD CARD STYLE =================*/
/* ===================================================== */

.upload-box {
  position: relative;
  border: 1px solid #ccc;
  border-radius: 6px;
  padding: 18px;
  transition: 0.25s ease;
  cursor: pointer;
  background: #ffffff;
  margin-bottom: 10px;
}

.upload-box:hover {
  border-color: #2c7be5;
  box-shadow: none;
}

.upload-title {
  font-weight: 600;
  font-size: 15px;
  margin-bottom: 14px;
}

/* Overlay upload button (ẩn mặc định) */
.upload-overlay-btn {
  position: absolute;
  bottom: 16px;
  right: 16px;
  padding: 8px 14px;
  font-size: 13px;
  background: #2c7be5;
  color: white;
  border-radius: 8px;
  opacity: 0;
  pointer-events: none;
  transition: 0.2s ease;
}

/* Khi active thì hiện */
.upload-box.active .upload-overlay-btn {
  opacity: 1;
  pointer-events: auto;
}

/* ================= STATUS ICON ================= */

.input-wrap {
  position: relative;
}

.input-with-status {
  position: relative;
  display: flex;
  align-items: center;
}

.input-with-status input,
.input-with-status textarea {
  width: 100%;
  padding-right: 35px;
}

.status-icon {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 16px;
  opacity: 1;
  transition: 0.2s ease;
  line-height: 1;
}

.status-icon::after {
  content: "";
  display: inline-block;
  min-width: 18px;
  text-align: center;
  opacity: 0;
}

.status-icon.typing::after {
  content: "✍";
  color: #3b82f6;
  opacity: 1;
}

/* đang lưu */
.status-icon.saving::after {
  content: "⏳";
  color: #f59e0b;
  opacity: 1;
}

/* lưu thành công */
.status-icon.success::after {
  content: "✓";
  color: #22c55e;
  font-weight: 700;
  opacity: 1;
}

/* chưa lưu / lưu lỗi */
.status-icon.unsaved::after {
  content: "✖";
  color: #ef4444;
  opacity: 1;
}
