/* Mùa Ruộng — nền tảng: màu, chữ, nút, hộp thoại, toast, ⌘K */
:root {
  --paper: #F2ECDF;      /* giấy sổ đồng */
  --paper-2: #E8DFCC;    /* kraft nhạt */
  --card: #FBF8F1;
  --ink: #1F2417;        /* mực xanh đen */
  --ink-2: #4D5240;
  --ink-3: #6E705E;
  --ma: #3B6623;         /* xanh mạ — màu hành động duy nhất */
  --ma-2: #2F531B;
  --on-ma: #F7F3E8;
  --ma-soft: #DDE6C8;
  --lua: #D2A03A;        /* vàng lúa chín */
  --lua-ink: #8A6414;
  --bun: #6B4A2E;        /* nâu bùn */
  --kraft: #BE9765;
  --line: rgba(31, 36, 23, .1);
  --late: #A4442B;
  --pk-bg: #EEE6D5;
  --shadow: 0 1px 0 rgba(31, 36, 23, .04), 0 8px 24px -16px rgba(60, 45, 20, .35);
  --ease: cubic-bezier(.2, .8, .2, 1);
  --spring: cubic-bezier(.34, 1.4, .5, 1);
  --serif: 'Fraunces', 'Times New Roman', serif;
  --sans: 'Be Vietnam Pro', system-ui, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, monospace;
  --r: 14px;
  --grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .35 0 0 0 0 .27 0 0 0 0 .15 0 0 0 .09 0'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)'/%3E%3C/svg%3E");
  color-scheme: light;
}
[data-theme="dark"] {
  --paper: #14170F;
  --paper-2: #1B1F15;
  --card: #20251A;
  --ink: #EEE7D4;
  --ink-2: #C3BCA6;
  --ink-3: #9C977F;
  --ma: #A3C870;
  --ma-2: #B9D88C;
  --on-ma: #14170F;
  --ma-soft: #2C3A1F;
  --lua: #E2B552;
  --lua-ink: #E8C470;
  --bun: #A98159;
  --kraft: #A07E55;
  --line: rgba(238, 231, 212, .1);
  --late: #E58A6C;
  --pk-bg: #2A2F22;
  --shadow: 0 1px 0 rgba(0, 0, 0, .2), 0 10px 28px -18px rgba(0, 0, 0, .7);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: auto; }
body { margin: 0; background: var(--paper) var(--grain); color: var(--ink); font: 400 16px/1.6 var(--sans); -webkit-font-smoothing: antialiased; overflow-x: hidden; }
html.locked body { overflow: hidden; }
img, video, svg { display: block; max-width: 100%; }
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3, p { margin: 0; }
.sr { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: fixed; left: 12px; top: -60px; z-index: 300; background: var(--ma); color: var(--on-ma); padding: 12px 16px; border-radius: 10px; text-decoration: none; transition: top .2s; }
.skip:focus { top: 12px; }
:focus-visible { outline: 2.5px solid var(--lua); outline-offset: 3px; border-radius: 6px; }
.mono { font-family: var(--mono); font-weight: 500; letter-spacing: -.01em; }
.muted { color: var(--ink-3); font-size: 15px; }
.num { font-variant-numeric: tabular-nums; }
.ic { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* chế độ hiển thị */
#landing, #appv, #trace { display: none; }
body[data-mode="landing"] #landing, body[data-mode="app"] #appv, body[data-mode="trace"] #trace { display: block; }

/* logo */
.logo { display: inline-flex; align-items: center; gap: 10px; color: inherit; }
.logo svg { width: 34px; height: 34px; }
.logo b { font: 500 21px/1 var(--serif); letter-spacing: -.01em; }

/* nút */
.btn { --bg: transparent; display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 18px; border-radius: 999px; border: 0; background: var(--bg); font-weight: 600; font-size: 15px; text-decoration: none; cursor: pointer; transition: transform .18s var(--ease), background .2s, box-shadow .2s, color .2s; white-space: nowrap; }
.btn:active { transform: scale(.97); }
.btn .ic { width: 18px; height: 18px; }
.btn.pri { --bg: var(--ma); color: var(--on-ma); }
.btn.pri:hover { --bg: var(--ma-2); }
.btn.ghost { box-shadow: inset 0 0 0 1.5px var(--line); }
.btn.ghost:hover { box-shadow: inset 0 0 0 1.5px var(--ink-3); background: color-mix(in srgb, var(--card) 70%, transparent); }
.btn.light { --bg: rgba(251, 248, 241, .92); color: #1F2417; }
.btn.danger { --bg: var(--late); color: #fff; }
.btn.sm { min-height: 40px; padding: 0 16px; font-size: 14px; }
.btn.xl { min-height: 56px; padding: 0 28px; font-size: 16px; }
.btn.wide { width: 100%; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.lnk { color: var(--ma); font-weight: 600; font-size: 15px; text-decoration: none; background: none; border: 0; padding: 0; cursor: pointer; text-underline-offset: 4px; }
.lnk:hover { text-decoration: underline; }
.ib { width: 44px; height: 44px; display: grid; place-items: center; border: 0; border-radius: 50%; background: transparent; cursor: pointer; transition: background .2s, transform .18s var(--ease); }
.ib:hover { background: var(--paper-2); }
.ib:active { transform: scale(.94); }

/* công tắc hiển thị */
.prefs { display: flex; gap: 6px; }
.pf { min-width: 44px; height: 44px; border-radius: 999px; border: 0; background: transparent; box-shadow: inset 0 0 0 1.5px var(--line); display: grid; place-items: center; cursor: pointer; font-weight: 600; font-size: 13px; letter-spacing: .04em; transition: background .2s, transform .18s var(--ease); }
.pf:hover { background: var(--paper-2); }
.pf:active { transform: scale(.95); }
.pf.on { background: var(--ma-soft); }
.pf .ic { width: 18px; height: 18px; }

/* chip giai đoạn & pill trạng thái */
.chip { display: inline-flex; align-items: center; gap: 8px; padding: 5px 12px 5px 8px; border-radius: 999px; background: color-mix(in srgb, var(--c) 18%, var(--card)); font-size: 13px; font-weight: 600; color: var(--ink); }
.chip i { width: 12px; height: 12px; border-radius: 50%; background: var(--c); box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .12); }
.pill { display: inline-flex; align-items: center; padding: 4px 12px; border-radius: 999px; font-size: 13px; font-weight: 600; background: var(--paper-2); color: var(--ink-2); white-space: nowrap; }
.pill.ok, .pill.giao { background: var(--ma-soft); color: var(--ma-2); }
[data-theme="dark"] .pill.ok, [data-theme="dark"] .pill.giao { color: var(--ma); }
.pill.low, .pill.dong { background: color-mix(in srgb, var(--lua) 26%, var(--card)); color: var(--lua-ink); }
.pill.out { background: color-mix(in srgb, var(--late) 18%, var(--card)); color: var(--late); }
.pill.xuat { background: color-mix(in srgb, var(--kraft) 28%, var(--card)); color: var(--bun); }
[data-theme="dark"] .pill.xuat { color: var(--ink); }

/* avatar chữ cái */
.av { --h: 0; width: 44px; height: 44px; flex: none; border-radius: 50%; display: grid; place-items: center; font-weight: 600; font-size: 14px; letter-spacing: .02em; color: #1F2417; background: hsl(calc(40 + var(--h) * 22) 38% 78%); }
[data-theme="dark"] .av { background: hsl(calc(40 + var(--h) * 22) 22% 38%); color: #F2ECDF; }

/* hộp thoại */
.mdl-wrap { position: fixed; inset: 0; z-index: 200; display: grid; place-items: center; padding: 20px; }
.mdl-bg { position: absolute; inset: 0; background: rgba(20, 23, 15, .5); opacity: 0; transition: opacity .3s var(--ease); }
.mdl { position: relative; width: min(560px, 100%); max-height: calc(100dvh - 40px); overflow: auto; background: var(--card); border-radius: 20px; box-shadow: 0 30px 80px -30px rgba(0, 0, 0, .5); opacity: 0; transform: translateY(16px) scale(.98); transition: opacity .3s var(--ease), transform .4s var(--spring); outline: none; }
.mdl.wide { width: min(1040px, 100%); }
.mdl-wrap.in .mdl-bg { opacity: 1; }
.mdl-wrap.in .mdl { opacity: 1; transform: none; }
.mdl-wrap.side { place-items: stretch end; padding: 0; }
.mdl-wrap.side .mdl { width: min(520px, 100%); max-height: 100dvh; height: 100dvh; border-radius: 20px 0 0 20px; transform: translateX(40px); }
.mdl-wrap.side.in .mdl { transform: none; }
.mdl-pad { padding: 28px; }
.mdl-h { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.mdl-h.pad { padding: 24px 24px 0 28px; }
.mdl-t { font: 500 26px/1.2 var(--serif); letter-spacing: -.01em; }
.mdl-p { color: var(--ink-2); margin: 8px 0 20px; }
.mdl-act { display: flex; justify-content: flex-end; gap: 12px; margin-top: 24px; flex-wrap: wrap; }
.mdl-wrap.cmdk { place-items: start center; padding-top: 12vh; }
.mdl-wrap.cmdk .mdl { width: min(620px, 100%); }

/* biểu mẫu */
.fg { display: grid; gap: 8px; margin: 0 0 18px; border: 0; padding: 0; font-size: 14px; font-weight: 600; color: var(--ink-2); }
.fg.two { grid-template-columns: 1fr 1fr; gap: 16px; }
.fg.two label { display: grid; gap: 8px; }
.fg legend, .fg .lbl { font-size: 14px; font-weight: 600; color: var(--ink-2); margin-bottom: 8px; padding: 0; }
input:not([type=radio]):not([type=checkbox]):not([type=range]), select, textarea { width: 100%; min-height: 48px; padding: 10px 14px; border-radius: 12px; border: 0; background: var(--paper); box-shadow: inset 0 0 0 1.5px var(--line); font-size: 16px; font-weight: 400; color: var(--ink); transition: box-shadow .2s; }
input:focus, select:focus, textarea:focus { outline: none; box-shadow: inset 0 0 0 2px var(--ma); }
textarea { resize: vertical; line-height: 1.5; }
.hint { font-weight: 400; color: var(--ink-3); font-size: 13px; }
.ferr { background: color-mix(in srgb, var(--late) 12%, var(--card)); color: var(--late); padding: 12px 14px; border-radius: 12px; font-size: 14px; font-weight: 500; }
.radios { display: flex; flex-wrap: wrap; gap: 8px; }
.rd { position: relative; }
.rd input { position: absolute; opacity: 0; inset: 0; }
.rd span { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 16px; border-radius: 999px; box-shadow: inset 0 0 0 1.5px var(--line); font-weight: 500; font-size: 15px; color: var(--ink); cursor: pointer; transition: background .2s, box-shadow .2s; }
.rd span .ic { width: 18px; height: 18px; }
.rd input:checked + span { background: var(--ma-soft); box-shadow: inset 0 0 0 2px var(--ma); }
.rd input:focus-visible + span { outline: 2.5px solid var(--lua); outline-offset: 2px; }
.its { display: grid; gap: 10px; }
.it-r { display: grid; grid-template-columns: 1fr 120px; gap: 10px; }
.phs { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.ph { position: relative; }
.ph input { position: absolute; opacity: 0; }
.ph span { display: grid; place-items: center; aspect-ratio: 1; border-radius: 12px; overflow: hidden; background: var(--paper); box-shadow: inset 0 0 0 1.5px var(--line); cursor: pointer; color: var(--ink-3); font-size: 13px; }
.ph span img { width: 100%; height: 100%; object-fit: cover; }
.ph input:checked + span { box-shadow: 0 0 0 3px var(--ma); }
.ph input:focus-visible + span { outline: 2.5px solid var(--lua); outline-offset: 3px; }

/* toast */
#toasts { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 260; display: grid; gap: 8px; pointer-events: none; width: min(440px, calc(100% - 32px)); }
.toast { display: flex; align-items: center; gap: 12px; padding: 14px 18px; border-radius: 14px; background: #1F2417; color: #F2ECDF; font-size: 15px; box-shadow: 0 18px 40px -18px rgba(0, 0, 0, .55); opacity: 0; transform: translateY(14px) scale(.98); transition: opacity .3s var(--ease), transform .45s var(--spring); }
.toast svg { width: 20px; height: 20px; color: #B9D88C; flex: none; }
.toast.in { opacity: 1; transform: none; }
[data-theme="dark"] .toast { background: #EEE7D4; color: #1F2417; }
[data-theme="dark"] .toast svg { color: #3B6623; }

/* ⌘K */
.ck-in { display: flex; align-items: center; gap: 12px; padding: 12px 18px; border-bottom: 1px solid var(--line); }
.ck-in svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.6; color: var(--ink-3); flex: none; }
.ck-in input { box-shadow: none !important; background: transparent !important; font-size: 18px !important; padding: 8px 0 !important; }
kbd { font: 500 12px/1 var(--mono); padding: 5px 7px; border-radius: 6px; background: var(--paper-2); color: var(--ink-3); }
.ck-list { list-style: none; margin: 0; padding: 8px; max-height: 56vh; overflow: auto; }
.ck-it { display: flex; align-items: center; gap: 14px; padding: 10px 12px; border-radius: 12px; text-decoration: none; min-height: 56px; }
.ck-it img, .ck-it .av { width: 44px; height: 44px; border-radius: 10px; object-fit: cover; flex: none; }
.ck-it .av { background: var(--paper-2); color: var(--ink-2); font-style: normal; }
.ck-it span { display: grid; min-width: 0; }
.ck-it b { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ck-it small { color: var(--ink-3); font-size: 13px; }
.ck-it.on, .ck-it:hover { background: var(--paper-2); }
.ck-empty { padding: 24px; color: var(--ink-3); }

/* hiện dần */
.rv { opacity: 0; transform: translateY(22px); transition: opacity .7s var(--ease), transform .8s var(--ease); transition-delay: calc(var(--i, 0) * 70ms); }
.rv.in { opacity: 1; transform: none; }
.rv-clip { clip-path: inset(12% 0 12% 0 round 16px); transition: clip-path 1.1s var(--ease); }
.rv-clip.in { clip-path: inset(0 0 0 0 round 16px); }
.rv-clip img { transform: scale(1.12); transition: transform 1.4s var(--ease); }
.rv-clip.in img { transform: scale(1); }

.cnote { font-size: 13px; color: var(--ink-3); line-height: 1.6; }
.cnote a { color: var(--ink-2); font-weight: 600; }

/* giảm chuyển động */
html.calm *, html.calm *::before, html.calm *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; transition-delay: 0s !important; scroll-behavior: auto !important; }
html.calm .rv { opacity: 1; transform: none; }
html.calm .rv-clip { clip-path: none; }
html.calm .rv-clip img { transform: none; }
@media (prefers-reduced-motion: reduce) { .rv { opacity: 1; transform: none; } .rv-clip { clip-path: none; } }

@media (max-width: 640px) {
  .fg.two { grid-template-columns: 1fr; }
  .mdl-wrap { padding: 0; place-items: end stretch; }
  .mdl { border-radius: 20px 20px 0 0; max-height: 92dvh; }
  .mdl-wrap.side { place-items: end stretch; }
  .mdl-wrap.side .mdl { height: 92dvh; border-radius: 20px 20px 0 0; transform: translateY(40px); }
  .mdl-pad { padding: 24px 20px; }
  .phs { grid-template-columns: repeat(5, 1fr); gap: 6px; }
  .it-r { grid-template-columns: 1fr 96px; }
  #toasts { bottom: 92px; }
}
