/* 논에서 장갑 끼고 쓴다는 전제로 만든다.
   - 버튼은 크게 (최소 64px 높이)
   - 대비를 세게 (햇빛 아래에서 봐야 함)
   - 색만으로 상태를 구분하지 않는다 (글자를 같이 쓴다) */

:root {
  --bg: #f1f5f9;
  --card: #ffffff;
  --line: #d8dee9;
  --text: #0f172a;
  --dim: #64748b;
  --open: #0284c7;
  --closed: #475569;
  --moving: #ea580c;
  --fault: #dc2626;
  --ok: #059669;
  --shadow: 0 1px 3px rgba(15, 23, 42, .12);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1220;
    --card: #151f33;
    --line: #24324d;
    --text: #e8eefc;
    --dim: #93a3bd;
    --open: #38bdf8;
    --closed: #7d8ba3;
    --moving: #fb923c;
    --fault: #f87171;
    --ok: #34d399;
    --shadow: none;
  }
}

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

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Malgun Gothic",
               "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.5;
  padding-bottom: env(safe-area-inset-bottom);
}

.hidden { display: none !important; }

/* ── 로그인 ─────────────────────────────────────────── */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.login-box { width: 100%; max-width: 340px; }
.login-box h1 { font-size: 26px; margin: 0 0 24px; text-align: center; }
.login-box input {
  width: 100%; height: 56px; margin-bottom: 12px; padding: 0 16px;
  font-size: 17px; border: 1px solid var(--line); border-radius: 12px;
  background: var(--card); color: var(--text);
}
.err { color: var(--fault); min-height: 22px; margin: 8px 0 0; font-size: 14px; }

/* ── 상단 ───────────────────────────────────────────── */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; background: var(--card); border-bottom: 1px solid var(--line);
}
.who { display: flex; align-items: center; gap: 8px; }
.chip {
  font-size: 12px; padding: 3px 9px; border-radius: 999px;
  background: var(--bg); color: var(--dim); border: 1px solid var(--line);
}
.link { background: none; border: 0; color: var(--dim); font-size: 14px; padding: 8px; }

main { padding: 12px 12px 96px; max-width: 640px; margin: 0 auto; }

/* ── 알림 배너 ──────────────────────────────────────── */
.alerts { max-width: 640px; margin: 0 auto; padding: 0 12px; }
.alert {
  display: flex; align-items: center; gap: 10px; margin-top: 10px;
  padding: 12px 14px; border-radius: 12px; font-size: 15px;
  background: var(--fault); color: #fff;
}
.alert button {
  margin-left: auto; flex-shrink: 0; background: rgba(255,255,255,.22);
  border: 0; color: #fff; padding: 8px 14px; border-radius: 8px; font-size: 14px;
}

/* ── 수문 카드 ──────────────────────────────────────── */
.gate {
  background: var(--card); border: 1px solid var(--line); border-radius: 16px;
  padding: 16px; margin-bottom: 14px; box-shadow: var(--shadow);
}
.gate-head { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
.gate-name { font-size: 19px; font-weight: 700; }
.dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.dot.on { background: var(--ok); }
.dot.off { background: var(--dim); }

.state {
  margin-left: auto; font-size: 15px; font-weight: 700; padding: 5px 12px;
  border-radius: 999px; border: 2px solid currentColor;
}
.state.open   { color: var(--open); }
.state.closed { color: var(--closed); }
.state.moving { color: var(--moving); animation: pulse 1.1s ease-in-out infinite; }
.state.fault  { color: var(--fault); }
.state.unknown{ color: var(--dim); }
@keyframes pulse { 50% { opacity: .35; } }

.meta { font-size: 13px; color: var(--dim); min-height: 20px; }

/* 개폐 정도 막대 */
.bar { height: 8px; border-radius: 999px; background: var(--bg); margin: 12px 0; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--open); transition: width .4s; }

.controls { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.btn {
  height: 64px; border: 0; border-radius: 14px; font-size: 19px; font-weight: 700;
  color: #fff; background: var(--closed);
}
.btn:disabled { opacity: .35; }
.btn.open   { background: var(--open); }
.btn.close  { background: var(--closed); }
.btn.stop   { grid-column: 1 / -1; background: var(--fault); height: 56px; }
.btn.primary{ width: 100%; background: var(--open); height: 56px; }
.btn.ghost {
  background: transparent; color: var(--text);
  border: 1px solid var(--line); height: 48px; font-size: 16px;
}

/* ── 목록 · 폼 ──────────────────────────────────────── */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  padding: 14px; margin-bottom: 12px; box-shadow: var(--shadow);
}
.row { display: flex; align-items: center; gap: 10px; }
.row + .row { margin-top: 10px; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--dim); font-size: 13px; }
h2 { font-size: 16px; margin: 20px 4px 10px; color: var(--dim); }
h2:first-child { margin-top: 4px; }

select, input[type=text], input[type=time], input[type=date],
input[type=password], input[type=number], input[type=datetime-local] {
  height: 48px; padding: 0 12px; font-size: 16px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--bg); color: var(--text);
}
label.field { display: block; margin-bottom: 10px; }
label.field > span { display: block; font-size: 13px; color: var(--dim); margin-bottom: 4px; }
label.field > select, label.field > input { width: 100%; }

.days { display: flex; gap: 6px; }
.days label {
  flex: 1; text-align: center; padding: 10px 0; border-radius: 10px;
  border: 1px solid var(--line); font-size: 14px;
}
.days input { display: none; }
.days input:checked + span { color: var(--open); font-weight: 700; }

.del { background: none; border: 0; color: var(--fault); font-size: 14px; padding: 8px; }

/* ── 기록 ───────────────────────────────────────────── */
.summary { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 14px; }
.summary div { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 6px; text-align: center; }
.summary b { display: block; font-size: 20px; }
.summary small { color: var(--dim); font-size: 12px; }

.evt { display: flex; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.evt:last-child { border-bottom: 0; }
.evt time { color: var(--dim); flex-shrink: 0; font-variant-numeric: tabular-nums; }
.evt .who2 { color: var(--dim); margin-left: auto; flex-shrink: 0; }
.evt.error { color: var(--fault); }

/* ── 하단 탭 ────────────────────────────────────────── */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbtn {
  background: none; border: 0; color: var(--dim);
  padding: 9px 0 11px; font-size: 12px; display: grid; gap: 2px; justify-items: center;
}
.tabbtn span { font-size: 21px; }
.tabbtn.active { color: var(--open); font-weight: 700; }

/* ── 토스트 ─────────────────────────────────────────── */
.toast {
  position: fixed; left: 50%; bottom: 88px; transform: translateX(-50%);
  z-index: 20; max-width: 90%; padding: 13px 18px; border-radius: 12px;
  background: var(--text); color: var(--bg); font-size: 15px; text-align: center;
  box-shadow: 0 6px 20px rgba(0,0,0,.3);
}
