:root {
  --bg: #0b0f1a; --panel: #121829; --panel2: #171f33; --line: rgba(255,255,255,.08);
  --text: #e6e9f2; --muted: #8b93a7; --accent: #7c3aed; --accent2: #3b82f6;
  --ok: #22c55e; --warn: #f59e0b; --bad: #ef4444; --unknown: #64748b;
  --side-w: 240px;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-family: "Segoe UI", "Hiragino Sans", "Noto Sans JP", system-ui, sans-serif; font-size: 14px; }
a { color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 12px; }
.error { color: #fca5a5; font-size: 13px; min-height: 18px; margin-top: 6px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
h1 { font-size: 17px; margin: 0; }
h2 { font-size: 16px; margin: 0; }

.btn { border: 1px solid var(--line); background: var(--panel2); color: var(--text); padding: 8px 14px; border-radius: 10px; cursor: pointer; font-size: 13px; white-space: nowrap; }
.btn:hover { border-color: rgba(139,92,246,.6); }
.btn.primary { background: linear-gradient(135deg, var(--accent), var(--accent2)); border: none; font-weight: 700; }
.btn.ghost { background: transparent; }
.btn.small { padding: 5px 9px; font-size: 12px; }
.btn.danger { color: #fca5a5; border-color: rgba(239,68,68,.4); }
.btn:disabled { opacity: .5; cursor: default; }

input, select, textarea { width: 100%; background: #0e1424; color: var(--text); border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; font-size: 14px; font-family: inherit; }
input:focus, select:focus, textarea:focus { outline: none; border-color: rgba(139,92,246,.7); }
label { display: block; font-size: 12px; color: var(--muted); margin: 10px 0 4px; }
input[type="file"] { padding: 6px; }

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand b { display: block; font-size: 15px; }
.brand .muted { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.logo { width: 36px; height: 36px; border-radius: 10px; background: linear-gradient(135deg, var(--accent), var(--accent2)); display: grid; place-items: center; font-weight: 800; color: #fff; flex: none; }

/* ログイン */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 22px; }
.login-card .btn { width: 100%; margin-top: 16px; }

/* ===== レイアウト: 左サイドメニュー＋右メイン ===== */
.app { display: flex; min-height: 100vh; }
.side { width: var(--side-w); flex: none; background: var(--panel); border-right: 1px solid var(--line); padding: 16px 12px; display: flex; flex-direction: column; gap: 12px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.side-brand { padding: 0 4px; }
.side-add { width: 100%; }
.side-nav { display: flex; flex-direction: column; gap: 14px; }
.side-sec .side-title { font-size: 11px; color: var(--muted); letter-spacing: .08em; padding: 0 8px 6px; }
.side-item { display: flex; align-items: center; gap: 8px; width: 100%; text-align: left; background: transparent; border: 1px solid transparent; color: var(--text); padding: 8px 10px; border-radius: 10px; cursor: pointer; font-size: 13px; font-family: inherit; }
.side-item:hover { background: var(--panel2); }
.side-item.active { background: linear-gradient(135deg, rgba(124,58,237,.3), rgba(59,130,246,.22)); border-color: rgba(139,92,246,.55); }
.side-item .ico { width: 20px; text-align: center; flex: none; }
.side-item .lbl { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-item .cnt { font-size: 11px; color: var(--muted); background: var(--panel2); border-radius: 999px; padding: 1px 7px; flex: none; }
.side-item.bad .cnt { color: #fecaca; background: rgba(239,68,68,.18); }
.side-item.warn .cnt { color: #fde68a; background: rgba(245,158,11,.18); }
.side-item.zero { opacity: .5; }
.side-foot { margin-top: auto; border-top: 1px solid var(--line); padding-top: 10px; display: flex; flex-direction: column; gap: 2px; }
.side-overlay { display: none; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.top { display: flex; align-items: center; gap: 12px; padding: 12px 18px; border-bottom: 1px solid var(--line); background: rgba(11,15,26,.9); position: sticky; top: 0; z-index: 5; backdrop-filter: blur(8px); }
.menu-btn { display: none; font-size: 16px; }
.top-title { min-width: 0; }
.top-title .muted { display: block; }
.top-tools { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.top-tools input[type="search"] { width: 260px; }
.top-tools select { width: auto; }

.filter-bar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 10px 18px 0; font-size: 12px; color: var(--muted); }
.filter-bar .chip { border: 1px solid rgba(139,92,246,.5); background: rgba(124,58,237,.18); color: var(--text); border-radius: 999px; padding: 4px 10px; cursor: pointer; }

/* ブランド・人物のまとめ表示（同じ人のSNSへのショートカット） */
.group-links { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; padding: 12px 18px 0; }
.group-links .glabel { font-size: 12px; color: var(--muted); }
.group-links a { display: inline-flex; align-items: center; gap: 8px; background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 5px 12px 5px 6px; text-decoration: none; font-size: 13px; }
.group-links a:hover { border-color: rgba(139,92,246,.6); }
.group-links a img, .group-links a .mini { width: 24px; height: 24px; border-radius: 50%; object-fit: cover; background: var(--panel2); display: grid; place-items: center; font-size: 11px; font-weight: 700; }
.group-links a .dot { width: 8px; height: 8px; }
.tag.grp { cursor: pointer; border: 1px solid rgba(139,92,246,.35); }
.tag.grp:hover { border-color: rgba(139,92,246,.8); }

/* カード */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; padding: 14px 18px 40px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 12px; display: flex; flex-direction: column; gap: 8px; position: relative; }
.card.stale-bad { border-color: rgba(239,68,68,.45); box-shadow: inset 3px 0 0 var(--bad); }
.card.stale-warn { border-color: rgba(245,158,11,.4); box-shadow: inset 3px 0 0 var(--warn); }
.card.stale-ok { box-shadow: inset 3px 0 0 var(--ok); }
.card.st-paused, .card.st-closed { opacity: .65; }
.card-head { display: flex; gap: 10px; align-items: center; }
.avatar { width: 52px; height: 52px; border-radius: 50%; object-fit: cover; background: var(--panel2); flex: none; display: grid; place-items: center; font-weight: 800; font-size: 18px; color: #fff; }
.avatar img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; }
.who { min-width: 0; flex: 1; }
.who .name { font-weight: 700; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who .handle { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pf { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; color: #fff; flex: none; }
.pf-x { background: #1d2430; } .pf-instagram { background: linear-gradient(45deg, #f09433, #dc2743, #bc1888); } .pf-threads { background: #333; }
.pf-tiktok { background: linear-gradient(90deg, #25f4ee33, #fe2c5533), #111; border: 1px solid #333; } .pf-youtube { background: #dc2626; } .pf-other { background: #475569; }
.purpose { font-size: 13px; color: #cfd5e3; line-height: 1.5; max-height: 3em; overflow: hidden; }
.meta { display: flex; gap: 6px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.tag { background: var(--panel2); border-radius: 6px; padding: 2px 7px; }
.status { border-radius: 6px; padding: 2px 7px; }
.status.active { color: #bbf7d0; background: rgba(34,197,94,.15); }
.status.paused { color: #fde68a; background: rgba(245,158,11,.15); }
.status.suspended { color: #fecaca; background: rgba(239,68,68,.15); }
.status.closed { color: #cbd5e1; background: rgba(100,116,139,.2); }
.last { display: flex; align-items: center; gap: 6px; font-size: 13px; flex-wrap: wrap; }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.dot.ok { background: var(--ok); } .dot.warn { background: var(--warn); } .dot.bad { background: var(--bad); } .dot.unknown { background: var(--unknown); }
.last b.bad { color: #fca5a5; } .last b.warn { color: #fde68a; }
.card-actions { display: flex; gap: 6px; margin-top: auto; }
.card-actions .btn { flex: 1; text-align: center; padding: 7px 6px; }
.card-actions a.btn { text-decoration: none; }
.err-line { font-size: 11px; color: #fca5a5; }
.empty { padding: 40px 16px; text-align: center; color: var(--muted); }

/* 履歴 */
.activity { padding: 12px 18px 40px; }
.act { display: grid; grid-template-columns: 150px 90px 1fr; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.act .muted { font-size: 12px; }

/* モーダル */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: grid; place-items: center; padding: 12px; z-index: 20; overflow: auto; }
.modal-card { width: 100%; max-width: 640px; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 18px; max-height: 96vh; overflow: auto; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
.modal-card .row > select { width: 130px; flex: none; }
.modal-card .row > input[type="text"] { flex: 1; min-width: 0; }
.avatar-preview { width: 48px; height: 48px; border-radius: 50%; background: var(--panel2); overflow: hidden; flex: none; }
.avatar-preview img { width: 100%; height: 100%; object-fit: cover; }
.form-actions { margin-top: 14px; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: #1f2937; border: 1px solid var(--line); padding: 10px 16px; border-radius: 12px; z-index: 30; font-size: 13px; max-width: 92vw; }

/* ===== スマホ: サイドメニューは引き出し式 ===== */
@media (max-width: 860px) {
  .side { position: fixed; left: 0; top: 0; bottom: 0; height: 100vh; z-index: 25; transform: translateX(-100%); transition: transform .2s ease; box-shadow: 0 0 40px rgba(0,0,0,.5); }
  .app.side-open .side { transform: translateX(0); }
  .side-overlay { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 24; opacity: 0; pointer-events: none; transition: opacity .2s; }
  .app.side-open .side-overlay { opacity: 1; pointer-events: auto; }
  .menu-btn { display: inline-block; }
  .top { flex-wrap: wrap; padding: 10px 12px; gap: 8px; }
  .top-title h1 { font-size: 15px; }
  .top-tools { margin-left: 0; width: 100%; display: grid; grid-template-columns: 1fr 1fr; }
  .top-tools input[type="search"] { width: 100%; grid-column: 1 / -1; }
  .top-tools select { width: 100%; }
  .filter-bar { padding: 10px 12px 0; }
  .group-links { padding: 10px 12px 0; }
  .cards { grid-template-columns: 1fr; padding: 12px 12px 40px; }
  .activity { padding: 12px 12px 40px; }
  .btn { padding: 8px 10px; }
  .grid2, .grid3 { grid-template-columns: 1fr; }
  .act { grid-template-columns: 1fr; gap: 2px; }
  .modal-card .row > select { width: 100%; }
}
