:root {
  --bg: #1e1f22;
  --bg-2: #232428;
  --surface: #2b2d31;
  --surface-2: #313338;
  --surface-3: #383a40;
  --border: #3f4147;
  --text: #f2f3f5;
  --text-2: #dbdee1;
  --muted: #a4a8b0;
  --faint: #80848e;
  --accent: #5865f2;
  --accent-hover: #4752c4;
  --green: #23a55a;
  --red: #f23f43;
  --yellow: #f0b232;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 8px 24px rgba(0, 0, 0, .35);
  --font: "Segoe UI", "Hiragino Sans", "Yu Gothic UI", "Meiryo", "Noto Sans JP", system-ui, sans-serif;
  --mono: "Cascadia Code", "Consolas", ui-monospace, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text-2);
  font: 14px/1.55 var(--font);
  -webkit-font-smoothing: antialiased;
}
a { color: #00a8fc; text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { color: var(--text); margin: 0; line-height: 1.3; }
h2 { font-size: 16px; font-weight: 700; }
h3 { font-size: 14px; font-weight: 700; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 12px; }
[hidden] { display: none !important; }

/* ---------- ボタン・入力 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; padding: 0 14px; border: 0; border-radius: var(--radius-sm);
  background: var(--surface-3); color: var(--text); font: inherit; font-weight: 600;
  cursor: pointer; white-space: nowrap; transition: background .12s, opacity .12s;
  text-decoration: none !important;
}
.btn:hover { background: #45474e; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-success { background: var(--green); color: #fff; }
.btn-success:hover { background: #1a8a4a; }
.btn-danger { background: transparent; color: var(--red); box-shadow: inset 0 0 0 1px rgba(242, 63, 67, .5); }
.btn-danger:hover { background: var(--red); color: #fff; }
.btn-ghost { background: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-3); }
.btn-sm { height: 28px; padding: 0 10px; font-size: 12.5px; }
.btn-lg { height: 46px; padding: 0 22px; font-size: 15px; width: 100%; }
.icon-btn {
  display: inline-grid; place-items: center; width: 32px; height: 32px; border: 0; border-radius: var(--radius-sm);
  background: transparent; color: var(--text-2); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-3); color: var(--text); }

input, select, textarea {
  width: 100%; min-height: 36px; padding: 7px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--bg); color: var(--text); font: inherit; outline: none;
}
textarea { resize: vertical; min-height: 70px; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(88, 101, 242, .25); }
input[type="checkbox"] { width: auto; min-height: 0; accent-color: var(--accent); }
input.invalid { border-color: var(--red); }

label.field { display: block; }
.field-label { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 5px; color: var(--muted); font-size: 12px; font-weight: 700; letter-spacing: .02em; }
.field-hint { margin-top: 4px; color: var(--faint); font-size: 12px; }
.counter { font-weight: 500; color: var(--faint); }
.counter.over { color: var(--red); }

.switch { position: relative; display: inline-block; width: 40px; height: 24px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; border-radius: 99px; background: #4e5058; transition: .15s; cursor: pointer; }
.switch span::before { content: ""; position: absolute; left: 3px; top: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: .15s; }
.switch input:checked + span { background: var(--green); }
.switch input:checked + span::before { transform: translateX(16px); }
.switch input:disabled + span { opacity: .5; cursor: not-allowed; }

/* ---------- レイアウト ---------- */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; display: flex; flex-direction: column; width: 232px; flex: none;
  height: 100vh; height: 100dvh;
  background: var(--bg-2); border-right: 1px solid #1a1b1e;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 16px 16px 14px; }
.brand-name { color: var(--text); font-weight: 800; font-size: 15px; }
.brand-sub { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); flex: none; }
.dot.on { background: var(--green); box-shadow: 0 0 0 3px rgba(35, 165, 90, .2); }
.dot.off { background: var(--red); }

/* ---------- アイコン ---------- */
.ic { flex: none; }
.chip .ic, .badge .ic { margin-right: -2px; }
.nav { display: flex; flex-direction: column; gap: 2px; padding: 6px 8px; flex: 1; overflow-y: auto; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: var(--radius-sm);
  color: var(--muted); font-weight: 600; text-decoration: none;
}
.nav a:hover { background: var(--surface-2); color: var(--text-2); }
.nav a.active { background: var(--surface-3); color: var(--text); }
.nav-ico { display: inline-flex; align-items: center; justify-content: center; width: 20px; flex: none; }
.me { display: flex; align-items: center; gap: 10px; padding: 10px 12px; padding-bottom: max(10px, env(safe-area-inset-bottom)); background: #1b1c1f; flex: none; }
.me img { width: 32px; height: 32px; border-radius: 50%; }
.me-name { flex: 1; min-width: 0; color: var(--text); font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 10px; height: 56px; padding: 0 24px;
  background: rgba(30, 31, 34, .9); backdrop-filter: blur(8px); border-bottom: 1px solid #1a1b1e;
}
.topbar h1 { font-size: 17px; flex: 1; }
.topbar-actions { display: flex; gap: 8px; }
#menu-btn { display: none; }
.banner { padding: 10px 24px; background: rgba(240, 178, 50, .12); color: var(--yellow); border-bottom: 1px solid rgba(240, 178, 50, .25); font-weight: 600; }
.banner-info { background: rgba(88, 101, 242, .12); color: #b3b9ff; border-bottom-color: rgba(88, 101, 242, .25); }
.view { padding: 24px; max-width: 1280px; width: 100%; }
.backdrop { display: none; }

@media (max-width: 860px) {
  .sidebar { position: fixed; left: 0; z-index: 30; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; box-shadow: var(--shadow); }
  .backdrop.open { display: block; position: fixed; inset: 0; z-index: 20; background: rgba(0, 0, 0, .5); }
  #menu-btn { display: inline-grid; }
  .topbar { padding: 0 12px; }
  .view { padding: 16px 12px; }
  .banner { padding: 10px 12px; }
}

/* ---------- 汎用パーツ ---------- */
.card { background: var(--surface); border: 1px solid #26282c; border-radius: var(--radius); }
.card-pad { padding: 16px; }
.section { margin-bottom: 28px; }
.section-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.section-head h2 { flex: 1; }
.row { display: flex; align-items: center; gap: 8px; }
.row-wrap { display: flex; flex-wrap: wrap; gap: 8px; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.grow { flex: 1; min-width: 0; }
.grid { display: grid; gap: 12px; }
.grid-stats { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
.grid-cards { grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (max-width: 640px) { .grid-2 { grid-template-columns: 1fr; } }
.badge {
  display: inline-flex; align-items: center; gap: 4px; height: 20px; padding: 0 7px; border-radius: 99px;
  background: var(--surface-3); color: var(--text-2); font-size: 11.5px; font-weight: 700; white-space: nowrap;
}
.badge-green { background: rgba(35, 165, 90, .18); color: #4ad487; }
.badge-red { background: rgba(242, 63, 67, .16); color: #ff7b7e; }
.badge-yellow { background: rgba(240, 178, 50, .16); color: var(--yellow); }
.badge-blue { background: rgba(88, 101, 242, .2); color: #9aa3ff; }
.empty { padding: 36px 16px; text-align: center; color: var(--muted); }
.empty-ico { display: flex; justify-content: center; margin-bottom: 8px; color: var(--faint); }
.divider { height: 1px; background: var(--border); margin: 16px 0; }
.alert { padding: 10px 12px; border-radius: var(--radius-sm); font-weight: 600; }
.alert-error { background: rgba(242, 63, 67, .12); color: #ff8a8d; border: 1px solid rgba(242, 63, 67, .3); }
.alert-info { background: rgba(88, 101, 242, .12); color: #b3b9ff; border: 1px solid rgba(88, 101, 242, .3); }
.search { position: relative; }
.search input { padding-left: 32px; }
.search::before {
  content: ""; position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
  width: 14px; height: 14px; background: currentColor; color: var(--faint); opacity: .8;
  -webkit-mask: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="black" stroke-width="2" stroke-linecap="round"><circle cx="10.5" cy="10.5" r="6.5"/><path d="m20 20-4.8-4.8"/></svg>') center/contain no-repeat;
  mask: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="black" stroke-width="2" stroke-linecap="round"><circle cx="10.5" cy="10.5" r="6.5"/><path d="m20 20-4.8-4.8"/></svg>') center/contain no-repeat;
}
.chip {
  display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 12px; border: 1px solid var(--border);
  border-radius: 99px; background: var(--surface-2); color: var(--text-2); font: inherit; font-weight: 600; cursor: pointer;
}
.chip:hover { border-color: #5b5e66; color: var(--text); }
.chip.on { border-color: var(--green); background: rgba(35, 165, 90, .12); color: #6fe3a2; }
.chip:disabled { opacity: .45; cursor: not-allowed; }

.offline [data-needs-bot], .viewer-mode [data-needs-bot] { opacity: .45; pointer-events: none; }
/* Botが不要な(常時押せる)導線でも、権限が無いなら他のボタン同様グレーアウトする */
.viewer-mode [data-toggle-action]:not([data-needs-bot]),
.viewer-mode [data-edit-action]:not([data-needs-bot]),
.viewer-mode [data-delete-action]:not([data-needs-bot]),
.viewer-mode [data-timer-action]:not([data-needs-bot]) { opacity: .45; pointer-events: none; }
.viewer-mode.can-toggle [data-toggle-action],
.viewer-mode.can-edit [data-edit-action],
.viewer-mode.can-delete [data-delete-action],
.viewer-mode.can-timer [data-timer-action] { opacity: 1; pointer-events: auto; }
.viewer-mode.can-edit.can-toggle [data-edit-and-toggle-action] { opacity: 1; pointer-events: auto; }
/* Botオフライン時は権限があっても常にブロックする (Botを必要とする要素のみ対象、詳細度を上げて確実に勝たせる) */
.offline.can-toggle [data-toggle-action][data-needs-bot],
.offline.can-edit [data-edit-action][data-needs-bot],
.offline.can-delete [data-delete-action][data-needs-bot],
.offline.can-timer [data-timer-action][data-needs-bot],
.offline.can-edit.can-toggle [data-edit-and-toggle-action][data-needs-bot] { opacity: .45; pointer-events: none; }

/* ---------- 統計 ---------- */
.stat { padding: 14px 16px; }
.stat-top { display: flex; justify-content: space-between; align-items: baseline; }
.stat-label { color: var(--muted); font-size: 12px; font-weight: 700; }
.stat-value { color: var(--text); font-size: 24px; font-weight: 800; font-variant-numeric: tabular-nums; }
.stat-sub { color: var(--faint); font-size: 12px; font-variant-numeric: tabular-nums; }
.meter { height: 6px; margin-top: 10px; border-radius: 99px; background: var(--bg); overflow: hidden; }
.meter > span { display: block; height: 100%; border-radius: inherit; background: var(--accent); transition: width .4s; }
.meter > span.warn { background: var(--yellow); }
.meter > span.crit { background: var(--red); }
.spark { display: block; width: 100%; height: 34px; margin-top: 8px; }
.spark path.line { fill: none; stroke: var(--accent); stroke-width: 1.6; }
.spark path.area { fill: rgba(88, 101, 242, .15); stroke: none; }

/* ---------- Discord風プレビュー ---------- */
.presence {
  padding: 12px; border-radius: 8px; background: #111214; color: #dbdee1; font-size: 13px;
}
.presence-head { margin-bottom: 8px; color: #b5bac1; font-size: 12px; font-weight: 700; }
.presence-body { display: flex; gap: 12px; align-items: center; }
.presence-art { position: relative; width: 72px; height: 72px; flex: none; }
.presence-art .large { width: 72px; height: 72px; border-radius: 8px; object-fit: cover; background: #2b2d31; }
.presence-art .small {
  position: absolute; right: -6px; bottom: -6px; width: 26px; height: 26px; border-radius: 50%;
  object-fit: cover; background: #2b2d31; border: 3px solid #111214;
}
.presence-art .ph { display: grid; place-items: center; color: #6d6f78; font-size: 11px; text-align: center; overflow: hidden; word-break: break-all; padding: 4px; }
.presence-text { min-width: 0; flex: 1; }
.presence-text div { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.presence-name { color: #f2f3f5; font-weight: 700; }
.presence-time { color: #3ba55c; font-variant-numeric: tabular-nums; font-size: 12px; margin-top: 1px; }
.presence-buttons { display: grid; gap: 6px; margin-top: 10px; }
.presence-buttons span {
  display: block; padding: 6px 8px; border-radius: 4px; background: #4e5058; color: #fff; text-align: center;
  font-weight: 600; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* ---------- ステータスカード ---------- */
.scard { display: flex; flex-direction: column; overflow: hidden; }
.scard.active { border-color: rgba(35, 165, 90, .55); box-shadow: 0 0 0 1px rgba(35, 165, 90, .25); }
.scard-body { display: flex; gap: 12px; padding: 14px; }
.scard-thumb { width: 56px; height: 56px; flex: none; border-radius: 8px; object-fit: cover; background: var(--surface-3); }
.scard-thumb.ph { display: grid; place-items: center; font-size: 22px; }
.scard-title { color: var(--text); font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.scard-sub { color: var(--muted); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.scard-foot { display: flex; align-items: center; gap: 6px; margin-top: auto; padding: 10px 14px; border-top: 1px solid #26282c; background: rgba(0, 0, 0, .08); }

.active-card { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 12px; align-items: start; padding: 12px; }
@media (max-width: 640px) { .active-card { grid-template-columns: 1fr; } }

/* ---------- エディタ ---------- */
.editor { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 20px; align-items: start; }
.editor-preview { position: sticky; top: 76px; }
@media (max-width: 1000px) { .editor { grid-template-columns: 1fr; } .editor-preview { position: static; order: -1; } }
.form-section { padding: 16px; }
.form-section + .form-section { border-top: 1px solid #26282c; }
.form-section h3 { margin-bottom: 12px; }
.ph-chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.ph-chips button {
  height: 22px; padding: 0 7px; border: 1px dashed #4e5058; border-radius: 4px; background: transparent;
  color: var(--muted); font: 11.5px var(--mono); cursor: pointer;
}
.ph-chips button:hover { color: var(--text); border-color: var(--accent); }
.app-info { display: flex; align-items: center; gap: 8px; margin-top: 6px; font-size: 12.5px; color: var(--muted); }
.app-info img { width: 20px; height: 20px; border-radius: 5px; }

/* ---------- テーブル ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 12px; text-align: left; border-bottom: 1px solid #26282c; vertical-align: middle; }
th { color: var(--muted); font-size: 12px; font-weight: 700; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
td.nowrap { white-space: nowrap; }

.days { display: flex; gap: 4px; flex-wrap: wrap; }
.day {
  width: 34px; height: 34px; border: 1px solid var(--border); border-radius: 50%; background: transparent;
  color: var(--muted); font: inherit; font-weight: 700; cursor: pointer;
}
.day.on { background: var(--accent); border-color: var(--accent); color: #fff; }

.setting-row { display: flex; align-items: center; gap: 16px; padding: 14px 16px; }
.setting-row + .setting-row { border-top: 1px solid #26282c; }

/* ---------- モーダル・トースト ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 16px;
  background: rgba(0, 0, 0, .6); animation: fade .12s ease-out;
}
.modal {
  width: min(520px, 100%); max-height: calc(100vh - 32px); display: flex; flex-direction: column;
  background: var(--surface-2); border-radius: 12px; box-shadow: var(--shadow); animation: pop .14s ease-out;
}
.modal-head { padding: 18px 20px 6px; }
.modal-head h2 { font-size: 18px; }
.modal-body { padding: 12px 20px; overflow-y: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; background: var(--surface); border-radius: 0 0 12px 12px; }
.check-list { display: flex; flex-direction: column; max-height: 320px; overflow-y: auto; border: 1px solid var(--border); border-radius: var(--radius-sm); }
.check-list label { display: flex; align-items: center; gap: 10px; padding: 8px 10px; cursor: pointer; }
.check-list label:hover { background: var(--surface-3); }
.check-list label + label { border-top: 1px solid #2a2c31; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: scale(.97); } }

.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 60; display: flex; flex-direction: column; gap: 8px; width: min(360px, calc(100vw - 32px)); }
.toast {
  display: flex; gap: 10px; padding: 11px 14px; border-radius: 8px; background: #111214; color: var(--text);
  box-shadow: var(--shadow); border-left: 4px solid var(--accent); animation: pop .14s ease-out; font-weight: 600;
}
.toast.ok { border-left-color: var(--green); }
.toast.err { border-left-color: var(--red); }
.toast.warn { border-left-color: var(--yellow); }

.spinner { width: 16px; height: 16px; border: 2px solid rgba(255, 255, 255, .3); border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- ログイン ---------- */
.login-body {
  display: grid; place-items: center; min-height: 100vh; padding: 16px;
  background: radial-gradient(1200px 600px at 20% -10%, rgba(88, 101, 242, .35), transparent 60%),
              radial-gradient(900px 500px at 110% 110%, rgba(35, 165, 90, .18), transparent 60%), var(--bg);
}
.login-card { width: min(400px, 100%); padding: 32px 28px; border-radius: 14px; background: var(--surface); box-shadow: var(--shadow); text-align: center; }
.login-logo { display: flex; justify-content: center; color: var(--muted); }
.login-card h1 { font-size: 22px; margin: 14px 0 8px; }
.login-card > p { margin: 0 0 22px; }
.login-card .alert { margin-bottom: 16px; text-align: left; }
.login-foot { margin: 16px 0 0 !important; font-size: 12px; }
