:root {
  --sidebar-bg: #1a1d29;
  --sidebar-fg: #cfd3e6;
  --sidebar-fg-dim: #8a8fae;
  --accent: #4a90d9;
  --bg: #ffffff;
  --border: #e2e5ea;
  --text: #1c1e26;
  --text-dim: #6b7080;
  --danger: #e63946;
  --success: #2ec47a;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Kaku Gothic ProN", "Yu Gothic", sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; color: var(--text); background: var(--bg); }
[hidden] { display: none !important; }

/* --- 認証画面 --- */
.auth-page {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; background: #f4f5f8;
}
.auth-box {
  background: #fff; padding: 32px; border-radius: 12px; width: 360px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.08);
}
.auth-box h1 { font-size: 18px; margin: 0 0 4px; color: var(--accent); }
.auth-box h2 { font-size: 20px; margin: 0 0 20px; }
.auth-box label { display: block; margin-bottom: 14px; font-size: 13px; color: var(--text-dim); }
.auth-box input {
  display: block; width: 100%; margin-top: 6px; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: 6px; font-size: 14px;
}
.auth-box button {
  width: 100%; padding: 11px; background: var(--accent); color: #fff; border: none;
  border-radius: 6px; font-size: 14px; font-weight: 600; cursor: pointer; margin-top: 6px;
}
.auth-box button:hover { opacity: 0.9; }
.auth-box .error { color: var(--danger); font-size: 13px; background: #fdecee; padding: 10px 12px; border-radius: 6px; }
.auth-box .success { color: #1a7a4c; font-size: 13px; background: #e8f8f0; padding: 10px 12px; border-radius: 6px; }
.auth-box .link { text-align: center; margin-top: 16px; font-size: 13px; }
.auth-box .link a { color: var(--accent); text-decoration: none; }

/* --- チャット画面 --- */
.chat-page { height: 100vh; overflow: hidden; }
#app { display: flex; height: 100vh; }

.sidebar {
  width: 240px; flex-shrink: 0; background: var(--sidebar-bg); color: var(--sidebar-fg);
  display: flex; flex-direction: column; padding: 16px 0;
}
.sidebar-header { padding: 0 16px 16px; display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid rgba(255,255,255,0.08); margin-bottom: 12px; }
.site-name { font-weight: 700; font-size: 15px; }
.logout-link { color: var(--sidebar-fg-dim); font-size: 12px; text-decoration: none; }
.logout-link:hover { color: #fff; }

.sidebar-section { padding: 0 8px; margin-bottom: 18px; }
.sidebar-section-title {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--sidebar-fg-dim);
  padding: 4px 8px; display: flex; justify-content: space-between; align-items: center;
}
.sidebar-section-title button {
  background: none; border: none; color: var(--sidebar-fg-dim); cursor: pointer; font-size: 15px; line-height: 1;
}
.sidebar-section-title button:hover { color: #fff; }

.nav-list { list-style: none; margin: 0; padding: 0; }
.nav-list li {
  padding: 7px 8px; border-radius: 6px; cursor: pointer; font-size: 14px;
  display: flex; align-items: center; justify-content: space-between; gap: 6px;
}
.nav-list li:hover { background: rgba(255,255,255,0.06); }
.nav-list li.active { background: var(--accent); color: #fff; }
.nav-list li .label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-list li .badge { background: var(--danger); color: #fff; font-size: 11px; padding: 1px 6px; border-radius: 10px; }

.sidebar-footer { margin-top: auto; padding: 12px 16px 0; border-top: 1px solid rgba(255,255,255,0.08); }
.current-user { display: flex; align-items: center; gap: 8px; font-size: 13px; margin-bottom: 10px; }
.avatar {
  width: 26px; height: 26px; border-radius: 50%; color: #fff; font-size: 12px; font-weight: 700;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.notif-btn {
  width: 100%; background: rgba(255,255,255,0.06); color: var(--sidebar-fg); border: none;
  padding: 8px; border-radius: 6px; font-size: 13px; cursor: pointer; display: flex; justify-content: center; gap: 6px;
}
.notif-btn:hover { background: rgba(255,255,255,0.12); }
.badge { background: var(--danger); color: #fff; font-size: 11px; padding: 1px 7px; border-radius: 10px; }

.chat-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.chat-header { padding: 14px 22px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 12px; }
.chat-header h2 { margin: 0; font-size: 16px; }
.chat-header p { margin: 2px 0 0; font-size: 12px; color: var(--text-dim); }
.menu-toggle { display: none; background: none; border: none; font-size: 20px; cursor: pointer; color: var(--text); flex-shrink: 0; }
.sidebar-backdrop { display: none; }

.message-list { flex: 1; overflow-y: auto; padding: 16px 22px; }
.message-row { display: flex; gap: 10px; margin-bottom: 16px; }
.message-row .avatar { width: 34px; height: 34px; font-size: 14px; }
.message-body-col { flex: 1; min-width: 0; }
.message-meta { font-size: 13px; margin-bottom: 2px; }
.message-meta .name { font-weight: 700; margin-right: 6px; }
.message-meta .time { color: var(--text-dim); font-size: 11px; }
.message-text { font-size: 14px; line-height: 1.5; word-break: break-word; white-space: pre-wrap; }
.message-text .mention { background: #eaf1fb; color: var(--accent); padding: 0 3px; border-radius: 4px; font-weight: 600; }
.attachment { margin-top: 6px; }
.attachment img { max-width: 320px; max-height: 240px; border-radius: 8px; display: block; }
.attachment a.file-link {
  display: inline-flex; align-items: center; gap: 6px; padding: 8px 12px; border: 1px solid var(--border);
  border-radius: 8px; font-size: 13px; color: var(--text); text-decoration: none; max-width: 320px;
}
.attachment a.file-link:hover { background: #f5f6f8; }
.empty-state { color: var(--text-dim); font-size: 13px; text-align: center; margin-top: 40px; }

.message-form { border-top: 1px solid var(--border); padding: 12px 22px; position: relative; }
.message-form textarea {
  width: 100%; resize: none; border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px;
  font-size: 14px; font-family: inherit;
}
.message-form-row { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.file-label { cursor: pointer; font-size: 16px; }
.file-label input { display: none; }
.file-name { font-size: 12px; color: var(--text-dim); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.message-form button[type=submit] {
  background: var(--accent); color: #fff; border: none; padding: 9px 20px; border-radius: 6px;
  font-size: 13px; font-weight: 600; cursor: pointer;
}

.mention-suggest {
  position: absolute; bottom: 100%; left: 22px; background: #fff; border: 1px solid var(--border);
  border-radius: 8px; box-shadow: 0 4px 14px rgba(0,0,0,0.12); width: 220px; max-height: 180px; overflow-y: auto; z-index: 5;
}
.mention-suggest div { padding: 8px 12px; font-size: 13px; cursor: pointer; }
.mention-suggest div:hover, .mention-suggest div.active { background: #eaf1fb; }

.notif-panel {
  position: fixed; top: 0; right: 0; width: 320px; height: 100vh; background: #fff;
  border-left: 1px solid var(--border); box-shadow: -4px 0 16px rgba(0,0,0,0.08); z-index: 10;
  display: flex; flex-direction: column;
}
.notif-panel-header { padding: 14px 18px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; font-weight: 700; }
.notif-panel-header button { background: none; border: none; font-size: 18px; cursor: pointer; color: var(--text-dim); }
.notif-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; }
.notif-list li { padding: 12px 18px; border-bottom: 1px solid var(--border); font-size: 13px; cursor: pointer; }
.notif-list li:hover { background: #f5f6f8; }
.notif-list li.unread { background: #f0f6fd; }
.notif-list .notif-from { font-weight: 700; }
.notif-list .notif-ctx { color: var(--text-dim); font-size: 11px; margin-left: 6px; }
.notif-list .notif-snippet { margin-top: 3px; color: var(--text-dim); }
.notif-list .notif-time { font-size: 11px; color: var(--text-dim); margin-top: 3px; }
.notif-empty { padding: 24px 18px; text-align: center; color: var(--text-dim); font-size: 13px; }

.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,0.35); display: flex; align-items: center; justify-content: center; z-index: 20;
}
.modal-box { background: #fff; border-radius: 10px; padding: 22px; width: 340px; }
.modal-box h3 { margin: 0 0 16px; font-size: 16px; }
.modal-box label { display: block; margin-bottom: 12px; font-size: 13px; color: var(--text-dim); }
.modal-box input {
  display: block; width: 100%; margin-top: 6px; padding: 9px 10px; border: 1px solid var(--border); border-radius: 6px; font-size: 14px;
}
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.modal-actions button { padding: 8px 16px; border-radius: 6px; border: none; font-size: 13px; cursor: pointer; }
.modal-actions button[type=submit] { background: var(--accent); color: #fff; }
.modal-actions button[type=button] { background: #eee; }

/* --- レスポンシブ(スマホ) --- */
@media (max-width: 768px) {
  .menu-toggle { display: block; }

  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 30;
    width: 80%; max-width: 300px;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
  }
  .sidebar.open { transform: translateX(0); }

  .sidebar-backdrop {
    display: block; position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 25;
  }

  .chat-main { width: 100%; }

  .message-list { padding: 12px; }
  .message-form { padding: 10px 12px; }
  .attachment img { max-width: 220px; max-height: 180px; }

  .notif-panel { width: 85%; max-width: 320px; }
  .modal-box { width: 85vw; max-width: 340px; padding: 18px; }
}
