/* =========================================================
 * MeishiHub — 本社管理ダッシュボード スタイル
 * ========================================================= */
:root {
  --green-800: #065f46;
  --green-700: #047857;
  --green-600: #059669;
  --green-500: #10b981;
  --green-400: #34d399;
  --green-100: #d1fae5;
  --green-50:  #ecfdf5;
  --ink:   #0f172a;
  --ink-2: #475569;
  --ink-3: #94a3b8;
  --line:  #e2e8f0;
  --bg:    #f6f8f7;
  --surface: #ffffff;
  --amber: #d97706; --amber-bg: #fef3c7;
  --red: #dc2626;   --red-bg: #fee2e2;
  --blue: #2563eb;  --blue-bg: #dbeafe;
  --shadow: 0 1px 3px rgba(15,23,42,.05), 0 4px 14px rgba(15,23,42,.05);
  --shadow-lg: 0 12px 40px rgba(15,23,42,.16);
}
* { margin: 0; padding: 0; box-sizing: border-box; }
html { color-scheme: light; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", "Segoe UI", sans-serif;
  background: var(--bg); color: var(--ink); font-size: 14px; line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; font-size: inherit; border: none; background: none; cursor: pointer; color: inherit; }
input, select, textarea { font-family: inherit; font-size: 14px; }
a { color: var(--green-700); text-decoration: none; }

.layout { display: flex; min-height: 100vh; }

/* ---------- サイドバー ---------- */
.sidebar {
  width: 240px; flex-shrink: 0; background: #0b3d2e; color: #d9efe6;
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.sidebar .brand {
  display: flex; align-items: center; gap: 10px; padding: 22px 20px 18px;
  font-weight: 800; font-size: 17px; color: #fff; letter-spacing: .01em;
}
.sidebar .brand .mark {
  width: 36px; height: 36px; border-radius: 11px; font-size: 18px;
  background: linear-gradient(135deg, var(--green-500), var(--green-700));
  display: flex; align-items: center; justify-content: center;
}
.sidebar .brand small { display: block; font-size: 10px; font-weight: 600; color: #8fc7b2; }
.side-nav { flex: 1; padding: 8px 12px; display: flex; flex-direction: column; gap: 2px; }
.side-item {
  display: flex; align-items: center; gap: 11px; padding: 11px 13px;
  border-radius: 10px; font-size: 13.5px; font-weight: 600; color: #a9d4c3;
  text-align: left; width: 100%; transition: background .12s ease;
}
.side-item:hover { background: rgba(255,255,255,.06); }
.side-item.active { background: var(--green-600); color: #fff; font-weight: 700; }
.side-item .n { margin-left: auto; background: rgba(255,255,255,.16); font-size: 10.5px; font-weight: 800; padding: 1px 8px; border-radius: 999px; }
.side-item.active .n { background: rgba(255,255,255,.25); }
.side-foot { padding: 16px 20px; font-size: 11px; color: #6ea892; border-top: 1px solid rgba(255,255,255,.08); }
.side-foot a { color: #a9d4c3; font-weight: 700; }

/* ---------- メイン ---------- */
.main { flex: 1; min-width: 0; padding: 24px 32px 48px; }
.topbar { display: flex; align-items: center; gap: 14px; margin-bottom: 22px; }
.topbar h1 { font-size: 21px; font-weight: 800; }
.topbar .sub { color: var(--ink-3); font-size: 12.5px; }
.topbar .spacer { flex: 1; }
.admin-chip {
  display: flex; align-items: center; gap: 9px; background: var(--surface);
  border-radius: 999px; padding: 7px 16px 7px 8px; box-shadow: var(--shadow); font-size: 13px; font-weight: 700;
}
.admin-chip .av { width: 30px; height: 30px; border-radius: 50%; background: var(--green-50); display: flex; align-items: center; justify-content: center; }

.view { display: none; }
.view.active { display: block; animation: fade .25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- カード / タイル ---------- */
.tile-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 22px; }
.tile { background: var(--surface); border-radius: 16px; padding: 18px 20px; box-shadow: var(--shadow); }
.tile .k { font-size: 12px; color: var(--ink-2); font-weight: 700; display: flex; align-items: center; gap: 7px; }
.tile .v { font-size: 30px; font-weight: 800; letter-spacing: -.01em; margin-top: 2px; }
.tile .v small { font-size: 14px; font-weight: 700; color: var(--ink-3); }
.tile .d { font-size: 11.5px; font-weight: 700; color: var(--green-700); margin-top: 2px; }
.tile .d.warn { color: var(--amber); }
.tile .d.crit { color: var(--red); }

.panel { background: var(--surface); border-radius: 16px; box-shadow: var(--shadow); padding: 20px 22px; margin-bottom: 20px; }
.panel-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.panel-head h2 { font-size: 15.5px; font-weight: 800; }
.panel-head .sub { font-size: 12px; color: var(--ink-3); }
.panel-head .spacer { flex: 1; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-32 { display: grid; grid-template-columns: 3fr 2fr; gap: 20px; }

/* ---------- ボタン / フォーム ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  border-radius: 11px; font-weight: 700; padding: 10px 18px; font-size: 13.5px;
  transition: transform .1s ease, opacity .1s ease;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--green-600); color: #fff; box-shadow: 0 3px 10px rgba(5,150,105,.3); }
.btn-outline { background: var(--surface); border: 1.5px solid var(--line); color: var(--ink); }
.btn-ghost { background: var(--green-50); color: var(--green-700); }
.btn-danger { background: var(--red-bg); color: var(--red); }
.btn-sm { padding: 6px 12px; font-size: 12.5px; border-radius: 9px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12px; font-weight: 700; color: var(--ink-2); margin-bottom: 5px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 10px 13px; border: 1.5px solid var(--line); border-radius: 10px;
  background: var(--surface); outline: none; color: var(--ink);
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--green-500); box-shadow: 0 0 0 3px var(--green-50); }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.toolbar input[type="search"] {
  padding: 10px 14px; border: 1.5px solid var(--line); border-radius: 10px; outline: none; min-width: 240px; background: var(--surface);
}
.toolbar select { padding: 10px 12px; border: 1.5px solid var(--line); border-radius: 10px; background: var(--surface); outline: none; font-weight: 600; color: var(--ink-2); }
.toolbar .spacer { flex: 1; }

/* ---------- テーブル ---------- */
.table-wrap { overflow-x: auto; border-radius: 12px; border: 1px solid var(--line); }
table { width: 100%; border-collapse: collapse; font-size: 13px; background: var(--surface); min-width: 720px; }
th {
  text-align: left; font-size: 11.5px; color: var(--ink-3); font-weight: 800;
  padding: 11px 14px; background: #fafcfb; border-bottom: 1px solid var(--line);
  white-space: nowrap; font-variant-numeric: tabular-nums;
}
td { padding: 11px 14px; border-bottom: 1px solid #f0f4f2; vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tbody tr { cursor: pointer; transition: background .1s ease; }
tbody tr:hover { background: var(--green-50); }
td .b { font-weight: 700; }
td .s { font-size: 11.5px; color: var(--ink-3); }
.badge { font-size: 10.5px; font-weight: 800; padding: 2.5px 9px; border-radius: 999px; white-space: nowrap; display: inline-block; }
.badge-green { background: var(--green-100); color: var(--green-800); }
.badge-amber { background: var(--amber-bg); color: var(--amber); }
.badge-red { background: var(--red-bg); color: var(--red); }
.badge-blue { background: var(--blue-bg); color: var(--blue); }
.badge-gray { background: #f1f5f9; color: var(--ink-2); }
.pager { display: flex; align-items: center; gap: 12px; justify-content: flex-end; padding-top: 12px; font-size: 12.5px; color: var(--ink-2); }
input[type="checkbox"] { accent-color: var(--green-600); width: 15px; height: 15px; }

/* ---------- チャート ---------- */
.chart-box { position: relative; }
.chart-box svg { display: block; width: 100%; height: auto; }
.chart-tip {
  position: absolute; pointer-events: none; background: var(--ink); color: #fff;
  font-size: 12px; font-weight: 700; padding: 6px 11px; border-radius: 8px;
  transform: translate(-50%, -130%); white-space: nowrap; opacity: 0; transition: opacity .1s ease; z-index: 5;
}
.chart-tip small { display: block; font-weight: 600; opacity: .75; font-size: 10.5px; }
.hbar-row { display: grid; grid-template-columns: 92px 1fr 52px; gap: 10px; align-items: center; margin-bottom: 9px; font-size: 12.5px; }
.hbar-row .hl { color: var(--ink-2); font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hbar-row .track { height: 14px; border-radius: 7px; background: #eef3f0; overflow: hidden; }
.hbar-row .fill { height: 100%; border-radius: 7px; background: var(--green-600); min-width: 3px; transition: width .5s ease; }
.hbar-row .hv { font-weight: 800; text-align: right; font-variant-numeric: tabular-nums; }

/* インサイト */
.insight {
  display: flex; gap: 13px; padding: 13px 15px; border-radius: 13px; margin-bottom: 10px;
  background: var(--bg); align-items: flex-start;
}
.insight .ic { font-size: 20px; width: 40px; height: 40px; border-radius: 12px; background: var(--surface); display: flex; align-items: center; justify-content: center; flex-shrink: 0; box-shadow: var(--shadow); }
.insight .t { font-weight: 800; font-size: 13.5px; }
.insight .d { font-size: 12.5px; color: var(--ink-2); }
.insight .act { margin-left: auto; flex-shrink: 0; }

/* ---------- モーダル ---------- */
.modal { position: fixed; inset: 0; z-index: 100; display: none; align-items: center; justify-content: center; padding: 24px; background: rgba(11, 40, 30, .45); backdrop-filter: blur(2px); }
.modal.open { display: flex; }
.modal-box { background: var(--surface); border-radius: 18px; max-width: 520px; width: 100%; padding: 26px 26px; box-shadow: var(--shadow-lg); max-height: 88vh; overflow-y: auto; animation: pop .22s cubic-bezier(.32,.72,.28,1); }
@keyframes pop { from { transform: scale(.94); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.modal-box h3 { font-size: 17px; font-weight: 800; margin-bottom: 14px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.wizard-steps { display: flex; gap: 6px; margin-bottom: 18px; }
.wizard-steps .ws { flex: 1; height: 5px; border-radius: 3px; background: var(--line); }
.wizard-steps .ws.on { background: var(--green-600); }

/* 2FAコード表示 */
.code-display {
  background: linear-gradient(140deg, #064e3b, var(--green-700)); color: #fff;
  border-radius: 16px; padding: 24px; text-align: center; margin-bottom: 16px;
}
.code-display .cd-label { font-size: 12px; font-weight: 700; opacity: .85; }
.code-display .cd-code { font-size: 46px; font-weight: 800; letter-spacing: .35em; padding-left: .35em; margin: 6px 0; }
.code-display .cd-exp { font-size: 11.5px; opacity: .75; }

/* スマホプレビュー（お知らせ配信） */
.phone-preview {
  width: 250px; border: 8px solid var(--ink); border-radius: 32px; background: var(--bg);
  padding: 20px 14px; margin: 0 auto;
}
.phone-preview .pp-pop { background: var(--surface); border-radius: 16px; padding: 16px 14px; box-shadow: var(--shadow-lg); }
.phone-preview .pp-tag { display: inline-block; background: var(--green-700); color: #fff; font-size: 9.5px; font-weight: 800; padding: 3px 9px; border-radius: 999px; margin-bottom: 8px; }
.phone-preview .pp-tag.warn { background: var(--amber); }
.phone-preview .pp-title { font-size: 13.5px; font-weight: 800; line-height: 1.4; }
.phone-preview .pp-body { font-size: 11px; color: var(--ink-2); margin-top: 5px; }
.phone-preview .pp-btn { margin-top: 12px; background: var(--green-600); color: #fff; font-size: 11px; font-weight: 700; text-align: center; border-radius: 9px; padding: 8px; }

/* ログインゲート */
#gate {
  position: fixed; inset: 0; z-index: 200; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(900px 500px at 50% -150px, var(--green-100), transparent 60%), var(--bg);
  padding: 24px;
}
#gate .gate-box { background: var(--surface); border-radius: 22px; box-shadow: var(--shadow-lg); padding: 34px 32px; width: 100%; max-width: 400px; }
#gate .mark { width: 58px; height: 58px; border-radius: 17px; margin: 0 auto 12px; font-size: 27px; background: linear-gradient(135deg, var(--green-500), var(--green-700)); display: flex; align-items: center; justify-content: center; }
#gate h1 { text-align: center; font-size: 20px; font-weight: 800; }
#gate .sub { text-align: center; color: var(--ink-2); font-size: 12.5px; margin-bottom: 20px; }
#gate .err { display: none; background: var(--red-bg); color: var(--red); font-size: 12.5px; font-weight: 700; border-radius: 10px; padding: 10px 13px; margin-bottom: 12px; }
#gate .note { text-align: center; font-size: 11.5px; color: var(--ink-3); margin-top: 16px; line-height: 1.8; }
#gate .note b { color: var(--green-700); }
#gate .note u { cursor: pointer; }

#toast {
  position: fixed; bottom: 28px; left: 50%; transform: translate(-50%, 16px);
  background: var(--ink); color: #fff; font-size: 13px; font-weight: 700;
  padding: 12px 22px; border-radius: 999px; z-index: 300; opacity: 0; pointer-events: none; transition: all .25s ease;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- レスポンシブ ---------- */
@media (max-width: 1080px) {
  .tile-row { grid-template-columns: repeat(2, 1fr); }
  .grid-2, .grid-32 { grid-template-columns: 1fr; }
}
@media (max-width: 800px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; }
  .side-nav { flex-direction: row; overflow-x: auto; padding-bottom: 12px; }
  .side-item { white-space: nowrap; width: auto; }
  .side-foot { display: none; }
  .main { padding: 18px 16px 40px; }
  .tile-row { grid-template-columns: repeat(2, 1fr); gap: 10px; }
}
