:root {
  --bg: #f5f6f8; --card: #ffffff; --text: #1d2126; --muted: #6b7280; --line: #e3e6ea;
  --accent: #2563eb; --accent-text: #ffffff; --ok: #16a34a; --warn: #d97706; --bad: #dc2626;
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171c; --card: #1e2229; --text: #e6e8eb; --muted: #9aa3ad; --line: #2c323b;
    --accent: #3b82f6;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
.hidden { display: none !important; }

.topbar { display: flex; align-items: center; justify-content: space-between; padding: 14px 20px; background: var(--card); border-bottom: 1px solid var(--line); }
.brand { font-weight: 700; font-size: 18px; }
.brand .sub { font-weight: 400; color: var(--muted); font-size: 13px; margin-left: 8px; }
.topright { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; justify-content: flex-end; }
.conn { font-size: 13px; padding: 4px 10px; border-radius: 999px; border: 1px solid var(--line); }
.conn-ok { color: var(--ok); border-color: var(--ok); }
.conn-bad { color: var(--bad); border-color: var(--bad); }
.conn-warn { color: var(--warn); border-color: var(--warn); }
.conn.clickable { cursor: pointer; }
.conn.clickable:hover { background: var(--bg); }
.conn-unknown { color: var(--muted); }

.tabs { display: flex; gap: 4px; padding: 10px 20px 0; background: var(--card); border-bottom: 1px solid var(--line); }
.tabs button { background: none; border: none; border-bottom: 2px solid transparent; padding: 8px 12px; font: inherit; color: var(--muted); cursor: pointer; }
.tabs button.active { color: var(--accent); border-bottom-color: var(--accent); }

main { max-width: 1000px; margin: 0 auto; padding: 20px 16px; }
.tab { display: none; }
.tab.active { display: block; }
.toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.hint { color: var(--muted); font-size: 13px; }
.empty { color: var(--muted); text-align: center; padding: 40px 0; }

button { font: inherit; padding: 7px 14px; border-radius: 8px; border: 1px solid var(--line); background: var(--card); color: var(--text); cursor: pointer; }
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
button.danger { color: var(--bad); }
button:disabled { opacity: .5; cursor: default; }
input, select { font: inherit; padding: 7px 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); color: var(--text); width: 100%; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.cards.profiles { grid-template-columns: repeat(auto-fill, minmax(440px, 1fr)); }
.cards.filters { grid-template-columns: repeat(auto-fill, minmax(380px, 1fr)); }
@media (max-width: 960px) { .cards.profiles, .cards.filters { grid-template-columns: 1fr; } }

/* profile card */
.card.profile .sched2 { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 14px; margin: 4px 0 12px; font-size: 13px; }
.card.profile .sched2 b { display: block; color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.card.profile .sched2 em { color: var(--warn); font-style: normal; font-size: 12px; }
.toggles { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 14px; margin-bottom: 12px; }
.switch { display: flex; align-items: center; gap: 8px; font-size: 13px; cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .track { width: 34px; height: 20px; border-radius: 999px; background: var(--line); position: relative; transition: background .15s; flex: none; }
.switch .track::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: var(--card); box-shadow: 0 1px 2px rgba(0,0,0,.3); transition: left .15s; }
.switch input:checked + .track { background: var(--bad); }
.switch input:checked + .track::after { left: 16px; }
.switch input:disabled + .track { opacity: .5; }
.switch input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }
.card.profile .devs span small { margin-left: 6px; color: var(--muted); }
.card.profile .meta { display: flex; gap: 16px; font-size: 13px; color: var(--muted); margin-bottom: 10px; flex-wrap: wrap; }
.card.profile .meta b { color: var(--text); font-weight: 600; }

/* schedule editor */
.form.wide { max-width: 680px; }
.form .row.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form .row.two label { display: flex; }
.sched-group { border-bottom: 1px solid var(--line); padding: 8px 0; }
.sched-group:last-child { border-bottom: none; }
.sg-head { display: flex; align-items: center; gap: 12px; margin-bottom: 6px; }
.sg-head .dn { font-weight: 600; width: 90px; }
.sg-head select { width: auto; }
.sched-group .windows { display: flex; flex-direction: column; gap: 6px; margin: 4px 0 6px 102px; }
.win { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.win input[type=time] { width: 120px; }
.win .rm { padding: 2px 8px; line-height: 1; }
.add-window { margin-left: 102px; font-size: 12px; padding: 4px 10px; }
button.small { font-size: 12px; padding: 4px 10px; }

/* filters */
.card.filter textarea { width: 100%; font: 13px/1.5 ui-monospace, Menlo, Consolas, monospace; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); color: var(--text); resize: vertical; }
.card.filter p.hint { margin: 0 0 8px; }
.card.filter h3 .badge { color: var(--muted); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.card h3 { margin: 0 0 6px; display: flex; align-items: center; justify-content: space-between; font-size: 17px; }
.badge { font-size: 12px; padding: 2px 8px; border-radius: 999px; border: 1px solid currentColor; }
.badge.paused { color: var(--bad); }
.badge.active { color: var(--ok); }
.badge.blocked { color: var(--warn); }
.card .sched { font-size: 13px; color: var(--muted); margin: 6px 0 10px; display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.card .sched div { text-align: center; }
.card .sched b { display: block; color: var(--text); }
.card .devs { font-size: 13px; margin-bottom: 10px; }
.card .devs span { display: inline-block; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 2px 8px; margin: 2px 4px 2px 0; }
.card .actions { display: flex; gap: 8px; flex-wrap: wrap; }

table.grid { width: 100%; border-collapse: collapse; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
table.grid th, table.grid td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); font-size: 14px; }
table.grid th { color: var(--muted); font-weight: 600; font-size: 13px; }
table.grid tr:last-child td { border-bottom: none; }
.mono { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; }
.st-ok { color: var(--ok); } .st-bad { color: var(--bad); } .st-muted { color: var(--muted); }

.form { display: flex; flex-direction: column; gap: 12px; max-width: 560px; }
.form label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.form .row { display: flex; gap: 10px; align-items: center; }
.form .row.small button { font-size: 12px; padding: 4px 10px; }
.msg { font-size: 13px; }
.msg.ok { color: var(--ok); } .msg.bad { color: var(--bad); }

dialog { border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); color: var(--text); padding: 20px 22px; width: min(600px, 92vw); }
dialog::backdrop { background: rgba(0,0,0,.45); }
dialog h2 { margin: 0 0 6px; font-size: 18px; }
fieldset.days { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; }
fieldset.days legend { font-size: 13px; color: var(--muted); padding: 0 6px; }

/* ---- dashboard ---- */
:root {
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100; --s5: #e87ba4; --s6: #008300; --s-other: #9aa3ad;
}
@media (prefers-color-scheme: dark) {
  :root { --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181; --s6: #008300; --s-other: #6b7280; }
}
.notice { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 14px; margin-bottom: 14px; border-radius: 8px; border: 1px solid var(--warn); color: var(--text); background: color-mix(in srgb, var(--warn) 10%, var(--card)); font-size: 14px; }
.notice.bad { border-color: var(--bad); background: color-mix(in srgb, var(--bad) 10%, var(--card)); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: none; border-radius: 0; border-right: 1px solid var(--line); padding: 6px 12px; }
.seg button:last-child { border-right: none; }
.seg button.active { background: var(--accent); color: var(--accent-text); }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 14px; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.tile .tl { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.tile .tv { font-size: 22px; font-weight: 600; margin-top: 4px; font-variant-numeric: tabular-nums; }
.tile .tv small { font-size: 13px; font-weight: 400; color: var(--muted); }
.chart-card { margin-bottom: 14px; position: relative; }
.chart-head { display: flex; align-items: baseline; justify-content: space-between; flex-wrap: wrap; gap: 8px; margin-bottom: 6px; }
.chart-head h3 { margin: 0; font-size: 15px; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12px; color: var(--muted); }
.legend span::before { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; background: var(--c); }
.chart { width: 100%; height: 240px; }
.chart svg { width: 100%; height: 100%; display: block; }
.chart .grid-line { stroke: var(--line); stroke-width: 1; }
.chart .axis-text { fill: var(--muted); font-size: 11px; }
.chart rect.seg { stroke: var(--card); stroke-width: 1; }
.chart rect.hit { fill: transparent; cursor: crosshair; }
.chart rect.hit:hover { fill: color-mix(in srgb, var(--text) 6%, transparent); }
.tip { position: absolute; pointer-events: none; background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font-size: 12px; box-shadow: 0 4px 16px rgba(0,0,0,.18); min-width: 160px; z-index: 5; }
.tip b { display: block; margin-bottom: 4px; }
.tip div { display: flex; justify-content: space-between; gap: 12px; }
.tip div::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 5px; background: var(--c); flex: none; align-self: center; }
table.grid th.num, table.grid td.num { text-align: right; font-variant-numeric: tabular-nums; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: 0; background: var(--muted); }
.dot.on { background: var(--ok); }
.dot.blocked { background: var(--bad); }

/* sign in and users */
.auth { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.auth-card { width: min(400px, 100%); max-width: none; padding: 22px 24px; }
.auth-card h2 { margin: 4px 0 0; font-size: 18px; }
.auth-card p.hint { margin: 0; }
h2.section { font-size: 17px; margin: 28px 0 4px; }
#users-table { margin: 10px 0 14px; }
.cards.user-forms { margin-bottom: 8px; }
.card.form h3 { margin: 0; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 8px; font-size: 14px; box-shadow: 0 4px 16px rgba(0,0,0,.25); }
.toast.bad { background: var(--bad); color: #fff; }

@media (max-width: 640px) {
  .topbar { flex-direction: column; align-items: flex-start; gap: 8px; }
  .topright { justify-content: flex-start; }
  .form .row.two { grid-template-columns: 1fr; }
  .sched-group .windows, .add-window { margin-left: 0; }
  .toggles { grid-template-columns: 1fr; }
  table.grid th:nth-child(3), table.grid td:nth-child(3) { display: none; }
  #usage-table th:nth-child(2), #usage-table td:nth-child(2),
  #usage-table th:nth-child(5), #usage-table td:nth-child(5),
  #usage-table th:nth-child(7), #usage-table td:nth-child(7),
  #usage-table th:nth-child(8), #usage-table td:nth-child(8) { display: none; }
}
