:root {
  --bg: #f5f3ee;
  --card: #ffffff;
  --ink: #1d2322;
  --muted: #69716f;
  --line: #e2ded5;
  --brand: #1f5f5b;
  --brand-ink: #ffffff;
  --brand-soft: #e3efed;
  --ok: #2e7d4f;
  --warn: #b8741a;
  --danger: #b43c32;
  --danger-soft: #f8e6e3;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 14px rgba(0,0,0,.04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141817;
    --card: #1d2322;
    --ink: #eef1f0;
    --muted: #9aa4a1;
    --line: #2d3533;
    --brand: #5fb3aa;
    --brand-ink: #0d1413;
    --brand-soft: #1f3331;
    --ok: #5fc38a;
    --warn: #e0a24a;
    --danger: #ef7d72;
    --danger-soft: #3a2220;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
}
#app { max-width: 640px; margin: 0 auto; padding: 16px 16px 110px; }

h1 { font-size: 1.5rem; margin: 8px 0 18px; letter-spacing: -.01em; }
h2 { font-size: 1.05rem; margin: 26px 0 10px; }
h3 { font-size: .95rem; margin: 0 0 8px; }
p { margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
code, .mono { font-family: ui-monospace, "Cascadia Mono", Menlo, monospace; font-size: .9em; }

.topbar { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.topbar h1 { flex: 1; margin: 8px 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.iconbtn {
  border: 0; background: transparent; color: var(--ink); font-size: 1.4rem; line-height: 1;
  padding: 8px 10px; border-radius: 10px; cursor: pointer;
}
.iconbtn:hover { background: var(--brand-soft); }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin-bottom: 14px; box-shadow: var(--shadow);
}
a.card { display: block; color: inherit; text-decoration: none; }

.status-row { display: flex; align-items: center; gap: 8px; font-size: .85rem; color: var(--muted); }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.on { background: var(--ok); }
.dot.off { background: var(--danger); }

.big { font-size: 2rem; font-weight: 650; letter-spacing: -.02em; margin: 6px 0 2px; }
.big.locked { color: var(--danger); }
.bar { height: 8px; background: var(--brand-soft); border-radius: 99px; overflow: hidden; margin: 10px 0 4px; }
.bar > span { display: block; height: 100%; background: var(--brand); border-radius: 99px; transition: width .3s; }
.bar.full > span { background: var(--danger); }

.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
button, .btn {
  font: inherit; font-weight: 600; border-radius: 11px; border: 1px solid var(--line);
  background: var(--card); color: var(--ink); padding: 10px 14px; cursor: pointer; min-height: 44px;
}
button:disabled { opacity: .5; cursor: default; }
.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.ghost { background: transparent; }
.grow { flex: 1; }
.wide { width: 100%; }

.alert { border-radius: 11px; padding: 10px 12px; margin: 10px 0; font-size: .9rem; background: var(--danger-soft); color: var(--danger); }
.alert.info { background: var(--brand-soft); color: var(--ink); }

label.field { display: block; margin: 12px 0; font-size: .9rem; color: var(--muted); }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=time], select {
  font: inherit; color: var(--ink); background: var(--bg); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 12px; min-height: 44px; width: 100%; margin-top: 4px;
}
input[type=time] { width: auto; padding: 8px; }
input[type=number] { width: 90px; }

.tabs { display: flex; gap: 4px; overflow-x: auto; margin: 18px -16px 6px; padding: 0 16px; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button {
  border: 0; background: transparent; color: var(--muted); padding: 8px 12px; min-height: 38px;
  border-radius: 99px; white-space: nowrap; font-weight: 600;
}
.tabs button.active { background: var(--brand); color: var(--brand-ink); }

.day { padding: 12px 0; border-bottom: 1px solid var(--line); }
.day:last-child { border-bottom: 0; }
.day-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.day-head strong { min-width: 80px; }
.window { display: flex; align-items: center; gap: 6px; margin: 6px 0; flex-wrap: wrap; }
.window .iconbtn { font-size: 1.1rem; color: var(--muted); }
.quota { display: flex; align-items: center; gap: 8px; font-size: .9rem; color: var(--muted); }
.quota select { width: auto; margin: 0; }

.toggle { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.toggle:last-child { border-bottom: 0; }
.toggle small { display: block; color: var(--muted); }
.switch { position: relative; width: 48px; height: 28px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; background: var(--line); border-radius: 99px; transition: .2s; }
.switch span::after { content: ""; position: absolute; width: 22px; height: 22px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.switch input:checked + span { background: var(--brand); }
.switch input:checked + span::after { transform: translateX(20px); }
.switch input:focus-visible + span { outline: 2px solid var(--brand); outline-offset: 2px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; background: var(--brand-soft); border-radius: 99px;
  padding: 6px 6px 6px 12px; font-size: .9rem; border: 0; min-height: 34px;
}
.chip button { min-height: 0; padding: 0 6px; border: 0; background: transparent; color: var(--muted); font-size: 1rem; }
.chip.suggest { background: transparent; border: 1px dashed var(--line); padding: 6px 12px; color: var(--muted); font-weight: 500; cursor: pointer; }
.chip.on { background: var(--brand); color: var(--brand-ink); }
.addrow { display: flex; gap: 8px; margin-top: 10px; }
.addrow input { margin: 0; }

.history { display: flex; align-items: flex-end; gap: 4px; height: 140px; margin: 10px 0 4px; }
.history div { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; height: 100%; }
.history i { display: block; width: 100%; background: var(--brand); border-radius: 5px 5px 2px 2px; min-height: 2px; }
.history i.today { background: var(--warn); }
.history-labels { display: flex; gap: 4px; font-size: .7rem; color: var(--muted); }
.history-labels span { flex: 1; text-align: center; }

.event { display: flex; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: .9rem; }
.event:last-child { border-bottom: 0; }
.event time { color: var(--muted); flex: none; width: 88px; font-size: .8rem; padding-top: 2px; }

.paircode { font: 700 2rem/1.2 ui-monospace, Menlo, monospace; letter-spacing: .15em; text-align: center; padding: 14px; background: var(--brand-soft); border-radius: 12px; margin: 10px 0; user-select: all; }
pre { background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px; overflow-x: auto; font-size: .8rem; white-space: pre-wrap; word-break: break-all; }

.savebar {
  position: fixed; left: 0; right: 0; bottom: 0; padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: var(--card); border-top: 1px solid var(--line); display: flex; justify-content: center; gap: 8px;
  transform: translateY(110%); transition: transform .2s;
}
.savebar.show { transform: none; }
.savebar > div { max-width: 608px; width: 100%; display: flex; gap: 8px; }

#toast {
  position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%) translateY(20px); opacity: 0;
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: .9rem;
  transition: .2s; pointer-events: none; max-width: calc(100% - 32px);
}
#toast.show { opacity: 1; transform: translateX(-50%); }

.login { max-width: 380px; margin: 12vh auto 0; }
.logo { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; }
.logo img { width: 48px; height: 48px; border-radius: 12px; }
.logo strong { font-size: 1.4rem; }
.empty { text-align: center; padding: 30px 10px; }

dialog { border: 0; border-radius: var(--radius); padding: 20px; background: var(--card); color: var(--ink); width: min(92vw, 420px); }
dialog::backdrop { background: rgba(0,0,0,.4); }
.menu button { display: block; width: 100%; text-align: left; margin-bottom: 8px; }
