/* 上網時間管理（手機版）— 桌面版配色：活動綠／待命藍／離線灰／斷網紅 */
:root {
  --bg: #f3f5f8;
  --card: #ffffff;
  --text: #1d2430;
  --muted: #5f6b7a;
  --line: #dde2e8;
  --brand: #1f3a5f;
  --brand-2: #2d6cdf;
  --on: #2e9e4f;
  --idle: #2d6cdf;
  --off: #8a939e;
  --cut: #c0392b;
  --warn: #d9822b;
  --btn: #eef1f5;
  --btn-text: #1d2430;
  --shadow: 0 1px 3px rgba(0, 0, 0, .08);
  --zoom: 1.15;
  --tab-h: 64px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12161c;
    --card: #1b2129;
    --text: #e6eaef;
    --muted: #9aa5b2;
    --line: #2c343e;
    --brand: #8fb4ff;
    --brand-2: #6f9dff;
    --on: #4cc06f;
    --idle: #6f9dff;
    --off: #7d8794;
    --cut: #ff6b5b;
    --warn: #f0a050;
    --btn: #262e38;
    --btn-text: #e6eaef;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  --bg: #12161c; --card: #1b2129; --text: #e6eaef; --muted: #9aa5b2; --line: #2c343e;
  --brand: #8fb4ff; --brand-2: #6f9dff; --on: #4cc06f; --idle: #6f9dff; --off: #7d8794;
  --cut: #ff6b5b; --warn: #f0a050; --btn: #262e38; --btn-text: #e6eaef; --shadow: none;
}

* { box-sizing: border-box; }
html { font-size: calc(16px * var(--zoom)); -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Microsoft JhengHei UI", "PingFang TC", "Noto Sans TC", system-ui, sans-serif;
  line-height: 1.45;
}
[hidden] { display: none !important; }
h1 { font-size: 1.15rem; margin: 0; }
h2 { font-size: 1.05rem; margin: 0 0 .25rem; }
h3 { font-size: 1rem; margin: 0 0 .6rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.pre { white-space: pre-line; }
.msg { white-space: pre-line; min-height: 1.3em; margin: .6rem 0 0; color: var(--muted); }
.msg.err { color: var(--cut); }
.row { display: flex; align-items: center; }
.gap { gap: .5rem; }
.wrap { flex-wrap: wrap; }

/* ---------- 按鈕 ---------- */
.btn {
  appearance: none; border: 1px solid var(--line); background: var(--btn); color: var(--btn-text);
  border-radius: 10px; padding: .6rem .9rem; font: inherit; min-height: 44px; cursor: pointer;
}
.btn:active { filter: brightness(.94); }
.btn.primary { background: var(--brand-2); border-color: var(--brand-2); color: #fff; }
.btn.danger { color: var(--cut); }
.btn.big { width: 100%; font-size: 1.05rem; min-height: 50px; }
.btn.wide { width: 100%; margin-top: .7rem; }
.btn:disabled { opacity: .5; }
.icon-btn {
  appearance: none; border: 0; background: transparent; color: inherit; font-size: 1.3rem;
  min-width: 44px; min-height: 44px; cursor: pointer; border-radius: 10px;
}

/* ---------- 登入 ---------- */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card {
  background: var(--card); border-radius: 16px; padding: 1.6rem 1.3rem; width: 100%; max-width: 380px;
  box-shadow: var(--shadow); text-align: center;
}
.login-logo { width: 72px; height: 72px; border-radius: 16px; }
.login-card h1 { margin-top: .5rem; font-size: 1.3rem; }
.login-card form { text-align: left; margin-top: 1rem; }
label { display: block; margin-bottom: .8rem; }
input[type=password], input[type=text], input[type=time], select {
  display: block; width: 100%; margin-top: .3rem; padding: .65rem .7rem; font: inherit;
  border: 1px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--text);
  min-height: 46px;
}
#in-code { letter-spacing: .4em; font-size: 1.3rem; text-align: center; }

/* ---------- PIN ---------- */
.pin-dots { display: flex; justify-content: center; gap: .7rem; margin: 1.2rem 0 .4rem; min-height: 22px; }
.pin-dots i { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--brand-2); }
.pin-dots i.on { background: var(--brand-2); }
.pin-pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: .6rem; margin-top: .6rem; }
.pin-pad button {
  appearance: none; border: 1px solid var(--line); background: var(--btn); color: var(--btn-text);
  border-radius: 14px; font: inherit; font-size: 1.5rem; min-height: 64px; cursor: pointer;
}
.pin-pad button:active { filter: brightness(.9); }
.pin-pad button.ok { background: var(--brand-2); border-color: var(--brand-2); color: #fff; }
.link-btn {
  appearance: none; border: 0; background: transparent; color: var(--brand-2); font: inherit;
  font-size: .9rem; margin-top: 1rem; min-height: 44px; cursor: pointer; text-decoration: underline;
}
label.inline { margin: .8rem 0 0; }
label.inline select { margin-top: .3rem; }
.pin-in { letter-spacing: .4em; font-size: 1.3rem; text-align: center; }

/* ---------- 頂部 ---------- */
.top {
  position: sticky; top: 0; z-index: 5; background: var(--brand); color: #fff;
  padding: calc(env(safe-area-inset-top) + .4rem) 16px .5rem;
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .top { background: #1b2a40; } }
.top-row { display: flex; align-items: center; justify-content: space-between; }
.engine {
  appearance: none; border: 0; background: rgba(255, 255, 255, .14); color: #fff; font: inherit;
  font-size: .9rem; width: 100%; text-align: left; border-radius: 8px; padding: .4rem .6rem; margin-top: .2rem;
}
.engine .dot { font-weight: bold; }

main { padding: 12px 16px calc(var(--tab-h) + env(safe-area-inset-bottom) + 16px); max-width: 760px; margin: 0 auto; }
.page-head { margin-bottom: .7rem; }
.legend { display: flex; flex-wrap: wrap; gap: .2rem .8rem; font-size: .85rem; color: var(--muted); }
.legend b { font-weight: normal; }

/* ---------- 清單卡片 ---------- */
.list { display: flex; flex-direction: column; gap: .55rem; }
.item {
  background: var(--card); border-radius: 12px; padding: .7rem .8rem; box-shadow: var(--shadow);
  border-left: 5px solid var(--off); display: block; width: 100%; text-align: left;
  font: inherit; color: inherit; border-top: 0; border-right: 0; border-bottom: 0; cursor: pointer;
}
.item.act_on { border-left-color: var(--on); }
.item.act_idle { border-left-color: var(--idle); }
.item.offline { border-left-color: var(--off); }
.item.cut_now { border-left-color: var(--cut); }
.item .name { font-weight: bold; font-size: 1.02rem; overflow-wrap: anywhere; }
.item .meta { color: var(--muted); font-size: .85rem; overflow-wrap: anywhere; }
.item .line1 { display: flex; justify-content: space-between; gap: .5rem; align-items: baseline; }
.pill { white-space: nowrap; font-size: .85rem; }
.c-act_on { color: var(--on); } .c-act_idle { color: var(--idle); }
.c-offline { color: var(--off); } .c-cut_now { color: var(--cut); } .c-warn { color: var(--warn); }
.tag { display: inline-block; font-size: .78rem; padding: 0 .4rem; border-radius: 6px; background: var(--btn); margin-left: .3rem; }
.empty { color: var(--muted); text-align: center; padding: 1.5rem 0; }

/* 出沒紀錄的 24 小時橫槓 */
.tl { position: relative; height: 12px; background: var(--btn); border-radius: 6px; margin-top: .45rem; overflow: hidden; }
.tl i { position: absolute; top: 0; bottom: 0; background: var(--on); }
.tl-ticks { display: flex; justify-content: space-between; font-size: .7rem; color: var(--muted); }

/* ---------- 時段 ---------- */
.state { font-weight: bold; }
.state.on { color: var(--cut); } .state.off { color: var(--on); }
.card { background: var(--card); border-radius: 12px; padding: .9rem; box-shadow: var(--shadow); margin-bottom: .8rem; }
.time-row { display: flex; gap: .8rem; }
.time-row label { flex: 1; }
.label { margin: .6rem 0 .4rem; }
.days { display: grid; grid-template-columns: repeat(7, 1fr); gap: .35rem; }
.day {
  appearance: none; border: 2px solid var(--line); background: var(--bg); color: var(--text);
  border-radius: 10px; min-height: 48px; font: inherit; font-weight: bold; cursor: pointer;
}
.day.on { border-color: var(--brand-2); background: var(--brand-2); color: #fff; }

/* ---------- 更多 ---------- */
.seg { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .3rem; margin-bottom: .8rem; }
.seg button {
  appearance: none; border: 1px solid var(--line); background: var(--card); line-height: 1.25;
  color: var(--text); border-radius: 10px; padding: .45rem .25rem; font: inherit; font-size: .88rem;
  min-height: 48px; cursor: pointer; overflow-wrap: anywhere;
}
.seg button.on { background: var(--brand-2); border-color: var(--brand-2); color: #fff; }
.chk { display: flex; align-items: center; gap: .3rem; margin: 0; }
.sub .row select { width: auto; margin: 0; }
.logs {
  white-space: pre-wrap; word-break: break-all; font-family: Consolas, ui-monospace, monospace;
  font-size: .78rem; background: var(--bg); padding: .6rem; border-radius: 8px; max-height: 50vh; overflow: auto;
}
.progress { height: 8px; background: var(--btn); border-radius: 4px; margin-top: .7rem; overflow: hidden; }
.progress .bar { height: 100%; width: 0; background: var(--brand-2); transition: width .3s; }

/* ---------- 底部分頁 ---------- */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; display: flex; background: var(--card);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
.tabs button {
  appearance: none; flex: 1; border: 0; background: transparent; color: var(--muted); font: inherit;
  font-size: .78rem; min-height: var(--tab-h); display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 2px; cursor: pointer;
}
.tabs button span { font-size: 1.25rem; line-height: 1; }
.tabs button.on { color: var(--brand-2); font-weight: bold; }

/* ---------- 底部選單 ---------- */
.sheet-bg { position: fixed; inset: 0; background: rgba(0, 0, 0, .4); z-index: 20; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21; background: var(--card);
  border-radius: 16px 16px 0 0; padding: .8rem 16px calc(env(safe-area-inset-bottom) + 1rem);
  max-height: 85vh; overflow-y: auto; max-width: 760px; margin: 0 auto;
}
.sheet-head { display: flex; justify-content: space-between; align-items: flex-start; gap: .5rem; margin-bottom: .5rem; }
.sheet-title { font-weight: bold; font-size: 1.05rem; overflow-wrap: anywhere; }
.sheet .act {
  appearance: none; display: block; width: 100%; text-align: left; border: 0; border-top: 1px solid var(--line);
  background: transparent; color: var(--text); font: inherit; padding: .85rem .2rem; min-height: 50px; cursor: pointer;
}
.sheet .act.danger { color: var(--cut); }
.sheet .act:active { background: var(--btn); }
.sheet .sec { font-size: .8rem; color: var(--muted); margin: .7rem 0 .2rem; }
.sheet .risk { border-top: 1px solid var(--line); padding: .55rem 0; }
.sheet .risk .lv-high { color: var(--cut); font-weight: bold; }
.sheet .risk .lv-medium { color: var(--warn); font-weight: bold; }
.sheet .risk .lv-info { color: var(--muted); }

.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 12px);
  z-index: 30; background: #263445; color: #fff; padding: .75rem 1rem; border-radius: 12px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .25); max-width: 560px; margin: 0 auto;
}
.toast.err { background: #8e2b20; }
