:root {
  --bg: #0d1117;
  --panel: #111;
  --text: #c9d1d9;
  --accent: #58a6ff;
  --border: #30363d;
}

/* ================= RESET ================= */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: "Segoe UI", system-ui, sans-serif;
}

/* ================= BODY ================= */
html, body {
  height: 100%;
}

body {
  min-height: 100vh;
  background: linear-gradient(135deg, #0d1117, #010409);
  color: var(--text);
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
}

/* ================= TOP BAR ================= */
.topbar {
  height: 64px;
  padding: 0 32px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid var(--border);
  background: #0f0f0f;
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar h1 {
  font-size: 20px;
  color: #fff;
}

/* ================= LAYOUT ================= */
.layout {
  min-height: calc(100vh - 64px);
  display: grid;
  grid-template-columns: 380px 1fr;
  gap: 24px;
  padding: 24px;
}

/* ================= PANEL ================= */
.panel {
  background: var(--panel);
  border-radius: 14px;
  padding: 24px;
  box-shadow: 0 10px 40px rgba(0,0,0,.6);
}

/* ================= LEFT PANEL ================= */
.panel.left input {
  width: 100%;
  padding: 14px;
  border-radius: 10px;
  border: none;
  background: #1c1c1c;
  color: #fff;
  font-size: 14px;
  margin-bottom: 20px;
}

.panel.left input::placeholder {
  color: #666;
}

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

/* ================= BUTTON ================= */
button {
  padding: 13px;
  border-radius: 10px;
  border: none;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.primary { background: #fff; color: #000; }
.normal { background: #1AC051; color: #000; }
.danger { background: #ff4d4f; color: #fff; }
.secondary { background: #FCFDDE; color: #000; }
.group { background: #e6e8ae; color: #000; }

/* ================= RIGHT PANEL ================= */
.panel.right {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

/* ================= PREVIEW (SCROLL CONTAINER) ================= */
.preview {
  flex: 1;
  min-height: 0;
  width: 100%;
  overflow-x: auto;
  overflow-y: auto;
  padding: 10px 10px 16px;
  -webkit-overflow-scrolling: touch;
}

/* ================= TABLE ================= */
.data-table {
  width: max-content;     /* 🔑 bảng tự mở rộng */
  min-width: 100%;        /* 🔑 không nhỏ hơn container */
  border-collapse: collapse;
  table-layout: auto;     /* 🔑 KHÔNG ép cột */
}

.data-table th,
.data-table td {
  padding: 8px 10px;
  border: 1px solid var(--border);
  white-space: nowrap;
}

.data-table th {
  background: #111;
  color: var(--accent);
  position: sticky;
  top: 0;
  z-index: 2;
}

.data-table tr:hover td {
  background: rgba(255,255,255,0.04);
}

/* ================= ALIGN ================= */
.data-table td {
  text-align: center;
}

.data-table .row-header {
  text-align: left;
  font-weight: 600;
}

.data-table .avg-cell {
  font-weight: 700;
}

.stt-cell {
  width: 50px;
  text-align: center;
  font-weight: 700;
}

/* ================= RESPONSIVE ================= */
@media (max-width: 900px) {

  .layout {
    grid-template-columns: 1fr;
    gap: 16px;
    padding: 16px;
  }

  .topbar {
    padding: 0 16px;
    height: 56px;
  }

  .topbar h1 {
    font-size: 16px;
  }

  /* CHỈ MOBILE MỚI GIỚI HẠN CỘT */
  .data-table th,
  .data-table td {
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .stt-cell {
    width: 42px;
  }
}

/* ================= MOBILE XOAY NGANG ================= */
@media (orientation: landscape) and (max-height: 500px) {
  .layout {
    min-height: auto;
  }

  .preview {
    max-height: none;
  }
}

.btn-link {
  display: inline-block;
  padding: 13px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  background: #FCFDDE;
  color: #000;
  text-decoration: none;
  text-align: center;
}
