/* Công cụ nội bộ, không phải landing page: bảng dày, một màu nhấn, không
   gradient, không bóng nhiều lớp. */
:root {
  --bg: #FBFBFA;
  --fg: #1A1A1A;
  --muted: #6B6B66;
  --line: #E4E4E1;
  --accent: #2C5AA0;
  --accent-soft: #EDF2FA;
  --warn: #A33;
  --ok: #2E6B3E;
  --radius: 4px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
        "Helvetica Neue", Arial, sans-serif;
}

a { color: var(--accent); }

main { padding: 20px 24px 48px; }
main.narrow { max-width: 680px; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.strong { font-weight: 600; }
.nowrap { white-space: nowrap; }
.mono { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 12px; }
.grow { flex: 1; }

/* ── Thanh trên ───────────────────────────────────────────── */
.topbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  padding: 10px 24px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.topbar nav { display: flex; align-items: baseline; gap: 18px; }
.topbar nav a { color: var(--fg); text-decoration: none; }
.topbar nav a.on { color: var(--accent); font-weight: 600; }
.topbar nav a:hover { text-decoration: underline; }
.brand { font-weight: 700; margin-right: 6px; }

.topbar-right { display: flex; align-items: center; gap: 16px; }
.runbox { display: flex; align-items: center; gap: 10px; }
.runbox .small { max-width: 46ch; }

/* ── Nút ──────────────────────────────────────────────────── */
button, .btn {
  font: inherit;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--fg);
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
}

button:hover:not(:disabled), .btn:hover { border-color: #C9C9C4; }

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

button.primary:hover:not(:disabled) { background: #24487F; }
button:disabled { opacity: .45; cursor: default; }

button.link {
  border: 0;
  background: none;
  color: var(--accent);
  padding: 6px 0;
}
a.link { color: var(--accent); }

/* ── Thông báo ────────────────────────────────────────────── */
.notice, .error {
  padding: 8px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  margin: 0 0 16px;
}
.notice { background: var(--accent-soft); border-color: #CBD9EE; }
.error { background: #FBEDED; border-color: #E7C9C9; color: var(--warn); }

/* ── Bộ lọc ───────────────────────────────────────────────── */
.filters {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  padding: 16px;
  margin-bottom: 16px;
}

.block-title {
  margin: 0 0 12px;
  font-size: 16px;
  font-weight: 600;
}

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }

.chip {
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--fg);
  text-decoration: none;
  font-size: 14px;
}
.chip.on { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.chip .n { color: var(--muted); margin-left: 4px; font-size: 12px; }
.chip.on .n { color: var(--accent); }
.chip.zero { opacity: .5; }
.chip.zero:hover { opacity: 1; }

/* Moi o co nhan rieng, khong chi dua vao placeholder */
.filter-form { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }

.fbox { display: flex; flex-direction: column; gap: 4px; }
.fbox.grow { flex: 1 1 240px; }
.fbox > label, .lbl-spacer {
  font-size: 12px;
  color: var(--muted);
  min-height: 16px;
  line-height: 16px;
}
.fbox input, .fbox select { height: 34px; }
.fbox button { height: 34px; }

.quick { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 16px; }

.pill {
  padding: 3px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--fg);
  text-decoration: none;
  font-size: 13px;
}
.pill:hover { border-color: #C9C9C4; }
.pill.on { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }

.applied {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 8px;
  border: 1px solid #CBD9EE;
  border-radius: var(--radius);
  background: var(--accent-soft);
  color: var(--accent);
  text-decoration: none;
  font-size: 13px;
}
.tag:hover { background: #DFE9F7; }
.tag .x { font-size: 15px; line-height: 1; }

input, select, textarea {
  font: inherit;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--fg);
}
input:focus, select:focus, textarea:focus, button:focus-visible, .chip:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* ── Thanh thao tác ───────────────────────────────────────── */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}

/* ── Bảng ─────────────────────────────────────────────────── */
table.leads { width: 100%; border-collapse: collapse; }

table.leads th, table.leads td {
  text-align: left;
  padding: 7px 10px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

table.leads th {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .03em;
  white-space: nowrap;
}

table.leads tbody tr:hover { background: #F4F4F2; cursor: pointer; }
table.leads td.num { text-align: right; white-space: nowrap; }
table.leads th.num { text-align: right; }
table.leads .tick { width: 1%; }

td.cut {
  max-width: 22ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Mot mau = mot nghia: gold dang cho nguoi xu ly, green xong, red hong hoac
   bi loai, xam trung lap. */
.st {
  font-size: 12px;
  white-space: nowrap;
  padding: 2px 8px;
  border-radius: 3px;
  border: 1px solid transparent;
}
.st-gold  { color: #7A5A00; background: #FDF4DF; border-color: #EBDBAE; }
.st-green { color: var(--ok); background: #EDF6EF; border-color: #C8E0CE; }
.st-red   { color: var(--warn); background: #FBEDED; border-color: #E7C9C9; }
.st-grey  { color: var(--muted); background: #F2F2F0; border-color: var(--line); }

.empty { padding: 40px 0; color: var(--muted); }

/* Tieu de cot bam duoc */
table.leads th.sortable { padding: 0; }
table.leads th.sortable a {
  display: block;
  padding: 7px 10px;
  color: inherit;
  text-decoration: none;
}
table.leads th.sortable a:hover { background: #F4F4F2; color: var(--fg); }
table.leads th.sortable.sorted a { color: var(--accent); }
table.leads th.num.sortable a { text-align: right; }
.arrow { margin-left: 5px; font-size: 9px; }

/* ── Phân trang ───────────────────────────────────────────── */
.pager {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: center;
  margin-top: 16px;
  padding: 12px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}

.size-form { display: flex; align-items: center; gap: 8px; }
.size-form label { font-size: 12px; color: var(--muted); }
.size-form select { padding: 3px 6px; }

.small-btn { padding: 3px 10px; font-size: 13px; }

.pages { display: flex; align-items: center; gap: 4px; }
.pages a, .pages > span {
  padding: 3px 9px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  text-decoration: none;
  font-size: 13px;
  background: #fff;
}
.pages a { color: var(--accent); }
.pages a:hover { border-color: #C9C9C4; }
.pages > span { color: #B5B5B0; }
.pages .cur { border-color: transparent; background: none; color: var(--muted); }

/* ── Modal chi tiết ───────────────────────────────────────── */
dialog {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0;
  max-width: 560px;
  width: calc(100% - 32px);
  background: #fff;
  color: var(--fg);
}
dialog::backdrop { background: rgba(0, 0, 0, .3); }
dialog article { padding: 20px 22px; }
dialog h2 { margin: 0 0 2px; font-size: 19px; }
dialog dl { display: grid; grid-template-columns: 110px 1fr; gap: 4px 12px; margin: 16px 0; }
dialog dt { color: var(--muted); font-size: 13px; }
dialog dd { margin: 0; overflow-wrap: anywhere; }
dialog footer { display: flex; justify-content: space-between; align-items: center; gap: 12px; }

.snippet {
  background: #F4F4F2;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
  font-size: 13px;
  overflow-wrap: anywhere;
}

/* ── Đăng nhập ────────────────────────────────────────────── */
.login { display: flex; justify-content: center; padding: 12vh 16px; }
.login .card {
  width: 320px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 24px;
}
.login h1 { margin: 0 0 4px; font-size: 20px; }
.login p { margin: 0 0 18px; font-size: 14px; }
.login label { display: block; font-size: 13px; margin-bottom: 4px; }
.login input { width: 100%; margin-bottom: 14px; }
.login button { width: 100%; }
.login .error { margin: 0 0 14px; font-size: 13px; }

/* ── Cài đặt ──────────────────────────────────────────────── */
.page-title { margin: 0 0 4px; font-size: 24px; font-weight: 600; }


.field { margin-bottom: 24px; }
.lead { margin: 0 0 24px; color: var(--muted); }

/* Tieu de o nhap kiem nut ?. Bam ca dong de mo giai thich, nen dong nay la
   summary chu khong phai label; o nhap giu ten goi qua aria-labelledby. */
.field-head > summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  user-select: none;
}
.field-head > summary::-webkit-details-marker { display: none; }

.qmark {
  width: 18px;
  height: 18px;
  line-height: 16px;
  text-align: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  flex: none;
}
.field-head > summary:hover .qmark { border-color: var(--accent); color: var(--accent); }
.field-head[open] > summary .qmark {
  border-color: var(--accent);
  color: #fff;
  background: var(--accent);
}

/* Nam trong luong, day noi dung xuong. Noi den tren dien thoai no che mat
   dung cai o nguoi dung sap go. */
.help-body {
  margin: 8px 0 0;
  padding: 12px 14px;
  border: 1px solid #CBD9EE;
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  background: var(--accent-soft);
  font-size: 13px;
  line-height: 1.55;
}

.check-line {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  font-weight: 400;
  cursor: pointer;
}

.estimate-box {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  padding: 12px 14px;
  margin-bottom: 24px;
}

.preview { margin-top: 12px; }
.preview ol { margin: 6px 0 0; padding-left: 22px; }
.preview li { margin-bottom: 3px; overflow-wrap: anywhere; }


.field .hint { margin: 4px 0 6px; font-size: 12px; color: var(--muted); }
.field textarea, .field input[type="number"], .field select { width: 100%; }
.field input[type="number"], .field select { max-width: 260px; }


.estimate { margin: 0 0 10px; font-size: 14px; }
.estimate.hot { color: var(--warn); font-weight: 600; }

details.advanced {
  border-top: 1px solid var(--line);
  padding-top: 16px;
  margin-bottom: 24px;
}
details.advanced > summary { cursor: pointer; font-weight: 600; margin-bottom: 8px; }
details.advanced > .muted { margin: 0 0 16px; }

/* ── Dưới 768px: bảng thành danh sách thẻ, không cuộn ngang ── */
@media (max-width: 768px) {
  main { padding: 16px; }
  .topbar { padding: 10px 16px; }
  .runbox .small { max-width: none; }
  /* flex-basis chứ không phải width: `flex: 1` đặt basis về 0 và nuốt mất
     width:100%, ô tìm kiếm bị bóp xuống còn nửa hàng. */
  .filter-inputs input[type="search"] { min-width: 0; flex-basis: 100%; }

  table.leads thead { display: none; }
  table.leads, table.leads tbody, table.leads tr, table.leads td { display: block; width: 100%; }

  table.leads tr {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #fff;
    margin-bottom: 10px;
    padding: 6px 4px;
    position: relative;
  }

  table.leads td {
    border: 0;
    padding: 3px 12px 3px 96px;
    text-align: left;
  }

  table.leads td::before {
    content: attr(data-th);
    position: absolute;
    left: 12px;
    width: 80px;
    color: var(--muted);
    font-size: 12px;
  }

  table.leads td.num { text-align: left; }
  /* Vẫn cắt ellipsis như trên desktop. Cho xuống dòng thoải mái thì một
     headline dài biến cả thẻ lead thành bức tường chữ - bấm vào thẻ là có
     modal đọc đầy đủ rồi. */
  table.leads td.cut { max-width: none; }
  table.leads td.tick { padding-left: 12px; }
  table.leads td.tick::before { content: none; }
}
