:root {
  --bg: #0f1115;
  --sidebar-bg: #14161c;
  --card-bg: #1a1d24;
  --text: #e8e8ec;
  --muted: #8a8f9a;
  --accent: #ff5c8a;
  --border: #2a2e37;
  --card-width: 260px;
  --card-gap: 12px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Segoe UI", "Noto Sans TC", sans-serif;
}

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

/* ── サイドバー ───────────────────────── */

.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  padding: 20px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.brand {
  display: block;
  text-decoration: none;
}

.brand-title {
  display: block;
  color: #ffffff;
  font-size: 20px;
  font-weight: 800;
  letter-spacing: 0.5px;
  line-height: 1.3;
  padding: 10px 12px;
}

.type-filter {
  display: flex;
  gap: 8px;
}

.type-btn {
  flex: 1;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 8px 0;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
}

.type-btn:hover { color: var(--text); border-color: var(--muted); }

.type-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #16090f;
}

.tag-filter {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tag-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 4px 10px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
}

.tag-btn:hover { color: var(--text); border-color: var(--muted); }

.tag-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #16090f;
}

.tag-btn.add-btn, .member-item.add-btn {
  border-style: dashed;
  opacity: 0.7;
}

.tag-btn.drag-over, .member-item.drag-over {
  outline: 2px dashed var(--accent);
  outline-offset: -2px;
}

.expand-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}

.expand-toggle input {
  accent-color: var(--accent);
  width: 15px;
  height: 15px;
  cursor: pointer;
}

.member-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.member-item {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 7px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.member-item:hover {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
}

.member-item.active {
  background: rgba(255, 92, 138, 0.15);
  color: var(--accent);
  font-weight: 700;
}

.inline-rename-input {
  width: 100%;
  background: #0f1115;
  border: 1px solid var(--accent);
  border-radius: 4px;
  color: var(--text);
  font-size: 13px;
  padding: 4px 6px;
}

.sidebar-footer {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.footer-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 7px 0;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
}

.footer-btn:hover { color: var(--text); border-color: var(--muted); }
.footer-btn.active { color: var(--accent); border-color: var(--accent); }

/* ── メインコンテンツ ───────────────────── */

.content {
  flex: 1;
  padding: 20px;
  min-width: 0;
}

.masonry {
  column-width: var(--card-width);
  column-gap: var(--card-gap);
}

.card {
  break-inside: avoid;
  margin-bottom: var(--card-gap);
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}

.card-media {
  position: relative;
}

.card img, .card video {
  width: 100%;
  display: block;
  background: #000;
}

.card-media img {
  cursor: zoom-in;
}

.card-expand {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.card-expand:hover {
  background: rgba(0, 0, 0, 0.8);
}

.card-body {
  padding: 10px 12px;
}

.card-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.card-avatar {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--border);
  object-fit: cover;
}

.card-handle {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  text-decoration: none;
}

.card-platform {
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--border);
  color: var(--muted);
  text-transform: uppercase;
  margin-left: auto;
}

.card-caption {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.4;
  margin: 0 0 6px;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-link {
  font-size: 12px;
  color: var(--accent);
  text-decoration: none;
}

.status {
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  padding: 24px;
}

#sentinel {
  height: 1px;
}

/* ── モーダル（Admin登入・版面設定） ───────────────────── */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

.modal[hidden] {
  display: none;
}

.modal-box {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
  width: 320px;
  max-width: 90vw;
}

.modal-box h2 {
  margin: 0 0 14px;
  font-size: 15px;
}

.modal-box label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin: 12px 0 6px;
}

.modal-box label:first-of-type { margin-top: 0; }

.modal-box input[type="password"],
.modal-box input[type="text"] {
  width: 100%;
  padding: 8px 10px;
  background: #0f1115;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 14px;
}

.modal-box input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.modal-msg {
  font-size: 12px;
  color: var(--muted);
  min-height: 16px;
  margin: 8px 0 0;
}

.modal-msg.err { color: #f87171; }
.modal-msg.ok { color: #4ade80; }

.modal-actions {
  display: flex;
  gap: 8px;
  margin-top: 14px;
}

.modal-actions button {
  flex: 1;
  padding: 8px 0;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 700;
  font-size: 13px;
}

.modal-actions button:not(.btn-secondary) {
  background: var(--accent);
  color: #16090f;
}

.modal-actions .btn-secondary {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
}

/* ── 右鍵選單 ───────────────────── */

.context-menu {
  position: fixed;
  z-index: 250;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  overflow: hidden;
}

.context-menu[hidden] {
  display: none;
}

.context-menu button {
  display: block;
  width: 100%;
  background: transparent;
  border: none;
  color: var(--text);
  padding: 9px 16px;
  text-align: left;
  cursor: pointer;
  font-size: 13px;
}

.context-menu button:hover {
  background: rgba(255, 255, 255, 0.06);
}

/* ── ライトボックス／貼文詳細 ───────────────────── */

.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

.lightbox[hidden] {
  display: none;
}

.lightbox-body {
  display: flex;
  gap: 20px;
  max-width: 95vw;
  max-height: 92vh;
}

.lightbox-media-area {
  position: relative;
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.lightbox-stage {
  max-width: 100%;
  max-height: 88vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.lightbox-stage img,
.lightbox-stage video {
  max-width: 100%;
  max-height: 88vh;
  object-fit: contain;
}

.lightbox-close {
  position: absolute;
  top: 18px;
  right: 18px;
  width: 36px;
  height: 36px;
  font-size: 16px;
  border: none;
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  cursor: pointer;
  border-radius: 50%;
  z-index: 10;
}

.lightbox-close:hover {
  background: rgba(255, 255, 255, 0.18);
}

.lightbox-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 44px;
  height: 44px;
  font-size: 24px;
  border: none;
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  cursor: pointer;
  border-radius: 50%;
}

.lightbox-nav:hover {
  background: rgba(255, 255, 255, 0.18);
}

.lightbox-prev { left: 8px; }
.lightbox-next { right: 8px; }

.lightbox-panel {
  width: 300px;
  flex-shrink: 0;
  max-height: 92vh;
  overflow-y: auto;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
}

.lightbox-meta {
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 8px;
}

.lightbox-caption {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.5;
  white-space: pre-wrap;
}

.lightbox-link {
  display: inline-block;
  margin: 8px 0;
  font-size: 12px;
  color: var(--accent);
  text-decoration: none;
}

.lightbox-count {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 8px;
}

.lightbox-admin {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.lightbox-admin h3 {
  font-size: 12px;
  color: var(--muted);
  margin: 0 0 8px;
}

.lightbox-thumbs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  margin-bottom: 14px;
}

.lightbox-thumbs img,
.lightbox-thumbs video {
  width: 52px;
  height: 52px;
  object-fit: cover;
  border-radius: 6px;
  border: 2px solid var(--border);
  cursor: grab;
  flex-shrink: 0;
}

.lightbox-thumbs .thumb.active {
  border-color: var(--accent);
}

.lightbox-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.lightbox-tags .tag-pill {
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 4px 10px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 12px;
}

.lightbox-tags .tag-pill.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #16090f;
}

/* ── モバイル：サイドバーを上部バーに折りたたむ ── */

@media (max-width: 640px) {
  .app-shell { flex-direction: column; }
  .sidebar {
    width: 100%;
    height: auto;
    position: static;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
  }
  .member-list {
    flex-direction: row;
    flex-wrap: wrap;
    width: 100%;
  }
  .sidebar-footer {
    margin-top: 0;
    flex-direction: row;
    width: 100%;
  }
  .lightbox-body {
    flex-direction: column;
    max-height: 95vh;
    overflow-y: auto;
  }
  .lightbox-panel {
    width: 100%;
  }
}
