:root {
  --green: #1a7f3c;
  --green-dark: #136030;
  --green-soft: #e8f5ec;
  --ink: #1c2420;
  --muted: #5f6b64;
  --line: #d9e0db;
  --bg: #f5f7f5;
  --card: #ffffff;
  --red: #c0392b;
  --red-soft: #fdecea;
  --amber-soft: #fff6dd;
  --amber: #8a6100;
  --radius: 10px;
}

* { box-sizing: border-box; }

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

h1, h2, h3, h4, p { margin: 0; }
h1 { font-size: 20px; }
h2 { font-size: 18px; }
h3 { font-size: 16px; }
h4 { font-size: 14px; }

.brand { color: var(--green); font-weight: 700; font-size: 13px; letter-spacing: .03em; text-transform: uppercase; }
.hint { color: var(--muted); font-size: 13px; }
.error { color: var(--red); font-size: 14px; }
.num { text-align: right; }

/* ---------- nút ---------- */
.btn {
  font: inherit; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--card); color: var(--ink); cursor: pointer; white-space: nowrap;
}
.btn:hover:not(:disabled) { border-color: var(--green); }
.btn:disabled { color: #9aa39d; background: #eef1ee; cursor: not-allowed; }
.btn.primary { background: var(--green); border-color: var(--green); color: #fff; font-weight: 600; }
.btn.primary:hover { background: var(--green-dark); }
.btn.danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.upload { display: inline-block; justify-self: start; color: var(--ink); font-weight: 400; }
:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; }

/* ---------- đăng nhập ---------- */
.login-page { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login-card {
  width: min(380px, 100%); background: var(--card); padding: 28px; border-radius: var(--radius);
  border: 1px solid var(--line);
}
.login-card form { display: grid; gap: 8px; margin-top: 18px; }
.login-card .btn { margin-top: 10px; }

/* ---------- trang chính ---------- */
.topbar {
  display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 14px 24px; background: var(--card); border-bottom: 1px solid var(--line);
}
.topbar nav { display: flex; gap: 8px; }
.page { max-width: 1100px; margin: 0 auto; padding: 20px 24px 60px; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.stat {
  font: inherit; text-align: left; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px 16px; cursor: pointer; color: var(--ink);
}
.stat:hover { border-color: var(--green); }
.stat[aria-pressed="true"] { border-color: var(--green); background: var(--green-soft); }
.stat .n { display: block; font-size: 28px; font-weight: 700; line-height: 1.1; }
.stat .l { color: var(--muted); font-size: 13px; }

.list-head { display: flex; justify-content: space-between; align-items: center; margin: 22px 0 10px; gap: 12px; }

.table-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
table { border-collapse: collapse; width: 100%; }
th, td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; white-space: nowrap; }
th.num, td.num { text-align: right; }
tbody tr:last-child td { border-bottom: 0; }
.list tbody tr:hover { background: var(--green-soft); }
.col-thumb { width: 56px; }
.row-thumb { width: 44px; height: 44px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); display: block; background: #eef1ee; }
.empty { padding: 28px; text-align: center; color: var(--muted); }

.link, .count-link {
  font: inherit; background: none; border: 0; padding: 0; color: var(--green-dark);
  cursor: pointer; text-decoration: underline; text-underline-offset: 2px; text-align: left;
}
.link.name { font-weight: 600; text-decoration: none; }
.link.name:hover { text-decoration: underline; }
.count-plain, .counter { color: var(--muted); font-weight: 400; font-size: 13px; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; background: #eef1ee; color: var(--muted); white-space: nowrap; }
.badge.checked { background: var(--amber-soft); color: var(--amber); }
.badge.posted { background: var(--green-soft); color: var(--green-dark); }
.badge.insecticide { background: var(--red-soft); color: var(--red); }
.badge.fungicide { background: var(--amber-soft); color: var(--amber); }

/* ---------- hộp thoại ---------- */
dialog { border: 0; padding: 0; border-radius: 12px; color: var(--ink); background: var(--card); }
dialog:modal { overscroll-behavior: contain; }
dialog::backdrop { background: rgba(20, 30, 24, .45); overflow: hidden; overscroll-behavior: contain; }

dialog.sheet[open] { display: flex; flex-direction: column; width: min(1000px, 96vw); height: 94vh; max-height: 94vh; }
dialog.sheet.narrow[open] { width: min(620px, 96vw); height: auto; max-height: 90vh; }
dialog.viewer[open] { display: flex; flex-direction: column; width: min(1100px, 96vw); height: 94vh; max-height: 94vh; }

.sheet-head {
  display: flex; align-items: center; gap: 10px; padding: 12px 20px; border-bottom: 1px solid var(--line);
}
.sheet-head h2 { margin-right: auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.save-state { color: var(--muted); font-size: 13px; }
.sheet-body { flex: 1; overflow-y: auto; padding: 4px 20px 20px; overscroll-behavior: contain; }
.sheet-body section { padding: 16px 0; border-bottom: 1px solid var(--line); display: grid; gap: 10px; }
.sheet-body section:last-child { border-bottom: 0; }
.sheet-foot {
  display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 12px 20px; border-top: 1px solid var(--line); background: #fafbfa; border-radius: 0 0 12px 12px;
}
.sheet-foot .actions, .danger-zone { display: flex; gap: 8px; align-items: center; }
/* Giữ chỗ cho nút xác nhận để các nút khác không nhảy vị trí */
#btn-delete-confirm, #delete-msg { visibility: hidden; }
.danger-zone.confirming #btn-delete-confirm, .danger-zone.confirming #delete-msg { visibility: visible; }

.sec-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.notice { margin-top: 14px; padding: 10px 14px; border-radius: 8px; font-size: 14px; }
.notice.block { background: var(--red-soft); color: var(--red); }
.notice.warn { background: var(--amber-soft); color: var(--amber); }

label { display: grid; gap: 4px; align-content: start; font-size: 13px; color: var(--muted); font-weight: 600; }
input, select, textarea {
  font: inherit; color: var(--ink); padding: 8px 10px; border: 1px solid var(--line);
  border-radius: 8px; background: #fff; width: 100%; font-weight: 400;
}
textarea { resize: vertical; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 12px; }
.grid .wide { grid-column: 1 / -1; }

.thumbs { display: flex; flex-wrap: wrap; gap: 10px; }
.thumb { position: relative; width: 112px; height: 112px; border-radius: 8px; border: 1px solid var(--line); overflow: hidden; background: #eef1ee; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .open { position: absolute; inset: 0; border: 0; padding: 0; background: none; cursor: zoom-in; }
.thumb .remove {
  position: absolute; top: 4px; right: 4px; width: 24px; height: 24px; border-radius: 50%; border: 0;
  background: rgba(0, 0, 0, .6); color: #fff; cursor: pointer; line-height: 1; font-size: 15px;
}
.thumb.empty { display: grid; place-items: center; text-align: center; font-size: 12px; color: var(--muted); border-style: dashed; padding: 6px; }

table.vars { min-width: 940px; }
table.vars th, table.vars td { padding: 6px; border-bottom: 0; }
table.vars input { padding: 6px 8px; }
table.vars td:first-child input { min-width: 170px; }
table.vars td:nth-child(9) input { min-width: 240px; }
table.vars .w-s { width: 78px; }
table.vars .w-m { width: 110px; }
.icon-btn { border: 0; background: none; cursor: pointer; color: var(--red); font-size: 18px; padding: 4px 8px; }

.attrs { display: grid; gap: 8px; }
.attr-row { display: grid; grid-template-columns: 1fr 1.4fr auto; gap: 8px; }

.docs { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.docs li { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; }

.viewer-body { flex: 1; overflow: auto; display: grid; place-items: center; background: #1c2420; overscroll-behavior: contain; }
.viewer-body img { max-width: 100%; max-height: 100%; object-fit: contain; }
.viewer-body iframe { width: 100%; height: 100%; border: 0; background: #fff; }
.viewer-body.strip .thumb { width: 240px; height: 240px; }
.viewer-body.strip { display: flex; flex-wrap: wrap; gap: 12px; padding: 16px; align-content: flex-start; background: var(--bg); }
