/* Vườn Xa: màu lá, đất, nước. Tự đổi theo chế độ sáng/tối của máy. */
:root {
  --bg: #eef2e8; --surface: #fbfcf8; --ink: #1d2a20; --muted: #5d6b5f; --line: #d3dccd;
  --leaf: #2f7d4a; --leaf-soft: #dcebd9; --soil: #7a5a40; --soil-soft: #efe3d6;
  --water: #2a76b3; --water-soft: #dbe9f5; --warn: #b86a12; --crit: #b3392f;
  --font-display: "Baloo 2", "Be Vietnam Pro", system-ui, sans-serif;
  --font-body: "Be Vietnam Pro", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-data: "JetBrains Mono", ui-monospace, Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121a14; --surface: #1a241d; --ink: #e6eee4; --muted: #9cab9d; --line: #2e3b31;
    --leaf: #6cc58a; --leaf-soft: #213a29; --soil: #c79a74; --soil-soft: #33281f;
    --water: #6fb2e6; --water-soft: #1c3142; --warn: #e3a050; --crit: #ec7a6f;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
    --bg: #121a14; --surface: #1a241d; --ink: #e6eee4; --muted: #9cab9d; --line: #2e3b31;
    --leaf: #6cc58a; --leaf-soft: #213a29; --soil: #c79a74; --soil-soft: #33281f;
    --water: #6fb2e6; --water-soft: #1c3142; --warn: #e3a050; --crit: #ec7a6f;
    color-scheme: dark;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font-body); font-size: 15px; line-height: 1.5;
  padding: 20px max(16px, env(safe-area-inset-left, 0px)) 48px max(16px, env(safe-area-inset-right, 0px)); }
.wrap { max-width: 1120px; margin: 0 auto; display: grid; gap: 20px; }
header { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 16px; }
.brand h1 { font-family: var(--font-display); font-weight: 800; font-size: 2.1rem; line-height: 1; margin: 0; color: var(--leaf); }
.brand p { margin: 4px 0 0; color: var(--muted); font-size: .9rem; }
h2.section { font-family: var(--font-display); font-weight: 600; font-size: 1.3rem; margin: 8px 0 0; }
.hud { display: flex; flex-wrap: wrap; gap: 10px; align-items: stretch; }
.chip { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px; display: grid; gap: 2px; }
.chip small { font-size: .7rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.chip b { font-family: var(--font-data); font-weight: 500; font-variant-numeric: tabular-nums; }
.xpbar { width: 120px; height: 6px; border-radius: 3px; background: var(--leaf-soft); overflow: hidden; }
.xpbar i { display: block; height: 100%; background: var(--leaf); }
.main { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 20px; align-items: start; }
@media (max-width: 860px) { .main { grid-template-columns: minmax(0, 1fr); } }
.col { display: grid; gap: 16px; min-width: 0; }
.plots { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
.plot { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; overflow: hidden; display: grid; align-content: start; }
.plot.ready { border-color: var(--leaf); box-shadow: 0 0 0 2px var(--leaf-soft); }
.scene { position: relative; background: linear-gradient(var(--water-soft), var(--surface) 70%, var(--soil-soft) 70%); height: 150px; display: grid; place-items: end center; }
.scene svg { width: 150px; height: 140px; }
.tag { position: absolute; top: 10px; left: 10px; font-family: var(--font-data); font-size: .75rem; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 1px 6px; }
.alert { position: absolute; top: 10px; right: 10px; font-size: .75rem; font-weight: 600; color: var(--surface); background: var(--crit); border-radius: 6px; padding: 1px 8px; }
.alert.ok { background: var(--leaf); } .alert.wait { background: var(--water); }
.body { padding: 12px 14px 14px; display: grid; gap: 10px; }
.title { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.title h3 { font-family: var(--font-display); font-weight: 600; font-size: 1.25rem; margin: 0; line-height: 1.2; }
.title span { font-family: var(--font-data); font-size: .8rem; color: var(--muted); white-space: nowrap; }
.meters { display: grid; gap: 6px; }
.meter { display: grid; grid-template-columns: 74px 1fr 44px; gap: 8px; align-items: center; font-size: .8rem; color: var(--muted); }
.meter .track { height: 8px; border-radius: 4px; background: var(--line); position: relative; overflow: hidden; }
.meter .track i { position: absolute; inset: 0 auto 0 0; border-radius: 4px; }
.meter b { font-family: var(--font-data); font-weight: 500; text-align: right; color: var(--ink); font-variant-numeric: tabular-nums; }
.hint { font-size: .8rem; color: var(--muted); margin: 0; }
.pending { font-size: .8rem; color: var(--water); font-weight: 500; margin: 0; }
.actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
button, .btn { font: inherit; font-size: .85rem; font-weight: 600; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); padding: 8px 10px; cursor: pointer; }
button:hover:not(:disabled) { background: var(--leaf-soft); }
button:disabled { opacity: .45; cursor: not-allowed; }
button.primary { background: var(--leaf); border-color: var(--leaf); color: var(--surface); }
button.primary:hover:not(:disabled) { background: var(--leaf); filter: brightness(1.08); }
button.full { grid-column: 1 / -1; width: 100%; }
button.link { background: none; border: none; color: var(--muted); text-decoration: underline; padding: 4px; }
button:focus-visible, select:focus-visible, input:focus-visible { outline: 2px solid var(--water); outline-offset: 2px; }
input, select, textarea { font: inherit; padding: 8px 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); width: 100%; }
label { font-size: .82rem; color: var(--muted); display: grid; gap: 4px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 16px; display: grid; gap: 12px; min-width: 0; }
.card h3 { font-family: var(--font-display); font-weight: 600; font-size: 1.15rem; margin: 0; }
.log { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; max-height: 640px; overflow-y: auto; }
.log li { display: grid; grid-template-columns: 1fr auto; gap: 8px; border-top: 1px solid var(--line); padding-top: 8px; font-size: .84rem; }
.meta { display: block; font-family: var(--font-data); font-size: .7rem; color: var(--muted); }
.k { font-weight: 600; }
.k.sensor { color: var(--water); } .k.farmer { color: var(--soil); } .k.order { color: var(--leaf); } .k.game { color: var(--muted); }
.photo { width: 84px; height: 63px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); background: var(--soil-soft); }
.auth { max-width: 420px; margin: 40px auto; }
.tabs { display: flex; gap: 6px; }
.tabs button[aria-selected="true"] { background: var(--leaf-soft); border-color: var(--leaf); }
.err { color: var(--crit); font-size: .85rem; min-height: 1.2em; margin: 0; }
.free { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.free .card { gap: 8px; padding: 12px; }
table { width: 100%; border-collapse: collapse; font-size: .85rem; }
th, td { text-align: left; padding: 8px 6px; border-top: 1px solid var(--line); vertical-align: middle; }
th { font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); border-top: none; }
td.num { font-family: var(--font-data); font-variant-numeric: tabular-nums; }
.scroll { overflow-x: auto; }
.tasks { display: grid; gap: 12px; }
.task { border: 1px solid var(--line); border-radius: 12px; padding: 12px; display: grid; gap: 8px; background: var(--bg); }
.task header { gap: 8px; }
.task .type { font-family: var(--font-display); font-weight: 600; font-size: 1.1rem; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: end; }
.row > * { flex: 1 1 140px; }
.toast { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: .88rem; max-width: calc(100% - 32px); z-index: 10; }
.empty-note { color: var(--muted); font-size: .9rem; margin: 0; }
details summary { cursor: pointer; font-weight: 600; font-size: .9rem; }
a.btn { text-decoration: none; display: inline-flex; align-items: center; justify-content: center; }
.btn.primary { background: var(--leaf); border-color: var(--leaf); color: var(--surface); }
[hidden] { display: none !important; }
/* Ô chat hỗ trợ */
.vx-chat { position: fixed; right: max(16px, env(safe-area-inset-right, 0px)); bottom: calc(16px + env(safe-area-inset-bottom, 0px)); z-index: 20; display: grid; justify-items: end; gap: 10px; }
.vx-chat-btn { border-radius: 999px; padding: 10px 16px; background: var(--leaf); border-color: var(--leaf); color: var(--surface); box-shadow: 0 4px 14px rgba(0,0,0,.18); }
.vx-chat-btn:hover:not(:disabled) { background: var(--leaf); filter: brightness(1.08); }
.vx-chat.open .vx-chat-btn { display: none; }
.vx-chat-box { width: min(380px, calc(100vw - 32px)); height: min(560px, calc(100vh - 100px)); background: var(--surface); border: 1px solid var(--line); border-radius: 16px; box-shadow: 0 10px 30px rgba(0,0,0,.2); display: grid; grid-template-rows: auto 1fr auto auto; overflow: hidden; }
.vx-chat-box[hidden] { display: none; }
.vx-chat-box header { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--line); background: var(--leaf-soft); }
.vx-chat-box header b { font-family: var(--font-display); font-size: 1.05rem; display: block; line-height: 1.2; }
.vx-chat-box header small { color: var(--muted); font-size: .75rem; }
.vx-chat-x { font-size: 1.2rem; line-height: 1; padding: 4px 10px; }
.vx-chat-log { overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.vx-msg { margin: 0; padding: 8px 12px; border-radius: 14px; max-width: 88%; font-size: .9rem; line-height: 1.45; overflow-wrap: anywhere; }
.vx-msg.bot { background: var(--bg); border: 1px solid var(--line); align-self: flex-start; border-bottom-left-radius: 4px; }
.vx-msg.me { background: var(--leaf); color: var(--surface); align-self: flex-end; border-bottom-right-radius: 4px; }
.vx-msg a { color: var(--leaf); font-weight: 600; }
.vx-msg .li { display: block; padding-left: 14px; position: relative; }
.vx-msg .li::before { content: "•"; position: absolute; left: 2px; }
.vx-typing i { display: inline-block; width: 6px; height: 6px; margin: 0 2px; border-radius: 50%; background: var(--muted); animation: vxdot 1s infinite; }
.vx-typing i:nth-child(2) { animation-delay: .15s; } .vx-typing i:nth-child(3) { animation-delay: .3s; }
@keyframes vxdot { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }
.vx-chat-sug { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 12px 8px; }
.vx-chat-sug:empty { display: none; }
.vx-chat-sug button { font-size: .78rem; font-weight: 500; padding: 5px 10px; border-radius: 999px; }
.vx-chat-form { display: flex; gap: 6px; padding: 10px 12px; border-top: 1px solid var(--line); }
.vx-chat-form input { flex: 1; }
/* Trang 3D: chừa chỗ cho bảng luống bên phải */
body.g3d .vx-chat { right: calc(384px + max(12px, env(safe-area-inset-right, 0px))); bottom: calc(12px + env(safe-area-inset-bottom, 0px)); }
@media (max-width: 900px) { body:has(.mobilebar) .vx-chat { bottom: calc(80px + env(safe-area-inset-bottom, 0px)); } }
@media (max-width: 760px) {
  body.g3d .vx-chat { right: max(12px, env(safe-area-inset-right, 0px)); bottom: auto; top: calc(130px + env(safe-area-inset-top, 0px)); }
  body.g3d .vx-chat-box { height: min(520px, calc(100vh - 160px)); }
  body.g3d .vx-chat-btn { padding: 8px 12px; font-size: .8rem; }
}
