/* ============================================================
   เกษตรภูมิใจ v51 — stylesheet (mobile-first)
   ============================================================ */
:root {
  --green: #16a34a;
  --green-dark: #15803d;
  --green-deep: #166534;
  --green-light: #dcfce7;
  --green-soft: #f0fdf4;
  --amber: #f59e0b;
  --amber-light: #fef3c7;
  --red: #dc2626;
  --red-light: #fee2e2;
  --blue: #2563eb;
  --blue-light: #dbeafe;
  --bg: #f7f9f8;
  --card: #ffffff;
  --card-border: #e6ece8;
  --text: #16211c;
  --muted: #5b6b62;
  --line: #e8eeea;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(16, 60, 32, .05), 0 4px 12px rgba(16, 60, 32, .06);
  --shadow-lg: 0 12px 28px rgba(16, 60, 32, .12);
  --topbar-h: 96px;
  --nav-h: 62px;
  --maxw: 520px;
  --side-w: 248px;
  --content-max: 1240px;
}

/* Multi-column wrapper for repeating cards (desktop) */
.card-grid { display: grid; gap: 12px; grid-template-columns: 1fr; }

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html { font-size: 16px; }

body {
  font-family: "Sarabun", "Noto Sans Thai", system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--text);
  min-height: 100vh;
  line-height: 1.45;
  background: var(--bg);
  background-image: radial-gradient(1200px 500px at 85% -5%, rgba(34, 197, 94, .06), transparent 60%),
                    radial-gradient(900px 420px at -10% 20%, rgba(37, 99, 235, .05), transparent 55%);
  background-attachment: fixed;
}

#app { max-width: var(--maxw); margin: 0 auto; min-height: 100vh; position: relative; }

button { font-family: inherit; border: none; background: none; cursor: pointer; color: inherit; }
input, select, textarea { font-family: inherit; font-size: 1rem; color: var(--text); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--green); outline-offset: 1px; }

/* ============ Top bar ============ */
.topbar {
  position: sticky; top: 0; z-index: 40;
  background: linear-gradient(135deg, var(--green-dark), var(--green-deep) 60%, #14532d);
  color: #fff;
  padding: 12px 16px 10px;
  border-radius: 0 0 18px 18px;
  box-shadow: 0 4px 14px rgba(20, 83, 45, .28);
}
.topbar-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-logo { font-size: 1.7rem; filter: drop-shadow(0 2px 3px rgba(0,0,0,.25)); }
.brand-logo[src] { width: 40px; height: 40px; object-fit: contain; border-radius: 50%; background: #fff; padding: 2px; flex-shrink: 0; }
.brand-text { min-width: 0; }
.brand-name { font-weight: 800; font-size: 1.05rem; letter-spacing: .2px; white-space: nowrap; }
.v-badge {
  display: inline-block; background: rgba(255,255,255,.2); border: 1px solid rgba(255,255,255,.35);
  font-size: .62rem; font-weight: 700; padding: 1px 6px; border-radius: 999px; vertical-align: 2px; margin-left: 3px;
}
.brand-sub { font-size: .68rem; opacity: .85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.btn-tour {
  background: rgba(255,255,255,.16); color: #fff; font-size: .78rem; font-weight: 600;
  padding: 7px 12px; border-radius: 999px; border: 1px solid rgba(255,255,255,.3);
  display: flex; align-items: center; gap: 5px; white-space: nowrap; flex-shrink: 0;
}
.btn-tour:active { transform: scale(.96); }

.role-switch {
  margin-top: 10px; display: flex; background: rgba(255,255,255,.14);
  border: 1px solid rgba(255,255,255,.22); border-radius: 999px; padding: 3px; gap: 3px;
}
.role-switch button {
  flex: 1; font-size: .78rem; font-weight: 600; color: #eafff1;
  padding: 6px 4px; border-radius: 999px; transition: all .18s;
}
.role-switch button.active { background: #fff; color: var(--green-deep); font-weight: 700; box-shadow: 0 1px 4px rgba(0,0,0,.2); }

/* ============ ใบส่งสินค้า (ขายสินค้า) A4 ============ */
.receipt {
  border: 1.5px dashed var(--line); border-radius: 12px; padding: 16px;
  background: #fff; font-size: .82rem; margin: 10px 0 4px;
}
.receipt-head { text-align: center; border-bottom: 2px solid var(--text); padding-bottom: 10px; margin-bottom: 10px; }
.receipt-brand { font-size: 1.3rem; font-weight: 800; color: var(--text); }
.receipt-sub { font-size: .72rem; color: var(--muted); }
.receipt-no { font-size: .9rem; font-weight: 700; margin-top: 6px; }
.receipt-meta { display: flex; justify-content: space-between; font-size: .86rem; margin-bottom: 10px; }
.receipt-meta span { color: var(--muted); margin-right: 6px; }
.receipt-cust, .receipt-date { display: flex; align-items: baseline; gap: 6px; }
.receipt-cust b, .receipt-date b { white-space: nowrap; }
.receipt-table { width: 100%; border-collapse: collapse; font-size: .78rem; }
.receipt-table th { border: 1px solid var(--text); background: var(--green-soft); text-align: center; padding: 5px 4px; font-size: .74rem; }
.receipt-table td { border: 1px solid #bbb; padding: 5px 4px; }
.receipt-empty-row td { border-color: #ddd; height: 20px; }
.receipt-total { margin-top: 8px; font-size: .86rem; max-width: 320px; margin-left: auto; }
.receipt-total .row { display: flex; justify-content: space-between; padding: 3px 6px; }
.receipt-total .receipt-grand { border-top: 2px solid var(--text); font-weight: 800; font-size: .98rem; margin-top: 4px; }
.receipt-baht { font-size: .76rem; color: var(--muted); padding: 2px 6px 0; }
.receipt-note { margin-top: 8px; font-size: .76rem; }
.receipt-note span { color: var(--muted); }
.receipt-sign { display: flex; justify-content: space-between; margin-top: 30px; text-align: center; gap: 40px; }
.receipt-sign-label { font-size: .84rem; font-weight: 700; }
.receipt-sign-line { margin-top: 28px; font-size: .84rem; }
.receipt-sign-date { font-size: .74rem; color: var(--muted); margin-top: 4px; }
.receipt-foot { margin-top: 12px; font-size: .72rem; color: var(--muted); text-align: center; }

/* ============ การแจ้งเตือน (กระดิ่ง) ============ */
.notif-btn { position: relative; }
.notif-badge {
  position: absolute; top: -5px; right: -5px; min-width: 17px; height: 17px;
  border-radius: 999px; background: var(--red); color: #fff;
  font-size: .58rem; font-weight: 800; line-height: 1;
  display: flex; align-items: center; justify-content: center; padding: 0 4px;
  border: 2px solid var(--green-deep); box-sizing: border-box;
}
.notif-panel {
  position: fixed; top: calc(var(--topbar-h) + 6px); right: 12px; z-index: 60;
  width: min(360px, calc(100vw - 24px)); max-height: calc(100vh - var(--topbar-h) - 40px);
  background: var(--card); border: 1px solid var(--card-border); border-radius: 14px;
  box-shadow: 0 12px 32px rgba(0,0,0,.22); overflow-y: auto; animation: fadeIn .18s ease;
}
.notif-head {
  position: sticky; top: 0; background: var(--card); z-index: 1;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 10px 14px; border-bottom: 1px solid var(--line);
  font-weight: 800; font-size: .9rem;
}
.notif-group h3 {
  font-size: .7rem; font-weight: 800; color: var(--muted);
  margin: 10px 14px 2px; letter-spacing: .02em; text-transform: uppercase;
}
.notif-row { display: flex; align-items: center; gap: 10px; padding: 8px 14px; border-bottom: 1px solid var(--line); }
.notif-row:last-child { border-bottom: none; }
.notif-row:hover { background: var(--green-light); }
.notif-x {
  border: 0; background: none; color: var(--muted); font-size: .85rem;
  width: 24px; height: 24px; border-radius: 50%; cursor: pointer; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}
.notif-x:hover { background: var(--red-light); color: var(--red); }
.notif-empty { text-align: center; padding: 22px 14px; color: var(--muted); font-size: .82rem; }
/* กัน display ของตัว badge/panel ไปชนกับ attribute hidden */
.notif-badge[hidden], .notif-panel[hidden] { display: none !important; }

/* ============ View ============ */
.view { padding: 16px 16px calc(var(--nav-h) + 90px); animation: fadeIn .3s cubic-bezier(.22, .7, .3, 1); }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes riseIn { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }

.section-title { font-size: 1.05rem; font-weight: 800; margin: 20px 2px 10px; display: flex; align-items: center; justify-content: space-between; }
.section-title:first-child { margin-top: 4px; }

/* ============ Cards ============ */
.card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  margin-bottom: 12px;
  transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
}
@media (hover: hover) {
  .card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
    border-color: #d4e2da;
  }
}
.card-pad { padding: 16px; }

/* ============ KPI row (always horizontal) ============ */
.kpi-row { display: flex; gap: 10px; }
.kpi {
  flex: 1; min-width: 0; background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 12px 10px; text-align: left; position: relative; overflow: hidden;
  transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
}
@media (hover: hover) { .kpi:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); border-color: #d4e2da; } }
.kpi .kpi-icon { font-size: 1.15rem; }
.kpi .kpi-label { font-size: .7rem; color: var(--muted); font-weight: 600; margin-top: 4px; white-space: nowrap; }
.kpi .kpi-value { font-size: 1.12rem; font-weight: 800; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi .kpi-sub { font-size: .65rem; color: var(--muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi.pos .kpi-value { color: var(--green); }
.kpi.neg .kpi-value { color: var(--red); }
.kpi::after {
  content: ""; position: absolute; right: -18px; top: -18px; width: 54px; height: 54px; border-radius: 50%; opacity: .12;
}
.kpi.green::after { background: var(--green); }
.kpi.amber::after { background: var(--amber); }
.kpi.blue::after { background: var(--blue); }

/* ============ Buttons ============ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font-weight: 700; font-size: .9rem; border-radius: 999px; padding: 11px 18px;
  transition: transform .12s, background .15s; user-select: none;
}
.btn:active { transform: scale(.97); }
@media (hover: hover) { .btn:hover { filter: brightness(1.04); } }
.btn-primary {
  background: var(--green);
  color: #fff; box-shadow: 0 3px 10px rgba(22,163,74,.3);
  transition: transform .15s, box-shadow .2s, background .2s;
}
@media (hover: hover) {
  .btn-primary:hover { background: var(--green-dark); box-shadow: 0 6px 16px rgba(22,163,74,.35); }
}
.btn-primary:active { transform: scale(.96); }
.btn-outline { background: #fff; color: var(--green-dark); border: 1.5px solid var(--green); }
.btn-danger-soft { background: var(--red-light); color: var(--red); }
.btn-ghost { background: var(--green-soft); color: var(--green-dark); }
@media (hover: hover) {
  .btn-outline:hover { background: var(--green-soft); }
  .btn-danger-soft:hover { background: #fbd5d5; }
  .btn-ghost:hover { background: var(--green-light); }
}
.btn-sm { padding: 7px 13px; font-size: .8rem; }
.btn-block { width: 100%; }
.btn-icon { padding: 8px; border-radius: 10px; font-size: .9rem; }

/* ============ SVG icons ============ */
.ic { width: 1.15em; height: 1.15em; flex-shrink: 0; vertical-align: -0.2em; }
.nav-ico .ic { width: 1.35em; height: 1.35em; }
.kpi-icon .ic { width: 1.3em; height: 1.3em; }
.plot-emoji .ic { width: 1.35em; height: 1.35em; }
.task-ico .ic { width: 1.1em; height: 1.1em; }
.mc-ico .ic { width: 1.8em; height: 1.8em; }
.e-ico .ic { width: 2.2em; height: 2.2em; color: var(--green); }
.btn-ico .ic { width: 1em; height: 1em; }
.fab-item .ic { width: 1.15em; height: 1.15em; color: var(--green-dark); }
.role-switch .ic { width: 1em; height: 1em; vertical-align: -0.15em; margin-right: 2px; }
.tabs .ic { width: 1.1em; height: 1.1em; vertical-align: -0.2em; margin-right: 3px; }
.ed-pen .ic { width: 1em; height: 1em; }
.badge .ic { width: .95em; height: .95em; vertical-align: -0.15em; margin-right: 2px; }
.task-tag .ic { width: .9em; height: .9em; vertical-align: -0.15em; margin-right: 2px; }
.plot-profit .plot-emoji .ic { color: var(--green); }
.task-arrow .ic { width: 1em; height: 1em; color: var(--muted); opacity: .55; flex-shrink: 0; }
.task-row { cursor: pointer; }
.task-row:hover { background: #f1f5f3; }
.task-row.done .task-arrow .ic { opacity: .25; }

/* ============ Badges & chips ============ */
.badge {
  display: inline-block; font-size: .66rem; font-weight: 700; padding: 2px 8px;
  border-radius: 999px; vertical-align: 1px;
}
.badge-green { background: var(--green-light); color: var(--green-deep); }
.badge-amber { background: var(--amber-light); color: #92400e; }
.badge-red { background: var(--red-light); color: var(--red); }
.badge-blue { background: var(--blue-light); color: #1e40af; }
.badge-gray { background: #eef0f2; color: var(--muted); }

/* ============ Bottom nav ============ */
.bottomnav {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: var(--maxw);
  background: #ffffff;
  border-top: 1px solid var(--line);
  display: flex; padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  z-index: 30; box-shadow: 0 -4px 14px rgba(16,60,32,.07);
}
.nav-item {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 4px 2px; font-size: .62rem; font-weight: 600; color: var(--muted); border-radius: 10px;
}
.nav-item .nav-ico { font-size: 1.25rem; line-height: 1; }
.nav-item.active { color: var(--green-dark); font-weight: 800; }
.nav-item.active .nav-ico { transform: translateY(-1px); }

/* ============ FAB (ปุ่มกลมมุมขวาล่าง) ============ */
.fab-dock { position: fixed; right: 20px; bottom: calc(76px + env(safe-area-inset-bottom)); z-index: 45; }
.fab {
  width: 56px; height: 56px; border-radius: 50%;
  background: linear-gradient(160deg, var(--green), var(--green-deep));
  color: #fff; box-shadow: 0 8px 22px rgba(22,101,52,.45);
  display: flex; align-items: center; justify-content: center;
  transition: transform .2s;
}
.fab:active { transform: scale(.94); }
.fab-icon { font-size: 1.9rem; font-weight: 300; line-height: 1; transition: transform .25s; }
.fab.open .fab-icon { transform: rotate(45deg); }

.fab-drawer {
  position: absolute; right: 84px; bottom: 64px; transform: translateX(12px);
  display: flex; flex-direction: column; gap: 8px; opacity: 0; pointer-events: none;
  transition: all .22s ease; width: 200px;
}
.fab-dock.open .fab-drawer { opacity: 1; transform: translateX(0); pointer-events: auto; }
.fab-item {
  background: #fff; border-radius: 999px; box-shadow: 0 4px 14px rgba(16,60,32,.2);
  padding: 10px 14px; font-size: .82rem; font-weight: 700; color: var(--text);
  display: flex; align-items: center; gap: 8px; text-align: left;
  border: 1px solid var(--green-light);
}
.fab-item:active { background: var(--green-soft); transform: scale(.97); }
.fab-item span { font-size: 1.05rem; }

/* ============ List rows ============ */
.row { display: flex; align-items: center; gap: 10px; }
.row-between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--muted); font-size: .78rem; }
.small { font-size: .78rem; }
.bold { font-weight: 700; }
.mt-4 { margin-top: 4px; } .mt-8 { margin-top: 8px; } .mt-12 { margin-top: 12px; }

/* ============ Tabs ============ */
/* เลือกปีวิเคราะห์: ◀ พ.ศ. 2569 ▶ + chips ปีทั้งหมด */
.year-nav {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  margin: 2px 0 8px;
}
.year-nav-btn {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--card); border: 1px solid var(--line);
  color: var(--green-deep); font-size: .8rem; font-weight: 800;
  display: inline-flex; align-items: center; justify-content: center;
  transition: background .15s, transform .12s;
}
.year-nav-btn:hover { background: var(--green-soft); }
.year-nav-btn:active { transform: scale(.92); }
.year-nav-label {
  font-size: 1.02rem; font-weight: 800; color: var(--green-deep);
  min-width: 78px; text-align: center;
}
.year-chips {
  display: flex; gap: 6px; flex-wrap: wrap; justify-content: center;
  margin-bottom: 12px;
}
.year-chip {
  padding: 5px 13px; border-radius: 999px; font-size: .8rem; font-weight: 700;
  background: var(--card); border: 1px solid var(--line); color: var(--muted);
  transition: background .15s, color .15s, border-color .15s;
}
.year-chip.active {
  background: var(--green); color: #fff; border-color: var(--green);
}
.tabs {
  display: flex; background: #eef2ef;
  border: 1px solid var(--line);
  border-radius: 12px; padding: 3px; margin-bottom: 14px;
}
.tabs button { flex: 1; padding: 8px 4px; font-size: .82rem; font-weight: 700; color: var(--muted); border-radius: 9px; transition: background .18s, color .18s; }
.tabs button.active { background: #fff; color: var(--green-deep); box-shadow: 0 1px 4px rgba(0,0,0,.1); }

/* ============ Calendar ============ */
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.cal-head .cal-title { font-weight: 800; font-size: 1rem; }
.cal-nav { display: flex; gap: 6px; }
.cal-nav button { width: 34px; height: 34px; border-radius: 10px; background: var(--green-soft); color: var(--green-dark); font-weight: 800; font-size: 1rem; }
.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.cal-dow { text-align: center; font-size: .68rem; font-weight: 700; color: var(--muted); padding: 4px 0; }
.cal-day {
  position: relative; border-radius: 10px; background: #f8faf9;
  border: 1px solid var(--line);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: .85rem; font-weight: 600; height: 58px; overflow: hidden; padding: 3px 2px;
  transition: transform .15s, box-shadow .15s, background .15s, border-color .15s;
}
@media (hover: hover) { .cal-day:hover { background: var(--green-light); } }
.cal-day.other { opacity: .35; }
.cal-day.today { background: var(--green-light); color: var(--green-deep); font-weight: 800; box-shadow: inset 0 0 0 2px var(--green); }
.cal-day.selected { outline: 2px solid var(--green); }
.cal-day .dots { display: flex; gap: 2px; height: 6px; }
.cal-day .dots i { width: 6px; height: 6px; border-radius: 50%; display: block; }
.dot-green { background: var(--green); } .dot-amber { background: var(--amber); } .dot-red { background: var(--red); }
/* ชื่องานในช่องวันปฏิทิน — เห็นงานได้เลยโดยไม่ต้องกดเข้าไป */
.cal-day .cal-tip {
  max-width: 100%; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
  font-size: .5rem; font-weight: 700; line-height: 1.15; padding: 0 2px;
}
.cal-tip.t-done { color: var(--green); text-decoration: line-through; }
.cal-tip.t-planned { color: #b45309; }
.cal-tip.t-overdue { color: var(--red); }
/* จำนวนงานที่เหลือเกินจากที่แสดง */
.cal-day .cal-more {
  font-size: .48rem; font-weight: 800; color: var(--muted);
  background: #eef2f0; border-radius: 5px; padding: 0 4px; line-height: 1.3;
}

.legend { display: flex; gap: 14px; font-size: .72rem; color: var(--muted); margin: 10px 2px; flex-wrap: wrap; }
.legend span { display: flex; align-items: center; gap: 5px; }
.legend i { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }

/* ============ Task rows (สไตล์ Farm Command: จุดสถานะ + แถวเรียบ) ============ */
.task-row { display: flex; align-items: center; gap: 12px; padding: 12px; background: #f8fafc; border-radius: 12px; animation: riseIn .35s ease both; }
.task-row + .task-row { margin-top: 8px; }
/* จุดสถานะกลม: เขียว=เสร็จ เหลือง=แผน แดง=เลยกำหนด — กดติ๊กเสร็จได้ */
.task-dot { width: 12px; height: 12px; border-radius: 50%; border: 0; padding: 0; flex-shrink: 0; cursor: pointer; transition: transform .15s ease; }
.task-dot:hover { transform: scale(1.4); }
.task-row.done .task-title { text-decoration: line-through; color: var(--muted); }
.task-title { font-weight: 700; font-size: .9rem; }
/* วันที่ในแถวงาน — แสดงเป็นไทยพร้อมไอคอนปฏิทิน */
.td-date { display: inline-flex; align-items: center; gap: 4px; color: var(--green-dark); font-weight: 700; }
.td-date .ic { width: .95em; height: .95em; }
/* กลุ่มงานตามวัน (วันนี้ / พรุ่งนี้ / เร็วๆ นี้) */
.task-group h3 { font-size: .78rem; font-weight: 800; color: var(--muted); margin: 14px 0 8px; letter-spacing: .02em; }
.task-group:first-of-type h3 { margin-top: 0; }
.task-tag { font-size: .68rem; font-weight: 700; padding: 1px 7px; border-radius: 999px; margin-left: 6px; vertical-align: 1px; }

/* ============ Chart blocks ============ */
/* กราฟจำกัดความกว้าง + จัดกลาง ให้สมดุลกับการ์ด (ไม่ยืดเต็มจอบนจอใหญ่) */
.chart-wrap { width: 100%; max-width: 440px; margin: 6px auto 0; }
.chart-wrap svg { width: 100%; height: auto; display: block; }
/* แผนวงกลม (donut) เล็กกว่ากราฟแท่ง — วงพอดี ไม่ยักษ์ */
.chart-wrap.chart-donut { max-width: 210px; }
.legend-list { display: flex; flex-direction: column; gap: 6px; margin: 10px auto 0; max-width: 440px; }
.legend-list .li { display: flex; align-items: center; gap: 8px; font-size: .8rem; }
.legend-list .li .sw { width: 11px; height: 11px; border-radius: 3px; flex-shrink: 0; }
.legend-list .li .val { margin-left: auto; font-weight: 700; }

/* ============ สต็อก: ของที่เปิดใช้แล้ว ============ */
.stock-open {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: .7rem; font-weight: 700; color: #b45309;
  background: #fef3c7; border-radius: 999px; padding: 2px 9px; margin-top: 6px;
}
.stock-open .ic { width: .95em; height: .95em; }
.stock-sealed {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: .7rem; font-weight: 700; color: var(--muted);
  background: #eef2f0; border-radius: 999px; padding: 2px 9px; margin-top: 6px;
}
.stock-sealed .ic { width: .95em; height: .95em; }
/* ป้ายหมวดสินค้า */
.stock-cat {
  display: inline-block; font-size: .62rem; font-weight: 800;
  background: var(--green-soft); color: var(--green-dark);
  border-radius: 999px; padding: 2px 8px; vertical-align: 2px; margin-left: 6px;
}
/* แถวล่างของการ์ดสต็อก: มูลค่ารวม + ปุ่มจัดการ (แยกคนละบรรทัด ไม่ให้ยาวเกินไปดันปุ่ม) */
.stock-value { font-size: .72rem; margin-bottom: 8px; }
.stock-value .bold { font-size: .8rem; }
.stock-actions { display: flex; gap: 6px; flex-wrap: wrap; }
/* ป้ายขนาดสินค้า */
.stock-size {
  display: inline-block; font-size: .62rem; font-weight: 700;
  background: #eef2f0; color: var(--muted);
  border-radius: 999px; padding: 2px 8px; vertical-align: 2px; margin-left: 4px;
}
/* ============ Picker เลือกสต็อก (ในฟอร์มเพิ่มกิจกรรม) ============ */
.stock-picker .sp-search {
  width: 100%; padding: 9px 11px; border: 1.5px solid var(--line); border-radius: 8px;
  background: #fff; font-size: .8rem; margin-bottom: 6px;
}
.stock-picker .sp-search:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(22, 163, 74, .12); outline: 0; }
.stock-pick-list {
  max-height: 150px; overflow-y: auto; display: flex; flex-direction: column; gap: 4px;
  border: 1px solid var(--line); border-radius: 8px; background: #fff; padding: 4px;
  overscroll-behavior: contain; /* เลื่อนสุดแล้วหยุด ไม่ลากพื้นหลังต่อ */
}
.stock-pick-item {
  display: flex; align-items: baseline; justify-content: space-between; gap: 8px;
  text-align: left; background: #f8fafc; border: 1px solid transparent; border-radius: 7px;
  padding: 7px 9px; cursor: pointer; font-size: .78rem;
  transition: background .15s, border-color .15s;
}
.stock-pick-item:hover { background: var(--green-soft); border-color: var(--green-light); }
.stock-pick-item.selected { background: var(--green-soft); border-color: var(--green); }
.stock-pick-item .sp-name { font-weight: 700; color: var(--text); }
/* ปุ่ม ✕ เอารายการที่เลือกอยู่ออก (กดอีกครั้งที่รายการก็ได้) */
.stock-pick-item .sp-x {
  margin-left: auto; flex-shrink: 0; width: 18px; height: 18px;
  display: inline-flex; align-items: center; justify-content: center;
  background: #fee2e2; color: var(--red); border-radius: 50%;
  font-size: .72rem; font-weight: 800; line-height: 1;
}
.stock-pick-item .sp-sub { font-size: .68rem; color: var(--muted); flex-shrink: 0; }
.stock-pick-item.selected .sp-name { color: var(--green-deep); }
/* รายการที่หมดสต็อก → แถบแดง */
.stock-pick-item.out {
  background: var(--red-light); border-color: #fecaca; cursor: not-allowed;
}
.stock-pick-item.out .sp-name { color: var(--red); }
.stock-pick-item.out:hover { background: var(--red-light); border-color: #fecaca; }
.sp-out {
  font-size: .64rem; font-weight: 800; color: #fff; background: var(--red);
  border-radius: 999px; padding: 1px 7px; flex-shrink: 0;
}
/* แถบเตือนจำนวนเกินของในสต็อก */
.ci-warn {
  font-size: .72rem; font-weight: 700; color: var(--red);
  background: var(--red-light); border: 1px solid #fecaca; border-radius: 8px;
  padding: 6px 9px; margin: 0 0 10px;
}
/* กล่องคำนวณการใช้ตามพื้นที่ */
.calc-box {
  margin: 2px 0 10px; padding: 10px 12px;
  background: #f0fdf4; border: 1.5px dashed var(--green-light); border-radius: 10px;
}
.calc-title { font-size: .76rem; font-weight: 800; color: var(--green-deep); margin-bottom: 6px; }
.calc-title .ic { width: .95em; height: .95em; vertical-align: -0.15em; }
.calc-result { font-size: .78rem; color: var(--text); margin-top: 6px; }
.calc-result .hint { margin-top: 2px; }
.calc-amt { color: var(--green-deep); font-weight: 800; }

/* ช่องค้นหาหน้าสต็อก */
.stock-thumb {
  width: 42px; height: 42px; flex-shrink: 0; border-radius: 10px;
  background: var(--bg); color: var(--muted);
  display: flex; align-items: center; justify-content: center;
  overflow: hidden; cursor: pointer;
}
.stock-thumb .ic { width: 20px; height: 20px; }
.stock-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.stock-thumb.lg { width: 92px; height: 92px; border-radius: 14px; flex-shrink: 0; }
.stock-thumb.lg .ic { width: 34px; height: 34px; }
.stock-detail-hint { color: var(--muted); opacity: .55; }
.plot-name[onclick] { cursor: pointer; transition: color .15s; }
.plot-name[onclick]:hover { color: var(--green); }
.stock-thumb:hover { box-shadow: 0 0 0 2px rgba(22, 163, 74, .35); }
.stock-detail-hint .ic { width: .82em; height: .82em; }
.sd-head { display: flex; gap: 12px; align-items: center; }
.sd-photo-actions { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; }
.sd-strip { display: flex; gap: 8px; overflow-x: auto; padding: 12px 2px 4px; }
.sd-strip-item { position: relative; flex-shrink: 0; width: 72px; height: 72px; }
.sd-strip-item img {
  width: 72px; height: 72px; object-fit: cover; border-radius: 10px; display: block;
  border: 1.5px solid var(--line); cursor: zoom-in; transition: border-color .15s;
}
.sd-strip-item img:hover { border-color: var(--green); }
.sd-strip-x {
  position: absolute; top: -6px; right: -6px; width: 20px; height: 20px; border-radius: 50%;
  border: 0; background: #ef4444; color: #fff; font-size: 11px; line-height: 1; cursor: pointer;
  display: flex; align-items: center; justify-content: center; box-shadow: 0 1px 4px rgba(0,0,0,.35);
}
.sd-no-photo {
  display: flex; align-items: center; gap: 8px; justify-content: center;
  color: var(--muted); padding: 18px 0; font-size: .85rem; border: 1.5px dashed var(--line); border-radius: 12px; margin-top: 12px;
}
#lightbox .lightbox-backdrop {
  position: fixed; inset: 0; z-index: 9999; background: rgba(0,0,0,.88);
  display: flex; align-items: center; justify-content: center;
}
#lightbox .lightbox-backdrop img {
  max-width: 92vw; max-height: 88vh; border-radius: 10px; box-shadow: 0 10px 40px rgba(0,0,0,.5);
}
.lightbox-x {
  position: absolute; top: 14px; right: 14px; width: 40px; height: 40px; border-radius: 50%;
  border: 0; background: rgba(255,255,255,.16); color: #fff; font-size: 18px; cursor: pointer;
}
.lightbox-nav {
  position: absolute; top: 50%; transform: translateY(-50%); width: 44px; height: 44px;
  border-radius: 50%; border: 0; background: rgba(255,255,255,.16); color: #fff;
  font-size: 26px; cursor: pointer; line-height: 1;
}
.lightbox-nav.prev { left: 12px; }
.lightbox-nav.next { right: 12px; }
.lightbox-count {
  position: absolute; bottom: 14px; left: 50%; transform: translateX(-50%);
  color: #fff; background: rgba(0,0,0,.55); padding: 4px 12px; border-radius: 20px; font-size: .8rem;
}
.sd-rows { margin-top: 12px; }
.sd-row {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 8px 0; border-bottom: 1px dashed var(--line); font-size: .88rem;
}
.sd-row .k { color: var(--muted); flex-shrink: 0; }
.stock-cat-wrap { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.stock-cat-select {
  flex: 1; min-width: 0; padding: 10px 12px; font-size: .85rem; color: var(--text);
  background: #fff; border: 1.5px solid var(--line); border-radius: 12px; outline: 0;
  transition: border-color .18s, box-shadow .18s;
}
.stock-cat-select:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(22, 163, 74, .12); }
.stock-search {
  display: flex; align-items: center; gap: 8px;
  background: #fff; border: 1.5px solid var(--line); border-radius: 12px;
  padding: 0 12px; margin-bottom: 14px;
  transition: border-color .18s, box-shadow .18s;
}
.stock-search:focus-within { border-color: var(--green); box-shadow: 0 0 0 3px rgba(22, 163, 74, .12); }
.stock-search .ic { width: 1.05em; height: 1.05em; color: var(--muted); flex-shrink: 0; }
.stock-search input {
  flex: 1; border: 0; outline: 0; background: transparent;
  padding: 11px 0; font-size: .9rem; min-width: 0;
}
.stock-search-clear {
  background: #eef2f0; border: 0; border-radius: 50%; width: 22px; height: 22px;
  font-size: .7rem; font-weight: 700; color: var(--muted); flex-shrink: 0; cursor: pointer;
}
/* แท็บกรองหน้าสต็อก */
.stock-tabs { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.stock-tabs .chip { font-size: .78rem; padding: 7px 14px; }
.stock-tabs .chip .badge {
  font-size: .66rem; background: rgba(0,0,0,.08); color: inherit;
  border-radius: 999px; padding: 1px 7px; margin-left: 4px; font-weight: 800;
}
.chip-active {
  background: var(--green) !important; color: #fff !important; border-color: var(--green) !important;
}

/* ============ Lists / plot cards ============ */
.plot-card .plot-top { display: flex; align-items: center; gap: 10px; }
.plot-emoji { width: 44px; height: 44px; border-radius: 13px; background: var(--green-soft); display: flex; align-items: center; justify-content: center; font-size: 1.4rem; flex-shrink: 0; }
.plot-name { font-weight: 800; font-size: .98rem; }
.meta-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.meta-box { background: var(--green-soft); border-radius: var(--radius-sm); padding: 8px 10px; }
.meta-box .lb { font-size: .66rem; color: var(--muted); font-weight: 600; }
.meta-box .vl { font-size: .86rem; font-weight: 700; }
.actions-row { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
/* พิกัด GPS -> ลิงก์เปิดแผนที่ */
.gps-link { color: var(--green-deep); text-decoration: underline; font-weight: 700; display: inline-flex; align-items: center; gap: 4px; word-break: break-all; }
.gps-link .ic { width: .95em; height: .95em; flex-shrink: 0; }

/* ============ สภาพอากาศรายแปลง (weather card) ============ */
.weather-card { padding: 14px; }
.weather-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.weather-loc { font-weight: 800; font-size: .9rem; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.weather-loc .ic { width: 1em; height: 1em; color: var(--green); }
.weather-addr { font-size: .72rem; color: var(--muted); font-weight: 600; }
.weather-updated { font-size: .66rem; color: var(--muted); margin-top: 2px; }
.weather-map { display: inline-flex; align-items: center; gap: 4px; font-size: .72rem; font-weight: 700; color: var(--green-deep); border: 1px solid var(--green-light); background: var(--green-soft); border-radius: 999px; padding: 5px 11px; text-decoration: none; white-space: nowrap; }
.weather-map .ic { width: .9em; height: .9em; }
.weather-now { display: flex; align-items: center; gap: 12px; margin: 12px 0 10px; }
.weather-emoji { font-size: 2.4rem; line-height: 1; }
.weather-temp { font-size: 2.1rem; font-weight: 800; line-height: 1.05; }
.weather-cond { font-size: .78rem; color: var(--muted); font-weight: 600; }
.weather-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.weather-chips span { background: var(--green-soft); border: 1px solid var(--green-light); border-radius: 999px; padding: 5px 11px; font-size: .72rem; font-weight: 700; color: var(--green-deep); }
.weather-days { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; }
.wday { text-align: center; background: #f8faf9; border: 1px solid var(--line); border-radius: 10px; padding: 8px 2px; }
.wday-name { font-size: .68rem; font-weight: 800; color: var(--muted); }
.wday-emoji { font-size: 1.25rem; margin: 3px 0; }
.wday-temp { font-size: .68rem; font-weight: 700; white-space: nowrap; }
.wday-rain { font-size: .6rem; color: #1d4ed8; font-weight: 700; }
.weather-note { font-size: .78rem; color: var(--muted); padding: 6px 0; display: flex; align-items: center; gap: 6px; }
.weather-note .ic { width: 1em; height: 1em; color: var(--green); flex-shrink: 0; }
.weather-loading { display: flex; align-items: center; gap: 8px; font-size: .8rem; color: var(--muted); padding: 8px 0; }
.weather-loading .ic { width: 1em; height: 1em; color: var(--green); }
/* Stock / equipment rows */
.stock-qty { font-size: 1.35rem; font-weight: 800; color: var(--green-dark); line-height: 1.1; }
.stock-qty small { font-size: .72rem; font-weight: 600; color: var(--muted); }
.stock-qty.out { color: #ef4444; }
.stock-card-out { background: #fef2f2; border-color: #fecaca; }
.stock-out-badge {
  display: inline-flex; align-items: center; gap: 3px; margin-left: 6px;
  background: #ef4444; color: #fff; font-size: .62rem; font-weight: 800;
  padding: 2px 8px; border-radius: 999px; vertical-align: middle; white-space: nowrap;
}
.stock-out-badge .ic { width: .72em; height: .72em; }
.stock-out {
  display: flex; align-items: center; gap: 5px; margin-top: 4px;
  font-size: .72rem; font-weight: 700; color: #dc2626;
}
.stock-out .ic { width: .9em; height: .9em; flex-shrink: 0; }

/* ============ Switch (IoT) ============ */
.switch { position: relative; width: 48px; height: 28px; border-radius: 999px; background: #cbd5d1; transition: background .18s; flex-shrink: 0; }
.switch::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.3); transition: transform .18s;
}
.switch.on { background: var(--green); }
.switch.on::after { transform: translateX(20px); }

/* ============ More menu grid ============ */
.more-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.more-card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 18px 14px; display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center;
  transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
}
@media (hover: hover) { .more-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); border-color: #d4e2da; } }
.more-card .mc-ico { font-size: 1.9rem; }
.more-card .mc-name { font-weight: 800; font-size: .9rem; }
.more-card .mc-desc { font-size: .7rem; color: var(--muted); }

/* ============ Modal (bottom sheet) ============ */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15, 23, 42, .5); z-index: 70;
  display: flex; align-items: flex-end; justify-content: center; animation: fadeIn .18s ease;
}
.modal {
  background: #fff;
  width: 100%; max-width: var(--maxw); max-height: 88vh; max-height: 88dvh; overflow-y: auto;
  border-radius: 20px 20px 0 0; padding: 18px 18px calc(20px + env(safe-area-inset-bottom));
  box-shadow: 0 -8px 30px rgba(16, 60, 32, .12);
  animation: slideUp .28s cubic-bezier(.22, .8, .3, 1);
  overscroll-behavior: contain; /* เลื่อน modal สุดแล้วไม่ลากพื้นหลัง */
}
@keyframes slideUp { from { transform: translateY(30px); opacity: 0; } to { transform: none; opacity: 1; } }
.modal h3 { font-size: 1.08rem; font-weight: 800; margin-bottom: 4px; }
.modal .modal-sub { font-size: .78rem; color: var(--muted); margin-bottom: 14px; }

.field { margin-bottom: 12px; }
.field label { display: block; font-size: .78rem; font-weight: 700; color: var(--muted); margin-bottom: 5px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 11px 12px; border: 1.5px solid var(--line); border-radius: var(--radius-sm);
  background: #fbfcfb;
  transition: border-color .18s, background .18s, box-shadow .18s;
}
/* ช่องวันที่ (type=date) — ปัญหาเฉพาะบางเบราว์เซอร์:
   1) Firefox/iOS บังคับความกว้างขั้นต่ำตามค่าเริ่มต้น + iOS มี min-width ภายในของตัวเอง
      → min-width:0 + max-width:100% ให้ย่อได้เท่ากับช่องอื่น (ใช้คู่กับ .form-row-2 ที่เป็น minmax(0,1fr))
   2) Safari/iOS เติม padding ภายใน (shadow DOM ของช่องวัน/เดือน/ปี) ทำให้ช่องสูง-ยาวไม่เท่ากับช่องอื่น
      → ลบ padding นั้นออก ให้สัดส่วนเท่ากับช่องกรอกทั่วไป */
.field input[type="date"] { min-width: 0; max-width: 100%; }
.field input[type="date"]::-webkit-datetime-edit,
.field input[type="date"]::-webkit-datetime-edit-fields-wrapper,
.field input[type="date"]::-webkit-datetime-edit-text,
.field input[type="date"]::-webkit-datetime-edit-day-field,
.field input[type="date"]::-webkit-datetime-edit-month-field,
.field input[type="date"]::-webkit-datetime-edit-year-field {
  padding: 0;
}
.field input[type="date"]::-webkit-inner-spin-button { height: auto; }
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--green); background: #fff;
  box-shadow: 0 0 0 3px rgba(22, 163, 74, .12);
}
.field .hint { font-size: .68rem; color: var(--muted); margin-top: 4px; }

.modal-actions { display: flex; gap: 10px; margin-top: 18px; }
.modal-actions .btn { flex: 1; }

/* ============ ฟอร์มเพิ่มกิจกรรม (แบบ Farm Command) ============ */
/* ใช้ minmax(0,1fr) แทน 1fr — ป้องกันคอลัมน์ถูกดันกว้างตามขนาดเนื้อหาขั้นต่ำของช่อง (เช่น input[type=date] บน iOS Safari มี min-content กว้างกว่า)
   ทำให้ 2 ช่องในแถวเท่ากันเสมอ */
.form-row-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.option-box {
  display: flex; align-items: center; gap: 10px;
  border: 1px solid var(--line); background: var(--green-soft); border-radius: 10px;
  padding: 12px 14px; margin-bottom: 12px; cursor: pointer;
  font-size: .86rem; font-weight: 700; color: var(--green-deep);
  transition: border-color .15s, box-shadow .15s;
}
.option-box:hover { border-color: var(--green-light); }
.option-box input { width: 17px; height: 17px; accent-color: var(--green); flex-shrink: 0; }
.option-box span { display: inline-flex; align-items: center; gap: 8px; }
.option-box .ic { width: 1.1em; height: 1.1em; color: var(--green); }
.option-box.inline-option { background: #fff; padding: 10px 12px; margin-bottom: 0; font-size: .8rem; }
.nested-fields {
  border: 1px solid var(--green-light); background: var(--green-soft);
  border-radius: 12px; padding: 12px; margin-bottom: 12px;
}
.nested-fields .field { margin-bottom: 10px; }
.usage-total {
  font-size: .82rem; font-weight: 700; color: var(--green-deep);
  text-align: right; padding-top: 8px; border-top: 1px dashed var(--green-light);
}
.usage-total strong { font-size: .92rem; }
/* การ์ดรายการค่าใช้จ่ายย่อย (หลายรายการต่องาน) */
.usage-row {
  background: #fff; border: 1px solid var(--green-light); border-radius: 10px;
  padding: 12px; margin-bottom: 10px;
}
.usage-row-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.usage-row-head strong { font-size: .78rem; color: var(--green-deep); }
.usage-row .field { margin-bottom: 8px; }
.usage-row .form-row-2:last-child { margin-bottom: 0; }
/* รายการค่าใช้จ่ายในหน้าดูรายละเอียดงาน */
.td-cost-title { font-size: .74rem; font-weight: 800; color: var(--green-deep); display: flex; align-items: center; gap: 5px; margin: 2px 0 6px; }
.td-cost-title .ic { width: 1em; height: 1em; }
.td-cost-list { border: 1px solid var(--green-light); background: var(--green-soft); border-radius: 10px; padding: 6px 10px; margin-bottom: 12px; }
.td-cost-row { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; padding: 6px 0; border-bottom: 1px dashed var(--green-light); font-size: .82rem; }
.td-cost-row:last-child { border-bottom: none; }
.td-cost-row b { color: var(--green-deep); flex-shrink: 0; }
@media (max-width: 480px) {
  .form-row-2 { grid-template-columns: 1fr; }
}
.modal-x { position: absolute; top: 14px; right: 14px; width: 32px; height: 32px; border-radius: 50%; background: #f1f5f4; font-size: 1rem; font-weight: 700; color: var(--muted); transition: background .15s; z-index: 1; }
.modal-x:hover { background: #e5ece8; }
.modal { position: relative; }

/* แผนที่ปักหมุด (Leaflet + OpenStreetMap) — แตะ/ลากหมุดเพื่อปักพิกัด */
.pick-hint { font-size: .72rem; color: var(--muted); margin: 2px 0 0; }
.pick-hint .ic { width: .95em; height: .95em; vertical-align: -2px; color: var(--green); }
.plot-pick-map { height: 230px; border-radius: 12px; overflow: hidden; border: 1.5px solid var(--green-light); margin-top: 8px; position: relative; z-index: 0; }
.plot-pick-map .leaflet-container { height: 100%; width: 100%; font-family: inherit; }
.plot-pick-map .leaflet-pane { z-index: 0; }
.plot-pick-map .leaflet-top, .plot-pick-map .leaflet-bottom { z-index: 1; }

/* ============ งาน: รายละเอียด (viewTask) ============ */
.td-list { display: flex; flex-direction: column; gap: 6px; margin: 4px 0 12px; }
.td-row { display: flex; align-items: baseline; gap: 10px; padding: 6px 0; border-bottom: 1px dashed var(--line); }
.td-row:last-child { border-bottom: none; }
.td-k { flex: 0 0 92px; font-size: .74rem; font-weight: 700; color: var(--muted); }
.td-v { flex: 1; font-size: .86rem; font-weight: 600; word-break: break-word; }
.td-note {
  background: var(--green-soft); border: 1px solid var(--green-light);
  border-radius: 12px; padding: 12px; margin-top: 4px;
}
.td-note-title { font-size: .78rem; font-weight: 800; color: var(--green-deep); display: flex; align-items: center; gap: 5px; margin-bottom: 5px; }
.td-note-title .ic { width: 1em; height: 1em; }
.td-note-body { font-size: .85rem; line-height: 1.6; white-space: pre-line; }

/* ============ Toast ============ */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--nav-h) + 16px); z-index: 80;
  background: #111827; color: #fff; padding: 11px 20px; border-radius: 999px; font-size: .84rem; font-weight: 600;
  box-shadow: 0 8px 24px rgba(0,0,0,.25); max-width: 90%; text-align: center;
  animation: slideUp .25s cubic-bezier(.22, .8, .3, 1);
}

/* ============ Plot profit rows (clickable) ============ */
.plot-profit {
  width: 100%; display: flex; align-items: center; gap: 10px;
  padding: 10px 0; border-bottom: 1px solid var(--line);
  cursor: pointer; text-align: left; background: none; color: inherit;
}
.plot-profit:last-child { border-bottom: none; }
.plot-profit:active { opacity: .7; }
.clickable { cursor: pointer; }
.clickable:active { opacity: .75; }

/* ============ Cycle cards (กดเข้ารอบการปลูก -> ดูงาน/กิจกรรมของรอบ) ============ */
/* หน้ารอบการปลูก: กลุ่มแปลง (หัวแปลงกดย่อ/ขยายได้) */
.plot-cycle-group { padding: 0; overflow: hidden; }
.plot-cycle-head {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px; cursor: pointer;
  background: linear-gradient(135deg, var(--green-soft), transparent);
  transition: background .15s;
}
.plot-cycle-head:active { opacity: .75; }
.plot-cycle-head .plot-emoji { width: 40px; height: 40px; font-size: 1.2rem; }
.plot-cycle-chevron {
  font-size: 1rem; color: var(--muted); transition: transform .18s;
  flex-shrink: 0;
}
.plot-cycle-body { padding: 10px 14px 14px; border-top: 1px dashed var(--line); }
/* การ์ดรอบในกลุ่มแปลง: มือถือ 1 ใบ/แถว, จอพอ (≥640px) 2 ใบ/แถว — กันการ์ดยืดยาวเกิน */
.cycle-grid { display: grid; grid-template-columns: 1fr; gap: 10px; }
/* สรุปต้นทุนรายหมวด (หน้ารายละเอียดรอบ): 2 หมวดต่อแถว */
.cc-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }
.cc-box {
  background: var(--green-soft); border-radius: var(--radius-sm); padding: 8px 10px;
  display: flex; flex-direction: column; gap: 2px; min-width: 0;
}
.cc-box .cc-label { font-size: .68rem; color: var(--muted); font-weight: 600; display: flex; align-items: center; gap: 5px; }
.cc-box .cc-val { font-size: .86rem; font-weight: 800; }
/* แถบพื้นที่เก็บข้อมูล (หน้าตั้งค่า) */
.storage-bar { height: 8px; border-radius: 999px; background: #eef2f0; overflow: hidden; margin-top: 8px; }
.storage-bar-fill { height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--green), var(--green-dark)); transition: width .35s ease; }
.storage-bar-fill.warn { background: linear-gradient(90deg, #f59e0b, var(--red)); }

/* แถบตัวกรองหน้ารอบการปลูก: ค้นหาชื่อแปลง/พืช + chips สถานะ */
.cycle-filter { padding: 12px 14px; }
.cycle-filter > input {
  width: 100%; padding: 9px 11px; border: 1.5px solid var(--line); border-radius: 8px;
  background: #fff; font-size: .8rem;
}
.cycle-filter > input:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(22, 163, 74, .12); outline: 0; }
.cycle-filter .stock-tabs { margin: 10px 0 0; }
.cycle-card { cursor: pointer; }
.cycle-open-hint {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--line);
  color: var(--green); font-size: .78rem; font-weight: 700;
}
.cycle-open-hint .ic { width: .95em; height: .95em; }

/* งานที่ยังไม่ผูกกับรอบการปลูก — ป้าย + เลือกผูกได้จากหน้าแปลง */
.task-nocycle {
  display: inline-block; background: #fef3c7; color: #92400e;
  font-size: .66rem; font-weight: 700; padding: 1px 8px; border-radius: 20px; vertical-align: 1px;
}
/* ป้ายแปลงเจ้าของงาน (หน้าแรก/ปฏิทิน) — เห็นทันทีว่างานนี้แปลงไหน */
.task-plot {
  display: inline-flex; align-items: center; gap: 3px;
  background: var(--green-soft); color: var(--green-dark);
  font-size: .68rem; font-weight: 700; padding: 1px 8px; border-radius: 20px; vertical-align: 1px;
}
/* สรุปวัสดุที่ใช้ในงาน — ชื่อ+จำนวน+หน่วย เห็นชัดว่าใช้อะไรไป */
.task-use { color: var(--green-dark); font-weight: 600; }
.task-use-more {
  display: inline-block; background: var(--green-soft); color: var(--green-dark);
  font-size: .64rem; font-weight: 700; padding: 0 6px; border-radius: 20px; vertical-align: 1px;
}
/* เลือกโหมดราคาต่อหน่วยของวัสดุ (ต้นทุน/ราคาขาย/พิมพ์เอง) */
.ci-pricemode { width: 100%; margin-bottom: 5px; font-size: .78rem; }
/* อันดับในรายการ Top (สินค้าขายดี / ลูกค้าท็อป) */
.rank-badge {
  flex-shrink: 0; width: 22px; height: 22px; border-radius: 50%;
  background: var(--green-soft); color: var(--green-deep);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: .7rem; font-weight: 800;
}
.row-line:first-child .rank-badge { background: #fef3c7; color: #92400e; } /* อันดับ 1 เน้นสีเหลือง */

/* เงินในแถวงาน: รายได้ = เขียว, ต้นทุน = แดง */
.task-money { display: inline-flex; align-items: center; gap: 3px; font-weight: 700; }
.task-money .ic { width: .95em; height: .95em; }
.task-money.in { color: var(--green); }
.task-money.out { color: var(--red); }
.task-cycle-assign {
  width: 100%; margin-top: 6px; padding: 7px 10px; font-size: .78rem;
  background: #fff; border: 1.5px dashed var(--green); border-radius: 10px; color: var(--text); outline: 0;
}
.task-cycle-assign:focus { border-color: var(--green); border-style: solid; }
/* รายการงานในวันที่เลือกจากปฏิทินรายรอบ */
.cycle-cal-day { margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--line); }

/* ============ Empty state ============ */
.empty { text-align: center; padding: 30px 16px; color: var(--muted); }
.empty .e-ico { font-size: 2.6rem; margin-bottom: 8px; }
.empty .e-title { font-weight: 700; color: var(--text); margin-bottom: 3px; }

/* ============ Tour ============ */
.tour-overlay { position: fixed; inset: 0; z-index: 90; }
.tour-dim { position: absolute; inset: 0; box-shadow: 0 0 0 9999px rgba(10, 20, 15, .55); border-radius: 0; transition: all .25s ease; }
.tour-bubble {
  position: absolute; background: #fff; border-radius: 14px; box-shadow: 0 10px 30px rgba(0,0,0,.3);
  padding: 14px 16px; width: min(300px, calc(100vw - 48px)); animation: slideUp .2s ease;
}
.tour-bubble .tb-title { font-weight: 800; font-size: .95rem; margin-bottom: 4px; color: var(--green-deep); }
.tour-bubble .tb-text { font-size: .8rem; color: var(--text); margin-bottom: 12px; }
.tour-bubble .tb-actions { display: flex; align-items: center; gap: 8px; }
.tour-bubble .tb-actions .tb-pos { font-size: .72rem; color: var(--muted); margin-right: auto; }

/* ============ Misc ============ */
.gps-box { border: 1.5px dashed var(--green); border-radius: var(--radius-sm); padding: 10px; background: var(--green-soft); }
.gps-box .gps-coords { font-weight: 700; font-size: .85rem; color: var(--green-deep); }
.divider { height: 1px; background: var(--line); margin: 12px 0; }
.price-trend-up { color: var(--green); font-weight: 700; }
.price-trend-down { color: var(--red); font-weight: 700; }

/* Desktop niceties */
@media (min-width: 640px) {
  .modal-backdrop { align-items: center; }
  .modal { border-radius: 22px; max-height: 85vh; }
  .cycle-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* Scrollbar cleanup */
::-webkit-scrollbar { width: 0; height: 0; }

/* ปิดแอนิเมชันเมื่อ re-render ในหน้าเดิม (กันกระพริบตอนกดวันที่/เปลี่ยนเดือน) */
.no-anim, .no-anim * {
  animation: none !important;
  animation-delay: 0s !important;
}

/* เกียรติผู้ใช้ที่ปิดการเคลื่อนไหว */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}

/* ============================================================
   Desktop / computer layout (≥1024px)
   ============================================================ */
@media (min-width: 1024px) {
  :root { --topbar-h: 64px; }

  body {
    background: var(--bg);
    background-image: radial-gradient(1200px 500px at 85% -5%, rgba(34, 197, 94, .06), transparent 60%),
                      radial-gradient(900px 420px at -10% 20%, rgba(37, 99, 235, .05), transparent 55%);
  }

  /* ---- app shell: sidebar + content ---- */
  #app {
    max-width: none;
    margin: 0;
    display: grid;
    grid-template-columns: var(--side-w) minmax(0, 1fr);
    grid-template-rows: auto 1fr;
    min-height: 100vh;
  }

  /* ---- full-width top bar ---- */
  .topbar {
    grid-column: 1 / -1;
    grid-row: 1;
    position: sticky;
    top: 0;
    height: var(--topbar-h);
    padding: 0 20px;
    border-radius: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    box-shadow: 0 2px 10px rgba(20, 83, 45, .2);
  }
  .topbar-row { flex: 1; min-width: 0; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
  .brand { flex-shrink: 0; }
  .brand-name { font-size: 1.15rem; }
  .role-switch { margin-top: 0; width: auto; max-width: 460px; flex-shrink: 0; }
  .role-switch button { padding: 7px 12px; font-size: .8rem; }

  /* ---- sidebar (was bottom nav) ---- */
  .bottomnav {
    grid-column: 1;
    grid-row: 2;
    position: sticky;
    top: var(--topbar-h);
    left: auto;
    transform: none;
    width: 100%;
    max-width: none;
    height: calc(100vh - var(--topbar-h));
    flex-direction: column;
    justify-content: flex-start;
    align-items: stretch;
    gap: 4px;
    padding: 18px 12px 24px;
    border-top: none;
    border-right: 1px solid var(--line);
    background: #ffffff;
    overflow-y: auto;
    overscroll-behavior: contain;
    z-index: 20;
  }
  .nav-item {
    flex-direction: row;
    justify-content: flex-start;
    align-items: center;
    gap: 12px;
    padding: 11px 14px;
    font-size: .88rem;
    border-radius: 12px;
    color: var(--muted);
  }
  .nav-item .nav-ico { font-size: 1.25rem; }
  .nav-item { transition: background .18s, color .18s, transform .18s; }
  .nav-item:hover { background: var(--green-soft); color: var(--green-dark); }
  .nav-item.active { background: var(--green-soft); color: var(--green-dark); font-weight: 800; }
  .nav-item.active .nav-ico { transform: none; }
  .nav-item::before {
    content: ""; width: 4px; height: 18px; border-radius: 4px;
    background: var(--green); opacity: 0; margin-left: -6px; transition: opacity .2s;
  }
  .nav-item.active::before { opacity: 1; }

  /* สเต็ปแอนิเมชัน section หน้าแรกแบบเรียงกัน */
  .home-flow > section { animation: riseIn .5s cubic-bezier(.22, .7, .3, 1) both; }
  .home-flow > section:nth-child(1) { animation-delay: .05s; }
  .home-flow > section:nth-child(2) { animation-delay: .15s; }
  .home-flow > section:nth-child(3) { animation-delay: .25s; }
  .home-flow > section:nth-child(4) { animation-delay: .35s; }

  /* ---- main content ---- */
  .view {
    grid-column: 2;
    grid-row: 2;
    max-width: var(--content-max);
    width: 100%;
    margin: 0 auto;
    padding: 26px 28px 80px;
    min-width: 0;
  }
  .section-title { font-size: 1.18rem; margin: 28px 2px 12px; }
  .section-title:first-child { margin-top: 4px; }

  .card { border-radius: 14px; padding: 18px; }
  .card-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; align-items: start; }
  .card-grid .card { margin-bottom: 0; }
  .more-grid { grid-template-columns: repeat(4, 1fr); }

  .kpi-row { gap: 16px; }
  .kpi { padding: 16px 14px; border-radius: 14px; }
  .kpi .kpi-value { font-size: 1.3rem; }
  .kpi .kpi-label { font-size: .74rem; }

  .tabs { max-width: 460px; }

  /* Calendar bigger cells */
  .cal-grid { gap: 6px; }
  .cal-day { height: 62px; font-size: .95rem; transition: transform .15s, box-shadow .15s, background .15s; }
  .cal-day:hover { transform: translateY(-2px); box-shadow: 0 6px 14px rgba(16, 60, 32, .12); }
  .cal-dow { font-size: .74rem; }

  /* modal → centered dialog */
  .modal-backdrop { align-items: center; justify-content: center; }
  .modal {
    width: 100%;
    max-width: 620px;
    max-height: 88vh;
    max-height: 88dvh;
    border-radius: 16px;
    padding: 22px 24px 26px;
    box-shadow: 0 24px 60px rgba(15, 23, 42, .28);
  }

  /* FAB → round button bottom-right */
  .fab-dock { right: 24px; top: auto; bottom: 24px; transform: none; }
  .fab { width: 58px; height: 58px; border-radius: 50%; box-shadow: 0 8px 22px rgba(22,101,52,.45); }
  .fab:active { transform: scale(.94); }
  .fab-icon { font-size: 2rem; }
  .fab-drawer { right: 90px; bottom: 66px; transform: translateX(12px); }
  .fab-dock.open .fab-drawer { transform: translateX(0); }

  /* toast bottom-right */
  .toast {
    left: auto; right: 24px; bottom: 24px; transform: none;
  }

  /* empty state / misc sizing */
  .empty { padding: 44px 20px; }
  .chart-wrap { max-width: 480px; }
  .legend-list { max-width: 480px; }

  .more-card { padding: 22px 14px; }
  .more-card .mc-ico { font-size: 2.1rem; }
  .more-card .mc-name { font-size: .95rem; }

  .cal-card .legend { max-width: 420px; }
}

/* ============================================================
   v52.1 — Home dashboard refresh (hero, progress, chips, task rows)
   ============================================================ */

/* ---- hero card ---- */
.hero {
  position: relative;
  overflow: hidden;
  background: linear-gradient(135deg, #ffffff 0%, #f7fdf9 60%, #eefaf3 100%);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  animation: riseIn .45s cubic-bezier(.22, .7, .3, 1) both;
}
.hero::after {
  content: "🌾";
  position: absolute;
  right: -8px;
  bottom: -18px;
  font-size: 5.2rem;
  opacity: .09;
  transform: rotate(-12deg);
  pointer-events: none;
}
.hero-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; position: relative; }
.hero-greet { font-size: 1.25rem; font-weight: 800; color: var(--green-deep); }
.hero-sub { font-size: .78rem; color: var(--muted); margin-top: 2px; }
.hero-ver {
  flex-shrink: 0;
  font-size: .66rem; font-weight: 700;
  padding: 4px 10px; border-radius: 999px;
  background: var(--green); color: #fff;
  box-shadow: 0 2px 6px rgba(22, 163, 74, .35);
}

/* ---- today progress ---- */
.hero-progress {
  margin-top: 14px;
  background: #f6faf7;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
}
.hp-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: .78rem; color: var(--muted); font-weight: 600; }
.hp-num { color: var(--green-deep); font-weight: 800; font-size: .84rem; }
.hp-bar { margin-top: 7px; height: 8px; border-radius: 999px; background: #d9efe1; overflow: hidden; }
.hp-bar i {
  display: block; height: 100%; border-radius: 999px;
  background: linear-gradient(90deg, var(--green), var(--green-dark));
  transition: width .35s ease;
}

/* ---- quick action chips ---- */
.hero-chips { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; position: relative; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px; border-radius: 999px;
  background: #fff; border: 1.5px solid var(--green-light); color: var(--green-dark);
  font-size: .8rem; font-weight: 700;
  box-shadow: 0 1px 3px rgba(16, 60, 32, .06);
  transition: transform .18s, background .18s, border-color .18s, box-shadow .18s;
}
.chip span { font-size: 1rem; }
@media (hover: hover) {
  .chip:hover { background: var(--green-soft); border-color: var(--green); transform: translateY(-1px); }
}
.chip:active { transform: scale(.96); }

/* ---- task rows v2 ---- */
.task-ico {
  width: 34px; height: 34px; border-radius: 10px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; font-size: 1.05rem;
}
.task-ico.work { background: #eef2ff; }
.task-ico.fertilize { background: var(--green-light); }
.task-ico.harvest { background: #ffedd5; }
.task-ico.water { background: #dbeafe; }
.task-ico.inspect { background: #fef3c7; }
.task-ico.expense { background: #fee2e2; }
.task-ico.spray { background: #f3e8ff; }

.task-check {
  width: 26px; height: 26px; border-radius: 50%; border: 2px solid #cbd5d1; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: .85rem; color: #fff; background: #fff; margin-top: 3px;
  transition: all .15s;
}
@media (hover: hover) {
  .task-check:hover { border-color: var(--green); background: var(--green-light); color: var(--green-dark); }
}
.task-check:active { transform: scale(.88); }
.task-row.done .task-check { background: var(--green); border-color: var(--green); color: #fff; }
.task-row.done .task-title { text-decoration: line-through; color: var(--muted); }

/* ---- list rows (recent / cycles) ---- */
.row-line {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 0; border-bottom: 1px solid var(--line);
}
.row-line:last-child { border-bottom: none; }
.plot-emoji.sm { width: 36px; height: 36px; font-size: 1.15rem; border-radius: 10px; }

/* ---- โหมดแก้ไขเว็บ (ผู้ดูแล) ---- */
.ed-row {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 0; border-bottom: 1px solid var(--line);
}
.ed-row:last-child { border-bottom: none; }
.ed-row .btn { padding: 5px 10px; font-size: .78rem; }

/* ---- หมวดต้นทุนที่เพิ่มเอง ---- */
.cc-dot { width: 14px; height: 14px; border-radius: 50%; flex-shrink: 0; display: inline-block; }
.cc-colors { display: flex; flex-wrap: wrap; gap: 8px; }
.cc-swatch {
  width: 30px; height: 30px; border-radius: 50%;
  border: 2px solid #fff; box-shadow: 0 0 0 1.5px var(--line);
  cursor: pointer; transition: transform .15s, box-shadow .15s;
}
.cc-swatch:hover { transform: scale(1.1); }
.cc-swatch.sel { box-shadow: 0 0 0 2.5px var(--green); transform: scale(1.1); }

/* ปุ่ม ✏️ เล็กๆ ข้างหัวข้อทุกหน้า (แสดงเมื่อผู้ดูแลปลดล็อก) */
.ed-pen {
  margin-left: 6px;
  border: 1px solid var(--green-light);
  background: var(--green-soft);
  color: var(--green-dark);
  border-radius: 7px;
  width: 24px; height: 24px;
  font-size: .68rem;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: transform .12s, background .15s;
  vertical-align: middle;
}
.ed-pen:hover { background: var(--green-light); transform: scale(1.08); }
.ed-pen:active { transform: scale(.94); }

/* ---- two-column homepage sections ----
   มือถือ: เรียงตาม DOM (ปฏิทิน+งานวันที่ → งานเร็วๆ นี้ → กำไร/ขาดทุนรายแปลง → กิจกรรมล่าสุด)
   เดสก์ท็อป: ซ้ายยาว = ปฏิทิน + งานวันที่, ขวา = งานเร็วๆ นี้ (บน) + กำไร/ขาดทุนรายแปลง (ล่าง),
            กิจกรรมล่าสุดเต็มความกว้างด้านล่าง */
.home-flow { display: grid; grid-template-columns: 1fr; gap: 0; }

@media (min-width: 1024px) {
  .home-flow {
    grid-template-columns: 1fr 1fr;
    grid-template-areas: var(--flow-areas, "cal tasks" "cal profit" "activity activity");
    gap: 0 26px;
    align-items: start;
  }
  .home-flow .sec-cal { grid-area: cal; }
  .home-flow .sec-tasks { grid-area: tasks; }
  .home-flow .sec-profit { grid-area: profit; }
  .home-flow .sec-activity { grid-area: activity; }
  .hero { padding: 22px 24px; border-radius: 18px; }
  .hero-greet { font-size: 1.45rem; }
  .hero-chips { gap: 10px; }
  .chip { padding: 9px 16px; font-size: .84rem; }
  .task-ico { width: 38px; height: 38px; font-size: 1.15rem; }
}

/* ============================================================
   v52.2 — ปฏิทินงานบนหน้าแรก (compact) + ปุ่มเลื่อนเดือน
   ============================================================ */

/* ปุ่ม ‹ › เลื่อนเดือน (ใช้ร่วม planner + หน้าแรก) */
.cal-nav {
  width: 34px; height: 34px; border-radius: 10px;
  background: var(--green-soft); color: var(--green-dark);
  font-weight: 800; font-size: 1.05rem; line-height: 1;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s, transform .12s;
}
@media (hover: hover) { .cal-nav:hover { background: var(--green-light); } }
.cal-nav:active { transform: scale(.92); }

/* ปุ่ม "วันนี้" — กระโดดกลับวันที่ปัจจุบัน (ทุกปฏิทิน) */
.cal-today {
  margin-left: auto; display: inline-flex; align-items: center; gap: 4px;
  padding: 4px 12px; border-radius: 20px;
  background: var(--green); color: #fff; font-size: .72rem; font-weight: 700;
  transition: background .15s, transform .12s;
}
.cal-today .ic { width: .9em; height: .9em; }
@media (hover: hover) { .cal-today:hover { background: var(--green-dark); } }
.cal-today:active { transform: scale(.94); }

/* ปฏิทินขนาดกะทัดรัดบนหน้าแรก */
.cal-sm .cal-head { margin-bottom: 8px; }
.cal-sm .cal-head .cal-title { font-size: .92rem; }
.cal-sm .cal-grid { gap: 4px; grid-template-columns: repeat(7, minmax(0, 1fr)); }
.cal-sm .cal-dow { font-size: .66rem; padding: 3px 0; }
.cal-sm .cal-day {
  height: 40px;
  min-height: 0;
  font-size: .8rem;
  border-radius: 9px;
}
.cal-sm .cal-day .dots { height: 5px; }
.cal-sm .cal-day .dots i { width: 5px; height: 5px; }
.cal-sm .legend { font-size: .68rem; margin: 8px 2px 2px; gap: 10px; }
@media (min-width: 1024px) {
  .cal-sm .cal-day { height: 44px; }
}
