@font-face {
  font-family: "Noto Fert Lab";
  src: url("noto-thai.woff") format("woff");
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "Noto Fert Lab";
  src: url("noto-thai-bold.woff") format("woff");
  font-weight: 700;
  font-display: swap;
}
:root {
  color-scheme: light;
  --canvas: #f1f4ee;
  --card: #fff;
  --ink: #172f27;
  --muted: #50655b;
  --line: #d9e2d8;
  --forest: #17483a;
  --green: #218061;
  --mint: #e5f0e5;
  --sage: #e7efeb;
  --lime: #dcefb8;
  --error: #a8342c;
  --shadow: 0 1px 2px #173f3010;
  --radius: 20px;
}
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--canvas);
  color: var(--ink);
  font: 400 1rem/1.55 "Noto Fert Lab", system-ui, sans-serif;
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .53; }
:focus-visible { outline: 3px solid #2b8664; outline-offset: 3px; }
h1, h2, h3, p, ul, dl, dd, figure { margin: 0; }
small { display: block; }
.sprite { width: 0; height: 0; position: absolute; pointer-events: none; }
.icon { width: 1.3rem; height: 1.3rem; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; flex: none; }

.topbar { background: var(--card); border-bottom: 1px solid var(--line); }
.topbar-inner, .layout { width: min(100% - 5rem, 1464px); margin-inline: auto; }
.topbar-inner {
  min-height: 79px;
  display: grid;
  align-items: center;
  grid-template-columns: 1fr auto 1fr;
  gap: 1rem;
}
.brand { display: inline-flex; width: max-content; align-items: center; gap: .75rem; line-height: 1.25; }
.brand strong { font-size: 1.65rem; letter-spacing: -.03em; }
.brand small { color: var(--muted); margin-top: .1rem; font-size: .82rem; }
.topbar nav { display: flex; align-items: center; gap: .25rem; }
.topbar nav a { color: var(--muted); border-radius: 11px; padding: .6rem 1.13rem; white-space: nowrap; }
.topbar nav a[aria-current="page"] { background: var(--mint); color: var(--forest); font-weight: 700; }
#auth-button { justify-self: end; white-space: nowrap; }
.button {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  gap: .45rem;
  min-height: 44px;
  margin: 0;
  border: 1px solid transparent;
  border-radius: 11px;
  padding: .52rem .92rem;
  font-weight: 700;
  line-height: 1.35;
  white-space: nowrap;
}
.primary { background: var(--forest); color: white; border-color: var(--forest); }
.primary:hover:not(:disabled) { background: #215945; }
.outline { background: #fff; color: var(--forest); border-color: var(--line); }
.outline:hover:not(:disabled) { background: #f5f8f3; }
.quiet { background: var(--mint); color: var(--forest); border-color: transparent; }
.quiet:hover:not(:disabled) { background: #d6e9d9; }
.danger { background: var(--error); color: #fff; border-color: var(--error); }
.danger:hover:not(:disabled) { background: #8d2b25; }
.layout { padding-block: 1.65rem 6.1rem; }
.page-title { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: 1.35rem; }
.page-title h1 { font-size: clamp(2rem, 3.45vw, 2.85rem); letter-spacing: -.038em; line-height: 1.28; }
.page-title p { color: var(--muted); margin-top: .2rem; }
.top-status, .page-actions { display: flex; gap: .65rem; align-items: center; flex-wrap: wrap; }
.connection { display: grid; grid-template-columns: auto max-content; column-gap: .4rem; align-items: center; font-size: .86rem; color: var(--muted); }
.connection small { grid-column: 2; }
.dot { width: .52rem; height: .52rem; border-radius: 50%; background: #9aab9f; }
.connection.online .dot { background: var(--green); }
.connection.online strong { color: var(--forest); }

.card, .metric { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.metrics { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); gap: 1rem; margin-bottom: 1.2rem; }
.metric { position: relative; min-height: 120px; padding: .95rem 1rem; display: flex; flex-direction: column; justify-content: center; gap: .12rem; }
.metric > span:first-child { font-size: .98rem; font-weight: 700; color: var(--muted); padding-right: 2.95rem; }
.metric-icon, .tile { display: inline-flex; justify-content: center; align-items: center; width: 39px; height: 39px; border-radius: 11px; color: var(--forest); background: var(--mint); flex: none; }
.metric-icon { position: absolute; right: 1rem; top: .95rem; }
.metric-icon.sage { background: var(--sage); }
.metric-icon.amber { background: #f7ede1; color: #924f28; }
.metric-icon.blue { background: #e9f0f4; color: #385e78; }
.reading { display: flex; gap: .32rem; align-items: baseline; white-space: nowrap; line-height: 1.32; margin-top: .2rem; }
.reading strong { font-size: clamp(1.95rem, 3.8vw, 2.62rem); letter-spacing: -.05em; font-variant-numeric: tabular-nums; }
.reading span { color: var(--muted); font-size: 1.15rem; font-weight: 700; }
.badge { border-radius: 8px; padding: .25rem .55rem; background: var(--mint); color: var(--forest); font-size: .79rem; font-weight: 700; line-height: 1.38; white-space: nowrap; }
.metric .badge { align-self: flex-start; }

.overview-grid { display: grid; grid-template-columns: minmax(0, 1.32fr) minmax(0, 1fr); gap: 1.15rem; align-items: start; }
.overview-main { display: grid; gap: 1.05rem; }
.irrigation { color: #f1f9ef; background: linear-gradient(135deg, #17483a, #14392f); border: 1px solid #17483a; border-radius: var(--radius); padding: 1.15rem 1.35rem 1.25rem; }
.irrigation-title { display: flex; gap: .65rem; align-items: center; }
.tile.dark { background: #2b604f; color: var(--lime); }
.irrigation h2, .section-title h2, .latest h2 { font-size: clamp(1.18rem, 2vw, 1.48rem); letter-spacing: -.019em; line-height: 1.3; }
.badge.dim { color: #dcefdc; background: #28604d; }
.irrigation-data { display: grid; grid-template-columns: minmax(0,1.45fr) minmax(0,1fr); gap: .85rem; padding-block: 1.3rem 1.25rem; }
.irrigation-data > div { min-width: 0; }
.irrigation-data > div:first-child > strong { display: block; font-size: clamp(1.64rem, 3.5vw, 2.75rem); line-height: 1.24; letter-spacing: -.035em; }
.irrigation-data p, .countdown-block span { color: #d3e5d9; margin-top: .32rem; }
.countdown-block { border-left: 1px solid #557568; padding-inline-start: 1.1rem; }
.countdown-block strong { display: block; color: var(--lime); font-size: clamp(2rem, 4vw, 3rem); line-height: 1.25; font-variant-numeric: tabular-nums; letter-spacing: -.04em; }
.phases { list-style: none; display: flex; flex-wrap: wrap; gap: .45rem; border-top: 1px solid #557568; padding: .8rem 0 0; }
.phases li { background: #275247; color: #ecf6ea; font-size: .87rem; font-weight: 700; padding: .42rem .68rem; border-radius: 9px; }
.phases li.current { background: var(--lime); color: var(--forest); }
.controls, .camera, .settings-card { padding: 1rem 1.12rem; }
.section-title { display: flex; align-items: center; gap: .65rem; flex-wrap: wrap; margin-bottom: .85rem; }
.controls .section-title .badge, .section-title > .button, .section-title > .muted { margin-inline-start: auto; }
.equipment { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: .55rem; margin-bottom: .68rem; }
.equipment-item { min-height: 65px; padding: .52rem .65rem; display: grid; grid-template-columns: auto 1fr auto; column-gap: .6rem; align-items: center; background: #f5f8f3; border: 1px solid #e6ede4; border-radius: 12px; }
.equipment-item strong, .control-line strong { font-size: 1rem; }
.equipment-item small, .control-line small { color: var(--muted); font-size: .84rem; }
.control-line { display: grid; grid-template-columns: auto 1fr auto auto; gap: .6rem; align-items: center; min-height: 43px; border-top: 1px solid var(--line); }
.control-line .icon { color: var(--forest); }
.switch { appearance: none; position: relative; width: 43px; height: 25px; background: #c7d5ca; border: 0; border-radius: 99px; transition: background .17s ease; flex: none; }
.switch::after { content: ""; position: absolute; display: block; left: 4px; top: 4px; width: 17px; height: 17px; border-radius: 50%; background: white; box-shadow: 0 1px 2px #1b32224d; transition: transform .17s ease; }
.switch[aria-checked="true"] { background: var(--green); }
.switch[aria-checked="true"]::after { transform: translateX(18px); }
.latest { display: flex; align-items: start; gap: .7rem; padding: 1rem; background: #eaf3e7; }
.latest h2 { font-size: 1.06rem; margin-bottom: .2rem; }
.latest p { overflow-wrap: anywhere; }
.latest > .badge { margin-inline-start: auto; }
.camera { margin: 0; }
.camera-actions { display: flex; flex-wrap: wrap; gap: .35rem; margin-inline-start: auto; }
#camera-dialog { width: min(720px, calc(100% - 32px)); max-width: 100%; }
#camera-dialog video { display: block; width: 100%; background: #172420; border-radius: 12px; }
#camera-status:empty { display: none; }
.camera img { width: 100%; display: block; height: auto; aspect-ratio: 1.55; object-fit: cover; border-radius: 13px; }
.camera p { color: var(--muted); font-size: .83rem; margin-top: .55rem; }

#settings-form { display: grid; gap: 1rem; }
.settings-grid { display: grid; grid-template-columns: minmax(0,1.3fr) minmax(0,1fr); gap: 1rem; }
.callout { padding: 1.1rem; display: flex; align-items: center; justify-content: space-between; gap: .8rem; }
.fields { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: .75rem 1rem; }
.profile-fields { grid-template-columns: 1fr 1fr 1.2fr; }
label, legend { font-size: .95rem; font-weight: 700; }
.fields label { display: grid; align-content: end; gap: .23rem; min-width: 0; }
input:not([type="radio"],[type="checkbox"],[type="file"]), select, textarea {
  width: 100%; min-width: 0; min-height: 44px; padding: .48rem .7rem; border-radius: 9px;
  border: 1px solid var(--line); background: #f7f9f5; color: var(--ink); font-weight: 400;
}
input:disabled, select:disabled { color: var(--muted); opacity: .76; }
input::placeholder, textarea::placeholder { color: #61736a; opacity: 1; }
.unit-field { position: relative; }
.unit-field input { padding-inline-end: 5.25rem !important; }
.unit-field > span { position: absolute; right: .65rem; top: 50%; transform: translateY(-50%); color: var(--muted); font-weight: 400; font-size: .88rem; pointer-events: none; }
.environment { border: 0; padding: 0; margin: 0; }
.segments { display: flex; padding: 3px; background: #f7f9f5; border: 1px solid var(--line); border-radius: 9px; margin-top: .23rem; }
.segments label { flex: 1; position: relative; text-align: center; }
.segments input { position: absolute; opacity: 0; pointer-events: none; }
.segments span { display: block; padding: .37rem .5rem; border-radius: 7px; color: var(--muted); cursor: pointer; }
.segments input:checked + span { color: var(--forest); background: #dceedd; }
.segments input:focus-visible + span { outline: 2px solid var(--green); }
.mode { background: var(--mint); color: var(--forest); font-weight: 700; border-radius: 9px; display: flex; align-items: center; justify-content: center; gap: .5rem; min-height: 44px; margin-bottom: .8rem; }
.light-card > p { margin-top: .75rem; }
.muted { color: var(--muted); font-size: .88rem; }
.formula-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)) minmax(0,1fr); gap: 1rem; }
.formula-title { background: var(--mint); border-radius: 9px; padding: .3rem .55rem; display: flex; align-items: center; justify-content: space-between; }
.formula-title h3, .dosing h3 { font-size: 1rem; }
.formula-title .button { font-size: .81rem; padding: .2rem .4rem; border: 1px solid #bed7c0; min-height: 30px; }
.formula-rows { display: grid; gap: .4rem; padding-top: .45rem; }
.formula-row { display: grid; grid-template-columns: minmax(0,1fr) minmax(4rem,.48fr) 4.4rem 34px; gap: .25rem; align-items: center; }
.formula-row > input, .formula-row > select { font-size: .86rem; padding-inline: .28rem; }
.formula-row .icon-button { width: 34px; height: 34px; }
.formula-empty { color: var(--muted); font-size: .88rem; padding: .4rem; }
.dosing { border-left: 1px solid var(--line); padding-left: 1rem; }
.dosing h3 { margin-bottom: .65rem; }
.fields label.check { display: flex; gap: .45rem; align-items: center; }
input[type="checkbox"] { accent-color: var(--green); width: 1.12rem; height: 1.12rem; }
.notice { color: var(--forest); padding: .65rem .85rem; border-radius: 9px; background: var(--mint); }
.notice.error { color: #851f19; background: #fdeceb; }
.suggested input:not([type="radio"]), .suggested select, .formula-rows.suggested { background: #eff6ea; border-color: #83a983; }

.toast { position: fixed; inset: auto auto 1.4rem 50%; transform: translateX(-50%); z-index: 5; background: #173e31; border: 1px solid #315749; color: white; box-shadow: 0 7px 27px #163d312e; padding: .7rem 1rem; border-radius: 10px; max-width: min(90vw, 38rem); }
.chat-launch, .chat { right: max(1.1rem, calc((100vw - 1464px)/2)); position: fixed; z-index: 4; box-shadow: 0 8px 28px #203f3340; }
.chat-launch {
  bottom: 1.2rem;
  display: inline-flex; gap: .5rem; align-items: center; padding: .4rem .85rem .4rem .48rem;
  color: white; background: var(--forest); border: 0; border-radius: 16px; font-weight: 700;
}
.chat-launch img, .chat-head img { display: block; object-fit: contain; background: #e2eee0; border-radius: 10px; }
.chat {
  bottom: 5.35rem; width: min(424px, calc(100vw - 2.2rem)); max-height: min(670px, calc(100dvh - 7rem));
  display: flex; flex-direction: column; background: var(--card); overflow: hidden;
  border: 1px solid #cbdad0; border-radius: var(--radius);
}
.chat-head { display: flex; align-items: center; gap: .65rem; padding: .76rem .82rem; border-bottom: 1px solid var(--line); }
.chat-head h2 { font-size: 1.27rem; line-height: 1.25; }
.chat-head p { color: var(--muted); font-size: .82rem; }
.chat-head button { margin-inline-start: auto; }
.icon-button { width: 38px; height: 38px; padding: .3rem; border: 1px solid transparent; border-radius: 9px; display: inline-flex; align-items: center; justify-content: center; flex: none; }
.chat-log { overflow-y: auto; padding: .78rem .86rem; min-height: 110px; flex: 1; overscroll-behavior: contain; }
.chat-messages, #chat-messages { display: grid; gap: .45rem; }
.bubble { max-width: 94%; padding: .56rem .73rem; border-radius: 11px; word-break: break-word; white-space: pre-wrap; }
.bubble.user { background: #e4f1e5; justify-self: end; }
.bubble.assistant { background: #f0f4ee; justify-self: start; }
.chat-log > .bubble { margin-bottom: .5rem; }
.chat audio { display: block; width: min(250px,100%); margin-top: .6rem; }
.proposal { margin-top: .65rem; padding: .65rem .66rem; background: #f2f7ee; border: 1px solid var(--line); border-radius: 11px; }
.proposal h3 { font-size: 1rem; margin-bottom: .4rem; }
.proposal dl div { display: grid; grid-template-columns: minmax(0,1fr) minmax(0,1.14fr); gap: .35rem; padding-block: .36rem; border-top: 1px solid var(--line); }
.proposal dt { font-size: .87rem; color: var(--muted); }
.proposal dd { font-size: .87rem; font-weight: 700; word-break: break-word; }
.proposal > p { margin-top: .45rem; font-weight: 700; }
.proposal-buttons { display: flex; gap: .36rem; margin-top: .56rem; }
.proposal-buttons .button { flex: 1; min-height: 38px; padding-inline: .45rem; font-size: .87rem; }
#chat-form { border-top: 1px solid var(--line); padding: .6rem .75rem .72rem; }
.composer { display: flex; align-items: center; gap: .38rem; }
.composer textarea { flex: 1; resize: vertical; max-height: 95px; min-height: 38px; padding: .39rem .55rem; }
.upload { cursor: pointer; position: relative; }
.upload:focus-within { outline: 3px solid var(--green); }
.upload input { position: absolute; inline-size: 1px; block-size: 1px; opacity: 0; }
.upload:has(input:disabled) { opacity: .53; cursor: not-allowed; }
#mic[aria-pressed="true"] { background: var(--error); color: white; }
.attachment-list { display: flex; gap: .3rem; flex-wrap: wrap; }
.file-chip { display: inline-flex; align-items: center; gap: .3rem; max-width: 100%; padding: .26rem .4rem; background: var(--mint); border-radius: 7px; margin-bottom: .22rem; font-size: .8rem; }
.file-chip span { max-width: 205px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-chip button { border: 0; padding: 0 .2rem; background: transparent; color: var(--forest); }
.attachment-note { color: var(--muted); font-size: .78rem; margin-bottom: .34rem; }
dialog { max-width: min(26rem,calc(100vw - 2rem)); width: 100%; border: 1px solid var(--line); border-radius: var(--radius); padding: 1.15rem; color: var(--ink); box-shadow: 0 12px 38px #1b3c3540; }
dialog::backdrop { background: #172f2770; }
dialog .section-title { justify-content: space-between; }
#login-form { display: grid; gap: .7rem; }
#login-form .section-title { margin: 0; }
#login-form button[type="submit"] { justify-self: end; }

@media (max-width: 1080px) {
  .topbar-inner, .layout { width: calc(100% - 3.2rem); }
  .metric { padding-inline: .8rem; }
  .metric-icon { right: .8rem; }
  .formula-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .dosing { grid-column: 1/-1; border-left: 0; border-top: 1px solid var(--line); padding: .75rem 0 0; }
}
@media (max-width: 780px) {
  .topbar-inner, .layout { width: calc(100% - 2rem); }
  .topbar-inner { min-height: 66px; grid-template-columns: 1fr auto; gap: .15rem .65rem; padding: .55rem 0; }
  .topbar nav { grid-column: 1/-1; grid-row: 2; }
  .topbar nav a { padding: .35rem .85rem; }
  .brand img { width: 39px; height: 39px; }
  .brand strong { font-size: 1.3rem; }
  .brand small { font-size: .74rem; }
  #auth-button { grid-column: 2; grid-row: 1; min-height: 39px; }
  .metrics { grid-template-columns: repeat(2,minmax(0,1fr)); gap: .55rem; margin-bottom: .8rem; }
  .metric { min-height: 95px; padding: .68rem; border-radius: 13px; }
  .metric > span:first-child { padding-right: 1.9rem; font-size: .85rem; }
  .metric-icon { top: .62rem; right: .62rem; width: 30px; height: 30px; border-radius: 8px; }
  .metric-icon .icon { width: 1rem; height: 1rem; }
  .overview-grid, .settings-grid { grid-template-columns: 1fr; gap: .8rem; }
  .overview-main { gap: .8rem; }
  .profile-fields { grid-template-columns: 1fr 1fr; }
  .profile-fields .environment { grid-column: 1/-1; }
  .page-title { align-items: flex-start; flex-direction: column; gap: .55rem; margin-bottom: .85rem; }
  .layout { padding-top: 1.1rem; }
  .irrigation { padding: .9rem; }
  .countdown-block { padding-inline-start: .66rem; }
}
@media (max-width: 475px) {
  .formula-grid { grid-template-columns: 1fr; }
  .profile .section-title .button { margin-left: 0; }
  .card { border-radius: 15px; }
  .settings-card, .controls, .camera { padding: .82rem; }
  .equipment-item { gap: .33rem; padding-inline: .37rem; }
  .equipment-item .tile { width: 31px; height: 31px; }
  .equipment-item strong, .control-line strong { font-size: .87rem; }
  .equipment-item small, .control-line small { font-size: .77rem; }
  .control-line { gap: .35rem; }
  .control-line .icon { width: 1rem; }
  .switch { width: 36px; }
  .switch[aria-checked="true"]::after { transform: translateX(11px); }
  .irrigation-data { grid-template-columns: 1.2fr 1fr; gap: .6rem; padding-block: .9rem; }
  .irrigation-data p, .countdown-block span { font-size: .87rem; }
  .fields { gap: .6rem; }
  .fields label, legend { font-size: .86rem; }
  .unit-field input { padding-inline-end: 3.25rem !important; }
  .unit-field > span { font-size: .75rem; right: .36rem; }
  .chat-launch, .chat { right: .85rem; }
  .chat { width: calc(100vw - 1.7rem); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: 0s !important; }
}
