/* CoCo-Repo 管理コンソール（管理PC 向け） */

:root {
  --bg: #f1f5f9;
  --panel: #ffffff;
  --ink: #0f172a;
  --ink-soft: #64748b;
  --line: #e2e8f0;
  --primary: #1d4ed8;
  --danger: #b91c1c;
  --ok: #15803d;
  --head: #0f172a;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg); color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Yu Gothic UI",
               "Hiragino Kaku Gothic ProN", "Noto Sans JP", sans-serif;
  font-size: 14px; line-height: 1.6;
}

.is-hidden { display: none !important; }
code { background: #eef2ff; padding: 1px 5px; border-radius: 4px; font-size: .92em; }

/* ---- ログイン / 遮断 ----------------------------------------------------- */
.gate {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  background: var(--head); padding: 24px;
}
.gate__card {
  width: 100%; max-width: 400px;
  background: #fff; border-radius: 16px; padding: 28px;
}
.gate__card h1 { font-size: 18px; margin: 0 0 16px; }
.gate__note, .gate__warn { color: var(--ink-soft); font-size: 13px; }
.gate__warn { background: #fffbeb; border: 1px solid #fde68a; border-radius: 8px; padding: 10px 12px; color: #92400e; }
/* 管理端末の登録の欄（受け付けているあいだだけ出る。D-85） */
.gate__enroll { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--line, #e2e8f0); }
.gate__enroll h2 { font-size: 15px; margin: 0 0 8px; }
.gate__enroll .field { margin-top: 10px; }

/* ---- ヘッダ -------------------------------------------------------------- */
.console { display: flex; flex-direction: column; height: 100%; }

.head {
  flex: 0 0 auto;
  display: flex; align-items: center; gap: 20px;
  padding: 10px 18px;
  background: var(--head); color: #f8fafc;
}
.head__brand { font-weight: 700; letter-spacing: .08em; }
.head__brand span { display: block; font-size: 11px; font-weight: 400; color: #94a3b8; letter-spacing: 0; }
.head__stats { display: flex; align-items: center; gap: 18px; margin-left: auto; font-size: 13px; color: #cbd5e1; }
.stat b { color: #fff; font-size: 16px; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: #22c55e; display: inline-block; }
.dot.is-down { background: #ef4444; }

/* ---- タブ ---------------------------------------------------------------- */
.tabs {
  flex: 0 0 auto;
  display: flex; gap: 2px;
  padding: 0 12px;
  background: #1e293b;
}
.tab {
  padding: 10px 18px;
  border: none; background: none;
  color: #94a3b8; font-size: 14px; font-weight: 700;
  cursor: pointer; border-bottom: 3px solid transparent;
}
.tab.is-active { color: #fff; border-bottom-color: #60a5fa; }
.tab__badge {
  display: inline-block;
  min-width: 18px; height: 18px; margin-left: 6px; padding: 0 5px;
  border-radius: 9px; background: #dc2626; color: #fff;
  font-size: 11px; line-height: 18px; text-align: center;
}

.opt-row {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 0; border-bottom: 1px solid var(--line);
}
.opt-row:last-child { border-bottom: none; }
.opt-row input[type="text"] {
  flex: 1 1 auto; min-width: 0;
  padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; font-size: 14px;
}
.opt-row.is-off input[type="text"] { background: #f8fafc; color: var(--ink-soft); }
.opt-move { display: flex; flex-direction: column; gap: 2px; }
.opt-move button {
  width: 26px; height: 17px; padding: 0; line-height: 1;
  border: 1px solid var(--line); background: #fff; border-radius: 5px;
  font-size: 11px; cursor: pointer; color: var(--ink-soft);
}
.opt-move button:disabled { opacity: .3; cursor: default; }

.panel { display: none; flex: 1 1 auto; min-height: 0; overflow: auto; }
.panel.is-active { display: block; }
#panel-map.is-active { display: flex; }

.pad { padding: 18px; max-width: 1100px; }

/* ---- 地図 ---------------------------------------------------------------- */
.split { display: flex; width: 100%; height: 100%; }
#admin-map { flex: 1 1 auto; height: 100%; background: #dbeafe; }
.side {
  flex: 0 0 330px;
  height: 100%;
  overflow-y: auto;
  background: var(--panel);
  border-left: 1px solid var(--line);
  padding: 14px;
}

.team-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 12px;
}
.team-card__head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 8px; }
.team-card__code { font-size: 18px; font-weight: 700; letter-spacing: .18em; }
.team-card__meta { font-size: 12px; color: var(--ink-soft); margin-left: auto; }

.member-row {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 0;
  border-top: 1px dashed var(--line);
  font-size: 13px;
}
.member-row svg { width: 20px; height: 20px; flex: 0 0 auto; }
.member-row__name { font-weight: 700; }
.member-row__sub { color: var(--ink-soft); font-size: 12px; }
.member-row__actions { margin-left: auto; }
.badge {
  font-size: 10px; padding: 1px 6px; border-radius: 999px;
  background: #eff6ff; color: var(--primary);
}
.badge--host { background: #fffbeb; color: #b45309; }
.badge--offline { background: #fef2f2; color: var(--danger); }
.badge--merged { background: #f5f3ff; color: #6d28d9; }
.badge--ok { background: #f0fdf4; color: #15803d; }
.badge--warn { background: #fffbeb; color: #b45309; }

/* ---- カード / フォーム --------------------------------------------------- */
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
  margin-bottom: 18px;
}
.card h2 { font-size: 15px; margin: 0 0 12px; }
.hint { color: var(--ink-soft); font-size: 12px; }

.field { display: block; margin: 0 0 12px; }
.field__label { display: block; font-size: 12px; font-weight: 700; color: var(--ink-soft); margin-bottom: 4px; }
.field input, .field select, textarea, input[type="search"] {
  width: 100%; padding: 9px 11px; font-size: 14px;
  border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink);
  font-family: inherit;
}
.field--check { display: flex; align-items: center; gap: 8px; }
.field--check input { width: auto; }

.grid-form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 16px; }
.form-actions { grid-column: 1 / -1; display: flex; align-items: center; gap: 10px; margin-top: 4px; }

.inline-form { display: flex; gap: 8px; margin-top: 12px; }
.inline-form input[type="text"] { flex: 1 1 auto; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; }
.inline-form input[type="number"] { width: 84px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; }

.btn {
  display: inline-block;
  padding: 10px 18px;
  font-size: 14px; font-weight: 700;
  border: 1px solid transparent; border-radius: 9px;
  background: var(--panel); color: var(--ink); cursor: pointer;
  font-family: inherit;
}
.btn--primary { background: var(--primary); color: #fff; }
.btn--ghost { background: #fff; border-color: var(--line); color: var(--ink-soft); }
.btn--danger { background: #fef2f2; border-color: #fecaca; color: var(--danger); }
.btn--sm { padding: 6px 12px; font-size: 13px; }
.btn--xs { padding: 3px 9px; font-size: 12px; border-radius: 7px; }
.btn:disabled { opacity: .5; cursor: default; }
.gate .btn { width: 100%; }

.error { color: var(--danger); font-size: 13px; min-height: 1.4em; }

/* ---- テーブル ------------------------------------------------------------ */
table { width: 100%; border-collapse: collapse; margin-top: 10px; font-size: 13px; }
th, td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--ink-soft); font-size: 12px; font-weight: 700; background: #f8fafc; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.is-off td { color: var(--ink-soft); background: #f8fafc; }

.empty { color: var(--ink-soft); padding: 18px 0; text-align: center; }

/* ---- 地図アイコン（利用者アプリと共通のクラス名） ------------------------- */
.mk { width: 72px; margin-left: -36px; margin-top: -20px; text-align: center; }
.mk__pin {
  width: 36px; height: 36px; margin: 0 auto;
  border-radius: 50%; background: #fff; border: 3px solid #64748b;
  box-shadow: 0 2px 8px rgba(15, 23, 42, .3);
  display: flex; align-items: center; justify-content: center; position: relative;
}
.mk__pin svg { width: 22px; height: 22px; display: block; }
.mk__label {
  display: inline-block; margin-top: 3px; max-width: 72px; padding: 1px 6px;
  background: rgba(255, 255, 255, .92); border-radius: 6px;
  font-size: 11px; font-weight: 700; line-height: 1.4; color: #0f172a;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  box-shadow: 0 1px 3px rgba(15, 23, 42, .2);
}
.mk.is-offline { opacity: .55; }
/* 9. 通信できていない相手は、地図の上でひと目で分かるようにする */
.mk__off {
  display: block;
  width: max-content;
  max-width: 72px;
  margin: 2px auto 0;
  padding: 0 5px;
  border-radius: 6px;
  background: #b91c1c;
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  line-height: 15px;
  letter-spacing: .02em;
  white-space: nowrap;
  box-shadow: 0 1px 3px rgba(15, 23, 42, .3);
}
/* 本当に圏外だと分かっているとき（自分の端末）は赤。
   相手については理由が分からないので、灰色で経過時間だけを出す。 */
.mk__off--stale { background: #475569; }
.mk.is-offline .mk__label { color: #475569; }
.mk__badge {
  position: absolute; top: -6px; right: -8px;
  min-width: 20px; height: 20px; padding: 0 5px; border-radius: 10px;
  background: #0f172a; color: #fff; font-size: 11px; font-weight: 700; line-height: 20px;
}
.mk__host {
  position: absolute; bottom: -5px; left: -6px;
  width: 18px; height: 18px; border-radius: 50%;
  background: #f59e0b; color: #fff; font-size: 10px; font-weight: 700; line-height: 18px;
}
.mk__team {
  position: absolute; top: -8px; left: -10px;
  padding: 0 5px; height: 17px; border-radius: 9px;
  background: #1d4ed8; color: #fff; font-size: 10px; font-weight: 700; line-height: 17px;
  letter-spacing: .06em;
}
.leaflet-div-icon { background: none; border: none; }

/* ---- 絞り込みの欄（操作ログ） --------------------------------------------- */
.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  margin: 12px 0 4px;
}
.filter { display: flex; flex-direction: column; gap: 4px; min-width: 140px; }
.filter--wide { flex: 1 1 220px; }
.filter__label { font-size: 12px; font-weight: 700; color: var(--ink-soft); }
.filter input, .filter select {
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 14px;
  background: #fff;
  color: var(--ink);
}

/* ---- 操作ログの表 --------------------------------------------------------- */
.log-table { width: 100%; border-collapse: collapse; }
.log-table th, .log-table td {
  padding: 7px 8px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
  font-size: 13px;
}
.log-table th { text-align: left; white-space: nowrap; }
/* 日付は変わったときだけ出す。同じ日が延々と並ぶより追いやすい */
.log-table tr.is-newday td { border-top: 2px solid #cbd5e1; }
.log-table .log-date { white-space: nowrap; color: var(--ink-soft); font-weight: 700; }
.log-table .log-time { white-space: nowrap; font-variant-numeric: tabular-nums; }
.log-table .log-ip   { white-space: nowrap; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px; }
.log-table .log-dev  { color: var(--ink-soft); font-size: 12px; }
.log-table .log-detail { color: var(--ink-soft); }
.log-tag {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
  background: #e2e8f0;
  color: #334155;
}
/* 見逃したくない操作は赤、管理者の操作は琥珀色にする */
.log-tag--alert { background: #fee2e2; color: #b91c1c; }
.log-tag--admin { background: #fef3c7; color: #92400e; }
.log-wrap { overflow-x: auto; margin-top: 10px; }

/* ---- トースト ------------------------------------------------------------ */
.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%);
  margin: 0; padding: 10px 18px;
  background: rgba(15, 23, 42, .92); color: #fff; font-size: 14px;
  border-radius: 999px; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 1200;
}
.toast.is-on { opacity: 1; }

@media (max-width: 900px) {
  .split { flex-direction: column; }
  .side { flex: 0 0 auto; width: 100%; height: 45%; border-left: none; border-top: 1px solid var(--line); }
  #admin-map { height: 55%; }
  .grid-form { grid-template-columns: 1fr; }
}

/* ---- スマートフォンから管理画面を使う場合 ------------------------------- */
@media (max-width: 640px) {
  body { font-size: 15px; }

  .head { flex-wrap: wrap; gap: 8px 14px; padding: 10px 12px; }
  .head__stats { width: 100%; margin-left: 0; gap: 12px; font-size: 12px; order: 3; }
  .head .btn { padding: 6px 12px; font-size: 13px; }

  .tabs { overflow-x: auto; -webkit-overflow-scrolling: touch; padding: 0 4px; }
  .tabs::-webkit-scrollbar { display: none; }
  .tab { flex: 0 0 auto; padding: 10px 12px; font-size: 13px; }

  .pad { padding: 12px; }
  .card { padding: 12px; border-radius: 12px; }

  /* 表は横スクロールさせる（つぶさない） */
  .card table { display: block; overflow-x: auto; white-space: nowrap; }

  .split { height: auto; }
  #admin-map { height: 55vh; }
  .side { height: auto; max-height: 45vh; }

  .inline-form { flex-wrap: wrap; }
  .inline-form input[type="text"], .inline-form input[type="tel"] { flex: 1 1 100%; }

  .opt-row { flex-wrap: wrap; }
  .opt-row input[type="text"] { flex: 1 1 100%; }

  /* 指で押しやすい大きさにする */
  .btn--xs { padding: 7px 12px; font-size: 13px; }
  .opt-move button { width: 34px; height: 24px; font-size: 13px; }

  .gate { padding: 14px; }
  .gate__card { padding: 20px 16px; }
}

/* 入力例（プレースホルダー）は、入力済みの文字と見間違えないよう薄く表示する */
input::placeholder,
textarea::placeholder {
  color: #b6bfcc;
  opacity: 1;              /* Firefox は既定で薄くするため明示的に固定 */
}
input::-webkit-input-placeholder,
textarea::-webkit-input-placeholder { color: #b6bfcc; }
input:-ms-input-placeholder,
textarea:-ms-input-placeholder { color: #b6bfcc; }

/* パスワード欄の「表示 / 隠す」ボタン */
.pw { position: relative; display: block; }
.pw input { width: 100%; padding-right: 60px; }
.pw__toggle {
  position: absolute;
  top: 50%;
  right: 6px;
  transform: translateY(-50%);
  border: none;
  background: none;
  color: #1d4ed8;
  font-size: 12px;
  font-weight: 700;
  padding: 6px 8px;
  cursor: pointer;
  font-family: inherit;
}
.pw__toggle:hover { text-decoration: underline; }

/* 利用者が置いた目印（利用者アプリと同じ見た目） */
.mkm {
  width: 30px; height: 30px;
  margin-left: -15px; margin-top: -30px;
  border-radius: 50% 50% 50% 4px;
  transform: rotate(-45deg);
  background: #fff;
  border: 3px solid #d97706;
  box-shadow: 0 2px 8px rgba(15, 23, 42, .35);
  display: flex; align-items: center; justify-content: center;
}
.mkm svg { transform: rotate(45deg); }

/* ---- サーバーの設定（監査の確認用）------------------------------------- */
.server-check__group {
  margin: 18px 0 6px;
  font-size: 13px;
  color: var(--ink-soft);
}
table.server-check td { vertical-align: top; }
table.server-check td code { font-size: 12px; word-break: break-all; }
table.server-check td:last-child {
  font-size: 12px;
  color: var(--ink-soft);
  line-height: 1.6;
}
.sc-badge {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}
.sc-badge--ok      { background: #dcfce7; color: #166534; }
.sc-badge--warn    { background: #fee2e2; color: #991b1b; }
.sc-badge--unknown { background: #e2e8f0; color: #475569; }
tr.sc--warn td { background: #fff7f7; }

/* ---- 警告（侵入の見張り。D-84） ------------------------------------------ */
.alerts { flex: 0 0 auto; background: #fffbeb; border-bottom: 1px solid #fcd34d; color: #78350f; }
.alerts--danger { background: #fef2f2; border-bottom-color: #fecaca; color: #7f1d1d; }
.alerts__bar { display: flex; align-items: center; gap: 12px; padding: 8px 16px; }
.alerts__icon {
  flex: 0 0 auto; width: 22px; height: 22px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  background: #b45309; color: #fff; font-weight: 700; font-size: 13px;
}
.alerts--danger .alerts__icon { background: var(--danger); }
.alerts__summary { flex: 1 1 auto; font-weight: 700; }
.alerts__list { max-height: 45vh; overflow: auto; padding: 0 16px 10px; }
.alerts__h { margin: 10px 0 6px; font-size: 13px; }
.alerts__actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 2px 0 10px; }
.alert {
  margin-bottom: 8px; padding: 10px 12px;
  background: #fff; border: 1px solid var(--line); border-radius: 10px; color: var(--ink);
}
.alert--danger  { border-color: #fecaca; }
.alert--caution { border-color: #fde68a; }
.alert--confirm { border-color: #bfdbfe; }
.alert__head { display: flex; align-items: center; gap: 10px; font-size: 12px; color: var(--ink-soft); }
.alert__level { padding: 1px 8px; border-radius: 999px; font-weight: 700; background: #eff6ff; color: var(--primary); }
.alert--danger  .alert__level { background: #fef2f2; color: var(--danger); }
.alert--caution .alert__level { background: #fffbeb; color: #b45309; }
.alert__title { margin: 2px 0; font-weight: 700; }
.alert__meta { font-size: 12px; color: var(--ink-soft); word-break: break-all; }
.alert__advice { margin: 4px 0 6px; font-size: 13px; }
.alert__items { margin: 4px 0; padding-left: 18px; font-size: 12px; word-break: break-all; }
@media (max-width: 640px) {
  .alerts__bar { flex-wrap: wrap; }
}
