/* farmctl — 휴대폰 우선. 어르신들이 쓰므로 글씨와 버튼을 크게 잡는다 */
:root {
  --bg: #f4f6f3; --card: #ffffff; --text: #17201a; --sub: #5d6b62; --line: #dfe5df;
  --brand: #1f7a4d; --brand-text: #ffffff; --on: #1f9d57; --on-bg: #e3f6ea;
  --off: #6b756e; --off-bg: #eef1ee; --bad: #c0392b; --bad-bg: #fbe9e6; --warn-bg: #fff6d9;
  --admin: #7a4b1f; --admin-bg: #f7ead9;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121613; --card: #1c221e; --text: #e9efe9; --sub: #9dac9f; --line: #2c352f;
    --brand: #2f9c66; --on: #46c980; --on-bg: #173524; --off: #9aa59c; --off-bg: #252c27;
    --bad: #ef7868; --bad-bg: #3a1e1a; --warn-bg: #3a3214; --admin: #e0b07a; --admin-bg: #3a2c1b;
  }
}
* { box-sizing: border-box; }
html { font-size: 18px; -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: system-ui, -apple-system, "Malgun Gothic", "Apple SD Gothic Neo", sans-serif;
  line-height: 1.45; padding-bottom: calc(76px + env(safe-area-inset-bottom));
}
[hidden] { display: none !important; }
h1, h2, h3, p { margin: 0; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }

#top {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 8px;
  padding: 10px 16px; background: var(--brand); color: var(--brand-text);
  padding-top: calc(10px + env(safe-area-inset-top));
}
#top h1 { font-size: 1.15rem; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#who { font-size: .8rem; opacity: .9; white-space: nowrap; }
.icon-btn {
  border: 0; background: rgba(255,255,255,.18); color: inherit; width: 44px; height: 44px;
  border-radius: 12px; font-size: 1.8rem; line-height: 1;
}

main { max-width: 760px; margin: 0 auto; padding: 16px; display: grid; gap: 14px; }

#tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5; display: flex;
  background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
#tabs a {
  flex: 1; text-align: center; padding: 8px 4px 10px; text-decoration: none;
  color: var(--sub); font-size: .85rem; font-weight: 600;
}
#tabs a .ico { display: block; font-size: 1.4rem; line-height: 1.3; }
#tabs a.active { color: var(--brand); }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 16px; }
.card h2 { font-size: 1.05rem; margin-bottom: 10px; }
.muted { color: var(--sub); font-size: .88rem; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.stack { display: grid; gap: 10px; }

.badge {
  display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: .8rem; font-weight: 700;
  background: var(--off-bg); color: var(--off); white-space: nowrap;
}
.badge.on { background: var(--on-bg); color: var(--on); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }
.badge.admin { background: var(--admin-bg); color: var(--admin); }

.btn {
  border: 1px solid var(--line); background: var(--card); border-radius: 14px;
  padding: 14px 18px; min-height: 56px; font-weight: 700; font-size: 1rem;
}
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-text); }
.btn.danger { color: var(--bad); border-color: var(--bad); }
.btn.small { min-height: 44px; padding: 8px 14px; font-size: .9rem; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .55; cursor: default; }

label { display: grid; gap: 6px; font-weight: 600; font-size: .95rem; }
input, select {
  width: 100%; padding: 14px; min-height: 56px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--card); font-size: 1.05rem;
}
input[type="file"] { padding: 12px; font-size: .95rem; }
input:focus, select:focus, .btn:focus-visible, .out:focus-visible { outline: 3px solid var(--brand); outline-offset: 2px; }
.error { color: var(--bad); font-weight: 600; min-height: 1.4em; }
.note { background: var(--warn-bg); border-radius: 12px; padding: 10px 14px; font-size: .88rem; margin-bottom: 12px; }

/* 로그인 */
.login { max-width: 420px; margin: 8vh auto 0; }
.login .logo { width: 84px; height: 84px; display: block; margin: 0 auto 12px; }
.login h2 { text-align: center; font-size: 1.5rem; margin-bottom: 4px; }
.login p.muted { text-align: center; margin-bottom: 8px; }

/* 장비 목록 */
.dev {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 18px 16px;
}
.dev .name { font-size: 1.15rem; font-weight: 700; }
.dev .chev { font-size: 1.6rem; color: var(--sub); }
.empty { text-align: center; color: var(--sub); padding: 32px 12px; }

/* 장비 화면 */
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: .95rem; margin: 4px 0 14px; }
.kv dt { color: var(--sub); }
.kv dd { margin: 0; font-weight: 600; text-align: right; word-break: break-all; }
.outs { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.outs + .error { margin-top: 12px; }
@media (min-width: 620px) { .outs { grid-template-columns: repeat(4, 1fr); } }
.out {
  border: 2px solid var(--line); background: var(--off-bg); color: var(--off);
  border-radius: 18px; padding: 16px 10px; min-height: 104px; display: grid; gap: 4px; justify-items: center;
}
.out .ch { font-size: .95rem; font-weight: 600; color: var(--sub); }
.out .st { font-size: 1.5rem; font-weight: 800; }
.out.on { background: var(--on-bg); border-color: var(--on); color: var(--on); }
.out.busy { opacity: .6; }

/* 이력 */
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--line); background: var(--card); border-radius: 999px;
  padding: 10px 18px; min-height: 44px; font-weight: 700; font-size: .92rem; color: var(--sub);
}
.chip.active { background: var(--brand); border-color: var(--brand); color: var(--brand-text); }
.log { display: grid; gap: 0; }
.log .item { padding: 12px 0; border-top: 1px solid var(--line); display: grid; gap: 4px; }
.log .item:first-child { border-top: 0; padding-top: 0; }
.log .what { font-weight: 700; }
.log .meta { color: var(--sub); font-size: .85rem; }

/* 관리 */
.user { border-top: 1px solid var(--line); padding: 14px 0; display: grid; gap: 10px; }
.user:first-child { border-top: 0; padding-top: 0; }
.user .uname { font-weight: 700; font-size: 1.05rem; }
.qr { width: 220px; max-width: 100%; height: auto; background: #fff; border-radius: 12px; border: 1px solid var(--line); justify-self: center; }
.url { word-break: break-all; text-align: center; }
a.btn { text-decoration: none; display: inline-flex; align-items: center; color: inherit; }
.checks { display: grid; gap: 8px; }
.checks label { display: flex; align-items: center; gap: 12px; font-weight: 600; min-height: 44px; }
.checks input { width: 26px; height: 26px; min-height: 0; padding: 0; flex: none; }

#toast {
  position: fixed; left: 50%; bottom: calc(92px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: #17201a; color: #fff; padding: 12px 18px; border-radius: 12px; font-weight: 600;
  width: max-content; max-width: calc(100vw - 32px); z-index: 10; text-align: center;
}
#toast.bad { background: var(--bad); color: #fff; }
