/* 運営の管理サイト（PC が主。スマホ幅 360px でも崩れないようにする）。
   トレーナー管理画面（緑）と見分けがつくよう、色は落ち着いた紺にする */
:root {
  --accent: #3b4a6b;
  --accent-strong: #2a3754;
  --accent-soft: #e8ecf4;
  --bg: #f4f5f8;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --text: #1d222c;
  --muted: #5d6576;
  --border: #dde1e9;
  --ok: #1d7a4f;
  --ok-soft: #e3f4ea;
  --error: #c62828;
  --error-soft: #fdecea;
  --warn: #9a5b00;
  --warn-soft: #fff4e0;
  --shadow: 0 1px 2px rgba(20, 28, 48, 0.06), 0 4px 16px rgba(20, 28, 48, 0.06);
  --line-green: #06c755;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --accent: #8fa3d1;
    --accent-strong: #b0c0e6;
    --accent-soft: #1f2738;
    --bg: #11141b;
    --surface: #1a1f2a;
    --surface-2: #161a23;
    --text: #e6e9f0;
    --muted: #a0a8b9;
    --border: #2d3443;
    --ok: #6fd3a0;
    --ok-soft: #173327;
    --error: #ff8a80;
    --error-soft: #3a1f1d;
    --warn: #f0b860;
    --warn-soft: #3a2c14;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN",
    "Noto Sans JP", "Yu Gothic", "Meiryo", sans-serif;
  font-size: 15px;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
}
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; line-height: 1.4; }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.num { font-variant-numeric: tabular-nums; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; word-break: break-all; }

/* ---- 読み込み中・ログイン ---- */
.state {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 24px 16px;
  text-align: center;
}
.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 28px 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: left;
}
.login-title { font-size: 22px; }
.eyebrow { margin: 0; color: var(--accent); font-size: 12px; font-weight: 700; letter-spacing: 0.08em; }

/* ---- ボタン・入力 ---- */
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  padding: 8px 16px;
  border: 1.5px solid transparent;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}
@media (prefers-color-scheme: dark) {
  .button { background: #3b4a6b; }
}
.button:hover { filter: brightness(1.08); }
.button:disabled { opacity: 0.5; cursor: not-allowed; filter: none; }
.button:focus-visible, .nav-link:focus-visible, .link-button:focus-visible, input:focus-visible, select:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 45%, transparent);
  outline-offset: 2px;
}
.button-line { background: var(--line-green) !important; min-height: 48px; font-size: 16px; }
.button-secondary { background: var(--surface) !important; color: var(--accent-strong); border-color: var(--accent); }
.button-ghost { background: transparent !important; color: var(--muted); border-color: var(--border); }
.button-ghost:hover { background: var(--accent-soft) !important; color: var(--text); }
.button-danger { background: var(--error) !important; }
@media (prefers-color-scheme: dark) {
  .button-danger { background: #b3261e !important; }
}
.button-danger-outline { background: transparent !important; color: var(--error); border-color: color-mix(in srgb, var(--error) 55%, transparent); }
.button-danger-outline:hover { background: var(--error-soft) !important; }
.button-small { min-height: 34px; padding: 4px 12px; font-size: 13px; }
.link-button {
  border: none;
  background: none;
  padding: 0;
  color: var(--accent-strong);
  font: inherit;
  font-weight: 700;
  text-align: left;
  cursor: pointer;
}
.link-button:hover { text-decoration: underline; }

input[type="text"], input[type="number"], select, textarea {
  min-height: 40px;
  padding: 6px 10px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  max-width: 100%;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input[aria-invalid="true"] { border-color: var(--error); }
.check-label { display: inline-flex; align-items: center; gap: 6px; min-height: 36px; cursor: pointer; }
.check-label input { width: 18px; height: 18px; accent-color: var(--accent); }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field-label { font-size: 13px; font-weight: 700; color: var(--muted); }
.form-row { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px 12px; }
.form-row .field { flex: 1 1 180px; }
.form-row .field-narrow { flex: 0 1 120px; }

.notice { padding: 10px 12px; border-radius: 10px; background: var(--accent-soft); font-size: 14px; }
.notice-error { background: var(--error-soft); color: var(--error); }
.notice-warn { background: var(--warn-soft); color: var(--warn); }
.notice-ok { background: var(--ok-soft); color: var(--ok); }
.notice code { user-select: all; }

.badge {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}
.badge-trial { color: var(--accent-strong); border-color: color-mix(in srgb, var(--accent) 40%, transparent); background: var(--accent-soft); }
.badge-active, .badge-ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 40%, transparent); background: var(--ok-soft); }
.badge-suspended, .badge-warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 40%, transparent); background: var(--warn-soft); }
.badge-ended, .badge-danger { color: var(--error); border-color: color-mix(in srgb, var(--error) 40%, transparent); background: var(--error-soft); }

/* ---- 本体 ---- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar-title { display: flex; flex-direction: column; min-width: 0; }
.operator-name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  padding: 8px 16px 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  scrollbar-width: thin;
}
.nav-link {
  flex: 0 0 auto;
  padding: 8px 12px 10px;
  border-bottom: 3px solid transparent;
  color: var(--muted);
  font-weight: 700;
  font-size: 14px;
  text-decoration: none;
  white-space: nowrap;
}
.nav-link:hover { color: var(--text); }
.nav-link[aria-current="page"] { color: var(--accent-strong); border-bottom-color: var(--accent); }
.nav-count { margin-left: 4px; padding: 0 6px; border-radius: 999px; background: var(--error); color: #fff; font-size: 11px; }

.main { max-width: 1120px; margin: 0 auto; padding: 16px; display: flex; flex-direction: column; gap: 16px; outline: none; }
.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; }
.page-title { font-size: 21px; }
.tools { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.back-link { font-size: 14px; }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}
.panel-title { font-size: 16px; }
.panel-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; }

/* ダッシュボードの数字 */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}
.stat-label { color: var(--muted); font-size: 13px; font-weight: 700; }
.stat-value { font-size: 28px; font-weight: 800; line-height: 1.2; font-variant-numeric: tabular-nums; }
.stat-unit { font-size: 14px; font-weight: 700; margin-left: 2px; color: var(--muted); }
.stat-sub { font-size: 13px; color: var(--muted); }
.meter { height: 8px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); overflow: hidden; }
.meter > span { display: block; height: 100%; background: var(--accent); }
.meter-warn > span { background: var(--warn); }

/* 表（PC は表、スマホ幅はカードのように縦に並べる） */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th, table.data td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
table.data th { color: var(--muted); font-size: 12px; font-weight: 700; white-space: nowrap; background: var(--surface-2); }
table.data td.num, table.data th.num { text-align: right; }
table.data tr:last-child td { border-bottom: none; }
table.data .row-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.empty { padding: 16px; color: var(--muted); text-align: center; }

@media (max-width: 720px) {
  .main { padding: 12px 16px 24px; }
  table.data.stack thead { display: none; }
  table.data.stack, table.data.stack tbody, table.data.stack tr, table.data.stack td { display: block; width: 100%; }
  table.data.stack tr { padding: 10px 0; border-bottom: 1px solid var(--border); }
  table.data.stack tr:last-child { border-bottom: none; }
  table.data.stack td { border: none; padding: 3px 0; display: flex; gap: 10px; text-align: left !important; }
  table.data.stack td::before {
    content: attr(data-label);
    flex: 0 0 96px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
    padding-top: 2px;
  }
  table.data.stack td.cell-main::before { display: none; }
  table.data.stack td.cell-main { font-size: 15px; }
  .stat-value { font-size: 24px; }
  .page-title { font-size: 19px; }
}

/* 発行した招待 URL（1回だけ表示） */
.once-box { border: 2px solid var(--warn); border-radius: 12px; padding: 12px; display: flex; flex-direction: column; gap: 8px; background: var(--warn-soft); }
.once-box .url { background: var(--surface); color: var(--text); border-radius: 8px; padding: 8px 10px; border: 1px solid var(--border); }

.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; font-size: 14px; }
.kv dt { color: var(--muted); font-weight: 700; }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
@media (max-width: 480px) {
  .kv { grid-template-columns: 1fr; gap: 0; }
  .kv dd { margin-bottom: 6px; }
}

.staff-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.staff-row:last-child { border-bottom: none; }
.staff-name { font-weight: 700; flex: 1 1 160px; min-width: 0; }

/* ---- 確認のシート（画面の中に出す。window.confirm は使わない） ---- */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(10, 14, 24, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.sheet {
  width: 100%;
  max-width: 520px;
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  background: var(--surface);
  border-radius: 16px;
  padding: 20px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.sheet-title { font-size: 18px; }
.sheet-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; margin-top: 6px; }
.sheet-actions .button { min-height: 46px; }
@media (max-width: 480px) {
  .sheet-backdrop { align-items: flex-end; padding: 0; }
  .sheet { border-radius: 16px 16px 0 0; max-height: 90vh; }
  .sheet-actions .button { flex: 1 1 auto; }
}

/* 数字だけの細い表（スマホ幅でも表のまま） */
@media (max-width: 720px) {
  table.data.compact { font-size: 13px; }
  table.data.compact th, table.data.compact td { padding: 6px 4px; }
  table.data.compact th { white-space: normal; }
}
